pub type Fq = Fq;
Aliased Type§
struct Fq(/* private fields */);
Implementations§
source§impl Fq
impl Fq
pub const MODULUS_LIMBS: [u64; 4] = _
pub const MODULUS_MINUS_ONE_DIV_TWO_LIMBS: [u64; 4] = _
pub const MODULUS_BIT_SIZE: u32 = 253u32
pub const TRACE_LIMBS: [u64; 4] = _
pub const TRACE_MINUS_ONE_DIV_TWO_LIMBS: [u64; 4] = _
pub const TWO_ADICITY: u32 = 47u32
pub const QUADRATIC_NON_RESIDUE_TO_TRACE: Self = _
pub const MULTIPLICATIVE_GENERATOR: Self = _
pub const TWO_ADIC_ROOT_OF_UNITY: Self = _
pub const FIELD_SIZE_POWER_OF_TWO: Self = _
pub fn from_le_bytes_mod_order(bytes: &[u8]) -> Self
sourcepub fn from_bytes_checked(bytes: &[u8; 32]) -> Result<Self, EncodingError>
pub fn from_bytes_checked(bytes: &[u8; 32]) -> Result<Self, EncodingError>
Convert bytes into an Fq element, returning None if these bytes are not already reduced.
This means that values that cannot be produced by encoding a field element will return None, enforcing canonical serialization.
pub fn to_bytes(&self) -> [u8; 32]
sourcepub fn rand<R: CryptoRngCore>(rng: &mut R) -> Self
pub fn rand<R: CryptoRngCore>(rng: &mut R) -> Self
Sample a random field element uniformly.
source§impl Fq
impl Fq
sourcepub fn sqrt_ratio_zeta(num: &Self, den: &Self) -> (bool, Self)
pub fn sqrt_ratio_zeta(num: &Self, den: &Self) -> (bool, Self)
Computes the square root of a ratio of field elements, returning:
(true, sqrt(num/den))
ifnum
andden
are both nonzero andnum/den
is square;(true, 0)
ifnum
is zero;(false, 0)
ifden
is zero;(false, sqrt(zeta*num/den))
ifnum
andden
are both nonzero andnum/den
is nonsquare;
Trait Implementations§
source§impl AddAssign for Fq
impl AddAssign for Fq
source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
Performs the
+=
operation. Read moresource§impl CanonicalDeserialize for Fq
impl CanonicalDeserialize for Fq
source§fn deserialize_with_mode<R: Read>(
reader: R,
_compress: Compress,
validate: Validate,
) -> Result<Self, SerializationError>
fn deserialize_with_mode<R: Read>( reader: R, _compress: Compress, validate: Validate, ) -> Result<Self, SerializationError>
The general deserialize method that takes in customization flags.
fn deserialize_compressed<R>(reader: R) -> Result<Self, SerializationError>where
R: Read,
fn deserialize_compressed_unchecked<R>(
reader: R,
) -> Result<Self, SerializationError>where
R: Read,
fn deserialize_uncompressed<R>(reader: R) -> Result<Self, SerializationError>where
R: Read,
fn deserialize_uncompressed_unchecked<R>(
reader: R,
) -> Result<Self, SerializationError>where
R: Read,
source§impl CanonicalDeserializeWithFlags for Fq
impl CanonicalDeserializeWithFlags for Fq
source§fn deserialize_with_flags<R: Read, F: Flags>(
reader: R,
) -> Result<(Self, F), SerializationError>
fn deserialize_with_flags<R: Read, F: Flags>( reader: R, ) -> Result<(Self, F), SerializationError>
Reads
Self
and Flags
from reader
.
Returns empty flags by default.source§impl CanonicalSerialize for Fq
impl CanonicalSerialize for Fq
source§fn serialize_with_mode<W: Write>(
&self,
writer: W,
_compress: Compress,
) -> Result<(), SerializationError>
fn serialize_with_mode<W: Write>( &self, writer: W, _compress: Compress, ) -> Result<(), SerializationError>
The general serialize method that takes in customization flags.
fn serialized_size(&self, _compress: Compress) -> usize
fn serialize_compressed<W>(&self, writer: W) -> Result<(), SerializationError>where
W: Write,
fn compressed_size(&self) -> usize
fn serialize_uncompressed<W>(&self, writer: W) -> Result<(), SerializationError>where
W: Write,
fn uncompressed_size(&self) -> usize
source§impl CanonicalSerializeWithFlags for Fq
impl CanonicalSerializeWithFlags for Fq
source§fn serialize_with_flags<W: Write, F: Flags>(
&self,
writer: W,
flags: F,
) -> Result<(), SerializationError>
fn serialize_with_flags<W: Write, F: Flags>( &self, writer: W, flags: F, ) -> Result<(), SerializationError>
Serializes
self
and flags
into writer
.source§fn serialized_size_with_flags<F: Flags>(&self) -> usize
fn serialized_size_with_flags<F: Flags>(&self) -> usize
Serializes
self
and flags
into writer
.source§impl DivAssign for Fq
impl DivAssign for Fq
source§fn div_assign(&mut self, other: Self)
fn div_assign(&mut self, other: Self)
Performs the
/=
operation. Read moresource§impl FftField for Fq
impl FftField for Fq
source§const GENERATOR: Self = Self::MULTIPLICATIVE_GENERATOR
const GENERATOR: Self = Self::MULTIPLICATIVE_GENERATOR
The generator of the multiplicative group of the field
source§const TWO_ADICITY: u32 = 47u32
const TWO_ADICITY: u32 = 47u32
Let
N
be the size of the multiplicative group defined by the field.
Then TWO_ADICITY
is the two-adicity of N
, i.e. the integer s
such that N = 2^s * t
for some odd integer t
.source§const TWO_ADIC_ROOT_OF_UNITY: Self = Self::TWO_ADIC_ROOT_OF_UNITY
const TWO_ADIC_ROOT_OF_UNITY: Self = Self::TWO_ADIC_ROOT_OF_UNITY
2^s root of unity computed by GENERATOR^t
source§const SMALL_SUBGROUP_BASE: Option<u32> = None
const SMALL_SUBGROUP_BASE: Option<u32> = None
An integer
b
such that there exists a multiplicative subgroup
of size b^k
for some integer k
.source§const SMALL_SUBGROUP_BASE_ADICITY: Option<u32> = None
const SMALL_SUBGROUP_BASE_ADICITY: Option<u32> = None
The integer
k
such that there exists a multiplicative subgroup
of size Self::SMALL_SUBGROUP_BASE^k
.source§const LARGE_SUBGROUP_ROOT_OF_UNITY: Option<Self> = None
const LARGE_SUBGROUP_ROOT_OF_UNITY: Option<Self> = None
GENERATOR^((MODULUS-1) / (2^s *
SMALL_SUBGROUP_BASE^SMALL_SUBGROUP_BASE_ADICITY)) Used for mixed-radix
FFT.
source§fn get_root_of_unity(n: u64) -> Option<Self>
fn get_root_of_unity(n: u64) -> Option<Self>
Returns the root of unity of order n, if one exists.
If no small multiplicative subgroup is defined, this is the 2-adic root
of unity of order n (for n a power of 2).
If a small multiplicative subgroup is defined, this is the root of unity
of order n for the larger subgroup generated by
FftConfig::LARGE_SUBGROUP_ROOT_OF_UNITY
(for n = 2^i * FftConfig::SMALL_SUBGROUP_BASE^j for some i, j).source§impl Field for Fq
impl Field for Fq
type BasePrimeField = Fq
type BasePrimeFieldIter = Once<<Fq as Field>::BasePrimeField>
source§const SQRT_PRECOMP: Option<SqrtPrecomputation<Self>> = _
const SQRT_PRECOMP: Option<SqrtPrecomputation<Self>> = _
Determines the algorithm for computing square roots.
source§fn extension_degree() -> u64
fn extension_degree() -> u64
Returns the extension degree of this field with respect
to
Self::BasePrimeField
.fn to_base_prime_field_elements(&self) -> Self::BasePrimeFieldIter
source§fn from_base_prime_field_elems(elems: &[Self::BasePrimeField]) -> Option<Self>
fn from_base_prime_field_elems(elems: &[Self::BasePrimeField]) -> Option<Self>
Convert a slice of base prime field elements into a field element.
If the slice length != Self::extension_degree(), must return None.
source§fn from_base_prime_field(elem: Self::BasePrimeField) -> Self
fn from_base_prime_field(elem: Self::BasePrimeField) -> Self
Constructs a field element from a single base prime field elements. Read more
source§fn double_in_place(&mut self) -> &mut Self
fn double_in_place(&mut self) -> &mut Self
Doubles
self
in place.source§fn neg_in_place(&mut self) -> &mut Self
fn neg_in_place(&mut self) -> &mut Self
Negates
self
in place.source§fn from_random_bytes_with_flags<F: Flags>(bytes: &[u8]) -> Option<(Self, F)>
fn from_random_bytes_with_flags<F: Flags>(bytes: &[u8]) -> Option<(Self, F)>
Attempt to deserialize a field element, splitting the bitflags metadata
according to
F
specification. Returns None
if the deserialization
fails. Read moresource§fn legendre(&self) -> LegendreSymbol
fn legendre(&self) -> LegendreSymbol
Returns a
LegendreSymbol
, which indicates whether this field element
is 1 : a quadratic residue
0 : equal to 0
-1 : a quadratic non-residuesource§fn square_in_place(&mut self) -> &mut Self
fn square_in_place(&mut self) -> &mut Self
Squares
self
in place.source§fn inverse(&self) -> Option<Self>
fn inverse(&self) -> Option<Self>
Computes the multiplicative inverse of
self
if self
is nonzero.source§fn inverse_in_place(&mut self) -> Option<&mut Self>
fn inverse_in_place(&mut self) -> Option<&mut Self>
If
self.inverse().is_none()
, this just returns None
. Otherwise, it sets
self
to self.inverse().unwrap()
.source§fn frobenius_map_in_place(&mut self, _power: usize)
fn frobenius_map_in_place(&mut self, _power: usize)
Sets
self
to self^s
, where s = Self::BasePrimeField::MODULUS^power
.
This is also called the Frobenius automorphism.source§fn characteristic() -> &'static [u64]
fn characteristic() -> &'static [u64]
Returns the characteristic of the field,
in little-endian representation.
source§fn from_random_bytes(bytes: &[u8]) -> Option<Self>
fn from_random_bytes(bytes: &[u8]) -> Option<Self>
Attempt to deserialize a field element. Returns
None
if the
deserialization fails. Read moresource§fn sqrt_in_place(&mut self) -> Option<&mut Self>
fn sqrt_in_place(&mut self) -> Option<&mut Self>
Sets
self
to be the square root of self
, if it exists.source§fn sum_of_products<const T: usize>(a: &[Self; T], b: &[Self; T]) -> Self
fn sum_of_products<const T: usize>(a: &[Self; T], b: &[Self; T]) -> Self
Returns
sum([a_i * b_i])
.source§fn frobenius_map(&self, power: usize) -> Self
fn frobenius_map(&self, power: usize) -> Self
Returns
self^s
, where s = Self::BasePrimeField::MODULUS^power
.
This is also called the Frobenius automorphism.source§fn pow<S>(&self, exp: S) -> Self
fn pow<S>(&self, exp: S) -> Self
Returns
self^exp
, where exp
is an integer represented with u64
limbs,
least significant limb first.source§fn pow_with_table<S>(powers_of_2: &[Self], exp: S) -> Option<Self>
fn pow_with_table<S>(powers_of_2: &[Self], exp: S) -> Option<Self>
Exponentiates a field element
f
by a number represented with u64
limbs, using a precomputed table containing as many powers of 2 of
f
as the 1 + the floor of log2 of the exponent exp
, starting
from the 1st power. That is, powers_of_2
should equal &[p, p^2, p^4, ..., p^(2^n)]
when exp
has at most n
bits. Read moresource§impl MulAssign for Fq
impl MulAssign for Fq
source§fn mul_assign(&mut self, other: Self)
fn mul_assign(&mut self, other: Self)
Performs the
*=
operation. Read moresource§impl Ord for Fq
impl Ord for Fq
source§impl PartialOrd for Fq
impl PartialOrd for Fq
source§impl PrimeField for Fq
impl PrimeField for Fq
source§const MODULUS: Self::BigInt = _
const MODULUS: Self::BigInt = _
The BLS12-377 scalar field modulus q
= 0x12ab655e9a2ca55660b44d1e5c37b00159aa76fed00000010a11800000000001
source§const MODULUS_MINUS_ONE_DIV_TWO: Self::BigInt = _
const MODULUS_MINUS_ONE_DIV_TWO: Self::BigInt = _
The value (p - 1)/ 2
.
source§const MODULUS_BIT_SIZE: u32 = 253u32
const MODULUS_BIT_SIZE: u32 = 253u32
The size of the modulus in bits.
source§const TRACE: Self::BigInt = _
const TRACE: Self::BigInt = _
The trace of the field is defined as the smallest integer t
such that by
2^s * t = p - 1
, and t
is coprime to 2.
source§const TRACE_MINUS_ONE_DIV_TWO: Self::BigInt = _
const TRACE_MINUS_ONE_DIV_TWO: Self::BigInt = _
The value (t - 1)/ 2
.
source§fn from_bigint(repr: Self::BigInt) -> Option<Self>
fn from_bigint(repr: Self::BigInt) -> Option<Self>
Construct a prime field element from an integer in the range 0..(p - 1).
source§fn into_bigint(self) -> Self::BigInt
fn into_bigint(self) -> Self::BigInt
Converts an element of the prime field into an integer in the range 0..(p - 1).
source§fn from_be_bytes_mod_order(bytes: &[u8]) -> Self
fn from_be_bytes_mod_order(bytes: &[u8]) -> Self
Reads bytes in big-endian, and converts them to a field element.
If the integer represented by
bytes
is larger than the modulus p
, this method
performs the appropriate reduction.source§fn from_le_bytes_mod_order(bytes: &[u8]) -> Self
fn from_le_bytes_mod_order(bytes: &[u8]) -> Self
Reads bytes in little-endian, and converts them to a field element.
If the integer represented by
bytes
is larger than the modulus p
, this method
performs the appropriate reduction.source§impl SubAssign for Fq
impl SubAssign for Fq
source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
Performs the
-=
operation. Read more