Trait g2p::GaloisField
source · pub trait GaloisField:
Add<Output = Self>
+ AddAssign
+ Sub<Output = Self>
+ SubAssign
+ Mul<Output = Self>
+ MulAssign
+ Div<Output = Self>
+ DivAssign
+ Copy
+ PartialEq
+ Eq {
const SIZE: usize;
const ZERO: Self;
const ONE: Self;
const GENERATOR: Self;
const MODULUS: G2Poly;
// Provided method
fn pow(self, p: usize) -> Self { ... }
}
Expand description
Common trait for finite fields
All types generated by g2p!
implement this trait.
The trait ensures that all the expected operations of a finite field are implemented.
In addition, some often used constants like ONE
and ZERO
are exported, as well as the more
esoteric GENERATOR
.
Required Associated Constants§
sourceconst GENERATOR: Self
const GENERATOR: Self
A generator of the multiplicative group of a finite field
The powers of this element will generate all non-zero elements of the finite field
use g2p::{GaloisField, g2p};
g2p!(GF4, 2);
let g = GF4::GENERATOR;
assert_ne!(g, GF4::ONE);
assert_ne!(g * g, GF4::ONE);
assert_eq!(g * g * g, GF4::ONE);
Provided Methods§
sourcefn pow(self, p: usize) -> Self
fn pow(self, p: usize) -> Self
Calculate the p-th power of a value
Calculate the value of x to the power p in finite field arithmethic
§Example
use g2p::{GaloisField, g2p};
g2p!(GF16, 4);
let g: GF16 = 2.into();
assert_eq!(g.pow(0), GF16::ONE);
assert_eq!(g.pow(1), g);
assert_eq!(g.pow(2), 4.into());
assert_eq!(g.pow(3), 8.into());
assert_eq!(g.pow(4), 3.into());
Object Safety§
This trait is not object safe.