mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-27 08:41:36 +00:00
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] <support@github.com> * 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 <mail@max-inden.de>
This commit is contained in:
@ -1,3 +1,7 @@
|
||||
# 0.28.4 [unreleased]
|
||||
|
||||
- Update dependencies.
|
||||
|
||||
# 0.28.3 [2021-04-26]
|
||||
|
||||
- Fix build with secp256k1 disabled [PR 2057](https://github.com/libp2p/rust-libp2p/pull/2057].
|
||||
|
@ -2,7 +2,7 @@
|
||||
name = "libp2p-core"
|
||||
edition = "2018"
|
||||
description = "Core traits and structs of libp2p"
|
||||
version = "0.28.3"
|
||||
version = "0.28.4"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/libp2p/rust-libp2p"
|
||||
@ -18,7 +18,7 @@ fnv = "1.0"
|
||||
futures = { version = "0.3.1", features = ["executor", "thread-pool"] }
|
||||
futures-timer = "3"
|
||||
lazy_static = "1.2"
|
||||
libsecp256k1 = { version = "0.3.1", optional = true }
|
||||
libsecp256k1 = { version = "0.5.0", optional = true }
|
||||
log = "0.4"
|
||||
multiaddr = { package = "parity-multiaddr", version = "0.11.2", path = "../misc/multiaddr" }
|
||||
multihash = { version = "0.13", default-features = false, features = ["std", "multihash-impl", "identity", "sha2"] }
|
||||
|
@ -21,9 +21,8 @@
|
||||
//! Secp256k1 keys.
|
||||
|
||||
use asn1_der::typed::{DerDecodable, Sequence};
|
||||
use rand::RngCore;
|
||||
use sha2::{Digest as ShaDigestTrait, Sha256};
|
||||
use secp256k1::{Message, Signature};
|
||||
use libsecp256k1::{Message, Signature};
|
||||
use super::error::{DecodingError, SigningError};
|
||||
use zeroize::Zeroize;
|
||||
use core::fmt;
|
||||
@ -61,7 +60,7 @@ impl fmt::Debug for Keypair {
|
||||
/// Promote a Secp256k1 secret key into a keypair.
|
||||
impl From<SecretKey> for Keypair {
|
||||
fn from(secret: SecretKey) -> Keypair {
|
||||
let public = PublicKey(secp256k1::PublicKey::from_secret_key(&secret.0));
|
||||
let public = PublicKey(libsecp256k1::PublicKey::from_secret_key(&secret.0));
|
||||
Keypair { secret, public }
|
||||
}
|
||||
}
|
||||
@ -75,7 +74,7 @@ impl From<Keypair> for SecretKey {
|
||||
|
||||
/// A Secp256k1 secret key.
|
||||
#[derive(Clone)]
|
||||
pub struct SecretKey(secp256k1::SecretKey);
|
||||
pub struct SecretKey(libsecp256k1::SecretKey);
|
||||
|
||||
impl fmt::Debug for SecretKey {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
@ -86,16 +85,7 @@ impl fmt::Debug for SecretKey {
|
||||
impl SecretKey {
|
||||
/// Generate a new Secp256k1 secret key.
|
||||
pub fn generate() -> SecretKey {
|
||||
let mut r = rand::thread_rng();
|
||||
let mut b = [0; secp256k1::util::SECRET_KEY_SIZE];
|
||||
// This is how it is done in `secp256k1::SecretKey::random` which
|
||||
// we do not use here because it uses `rand::Rng` from rand-0.4.
|
||||
loop {
|
||||
r.fill_bytes(&mut b);
|
||||
if let Ok(k) = secp256k1::SecretKey::parse(&b) {
|
||||
return SecretKey(k)
|
||||
}
|
||||
}
|
||||
SecretKey(libsecp256k1::SecretKey::random(&mut rand::thread_rng()))
|
||||
}
|
||||
|
||||
/// Create a secret key from a byte slice, zeroing the slice on success.
|
||||
@ -103,7 +93,7 @@ impl SecretKey {
|
||||
/// error is returned.
|
||||
pub fn from_bytes(mut sk: impl AsMut<[u8]>) -> Result<SecretKey, DecodingError> {
|
||||
let sk_bytes = sk.as_mut();
|
||||
let secret = secp256k1::SecretKey::parse_slice(&*sk_bytes)
|
||||
let secret = libsecp256k1::SecretKey::parse_slice(&*sk_bytes)
|
||||
.map_err(|_| DecodingError::new("failed to parse secp256k1 secret key"))?;
|
||||
sk_bytes.zeroize();
|
||||
Ok(SecretKey(secret))
|
||||
@ -146,13 +136,13 @@ impl SecretKey {
|
||||
pub fn sign_hash(&self, msg: &[u8]) -> Result<Vec<u8>, SigningError> {
|
||||
let m = Message::parse_slice(msg)
|
||||
.map_err(|_| SigningError::new("failed to parse secp256k1 digest"))?;
|
||||
Ok(secp256k1::sign(&m, &self.0).0.serialize_der().as_ref().into())
|
||||
Ok(libsecp256k1::sign(&m, &self.0).0.serialize_der().as_ref().into())
|
||||
}
|
||||
}
|
||||
|
||||
/// A Secp256k1 public key.
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
pub struct PublicKey(secp256k1::PublicKey);
|
||||
pub struct PublicKey(libsecp256k1::PublicKey);
|
||||
|
||||
impl fmt::Debug for PublicKey {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
@ -173,7 +163,7 @@ impl PublicKey {
|
||||
/// Verify the Secp256k1 DER-encoded signature on a raw 256-bit message using the public key.
|
||||
pub fn verify_hash(&self, msg: &[u8], sig: &[u8]) -> bool {
|
||||
Message::parse_slice(msg)
|
||||
.and_then(|m| Signature::parse_der(sig).map(|s| secp256k1::verify(&m, &s, &self.0)))
|
||||
.and_then(|m| Signature::parse_der(sig).map(|s| libsecp256k1::verify(&m, &s, &self.0)))
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
@ -191,7 +181,7 @@ impl PublicKey {
|
||||
/// Decode a public key from a byte slice in the the format produced
|
||||
/// by `encode`.
|
||||
pub fn decode(k: &[u8]) -> Result<PublicKey, DecodingError> {
|
||||
secp256k1::PublicKey::parse_slice(k, Some(secp256k1::PublicKeyFormat::Compressed))
|
||||
libsecp256k1::PublicKey::parse_slice(k, Some(libsecp256k1::PublicKeyFormat::Compressed))
|
||||
.map_err(|_| DecodingError::new("failed to parse secp256k1 public key"))
|
||||
.map(PublicKey)
|
||||
}
|
||||
|
Reference in New Issue
Block a user