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
Sourcepub const MINUS_TWO_INVERSE: Self = _
pub const MINUS_TWO_INVERSE: Self = _
-2^-1
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
👎Deprecated since 0.42.0: endianness must not be platform specific; use <&[u8]>::try_from()
instead
pub fn from_ne_bytes(bytes: &[u8]) -> BFieldElement
<&[u8]>::try_from()
insteadConvert 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 const fn raw_u64(&self) -> u64
pub const fn is_canonical(x: u64) -> bool
Trait Implementations§
Source§impl Add<BFieldElement> for XFieldElement
impl Add<BFieldElement> for XFieldElement
Source§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.
Source§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 ConstOne for BFieldElement
impl ConstOne for BFieldElement
Source§impl ConstZero for BFieldElement
impl ConstZero for BFieldElement
Source§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 i128
impl From<&BFieldElement> for i128
Source§fn from(elem: &BFieldElement) -> Self
fn from(elem: &BFieldElement) -> Self
Source§impl From<&BFieldElement> for i64
impl From<&BFieldElement> for i64
Source§fn from(elem: &BFieldElement) -> Self
fn from(elem: &BFieldElement) -> Self
Source§impl From<&BFieldElement> for u128
impl From<&BFieldElement> for u128
Source§fn from(elem: &BFieldElement) -> Self
fn from(elem: &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<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 i128
impl From<BFieldElement> for i128
Source§fn from(elem: BFieldElement) -> Self
fn from(elem: BFieldElement) -> Self
Source§impl From<BFieldElement> for i64
impl From<BFieldElement> for i64
Source§fn from(elem: BFieldElement) -> Self
fn from(elem: BFieldElement) -> Self
Source§impl From<BFieldElement> for u128
impl From<BFieldElement> for u128
Source§fn from(elem: BFieldElement) -> Self
fn from(elem: 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<i16> for BFieldElement
impl From<i16> for BFieldElement
Source§impl From<i32> for BFieldElement
impl From<i32> for BFieldElement
Source§impl From<i64> for BFieldElement
impl From<i64> for BFieldElement
Source§impl From<i8> for BFieldElement
impl From<i8> for BFieldElement
Source§impl From<isize> for BFieldElement
impl From<isize> for BFieldElement
Source§impl From<u128> for BFieldElement
impl From<u128> 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 From<usize> for BFieldElement
impl From<usize> 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.
Source§type Output = XFieldElement
type Output = XFieldElement
*
operator.Source§fn mul(self, other: BFieldElement) -> Self
fn mul(self, other: BFieldElement) -> Self
*
operation. Read moreSource§impl<FF, FF2> Mul<Polynomial<'_, FF>> for BFieldElement
impl<FF, FF2> Mul<Polynomial<'_, FF>> for BFieldElement
Source§type Output = Polynomial<'static, FF2>
type Output = Polynomial<'static, FF2>
*
operator.Source§impl Mul<XFieldElement> for BFieldElement
impl Mul<XFieldElement> for BFieldElement
Source§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§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
Source§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
Source§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<&[u8]> for BFieldElement
impl TryFrom<&[u8]> for BFieldElement
Source§impl TryFrom<&BFieldElement> for i16
impl TryFrom<&BFieldElement> for i16
Source§type Error = TryFromIntError
type Error = TryFromIntError
Source§impl TryFrom<&BFieldElement> for i32
impl TryFrom<&BFieldElement> for i32
Source§type Error = TryFromIntError
type Error = TryFromIntError
Source§impl TryFrom<&BFieldElement> for i8
impl TryFrom<&BFieldElement> for i8
Source§type Error = TryFromIntError
type Error = TryFromIntError
Source§impl TryFrom<&BFieldElement> for isize
impl TryFrom<&BFieldElement> for isize
Source§type Error = TryFromIntError
type Error = TryFromIntError
Source§impl TryFrom<&BFieldElement> for u16
impl TryFrom<&BFieldElement> for u16
Source§type Error = TryFromIntError
type Error = TryFromIntError
Source§impl TryFrom<&BFieldElement> for u32
impl TryFrom<&BFieldElement> for u32
Source§type Error = TryFromIntError
type Error = TryFromIntError
Source§impl TryFrom<&BFieldElement> for u8
impl TryFrom<&BFieldElement> for u8
Source§type Error = TryFromIntError
type Error = TryFromIntError
Source§impl TryFrom<&BFieldElement> for usize
impl TryFrom<&BFieldElement> for usize
Source§type Error = TryFromIntError
type Error = TryFromIntError
Source§impl TryFrom<BFieldElement> for i16
impl TryFrom<BFieldElement> for i16
Source§type Error = TryFromIntError
type Error = TryFromIntError
Source§impl TryFrom<BFieldElement> for i32
impl TryFrom<BFieldElement> for i32
Source§type Error = TryFromIntError
type Error = TryFromIntError
Source§impl TryFrom<BFieldElement> for i8
impl TryFrom<BFieldElement> for i8
Source§type Error = TryFromIntError
type Error = TryFromIntError
Source§impl TryFrom<BFieldElement> for isize
impl TryFrom<BFieldElement> for isize
Source§type Error = TryFromIntError
type Error = TryFromIntError
Source§impl TryFrom<BFieldElement> for u16
impl TryFrom<BFieldElement> for u16
Source§type Error = TryFromIntError
type Error = TryFromIntError
Source§impl TryFrom<BFieldElement> for u32
impl TryFrom<BFieldElement> for u32
Source§type Error = TryFromIntError
type Error = TryFromIntError
Source§impl TryFrom<BFieldElement> for u8
impl TryFrom<BFieldElement> for u8
Source§type Error = TryFromIntError
type Error = TryFromIntError
Source§impl TryFrom<BFieldElement> for usize
impl TryFrom<BFieldElement> for usize
Source§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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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