Trait modular_frost::curve::PrimeField
source · pub trait PrimeField: Field + From<u64> {
type Repr: Copy + Default + Send + Sync + 'static + AsRef<[u8]> + AsMut<[u8]>;
const MODULUS: &'static str;
const NUM_BITS: u32;
const CAPACITY: u32;
const TWO_INV: Self;
const MULTIPLICATIVE_GENERATOR: Self;
const S: u32;
const ROOT_OF_UNITY: Self;
const ROOT_OF_UNITY_INV: Self;
const DELTA: Self;
// Required methods
fn from_repr(repr: Self::Repr) -> CtOption<Self>;
fn to_repr(&self) -> Self::Repr;
fn is_odd(&self) -> Choice;
// Provided methods
fn from_str_vartime(s: &str) -> Option<Self> { ... }
fn from_u128(v: u128) -> Self { ... }
fn from_repr_vartime(repr: Self::Repr) -> Option<Self> { ... }
fn is_even(&self) -> Choice { ... }
}
Expand description
This represents an element of a non-binary prime field.
Required Associated Types§
Required Associated Constants§
sourceconst MODULUS: &'static str
const MODULUS: &'static str
Modulus of the field written as a string for debugging purposes.
The encoding of the modulus is implementation-specific. Generic users of the
PrimeField
trait should treat this string as opaque.
sourceconst CAPACITY: u32
const CAPACITY: u32
How many bits of information can be reliably stored in the field element.
This is usually Self::NUM_BITS - 1
.
sourceconst MULTIPLICATIVE_GENERATOR: Self
const MULTIPLICATIVE_GENERATOR: Self
A fixed multiplicative generator of modulus - 1
order. This element must also be
a quadratic nonresidue.
It can be calculated using SageMath as GF(modulus).primitive_element()
.
Implementations of this trait MUST ensure that this is the generator used to
derive Self::ROOT_OF_UNITY
.
sourceconst S: u32
const S: u32
An integer s
satisfying the equation 2^s * t = modulus - 1
with t
odd.
This is the number of leading zero bits in the little-endian bit representation of
modulus - 1
.
sourceconst ROOT_OF_UNITY: Self
const ROOT_OF_UNITY: Self
The 2^s
root of unity.
It can be calculated by exponentiating Self::MULTIPLICATIVE_GENERATOR
by t
,
where t = (modulus - 1) >> Self::S
.
sourceconst ROOT_OF_UNITY_INV: Self
const ROOT_OF_UNITY_INV: Self
Inverse of Self::ROOT_OF_UNITY
.
sourceconst DELTA: Self
const DELTA: Self
Generator of the t-order
multiplicative subgroup.
It can be calculated by exponentiating Self::MULTIPLICATIVE_GENERATOR
by 2^s
,
where s
is Self::S
.
Required Methods§
sourcefn from_repr(repr: Self::Repr) -> CtOption<Self>
fn from_repr(repr: Self::Repr) -> CtOption<Self>
Attempts to convert a byte representation of a field element into an element of this prime field, failing if the input is not canonical (is not smaller than the field’s modulus).
The byte representation is interpreted with the same endianness as elements
returned by PrimeField::to_repr
.
Provided Methods§
sourcefn from_str_vartime(s: &str) -> Option<Self>
fn from_str_vartime(s: &str) -> Option<Self>
Interpret a string of numbers as a (congruent) prime field element. Does not accept unnecessary leading zeroes or a blank string.
§Security
This method provides no constant-time guarantees.
sourcefn from_u128(v: u128) -> Self
fn from_u128(v: u128) -> Self
Obtains a field element congruent to the integer v
.
For fields where Self::CAPACITY >= 128
, this is injective and will produce a
unique field element.
For fields where Self::CAPACITY < 128
, this is surjective; some field elements
will be produced by multiple values of v
.
If you want to deterministically sample a field element representing a value, use
FromUniformBytes
instead.
sourcefn from_repr_vartime(repr: Self::Repr) -> Option<Self>
fn from_repr_vartime(repr: Self::Repr) -> Option<Self>
Attempts to convert a byte representation of a field element into an element of this prime field, failing if the input is not canonical (is not smaller than the field’s modulus).
The byte representation is interpreted with the same endianness as elements
returned by PrimeField::to_repr
.
§Security
This method provides no constant-time guarantees. Implementors of the
PrimeField
trait may optimise this method using non-constant-time logic.
Object Safety§
Implementations on Foreign Types§
source§impl PrimeField for Scalar
Available on crate feature group
only.
impl PrimeField for Scalar
group
only.type Repr = [u8; 32]
fn from_repr(repr: <Scalar as PrimeField>::Repr) -> CtOption<Scalar>
fn from_repr_vartime(repr: <Scalar as PrimeField>::Repr) -> Option<Scalar>
fn to_repr(&self) -> <Scalar as PrimeField>::Repr
fn is_odd(&self) -> Choice
const MODULUS: &'static str = "0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"
const NUM_BITS: u32 = 253u32
const CAPACITY: u32 = 252u32
const TWO_INV: Scalar = _
const MULTIPLICATIVE_GENERATOR: Scalar = _
const S: u32 = 2u32
const ROOT_OF_UNITY: Scalar = _
const ROOT_OF_UNITY_INV: Scalar = _
const DELTA: Scalar = _
source§impl PrimeField for FieldElement
impl PrimeField for FieldElement
type Repr = [u8; 32]
const MODULUS: &'static str = "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"
const NUM_BITS: u32 = 255u32
const CAPACITY: u32 = 254u32
const TWO_INV: FieldElement = _
const MULTIPLICATIVE_GENERATOR: FieldElement = _
const S: u32 = 2u32
const ROOT_OF_UNITY: FieldElement = _
const ROOT_OF_UNITY_INV: FieldElement = _
const DELTA: FieldElement = _
fn from_repr(bytes: [u8; 32]) -> CtOption<FieldElement>
fn to_repr(&self) -> [u8; 32]
fn is_odd(&self) -> Choice
fn from_u128(num: u128) -> FieldElement
source§impl PrimeField for Scalar
impl PrimeField for Scalar
type Repr = [u8; 32]
const MODULUS: &'static str = <DScalar as PrimeField>::MODULUS
const NUM_BITS: u32 = 253u32
const CAPACITY: u32 = 252u32
const TWO_INV: Scalar = _
const MULTIPLICATIVE_GENERATOR: Scalar = _
const S: u32 = 2u32
const ROOT_OF_UNITY: Scalar = _
const ROOT_OF_UNITY_INV: Scalar = _
const DELTA: Scalar = _
fn from_repr(bytes: [u8; 32]) -> CtOption<Scalar>
fn to_repr(&self) -> [u8; 32]
fn is_odd(&self) -> Choice
fn from_u128(num: u128) -> Scalar
source§impl PrimeField for Scalar
impl PrimeField for Scalar
source§fn from_repr(
bytes: GenericArray<u8, <Secp256k1 as Curve>::FieldBytesSize>,
) -> CtOption<Scalar>
fn from_repr( bytes: GenericArray<u8, <Secp256k1 as Curve>::FieldBytesSize>, ) -> CtOption<Scalar>
Attempts to parse the given byte array as an SEC1-encoded scalar.
Returns None if the byte array does not contain a big-endian integer in the range [0, p).
type Repr = GenericArray<u8, <Secp256k1 as Curve>::FieldBytesSize>
const MODULUS: &'static str = ORDER_HEX
const NUM_BITS: u32 = 256u32
const CAPACITY: u32 = 255u32
const TWO_INV: Scalar = _
const MULTIPLICATIVE_GENERATOR: Scalar = _
const S: u32 = 6u32
const ROOT_OF_UNITY: Scalar = _
const ROOT_OF_UNITY_INV: Scalar = _
const DELTA: Scalar = _
fn to_repr(&self) -> GenericArray<u8, <Secp256k1 as Curve>::FieldBytesSize>
fn is_odd(&self) -> Choice
source§impl PrimeField for FieldElement
impl PrimeField for FieldElement
type Repr = GenericArray<u8, UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B1>, B1>, B0>, B0>, B1>>
const MODULUS: &'static str = MODULUS_STR
const NUM_BITS: u32 = 448u32
const CAPACITY: u32 = 447u32
const TWO_INV: FieldElement = _
const MULTIPLICATIVE_GENERATOR: FieldElement = _
const S: u32 = 1u32
const ROOT_OF_UNITY: FieldElement = _
const ROOT_OF_UNITY_INV: FieldElement = _
const DELTA: FieldElement = _
fn from_repr( bytes: <FieldElement as PrimeField>::Repr, ) -> CtOption<FieldElement>
fn to_repr(&self) -> <FieldElement as PrimeField>::Repr
fn is_odd(&self) -> Choice
source§impl PrimeField for Scalar
impl PrimeField for Scalar
type Repr = GenericArray<u8, UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B1>, B1>, B0>, B0>, B1>>
const MODULUS: &'static str = MODULUS_STR
const NUM_BITS: u32 = 446u32
const CAPACITY: u32 = 445u32
const TWO_INV: Scalar = _
const MULTIPLICATIVE_GENERATOR: Scalar = _
const S: u32 = 1u32
const ROOT_OF_UNITY: Scalar = _
const ROOT_OF_UNITY_INV: Scalar = _
const DELTA: Scalar = _
fn from_repr(bytes: <Scalar as PrimeField>::Repr) -> CtOption<Scalar>
fn to_repr(&self) -> <Scalar as PrimeField>::Repr
fn is_odd(&self) -> Choice
source§impl PrimeField for Scalar
impl PrimeField for Scalar
source§fn from_repr(
bytes: GenericArray<u8, <NistP256 as Curve>::FieldBytesSize>,
) -> CtOption<Scalar>
fn from_repr( bytes: GenericArray<u8, <NistP256 as Curve>::FieldBytesSize>, ) -> CtOption<Scalar>
Attempts to parse the given byte array as an SEC1-encoded scalar.
Returns None if the byte array does not contain a big-endian integer in the range [0, p).