sm3_update() and sm3_final() clear the message schedule with memset() in the block where it dies, so the compiler removes both clears, including the one under the "Zeroize sensitive information." comment. Use memzero_explicit() for them.
sm3_final() also clears the caller's context in the same block; that store survives today and is left alone here. Cc: Tom Rini <[email protected]> Signed-off-by: Xiaoyi Suo <[email protected]> --- lib/sm3.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/sm3.c b/lib/sm3.c index 058800997..4564cdb2a 100644 --- a/lib/sm3.c +++ b/lib/sm3.c @@ -230,7 +230,7 @@ void sm3_update(struct sm3_context *sctx, const uint8_t *input, size_t ilen) input += blocks * SM3_BLOCK_SIZE; } - memset(W, 0, sizeof(W)); + memzero_explicit(W, sizeof(W)); partial = 0; } @@ -263,7 +263,7 @@ void sm3_final(struct sm3_context *sctx, uint8_t output[SM3_DIGEST_SIZE]) put_unaligned_be32(sctx->state[i], digest++); /* Zeroize sensitive information. */ - memset(W, 0, sizeof(W)); + memzero_explicit(W, sizeof(W)); memset(sctx, 0, sizeof(*sctx)); } -- 2.43.0
