Struct libsecp256k1_core::curve::Field
source · 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, ) -> Self
pub const fn new( d7: u32, d6: u32, d5: u32, d4: u32, d3: u32, d2: u32, d1: u32, d0: u32, ) -> Self
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 moresource§impl Ord for Field
impl Ord for Field
source§impl PartialEq for Field
impl PartialEq for Field
source§impl PartialOrd for Field
impl PartialOrd for Field
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl Copy for Field
impl Eq for Field
Auto Trait Implementations§
impl Freeze for Field
impl RefUnwindSafe for Field
impl Send for Field
impl Sync for Field
impl Unpin for Field
impl UnwindSafe for Field
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: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)