pub struct Field128(/* private fields */);
Expand description
GF(340282366920938462946865773367900766209)
, a 128-bit field.
This structure represents a field element in a prime order field. The concrete
representation of the element is via the Montgomery domain. For an element n
in
GF(p)
, we store n * R^-1 mod p
(where R
is a given power of two). This
representation enables using a more efficient (and branchless) multiplication algorithm,
at the expense of having to convert elements between their Montgomery domain
representation and natural representation. For calculations with many multiplications or
exponentiations, this is worthwhile.
As an invariant, this integer representing the field element in the Montgomery domain
must be less than the field modulus, p
.
Trait Implementations§
source§impl AddAssign for Field128
impl AddAssign for Field128
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the
+=
operation. Read moresource§impl ConditionallySelectable for Field128
impl ConditionallySelectable for Field128
source§impl ConstantTimeEq for Field128
impl ConstantTimeEq for Field128
source§impl Decode for Field128
impl Decode for Field128
source§fn decode(bytes: &mut Cursor<&[u8]>) -> Result<Self, CodecError>
fn decode(bytes: &mut Cursor<&[u8]>) -> Result<Self, CodecError>
Read and decode an encoded object from
bytes
. On success, the decoded value is returned
and bytes
is advanced by the encoded size of the value. On failure, an error is returned
and no further attempt to read from bytes
should be made.source§fn get_decoded(bytes: &[u8]) -> Result<Self, CodecError>
fn get_decoded(bytes: &[u8]) -> Result<Self, CodecError>
Convenience method to get a decoded value. Returns an error if
Self::decode
fails, or if
there are any bytes left in bytes
after decoding a value.source§impl<'de> Deserialize<'de> for Field128
impl<'de> Deserialize<'de> for Field128
source§fn deserialize<D: Deserializer<'de>>(
deserializer: D
) -> Result<Field128, D::Error>
fn deserialize<D: Deserializer<'de>>( deserializer: D ) -> Result<Field128, D::Error>
Deserialize this value from the given Serde deserializer. Read more
source§impl Distribution<Field128> for Standard
impl Distribution<Field128> for Standard
source§impl DivAssign for Field128
impl DivAssign for Field128
source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
Performs the
/=
operation. Read moresource§impl Encode for Field128
impl Encode for Field128
source§fn encode(&self, bytes: &mut Vec<u8>) -> Result<(), CodecError>
fn encode(&self, bytes: &mut Vec<u8>) -> Result<(), CodecError>
Append the encoded form of this object to the end of
bytes
, growing the vector as needed.source§fn encoded_len(&self) -> Option<usize>
fn encoded_len(&self) -> Option<usize>
Returns an optional hint indicating how many bytes will be required to encode this value, or
None
by default.source§fn get_encoded(&self) -> Result<Vec<u8>, CodecError>
fn get_encoded(&self) -> Result<Vec<u8>, CodecError>
Convenience method to encode a value into a new
Vec<u8>
.source§impl FftFriendlyFieldElement for Field128
impl FftFriendlyFieldElement for Field128
source§fn generator() -> Self
fn generator() -> Self
Returns the generator of the multiplicative subgroup of size
FftFriendlyFieldElement::generator_order
.source§fn generator_order() -> Self::Integer
fn generator_order() -> Self::Integer
Returns the size of the multiplicative subgroup generated by
FftFriendlyFieldElement::generator
.source§impl FieldElement for Field128
impl FieldElement for Field128
source§const ENCODED_SIZE: usize = 16usize
const ENCODED_SIZE: usize = 16usize
Size in bytes of an encoded field element.
source§fn inv(&self) -> Self
fn inv(&self) -> Self
Modular inversion, i.e.,
self^-1 (mod p)
. If self
is 0, then the output is undefined.source§fn slice_into_byte_vec(values: &[Self]) -> Vec<u8>
fn slice_into_byte_vec(values: &[Self]) -> Vec<u8>
👎Deprecated
Convert a slice of field elements into a vector of bytes. Read more
source§fn byte_slice_into_vec(bytes: &[u8]) -> Result<Vec<Self>, FieldError>
fn byte_slice_into_vec(bytes: &[u8]) -> Result<Vec<Self>, FieldError>
👎Deprecated
Convert a slice of bytes into a vector of field elements. The slice is interpreted as a
sequence of
Self::ENCODED_SIZE
-byte sequences. Read moresource§impl FieldElementWithInteger for Field128
impl FieldElementWithInteger for Field128
source§fn encode_as_bitvector(
input: Self::Integer,
bits: usize
) -> Result<BitvectorRepresentationIter<Self>, FieldError>
fn encode_as_bitvector( input: Self::Integer, bits: usize ) -> Result<BitvectorRepresentationIter<Self>, FieldError>
Encode the integer
input
as a sequence of bits in two’s complement representation, least
significant bit first, and then map each bit to a field element. Read moresource§fn decode_bitvector(input: &[Self]) -> Result<Self, FieldError>
fn decode_bitvector(input: &[Self]) -> Result<Self, FieldError>
Inverts the encoding done by
Self::encode_as_bitvector
, and returns a single field
element. Read moresource§impl MulAssign for Field128
impl MulAssign for Field128
source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
Performs the
*=
operation. Read moresource§impl SubAssign for Field128
impl SubAssign for Field128
source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Performs the
-=
operation. Read moresource§impl<'a> TryFrom<&'a [u8]> for Field128
impl<'a> TryFrom<&'a [u8]> for Field128
§type Error = FieldError
type Error = FieldError
The type returned in the event of a conversion error.
impl Copy for Field128
impl Eq for Field128
Auto Trait Implementations§
impl Freeze for Field128
impl RefUnwindSafe for Field128
impl Send for Field128
impl Sync for Field128
impl Unpin for Field128
impl UnwindSafe for Field128
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
Mutably borrows from an owned value. Read more
source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Casts the value.
source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
source§impl<T> ConditionallyNegatable for T
impl<T> ConditionallyNegatable for T
source§fn conditional_negate(&mut self, choice: Choice)
fn conditional_negate(&mut self, choice: Choice)
source§impl<T> FmtForward for T
impl<T> FmtForward for T
source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
Causes
self
to use its Binary
implementation when Debug
-formatted.source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
Causes
self
to use its Display
implementation when
Debug
-formatted.source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
Causes
self
to use its LowerExp
implementation when
Debug
-formatted.source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
Causes
self
to use its LowerHex
implementation when
Debug
-formatted.source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
Causes
self
to use its Octal
implementation when Debug
-formatted.source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
Causes
self
to use its Pointer
implementation when
Debug
-formatted.source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
Causes
self
to use its UpperExp
implementation when
Debug
-formatted.source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
Causes
self
to use its UpperHex
implementation when
Debug
-formatted.source§impl<F> IdpfValue for Fwhere
F: FieldElement,
impl<F> IdpfValue for Fwhere
F: FieldElement,
§type ValueParameter = ()
type ValueParameter = ()
Available on crate features
crypto-dependencies
and experimental
only.Any run-time parameters needed to produce a value.
source§fn generate<S>(seed_stream: &mut S, _: &()) -> Fwhere
S: RngCore,
fn generate<S>(seed_stream: &mut S, _: &()) -> Fwhere
S: RngCore,
Available on crate features
crypto-dependencies
and experimental
only.Generate a pseudorandom value from a seed stream.
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>
Converts
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>
Converts
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 moresource§impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
source§fn lossless_try_into(self) -> Option<Dst>
fn lossless_try_into(self) -> Option<Dst>
Performs the conversion.
source§impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
source§fn lossy_into(self) -> Dst
fn lossy_into(self) -> Dst
Performs the conversion.
source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Casts the value.
source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Casts the value.
source§impl<D, T> ParameterizedDecode<T> for D
impl<D, T> ParameterizedDecode<T> for D
source§fn decode_with_param(
_decoding_parameter: &T,
bytes: &mut Cursor<&[u8]>
) -> Result<D, CodecError>
fn decode_with_param( _decoding_parameter: &T, bytes: &mut Cursor<&[u8]> ) -> Result<D, CodecError>
Read and decode an encoded object from
bytes
. decoding_parameter
provides details of the
wire encoding such as lengths of different portions of the message. On success, the decoded
value is returned and bytes
is advanced by the encoded size of the value. On failure, an
error is returned and no further attempt to read from bytes
should be made.source§fn get_decoded_with_param(
decoding_parameter: &P,
bytes: &[u8]
) -> Result<Self, CodecError>
fn get_decoded_with_param( decoding_parameter: &P, bytes: &[u8] ) -> Result<Self, CodecError>
Convenience method to get a decoded value. Returns an error if
Self::decode_with_param
fails, or if there are any bytes left in bytes
after decoding a value.source§impl<E, T> ParameterizedEncode<T> for E
impl<E, T> ParameterizedEncode<T> for E
source§fn encode_with_param(
&self,
_encoding_parameter: &T,
bytes: &mut Vec<u8>
) -> Result<(), CodecError>
fn encode_with_param( &self, _encoding_parameter: &T, bytes: &mut Vec<u8> ) -> Result<(), CodecError>
Append the encoded form of this object to the end of
bytes
, growing the vector as needed.
encoding_parameter
provides details of the wire encoding, used to control how the value
is encoded.source§fn encoded_len_with_param(&self, _encoding_parameter: &T) -> Option<usize>
fn encoded_len_with_param(&self, _encoding_parameter: &T) -> Option<usize>
Returns an optional hint indicating how many bytes will be required to encode this value, or
None
by default.source§fn get_encoded_with_param(
&self,
encoding_parameter: &P
) -> Result<Vec<u8>, CodecError>
fn get_encoded_with_param( &self, encoding_parameter: &P ) -> Result<Vec<u8>, CodecError>
Convenience method to encode a value into a new
Vec<u8>
.source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Pipes by value. This is generally the method you want to use. Read more
source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
Borrows
self
and passes that borrow into the pipe function. Read moresource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
Mutably borrows
self
and passes that borrow into the pipe function. Read moresource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> R
source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
Borrows
self
, then passes self.as_ref()
into the pipe function.source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
Mutably borrows
self
, then passes self.as_mut()
into the pipe
function.source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
Borrows
self
, then passes self.deref()
into the pipe function.source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Casts the value.
source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
source§impl<T> Tap for T
impl<T> Tap for T
source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Immutable access to the
Borrow<B>
of a value. Read moresource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
Mutable access to the
BorrowMut<B>
of a value. Read moresource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
Immutable access to the
AsRef<R>
view of a value. Read moresource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
Mutable access to the
AsMut<R>
view of a value. Read moresource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Immutable access to the
Deref::Target
of a value. Read moresource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Mutable access to the
Deref::Target
of a value. Read moresource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
Calls
.tap()
only in debug builds, and is erased in release builds.source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
Calls
.tap_mut()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
Calls
.tap_borrow()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
Calls
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
Calls
.tap_ref()
only in debug builds, and is erased in release
builds.source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
Calls
.tap_ref_mut()
only in debug builds, and is erased in release
builds.source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
Calls
.tap_deref()
only in debug builds, and is erased in release
builds.source§impl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
source§fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
Casts the value.
source§impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
source§fn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
Casts the value.
source§impl<T> WrappingAs for T
impl<T> WrappingAs for T
source§fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
Casts the value.
source§impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
source§fn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
Casts the value.