Add Decaf wrapper for k-fold vartime

This commit is contained in:
Henry de Valence 2017-05-03 17:39:06 -07:00
parent 5100ba4a07
commit a479b627a8

View file

@ -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<Scalar>,
points: &Vec<DecafPoint>) -> DecafPoint {
let extended_points: Vec<ExtendedPoint> = points.iter().map(|P| P.0).collect();
DecafPoint(curve::vartime::k_fold_scalar_mult(scalars, &extended_points))
}
}
// ------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------