Struct libsecp256k1_core::curve::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

§

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

§

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

§

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

§

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 + PartialOrd,

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

impl PartialEq for Field

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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

This method 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

This method 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

This method 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

This method 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: Copy,

source§

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

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

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

source§

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

🔬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

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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>,

§

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.