Skip to main content

FpExt

Struct FpExt 

Source
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>,

Source

pub fn new(coeffs: [FpElement<MOD, LIMBS>; M]) -> Self

Construct from a coefficient array [a_0, ..., a_{M-1}].

Source

pub fn from_base(a: FpElement<MOD, LIMBS>) -> Self

Embed a base-field element as $a + 0x + … + 0x^{M-1}$.

Source

pub fn coeff(&self, i: usize) -> &FpElement<MOD, LIMBS>

Return the coefficient of $x^i$.

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>,

Source§

type Output = FpExt<MOD, LIMBS, M, N, P, TSCONSTS>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self

Performs the + operation. Read more
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>,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
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>,

Source§

fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self

Select a or b according to choice. Read more
Source§

fn conditional_assign(&mut self, other: &Self, choice: Choice)

Conditionally assign other to self, according to choice. Read more
Source§

fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)

Conditionally swap self and other if choice == 1; otherwise, reassign both unto themselves. Read more
Source§

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§

fn ct_eq(&self, other: &Self) -> Choice

Determine if two items are equal. Read more
Source§

fn ct_ne(&self, other: &Self) -> Choice

Determine if two items are NOT equal. Read more
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,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
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>,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
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.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
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>,

Source§

type Repr = [FpElement<MOD, LIMBS>; M]

The representation type accepted by this field.
Source§

fn from_repr(x: Self::Repr) -> Self

Constructs a field element from the given representation.
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>,

Source§

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>

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

φ_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

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

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>

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>)

Inverse and sqrt in one exponentiation

Computes the inverse and squareroot of self in one exponentiation using the tricks in Scott’s article

§Arguments
  • &self - An element of Fp^M (type: &self)
§Returns

(myinv, mysqrt) which is self.invert() and self.sqrt() (type: CtOption<Self>, CtOption<Self>)

Source§

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>)

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>

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

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 degree() -> u32

Degree of Fp^M over the prime subfield Fp.

Source§

fn zero() -> Self

Create the constant zero
Source§

fn one() -> Self

Create the constant one
Source§

fn from_u64(x: u64) -> Self

Convert u64 to the field.
Source§

fn is_zero(&self) -> Choice

Check if element is zero
Source§

fn is_one(&self) -> Choice

Check if element is one
Source§

fn negate(&self) -> Self

Negate self to -self
Source§

fn add(&self, rhs: &Self) -> Self

Add rhs to self
Source§

fn sub(&self, rhs: &Self) -> Self

Sub rhs from self
Source§

fn square(&self) -> Self

Square self
Source§

fn double(&self) -> Self

Double self
Source§

fn characteristic() -> Vec<u64>

Returns the characteristic of the field.
Source§

fn div(&self, rhs: &Self) -> CtOption<Self>

Divide self by rhs
Source§

fn pow_vartime(&self, exp: &[u64]) -> Self

self^exp using square-and multiply (litte-endian bit order) Read more
Source§

fn pow(&self, exp: &[u64]) -> Self

self^pow in constant time using a Montgomery ladder Read more
Source§

fn frobenius_pow(&self, k: u32) -> Self

Compute self^{p^k} a power of the frobenius
Source§

impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> FieldRandom 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 random(rng: &mut (impl CryptoRng + Rng)) -> Self

Sample a uniformly random element of Fp^M by drawing each coefficient independently from Fp.

Source§

impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> Mul for FpExt<MOD, LIMBS, M, N, P, TSCONSTS>
where MOD: ConstPrimeMontyParams<LIMBS>, P: IrreduciblePoly<MOD, LIMBS, M>, TSCONSTS: TonelliShanksConstants<MOD, LIMBS, M, N>,

Source§

type Output = FpExt<MOD, LIMBS, M, N, P, TSCONSTS>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self

Performs the * operation. Read more
Source§

impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> Neg for FpExt<MOD, LIMBS, M, N, P, TSCONSTS>
where MOD: ConstPrimeMontyParams<LIMBS>, P: IrreduciblePoly<MOD, LIMBS, M>, TSCONSTS: TonelliShanksConstants<MOD, LIMBS, M, N>,

Source§

type Output = FpExt<MOD, LIMBS, M, N, P, TSCONSTS>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> PartialEq 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 eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> Sub for FpExt<MOD, LIMBS, M, N, P, TSCONSTS>
where MOD: ConstPrimeMontyParams<LIMBS>, P: IrreduciblePoly<MOD, LIMBS, M>, TSCONSTS: TonelliShanksConstants<MOD, LIMBS, M, N>,

Source§

type Output = FpExt<MOD, LIMBS, M, N, P, TSCONSTS>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self

Performs the - operation. Read more
Source§

impl<MOD, const LIMBS: usize, const M: usize, P, const N: usize, TSCONSTS> Copy 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>; M]: Copy,

Source§

impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> Eq for FpExt<MOD, LIMBS, M, N, P, TSCONSTS>
where MOD: ConstPrimeMontyParams<LIMBS>, P: IrreduciblePoly<MOD, LIMBS, M>, TSCONSTS: TonelliShanksConstants<MOD, LIMBS, M, N>,

Auto Trait Implementations§

§

impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> Freeze for FpExt<MOD, LIMBS, M, N, P, TSCONSTS>

§

impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> RefUnwindSafe for FpExt<MOD, LIMBS, M, N, P, TSCONSTS>
where P: RefUnwindSafe, TSCONSTS: RefUnwindSafe, MOD: RefUnwindSafe,

§

impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> Send for FpExt<MOD, LIMBS, M, N, P, TSCONSTS>
where P: Send, TSCONSTS: Send,

§

impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> Sync for FpExt<MOD, LIMBS, M, N, P, TSCONSTS>
where P: Sync, TSCONSTS: Sync,

§

impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> Unpin for FpExt<MOD, LIMBS, M, N, P, TSCONSTS>
where P: Unpin, TSCONSTS: Unpin, MOD: Unpin,

§

impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> UnsafeUnpin for FpExt<MOD, LIMBS, M, N, P, TSCONSTS>

§

impl<MOD, const LIMBS: usize, const M: usize, const N: usize, P, TSCONSTS> UnwindSafe for FpExt<MOD, LIMBS, M, N, P, TSCONSTS>
where P: UnwindSafe, TSCONSTS: UnwindSafe, MOD: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.