pub struct WnafBase<G: Group, W: WindowSize> { /* private fields */ }Expand description
Fixed window table for a group element, precomputed to improve scalar multiplication speed.
By fixing the window size at compile time, we are able to support fully no_alloc
stack-allocated operation, and also use the type system to ensure WnafBase and
WnafScalar are using the same window size.
Precomputations are guaranteed to only occur once per base and once per scalar. Users should select their window size based on how long the bases are expected to live; a larger window size will consume more memory and take longer to precompute, but result in faster scalar multiplications.
§Examples
type MyWnafBase = WnafBase<ProjectivePoint, U5, U8>;
type MyWnafScalar = WnafScalar<Scalar, U5, U129>;
let base = MyWnafBase::new(ProjectivePoint::GENERATOR);
let scalar = MyWnafScalar::new(&s);
let result = base * scalar;Note that this pattern requires specifying a fixed window size W. This is necessary to ensure
in the type system that the base and scalar Wnafs were computed with the same window
size, allowing the result to be computed infallibly.
Implementations§
Source§impl<G: Group, W: WindowSize> WnafBase<G, W>
impl<G: Group, W: WindowSize> WnafBase<G, W>
Sourcepub fn new(base: &G) -> Self
pub fn new(base: &G) -> Self
Computes a window table for the given base with the specified window size W.
Sourcepub fn init_from_base(&mut self, base: &G)
pub fn init_from_base(&mut self, base: &G)
Initialize an already allocated window table from the given base.
Sourcepub fn multiscalar_mul<'a, I>(pairs: I) -> G
pub fn multiscalar_mul<'a, I>(pairs: I) -> G
Perform a multiscalar multiplication.
Computes a sum-of-products aA + bB + ... in variable time with wNAF multi-exponentiation
using the interleaved window method, also known as Straus’s method.