bdk_chain::bitcoin::bech32::primitives::checksum

Trait PackedFe32

pub trait PackedFe32:
    Copy
    + PartialEq
    + Eq
    + BitXor<Output = Self> {
    const ONE: Self;
    const WIDTH: usize = _;

    // Required methods
    fn unpack(&self, n: usize) -> u8;
    fn mul_by_x_then_add(&mut self, degree: usize, add: u8) -> u8;
}
Expand description

Trait describing an integer type which can be used as a “packed” sequence of Fe32s.

This is implemented for u32, u64 and u128, as a way to treat these primitive types as packed coefficients of polynomials over GF32 (up to some maximal degree, of course).

This is useful because then multiplication by x reduces to simply left-shifting by 5, and addition of entire polynomials can be done by xor.

Required Associated Constants§

const ONE: Self

The one constant, for which stdlib provides no existing trait.

Provided Associated Constants§

const WIDTH: usize = _

The number of fe32s that can fit into the type; computed as floor(bitwidth / 5).

Required Methods§

fn unpack(&self, n: usize) -> u8

Extracts the coefficient of the x^n from the packed polynomial.

fn mul_by_x_then_add(&mut self, degree: usize, add: u8) -> u8

Multiply the polynomial by x, drop its highest coefficient (and return it), and add a new field element to the now-0 constant coefficient.

Takes the degree of the polynomial as an input; for checksum applications this should basically always be Checksum::CHECKSUM_WIDTH.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

§

impl PackedFe32 for u32

§

const ONE: u32 = 1u32

§

fn unpack(&self, n: usize) -> u8

§

fn mul_by_x_then_add(&mut self, degree: usize, add: u8) -> u8

§

impl PackedFe32 for u64

§

const ONE: u64 = 1u64

§

fn unpack(&self, n: usize) -> u8

§

fn mul_by_x_then_add(&mut self, degree: usize, add: u8) -> u8

§

impl PackedFe32 for u128

§

const ONE: u128 = 1u128

§

fn unpack(&self, n: usize) -> u8

§

fn mul_by_x_then_add(&mut self, degree: usize, add: u8) -> u8

Implementors§

§

impl PackedFe32 for PackedNull

§

const ONE: PackedNull = PackedNull