Trait PackedFe32

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

Source

const ONE: Self

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

Provided Associated Constants§

Source

const WIDTH: usize = _

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

Required Methods§

Source

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

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

Source

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§

Source§

impl PackedFe32 for u32

Source§

const ONE: u32 = 1u32

Source§

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

Source§

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

Source§

impl PackedFe32 for u64

Source§

const ONE: u64 = 1u64

Source§

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

Source§

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

Source§

impl PackedFe32 for u128

Source§

const ONE: u128 = 1u128

Source§

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

Source§

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

Implementors§