Skip to content

Commit e89d8f8

Browse files
committed
BREAKING CHANGE: Removed pre-hashing (tagged hash) support for Schnorr signatures, making them BIP-340 compliant.
1 parent 5ce6371 commit e89d8f8

File tree

6 files changed

+316
-57
lines changed

6 files changed

+316
-57
lines changed

Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bc-crypto"
3-
version = "0.4.0"
3+
version = "0.5.0"
44
edition = "2021"
55
description = "A uniform API for cryptographic primitives used in Blockchain Commons projects"
66
authors = ["Blockchain Commons"]
@@ -19,9 +19,12 @@ pbkdf2 = "^0.12.1"
1919
hkdf = "^0.12.3"
2020
crc32fast = "^1.3.2"
2121
chacha20poly1305 = "^0.10.1"
22-
secp256k1 = "^0.27.0"
22+
# secp256k1 = {version = "^0.27.0", features = ["bitcoin_hashes"]}
23+
#secp256k1 = "^0.27.0"
24+
secp256k1 = { git = "https://github.com/rust-bitcoin/rust-secp256k1/", branch = "master" }
2325
x25519-dalek = {version = "2.0.0-rc.2", features = ["static_secrets"]}
2426
thiserror = "^1.0.48"
27+
hex = "^0.4.3"
2528

2629
[dev-dependencies]
2730
hex-literal = "^0.4.1"

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@
2727

2828
```toml
2929
[dependencies]
30-
bc-crypto = "0.4.0"
30+
bc-crypto = "0.5.0"
3131
```
3232

33+
## Version History
34+
35+
- **0.5.0, September 14, 2024** - BREAKING CHANGE: Removed pre-hashing (tagged hash) support for Schnorr signatures, making them BIP-340 compliant. Signatures produced by previous versions of this crate will now only verify if you pre-hash the image yourself using the BIP-340 method and the tag you previously used, if any.
36+
3337
## Related Projects
3438

3539
Higher-level Blockchain Commons projects that use this crate include:

src/ecdsa_keys.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use bc_rand::RandomNumberGenerator;
2-
use secp256k1::{Secp256k1, SecretKey, PublicKey, KeyPair, constants::{PUBLIC_KEY_SIZE, SECRET_KEY_SIZE, UNCOMPRESSED_PUBLIC_KEY_SIZE}};
2+
use secp256k1::{Secp256k1, SecretKey, PublicKey, Keypair, constants::{PUBLIC_KEY_SIZE, SECRET_KEY_SIZE, UNCOMPRESSED_PUBLIC_KEY_SIZE}};
33

44
use crate::{ECDSA_PRIVATE_KEY_SIZE, hash::hkdf_hmac_sha256, SCHNORR_PUBLIC_KEY_SIZE};
55

@@ -43,7 +43,7 @@ pub fn ecdsa_derive_private_key(key_material: impl AsRef<[u8]>) -> Vec<u8> {
4343
/// Derives the Schnorr public key from the given private key.
4444
pub fn schnorr_public_key_from_private_key(private_key: &[u8; ECDSA_PRIVATE_KEY_SIZE]) -> [u8; SCHNORR_PUBLIC_KEY_SIZE] {
4545
let secp = Secp256k1::new();
46-
let kp: KeyPair = KeyPair::from_seckey_slice(&secp, private_key).unwrap();
46+
let kp: Keypair = Keypair::from_seckey_slice(&secp, private_key).unwrap();
4747
let (x, _) = kp.x_only_public_key();
4848
x.serialize()
4949
}

src/ecdsa_signing.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub fn ecdsa_sign(private_key: &[u8; ECDSA_PRIVATE_KEY_SIZE], message: impl AsRe
66
let secp = Secp256k1::new();
77
let sk = SecretKey::from_slice(private_key).expect("32 bytes, within curve order");
88
let hash = double_sha256(message.as_ref());
9-
let msg = Message::from_slice(&hash).unwrap();
9+
let msg = Message::from_digest(hash);
1010
let sig = secp.sign_ecdsa(&msg, &sk);
1111
sig.serialize_compact().to_vec().try_into().unwrap()
1212
}
@@ -19,8 +19,7 @@ pub fn ecdsa_verify(public_key: &[u8; ECDSA_PUBLIC_KEY_SIZE], signature: &[u8; E
1919
let pk = PublicKey::from_slice(public_key)
2020
.expect("33 or 65 bytes, serialized according to the spec");
2121
let hash = double_sha256(message.as_ref());
22-
let msg = Message::from_slice(&hash)
23-
.expect("Message hash must be 32 bytes");
22+
let msg = Message::from_digest(hash);
2423
let sig = Signature::from_compact(signature)
2524
.expect("64 bytes, signature according to the spec");
2625
secp.verify_ecdsa(&msg, &sig, &pk).is_ok()

src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![doc(html_root_url = "https://docs.rs/bc-crypto/0.4.0")]
1+
#![doc(html_root_url = "https://docs.rs/bc-crypto/0.5.0")]
22
#![warn(rust_2018_idioms)]
33

44
//! # Introduction
@@ -24,7 +24,7 @@
2424
//!
2525
//! ```toml
2626
//! [dependencies]
27-
//! bc-crypto = "0.4.0"
27+
//! bc-crypto = "0.5.0"
2828
//! ```
2929
3030
pub const CRC32_SIZE: usize = 4;
@@ -86,6 +86,7 @@ mod schnorr_signing;
8686
pub use schnorr_signing::{
8787
schnorr_sign,
8888
schnorr_sign_using,
89+
schnorr_sign_with_aux_rand,
8990
schnorr_verify,
9091
};
9192

0 commit comments

Comments
 (0)