The message schedule W in sm3_update() and sm3_final() is cleared with
memset() in the block where it dies, so the compiler deletes both clears.
-fdump-tree-dse-details names them:
Deleted dead call: memset (&W, 0, 64);
Deleted dead call: memset (&W, 0, 64);
The second of the two sits under a comment that says "Zeroize sensitive
information.", so the intent is explicit and the clear the comment promises
is the one the compiler removes.
Use memzero_explicit() for those two clears. sm3_final() also clears the
caller's context in the same block; that store survives today and is left
alone here.
Measured with GCC 13.3.0 on x86-64 against the default branch, with
u-boot's own include prologue: two deleted memset calls in lib/sm3.c
before this patch, none after it.
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