Same as sha1_hmac(): the key schedule and keybuf are locals cleared just
before the function returns, so those stores are dead too. keybuf holds
the key, or its digest when the key is longer than a block.

The memset() that initialises keybuf is not one of the clears, so leave
it alone.

Cc: Tom Rini <[email protected]>
Signed-off-by: Xiaoyi Suo <[email protected]>
---
 lib/sha256.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/sha256.c b/lib/sha256.c
index c2e77c854..226af9b2d 100644
--- a/lib/sha256.c
+++ b/lib/sha256.c
@@ -307,11 +307,11 @@ int sha256_hmac(const unsigned char *key, int keylen,
        sha256_update(&ctx, tmpbuf, sizeof(tmpbuf));
        sha256_finish(&ctx, output);
 
-       memset(k_ipad, 0, sizeof(k_ipad));
-       memset(k_opad, 0, sizeof(k_opad));
-       memset(tmpbuf, 0, sizeof(tmpbuf));
-       memset(keybuf, 0, sizeof(keybuf));
-       memset(&ctx, 0, sizeof(sha256_context));
+       memzero_explicit(k_ipad, sizeof(k_ipad));
+       memzero_explicit(k_opad, sizeof(k_opad));
+       memzero_explicit(tmpbuf, sizeof(tmpbuf));
+       memzero_explicit(keybuf, sizeof(keybuf));
+       memzero_explicit(&ctx, sizeof(sha256_context));
 
        return 0;
 }
-- 
2.43.0

Reply via email to