libsecp256k1_core::curve

Struct Field

Source
pub struct Field { /* private fields */ }
Expand description

Field element for secp256k1.

Implementations§

Source§

impl Field

Source

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

Source

pub const fn new( d7: u32, d6: u32, d5: u32, d4: u32, d3: u32, d2: u32, d1: u32, d0: u32, ) -> Self

Source

pub fn from_int(a: u32) -> Field

Source

pub fn normalize(&mut self)

Normalize a field element.

Source

pub fn normalize_weak(&mut self)

Weakly normalize a field element: reduce it magnitude to 1, but don’t fully normalize.

Source

pub fn normalize_var(&mut self)

Normalize a field element, without constant-time guarantee.

Source

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.

Source

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.

Source

pub fn set_int(&mut self, a: u32)

Set a field element equal to a small integer. Resulting field element is normalized.

Source

pub fn is_zero(&self) -> bool

Verify whether a field element is zero. Requires the input to be normalized.

Source

pub fn is_odd(&self) -> bool

Check the “oddness” of a field element. Requires the input to be normalized.

Source

pub fn clear(&mut self)

Sets a field element equal to zero, initializing all fields.

Source

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.

Source

pub fn fill_b32(&self, r: &mut [u8; 32])

Source

pub fn b32(&self) -> [u8; 32]

Convert a field element to a 32-byte big endian value. Requires the input to be normalized.

Source

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.

Source

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.

Source

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.

Source

pub fn cmp_var(&self, other: &Field) -> Ordering

Compare two field elements. Requires both inputs to be normalized.

Source

pub fn eq_var(&self, other: &Field) -> bool

Source

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).

Source

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).

Source

pub fn sqr(&self) -> Field

Source

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.

Source

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).

Source

pub fn inv_var(&self) -> Field

Potentially faster version of secp256k1_fe_inv, without constant-time guarantee.

Source

pub fn is_quad_var(&self) -> bool

Checks whether a field element is a quadratic residue.

Source

pub fn cmov(&mut self, other: &Field, flag: bool)

If flag is true, set *r equal to *a; otherwise leave it. Constant-time.

Trait Implementations§

Source§

impl<'a, 'b> Add<&'a Field> for &'b Field

Source§

type Output = Field

The resulting type after applying the + operator.
Source§

fn add(self, other: &'a Field) -> Field

Performs the + operation. Read more
Source§

impl Add for Field

Source§

type Output = Field

The resulting type after applying the + operator.
Source§

fn add(self, other: Field) -> Field

Performs the + operation. Read more
Source§

impl<'a> AddAssign<&'a Field> for Field

Source§

fn add_assign(&mut self, other: &'a Field)

Performs the += operation. Read more
Source§

impl AddAssign for Field

Source§

fn add_assign(&mut self, other: Field)

Performs the += operation. Read more
Source§

impl Clone for Field

Source§

fn clone(&self) -> Field

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Field

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Field

Source§

fn default() -> Field

Returns the “default value” for a type. Read more
Source§

impl From<FieldStorage> for Field

Source§

fn from(a: FieldStorage) -> Field

Converts to this type from the input type.
Source§

impl Into<FieldStorage> for Field

Source§

fn into(self) -> FieldStorage

Converts this type into the (usually inferred) input type.
Source§

impl<'a, 'b> Mul<&'a Field> for &'b Field

Source§

type Output = Field

The resulting type after applying the * operator.
Source§

fn mul(self, other: &'a Field) -> Field

Performs the * operation. Read more
Source§

impl Mul for Field

Source§

type Output = Field

The resulting type after applying the * operator.
Source§

fn mul(self, other: Field) -> Field

Performs the * operation. Read more
Source§

impl<'a> MulAssign<&'a Field> for Field

Source§

fn mul_assign(&mut self, other: &'a Field)

Performs the *= operation. Read more
Source§

impl MulAssign for Field

Source§

fn mul_assign(&mut self, other: Field)

Performs the *= operation. Read more
Source§

impl Ord for Field

Source§

fn cmp(&self, other: &Field) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Field

Source§

fn eq(&self, other: &Field) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Field

Source§

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 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for Field

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.