[−][src]Trait curve25519_dalek::traits::MultiscalarMul
A trait for constant-time multiscalar multiplication without precomputation.
Associated Types
Required methods
fn multiscalar_mul<I, J>(scalars: I, points: J) -> Self::Point where
I: IntoIterator,
I::Item: Borrow<Scalar>,
J: IntoIterator,
J::Item: Borrow<Self::Point>,
[−]
I: IntoIterator,
I::Item: Borrow<Scalar>,
J: IntoIterator,
J::Item: Borrow<Self::Point>,
Given an iterator of (possibly secret) scalars and an iterator of public points, compute
It is an error to call this function with two iterators of different lengths.
Examples
The trait bound aims for maximum flexibility: the inputs must be
convertable to iterators (I: IntoIter
), and the iterator's items
must be Borrow<Scalar>
(or Borrow<Point>
), to allow
iterators returning either Scalar
s or &Scalar
s.
use curve25519_dalek::constants; use curve25519_dalek::traits::MultiscalarMul; use curve25519_dalek::ristretto::RistrettoPoint; use curve25519_dalek::scalar::Scalar; // Some scalars let a = Scalar::from(87329482u64); let b = Scalar::from(37264829u64); let c = Scalar::from(98098098u64); // Some points let P = constants::RISTRETTO_BASEPOINT_POINT; let Q = P + P; let R = P + Q; // A1 = a*P + b*Q + c*R let abc = [a,b,c]; let A1 = RistrettoPoint::multiscalar_mul(&abc, &[P,Q,R]); // Note: (&abc).into_iter(): Iterator<Item=&Scalar> // A2 = (-a)*P + (-b)*Q + (-c)*R let minus_abc = abc.iter().map(|x| -x); let A2 = RistrettoPoint::multiscalar_mul(minus_abc, &[P,Q,R]); // Note: minus_abc.into_iter(): Iterator<Item=Scalar> assert_eq!(A1.compress(), (-A2).compress());
Implementors
impl MultiscalarMul for Straus
[src][−]
type Point = EdwardsPoint
fn multiscalar_mul<I, J>(scalars: I, points: J) -> EdwardsPoint where
I: IntoIterator,
I::Item: Borrow<Scalar>,
J: IntoIterator,
J::Item: Borrow<EdwardsPoint>,
[src][−]
I: IntoIterator,
I::Item: Borrow<Scalar>,
J: IntoIterator,
J::Item: Borrow<EdwardsPoint>,
Constant-time Straus using a fixed window of size .
Our goal is to compute
For each point , precompute a lookup table of
For each scalar , compute its radix- signed digits , i.e., with . Since , we can retrieve from the lookup table with a conditional negation: using signed digits halves the required table size.
Then as in the single-base fixed window case, we have so each can be computed by alternately adding a precomputed multiple of and repeatedly doubling.
Now consider the two-dimensional sum The sum of the left-hand column is the result ; by computing the two-dimensional sum on the right column-wise, top-to-bottom, then right-to-left, we need to multiply by only once per column, sharing the doublings across all of the input points.
impl MultiscalarMul for EdwardsPoint
[src][−]
type Point = EdwardsPoint
fn multiscalar_mul<I, J>(scalars: I, points: J) -> EdwardsPoint where
I: IntoIterator,
I::Item: Borrow<Scalar>,
J: IntoIterator,
J::Item: Borrow<EdwardsPoint>,
[src]
I: IntoIterator,
I::Item: Borrow<Scalar>,
J: IntoIterator,
J::Item: Borrow<EdwardsPoint>,
impl MultiscalarMul for RistrettoPoint
[src][−]
type Point = RistrettoPoint
fn multiscalar_mul<I, J>(scalars: I, points: J) -> RistrettoPoint where
I: IntoIterator,
I::Item: Borrow<Scalar>,
J: IntoIterator,
J::Item: Borrow<RistrettoPoint>,
[src]
I: IntoIterator,
I::Item: Borrow<Scalar>,
J: IntoIterator,
J::Item: Borrow<RistrettoPoint>,