From b81ec7d7e0170bed5a878169daed9392bf80751d Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Tue, 20 Sep 2016 14:14:49 +0200 Subject: Crypto: make HMAC-SHA512 code more clear by removing the memory usage optimization and make field k of hmac_sha512_ctx big enough to hold computation results instead of relying on the field u that follows it. --- src/Common/Pkcs5.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'src/Common') diff --git a/src/Common/Pkcs5.c b/src/Common/Pkcs5.c index 3dbfd322..d0dbd8bc 100644 --- a/src/Common/Pkcs5.c +++ b/src/Common/Pkcs5.c @@ -280,7 +280,7 @@ typedef struct hmac_sha512_ctx_struct sha512_ctx ctx; sha512_ctx inner_digest_ctx; /*pre-computed inner digest context */ sha512_ctx outer_digest_ctx; /*pre-computed outer digest context */ - char k[PKCS5_SALT_SIZE + 4]; /* enough to hold (salt_len + 4) and also the SHA512 hash */ + char k[SHA512_BLOCKSIZE]; /* enough to hold (salt_len + 4) and also the SHA512 hash */ char u[SHA512_DIGESTSIZE]; } hmac_sha512_ctx; @@ -322,9 +322,7 @@ void hmac_sha512 { hmac_sha512_ctx hmac; sha512_ctx* ctx; - char* buf = hmac.k; /* there is enough space to hold SHA512_BLOCKSIZE (128) bytes - * because k is followed by u in hmac_sha512_ctx - */ + char* buf = hmac.k; int b; char key[SHA512_DIGESTSIZE]; @@ -405,9 +403,7 @@ void derive_key_sha512 (char *pwd, int pwd_len, char *salt, int salt_len, uint32 { hmac_sha512_ctx hmac; sha512_ctx* ctx; - char* buf = hmac.k; /* there is enough space to hold SHA512_BLOCKSIZE (128) bytes - * because k is followed by u in hmac_sha512_ctx - */ + char* buf = hmac.k; int b, l, r; char key[SHA512_DIGESTSIZE]; -- cgit v1.2.3