#finite-fields #polynomial #gf #galois #field #galois-field #cryptography

no-std g2poly

Primitive implementation of polynomials over the field GF(2)

7 releases (3 stable)

1.1.0 Aug 12, 2024
1.0.1 Jan 17, 2023
0.4.0 May 25, 2019
0.2.0 Apr 2, 2019
0.1.0 Dec 25, 2018

#573 in Algorithms

Download history 27751/week @ 2024-07-17 33385/week @ 2024-07-24 19700/week @ 2024-07-31 24108/week @ 2024-08-07 18349/week @ 2024-08-14 19752/week @ 2024-08-21 19583/week @ 2024-08-28 24483/week @ 2024-09-04 18784/week @ 2024-09-11 23071/week @ 2024-09-18 23032/week @ 2024-09-25 23868/week @ 2024-10-02 21858/week @ 2024-10-09 29391/week @ 2024-10-16 29242/week @ 2024-10-23 19920/week @ 2024-10-30

106,098 downloads per month
Used in 34 crates (2 directly)

MIT/Apache

21KB
317 lines

g2poly

A small library to handle polynomials of degree < 64 over the finite field GF(2).

The main motivation for this library is generating finite fields of the form GF(2^p). Elements of GF(2^p) can be expressed as polynomials over GF(2) with degree < p. These finite fields are used in cryptographic algorithms as well as error detecting / correcting codes.

Documentation

Example

use g2poly;

let a = g2poly::G2Poly(0b10011);
assert_eq!(format!("{}", a), "G2Poly { x^4 + x + 1 }");
let b = g2poly::G2Poly(0b1);
assert_eq!(a + b, g2poly::G2Poly(0b10010));

// Since products could overflow in u64, the product is defined as a u128
assert_eq!(a * a, g2poly::G2PolyProd(0b100000101));

// This can be reduced using another polynomial
let s = a * a % g2poly::G2Poly(0b1000000);
assert_eq!(s, g2poly::G2Poly(0b101));

License

// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms.

No runtime deps