Skip to content

Commit 116a812

Browse files
committed
chore(deps): bump rand in identity and core
1 parent 1aa4337 commit 116a812

File tree

10 files changed

+63
-17
lines changed

10 files changed

+63
-17
lines changed

Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ libp2p = { version = "0.56.0", path = "libp2p" }
7878
libp2p-allow-block-list = { version = "0.6.0", path = "misc/allow-block-list" }
7979
libp2p-autonat = { version = "0.15.0", path = "protocols/autonat" }
8080
libp2p-connection-limits = { version = "0.6.0", path = "misc/connection-limits" }
81-
libp2p-core = { version = "0.43.1", path = "core" }
81+
libp2p-core = { version = "0.43.2", path = "core" }
8282
libp2p-dcutr = { version = "0.14.0", path = "protocols/dcutr" }
8383
libp2p-dns = { version = "0.44.0", path = "transports/dns" }
8484
libp2p-floodsub = { version = "0.47.0", path = "protocols/floodsub" }
8585
libp2p-gossipsub = { version = "0.49.0", path = "protocols/gossipsub" }
8686
libp2p-identify = { version = "0.47.0", path = "protocols/identify" }
87-
libp2p-identity = { version = "0.2.12" }
87+
libp2p-identity = { version = "0.2.13" }
8888
libp2p-kad = { version = "0.48.1", path = "protocols/kad" }
8989
libp2p-mdns = { version = "0.48.0", path = "protocols/mdns" }
9090
libp2p-memory-connection-limits = { version = "0.5.0", path = "misc/memory-connection-limits" }
@@ -124,15 +124,17 @@ futures = "0.3.30"
124124
futures-bounded = { version = "0.2.4" }
125125
futures-rustls = { version = "0.26.0", default-features = false }
126126
getrandom = "0.2"
127-
if-watch = "3.2.1"
127+
hashlink = "0.9.0"
128128
hickory-proto = { version = "0.25.2", default-features = false }
129129
hickory-resolver = { version = "0.25.2", default-features = false }
130+
if-watch = "3.2.1"
130131
multiaddr = "0.18.1"
131132
multihash = "0.19.1"
132133
multistream-select = { version = "0.13.0", path = "misc/multistream-select" }
133134
prometheus-client = "0.23"
134135
quick-protobuf-codec = { version = "0.3.1", path = "misc/quick-protobuf-codec" }
135136
quickcheck = { package = "quickcheck-ext", path = "misc/quickcheck-ext" }
137+
rand = { version = "0.9", default-features = false }
136138
rcgen = "0.13"
137139
ring = "0.17.12"
138140
rw-stream-sink = { version = "0.4.0", path = "misc/rw-stream-sink" }
@@ -142,7 +144,6 @@ tracing = "0.1.41"
142144
tracing-subscriber = "0.3.19"
143145
unsigned-varint = { version = "0.8.0" }
144146
web-time = "1.1.0"
145-
hashlink = "0.9.0"
146147

147148
[patch.crates-io]
148149

core/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.43.2
2+
- Upgrade `rand` to `0.9`.
3+
See [PR 6092](https://github.com/libp2p/rust-libp2p/pull/6092)
4+
15
## 0.43.1
26
- Remove `once_cell` dependency.
37
See [PR 5913](https://github.com/libp2p/rust-libp2p/pull/5913)

core/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "libp2p-core"
33
edition.workspace = true
44
rust-version = { workspace = true }
55
description = "Core traits and structs of libp2p"
6-
version = "0.43.1"
6+
version = "0.43.2"
77
authors = ["Parity Technologies <[email protected]>"]
88
license = "MIT"
99
repository = "https://github.com/libp2p/rust-libp2p"
@@ -23,7 +23,7 @@ multistream-select = { workspace = true }
2323
parking_lot = "0.12.3"
2424
pin-project = "1.1.5"
2525
quick-protobuf = "0.8"
26-
rand = "0.8"
26+
rand = { workspace = true }
2727
rw-stream-sink = { workspace = true }
2828
thiserror = { workspace = true }
2929
tracing = { workspace = true }

identity/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.2.13
2+
3+
- Upgrade `rand` to `0.9`.
4+
See [PR 6092](https://github.com/libp2p/rust-libp2p/pull/6092)
5+
16
## 0.2.12
27

38
- Avoid depending on the `rand_core` feature in `ed25519-dalek` crate.

identity/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "libp2p-identity"
3-
version = "0.2.12"
3+
version = "0.2.13"
44
edition = "2021" # MUST NOT inherit from workspace because we don't want to publish breaking changes to `libp2p-identity`.
55
description = "Data structures and algorithms for identifying peers in libp2p."
66
rust-version = "1.73.0" # MUST NOT inherit from workspace because we don't want to publish breaking changes to `libp2p-identity`.
@@ -21,7 +21,7 @@ tracing = { workspace = true }
2121
multihash = { version = "0.19.1", optional = true }
2222
p256 = { version = "0.13", default-features = false, features = ["ecdsa", "std", "pem"], optional = true }
2323
quick-protobuf = "0.8.1"
24-
rand = { version = "0.8", optional = true }
24+
rand = { workspace = true, optional = true, features = ["thread_rng"]}
2525
sec1 = { version = "0.7", default-features = false, optional = true }
2626
serde = { version = "1", optional = true, features = ["derive"] }
2727
sha2 = { version = "0.10.8", optional = true }

identity/src/ecdsa.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,25 @@ impl SecretKey {
9696
/// Generate a new random ECDSA secret key.
9797
#[cfg(feature = "rand")]
9898
pub fn generate() -> SecretKey {
99-
SecretKey(SigningKey::random(&mut rand::thread_rng()))
99+
use k256::elliptic_curve::PrimeField as _;
100+
use rand::RngCore as _;
101+
102+
let mut rng = rand::rng();
103+
let non_zero_scalar = loop {
104+
let scalar: p256::Scalar = {
105+
let mut bytes = k256::FieldBytes::default();
106+
loop {
107+
rng.fill_bytes(&mut bytes);
108+
if let Some(scalar) = p256::Scalar::from_repr(bytes).into() {
109+
break scalar;
110+
}
111+
}
112+
};
113+
if let Some(non_zero_scalar) = p256::NonZeroScalar::new(scalar).into_option() {
114+
break non_zero_scalar;
115+
}
116+
};
117+
SecretKey(non_zero_scalar.into())
100118
}
101119

102120
/// Sign a message with this secret key, producing a DER-encoded ECDSA signature.

identity/src/ed25519.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl SecretKey {
187187
use rand::RngCore as _;
188188

189189
let mut secret = ed25519::SecretKey::default();
190-
rand::rngs::OsRng.fill_bytes(&mut secret);
190+
rand::rng().fill_bytes(&mut secret);
191191
SecretKey(secret)
192192
}
193193

identity/src/peer_id.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl PeerId {
106106
/// This is useful for randomly walking on a DHT, or for testing purposes.
107107
#[cfg(feature = "rand")]
108108
pub fn random() -> PeerId {
109-
let peer_id = rand::thread_rng().gen::<[u8; 32]>();
109+
let peer_id = rand::rng().random::<[u8; 32]>();
110110
PeerId {
111111
multihash: Multihash::wrap(0x0, &peer_id).expect("The digest size is never too large"),
112112
}

identity/src/secp256k1.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,25 @@ impl SecretKey {
9494
/// Generate a new random Secp256k1 secret key.
9595
#[cfg(feature = "rand")]
9696
pub fn generate() -> SecretKey {
97-
SecretKey(k256::ecdsa::SigningKey::random(&mut rand::thread_rng()))
97+
use k256::elliptic_curve::PrimeField as _;
98+
use rand::RngCore as _;
99+
100+
let mut rng = rand::rng();
101+
let non_zero_scalar = loop {
102+
let scalar: k256::Scalar = {
103+
let mut bytes = k256::FieldBytes::default();
104+
loop {
105+
rng.fill_bytes(&mut bytes);
106+
if let Some(scalar) = k256::Scalar::from_repr(bytes).into() {
107+
break scalar;
108+
}
109+
}
110+
};
111+
if let Some(non_zero_scalar) = k256::NonZeroScalar::new(scalar).into_option() {
112+
break non_zero_scalar;
113+
}
114+
};
115+
SecretKey(non_zero_scalar.into())
98116
}
99117

100118
/// Create a secret key from a byte slice, zeroing the slice on success.

0 commit comments

Comments
 (0)