Trait bech32::primitives::checksum::PackedFe32
source · pub trait PackedFe32: Copy + PartialEq + Eq + BitXor<Self, 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§
Provided Associated Constants§
Required Methods§
sourcefn unpack(&self, n: usize) -> u8
fn unpack(&self, n: usize) -> u8
Extracts the coefficient of the x^n from the packed polynomial.
sourcefn mul_by_x_then_add(&mut self, degree: usize, add: u8) -> u8
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
.