mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-04 20:24:10 +00:00
Fix a negate-with-overflow edgecase by widening before computation.
This fixes a bug in the Pippenger implementation reported by Fernando Krell and diagnosed by Oleg Andreev. The problem is that at the largest problem sizes (using w=8), the signed digits fill the value range of an i8, and so doing computation on them to calculate the bucket index can hit an overflow. This was not caught in CI because the test suite didn't check all problem sizes; tests for these sizes which expose this bug were added in the previous commit.
This commit is contained in:
parent
6fe93564cd
commit
5f1d73bca0
2 changed files with 4 additions and 2 deletions
|
|
@ -125,7 +125,8 @@ impl VartimeMultiscalarMul for Pippenger {
|
|||
// Note: if we add support for precomputed lookup tables,
|
||||
// we'll be adding/subtracting point premultiplied by `digits[i]` to buckets[0].
|
||||
for (digits, pt) in scalars_points.iter() {
|
||||
let digit = digits[digit_index];
|
||||
// Widen digit so that we don't run into edge cases when w=8.
|
||||
let digit = digits[digit_index] as i16;
|
||||
if digit > 0 {
|
||||
let b = (digit - 1) as usize;
|
||||
buckets[b] = (&buckets[b] + pt).to_extended();
|
||||
|
|
|
|||
|
|
@ -82,7 +82,8 @@ impl VartimeMultiscalarMul for Pippenger {
|
|||
// Note: if we add support for precomputed lookup tables,
|
||||
// we'll be adding/subtractiong point premultiplied by `digits[i]` to buckets[0].
|
||||
for (digits, pt) in scalars_points.iter() {
|
||||
let digit = digits[digit_index];
|
||||
// Widen digit so that we don't run into edge cases when w=8.
|
||||
let digit = digits[digit_index] as i16;
|
||||
if digit > 0 {
|
||||
let b = (digit - 1) as usize;
|
||||
buckets[b] = &buckets[b] + pt;
|
||||
|
|
|
|||
Loading…
Reference in a new issue