generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 155
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1a27be3
verify size of mlen in external mu mode
jakemas 2185013
Cleanse intermediates when ending early
jakemas 0d23bd5
CR fixes
jakemas 5b1c5a5
Comment fixz
jakemas 405486d
propigate return value
jakemas ff7fbb9
CR nits
jakemas f4128f8
Merge branch 'main' into mldsa-mu-length-check
jakemas eaa6bae
Merge branch 'main' into mldsa-mu-length-check
jakemas fccee3f
Merge branch 'main' into mldsa-mu-length-check
jakemas dbe6f09
Merge branch 'main' into mldsa-mu-length-check
jakemas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 too long or incorrect mlen in external mu) | ||
| **************************************************/ | ||
| int ml_dsa_sign_internal(ml_dsa_params *params, | ||
| uint8_t *sig, | ||
|
|
@@ -184,6 +184,10 @@ int ml_dsa_sign_internal(ml_dsa_params *params, | |
| ml_dsa_poly cp; | ||
| KECCAK1600_CTX state; | ||
|
|
||
| if (external_mu && mlen != ML_DSA_CRHBYTES) { | ||
| return -1; | ||
| } | ||
|
|
||
| rho = seedbuf; | ||
| tr = rho + ML_DSA_SEEDBYTES; | ||
| key = tr + ML_DSA_TRBYTES; | ||
|
|
@@ -346,12 +350,12 @@ int ml_dsa_sign(ml_dsa_params *params, | |
| if (!RAND_bytes(rnd, ML_DSA_RNDBYTES)) { | ||
| return -1; | ||
| } | ||
| ml_dsa_sign_internal(params, sig, siglen, m, mlen, pre, 2 + ctxlen, rnd, sk, 0); | ||
| int ret = ml_dsa_sign_internal(params, sig, siglen, m, mlen, pre, 2 + ctxlen, rnd, sk, 0); | ||
|
|
||
| /* FIPS 204. Section 3.6.3 Destruction of intermediate values. */ | ||
| OPENSSL_cleanse(pre, sizeof(pre)); | ||
| OPENSSL_cleanse(rnd, sizeof(rnd)); | ||
| return 0; | ||
| return ret; | ||
| } | ||
|
|
||
| /************************************************* | ||
|
|
@@ -380,11 +384,11 @@ int ml_dsa_extmu_sign(ml_dsa_params *params, | |
| if (!RAND_bytes(rnd, ML_DSA_RNDBYTES)) { | ||
| return -1; | ||
| } | ||
| ml_dsa_sign_internal(params, sig, siglen, mu, mulen, NULL, 0, rnd, sk, 1); | ||
| int ret = ml_dsa_sign_internal(params, sig, siglen, mu, mulen, NULL, 0, rnd, sk, 1); | ||
|
|
||
| /* FIPS 204. Section 3.6.3 Destruction of intermediate values. */ | ||
| OPENSSL_cleanse(rnd, sizeof(rnd)); | ||
| return 0; | ||
| return ret; | ||
| } | ||
|
|
||
| /************************************************* | ||
|
|
@@ -469,6 +473,11 @@ int ml_dsa_verify_internal(ml_dsa_params *params, | |
| if(siglen != params->bytes) { | ||
|
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. we could add space here
Collaborator
Author
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. There is a mix of if's with and without -- for now I can live with this |
||
| return -1; | ||
| } | ||
|
|
||
| if (external_mu && mlen != ML_DSA_CRHBYTES) { | ||
| return -1; | ||
| } | ||
|
|
||
| /* FIPS 204: line 1 */ | ||
| ml_dsa_unpack_pk(params, rho, &t1, pk); | ||
| /* FIPS 204: line 2 */ | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
warning: use of undeclared identifier 'KECCAK1600_CTX' [clang-diagnostic-error]