Skip to content
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

Make cx_math_is_zero run in constant time #823

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions lib_cxng/include/lcx_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -568,13 +568,11 @@ DEPRECATED static inline void cx_math_next_prime(uint8_t *r, uint32_t len)
*/
static inline bool cx_math_is_zero(const uint8_t *a, size_t len)
{
uint32_t i;
for (i = 0; i < len; i++) {
if (a[i] != 0) {
return 0;
}
uint8_t acc = 0; // accumulate all the bytes in order to run in constant time
for (size_t i = 0; i < len; i++) {
acc |= a[i];
}
return 1;
return acc == 0;
}

#endif // HAVE_MATH
Expand Down
Loading