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§

source§

impl<G: Group, const WINDOW_SIZE: usize> WnafBase<G, WINDOW_SIZE>

source

pub fn new(base: G) -> Self

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

Trait Implementations§

source§

impl<G: Clone + Group, const WINDOW_SIZE: usize> Clone for WnafBase<G, WINDOW_SIZE>

source§

fn clone(&self) -> WnafBase<G, WINDOW_SIZE>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<G: Debug + Group, const WINDOW_SIZE: usize> Debug for WnafBase<G, WINDOW_SIZE>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<G: Group, const WINDOW_SIZE: usize> Mul<&WnafScalar<<G as Group>::Scalar, WINDOW_SIZE>> for &WnafBase<G, WINDOW_SIZE>

§

type Output = G

The resulting type after applying the * operator.
source§

fn mul(self, rhs: &WnafScalar<G::Scalar, WINDOW_SIZE>) -> Self::Output

Performs the * operation. Read more

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.