Skip to content

Commit 22374b2

Browse files
committed
Simplify some code
1 parent 37d93c8 commit 22374b2

File tree

3 files changed

+3
-8
lines changed

3 files changed

+3
-8
lines changed

ed448-goldilocks/src/curve/scalar_mul/double_and_add.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ pub(crate) fn double_and_add(point: &ExtendedPoint, s_bits: [bool; 448]) -> Exte
99
// XXX: Would be great if subtle had a From<u32> for Choice. But maybe that is not it's purpose?
1010
for bit in s_bits.into_iter().rev() {
1111
result = result.double();
12-
13-
let mut p = ExtendedPoint::IDENTITY;
14-
p.conditional_assign(point, Choice::from(bit as u8));
15-
result = result.add(&p);
12+
result.conditional_assign(&(result.add(point)), Choice::from(u8::from(bit)));
1613
}
1714

1815
result

ed448-goldilocks/src/field/element.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ impl FieldElement {
476476
let e = b * c;
477477

478478
let mut a = n * e;
479-
a.conditional_negate(!Choice::from(a.0.retrieve().bit(0)) ^ square);
479+
a.conditional_negate(!a.is_negative() ^ square);
480480

481481
let c = e * ONE_MINUS_TWO_D;
482482
let b = c.square();

ed448-goldilocks/src/montgomery/x.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,11 @@ impl ProjectiveMontgomeryXpoint {
265265
/// Double this point
266266
// https://eprint.iacr.org/2020/1338.pdf (2.2)
267267
pub fn double(&self) -> Self {
268-
const C: FieldElement = FieldElement(ConstMontyType::new(&U448::from_u64(39082)));
269-
270268
let v1 = (self.U + self.W).square();
271269
let v2 = (self.U - self.W).square();
272270
let U = v1 * v2;
273271
let v3 = v1 - v2;
274-
let v4 = C * v3;
272+
let v4 = FieldElement::A_PLUS_TWO_OVER_FOUR * v3;
275273
let v5 = v2 + v4;
276274
let W = v3 * v5;
277275

0 commit comments

Comments
 (0)