mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-04 20:24:10 +00:00
Rename mult_by_pow_2 to mul_by_pow_2 for consistency
This commit is contained in:
parent
c20e09f6cc
commit
8de3d7576a
4 changed files with 18 additions and 18 deletions
|
|
@ -237,7 +237,7 @@ impl ExtendedPoint {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn mult_by_pow_2(&self, k: u32) -> ExtendedPoint {
|
||||
pub fn mul_by_pow_2(&self, k: u32) -> ExtendedPoint {
|
||||
let mut tmp: ExtendedPoint = *self;
|
||||
for _ in 0..k {
|
||||
tmp = tmp.double();
|
||||
|
|
@ -396,7 +396,7 @@ impl<'a, 'b> Mul<&'b Scalar> for &'a ExtendedPoint {
|
|||
let mut Q = ExtendedPoint::identity();
|
||||
for i in (0..64).rev() {
|
||||
// Q = 16*Q
|
||||
Q = Q.mult_by_pow_2(4);
|
||||
Q = Q.mul_by_pow_2(4);
|
||||
// Q += P*s_i
|
||||
Q = &Q + &lookup_table.select(scalar_digits[i]);
|
||||
}
|
||||
|
|
@ -420,7 +420,7 @@ impl<'a, 'b> Mul<&'b Scalar> for &'a EdwardsBasepointTable {
|
|||
P = &P + &tables[i/2].select(a[i]);
|
||||
}
|
||||
|
||||
P = P.mult_by_pow_2(4);
|
||||
P = P.mul_by_pow_2(4);
|
||||
|
||||
for i in (0..64).filter(|x| x % 2 == 0) {
|
||||
P = &P + &tables[i/2].select(a[i]);
|
||||
|
|
@ -448,7 +448,7 @@ impl EdwardsBasepointTable {
|
|||
for i in 0..32 {
|
||||
// P = (16^2)^i * B
|
||||
table.0[i] = LookupTable::from(P);
|
||||
P = P.mult_by_pow_2(8);
|
||||
P = P.mul_by_pow_2(8);
|
||||
}
|
||||
table
|
||||
}
|
||||
|
|
@ -507,7 +507,7 @@ pub fn multiscalar_mul<I, J>(scalars: I, points: J) -> edwards::EdwardsPoint
|
|||
let mut Q = ExtendedPoint::identity();
|
||||
// XXX this algorithm makes no effort to be cache-aware; maybe it could be improved?
|
||||
for j in (0..64).rev() {
|
||||
Q = Q.mult_by_pow_2(4);
|
||||
Q = Q.mul_by_pow_2(4);
|
||||
let it = scalar_digits.iter().zip(lookup_tables.iter());
|
||||
for (s_i, lookup_table_i) in it {
|
||||
// Q = Q + s_{i,j} * P_i
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ mod test {
|
|||
#[test]
|
||||
fn test_eight_torsion() {
|
||||
for i in 0..8 {
|
||||
let Q = constants::EIGHT_TORSION[i].mult_by_pow_2(3);
|
||||
let Q = constants::EIGHT_TORSION[i].mul_by_pow_2(3);
|
||||
assert!(Q.is_valid());
|
||||
assert!(Q.is_identity());
|
||||
}
|
||||
|
|
@ -114,7 +114,7 @@ mod test {
|
|||
#[test]
|
||||
fn test_four_torsion() {
|
||||
for i in (0..8).filter(|i| i % 2 == 0) {
|
||||
let Q = constants::EIGHT_TORSION[i].mult_by_pow_2(2);
|
||||
let Q = constants::EIGHT_TORSION[i].mul_by_pow_2(2);
|
||||
assert!(Q.is_valid());
|
||||
assert!(Q.is_identity());
|
||||
}
|
||||
|
|
@ -123,7 +123,7 @@ mod test {
|
|||
#[test]
|
||||
fn test_two_torsion() {
|
||||
for i in (0..8).filter(|i| i % 4 == 0) {
|
||||
let Q = constants::EIGHT_TORSION[i].mult_by_pow_2(1);
|
||||
let Q = constants::EIGHT_TORSION[i].mul_by_pow_2(1);
|
||||
assert!(Q.is_valid());
|
||||
assert!(Q.is_identity());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -505,7 +505,7 @@ impl<'a, 'b> Mul<&'b Scalar> for &'a EdwardsPoint {
|
|||
let mut Q = EdwardsPoint::identity();
|
||||
for i in (0..64).rev() {
|
||||
// Q <-- 16*Q
|
||||
Q = Q.mult_by_pow_2(4);
|
||||
Q = Q.mul_by_pow_2(4);
|
||||
// Q <-- Q + P * s_i
|
||||
Q = (&Q + &lookup_table.select(scalar_digits[i])).to_extended()
|
||||
}
|
||||
|
|
@ -634,7 +634,7 @@ pub fn multiscalar_mul<I, J>(scalars: I, points: J) -> EdwardsPoint
|
|||
let mut Q = EdwardsPoint::identity();
|
||||
// XXX this impl makes no effort to be cache-aware; maybe it could be improved?
|
||||
for j in (0..64).rev() {
|
||||
Q = Q.mult_by_pow_2(4);
|
||||
Q = Q.mul_by_pow_2(4);
|
||||
let it = scalar_digits.iter().zip(lookup_tables.iter());
|
||||
for (s_i, lookup_table_i) in it {
|
||||
// R_i = s_{i,j} * P_i
|
||||
|
|
@ -694,7 +694,7 @@ impl EdwardsBasepointTable {
|
|||
P = (&P + &tables[i/2].select(a[i])).to_extended();
|
||||
}
|
||||
|
||||
P = P.mult_by_pow_2(4);
|
||||
P = P.mul_by_pow_2(4);
|
||||
|
||||
for i in (0..64).filter(|x| x % 2 == 0) {
|
||||
P = (&P + &tables[i/2].select(a[i])).to_extended();
|
||||
|
|
@ -734,7 +734,7 @@ impl EdwardsBasepointTable {
|
|||
for i in 0..32 {
|
||||
// P = (16^2)^i * B
|
||||
table.0[i] = LookupTable::from(&P);
|
||||
P = P.mult_by_pow_2(8);
|
||||
P = P.mul_by_pow_2(8);
|
||||
}
|
||||
table
|
||||
}
|
||||
|
|
@ -752,11 +752,11 @@ impl EdwardsBasepointTable {
|
|||
impl EdwardsPoint {
|
||||
/// Multiply by the cofactor: return \\([8]P\\).
|
||||
pub fn mult_by_cofactor(&self) -> EdwardsPoint {
|
||||
self.mult_by_pow_2(3)
|
||||
self.mul_by_pow_2(3)
|
||||
}
|
||||
|
||||
/// Compute \\([2\^k] P \\) by successive doublings. Requires \\( k > 0 \\).
|
||||
pub(crate) fn mult_by_pow_2(&self, k: u32) -> EdwardsPoint {
|
||||
pub(crate) fn mul_by_pow_2(&self, k: u32) -> EdwardsPoint {
|
||||
debug_assert!( k > 0 );
|
||||
let mut r: CompletedPoint;
|
||||
let mut s = self.to_projective();
|
||||
|
|
@ -1276,10 +1276,10 @@ mod test {
|
|||
constants::ED25519_BASEPOINT_COMPRESSED);
|
||||
}
|
||||
|
||||
/// Test computing 16*basepoint vs mult_by_pow_2(4)
|
||||
/// Test computing 16*basepoint vs mul_by_pow_2(4)
|
||||
#[test]
|
||||
fn basepoint16_vs_mult_by_pow_2_4() {
|
||||
let bp16 = constants::ED25519_BASEPOINT_POINT.mult_by_pow_2(4);
|
||||
fn basepoint16_vs_mul_by_pow_2_4() {
|
||||
let bp16 = constants::ED25519_BASEPOINT_POINT.mul_by_pow_2(4);
|
||||
assert_eq!(bp16.compress(), BASE16_CMPRSSD);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1327,7 +1327,7 @@ mod test {
|
|||
let bp_recaf = bp_compressed_ristretto.decompress().unwrap().0;
|
||||
// Check that bp_recaf differs from bp by a point of order 4
|
||||
let diff = &constants::RISTRETTO_BASEPOINT_POINT.0 - &bp_recaf;
|
||||
let diff4 = diff.mult_by_pow_2(2);
|
||||
let diff4 = diff.mul_by_pow_2(2);
|
||||
assert_eq!(diff4.compress(), CompressedEdwardsY::identity());
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue