Skip to content

Commit bf0cdbb

Browse files
build(deps): Update libsecp256k1 requirement from 0.3.1 to 0.5.0 (#2074)
* build(deps): Update libsecp256k1 requirement from 0.3.1 to 0.5.0 Updates the requirements on [libsecp256k1](https://github.com/paritytech/libsecp256k1) to permit the latest version. - [Release notes](https://github.com/paritytech/libsecp256k1/releases) - [Changelog](https://github.com/paritytech/libsecp256k1/blob/master/CHANGELOG.md) - [Commits](https://github.com/paritytech/libsecp256k1/commits) Signed-off-by: dependabot[bot] <[email protected]> * core/identity/scp256k1: Use libsecp256k1::SecretKey::random directly * core/: Update changelog and cargo toml Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Max Inden <[email protected]>
1 parent d9f1c71 commit bf0cdbb

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

core/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.28.4 [unreleased]
2+
3+
- Update dependencies.
4+
15
# 0.28.3 [2021-04-26]
26

37
- Fix build with secp256k1 disabled [PR 2057](https://github.com/libp2p/rust-libp2p/pull/2057].

core/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "libp2p-core"
33
edition = "2018"
44
description = "Core traits and structs of libp2p"
5-
version = "0.28.3"
5+
version = "0.28.4"
66
authors = ["Parity Technologies <[email protected]>"]
77
license = "MIT"
88
repository = "https://github.com/libp2p/rust-libp2p"
@@ -18,7 +18,7 @@ fnv = "1.0"
1818
futures = { version = "0.3.1", features = ["executor", "thread-pool"] }
1919
futures-timer = "3"
2020
lazy_static = "1.2"
21-
libsecp256k1 = { version = "0.3.1", optional = true }
21+
libsecp256k1 = { version = "0.5.0", optional = true }
2222
log = "0.4"
2323
multiaddr = { package = "parity-multiaddr", version = "0.11.2", path = "../misc/multiaddr" }
2424
multihash = { version = "0.13", default-features = false, features = ["std", "multihash-impl", "identity", "sha2"] }

core/src/identity/secp256k1.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@
2121
//! Secp256k1 keys.
2222
2323
use asn1_der::typed::{DerDecodable, Sequence};
24-
use rand::RngCore;
2524
use sha2::{Digest as ShaDigestTrait, Sha256};
26-
use secp256k1::{Message, Signature};
25+
use libsecp256k1::{Message, Signature};
2726
use super::error::{DecodingError, SigningError};
2827
use zeroize::Zeroize;
2928
use core::fmt;
@@ -61,7 +60,7 @@ impl fmt::Debug for Keypair {
6160
/// Promote a Secp256k1 secret key into a keypair.
6261
impl From<SecretKey> for Keypair {
6362
fn from(secret: SecretKey) -> Keypair {
64-
let public = PublicKey(secp256k1::PublicKey::from_secret_key(&secret.0));
63+
let public = PublicKey(libsecp256k1::PublicKey::from_secret_key(&secret.0));
6564
Keypair { secret, public }
6665
}
6766
}
@@ -75,7 +74,7 @@ impl From<Keypair> for SecretKey {
7574

7675
/// A Secp256k1 secret key.
7776
#[derive(Clone)]
78-
pub struct SecretKey(secp256k1::SecretKey);
77+
pub struct SecretKey(libsecp256k1::SecretKey);
7978

8079
impl fmt::Debug for SecretKey {
8180
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -86,24 +85,15 @@ impl fmt::Debug for SecretKey {
8685
impl SecretKey {
8786
/// Generate a new Secp256k1 secret key.
8887
pub fn generate() -> SecretKey {
89-
let mut r = rand::thread_rng();
90-
let mut b = [0; secp256k1::util::SECRET_KEY_SIZE];
91-
// This is how it is done in `secp256k1::SecretKey::random` which
92-
// we do not use here because it uses `rand::Rng` from rand-0.4.
93-
loop {
94-
r.fill_bytes(&mut b);
95-
if let Ok(k) = secp256k1::SecretKey::parse(&b) {
96-
return SecretKey(k)
97-
}
98-
}
88+
SecretKey(libsecp256k1::SecretKey::random(&mut rand::thread_rng()))
9989
}
10090

10191
/// Create a secret key from a byte slice, zeroing the slice on success.
10292
/// If the bytes do not constitute a valid Secp256k1 secret key, an
10393
/// error is returned.
10494
pub fn from_bytes(mut sk: impl AsMut<[u8]>) -> Result<SecretKey, DecodingError> {
10595
let sk_bytes = sk.as_mut();
106-
let secret = secp256k1::SecretKey::parse_slice(&*sk_bytes)
96+
let secret = libsecp256k1::SecretKey::parse_slice(&*sk_bytes)
10797
.map_err(|_| DecodingError::new("failed to parse secp256k1 secret key"))?;
10898
sk_bytes.zeroize();
10999
Ok(SecretKey(secret))
@@ -146,13 +136,13 @@ impl SecretKey {
146136
pub fn sign_hash(&self, msg: &[u8]) -> Result<Vec<u8>, SigningError> {
147137
let m = Message::parse_slice(msg)
148138
.map_err(|_| SigningError::new("failed to parse secp256k1 digest"))?;
149-
Ok(secp256k1::sign(&m, &self.0).0.serialize_der().as_ref().into())
139+
Ok(libsecp256k1::sign(&m, &self.0).0.serialize_der().as_ref().into())
150140
}
151141
}
152142

153143
/// A Secp256k1 public key.
154144
#[derive(PartialEq, Eq, Clone)]
155-
pub struct PublicKey(secp256k1::PublicKey);
145+
pub struct PublicKey(libsecp256k1::PublicKey);
156146

157147
impl fmt::Debug for PublicKey {
158148
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -173,7 +163,7 @@ impl PublicKey {
173163
/// Verify the Secp256k1 DER-encoded signature on a raw 256-bit message using the public key.
174164
pub fn verify_hash(&self, msg: &[u8], sig: &[u8]) -> bool {
175165
Message::parse_slice(msg)
176-
.and_then(|m| Signature::parse_der(sig).map(|s| secp256k1::verify(&m, &s, &self.0)))
166+
.and_then(|m| Signature::parse_der(sig).map(|s| libsecp256k1::verify(&m, &s, &self.0)))
177167
.unwrap_or(false)
178168
}
179169

@@ -191,7 +181,7 @@ impl PublicKey {
191181
/// Decode a public key from a byte slice in the the format produced
192182
/// by `encode`.
193183
pub fn decode(k: &[u8]) -> Result<PublicKey, DecodingError> {
194-
secp256k1::PublicKey::parse_slice(k, Some(secp256k1::PublicKeyFormat::Compressed))
184+
libsecp256k1::PublicKey::parse_slice(k, Some(libsecp256k1::PublicKeyFormat::Compressed))
195185
.map_err(|_| DecodingError::new("failed to parse secp256k1 public key"))
196186
.map(PublicKey)
197187
}

0 commit comments

Comments
 (0)