pub struct Field { /* private fields */ }
Expand description
Field element for secp256k1.
Implementations§
Source§impl Field
impl Field
pub const fn new_raw( d9: u32, d8: u32, d7: u32, d6: u32, d5: u32, d4: u32, d3: u32, d2: u32, d1: u32, d0: u32, ) -> Field
pub const fn new( d7: u32, d6: u32, d5: u32, d4: u32, d3: u32, d2: u32, d1: u32, d0: u32, ) -> Field
pub fn from_int(a: u32) -> Field
Sourcepub fn normalize_weak(&mut self)
pub fn normalize_weak(&mut self)
Weakly normalize a field element: reduce it magnitude to 1, but don’t fully normalize.
Sourcepub fn normalize_var(&mut self)
pub fn normalize_var(&mut self)
Normalize a field element, without constant-time guarantee.
Sourcepub fn normalizes_to_zero(&self) -> bool
pub fn normalizes_to_zero(&self) -> bool
Verify whether a field element represents zero i.e. would normalize to a zero value. The field implementation may optionally normalize the input, but this should not be relied upon.
Sourcepub fn normalizes_to_zero_var(&self) -> bool
pub fn normalizes_to_zero_var(&self) -> bool
Verify whether a field element represents zero i.e. would normalize to a zero value. The field implementation may optionally normalize the input, but this should not be relied upon.
Sourcepub fn set_int(&mut self, a: u32)
pub fn set_int(&mut self, a: u32)
Set a field element equal to a small integer. Resulting field element is normalized.
Sourcepub fn is_zero(&self) -> bool
pub fn is_zero(&self) -> bool
Verify whether a field element is zero. Requires the input to be normalized.
Sourcepub fn is_odd(&self) -> bool
pub fn is_odd(&self) -> bool
Check the “oddness” of a field element. Requires the input to be normalized.
Sourcepub fn set_b32(&mut self, a: &[u8; 32]) -> bool
pub fn set_b32(&mut self, a: &[u8; 32]) -> bool
Set a field element equal to 32-byte big endian value. If successful, the resulting field element is normalized.
pub fn fill_b32(&self, r: &mut [u8; 32])
Sourcepub fn b32(&self) -> [u8; 32]
pub fn b32(&self) -> [u8; 32]
Convert a field element to a 32-byte big endian value. Requires the input to be normalized.
Sourcepub fn neg_in_place(&mut self, other: &Field, m: u32)
pub fn neg_in_place(&mut self, other: &Field, m: u32)
Set a field element equal to the additive inverse of another. Takes a maximum magnitude of the input as an argument. The magnitude of the output is one higher.
Sourcepub fn neg(&self, m: u32) -> Field
pub fn neg(&self, m: u32) -> Field
Compute the additive inverse of this element. Takes the maximum expected magnitude of this element as an argument.
Sourcepub fn mul_int(&mut self, a: u32)
pub fn mul_int(&mut self, a: u32)
Multiplies the passed field element with a small integer constant. Multiplies the magnitude by that small integer.
Sourcepub fn cmp_var(&self, other: &Field) -> Ordering
pub fn cmp_var(&self, other: &Field) -> Ordering
Compare two field elements. Requires both inputs to be normalized.
pub fn eq_var(&self, other: &Field) -> bool
Sourcepub fn mul_in_place(&mut self, a: &Field, b: &Field)
pub fn mul_in_place(&mut self, a: &Field, b: &Field)
Sets a field element to be the product of two others. Requires the inputs’ magnitudes to be at most 8. The output magnitude is 1 (but not guaranteed to be normalized).
Sourcepub fn sqr_in_place(&mut self, a: &Field)
pub fn sqr_in_place(&mut self, a: &Field)
Sets a field element to be the square of another. Requires the input’s magnitude to be at most 8. The output magnitude is 1 (but not guaranteed to be normalized).
pub fn sqr(&self) -> Field
Sourcepub fn sqrt(&self) -> (Field, bool)
pub fn sqrt(&self) -> (Field, bool)
If a has a square root, it is computed in r and 1 is returned. If a does not have a square root, the root of its negation is computed and 0 is returned. The input’s magnitude can be at most 8. The output magnitude is 1 (but not guaranteed to be normalized). The result in r will always be a square itself.
Sourcepub fn inv(&self) -> Field
pub fn inv(&self) -> Field
Sets a field element to be the (modular) inverse of another. Requires the input’s magnitude to be at most 8. The output magnitude is 1 (but not guaranteed to be normalized).
Sourcepub fn inv_var(&self) -> Field
pub fn inv_var(&self) -> Field
Potentially faster version of secp256k1_fe_inv, without constant-time guarantee.
Sourcepub fn is_quad_var(&self) -> bool
pub fn is_quad_var(&self) -> bool
Checks whether a field element is a quadratic residue.
Trait Implementations§
Source§impl<'a> AddAssign<&'a Field> for Field
impl<'a> AddAssign<&'a Field> for Field
Source§fn add_assign(&mut self, other: &'a Field)
fn add_assign(&mut self, other: &'a Field)
+=
operation. Read moreSource§impl AddAssign for Field
impl AddAssign for Field
Source§fn add_assign(&mut self, other: Field)
fn add_assign(&mut self, other: Field)
+=
operation. Read moreSource§impl From<FieldStorage> for Field
impl From<FieldStorage> for Field
Source§fn from(a: FieldStorage) -> Field
fn from(a: FieldStorage) -> Field
Source§impl Into<FieldStorage> for Field
impl Into<FieldStorage> for Field
Source§fn into(self) -> FieldStorage
fn into(self) -> FieldStorage
Source§impl<'a> MulAssign<&'a Field> for Field
impl<'a> MulAssign<&'a Field> for Field
Source§fn mul_assign(&mut self, other: &'a Field)
fn mul_assign(&mut self, other: &'a Field)
*=
operation. Read moreSource§impl MulAssign for Field
impl MulAssign for Field
Source§fn mul_assign(&mut self, other: Field)
fn mul_assign(&mut self, other: Field)
*=
operation. Read more