Skip to content

Commit 55b2586

Browse files
committed
Re-use Scalar::halve() to compute div_by_four()
1 parent b0bb83e commit 55b2586

File tree

2 files changed

+3
-16
lines changed

2 files changed

+3
-16
lines changed

ed448-goldilocks/src/edwards/extended.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,8 +553,7 @@ impl EdwardsPoint {
553553
/// Generic scalar multiplication to compute s*P
554554
pub fn scalar_mul(&self, scalar: &EdwardsScalar) -> Self {
555555
// Compute floor(s/4)
556-
let mut scalar_div_four = *scalar;
557-
scalar_div_four.div_by_four();
556+
let scalar_div_four = scalar.div_by_four();
558557

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

ed448-goldilocks/src/field/scalar.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -661,20 +661,8 @@ impl<C: CurveWithScalar> Scalar<C> {
661661
/// Divides a scalar by four without reducing mod p
662662
/// This is used in the 2-isogeny when mapping points from Ed448-Goldilocks
663663
/// 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;
664+
pub(crate) fn div_by_four(&self) -> Self {
665+
self.halve().halve()
678666
}
679667

680668
// This method was modified from Curve25519-Dalek codebase. [scalar.rs]

0 commit comments

Comments
 (0)