Wipe bugfix for StaticArray.

Thanks (in no particular order shuffled randomly until alphabetical)
  @asterite @bcardiff @blacksmoke16
This commit is contained in:
Didactic Drunk 2019-06-30 14:03:08 -07:00
parent 731a3d7a4c
commit 7745e2f912
2 changed files with 17 additions and 16 deletions

View File

@ -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

View File

@ -15,18 +15,19 @@ 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
end
raise "unsupported wipe type for #{typeof(@{{ ivar.id }})} {{ ivar.id }}"
end
{% end %}
{% end %}
{% end %}
end
def finalize