Improve performance of IncompletePoint addition

We only need to track the occurrence of any edge cases, and we can do so
without expensive inversions at every addition step, by instead
performing the checks on the projective form directly.
This commit is contained in:
Jack Grigg 2021-04-22 11:59:55 +12:00
parent 3cadb7bb48
commit 09e70cb6e3
1 changed files with 9 additions and 10 deletions

View File

@ -1,7 +1,7 @@
use std::ops::Add;
use group::Curve;
use pasta_curves::{arithmetic::CurveAffine, pallas};
use group::Group;
use pasta_curves::pallas;
use subtle::{ConstantTimeEq, CtOption};
/// P {⊥}
@ -33,14 +33,13 @@ impl Add for IncompletePoint {
rhs.0.and_then(|q| {
// 0 ⊹ 0 = ⊥
// 0 ⊹ P = ⊥
p.to_affine().coordinates().and_then(|c_p| {
// P ⊹ 0 = ⊥
q.to_affine().coordinates().and_then(|c_q| {
// (x, y) ⊹ (x', y') = ⊥ if x == x'
// (x, y) ⊹ (x', y') = (x, y) + (x', y') if x != x'
CtOption::new(p + q, !c_p.x().ct_eq(c_q.x()))
})
})
// P ⊹ 0 = ⊥
// (x, y) ⊹ (x', y') = ⊥ if x == x'
// (x, y) ⊹ (x', y') = (x, y) + (x', y') if x != x'
CtOption::new(
p + q,
!(p.is_identity() | q.is_identity() | p.ct_eq(&q) | p.ct_eq(&-q)),
)
})
}))
}