Skip to content

Commit 6e65c6e

Browse files
mkannwischerhanno-becker
authored andcommitted
Clear signature outputs with mld_zeroize on failure
Scrub the detached-signature buffer on error paths with mld_zeroize rather than memset, matching key generation and pk_from_sk. This is a conservative measure. A plain memset of an output buffer is not a dead store while the signing routine is a separate call, so the compiler will not remove it; it could only be optimized away if the routine were inlined into a caller that discards the signature. Signed-off-by: Matthias J. Kannwischer <matthias@zerorisc.com>
1 parent e48be7b commit 6e65c6e

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

mldsa/src/sign.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ int mld_sign_signature_internal(uint8_t sig[MLDSA_CRYPTO_BYTES],
10501050
if (ret != 0)
10511051
{
10521052
/* To be on the safe-side, we zeroize the signature buffer. */
1053-
mld_memset(sig, 0, MLDSA_CRYPTO_BYTES);
1053+
mld_zeroize(sig, MLDSA_CRYPTO_BYTES);
10541054
}
10551055

10561056
/* @[FIPS204, Section 3.6.3] Destruction of intermediate values. */
@@ -1111,9 +1111,9 @@ int mld_sign_signature(uint8_t sig[MLDSA_CRYPTO_BYTES], const uint8_t *m,
11111111
* the case of error.
11121112
*
11131113
* If we come from mld_sign_signature_internal, this is redundant, but the
1114-
* error case should not be the norm, and the added cost of the memset
1114+
* error case should not be the norm, and the added cost of the zeroization
11151115
* insignificant. */
1116-
mld_memset(sig, 0, MLDSA_CRYPTO_BYTES);
1116+
mld_zeroize(sig, MLDSA_CRYPTO_BYTES);
11171117
}
11181118

11191119
/* @[FIPS204, Section 3.6.3] Destruction of intermediate values. */
@@ -1370,9 +1370,9 @@ int mld_sign_signature_pre_hash_internal(
13701370
* the case of error.
13711371
*
13721372
* If we come from mld_sign_signature_internal, this is redundant, but the
1373-
* error case should not be the norm, and the added cost of the memset
1373+
* error case should not be the norm, and the added cost of the zeroization
13741374
* insignificant. */
1375-
mld_memset(sig, 0, MLDSA_CRYPTO_BYTES);
1375+
mld_zeroize(sig, MLDSA_CRYPTO_BYTES);
13761376
}
13771377

13781378
/* @[FIPS204, Section 3.6.3] Destruction of intermediate values. */

0 commit comments

Comments
 (0)