-
Notifications
You must be signed in to change notification settings - Fork 139
ML-DSA constant-time hardening for caddq, poly_chknorm, decompose #2602
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
Changes from all commits
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 |
---|---|---|
|
@@ -52,7 +52,8 @@ int32_t ml_dsa_reduce32(int32_t a) { | |
* Returns r. | ||
**************************************************/ | ||
int32_t ml_dsa_caddq(int32_t a) { | ||
a += (a >> 31) & ML_DSA_Q; | ||
// a = a < 0 ? a + Q : a; | ||
a = constant_time_select_int(constant_time_msb_w(a), a + ML_DSA_Q, a); | ||
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 'constant_time_select_int'; ISO C99 and later do not support implicit function declarations [clang-diagnostic-implicit-function-declaration] a = constant_time_select_int(constant_time_msb_w(a), a + ML_DSA_Q, a);
^ |
||
return a; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,17 +44,20 @@ int32_t ml_dsa_decompose(ml_dsa_params *params, int32_t *a0, int32_t a) { | |
|
||
int32_t a1; | ||
|
||
a1 = (a + 127) >> 7; | ||
a1 = (a + 127) >> 7; | ||
if (params->gamma2 == (ML_DSA_Q-1)/32) { | ||
a1 = (a1*1025 + (1 << 21)) >> 22; | ||
a1 &= 15; | ||
} | ||
if (params->gamma2 == (ML_DSA_Q-1)/88) { | ||
} else if (params->gamma2 == (ML_DSA_Q-1)/88) { | ||
a1 = (a1*11275 + (1 << 23)) >> 24; | ||
a1 ^= ((43 - a1) >> 31) & a1; | ||
// a1 = 43 < a1 ? 0 : a1; | ||
a1 = constant_time_select_int(constant_time_msb_w(43 - a1), 0, a1); | ||
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 'constant_time_msb_w'; ISO C99 and later do not support implicit function declarations [clang-diagnostic-implicit-function-declaration] a1 = constant_time_select_int(constant_time_msb_w(43 - a1), 0, a1);
^ 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 'constant_time_select_int'; ISO C99 and later do not support implicit function declarations [clang-diagnostic-implicit-function-declaration] a1 = constant_time_select_int(constant_time_msb_w(43 - a1), 0, a1);
^ |
||
} | ||
*a0 = a - a1*2*params->gamma2; | ||
*a0 -= (((ML_DSA_Q-1)/2 - *a0) >> 31) & ML_DSA_Q; | ||
|
||
*a0 = a - a1*2*params->gamma2; | ||
// a0 = (Q-1)/2 < a0 ? a0 - Q : a0; | ||
*a0 = constant_time_select_int(constant_time_msb_w((ML_DSA_Q-1)/2 - *a0), | ||
*a0 - ML_DSA_Q, *a0); | ||
return a1; | ||
} | ||
|
||
|
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: call to undeclared function 'constant_time_msb_w'; ISO C99 and later do not support implicit function declarations [clang-diagnostic-implicit-function-declaration]