Skip to main content

Secp256k1

Struct Secp256k1 

Source
pub struct Secp256k1;
Expand description

secp256k1 (K-256) elliptic curve.

Specified in Certicom’s SECG in “SEC 2: Recommended Elliptic Curve Domain Parameters”:

https://www.secg.org/sec2-v2.pdf

The curve’s equation is y² = x³ + 7 over a ~256-bit prime field.

It’s primarily notable for usage in Bitcoin and other cryptocurrencies, particularly in conjunction with the Elliptic Curve Digital Signature Algorithm (ECDSA).

Trait Implementations§

Source§

impl AssociatedOid for Secp256k1

Available on crate feature pkcs8 only.
Source§

const OID: ObjectIdentifier

The OID associated with this type.
Source§

impl Clone for Secp256k1

Source§

fn clone(&self) -> Secp256k1

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Secp256k1

Source§

impl Curve for Secp256k1

Source§

const ORDER: Odd<U256> = ORDER

Curve order.

Source§

type FieldBytesSize = UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>

32-byte serialized field elements.

Source§

type Uint = Uint<crypto_bigint::::uint::U256::{constant#0}>

256-bit field modulus.

Source§

const FIELD_ENDIANNESS: ByteOrder = ByteOrder::BigEndian

Endianness used for serializing field elements of this curve.
Source§

impl CurveArithmetic for Secp256k1

Source§

type AffinePoint = AffinePoint

Elliptic curve point in affine coordinates.
Source§

type ProjectivePoint = ProjectivePoint

Elliptic curve point in projective coordinates. Read more
Source§

type Scalar = Scalar

Scalar field modulo this curve’s order. Read more
Source§

impl Debug for Secp256k1

Source§

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

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

impl DecompactPoint<Secp256k1> for AffinePoint

Decompaction using Taproot conventions as described in BIP 340.

Source§

fn decompact(x_bytes: &FieldBytes) -> CtOption<Self>

Attempt to decompact an elliptic curve point
Source§

impl DecompressPoint<Secp256k1> for AffinePoint

Source§

fn decompress(x_bytes: &FieldBytes, y_is_odd: Choice) -> CtOption<Self>

Attempt to decompress an elliptic curve point.
Source§

impl Default for Secp256k1

Source§

fn default() -> Secp256k1

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

impl DigestAlgorithm for Secp256k1

Available on crate feature sha256 only.
Source§

type Digest = Sha256

Preferred digest to use when computing ECDSA signatures for this elliptic curve. This is typically a member of the SHA-2 family.
Source§

impl EcdsaCurve for Secp256k1

Source§

const NORMALIZE_S: bool = true

Does this curve use low-S normalized signatures? Read more
Source§

impl Eq for Secp256k1

Source§

impl FieldArithmetic for Secp256k1

Source§

type FieldElement = FieldElement

Base field element type.
Source§

impl FromSec1Point<Secp256k1> for AffinePoint

Source§

fn from_sec1_point(encoded_point: &Sec1Point) -> CtOption<Self>

Attempts to parse the given Sec1Point as an SEC1-encoded AffinePoint.

§Returns

None value if encoded_point is not on the secp256k1 curve.

Source§

fn from_sec1_bytes(bytes: &[u8]) -> Result<Self, Error>

Decode curve point from the provided SEC1 encoding (compressed, uncompressed, or identity) using the Octet-String-to-Elliptic-Curve-Point conversion. Read more
Source§

fn from_encoded_point( point: &EncodedPoint<<C as Curve>::FieldBytesSize>, ) -> CtOption<Self>

👎Deprecated since 0.14.0:

use FromSec1Point::from_sec1_point instead

DEPRECATED: legacy name for FromSec1Point::from_sec1_point.
Source§

impl FromSec1Point<Secp256k1> for ProjectivePoint

Source§

fn from_sec1_point(p: &Sec1Point) -> CtOption<Self>

Decode curve point from a SEC1 Sec1Point.
Source§

fn from_sec1_bytes(bytes: &[u8]) -> Result<Self, Error>

Decode curve point from the provided SEC1 encoding (compressed, uncompressed, or identity) using the Octet-String-to-Elliptic-Curve-Point conversion. Read more
Source§

fn from_encoded_point( point: &EncodedPoint<<C as Curve>::FieldBytesSize>, ) -> CtOption<Self>

👎Deprecated since 0.14.0:

use FromSec1Point::from_sec1_point instead

DEPRECATED: legacy name for FromSec1Point::from_sec1_point.
Source§

impl Mul<&<Secp256k1 as CurveArithmetic>::AffinePoint> for Scalar

Source§

type Output = <Secp256k1 as CurveArithmetic>::ProjectivePoint

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &AffinePoint<Secp256k1>) -> ProjectivePoint<Secp256k1>

Performs the * operation. Read more
Source§

impl Mul<&<Secp256k1 as CurveArithmetic>::AffinePoint> for &Scalar

Source§

type Output = <Secp256k1 as CurveArithmetic>::ProjectivePoint

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &AffinePoint<Secp256k1>) -> ProjectivePoint<Secp256k1>

Performs the * operation. Read more
Source§

impl Mul<&<Secp256k1 as CurveArithmetic>::ProjectivePoint> for Scalar

Source§

type Output = <Secp256k1 as CurveArithmetic>::ProjectivePoint

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &ProjectivePoint<Secp256k1>) -> ProjectivePoint<Secp256k1>

Performs the * operation. Read more
Source§

impl Mul<&<Secp256k1 as CurveArithmetic>::ProjectivePoint> for &Scalar

Source§

type Output = <Secp256k1 as CurveArithmetic>::ProjectivePoint

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &ProjectivePoint<Secp256k1>) -> ProjectivePoint<Secp256k1>

Performs the * operation. Read more
Source§

impl Mul<<Secp256k1 as CurveArithmetic>::AffinePoint> for Scalar

Source§

type Output = <Secp256k1 as CurveArithmetic>::ProjectivePoint

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: AffinePoint<Secp256k1>) -> ProjectivePoint<Secp256k1>

Performs the * operation. Read more
Source§

impl Mul<<Secp256k1 as CurveArithmetic>::AffinePoint> for &Scalar

Source§

type Output = <Secp256k1 as CurveArithmetic>::ProjectivePoint

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: AffinePoint<Secp256k1>) -> ProjectivePoint<Secp256k1>

Performs the * operation. Read more
Source§

impl Mul<<Secp256k1 as CurveArithmetic>::ProjectivePoint> for Scalar

Source§

type Output = <Secp256k1 as CurveArithmetic>::ProjectivePoint

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: ProjectivePoint<Secp256k1>) -> ProjectivePoint<Secp256k1>

Performs the * operation. Read more
Source§

impl Mul<<Secp256k1 as CurveArithmetic>::ProjectivePoint> for &Scalar

Source§

type Output = <Secp256k1 as CurveArithmetic>::ProjectivePoint

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: ProjectivePoint<Secp256k1>) -> ProjectivePoint<Secp256k1>

Performs the * operation. Read more
Source§

impl MulVartime<&<Secp256k1 as CurveArithmetic>::AffinePoint> for Scalar

Source§

fn mul_vartime(self, rhs: &AffinePoint<Secp256k1>) -> ProjectivePoint<Secp256k1>

Multiply self by rhs in variable-time.
Source§

impl MulVartime<&<Secp256k1 as CurveArithmetic>::AffinePoint> for &Scalar

Source§

fn mul_vartime(self, rhs: &AffinePoint<Secp256k1>) -> ProjectivePoint<Secp256k1>

Multiply self by rhs in variable-time.
Source§

impl MulVartime<&<Secp256k1 as CurveArithmetic>::ProjectivePoint> for Scalar

Source§

fn mul_vartime( self, rhs: &ProjectivePoint<Secp256k1>, ) -> ProjectivePoint<Secp256k1>

Multiply self by rhs in variable-time.
Source§

impl MulVartime<&<Secp256k1 as CurveArithmetic>::ProjectivePoint> for &Scalar

Source§

fn mul_vartime( self, rhs: &ProjectivePoint<Secp256k1>, ) -> ProjectivePoint<Secp256k1>

Multiply self by rhs in variable-time.
Source§

impl MulVartime<<Secp256k1 as CurveArithmetic>::AffinePoint> for Scalar

Source§

fn mul_vartime(self, rhs: AffinePoint<Secp256k1>) -> ProjectivePoint<Secp256k1>

Multiply self by rhs in variable-time.
Source§

impl MulVartime<<Secp256k1 as CurveArithmetic>::AffinePoint> for &Scalar

Source§

fn mul_vartime(self, rhs: AffinePoint<Secp256k1>) -> ProjectivePoint<Secp256k1>

Multiply self by rhs in variable-time.
Source§

impl MulVartime<<Secp256k1 as CurveArithmetic>::ProjectivePoint> for Scalar

Source§

fn mul_vartime( self, rhs: ProjectivePoint<Secp256k1>, ) -> ProjectivePoint<Secp256k1>

Multiply self by rhs in variable-time.
Source§

impl MulVartime<<Secp256k1 as CurveArithmetic>::ProjectivePoint> for &Scalar

Source§

fn mul_vartime( self, rhs: ProjectivePoint<Secp256k1>, ) -> ProjectivePoint<Secp256k1>

Multiply self by rhs in variable-time.
Source§

impl Ord for Secp256k1

Source§

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

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · 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 Secp256k1

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for Secp256k1

Source§

fn partial_cmp(&self, other: &Secp256k1) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 PointCompression for Secp256k1

Source§

const COMPRESS_POINTS: bool = true

secp256k1 points are typically compressed.

Source§

impl PrimeCurve for Secp256k1

Source§

impl PrimeCurveWithBasepointTable<WINDOW_SIZE> for Secp256k1

Source§

const BASEPOINT_TABLE: &'static BasepointTable<ProjectivePoint, WINDOW_SIZE>

Basepoint table for this curve.
Source§

impl StructuralPartialEq for Secp256k1

Source§

impl ToSec1Point<Secp256k1> for AffinePoint

Source§

fn to_sec1_point(&self, compress: bool) -> Sec1Point

Serialize curve point as a SEC1 Sec1Point, optionally applying point compression according to the compress flag.
Source§

fn to_sec1_bytes(&self) -> Box<[u8]>

Encode curve point using the Elliptic-Curve-Point-to-Octet-String conversion and the point compression default for this curve as specified by the PointCompression trait.
Source§

fn to_compressed_point( &self, ) -> Array<u8, <<C as Curve>::FieldBytesSize as ModulusSize>::CompressedPointSize>

Serialize curve point as a CompressedPoint.
Source§

fn to_uncompressed_point( &self, ) -> Array<u8, <<C as Curve>::FieldBytesSize as ModulusSize>::UncompressedPointSize>

Serialize curve point as a CompressedPoint.
Source§

fn to_encoded_point( &self, compress: bool, ) -> EncodedPoint<<C as Curve>::FieldBytesSize>

👎Deprecated since 0.14.0:

use ToSec1Point::to_sec1_point instead

DEPRECATED: legacy name for ToSec1Point::to_sec1_point.
Source§

impl ToSec1Point<Secp256k1> for ProjectivePoint

Source§

fn to_sec1_point(&self, compress: bool) -> Sec1Point

Serialize curve point as a SEC1 Sec1Point, optionally applying point compression according to the compress flag.
Source§

fn to_sec1_bytes(&self) -> Box<[u8]>

Encode curve point using the Elliptic-Curve-Point-to-Octet-String conversion and the point compression default for this curve as specified by the PointCompression trait.
Source§

fn to_compressed_point( &self, ) -> Array<u8, <<C as Curve>::FieldBytesSize as ModulusSize>::CompressedPointSize>

Serialize curve point as a CompressedPoint.
Source§

fn to_uncompressed_point( &self, ) -> Array<u8, <<C as Curve>::FieldBytesSize as ModulusSize>::UncompressedPointSize>

Serialize curve point as a CompressedPoint.
Source§

fn to_encoded_point( &self, compress: bool, ) -> EncodedPoint<<C as Curve>::FieldBytesSize>

👎Deprecated since 0.14.0:

use ToSec1Point::to_sec1_point instead

DEPRECATED: legacy name for ToSec1Point::to_sec1_point.

Auto Trait Implementations§

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, dest: *mut u8)

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

impl<T> DynAssociatedOid for T
where T: AssociatedOid,

Source§

fn oid(&self) -> ObjectIdentifier

Get the OID associated with this value.
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.
Source§

impl<C> ValidatePublicKey for C

Source§

fn validate_public_key( secret_key: &SecretKey<C>, public_key: &EncodedPoint<<C as Curve>::FieldBytesSize>, ) -> Result<(), Error>

Validate that the given Sec1Point is a valid public key for the provided secret value. Read more