Rename multiscalar_mult->multiscalar_mul to match Mul traits

This commit is contained in:
Henry de Valence 2018-03-19 14:28:21 -07:00
parent fc6672ab43
commit c20e09f6cc
3 changed files with 39 additions and 39 deletions

View file

@ -456,7 +456,7 @@ impl EdwardsBasepointTable {
/// Internal multiscalar code. /// Internal multiscalar code.
#[cfg(any(feature = "alloc", feature = "std"))] #[cfg(any(feature = "alloc", feature = "std"))]
pub fn multiscalar_mult<I, J>(scalars: I, points: J) -> edwards::EdwardsPoint pub fn multiscalar_mul<I, J>(scalars: I, points: J) -> edwards::EdwardsPoint
where I: IntoIterator, where I: IntoIterator,
I::Item: Borrow<Scalar>, I::Item: Borrow<Scalar>,
J: IntoIterator, J: IntoIterator,
@ -596,7 +596,7 @@ pub mod vartime {
/// Internal multiscalar function /// Internal multiscalar function
#[cfg(any(feature = "alloc", feature = "std"))] #[cfg(any(feature = "alloc", feature = "std"))]
pub fn multiscalar_mult<I, J>(scalars: I, points: J) -> edwards::EdwardsPoint pub fn multiscalar_mul<I, J>(scalars: I, points: J) -> edwards::EdwardsPoint
where I: IntoIterator, where I: IntoIterator,
I::Item: Borrow<Scalar>, I::Item: Borrow<Scalar>,
J: IntoIterator, J: IntoIterator,
@ -881,7 +881,7 @@ mod test {
} }
#[test] #[test]
fn multiscalar_mult_vs_adding_scalar_mults() { fn multiscalar_mul_vs_adding_scalar_mults() {
let B: ExtendedPoint = constants::ED25519_BASEPOINT_POINT.into(); let B: ExtendedPoint = constants::ED25519_BASEPOINT_POINT.into();
let s1 = Scalar::from_bits([233, 1, 233, 147, 113, 78, 244, 120, 40, 45, 103, 51, 224, 199, 189, 218, 96, 140, 211, 112, 39, 194, 73, 216, 173, 33, 102, 93, 76, 200, 84, 12]); let s1 = Scalar::from_bits([233, 1, 233, 147, 113, 78, 244, 120, 40, 45, 103, 51, 224, 199, 189, 218, 96, 140, 211, 112, 39, 194, 73, 216, 173, 33, 102, 93, 76, 200, 84, 12]);
let s2 = Scalar::from_bits([165, 30, 79, 89, 58, 24, 195, 245, 248, 146, 203, 236, 119, 43, 64, 119, 196, 111, 188, 251, 248, 53, 234, 59, 215, 28, 218, 13, 59, 120, 14, 4]); let s2 = Scalar::from_bits([165, 30, 79, 89, 58, 24, 195, 245, 248, 146, 203, 236, 119, 43, 64, 119, 196, 111, 188, 251, 248, 53, 234, 59, 215, 28, 218, 13, 59, 120, 14, 4]);
@ -891,7 +891,7 @@ mod test {
let R = &(&P1 * &s1) + &(&P2 * &s2); let R = &(&P1 * &s1) + &(&P2 * &s2);
let R_multiscalar = multiscalar_mult(&[s1, s2], &[P1.into(), P2.into()]); let R_multiscalar = multiscalar_mul(&[s1, s2], &[P1.into(), P2.into()]);
assert_eq!(edwards::EdwardsPoint::from(R).compress(), assert_eq!(edwards::EdwardsPoint::from(R).compress(),
R_multiscalar.compress()); R_multiscalar.compress());
@ -901,7 +901,7 @@ mod test {
use super::*; use super::*;
#[test] #[test]
fn multiscalar_mult_vs_adding_scalar_mults() { fn multiscalar_mul_vs_adding_scalar_mults() {
let B: ExtendedPoint = constants::ED25519_BASEPOINT_POINT.into(); let B: ExtendedPoint = constants::ED25519_BASEPOINT_POINT.into();
let s1 = Scalar::from_bits([233, 1, 233, 147, 113, 78, 244, 120, 40, 45, 103, 51, 224, 199, 189, 218, 96, 140, 211, 112, 39, 194, 73, 216, 173, 33, 102, 93, 76, 200, 84, 12]); let s1 = Scalar::from_bits([233, 1, 233, 147, 113, 78, 244, 120, 40, 45, 103, 51, 224, 199, 189, 218, 96, 140, 211, 112, 39, 194, 73, 216, 173, 33, 102, 93, 76, 200, 84, 12]);
let s2 = Scalar::from_bits([165, 30, 79, 89, 58, 24, 195, 245, 248, 146, 203, 236, 119, 43, 64, 119, 196, 111, 188, 251, 248, 53, 234, 59, 215, 28, 218, 13, 59, 120, 14, 4]); let s2 = Scalar::from_bits([165, 30, 79, 89, 58, 24, 195, 245, 248, 146, 203, 236, 119, 43, 64, 119, 196, 111, 188, 251, 248, 53, 234, 59, 215, 28, 218, 13, 59, 120, 14, 4]);
@ -911,7 +911,7 @@ mod test {
let R = &(&P1 * &s1) + &(&P2 * &s2); let R = &(&P1 * &s1) + &(&P2 * &s2);
let R_multiscalar = vartime::multiscalar_mult(&[s1, s2], &[P1.into(), P2.into()]); let R_multiscalar = vartime::multiscalar_mul(&[s1, s2], &[P1.into(), P2.into()]);
assert_eq!(edwards::EdwardsPoint::from(R).compress(), assert_eq!(edwards::EdwardsPoint::from(R).compress(),
R_multiscalar.compress()); R_multiscalar.compress());
@ -1004,7 +1004,7 @@ mod bench {
let B = &constants::ED25519_BASEPOINT_TABLE; let B = &constants::ED25519_BASEPOINT_TABLE;
let points: Vec<_> = scalars.iter().map(|s| B * s).collect(); let points: Vec<_> = scalars.iter().map(|s| B * s).collect();
b.iter(|| multiscalar_mult(&scalars, &points)); b.iter(|| multiscalar_mul(&scalars, &points));
} }
mod vartime { mod vartime {
@ -1031,7 +1031,7 @@ mod bench {
let B = &constants::ED25519_BASEPOINT_TABLE; let B = &constants::ED25519_BASEPOINT_TABLE;
let points: Vec<_> = scalars.iter().map(|s| B * s).collect(); let points: Vec<_> = scalars.iter().map(|s| B * s).collect();
b.iter(|| vartime::multiscalar_mult(&scalars, &points)); b.iter(|| vartime::multiscalar_mul(&scalars, &points));
} }
} }
} }

View file

@ -57,10 +57,10 @@
//! `EdwardsBasepointTable`, which performs constant-time fixed-base //! `EdwardsBasepointTable`, which performs constant-time fixed-base
//! scalar multiplication; //! scalar multiplication;
//! //!
//! * the `edwards::multiscalar_mult` function, which performs //! * the `edwards::multiscalar_mul` function, which performs
//! constant-time variable-base multiscalar multiplication; //! constant-time variable-base multiscalar multiplication;
//! //!
//! * the `edwards::vartime::multiscalar_mult` function, which //! * the `edwards::vartime::multiscalar_mul` function, which
//! performs variable-time variable-base multiscalar multiplication. //! performs variable-time variable-base multiscalar multiplication.
//! //!
//! ## Implementation //! ## Implementation
@ -534,7 +534,7 @@ impl<'a, 'b> Mul<&'b EdwardsPoint> for &'a Scalar {
/// $$ /// $$
/// ///
/// This function has the same behaviour as /// This function has the same behaviour as
/// `vartime::multiscalar_mult` but is constant-time. /// `vartime::multiscalar_mul` but is constant-time.
/// ///
/// It is an error to call this function with two iterators of different lengths. /// It is an error to call this function with two iterators of different lengths.
/// ///
@ -561,12 +561,12 @@ impl<'a, 'b> Mul<&'b EdwardsPoint> for &'a Scalar {
/// ///
/// // A1 = a*P + b*Q + c*R /// // A1 = a*P + b*Q + c*R
/// let abc = [a,b,c]; /// let abc = [a,b,c];
/// let A1 = edwards::multiscalar_mult(&abc, &[P,Q,R]); /// let A1 = edwards::multiscalar_mul(&abc, &[P,Q,R]);
/// // Note: (&abc).into_iter(): Iterator<Item=&Scalar> /// // Note: (&abc).into_iter(): Iterator<Item=&Scalar>
/// ///
/// // A2 = (-a)*P + (-b)*Q + (-c)*R /// // A2 = (-a)*P + (-b)*Q + (-c)*R
/// let minus_abc = abc.iter().map(|x| -x); /// let minus_abc = abc.iter().map(|x| -x);
/// let A2 = edwards::multiscalar_mult(minus_abc, &[P,Q,R]); /// let A2 = edwards::multiscalar_mul(minus_abc, &[P,Q,R]);
/// // Note: minus_abc.into_iter(): Iterator<Item=Scalar> /// // Note: minus_abc.into_iter(): Iterator<Item=Scalar>
/// ///
/// assert_eq!(A1.compress(), (-A2).compress()); /// assert_eq!(A1.compress(), (-A2).compress());
@ -574,7 +574,7 @@ impl<'a, 'b> Mul<&'b EdwardsPoint> for &'a Scalar {
// XXX later when we do more fancy multiscalar mults, we can delegate // XXX later when we do more fancy multiscalar mults, we can delegate
// based on the iter's size hint -- hdevalence // based on the iter's size hint -- hdevalence
#[cfg(any(feature = "alloc", feature = "std"))] #[cfg(any(feature = "alloc", feature = "std"))]
pub fn multiscalar_mult<I, J>(scalars: I, points: J) -> EdwardsPoint pub fn multiscalar_mul<I, J>(scalars: I, points: J) -> EdwardsPoint
where I: IntoIterator, where I: IntoIterator,
I::Item: Borrow<Scalar>, I::Item: Borrow<Scalar>,
J: IntoIterator, J: IntoIterator,
@ -584,7 +584,7 @@ pub fn multiscalar_mult<I, J>(scalars: I, points: J) -> EdwardsPoint
#[cfg(all(feature="nightly", all(feature="avx2_backend", target_feature="avx2")))] { #[cfg(all(feature="nightly", all(feature="avx2_backend", target_feature="avx2")))] {
use backend::avx2::edwards as edwards_avx2; use backend::avx2::edwards as edwards_avx2;
edwards_avx2::multiscalar_mult(scalars, points) edwards_avx2::multiscalar_mul(scalars, points)
} }
// Otherwise, proceed as normal: // Otherwise, proceed as normal:
#[cfg(not(all(feature="nightly", all(feature="avx2_backend", target_feature="avx2"))))] { #[cfg(not(all(feature="nightly", all(feature="avx2_backend", target_feature="avx2"))))] {
@ -909,7 +909,7 @@ pub mod vartime {
/// $$ /// $$
/// ///
/// This function has the same behaviour as /// This function has the same behaviour as
/// `edwards::multiscalar_mult` but operates on non-secret data. /// `edwards::multiscalar_mul` but operates on non-secret data.
/// ///
/// It is an error to call this function with two iterators of different lengths. /// It is an error to call this function with two iterators of different lengths.
/// ///
@ -936,12 +936,12 @@ pub mod vartime {
/// ///
/// // A1 = a*P + b*Q + c*R /// // A1 = a*P + b*Q + c*R
/// let abc = [a,b,c]; /// let abc = [a,b,c];
/// let A1 = edwards::vartime::multiscalar_mult(&abc, &[P,Q,R]); /// let A1 = edwards::vartime::multiscalar_mul(&abc, &[P,Q,R]);
/// // Note: (&abc).into_iter(): Iterator<Item=&Scalar> /// // Note: (&abc).into_iter(): Iterator<Item=&Scalar>
/// ///
/// // A2 = (-a)*P + (-b)*Q + (-c)*R /// // A2 = (-a)*P + (-b)*Q + (-c)*R
/// let minus_abc = abc.iter().map(|x| -x); /// let minus_abc = abc.iter().map(|x| -x);
/// let A2 = edwards::vartime::multiscalar_mult(minus_abc, &[P,Q,R]); /// let A2 = edwards::vartime::multiscalar_mul(minus_abc, &[P,Q,R]);
/// // Note: minus_abc.into_iter(): Iterator<Item=Scalar> /// // Note: minus_abc.into_iter(): Iterator<Item=Scalar>
/// ///
/// assert_eq!(A1.compress(), (-A2).compress()); /// assert_eq!(A1.compress(), (-A2).compress());
@ -949,7 +949,7 @@ pub mod vartime {
// XXX later when we do more fancy multiscalar mults, we can delegate // XXX later when we do more fancy multiscalar mults, we can delegate
// based on the iter's size hint -- hdevalence // based on the iter's size hint -- hdevalence
#[cfg(any(feature = "alloc", feature = "std"))] #[cfg(any(feature = "alloc", feature = "std"))]
pub fn multiscalar_mult<I, J>(scalars: I, points: J) -> EdwardsPoint pub fn multiscalar_mul<I, J>(scalars: I, points: J) -> EdwardsPoint
where I: IntoIterator, where I: IntoIterator,
I::Item: Borrow<Scalar>, I::Item: Borrow<Scalar>,
J: IntoIterator, J: IntoIterator,
@ -959,7 +959,7 @@ pub mod vartime {
#[cfg(all(feature="nightly", all(feature="avx2_backend", target_feature="avx2")))] { #[cfg(all(feature="nightly", all(feature="avx2_backend", target_feature="avx2")))] {
use backend::avx2::edwards as edwards_avx2; use backend::avx2::edwards as edwards_avx2;
edwards_avx2::vartime::multiscalar_mult(scalars, points) edwards_avx2::vartime::multiscalar_mul(scalars, points)
} }
// Otherwise, proceed as normal: // Otherwise, proceed as normal:
#[cfg(not(all(feature="nightly", all(feature="avx2_backend", target_feature="avx2"))))] { #[cfg(not(all(feature="nightly", all(feature="avx2_backend", target_feature="avx2"))))] {
@ -1363,9 +1363,9 @@ mod test {
} }
#[test] #[test]
fn multiscalar_mult_vs_ed25519py() { fn multiscalar_mul_vs_ed25519py() {
let A = A_TIMES_BASEPOINT.decompress().unwrap(); let A = A_TIMES_BASEPOINT.decompress().unwrap();
let result = vartime::multiscalar_mult( let result = vartime::multiscalar_mul(
&[A_SCALAR, B_SCALAR], &[A_SCALAR, B_SCALAR],
&[A, constants::ED25519_BASEPOINT_POINT] &[A, constants::ED25519_BASEPOINT_POINT]
); );
@ -1373,13 +1373,13 @@ mod test {
} }
#[test] #[test]
fn multiscalar_mult_vartime_vs_consttime() { fn multiscalar_mul_vartime_vs_consttime() {
let A = A_TIMES_BASEPOINT.decompress().unwrap(); let A = A_TIMES_BASEPOINT.decompress().unwrap();
let result_vartime = vartime::multiscalar_mult( let result_vartime = vartime::multiscalar_mul(
&[A_SCALAR, B_SCALAR], &[A_SCALAR, B_SCALAR],
&[A, constants::ED25519_BASEPOINT_POINT] &[A, constants::ED25519_BASEPOINT_POINT]
); );
let result_consttime = multiscalar_mult( let result_consttime = multiscalar_mul(
&[A_SCALAR, B_SCALAR], &[A_SCALAR, B_SCALAR],
&[A, constants::ED25519_BASEPOINT_POINT] &[A, constants::ED25519_BASEPOINT_POINT]
); );
@ -1526,7 +1526,7 @@ mod bench {
let B = &constants::ED25519_BASEPOINT_TABLE; let B = &constants::ED25519_BASEPOINT_TABLE;
let points: Vec<_> = scalars.iter().map(|s| B * &s).collect(); let points: Vec<_> = scalars.iter().map(|s| B * &s).collect();
b.iter(|| multiscalar_mult(&scalars, &points)); b.iter(|| multiscalar_mul(&scalars, &points));
} }
mod vartime { mod vartime {
@ -1556,7 +1556,7 @@ mod bench {
// //
// Since this is a variable-time function, this means the // Since this is a variable-time function, this means the
// benchmark is only useful as a ballpark measurement. // benchmark is only useful as a ballpark measurement.
b.iter(|| vartime::multiscalar_mult(&scalars, &points)); b.iter(|| vartime::multiscalar_mul(&scalars, &points));
} }
} }
} }

View file

@ -78,10 +78,10 @@
//! `RistrettoBasepointTable`, which performs constant-time fixed-base //! `RistrettoBasepointTable`, which performs constant-time fixed-base
//! scalar multiplication; //! scalar multiplication;
//! //!
//! * the `ristretto::multiscalar_mult` function, which performs //! * the `ristretto::multiscalar_mul` function, which performs
//! constant-time variable-base multiscalar multiplication; //! constant-time variable-base multiscalar multiplication;
//! //!
//! * the `ristretto::vartime::multiscalar_mult` function, which //! * the `ristretto::vartime::multiscalar_mul` function, which
//! performs variable-time variable-base multiscalar multiplication. //! performs variable-time variable-base multiscalar multiplication.
//! //!
//! ## Random Points and Hashing to Ristretto //! ## Random Points and Hashing to Ristretto
@ -1059,7 +1059,7 @@ define_mul_variants!(LHS = Scalar, RHS = RistrettoPoint, Output = RistrettoPoint
/// $$ /// $$
/// ///
/// This function has the same behaviour as /// This function has the same behaviour as
/// `vartime::multiscalar_mult` but is constant-time. /// `vartime::multiscalar_mul` but is constant-time.
/// ///
/// It is an error to call this function with two iterators of different lengths. /// It is an error to call this function with two iterators of different lengths.
/// ///
@ -1086,25 +1086,25 @@ define_mul_variants!(LHS = Scalar, RHS = RistrettoPoint, Output = RistrettoPoint
/// ///
/// // A1 = a*P + b*Q + c*R /// // A1 = a*P + b*Q + c*R
/// let abc = [a,b,c]; /// let abc = [a,b,c];
/// let A1 = ristretto::multiscalar_mult(&abc, &[P,Q,R]); /// let A1 = ristretto::multiscalar_mul(&abc, &[P,Q,R]);
/// // Note: (&abc).into_iter(): Iterator<Item=&Scalar> /// // Note: (&abc).into_iter(): Iterator<Item=&Scalar>
/// ///
/// // A2 = (-a)*P + (-b)*Q + (-c)*R /// // A2 = (-a)*P + (-b)*Q + (-c)*R
/// let minus_abc = abc.iter().map(|x| -x); /// let minus_abc = abc.iter().map(|x| -x);
/// let A2 = ristretto::multiscalar_mult(minus_abc, &[P,Q,R]); /// let A2 = ristretto::multiscalar_mul(minus_abc, &[P,Q,R]);
/// // Note: minus_abc.into_iter(): Iterator<Item=Scalar> /// // Note: minus_abc.into_iter(): Iterator<Item=Scalar>
/// ///
/// assert_eq!(A1.compress(), (-A2).compress()); /// assert_eq!(A1.compress(), (-A2).compress());
/// ``` /// ```
#[cfg(any(feature = "alloc", feature = "std"))] #[cfg(any(feature = "alloc", feature = "std"))]
pub fn multiscalar_mult<I, J>(scalars: I, points: J) -> RistrettoPoint pub fn multiscalar_mul<I, J>(scalars: I, points: J) -> RistrettoPoint
where I: IntoIterator, where I: IntoIterator,
I::Item: Borrow<Scalar>, I::Item: Borrow<Scalar>,
J: IntoIterator, J: IntoIterator,
J::Item: Borrow<RistrettoPoint>, J::Item: Borrow<RistrettoPoint>,
{ {
let extended_points = points.into_iter().map(|P| P.borrow().0); let extended_points = points.into_iter().map(|P| P.borrow().0);
RistrettoPoint(edwards::multiscalar_mult(scalars, extended_points)) RistrettoPoint(edwards::multiscalar_mul(scalars, extended_points))
} }
/// A precomputed table of multiples of a basepoint, used to accelerate /// A precomputed table of multiples of a basepoint, used to accelerate
@ -1210,7 +1210,7 @@ pub mod vartime {
/// $$ /// $$
/// ///
/// This function has the same behaviour as /// This function has the same behaviour as
/// `vartime::multiscalar_mult` but is constant-time. /// `vartime::multiscalar_mul` but is constant-time.
/// ///
/// It is an error to call this function with two iterators of different lengths. /// It is an error to call this function with two iterators of different lengths.
/// ///
@ -1237,25 +1237,25 @@ pub mod vartime {
/// ///
/// // A1 = a*P + b*Q + c*R /// // A1 = a*P + b*Q + c*R
/// let abc = [a,b,c]; /// let abc = [a,b,c];
/// let A1 = ristretto::vartime::multiscalar_mult(&abc, &[P,Q,R]); /// let A1 = ristretto::vartime::multiscalar_mul(&abc, &[P,Q,R]);
/// // Note: (&abc).into_iter(): Iterator<Item=&Scalar> /// // Note: (&abc).into_iter(): Iterator<Item=&Scalar>
/// ///
/// // A2 = (-a)*P + (-b)*Q + (-c)*R /// // A2 = (-a)*P + (-b)*Q + (-c)*R
/// let minus_abc = abc.iter().map(|x| -x); /// let minus_abc = abc.iter().map(|x| -x);
/// let A2 = ristretto::vartime::multiscalar_mult(minus_abc, &[P,Q,R]); /// let A2 = ristretto::vartime::multiscalar_mul(minus_abc, &[P,Q,R]);
/// // Note: minus_abc.into_iter(): Iterator<Item=Scalar> /// // Note: minus_abc.into_iter(): Iterator<Item=Scalar>
/// ///
/// assert_eq!(A1.compress(), (-A2).compress()); /// assert_eq!(A1.compress(), (-A2).compress());
/// ``` /// ```
#[cfg(any(feature = "alloc", feature = "std"))] #[cfg(any(feature = "alloc", feature = "std"))]
pub fn multiscalar_mult<I, J>(scalars: I, points: J) -> RistrettoPoint pub fn multiscalar_mul<I, J>(scalars: I, points: J) -> RistrettoPoint
where I: IntoIterator, where I: IntoIterator,
I::Item: Borrow<Scalar>, I::Item: Borrow<Scalar>,
J: IntoIterator, J: IntoIterator,
J::Item: Borrow<RistrettoPoint>, J::Item: Borrow<RistrettoPoint>,
{ {
let extended_points = points.into_iter().map(|P| P.borrow().0); let extended_points = points.into_iter().map(|P| P.borrow().0);
RistrettoPoint(edwards::vartime::multiscalar_mult(scalars, extended_points)) RistrettoPoint(edwards::vartime::multiscalar_mul(scalars, extended_points))
} }
} }