Skip to main content

Module poly

Module poly 

Source
Expand description

Polynomial-basis binary presentations at degrees 1, 2, 4, and 8.

Polynomial is the construction GF(2)[x] / p(x) for an irreducible degree-N p. The representation, its descriptor, and its generator derive from the polynomial at compile time, so each polynomial is a distinct representation with fully const scalar arithmetic.

ConstantPolynomialConvention
AES0x11BAES/Rijndael; the field GF2P8MULB multiplies natively
RS0x11DIntel ISA-L, klauspost/reedsolomon, QR codes

Any other degree-8 irreducible polynomial is spelled directly, such as Polynomial<0x12D> for Data Matrix or Polynomial<0x187> for the CCSDS Reed–Solomon field. Distinct polynomials are unrelated encodings: a byte has different products under each, so a buffer carries one convention and never two.

use fgf::{AES, Elem, Binary, Polynomial, RS};

// The same bytes multiply differently under the two conventions.
let (a, b) = (0x53, 0xca);
assert_eq!(
    Elem::<Binary<8, Polynomial<AES>>>::from_raw(a)
        .mul(Elem::<Binary<8, Polynomial<AES>>>::from_raw(b))
        .to_raw(),
    0x01
);
assert_eq!(
    Elem::<Binary<8, Polynomial<RS>>>::from_raw(a)
        .mul(Elem::<Binary<8, Polynomial<RS>>>::from_raw(b))
        .to_raw(),
    0x8f
);

// Any irreducible polynomial is a field; its generator is derived.
assert_eq!(
    Elem::<Binary<8, Polynomial<0x12D>>>::GENERATOR.pow(255),
    Elem::<Binary<8, Polynomial<0x12D>>>::ONE
);
ⓘ
// x^8 + 1 = (x + 1)^8 is reducible, so this field does not exist.
let _ = fgf::Elem::<fgf::Binary<8, fgf::Polynomial<0x101>>>::from_raw(1);
ⓘ
// The degree-eight polynomial does not match a degree-four field.
let _ = fgf::Elem::<fgf::Binary<4, fgf::Polynomial<0x11B>>>::from_raw(1);

Structs§

Polynomial
The polynomial-basis representation of GF(2^N) under the reduction polynomial P.

Constants§

AES
The AES/Rijndael polynomial x^8 + x^4 + x^3 + x + 1.
RS
The 0x11D Reed–Solomon convention, x^8 + x^4 + x^3 + x^2 + 1.