ckb_crypto::secp

Struct SECP256K1

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

The reference to lazily-initialized static secp256k1 engine, used to execute all signature operations

Methods from Deref<Target = Secp256k1<All>>§

Source

pub fn sign_ecdsa_recoverable( &self, msg: &Message, sk: &SecretKey, ) -> RecoverableSignature

Constructs a signature for msg using the secret key sk and RFC6979 nonce Requires a signing-capable context.

Source

pub fn sign_ecdsa_recoverable_with_noncedata( &self, msg: &Message, sk: &SecretKey, noncedata: &[u8; 32], ) -> RecoverableSignature

Constructs a signature for msg using the secret key sk and RFC6979 nonce and includes 32 bytes of noncedata in the nonce generation via inclusion in one of the hash operations during nonce generation. This is useful when multiple signatures are needed for the same Message and SecretKey while still using RFC6979. Requires a signing-capable context.

Source

pub fn recover_ecdsa( &self, msg: &Message, sig: &RecoverableSignature, ) -> Result<PublicKey, Error>

Determines the public key for which sig is a valid signature for msg. Requires a verify-capable context.

Source

pub fn sign_ecdsa(&self, msg: &Message, sk: &SecretKey) -> Signature

Constructs a signature for msg using the secret key sk and RFC6979 nonce Requires a signing-capable context.

Source

pub fn sign_ecdsa_with_noncedata( &self, msg: &Message, sk: &SecretKey, noncedata: &[u8; 32], ) -> Signature

Constructs a signature for msg using the secret key sk and RFC6979 nonce and includes 32 bytes of noncedata in the nonce generation via inclusion in one of the hash operations during nonce generation. This is useful when multiple signatures are needed for the same Message and SecretKey while still using RFC6979. Requires a signing-capable context.

Source

pub fn sign_ecdsa_grind_r( &self, msg: &Message, sk: &SecretKey, bytes_to_grind: usize, ) -> Signature

Constructs a signature for msg using the secret key sk, RFC6979 nonce and “grinds” the nonce by passing extra entropy if necessary to produce a signature that is less than 71 - bytes_to_grind bytes. The number of signing operation performed by this function is exponential in the number of bytes grinded. Requires a signing capable context.

Source

pub fn sign_ecdsa_low_r(&self, msg: &Message, sk: &SecretKey) -> Signature

Constructs a signature for msg using the secret key sk, RFC6979 nonce and “grinds” the nonce by passing extra entropy if necessary to produce a signature that is less than 71 bytes and compatible with the low r signature implementation of bitcoin core. In average, this function will perform two signing operations. Requires a signing capable context.

Source

pub fn verify_ecdsa( &self, msg: &Message, sig: &Signature, pk: &PublicKey, ) -> Result<(), Error>

Checks that sig is a valid ECDSA signature for msg using the public key pubkey. Returns Ok(()) on success. Note that this function cannot be used for Bitcoin consensus checking since there may exist signatures which OpenSSL would verify but not libsecp256k1, or vice-versa. Requires a verify-capable context.

let message = Message::from_digest_slice(&[0xab; 32]).expect("32 bytes");
let sig = secp.sign_ecdsa(&message, &secret_key);
assert_eq!(secp.verify_ecdsa(&message, &sig, &public_key), Ok(()));

let message = Message::from_digest_slice(&[0xcd; 32]).expect("32 bytes");
assert_eq!(secp.verify_ecdsa(&message, &sig, &public_key), Err(Error::IncorrectSignature));
Source

pub fn sign_schnorr_no_aux_rand( &self, msg: &Message, keypair: &Keypair, ) -> Signature

Creates a schnorr signature without using any auxiliary random data.

Source

pub fn sign_schnorr_with_aux_rand( &self, msg: &Message, keypair: &Keypair, aux_rand: &[u8; 32], ) -> Signature

Creates a schnorr signature using the given auxiliary random data.

Source

pub fn verify_schnorr( &self, sig: &Signature, msg: &Message, pubkey: &XOnlyPublicKey, ) -> Result<(), Error>

Verifies a schnorr signature.

Source

pub fn ctx(&self) -> NonNull<Context>

Getter for the raw pointer to the underlying secp256k1 context. This shouldn’t be needed with normal usage of the library. It enables extending the Secp256k1 with more cryptographic algorithms outside of this crate.

Trait Implementations§

Source§

impl Deref for SECP256K1

Source§

type Target = Secp256k1<All>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Secp256k1<All>

Dereferences the value.
Source§

impl LazyStatic for SECP256K1

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> 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, 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V