From ddaf602a0956abe60f9bb9ac27251ce9814096e7 Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Mon, 31 Jul 2017 18:40:11 -0700 Subject: [PATCH] Add multiscalar_mult to Decaf. --- src/decaf.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/decaf.rs b/src/decaf.rs index 15517c7..a6e809b 100644 --- a/src/decaf.rs +++ b/src/decaf.rs @@ -577,6 +577,24 @@ impl<'a, 'b> Mul<&'b DecafPoint> for &'a Scalar { } } +/// Given a vector of (possibly secret) scalars and a vector of +/// (possibly secret) points, compute `c_1 P_1 + ... + c_n P_n`. +/// +/// This function has the same behaviour as +/// `vartime::multiscalar_mult` but is constant-time. +/// +/// # Input +/// +/// A vector of `Scalar`s and a vector of `DecafPoints`. It is an +/// error to call this function with two vectors of different lengths. +#[cfg(any(feature = "alloc", feature = "std"))] +pub fn multiscalar_mult<'a, 'b, I, J>(scalars: I, points: J) -> DecafPoint + where I: IntoIterator, + J: IntoIterator, +{ + let extended_points = points.into_iter().map(|P| &P.0); + DecafPoint(curve::multiscalar_mult(scalars, extended_points)) +} /// Precomputation #[derive(Clone)]