Skip to content

Commit

Permalink
Merge pull request #823 from LedgerHQ/is_zero
Browse files Browse the repository at this point in the history
Make cx_math_is_zero run in constant time
  • Loading branch information
bigspider authored Nov 14, 2024
2 parents 98eaa57 + fa3f9b8 commit fe9d203
Showing 1 changed file with 4 additions and 6 deletions.
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

0 comments on commit fe9d203

Please sign in to comment.