pub struct Field { /* private fields */ }
Expand description
Field element for secp256k1.
Implementations
sourceimpl Field
impl Field
pub 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
sourceimpl<'a> AddAssign<&'a Field> for Field
impl<'a> AddAssign<&'a Field> for Field
sourcefn add_assign(&mut self, other: &'a Field)
fn add_assign(&mut self, other: &'a Field)
Performs the +=
operation. Read more
sourceimpl AddAssign<Field> for Field
impl AddAssign<Field> for Field
sourcefn add_assign(&mut self, other: Field)
fn add_assign(&mut self, other: Field)
Performs the +=
operation. Read more
sourceimpl<'a> MulAssign<&'a Field> for Field
impl<'a> MulAssign<&'a Field> for Field
sourcefn mul_assign(&mut self, other: &'a Field)
fn mul_assign(&mut self, other: &'a Field)
Performs the *=
operation. Read more
sourceimpl MulAssign<Field> for Field
impl MulAssign<Field> for Field
sourcefn mul_assign(&mut self, other: Field)
fn mul_assign(&mut self, other: Field)
Performs the *=
operation. Read more
sourceimpl Ord for Field
impl Ord for Field
sourceimpl PartialOrd<Field> for Field
impl PartialOrd<Field> for Field
sourcefn partial_cmp(&self, other: &Field) -> Option<Ordering>
fn partial_cmp(&self, other: &Field) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Eq for Field
Auto Trait Implementations
impl RefUnwindSafe for Field
impl Send for Field
impl Sync for Field
impl Unpin for Field
impl UnwindSafe for Field
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more