From 40b95605213c67c14cba11be766a022f4223bd90 Mon Sep 17 00:00:00 2001 From: Patrick Oppenlander Date: Mon, 17 Aug 2020 09:43:53 +1000 Subject: [PATCH 1/2] HASH_PROCESS: fix overflow test state_var.length counts bits, inlen is in bytes. --- src/headers/tomcrypt_private.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/headers/tomcrypt_private.h b/src/headers/tomcrypt_private.h index e5e716584..4c3ea9fd3 100644 --- a/src/headers/tomcrypt_private.h +++ b/src/headers/tomcrypt_private.h @@ -90,7 +90,7 @@ int func_name (hash_state * md, const unsigned char *in, unsigned long inlen) if (md-> state_var .curlen > sizeof(md-> state_var .buf)) { \ return CRYPT_INVALID_ARG; \ } \ - if ((md-> state_var .length + inlen) < md-> state_var .length) { \ + if ((md-> state_var .length + inlen * 8) < md-> state_var .length) { \ return CRYPT_HASH_OVERFLOW; \ } \ while (inlen > 0) { \ From d63d6faf22412d7e0eb4978bca8aa7d1d5dbd0bc Mon Sep 17 00:00:00 2001 From: Patrick Oppenlander Date: Mon, 17 Aug 2020 09:45:15 +1000 Subject: [PATCH 2/2] sha256: minor undef cleanup RND is #defined in both the #if and #else case, so move the #undef after the #endif. --- src/hashes/sha2/sha256.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/hashes/sha2/sha256.c b/src/hashes/sha2/sha256.c index 1cd375012..ff2006807 100644 --- a/src/hashes/sha2/sha256.c +++ b/src/hashes/sha2/sha256.c @@ -168,10 +168,8 @@ static int s_sha256_compress(hash_state * md, const unsigned char *buf) RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],61,0xa4506ceb); RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],62,0xbef9a3f7); RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],63,0xc67178f2); - -#undef RND - #endif +#undef RND /* feedback */ for (i = 0; i < 8; i++) {