Struct group::WnafBase

source ·
pub struct WnafBase<G: Group, const WINDOW_SIZE: usize> { /* private fields */ }
Expand description

A fixed window table for a group element, precomputed to improve the speed of scalar multiplication.

This struct is designed for usage patterns that have long-term cached bases and/or scalars, or Cartesian products of bases and scalars. The Wnaf API enables one or the other to be cached, but requires either the base window tables or the scalar w-NAF forms to be computed repeatedly on the fly, which can become a significant performance issue for some use cases.

WnafBase and WnafScalar enable an alternative trade-off: by fixing the window size at compile time, the 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

use group::{WnafBase, WnafScalar};

let wnaf_bases: Vec<_> = bases.into_iter().map(WnafBase::<_, 4>::new).collect();
let wnaf_scalars: Vec<_> = scalars.iter().map(WnafScalar::new).collect();
let results: Vec<_> = wnaf_bases
    .iter()
    .flat_map(|base| wnaf_scalars.iter().map(|scalar| base * scalar))
    .collect();

Note that this pattern requires specifying a fixed window size (unlike previous patterns that picked a suitable window size internally). 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§

Computes a window table for the given base with the specified WINDOW_SIZE.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.