Skip to content

Commit

Permalink
Reduce side channels from single-bit reads
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdettman authored and sipa committed Dec 30, 2021
1 parent c727086 commit 80ba4c5
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/ecmult_gen_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,15 @@ static void secp256k1_ecmult_gen(const secp256k1_ecmult_gen_context *ctx, secp25
* ((block*COMB_TEETH + tooth)*COMB_SPACING + comb_off) of recoded. */
uint32_t bits = 0, sign, abs, index, tooth;
for (tooth = 0; tooth < COMB_TEETH; ++tooth) {
uint32_t bit = (recoded[bit_pos >> 5] >> (bit_pos & 0x1f)) & 1;
bits |= bit << tooth;
/* Instead of reading individual bits here to construct bits, build up
* the result by xoring shifted reads together. In every iteration, one
* additional bit is made correct, starting at the bottom. The bits
* above that contain junk. This reduces leakage from single bits. See
* https://www.usenix.org/system/files/conference/usenixsecurity18/sec18-alam.pdf
*/
uint32_t bitdata = recoded[bit_pos >> 5] >> (bit_pos & 0x1f);
bits &= ~(1 << tooth);
bits ^= bitdata << tooth;
bit_pos += COMB_SPACING;
}

Expand Down

0 comments on commit 80ba4c5

Please sign in to comment.