Skip to content

Commit 02e61ef

Browse files
committed
Re-use Scalar::halve() to compute div_by_four()
1 parent 7fc6f6a commit 02e61ef

File tree

2 files changed

+1
-21
lines changed

2 files changed

+1
-21
lines changed

ed448-goldilocks/src/edwards/extended.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,7 @@ impl EdwardsPoint {
334334
/// Generic scalar multiplication to compute s*P
335335
pub fn scalar_mul(&self, scalar: &EdwardsScalar) -> Self {
336336
// Compute floor(s/4)
337-
let mut scalar_div_four = *scalar;
338-
scalar_div_four.div_by_four();
337+
let scalar_div_four = scalar.halve().halve();
339338

340339
// Use isogeny and dual isogeny to compute phi^-1((s/4) * phi(P))
341340
variable_base(&self.to_twisted(), &scalar_div_four).to_untwisted()

ed448-goldilocks/src/field/scalar.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -658,25 +658,6 @@ impl<C: CurveWithScalar> Scalar<C> {
658658
self.scalar.is_zero()
659659
}
660660

661-
/// Divides a scalar by four without reducing mod p
662-
/// This is used in the 2-isogeny when mapping points from Ed448-Goldilocks
663-
/// to Twisted-Goldilocks
664-
pub(crate) fn div_by_four(&mut self) {
665-
let s_mod_4 = self[0] & 3;
666-
667-
let s_plus_l = self.scalar + ORDER;
668-
let s_plus_2l = s_plus_l + ORDER;
669-
let s_plus_3l = s_plus_2l + ORDER;
670-
671-
self.scalar.conditional_assign(&s_plus_l, s_mod_4.ct_eq(&1));
672-
self.scalar
673-
.conditional_assign(&s_plus_2l, s_mod_4.ct_eq(&2));
674-
self.scalar
675-
.conditional_assign(&s_plus_3l, s_mod_4.ct_eq(&3));
676-
677-
self.scalar >>= 2;
678-
}
679-
680661
// This method was modified from Curve25519-Dalek codebase. [scalar.rs]
681662
// We start with 14 u32s and convert them to 56 u8s.
682663
// We then use the code copied from Dalek to convert the 56 u8s to radix-16 and re-center the coefficients to be between [-16,16)

0 commit comments

Comments
 (0)