On Sun, Oct 04, 2026 at 11:27:14PM +0800, Xiaoyi Suo wrote:
> sm3_update() and sm3_final() clear W in the block where it dies, so both
> clears go away from -O1 up. One of them is the clear the "Zeroize
> sensitive information." comment is about.
> 
> sm3_final() also clears the caller's context in the same block. That
> store survives today, so leave it as it is.
> 
> 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));

Why is this last memset call clear here safe? I'm not saying it's not, I
just want to be clear.

-- 
Tom

Attachment: signature.asc
Description: PGP signature

Reply via email to