Skip to main content

Limbs

Trait Limbs 

Source
pub(crate) trait Limbs:
    AsRef<[Limb]>
    + AsMut<[Limb]>
    + CtEq
    + Zero
    + BitOps {
    // Required method
    fn like_zero(&self) -> Self;

    // Provided method
    fn swap(&mut self, b: &mut Self, choice: Choice) { ... }
}
Expand description

A collection of limbs and associated helper methods.

The provided reduction algorithm dances along the Limb boundaries, performance requiring correct decision of when to terminate execution of a given function. This API unifies Uint and BoxedUint (in a way Integer appeared ineligible for) while providing the niche methods required for performance.

Implementations MAY iterate up to the limbs argument (for performance) or MAY ignore it. Callers MUST NOT expect that if they specify a limbs argument, operations will only occur to that subset of limbs, and any results are undefined when any non-included limbs are non-zero. Callers MUST NOT specify more limbs than the value has.

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.

A long-term goal is to replace this entirely for just UintRef. Currently, the reduction algorithm still requires allocating one scratch variable however, making this non-immediate.

Required Methods§

Source

fn like_zero(&self) -> Self

The number but with precision equal to self.

This is equivalent to crypto_bigint::Zero::zero_like but avoids requiring Self: Clone. We do not want to bound Self: Clone for performance reasons. Specifically, it’s a goal of the reduction algorithm to not allocate at all (for performance reasons), this one function being necessary in one spot and the current sole exception.

Provided Methods§

Source

fn swap(&mut self, b: &mut Self, choice: Choice)

Swap the values of self and b if choice is true.

This is a basic helper as there is no UintRef::ct_swap.

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§

fn like_zero(&self) -> Self

Source§

impl<const LIMBS: usize> Limbs for Uint<LIMBS>

Source§

fn like_zero(&self) -> Self

Implementors§