pub struct FpExt<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS>where
MOD: ConstPrimeMontyParams<LIMBS>,
P: IrreduciblePoly<MOD, LIMBS, M>,
TSCONSTS: TonelliShanksConstants<MOD, LIMBS, M, N>,{
pub coeffs: [FpElement<MOD, LIMBS>; M],
/* private fields */
}Expand description
An element of the extension field $\mathbb{F}_{p^M} = \mathbb{F}_p[x] / (f(x))$.
P is a zero-size marker type implementing IrreduciblePoly.
M is the extension degree (number of base-field coefficients stored).
N is the number limbs needed to store p^M
Fields§
§coeffs: [FpElement<MOD, LIMBS>; M]Coefficients in ascending degree, that is coeffs[i] is
the coefficient of $x^i$ (zero indexed).
Implementations§
Source§impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> FpExt<MOD, LIMBS, M, N, P, TSCONSTS>where
MOD: ConstPrimeMontyParams<LIMBS>,
P: IrreduciblePoly<MOD, LIMBS, M>,
TSCONSTS: TonelliShanksConstants<MOD, LIMBS, M, N>,
impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> FpExt<MOD, LIMBS, M, N, P, TSCONSTS>where
MOD: ConstPrimeMontyParams<LIMBS>,
P: IrreduciblePoly<MOD, LIMBS, M>,
TSCONSTS: TonelliShanksConstants<MOD, LIMBS, M, N>,
Trait Implementations§
Source§impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> Add for FpExt<MOD, LIMBS, M, N, P, TSCONSTS>where
MOD: ConstPrimeMontyParams<LIMBS>,
P: IrreduciblePoly<MOD, LIMBS, M>,
TSCONSTS: TonelliShanksConstants<MOD, LIMBS, M, N>,
impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> Add for FpExt<MOD, LIMBS, M, N, P, TSCONSTS>where
MOD: ConstPrimeMontyParams<LIMBS>,
P: IrreduciblePoly<MOD, LIMBS, M>,
TSCONSTS: TonelliShanksConstants<MOD, LIMBS, M, N>,
Source§impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> Clone for FpExt<MOD, LIMBS, M, N, P, TSCONSTS>where
MOD: ConstPrimeMontyParams<LIMBS>,
P: IrreduciblePoly<MOD, LIMBS, M>,
TSCONSTS: TonelliShanksConstants<MOD, LIMBS, M, N>,
impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> Clone for FpExt<MOD, LIMBS, M, N, P, TSCONSTS>where
MOD: ConstPrimeMontyParams<LIMBS>,
P: IrreduciblePoly<MOD, LIMBS, M>,
TSCONSTS: TonelliShanksConstants<MOD, LIMBS, M, N>,
Source§impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> ConditionallySelectable for FpExt<MOD, LIMBS, M, N, P, TSCONSTS>where
MOD: ConstPrimeMontyParams<LIMBS>,
P: IrreduciblePoly<MOD, LIMBS, M>,
TSCONSTS: TonelliShanksConstants<MOD, LIMBS, M, N>,
impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> ConditionallySelectable for FpExt<MOD, LIMBS, M, N, P, TSCONSTS>where
MOD: ConstPrimeMontyParams<LIMBS>,
P: IrreduciblePoly<MOD, LIMBS, M>,
TSCONSTS: TonelliShanksConstants<MOD, LIMBS, M, N>,
Source§fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self
Source§fn conditional_assign(&mut self, other: &Self, choice: Choice)
fn conditional_assign(&mut self, other: &Self, choice: Choice)
Source§fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)
fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)
self and other if choice == 1; otherwise,
reassign both unto themselves. Read moreSource§impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> ConstantTimeEq for FpExt<MOD, LIMBS, M, N, P, TSCONSTS>where
MOD: ConstPrimeMontyParams<LIMBS>,
P: IrreduciblePoly<MOD, LIMBS, M>,
TSCONSTS: TonelliShanksConstants<MOD, LIMBS, M, N>,
impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> ConstantTimeEq for FpExt<MOD, LIMBS, M, N, P, TSCONSTS>where
MOD: ConstPrimeMontyParams<LIMBS>,
P: IrreduciblePoly<MOD, LIMBS, M>,
TSCONSTS: TonelliShanksConstants<MOD, LIMBS, M, N>,
Source§impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> Debug for FpExt<MOD, LIMBS, M, N, P, TSCONSTS>where
MOD: ConstPrimeMontyParams<LIMBS>,
P: IrreduciblePoly<MOD, LIMBS, M>,
TSCONSTS: TonelliShanksConstants<MOD, LIMBS, M, N>,
FpElement<MOD, LIMBS>: Debug,
impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> Debug for FpExt<MOD, LIMBS, M, N, P, TSCONSTS>where
MOD: ConstPrimeMontyParams<LIMBS>,
P: IrreduciblePoly<MOD, LIMBS, M>,
TSCONSTS: TonelliShanksConstants<MOD, LIMBS, M, N>,
FpElement<MOD, LIMBS>: Debug,
Source§impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> Default for FpExt<MOD, LIMBS, M, N, P, TSCONSTS>where
MOD: ConstPrimeMontyParams<LIMBS>,
P: IrreduciblePoly<MOD, LIMBS, M>,
TSCONSTS: TonelliShanksConstants<MOD, LIMBS, M, N>,
impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> Default for FpExt<MOD, LIMBS, M, N, P, TSCONSTS>where
MOD: ConstPrimeMontyParams<LIMBS>,
P: IrreduciblePoly<MOD, LIMBS, M>,
TSCONSTS: TonelliShanksConstants<MOD, LIMBS, M, N>,
Source§impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> Display for FpExt<MOD, LIMBS, M, N, P, TSCONSTS>where
MOD: ConstPrimeMontyParams<LIMBS>,
P: IrreduciblePoly<MOD, LIMBS, M>,
TSCONSTS: TonelliShanksConstants<MOD, LIMBS, M, N>,
FpElement<MOD, LIMBS>: Display,
Shows the element as $a_0 + a_1 x + a_2 x^2 + …$ with zero
coefficients suppressed. The zero element prints as 0.
impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> Display for FpExt<MOD, LIMBS, M, N, P, TSCONSTS>where
MOD: ConstPrimeMontyParams<LIMBS>,
P: IrreduciblePoly<MOD, LIMBS, M>,
TSCONSTS: TonelliShanksConstants<MOD, LIMBS, M, N>,
FpElement<MOD, LIMBS>: Display,
Shows the element as $a_0 + a_1 x + a_2 x^2 + …$ with zero
coefficients suppressed. The zero element prints as 0.
Source§impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> FieldFromRepr for FpExt<MOD, LIMBS, M, N, P, TSCONSTS>where
MOD: ConstPrimeMontyParams<LIMBS>,
P: IrreduciblePoly<MOD, LIMBS, M>,
TSCONSTS: TonelliShanksConstants<MOD, LIMBS, M, N>,
impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> FieldFromRepr for FpExt<MOD, LIMBS, M, N, P, TSCONSTS>where
MOD: ConstPrimeMontyParams<LIMBS>,
P: IrreduciblePoly<MOD, LIMBS, M>,
TSCONSTS: TonelliShanksConstants<MOD, LIMBS, M, N>,
Source§impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> FieldOps for FpExt<MOD, LIMBS, M, N, P, TSCONSTS>where
MOD: ConstPrimeMontyParams<LIMBS>,
P: IrreduciblePoly<MOD, LIMBS, M>,
TSCONSTS: TonelliShanksConstants<MOD, LIMBS, M, N>,
impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> FieldOps for FpExt<MOD, LIMBS, M, N, P, TSCONSTS>where
MOD: ConstPrimeMontyParams<LIMBS>,
P: IrreduciblePoly<MOD, LIMBS, M>,
TSCONSTS: TonelliShanksConstants<MOD, LIMBS, M, N>,
Source§fn mul(&self, rhs: &Self) -> Self
fn mul(&self, rhs: &Self) -> Self
Schoolbook multiplication followed by reduction modulo $f(x)$.
Product has degree $\leq 2M−2$, then each high-degree term is replaced using $x^M \equiv −\sum_j \texttt{modulus}[j] x^j$ until all degrees are below $M$.
Source§fn invert(&self) -> CtOption<Self>
fn invert(&self) -> CtOption<Self>
Inversion via polynomial extended GCD.
Finds $s$ such that $\texttt{self} \times s \equiv 1 \pmod{f}$
by computing $\gcd(\texttt{self}, f) = g$ (a nonzero constant
if self is nonzero) and then returning $s g^{-1} \pmod{f}$.
Source§fn frobenius(&self) -> Self
fn frobenius(&self) -> Self
φ_p(a) = a^p — the p-power Frobenius endomorphism.
Computed via square-and-multiply using the characteristic p retrieved from the base field.
Source§fn norm(&self) -> Self
fn norm(&self) -> Self
N_{Fp^M/Fp}(a) = ∏_{i=0}^{M-1} φ_p^i(a) — product of all Galois conjugates.
The result lies in Fp (all higher coefficients are 0), but is returned
embedded in Fp^M for uniformity with the FieldOps signature.
Source§fn trace(&self) -> Self
fn trace(&self) -> Self
Tr_{Fp^M/Fp}(a) = Σ_{i=0}^{M-1} φ_p^i(a) — sum of all Galois conjugates.
Like norm, the result lies in Fp but is returned embedded in Fp^M.
Source§fn sqrt(&self) -> CtOption<Self>
fn sqrt(&self) -> CtOption<Self>
Tonelli–Shanks squareroot algorithm
Implementation of the Tonelli–Shanks square root algorithm. Requires only a factorisation as $p^M - 1 = 2^K N$ so can compute this at compile time by truncating zeros.
§Arguments
&self- An element of Fp^M (type: &self)
§Returns
self^(1/2) a choice of squareroot (type: Self)
Source§fn inverse_and_sqrt(&self) -> (CtOption<Self>, CtOption<Self>)
fn inverse_and_sqrt(&self) -> (CtOption<Self>, CtOption<Self>)
Source§fn inv_sqrt(&self) -> CtOption<Self>
fn inv_sqrt(&self) -> CtOption<Self>
Inverse of squareroot of self in 1 exponentiation
Computes 1/sqrt(self) using the trick from Mike Scott’s “Tricks of the trade” article Section 2 https://eprint.iacr.org/2020/1497
§Arguments
&self- Description of &self (type: self)
§Returns
The inverse of the squareroot of self (type: CtOption<Self>)
Source§fn invertme_sqrtother(&self, rhs: &Self) -> (CtOption<Self>, CtOption<Self>)
fn invertme_sqrtother(&self, rhs: &Self) -> (CtOption<Self>, CtOption<Self>)
Inverse of self and squareroot of rhs in 1 exponentiation
Computes 1/self and rhs.sqrt() simulaineously using the
trick from Mike Scott’s “Tricks of the trade” article Section
2 https://eprint.iacr.org/2020/1497
§Returns
The inverse of self and square root fo rhs. Theq former is
none if and only if self is nonzero and the latter is not
none if and only if there exists a squareroot of rhs in FpM
(type: (CtOption<Self>, CtOption<Self>))
Source§fn sqrt_ratio(&self, rhs: &Self) -> CtOption<Self>
fn sqrt_ratio(&self, rhs: &Self) -> CtOption<Self>
Computes the squareroot of a ratio self/rhs
Computes sqrt(self/rhs) in one exponentiation using the
trick from Mike Scott’s “Tricks of the trade” article Section
2 https://eprint.iacr.org/2020/1497
§Arguments
&self- Element of FpM (type: self)rhs- Element of FpM (type: &Self)
§Returns
The squareroot of the ratio self/rhs is not none if and only
if rhs is invertible and the ratio has an FpM squareroot
(type: CtOption<Self>)
Source§fn legendre(&self) -> i8
fn legendre(&self) -> i8
a is a QR in Fp^M iff a^{(p^M-1)/2} = 1.
Implements the “Legendre symbol” which is 1 if and only if we
have a quadratic residue in FpM
WARNING: Not constant time if self is zero
§Arguments
&self- Element of FpM (type: self)
§Returns
Either 0 if &self is 0, 1 if &self is a QR or -1 if
&self is not a QR. (type: i8)
Source§fn characteristic() -> Vec<u64>
fn characteristic() -> Vec<u64>
Source§fn pow_vartime(&self, exp: &[u64]) -> Self
fn pow_vartime(&self, exp: &[u64]) -> Self
self^exp using square-and multiply (litte-endian bit order) Read moreSource§fn pow(&self, exp: &[u64]) -> Self
fn pow(&self, exp: &[u64]) -> Self
self^pow in constant time using a Montgomery ladder Read moreSource§fn frobenius_pow(&self, k: u32) -> Self
fn frobenius_pow(&self, k: u32) -> Self
self^{p^k} a power of the frobenius