-
Notifications
You must be signed in to change notification settings - Fork 154
Verify size of mlen in ML-DSA external mu mode #2841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
1a27be3
2185013
0d23bd5
5b1c5a5
405486d
ff7fbb9
f4128f8
eaa6bae
fccee3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -161,7 +161,7 @@ int ml_dsa_keypair(ml_dsa_params *params, uint8_t *pk, uint8_t *sk, uint8_t *see | |
| * - uint8_t *sk: pointer to bit-packed secret key | ||
| * - int external_mu: indicates input message m is to be processed as mu | ||
| * | ||
| * Returns 0 (success) or -1 (context string too long) | ||
| * Returns 0 (success) or -1 (context string or mlen too long) | ||
| **************************************************/ | ||
| int ml_dsa_sign_internal(ml_dsa_params *params, | ||
| uint8_t *sig, | ||
|
|
@@ -205,6 +205,15 @@ int ml_dsa_sign_internal(ml_dsa_params *params, | |
| SHAKE_Final(mu, &state, ML_DSA_CRHBYTES); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: call to undeclared function 'SHAKE_Final'; ISO C99 and later do not support implicit function declarations [clang-diagnostic-implicit-function-declaration] SHAKE_Final(mu, &state, ML_DSA_CRHBYTES);
^Additional contextcrypto/fipsmodule/ml_dsa/ml_dsa_ref/sign.c:204: did you mean 'SHA1_Final'? SHAKE_Final(mu, &state, ML_DSA_CRHBYTES);
^include/openssl/sha.h:84: 'SHA1_Final' declared here OPENSSL_EXPORT int SHA1_Final(uint8_t out[SHA_DIGEST_LENGTH], SHA_CTX *sha);
^
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: use of undeclared identifier 'state' [clang-diagnostic-error] SHAKE_Final(mu, &state, ML_DSA_CRHBYTES);
^ |
||
| } | ||
| else { | ||
| // When external_mu is true, m is expected to be exactly ML_DSA_CRHBYTES | ||
| if (mlen != ML_DSA_CRHBYTES) { | ||
| /* FIPS 204. Section 3.6.3 Destruction of intermediate values. */ | ||
| OPENSSL_cleanse(seedbuf, sizeof(seedbuf)); | ||
| OPENSSL_cleanse(&t0, sizeof(t0)); | ||
| OPENSSL_cleanse(&s1, sizeof(s1)); | ||
| OPENSSL_cleanse(&s2, sizeof(s2)); | ||
| return -1; | ||
|
||
| } | ||
| OPENSSL_memcpy(mu, m, mlen); | ||
| } | ||
|
|
||
|
|
@@ -492,6 +501,16 @@ int ml_dsa_verify_internal(ml_dsa_params *params, | |
| SHAKE_Final(mu, &state, ML_DSA_CRHBYTES); | ||
| } | ||
| else { | ||
| // When external_mu is true, m is expected to be exactly ML_DSA_CRHBYTES | ||
| if (mlen != ML_DSA_CRHBYTES) { | ||
| /* FIPS 204. Section 3.6.3 Destruction of intermediate values. */ | ||
| OPENSSL_cleanse(rho, sizeof(rho)); | ||
| OPENSSL_cleanse(&t1, sizeof(t1)); | ||
| OPENSSL_cleanse(c, sizeof(c)); | ||
| OPENSSL_cleanse(&z, sizeof(z)); | ||
| OPENSSL_cleanse(&h, sizeof(h)); | ||
| return -1; | ||
|
||
| } | ||
| OPENSSL_memcpy(mu, m, mlen); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or too short? I could not see where the length of context is checked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in 5b1c5a5