pub struct SmallFp<P: SmallFpConfig> {
pub value: P::T,
/* private fields */
}Expand description
Represents an element of the prime field F_p, where p == P::MODULUS.
This type can represent elements in any field of size up to 128 bits.
The arithmetic implementation is determined by the P: SmallFpConfig
parameter, which can be configured to use different backends
Fields§
§value: P::TImplementations§
Trait Implementations§
Source§impl<P: SmallFpConfig> Add for SmallFp<P>
impl<P: SmallFpConfig> Add for SmallFp<P>
Source§impl<P: SmallFpConfig> AddAssign<&SmallFp<P>> for SmallFp<P>
impl<P: SmallFpConfig> AddAssign<&SmallFp<P>> for SmallFp<P>
Source§fn add_assign(&mut self, other: &Self)
fn add_assign(&mut self, other: &Self)
+= operation. Read moreSource§impl<'a, P: SmallFpConfig> AddAssign<&'a mut SmallFp<P>> for SmallFp<P>
impl<'a, P: SmallFpConfig> AddAssign<&'a mut SmallFp<P>> for SmallFp<P>
Source§fn add_assign(&mut self, other: &'a mut Self)
fn add_assign(&mut self, other: &'a mut Self)
+= operation. Read moreSource§impl<P: SmallFpConfig> AddAssign for SmallFp<P>
impl<P: SmallFpConfig> AddAssign for SmallFp<P>
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
+= operation. Read moreSource§impl<P: SmallFpConfig> AdditiveGroup for SmallFp<P>
impl<P: SmallFpConfig> AdditiveGroup for SmallFp<P>
Source§impl<P: SmallFpConfig> CanonicalDeserialize for SmallFp<P>
impl<P: SmallFpConfig> CanonicalDeserialize for SmallFp<P>
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>
Source§fn deserialize_compressed<R>(reader: R) -> Result<Self, SerializationError>where
R: Read,
fn deserialize_compressed<R>(reader: R) -> Result<Self, SerializationError>where
R: Read,
Self from reader using the compressed form if applicable.
Performs validation if applicable.Source§fn deserialize_compressed_unchecked<R>(
reader: R,
) -> Result<Self, SerializationError>where
R: Read,
fn deserialize_compressed_unchecked<R>(
reader: R,
) -> Result<Self, SerializationError>where
R: Read,
Self from reader using the compressed form if applicable, without validating the
deserialized value. Read moreSource§fn deserialize_uncompressed<R>(reader: R) -> Result<Self, SerializationError>where
R: Read,
fn deserialize_uncompressed<R>(reader: R) -> Result<Self, SerializationError>where
R: Read,
Self from reader using the uncompressed form. Performs validation if applicable.Source§fn deserialize_uncompressed_unchecked<R>(
reader: R,
) -> Result<Self, SerializationError>where
R: Read,
fn deserialize_uncompressed_unchecked<R>(
reader: R,
) -> Result<Self, SerializationError>where
R: Read,
Self from reader using the uncompressed form, without validating the deserialized
value. Read moreSource§impl<P: SmallFpConfig> CanonicalDeserializeWithFlags for SmallFp<P>
impl<P: SmallFpConfig> CanonicalDeserializeWithFlags for SmallFp<P>
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>
Self and Flags from reader.
Returns empty flags by default.Source§impl<P: SmallFpConfig> CanonicalSerialize for SmallFp<P>
impl<P: SmallFpConfig> CanonicalSerialize for SmallFp<P>
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>
Source§fn serialized_size(&self, _compress: Compress) -> usize
fn serialized_size(&self, _compress: Compress) -> usize
self with the given compression mode.Source§fn serialize_compressed<W>(&self, writer: W) -> Result<(), SerializationError>where
W: Write,
fn serialize_compressed<W>(&self, writer: W) -> Result<(), SerializationError>where
W: Write,
self into writer using the compressed form if applicable.Source§fn compressed_size(&self) -> usize
fn compressed_size(&self) -> usize
self.Source§fn serialize_uncompressed<W>(&self, writer: W) -> Result<(), SerializationError>where
W: Write,
fn serialize_uncompressed<W>(&self, writer: W) -> Result<(), SerializationError>where
W: Write,
self into writer using the uncompressed form.Source§fn uncompressed_size(&self) -> usize
fn uncompressed_size(&self) -> usize
self.Source§impl<P: SmallFpConfig> CanonicalSerializeWithFlags for SmallFp<P>
impl<P: SmallFpConfig> CanonicalSerializeWithFlags for SmallFp<P>
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>
self and flags into writer.Source§fn serialized_size_with_flags<F: Flags>(&self) -> usize
fn serialized_size_with_flags<F: Flags>(&self) -> usize
self and flags into writer.Source§impl<P: SmallFpConfig> Clone for SmallFp<P>
impl<P: SmallFpConfig> Clone for SmallFp<P>
Source§impl<P: SmallFpConfig> Debug for SmallFp<P>
impl<P: SmallFpConfig> Debug for SmallFp<P>
Source§impl<P: SmallFpConfig> Default for SmallFp<P>
impl<P: SmallFpConfig> Default for SmallFp<P>
Source§impl<P: SmallFpConfig> Display for SmallFp<P>
Outputs a string containing the value of self,
represented as a decimal without leading zeroes.
impl<P: SmallFpConfig> Display for SmallFp<P>
Outputs a string containing the value of self,
represented as a decimal without leading zeroes.
Source§impl<P: SmallFpConfig> Distribution<SmallFp<P>> for Standard
impl<P: SmallFpConfig> Distribution<SmallFp<P>> for Standard
Source§impl<P: SmallFpConfig> Div for SmallFp<P>
impl<P: SmallFpConfig> Div for SmallFp<P>
Source§impl<P: SmallFpConfig> DivAssign<&SmallFp<P>> for SmallFp<P>
Computes self *= other.inverse() if other.inverse() is Some, and
panics otherwise.
impl<P: SmallFpConfig> DivAssign<&SmallFp<P>> for SmallFp<P>
Computes self *= other.inverse() if other.inverse() is Some, and
panics otherwise.
Source§fn div_assign(&mut self, other: &Self)
fn div_assign(&mut self, other: &Self)
/= operation. Read moreSource§impl<'a, P: SmallFpConfig> DivAssign<&'a mut SmallFp<P>> for SmallFp<P>
impl<'a, P: SmallFpConfig> DivAssign<&'a mut SmallFp<P>> for SmallFp<P>
Source§fn div_assign(&mut self, other: &'a mut Self)
fn div_assign(&mut self, other: &'a mut Self)
/= operation. Read moreSource§impl<P: SmallFpConfig> DivAssign for SmallFp<P>
impl<P: SmallFpConfig> DivAssign for SmallFp<P>
Source§fn div_assign(&mut self, other: Self)
fn div_assign(&mut self, other: Self)
/= operation. Read moreSource§impl<P: SmallFpConfig> FftField for SmallFp<P>
impl<P: SmallFpConfig> FftField for SmallFp<P>
Source§const TWO_ADICITY: u32 = P::TWO_ADICITY
const TWO_ADICITY: u32 = P::TWO_ADICITY
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 = P::TWO_ADIC_ROOT_OF_UNITY
const TWO_ADIC_ROOT_OF_UNITY: Self = P::TWO_ADIC_ROOT_OF_UNITY
Source§const SMALL_SUBGROUP_BASE: Option<u32> = P::SMALL_SUBGROUP_BASE
const SMALL_SUBGROUP_BASE: Option<u32> = P::SMALL_SUBGROUP_BASE
b such that there exists a multiplicative subgroup
of size b^k for some integer k.Source§const SMALL_SUBGROUP_BASE_ADICITY: Option<u32> = P::SMALL_SUBGROUP_BASE_ADICITY
const SMALL_SUBGROUP_BASE_ADICITY: Option<u32> = P::SMALL_SUBGROUP_BASE_ADICITY
k such that there exists a multiplicative subgroup
of size Self::SMALL_SUBGROUP_BASE^k.Source§const LARGE_SUBGROUP_ROOT_OF_UNITY: Option<Self> = P::LARGE_SUBGROUP_ROOT_OF_UNITY
const LARGE_SUBGROUP_ROOT_OF_UNITY: Option<Self> = P::LARGE_SUBGROUP_ROOT_OF_UNITY
Source§fn get_root_of_unity(n: u64) -> Option<Self>
fn get_root_of_unity(n: u64) -> Option<Self>
FftConfig::LARGE_SUBGROUP_ROOT_OF_UNITY
(for n = 2^i * FftConfig::SMALL_SUBGROUP_BASE^j for some i, j).Source§fn get_root_of_unity_big_int(n: BigUint) -> Option<Self>
fn get_root_of_unity_big_int(n: BigUint) -> Option<Self>
FftConfig::LARGE_SUBGROUP_ROOT_OF_UNITY
(for n = 2^i * FftConfig::SMALL_SUBGROUP_BASE^j for some i, j).Source§impl<P: SmallFpConfig> Field for SmallFp<P>
impl<P: SmallFpConfig> Field for SmallFp<P>
Source§fn frobenius_map_in_place(&mut self, _: usize)
fn frobenius_map_in_place(&mut self, _: usize)
The Frobenius map has no effect in a prime field.
Source§const SQRT_PRECOMP: Option<SqrtPrecomputation<Self>> = P::SQRT_PRECOMP
const SQRT_PRECOMP: Option<SqrtPrecomputation<Self>> = P::SQRT_PRECOMP
type BasePrimeField = SmallFp<P>
Source§fn extension_degree() -> u64
fn extension_degree() -> u64
Self::BasePrimeField.Source§fn from_base_prime_field(elem: Self::BasePrimeField) -> Self
fn from_base_prime_field(elem: Self::BasePrimeField) -> Self
fn to_base_prime_field_elements(&self) -> impl Iterator<Item = Self>
Source§fn from_base_prime_field_elems(
elems: impl IntoIterator<Item = Self::BasePrimeField>,
) -> Option<Self>
fn from_base_prime_field_elems( elems: impl IntoIterator<Item = Self::BasePrimeField>, ) -> Option<Self>
Source§fn characteristic() -> &'static [u64]
fn characteristic() -> &'static [u64]
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
sum([a_i * b_i]).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)>
F specification. Returns None if the deserialization
fails. Read moreSource§fn square_in_place(&mut self) -> &mut Self
fn square_in_place(&mut self) -> &mut Self
self in place.Source§fn inverse(&self) -> Option<Self>
fn inverse(&self) -> Option<Self>
self if self is nonzero.Source§fn inverse_in_place(&mut self) -> Option<&mut Self>
fn inverse_in_place(&mut self) -> Option<&mut Self>
self.inverse().is_none(), this just returns None. Otherwise, it sets
self to self.inverse().unwrap().Source§fn legendre(&self) -> LegendreSymbol
fn legendre(&self) -> LegendreSymbol
LegendreSymbol, which indicates whether this field element
is 1 : a quadratic residue
0 : equal to 0
-1 : a quadratic non-residuefn mul_by_base_prime_field(&self, elem: &Self::BasePrimeField) -> Self
Source§fn from_random_bytes(bytes: &[u8]) -> Option<Self>
fn from_random_bytes(bytes: &[u8]) -> Option<Self>
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>
self to be the square root of self, if it exists.Source§fn frobenius_map(&self, power: usize) -> Self
fn frobenius_map(&self, power: usize) -> Self
self^s, where s = Self::BasePrimeField::MODULUS^power.
This is also called the Frobenius automorphism.Source§fn pow<S: AsRef<[u64]>>(&self, exp: S) -> Self
fn pow<S: AsRef<[u64]>>(&self, exp: S) -> Self
self^exp, where exp is an integer represented with u64 limbs,
least significant limb first.Source§fn pow_with_table<S: AsRef<[u64]>>(powers_of_2: &[Self], exp: S) -> Option<Self>
fn pow_with_table<S: AsRef<[u64]>>(powers_of_2: &[Self], exp: S) -> Option<Self>
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<P: SmallFpConfig> FromStr for SmallFp<P>
impl<P: SmallFpConfig> FromStr for SmallFp<P>
Source§impl<P: SmallFpConfig> Hash for SmallFp<P>
impl<P: SmallFpConfig> Hash for SmallFp<P>
Source§impl<P: SmallFpConfig> Mul for SmallFp<P>
impl<P: SmallFpConfig> Mul for SmallFp<P>
Source§impl<P: SmallFpConfig> MulAssign<&SmallFp<P>> for SmallFp<P>
impl<P: SmallFpConfig> MulAssign<&SmallFp<P>> for SmallFp<P>
Source§fn mul_assign(&mut self, other: &Self)
fn mul_assign(&mut self, other: &Self)
*= operation. Read moreSource§impl<'a, P: SmallFpConfig> MulAssign<&'a mut SmallFp<P>> for SmallFp<P>
impl<'a, P: SmallFpConfig> MulAssign<&'a mut SmallFp<P>> for SmallFp<P>
Source§fn mul_assign(&mut self, other: &'a mut Self)
fn mul_assign(&mut self, other: &'a mut Self)
*= operation. Read moreSource§impl<P: SmallFpConfig> MulAssign for SmallFp<P>
impl<P: SmallFpConfig> MulAssign for SmallFp<P>
Source§fn mul_assign(&mut self, other: Self)
fn mul_assign(&mut self, other: Self)
*= operation. Read moreSource§impl<P: SmallFpConfig> Neg for SmallFp<P>
impl<P: SmallFpConfig> Neg for SmallFp<P>
Source§impl<P: SmallFpConfig> One for SmallFp<P>
impl<P: SmallFpConfig> One for SmallFp<P>
Source§impl<P: SmallFpConfig> Ord for SmallFp<P>
Note that this implementation of Ord compares field elements viewing
them as integers in the range 0, 1, …, P::MODULUS - 1. However, other
implementations of PrimeField might choose a different ordering, and
as such, users should use this Ord for applications where
any ordering suffices (like in a BTreeMap), and not in applications
where a particular ordering is required.
impl<P: SmallFpConfig> Ord for SmallFp<P>
Note that this implementation of Ord compares field elements viewing
them as integers in the range 0, 1, …, P::MODULUS - 1. However, other
implementations of PrimeField might choose a different ordering, and
as such, users should use this Ord for applications where
any ordering suffices (like in a BTreeMap), and not in applications
where a particular ordering is required.
Source§impl<P: SmallFpConfig> PartialEq for SmallFp<P>
impl<P: SmallFpConfig> PartialEq for SmallFp<P>
Source§impl<P: SmallFpConfig> PartialOrd for SmallFp<P>
Note that this implementation of PartialOrd compares field elements
viewing them as integers in the range 0, 1, …, P::MODULUS - 1. However,
other implementations of PrimeField might choose a different ordering, and
as such, users should use this PartialOrd for applications where
any ordering suffices (like in a BTreeMap), and not in applications
where a particular ordering is required.
impl<P: SmallFpConfig> PartialOrd for SmallFp<P>
Note that this implementation of PartialOrd compares field elements
viewing them as integers in the range 0, 1, …, P::MODULUS - 1. However,
other implementations of PrimeField might choose a different ordering, and
as such, users should use this PartialOrd for applications where
any ordering suffices (like in a BTreeMap), and not in applications
where a particular ordering is required.
Source§impl<P: SmallFpConfig> PrimeField for SmallFp<P>
impl<P: SmallFpConfig> PrimeField for SmallFp<P>
Source§const MODULUS_MINUS_ONE_DIV_TWO: Self::BigInt
const MODULUS_MINUS_ONE_DIV_TWO: Self::BigInt
(p - 1)/ 2.Source§const MODULUS_BIT_SIZE: u32
const MODULUS_BIT_SIZE: u32
Source§const TRACE: Self::BigInt
const TRACE: Self::BigInt
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
(t - 1)/ 2.Source§fn from_bigint(r: BigInt<1>) -> Option<Self>
fn from_bigint(r: BigInt<1>) -> Option<Self>
Source§fn into_bigint(self) -> BigInt<1>
fn into_bigint(self) -> BigInt<1>
Source§fn from_be_bytes_mod_order(bytes: &[u8]) -> Self
fn from_be_bytes_mod_order(bytes: &[u8]) -> Self
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
bytes is larger than the modulus p, this method
performs the appropriate reduction.Source§impl<P: SmallFpConfig> Product for SmallFp<P>
impl<P: SmallFpConfig> Product for SmallFp<P>
Source§impl<P: SmallFpConfig> Sub for SmallFp<P>
impl<P: SmallFpConfig> Sub for SmallFp<P>
Source§impl<P: SmallFpConfig> SubAssign<&SmallFp<P>> for SmallFp<P>
impl<P: SmallFpConfig> SubAssign<&SmallFp<P>> for SmallFp<P>
Source§fn sub_assign(&mut self, other: &Self)
fn sub_assign(&mut self, other: &Self)
-= operation. Read moreSource§impl<'a, P: SmallFpConfig> SubAssign<&'a mut SmallFp<P>> for SmallFp<P>
impl<'a, P: SmallFpConfig> SubAssign<&'a mut SmallFp<P>> for SmallFp<P>
Source§fn sub_assign(&mut self, other: &'a mut Self)
fn sub_assign(&mut self, other: &'a mut Self)
-= operation. Read moreSource§impl<P: SmallFpConfig> SubAssign for SmallFp<P>
impl<P: SmallFpConfig> SubAssign for SmallFp<P>
Source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
-= operation. Read moreSource§impl<P: SmallFpConfig> Sum for SmallFp<P>
impl<P: SmallFpConfig> Sum for SmallFp<P>
Source§impl<P: SmallFpConfig> Valid for SmallFp<P>
impl<P: SmallFpConfig> Valid for SmallFp<P>
Source§fn check(&self) -> Result<(), SerializationError>
fn check(&self) -> Result<(), SerializationError>
self is valid. If self is valid, returns Ok(()). Otherwise, returns
an error describing the failure.
This method is called by deserialize_with_mode if validate is Validate::Yes.Source§const TRIVIAL_CHECK: bool = false
const TRIVIAL_CHECK: bool = false
check method is trivial (i.e. always returns Ok(())). If this is true,
the batch_check method will skip all checks and return Ok(()).
This should be set to true for types where check is trivial, e.g.
integers, field elements, etc.
This is false by default.
This is primarily an optimization to skip unnecessary checks in batch_check.Source§fn batch_check<'a>(
batch: impl Iterator<Item = &'a Self> + Send,
) -> Result<(), SerializationError>where
Self: 'a,
fn batch_check<'a>(
batch: impl Iterator<Item = &'a Self> + Send,
) -> Result<(), SerializationError>where
Self: 'a,
batch are valid. If all items are valid, returns Ok(()).
Otherwise, returns an error describing the first failure.