Skip to content

Commit 2b3c025

Browse files
Use ForceZero to clean up HMAC-BLAKE2[bs]
1 parent ee708dc commit 2b3c025

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

wolfcrypt/src/blake2b.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737

3838
#include <wolfssl/wolfcrypt/blake2.h>
3939
#include <wolfssl/wolfcrypt/blake2-impl.h>
40+
#ifdef NO_INLINE
41+
#include <wolfssl/wolfcrypt/misc.h>
42+
#else
43+
#define WOLFSSL_MISC_INCLUDED
44+
#include <wolfcrypt/src/misc.c>
45+
#endif
4046

4147
static const word64 blake2b_IV[8] =
4248
{
@@ -564,8 +570,8 @@ int wc_Blake2bHmac(const byte * in, size_t in_len,
564570
return ret;
565571

566572
XMEMCPY(out, i_hash, BLAKE2B_OUTBYTES);
567-
XMEMSET(x_key, 0, BLAKE2B_BLOCKBYTES);
568-
XMEMSET(i_hash, 0, BLAKE2B_OUTBYTES);
573+
ForceZero(x_key, BLAKE2B_BLOCKBYTES);
574+
ForceZero(i_hash, BLAKE2B_OUTBYTES);
569575

570576
return 0;
571577
}

wolfcrypt/src/blake2s.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737

3838
#include <wolfssl/wolfcrypt/blake2.h>
3939
#include <wolfssl/wolfcrypt/blake2-impl.h>
40+
#ifdef NO_INLINE
41+
#include <wolfssl/wolfcrypt/misc.h>
42+
#else
43+
#define WOLFSSL_MISC_INCLUDED
44+
#include <wolfcrypt/src/misc.c>
45+
#endif
4046

4147
static const word32 blake2s_IV[8] =
4248
{
@@ -558,8 +564,8 @@ int wc_Blake2sHmac(const byte * in, size_t in_len,
558564
return ret;
559565

560566
XMEMCPY(out, i_hash, BLAKE2S_OUTBYTES);
561-
XMEMSET(x_key, 0, BLAKE2S_BLOCKBYTES);
562-
XMEMSET(i_hash, 0, BLAKE2S_OUTBYTES);
567+
ForceZero(x_key, BLAKE2S_BLOCKBYTES);
568+
ForceZero(i_hash, BLAKE2S_OUTBYTES);
563569

564570
return 0;
565571
}

0 commit comments

Comments
 (0)