pub trait VartimePrecomputedMultiscalarMul: Sized {
type Point: Clone;
// Required methods
fn new<I>(static_points: I) -> Self
where I: IntoIterator,
I::Item: Borrow<Self::Point>;
fn optional_mixed_multiscalar_mul<I, J, K>(
&self,
static_scalars: I,
dynamic_scalars: J,
dynamic_points: K
) -> Option<Self::Point>
where I: IntoIterator,
I::Item: Borrow<Scalar>,
J: IntoIterator,
J::Item: Borrow<Scalar>,
K: IntoIterator<Item = Option<Self::Point>>;
// Provided methods
fn vartime_multiscalar_mul<I>(&self, static_scalars: I) -> Self::Point
where I: IntoIterator,
I::Item: Borrow<Scalar> { ... }
fn vartime_mixed_multiscalar_mul<I, J, K>(
&self,
static_scalars: I,
dynamic_scalars: J,
dynamic_points: K
) -> Self::Point
where I: IntoIterator,
I::Item: Borrow<Scalar>,
J: IntoIterator,
J::Item: Borrow<Scalar>,
K: IntoIterator,
K::Item: Borrow<Self::Point> { ... }
}
Expand description
A trait for variable-time multiscalar multiplication with precomputation.
A general multiscalar multiplication with precomputation can be written as $$ Q = a_1 A_1 + \cdots + a_n A_n + b_1 B_1 + \cdots + b_m B_m, $$ where the \(B_i\) are static points, for which precomputation is possible, and the \(A_j\) are dynamic points, for which precomputation is not possible.
This trait has three methods for performing this computation:
-
Self::vartime_multiscalar_mul
, which handles the special case where \(n = 0\) and there are no dynamic points; -
Self::vartime_mixed_multiscalar_mul
, which takes the dynamic points as already-validatedPoint
s and is infallible; -
Self::optional_mixed_multiscalar_mul
, which takes the dynamic points asOption<Point>
s and returns anOption<Point>
, allowing decompression to be composed into the input iterators.
All methods require that the lengths of the input iterators be
known and matching, as if they were ExactSizeIterator
s. (It
does not require ExactSizeIterator
only because that trait is
broken).
Required Associated Types§
Required Methods§
sourcefn new<I>(static_points: I) -> Selfwhere
I: IntoIterator,
I::Item: Borrow<Self::Point>,
fn new<I>(static_points: I) -> Selfwhere I: IntoIterator, I::Item: Borrow<Self::Point>,
Given the static points \( B_i \), perform precomputation and return the precomputation data.
sourcefn optional_mixed_multiscalar_mul<I, J, K>(
&self,
static_scalars: I,
dynamic_scalars: J,
dynamic_points: K
) -> Option<Self::Point>where
I: IntoIterator,
I::Item: Borrow<Scalar>,
J: IntoIterator,
J::Item: Borrow<Scalar>,
K: IntoIterator<Item = Option<Self::Point>>,
fn optional_mixed_multiscalar_mul<I, J, K>( &self, static_scalars: I, dynamic_scalars: J, dynamic_points: K ) -> Option<Self::Point>where I: IntoIterator, I::Item: Borrow<Scalar>, J: IntoIterator, J::Item: Borrow<Scalar>, K: IntoIterator<Item = Option<Self::Point>>,
Given static_scalars
, an iterator of public scalars
\(b_i\), dynamic_scalars
, an iterator of public scalars
\(a_i\), and dynamic_points
, an iterator of points
\(A_i\), compute
$$
Q = a_1 A_1 + \cdots + a_n A_n + b_1 B_1 + \cdots + b_m B_m,
$$
where the \(B_j\) are the points that were supplied to new
.
If any of the dynamic points were None
, return None
.
It is an error to call this function with iterators of inconsistent lengths.
This function is particularly useful when verifying statements
involving compressed points. Accepting Option<Point>
allows
inlining point decompression into the multiscalar call,
avoiding the need for temporary buffers.
Provided Methods§
sourcefn vartime_multiscalar_mul<I>(&self, static_scalars: I) -> Self::Pointwhere
I: IntoIterator,
I::Item: Borrow<Scalar>,
fn vartime_multiscalar_mul<I>(&self, static_scalars: I) -> Self::Pointwhere I: IntoIterator, I::Item: Borrow<Scalar>,
Given static_scalars
, an iterator of public scalars
\(b_i\), compute
$$
Q = b_1 B_1 + \cdots + b_m B_m,
$$
where the \(B_j\) are the points that were supplied to new
.
It is an error to call this function with iterators of inconsistent lengths.
The trait bound aims for maximum flexibility: the input must
be convertable to iterators (I: IntoIter
), and the
iterator’s items must be Borrow<Scalar>
, to allow iterators
returning either Scalar
s or &Scalar
s.
sourcefn vartime_mixed_multiscalar_mul<I, J, K>(
&self,
static_scalars: I,
dynamic_scalars: J,
dynamic_points: K
) -> Self::Pointwhere
I: IntoIterator,
I::Item: Borrow<Scalar>,
J: IntoIterator,
J::Item: Borrow<Scalar>,
K: IntoIterator,
K::Item: Borrow<Self::Point>,
fn vartime_mixed_multiscalar_mul<I, J, K>( &self, static_scalars: I, dynamic_scalars: J, dynamic_points: K ) -> Self::Pointwhere I: IntoIterator, I::Item: Borrow<Scalar>, J: IntoIterator, J::Item: Borrow<Scalar>, K: IntoIterator, K::Item: Borrow<Self::Point>,
Given static_scalars
, an iterator of public scalars
\(b_i\), dynamic_scalars
, an iterator of public scalars
\(a_i\), and dynamic_points
, an iterator of points
\(A_i\), compute
$$
Q = a_1 A_1 + \cdots + a_n A_n + b_1 B_1 + \cdots + b_m B_m,
$$
where the \(B_j\) are the points that were supplied to new
.
It is an error to call this function with iterators of inconsistent lengths.
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.