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 Wnaf
s were computed with the same window
size, allowing the result to be computed infallibly.
Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<G, const WINDOW_SIZE: usize> Freeze for WnafBase<G, WINDOW_SIZE>
impl<G, const WINDOW_SIZE: usize> RefUnwindSafe for WnafBase<G, WINDOW_SIZE>where
G: RefUnwindSafe,
impl<G, const WINDOW_SIZE: usize> Send for WnafBase<G, WINDOW_SIZE>
impl<G, const WINDOW_SIZE: usize> Sync for WnafBase<G, WINDOW_SIZE>
impl<G, const WINDOW_SIZE: usize> Unpin for WnafBase<G, WINDOW_SIZE>where
G: Unpin,
impl<G, const WINDOW_SIZE: usize> UnwindSafe for WnafBase<G, WINDOW_SIZE>where
G: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)