Skip to main content

WnafBase

Struct WnafBase 

Source
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>

Source

pub fn new(base: &G) -> Self

Computes a window table for the given base with the specified window size W.

Source

pub fn init_from_base(&mut self, base: &G)

Initialize an already allocated window table from the given base.

Source

pub fn multiscalar_mul<'a, I>(pairs: I) -> G
where G::Scalar: WnafSize, I: Clone + Iterator<Item = (&'a Self, &'a WnafScalar<G::Scalar, W>)>,

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.

Trait Implementations§

Source§

impl<G: Clone + Group, W: Clone + WindowSize> Clone for WnafBase<G, W>
where W::TableSize: Clone,

Source§

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

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<G: Debug + Group, W: Debug + WindowSize> Debug for WnafBase<G, W>
where W::TableSize: Debug,

Source§

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

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

impl<G: Group, W: WindowSize> Default for WnafBase<G, W>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<G, W> Mul<&WnafScalar<<G as Group>::Scalar, W>> for &WnafBase<G, W>
where G: Group<Scalar: WnafSize>, W: WindowSize,

Source§

type Output = G

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<G, W> Mul<&WnafScalar<<G as Group>::Scalar, W>> for WnafBase<G, W>
where G: Group<Scalar: WnafSize>, W: WindowSize,

Source§

type Output = G

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<G, W> Mul<WnafScalar<<G as Group>::Scalar, W>> for WnafBase<G, W>
where G: Group<Scalar: WnafSize>, W: WindowSize,

Source§

type Output = G

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more

Auto Trait Implementations§

§

impl<G, W> Freeze for WnafBase<G, W>
where <<W as WindowSize>::TableSize as ArraySize>::ArrayType<G>: Freeze,

§

impl<G, W> RefUnwindSafe for WnafBase<G, W>

§

impl<G, W> Send for WnafBase<G, W>

§

impl<G, W> Sync for WnafBase<G, W>

§

impl<G, W> Unpin for WnafBase<G, W>
where <<W as WindowSize>::TableSize as ArraySize>::ArrayType<G>: Unpin,

§

impl<G, W> UnsafeUnpin for WnafBase<G, W>

§

impl<G, W> UnwindSafe for WnafBase<G, W>

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§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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>,

Source§

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.