From 7745e2f9125b3c68b13d9068a22626b8d932ce41 Mon Sep 17 00:00:00 2001 From: Didactic Drunk <1479616+didactic-drunk@users.noreply.github.com> Date: Sun, 30 Jun 2019 14:03:08 -0700 Subject: [PATCH] Wipe bugfix for StaticArray. Thanks (in no particular order shuffled randomly until alphabetical) @asterite @bcardiff @blacksmoke16 --- src/sodium/digest/blake2b.cr | 16 ++++++++-------- src/sodium/wipe.cr | 17 +++++++++-------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/sodium/digest/blake2b.cr b/src/sodium/digest/blake2b.cr index c206cd2..98212d8 100644 --- a/src/sodium/digest/blake2b.cr +++ b/src/sodium/digest/blake2b.cr @@ -17,17 +17,17 @@ module Sodium::Digest include OpenSSL::DigestBase include Wipe - KEY_SIZE = LibSodium.crypto_generichash_blake2b_keybytes - KEY_SIZE_MIN = LibSodium.crypto_generichash_blake2b_keybytes_min - KEY_SIZE_MAX = LibSodium.crypto_generichash_blake2b_keybytes_max + KEY_SIZE = LibSodium.crypto_generichash_blake2b_keybytes # 32 + KEY_SIZE_MIN = LibSodium.crypto_generichash_blake2b_keybytes_min # 16 + KEY_SIZE_MAX = LibSodium.crypto_generichash_blake2b_keybytes_max # 64 - SALT_SIZE = LibSodium.crypto_generichash_blake2b_saltbytes + SALT_SIZE = LibSodium.crypto_generichash_blake2b_saltbytes # 16 - PERSONAL_SIZE = LibSodium.crypto_generichash_blake2b_personalbytes + PERSONAL_SIZE = LibSodium.crypto_generichash_blake2b_personalbytes # 16 - OUT_SIZE = LibSodium.crypto_generichash_blake2b_bytes.to_i32 - OUT_SIZE_MIN = LibSodium.crypto_generichash_blake2b_bytes_min.to_i32 - OUT_SIZE_MAX = LibSodium.crypto_generichash_blake2b_bytes_max.to_i32 + OUT_SIZE = LibSodium.crypto_generichash_blake2b_bytes.to_i32 # 32 + OUT_SIZE_MIN = LibSodium.crypto_generichash_blake2b_bytes_min.to_i32 # 16 + OUT_SIZE_MAX = LibSodium.crypto_generichash_blake2b_bytes_max.to_i32 # 64 getter digest_size diff --git a/src/sodium/wipe.cr b/src/sodium/wipe.cr index cbfab73..798a90b 100644 --- a/src/sodium/wipe.cr +++ b/src/sodium/wipe.cr @@ -15,16 +15,17 @@ module Sodium::Wipe {% for ivar in @type.instance_vars %} {% if ann = ivar.annotation(Wipe::Var) %} - if var = @{{ ivar.id }} - case var - when StaticArray -#puts "wiping {{ivar}}" -# Sodium.memzero var.to_slice -# @{{ ivar.id }} = var + {% if ivar.type <= StaticArray %} + Sodium.memzero @{{ivar.id}}.to_slice + {% else %} + case var = @{{ ivar.id }} + when Slice + Sodium.memzero var + when nil else - Sodium.memzero var.to_slice + raise "unsupported wipe type for #{typeof(@{{ ivar.id }})} {{ ivar.id }}" end - end + {% end %} {% end %} {% end %} end