Skip to content

Commit be15d52

Browse files
committed
primefield: source PrimeField::S from PrimeParams
Uses `crypto-bigint` to compute `S`
1 parent f001b5d commit be15d52

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

primefield/src/monty.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ where
463463
const CAPACITY: u32 = Self::NUM_BITS - 1;
464464
const TWO_INV: Self = Self::from_u64(2).const_invert();
465465
const MULTIPLICATIVE_GENERATOR: Self = Self::from_u64(MOD::MULTIPLICATIVE_GENERATOR);
466-
const S: u32 = compute_s(MOD::PARAMS.modulus().as_ref());
466+
const S: u32 = MOD::PRIME_PARAMS.s().get();
467467
const ROOT_OF_UNITY: Self = Self::MULTIPLICATIVE_GENERATOR.pow_vartime(&MOD::T);
468468
const ROOT_OF_UNITY_INV: Self = Self::ROOT_OF_UNITY.const_invert();
469469
const DELTA: Self = Self::MULTIPLICATIVE_GENERATOR.sqn_vartime(Self::S as usize);
@@ -966,16 +966,10 @@ where
966966
}
967967
}
968968

969-
/// Compute `S = (modulus - 1).trailing_zeros()`
970-
const fn compute_s<const LIMBS: usize>(modulus: &Uint<LIMBS>) -> u32 {
971-
modulus.wrapping_sub(&Uint::ONE).trailing_zeros()
972-
}
973-
974969
/// Compute `t = (modulus - 1) >> S`
975970
pub const fn compute_t<const LIMBS: usize>(modulus: &Uint<LIMBS>) -> Uint<LIMBS> {
976-
modulus
977-
.wrapping_sub(&Uint::ONE)
978-
.unbounded_shr(compute_s(modulus))
971+
let s = modulus.wrapping_sub(&Uint::ONE).trailing_zeros();
972+
modulus.wrapping_sub(&Uint::ONE).unbounded_shr(s)
979973
}
980974

981975
#[cfg(test)]

0 commit comments

Comments
 (0)