Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ don't have to create and pass in a context object in all the APIs - BOOM!
* Remove context from the API [#844](https://github.com/rust-bitcoin/rust-secp256k1/pull/844)
* Fix rerandomization seed usage [#855](https://github.com/rust-bitcoin/rust-secp256k1/pull/855)

(Note, to help with the upgrade path we left the methods on the context in place but deprecated.)

And we also did:

* Remove the `bitcoin-hashes` feature (and dependency) [#837](https://github.com/rust-bitcoin/rust-secp256k1/pull/837)
Expand Down
2 changes: 1 addition & 1 deletion Cargo-minimal.lock
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2"

[[package]]
name = "secp256k1"
version = "0.32.0-beta.0"
version = "0.32.0-beta.1"
dependencies = [
"arbitrary",
"bincode",
Expand Down
2 changes: 1 addition & 1 deletion Cargo-recent.lock
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294"

[[package]]
name = "secp256k1"
version = "0.32.0-beta.0"
version = "0.32.0-beta.1"
dependencies = [
"arbitrary",
"bincode",
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "secp256k1"
version = "0.32.0-beta.0"
version = "0.32.0-beta.1"
authors = [ "Dawid Ciężarkiewicz <[email protected]>",
"Andrew Poelstra <[email protected]>" ]
license = "CC0-1.0"
Expand Down
2 changes: 2 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
default:
@just --list

alias ulf := update-lock-files

# Cargo build everything.
build:
cargo build --workspace --all-targets --all-features
Expand Down
89 changes: 88 additions & 1 deletion src/ecdsa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use core::{fmt, ptr, str};
pub use self::recovery::{RecoverableSignature, RecoveryId};
pub use self::serialized_signature::SerializedSignature;
use crate::ffi::CPtr;
use crate::{ecdsa, ffi, from_hex, Error, Message, PublicKey, Secp256k1, SecretKey};
use crate::{
ecdsa, ffi, from_hex, Error, Message, PublicKey, Secp256k1, SecretKey, Signing, Verification,
};

/// An ECDSA signature
#[derive(Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -341,6 +343,91 @@ pub fn sign_low_r(msg: impl Into<Message>, sk: &SecretKey) -> Signature {
sign_grind_with_check(msg, sk, compact_sig_has_zero_first_bit)
}

impl<C: Signing> Secp256k1<C> {
/// Constructs a signature for `msg` using the secret key `sk` and RFC6979 nonce
/// Requires a signing-capable context.
#[deprecated(since = "0.32.0", note = "use ecdsa::sign instead")]
pub fn sign_ecdsa(&self, msg: impl Into<Message>, sk: &SecretKey) -> Signature {
self::sign(msg, sk)
}

/// 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.
#[deprecated(since = "0.32.0", note = "use ecdsa::sign_with_noncedata instead")]
pub fn sign_ecdsa_with_noncedata(
&self,
msg: impl Into<Message>,
sk: &SecretKey,
noncedata: &[u8; 32],
) -> Signature {
self::sign_with_noncedata(msg, sk, noncedata)
}

/// 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.
#[deprecated(since = "0.32.0", note = "use ecdsa::sign_grind_r instead")]
pub fn sign_ecdsa_grind_r(
&self,
msg: impl Into<Message>,
sk: &SecretKey,
bytes_to_grind: usize,
) -> Signature {
self::sign_grind_r(msg, sk, bytes_to_grind)
}

/// 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.
#[deprecated(since = "0.32.0", note = "use ecdsa::sign_low_r instead")]
pub fn sign_ecdsa_low_r(&self, msg: impl Into<Message>, sk: &SecretKey) -> Signature {
self::sign_low_r(msg, sk)
}
}

impl<C: Verification> Secp256k1<C> {
/// 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.
///
/// ```rust
/// # #[cfg(all(feature = "rand", feature = "std"))] {
/// # use secp256k1::{rand, Secp256k1, Message, Error};
/// #
/// # let secp = Secp256k1::new();
/// # let (secret_key, public_key) = secp.generate_keypair(&mut rand::rng());
/// #
/// let message = Message::from_digest_slice(&[0xab; 32]).expect("32 bytes");
/// let sig = secp.sign_ecdsa(message, &secret_key);
/// assert_eq!(secp.verify_ecdsa(&sig, message, &public_key), Ok(()));
///
/// let message = Message::from_digest_slice(&[0xcd; 32]).expect("32 bytes");
/// assert_eq!(secp.verify_ecdsa(&sig, message, &public_key), Err(Error::IncorrectSignature));
/// # }
/// ```
#[inline]
#[deprecated(since = "0.32.0", note = "use ecdsa::verify instead")]
pub fn verify_ecdsa(
&self,
sig: &Signature,
msg: impl Into<Message>,
pk: &PublicKey,
) -> Result<(), Error> {
self::verify(sig, msg, pk)
}
}

/// 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
Expand Down
49 changes: 48 additions & 1 deletion src/ecdsa/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use self::super_ffi::CPtr;
use super::ffi as super_ffi;
use crate::ecdsa::Signature;
use crate::ffi::recovery as ffi;
use crate::{key, Error, Message};
use crate::{key, Error, Message, Secp256k1, Signing, Verification};

/// A tag used for recovering the public key from a compact signature.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
Expand Down Expand Up @@ -229,6 +229,53 @@ impl RecoverableSignature {
}
}

impl<C: Signing> Secp256k1<C> {
/// Constructs a signature for `msg` using the secret key `sk` and RFC6979 nonce
/// Requires a signing-capable context.
#[deprecated(
since = "0.32.0",
note = "use RecoverableSignature::sign_ecdsa_recoverable instead"
)]
pub fn sign_ecdsa_recoverable(
&self,
msg: impl Into<Message>,
sk: &key::SecretKey,
) -> RecoverableSignature {
RecoverableSignature::sign_ecdsa_recoverable(msg, sk)
}

/// 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.
#[deprecated(
since = "0.32.0",
note = "use RecoverableSignature::sign_ecdsa_recoverable_with_noncedata instead"
)]
pub fn sign_ecdsa_recoverable_with_noncedata(
&self,
msg: impl Into<Message>,
sk: &key::SecretKey,
noncedata: &[u8; 32],
) -> RecoverableSignature {
RecoverableSignature::sign_ecdsa_recoverable_with_noncedata(msg, sk, noncedata)
}
}

impl<C: Verification> Secp256k1<C> {
/// Determines the public key for which `sig` is a valid signature for
/// `msg`. Requires a verify-capable context.
#[deprecated(since = "0.32.0", note = "use sig.recover_ecdsa instead")]
pub fn recover_ecdsa(
&self,
msg: impl Into<Message>,
sig: &RecoverableSignature,
) -> Result<key::PublicKey, Error> {
sig.recover_ecdsa(msg)
}
}

#[cfg(test)]
#[allow(unused_imports)]
mod tests {
Expand Down
14 changes: 14 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,20 @@ impl<C: Context> Secp256k1<C> {
}
}

impl<C: Signing> Secp256k1<C> {
/// Generates a random keypair. Convenience function for [`SecretKey::new`] and
/// [`PublicKey::from_secret_key`].
#[inline]
#[cfg(feature = "rand")]
#[deprecated(since = "0.32.0", note = "use secp256k1::generate_keypair instead")]
pub fn generate_keypair<R: rand::Rng + ?Sized>(
&self,
rng: &mut R,
) -> (key::SecretKey, key::PublicKey) {
generate_keypair(rng)
}
}

/// Generates a random keypair. Convenience function for [`SecretKey::new`] and
/// [`PublicKey::from_secret_key`].
#[inline]
Expand Down
55 changes: 54 additions & 1 deletion src/schnorr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use secp256k1_sys::SchnorrSigExtraParams;

use crate::ffi::{self, CPtr};
use crate::key::{Keypair, XOnlyPublicKey};
use crate::{constants, from_hex, Error, Secp256k1};
use crate::{constants, from_hex, Error, Secp256k1, Signing, Verification};

/// Represents a schnorr signature.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
Expand Down Expand Up @@ -183,6 +183,59 @@ pub fn verify(sig: &Signature, msg: &[u8], pubkey: &XOnlyPublicKey) -> Result<()
}
}

impl<C: Signing> Secp256k1<C> {
/// Creates a schnorr signature internally using the [`rand::rngs::ThreadRng`] random number
/// generator to generate the auxiliary random data.
#[cfg(all(feature = "rand", feature = "std"))]
#[deprecated(since = "0.32.0", note = "use schnorr::sign instead")]
pub fn sign_schnorr(&self, msg: &[u8], keypair: &Keypair) -> Signature {
self::sign(msg, keypair)
}

/// Creates a schnorr signature without using any auxiliary random data.
#[deprecated(since = "0.32.0", note = "use schnorr::sign_no_aux_rand instead")]
pub fn sign_schnorr_no_aux_rand(&self, msg: &[u8], keypair: &Keypair) -> Signature {
self::sign_no_aux_rand(msg, keypair)
}

/// Creates a schnorr signature using the given auxiliary random data.
#[deprecated(since = "0.32.0", note = "use schnorr::sign_with_aux_rand instead")]
pub fn sign_schnorr_with_aux_rand(
&self,
msg: &[u8],
keypair: &Keypair,
aux_rand: &[u8; 32],
) -> Signature {
self::sign_with_aux_rand(msg, keypair, aux_rand)
}

/// Creates a schnorr signature using the given random number generator to
/// generate the auxiliary random data.
#[cfg(feature = "rand")]
#[deprecated(since = "0.32.0", note = "use schnorr::sign_with_rng instead")]
pub fn sign_schnorr_with_rng<R: Rng + CryptoRng>(
&self,
msg: &[u8],
keypair: &Keypair,
rng: &mut R,
) -> Signature {
self::sign_with_rng(msg, keypair, rng)
}
}

impl<C: Verification> Secp256k1<C> {
/// Verifies a schnorr signature.
#[deprecated(since = "0.32.0", note = "use schnorr::verify instead")]
pub fn verify_schnorr(
&self,
sig: &Signature,
msg: &[u8],
pubkey: &XOnlyPublicKey,
) -> Result<(), Error> {
self::verify(sig, msg, pubkey)
}
}

#[cfg(test)]
#[allow(unused_imports)]
mod tests {
Expand Down
Loading