-
Notifications
You must be signed in to change notification settings - Fork 151
Make poly_chknorm constant flow #2788
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
5e55c04
5790986
434425b
2ed8979
783faa5
0327643
16e8e62
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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -223,16 +223,20 @@ void ml_dsa_polyvecl_pointwise_acc_montgomery(ml_dsa_params *params, | |||||||||
| * - int32_t B: norm bound | ||||||||||
| * | ||||||||||
| * Returns 0 if norm of all polynomials is strictly smaller than B <= (Q-1)/8 | ||||||||||
| * and 1 otherwise. | ||||||||||
| * and 0xFFFFFFFF otherwise. | ||||||||||
| **************************************************/ | ||||||||||
| int ml_dsa_polyvecl_chknorm(ml_dsa_params *params, const polyvecl *v, int32_t bound) { | ||||||||||
| uint32_t ml_dsa_polyvecl_chknorm(ml_dsa_params *params, const polyvecl *v, int32_t bound) { | ||||||||||
| unsigned int i; | ||||||||||
| uint32_t r = 0; | ||||||||||
|
|
||||||||||
| /* Reference: Leaks which polynomial violates the bound via a conditional. | ||||||||||
| * We are more conservative to reduce the number of declassifications in | ||||||||||
| * constant-time testing. | ||||||||||
| */ | ||||||||||
|
||||||||||
| /* Reference: Leaks which polynomial violates the bound via a conditional. | |
| * We are more conservative to reduce the number of declassifications in | |
| * constant-time testing. | |
| */ |
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.
removed!
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -178,6 +178,7 @@ int ml_dsa_sign_internal(ml_dsa_params *params, | |
| uint8_t seedbuf[2*ML_DSA_SEEDBYTES + ML_DSA_TRBYTES + 2*ML_DSA_CRHBYTES]; | ||
| uint8_t *rho, *tr, *key, *mu, *rhoprime; | ||
| uint16_t nonce = 0; | ||
| uint32_t z_invalid, w0_invalid, h_invalid; | ||
jakemas marked this conversation as resolved.
Show resolved
Hide resolved
jakemas marked this conversation as resolved.
Show resolved
Hide resolved
jakemas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| polyvecl mat[ML_DSA_K_MAX], s1, y, z; | ||
| polyveck t0, s2, w1, w0, h; | ||
| ml_dsa_poly cp; | ||
|
|
@@ -248,25 +249,28 @@ int ml_dsa_sign_internal(ml_dsa_params *params, | |
| ml_dsa_polyvecl_invntt_tomont(params, &z); | ||
| ml_dsa_polyvecl_add(params, &z, &z, &y); | ||
| ml_dsa_polyvecl_reduce(params, &z); | ||
| if(ml_dsa_polyvecl_chknorm(params, &z, params->gamma1 - params->beta)) { | ||
| goto rej; | ||
| } | ||
| z_invalid = ml_dsa_polyvecl_chknorm(params, &z, params->gamma1 - params->beta); | ||
|
|
||
| /* FIPS 204: line 21 Check that subtracting cs2 does not change high bits of w and low bits | ||
| * do not reveal secret information */ | ||
| ml_dsa_polyveck_pointwise_poly_montgomery(params, &h, &cp, &s2); | ||
| ml_dsa_polyveck_invntt_tomont(params, &h); | ||
| ml_dsa_polyveck_sub(params, &w0, &w0, &h); | ||
| ml_dsa_polyveck_reduce(params, &w0); | ||
| if(ml_dsa_polyveck_chknorm(params, &w0, params->gamma2 - params->beta)) { | ||
| w0_invalid = ml_dsa_polyveck_chknorm(params, &w0, params->gamma2 - params->beta); | ||
|
|
||
| /* FIPS 204: Algorithm 7 line 23 - Reject if either check fails (constant-time to avoid leaking | ||
| which check failed) */ | ||
| if(z_invalid | w0_invalid) { | ||
|
||
| goto rej; | ||
| } | ||
|
|
||
| /* FIPS 204: line 25 */ | ||
| ml_dsa_polyveck_pointwise_poly_montgomery(params, &h, &cp, &t0); | ||
| ml_dsa_polyveck_invntt_tomont(params, &h); | ||
| ml_dsa_polyveck_reduce(params, &h); | ||
| if(ml_dsa_polyveck_chknorm(params, &h, params->gamma2)) { | ||
| h_invalid = ml_dsa_polyveck_chknorm(params, &h, params->gamma2); | ||
| if(h_invalid) { | ||
| goto rej; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.