Struct twenty_first::math::b_field_element::BFieldElement
source · pub struct BFieldElement(/* private fields */);Expand description
Base field element ∈ ℤ_{2^64 - 2^32 + 1}.
In Montgomery representation. This implementation follows https://eprint.iacr.org/2022/274.pdf and https://github.com/novifinancial/winterfell/pull/101/files.
Implementations§
source§impl BFieldElement
impl BFieldElement
pub const BYTES: usize = 8usize
sourcepub const P: u64 = 18_446_744_069_414_584_321u64
pub const P: u64 = 18_446_744_069_414_584_321u64
The base field’s prime, i.e., 2^64 - 2^32 + 1.
pub const MAX: u64 = 18_446_744_069_414_584_320u64
pub const fn new(value: u64) -> Self
pub const fn value(&self) -> u64
sourcepub const fn power_accumulator<const N: usize, const M: usize>(
base: [Self; N],
tail: [Self; N]
) -> [Self; N]
pub const fn power_accumulator<const N: usize, const M: usize>( base: [Self; N], tail: [Self; N] ) -> [Self; N]
Square the base M times and multiply the result by the tail value
pub const fn lift(&self) -> XFieldElement
pub fn increment(&mut self)
pub fn decrement(&mut self)
pub const fn mod_pow(&self, exp: u64) -> Self
sourcepub fn from_ne_bytes(bytes: &[u8]) -> BFieldElement
pub fn from_ne_bytes(bytes: &[u8]) -> BFieldElement
Convert a BFieldElement from a byte slice in native endianness.
sourcepub const fn raw_bytes(&self) -> [u8; 8]
pub const fn raw_bytes(&self) -> [u8; 8]
Return the raw bytes or 8-bit chunks of the Montgomery representation, in little-endian byte order
sourcepub const fn from_raw_bytes(bytes: &[u8; 8]) -> Self
pub const fn from_raw_bytes(bytes: &[u8; 8]) -> Self
Take a slice of 8 bytes and interpret it as an integer in little-endian byte order, and cast it to a BFieldElement in Montgomery representation
sourcepub const fn raw_u16s(&self) -> [u16; 4]
pub const fn raw_u16s(&self) -> [u16; 4]
Return the raw 16-bit chunks of the Montgomery representation, in little-endian chunk order
sourcepub const fn from_raw_u16s(chunks: &[u16; 4]) -> Self
pub const fn from_raw_u16s(chunks: &[u16; 4]) -> Self
Take a slice of 4 16-bit chunks and interpret it as an integer in little-endian chunk order, and cast it to a BFieldElement in Montgomery representation
pub fn raw_u128(&self) -> u128
pub const fn from_raw_u64(e: u64) -> BFieldElement
pub fn raw_u64(&self) -> u64
Trait Implementations§
source§impl Add<BFieldElement> for XFieldElement
impl Add<BFieldElement> for XFieldElement
§type Output = XFieldElement
type Output = XFieldElement
+ operator.source§fn add(self, other: BFieldElement) -> Self
fn add(self, other: BFieldElement) -> Self
+ operation. Read moresource§impl Add<XFieldElement> for BFieldElement
impl Add<XFieldElement> for BFieldElement
The bfe + xfe -> xfe instance belongs to BFieldElement.
§type Output = XFieldElement
type Output = XFieldElement
+ operator.source§fn add(self, other: XFieldElement) -> XFieldElement
fn add(self, other: XFieldElement) -> XFieldElement
+ operation. Read moresource§impl Add for BFieldElement
impl Add for BFieldElement
source§impl AddAssign<BFieldElement> for XFieldElement
impl AddAssign<BFieldElement> for XFieldElement
source§fn add_assign(&mut self, rhs: BFieldElement)
fn add_assign(&mut self, rhs: BFieldElement)
+= operation. Read moresource§impl AddAssign for BFieldElement
impl AddAssign for BFieldElement
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moresource§impl<'a> Arbitrary<'a> for BFieldElement
impl<'a> Arbitrary<'a> for BFieldElement
source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Self from the given unstructured data. Read moresource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moresource§impl BFieldCodec for BFieldElement
impl BFieldCodec for BFieldElement
type Error = BFieldCodecError
fn decode(sequence: &[BFieldElement]) -> Result<Box<Self>, Self::Error>
fn encode(&self) -> Vec<BFieldElement>
source§fn static_length() -> Option<usize>
fn static_length() -> Option<usize>
source§impl Clone for BFieldElement
impl Clone for BFieldElement
source§fn clone(&self) -> BFieldElement
fn clone(&self) -> BFieldElement
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl CyclicGroupGenerator for BFieldElement
impl CyclicGroupGenerator for BFieldElement
source§impl Debug for BFieldElement
impl Debug for BFieldElement
source§impl Default for BFieldElement
impl Default for BFieldElement
source§fn default() -> BFieldElement
fn default() -> BFieldElement
source§impl<'de> Deserialize<'de> for BFieldElement
impl<'de> Deserialize<'de> for BFieldElement
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
source§impl Display for BFieldElement
impl Display for BFieldElement
source§impl Distribution<BFieldElement> for Standard
impl Distribution<BFieldElement> for Standard
source§fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> BFieldElement
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> BFieldElement
T, using rng as the source of randomness.source§fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T>
fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T>
T, using rng as
the source of randomness. Read moresource§impl Div for BFieldElement
impl Div for BFieldElement
source§impl FiniteField for BFieldElement
impl FiniteField for BFieldElement
source§impl From<&BFieldElement> for u64
impl From<&BFieldElement> for u64
source§fn from(elem: &BFieldElement) -> Self
fn from(elem: &BFieldElement) -> Self
source§impl From<BFieldElement> for [u8; 8]
impl From<BFieldElement> for [u8; 8]
Convert a B-field element to a byte array. The client uses this for its database.
source§fn from(bfe: BFieldElement) -> Self
fn from(bfe: BFieldElement) -> Self
source§impl From<BFieldElement> for u64
impl From<BFieldElement> for u64
source§fn from(elem: BFieldElement) -> Self
fn from(elem: BFieldElement) -> Self
source§impl From<i32> for BFieldElement
impl From<i32> for BFieldElement
source§impl From<u16> for BFieldElement
impl From<u16> for BFieldElement
source§impl From<u32> for BFieldElement
impl From<u32> for BFieldElement
source§impl From<u64> for BFieldElement
impl From<u64> for BFieldElement
source§impl From<u8> for BFieldElement
impl From<u8> for BFieldElement
source§impl FromStr for BFieldElement
impl FromStr for BFieldElement
source§impl GetSize for BFieldElement
impl GetSize for BFieldElement
source§fn get_stack_size() -> usize
fn get_stack_size() -> usize
source§fn get_heap_size(&self) -> usize
fn get_heap_size(&self) -> usize
source§impl Hash for BFieldElement
impl Hash for BFieldElement
source§impl Inverse for BFieldElement
impl Inverse for BFieldElement
source§impl ModPowU32 for BFieldElement
impl ModPowU32 for BFieldElement
fn mod_pow_u32(&self, exp: u32) -> Self
source§impl ModPowU64 for BFieldElement
impl ModPowU64 for BFieldElement
fn mod_pow_u64(&self, pow: u64) -> Self
source§impl Mul<BFieldElement> for XFieldElement
impl Mul<BFieldElement> for XFieldElement
XField * BField means scalar multiplication of the BFieldElement onto each coefficient of the XField.
§type Output = XFieldElement
type Output = XFieldElement
* operator.source§fn mul(self, other: BFieldElement) -> Self
fn mul(self, other: BFieldElement) -> Self
* operation. Read moresource§impl Mul<XFieldElement> for BFieldElement
impl Mul<XFieldElement> for BFieldElement
§type Output = XFieldElement
type Output = XFieldElement
* operator.source§fn mul(self, other: XFieldElement) -> XFieldElement
fn mul(self, other: XFieldElement) -> XFieldElement
* operation. Read moresource§impl Mul for BFieldElement
impl Mul for BFieldElement
source§impl MulAssign<BFieldElement> for XFieldElement
impl MulAssign<BFieldElement> for XFieldElement
source§fn mul_assign(&mut self, rhs: BFieldElement)
fn mul_assign(&mut self, rhs: BFieldElement)
*= operation. Read moresource§impl MulAssign for BFieldElement
impl MulAssign for BFieldElement
source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read moresource§impl Neg for BFieldElement
impl Neg for BFieldElement
source§impl One for BFieldElement
impl One for BFieldElement
source§impl PartialEq for BFieldElement
impl PartialEq for BFieldElement
source§fn eq(&self, other: &BFieldElement) -> bool
fn eq(&self, other: &BFieldElement) -> bool
self and other values to be equal, and is used
by ==.source§impl PrimitiveRootOfUnity for BFieldElement
impl PrimitiveRootOfUnity for BFieldElement
fn primitive_root_of_unity(n: u64) -> Option<BFieldElement>
source§impl Serialize for BFieldElement
impl Serialize for BFieldElement
source§impl Sub<BFieldElement> for XFieldElement
impl Sub<BFieldElement> for XFieldElement
§type Output = XFieldElement
type Output = XFieldElement
- operator.source§fn sub(self, other: BFieldElement) -> Self
fn sub(self, other: BFieldElement) -> Self
- operation. Read moresource§impl Sub<XFieldElement> for BFieldElement
impl Sub<XFieldElement> for BFieldElement
§type Output = XFieldElement
type Output = XFieldElement
- operator.source§fn sub(self, other: XFieldElement) -> XFieldElement
fn sub(self, other: XFieldElement) -> XFieldElement
- operation. Read moresource§impl Sub for BFieldElement
impl Sub for BFieldElement
source§impl SubAssign<BFieldElement> for XFieldElement
impl SubAssign<BFieldElement> for XFieldElement
source§fn sub_assign(&mut self, rhs: BFieldElement)
fn sub_assign(&mut self, rhs: BFieldElement)
-= operation. Read moresource§impl SubAssign for BFieldElement
impl SubAssign for BFieldElement
source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read moresource§impl Sum for BFieldElement
impl Sum for BFieldElement
source§impl TryFrom<BFieldElement> for u32
impl TryFrom<BFieldElement> for u32
§type Error = TryFromIntError
type Error = TryFromIntError
source§impl Zero for BFieldElement
impl Zero for BFieldElement
impl Copy for BFieldElement
impl Eq for BFieldElement
impl StructuralPartialEq for BFieldElement
Auto Trait Implementations§
impl Freeze for BFieldElement
impl RefUnwindSafe for BFieldElement
impl Send for BFieldElement
impl Sync for BFieldElement
impl Unpin for BFieldElement
impl UnwindSafe for BFieldElement
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more