diff --git a/src/decaf.rs b/src/decaf.rs index 19d4977..bb73132 100644 --- a/src/decaf.rs +++ b/src/decaf.rs @@ -36,6 +36,7 @@ use collections::boxed::Box; #[cfg(all(feature = "std", feature = "basepoint_table_creation"))] use std::boxed::Box; +use curve; use curve::ExtendedPoint; use curve::EdwardsBasepointTable; use curve::BasepointMult; @@ -304,6 +305,30 @@ impl Debug for DecafPoint { } } +// ------------------------------------------------------------------------ +// Variable-time functions +// ------------------------------------------------------------------------ + +pub mod vartime { + //! Variable-time operations on decaf points, useful for non-secret data. + use super::*; + + /// Given a vector of public scalars and a vector of (possibly secret) + /// points, compute + /// + /// c_1 P_1 + ... + c_n P_n. + /// + /// # Input + /// + /// A vector of `Scalar`s and a vector of `ExtendedPoints`. It is an + /// error to call this function with two vectors of different lengths. + pub fn k_fold_scalar_mult(scalars: &Vec, + points: &Vec) -> DecafPoint { + let extended_points: Vec = points.iter().map(|P| P.0).collect(); + DecafPoint(curve::vartime::k_fold_scalar_mult(scalars, &extended_points)) + } +} + // ------------------------------------------------------------------------ // Tests // ------------------------------------------------------------------------