Skip to main content

Limbs

Trait Limbs 

Source
pub(crate) trait Limbs:
    Clone
    + AsRef<[Limb]>
    + AsMut<[Limb]>
    + CtEq
    + CtAssign
    + LimbHelpers {
    type Wide: WideLimbs<Self>;

    // Required methods
    fn xgcd(self, other: Self) -> Xgcd<Self>;
    fn div(self, denom: &Self) -> Self;
    fn mul(&self, other: &Self) -> Self::Wide;

    // Provided methods
    fn mul_mod(&self, other: &Self, modulus: &Self) -> Self { ... }
    fn square(&self) -> Self::Wide { ... }
}
Expand description

The required view over a collection of limbs to calculate the c coefficient.

Implementations MUST implement all functions in time constant to the value of the inputs, except for the amount of limbs, unless otherwise stated. Implementations MUST NOT panic for any input which the caller MAY pass.

Required Associated Types§

Source

type Wide: WideLimbs<Self>

A wider container capable of storing the product of any two values representable within this container.

Required Methods§

Source

fn xgcd(self, other: Self) -> Xgcd<Self>

Calculate the GCD d of self, other (as a, b) and the coefficients such that ua + vb = d.

Callers MUST ensure the inputs have the same amount of limbs. Callers MUST NOT pass a = 0 or b = 0.

Implementations MUST return values with the same amount of limbs as the inputs.

Source

fn div(self, denom: &Self) -> Self

Calculate self / denom where denom | self.

Callers MUST ensure the inputs have the same amount of limbs. Callers MUST NOT pass denom = 0.

Implementations MUST return a value with the same amount of limbs as the numerator.

Source

fn mul(&self, other: &Self) -> Self::Wide

Multiply two values into a wide value.

Provided Methods§

Source

fn mul_mod(&self, other: &Self, modulus: &Self) -> Self

Multiply two values modulo modulus.

Callers MUST ensure the inputs have the same amount of limbs. Callers MUST NOT pass modulus = 0.

Implementations MUST support any factors, not just those less than the modulus. Implementations MUST return a value with the same amount of limbs as the modulus.

Source

fn square(&self) -> Self::Wide

Square a value into a wide value.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Limbs for BoxedUint

Available on crate feature alloc only.
Source§

type Wide = BoxedUint

Source§

fn xgcd(self, other: Self) -> Xgcd<Self>

Source§

fn div(self, denom: &Self) -> Self

Source§

fn mul_mod(&self, other: &Self, modulus: &Self) -> Self

Source§

fn mul(&self, other: &Self) -> Self::Wide

Source§

fn square(&self) -> Self::Wide

Source§

impl<const LIMBS: usize, const WIDE_LIMBS: usize> Limbs for Uint<LIMBS>
where Self: Concat<LIMBS, Output = Uint<WIDE_LIMBS>>, Uint<WIDE_LIMBS>: SplitEven<Output = Self>,

Source§

type Wide = <Uint<LIMBS> as Concat<LIMBS>>::Output

Source§

fn xgcd(self, other: Self) -> Xgcd<Self>

Source§

fn div(self, denom: &Self) -> Self

Source§

fn mul_mod(&self, other: &Self, modulus: &Self) -> Self

Source§

fn mul(&self, other: &Self) -> Self::Wide

Source§

fn square(&self) -> Self::Wide

Implementors§