Skip to content

Commit b159cbd

Browse files
committed
stop using deprecated thread_rng
In rand 0.9 `thread_rng` has been renamed to `rng`. The recent Musig2 PR predates the transition to rand 0.9.
1 parent 4d36fef commit b159cbd

File tree

4 files changed

+42
-42
lines changed

4 files changed

+42
-42
lines changed

examples/musig.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use secp256k1::{pubkey_sort, Keypair, Message, PublicKey, Scalar, Secp256k1, Sec
88

99
fn main() {
1010
let secp = Secp256k1::new();
11-
let mut rng = rand::thread_rng();
11+
let mut rng = rand::rng();
1212

1313
let (seckey1, pubkey1) = secp.generate_keypair(&mut rng);
1414

src/ecdsa/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ impl<C: Verification> Secp256k1<C> {
371371
/// # use secp256k1::{rand, Secp256k1, Message, Error};
372372
/// #
373373
/// # let secp = Secp256k1::new();
374-
/// # let (secret_key, public_key) = secp.generate_keypair(&mut rand::thread_rng());
374+
/// # let (secret_key, public_key) = secp.generate_keypair(&mut rand::rng());
375375
/// #
376376
/// let message = Message::from_digest_slice(&[0xab; 32]).expect("32 bytes");
377377
/// let sig = secp.sign_ecdsa(message, &secret_key);

src/key.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,12 +1622,12 @@ impl<'de> serde::Deserialize<'de> for XOnlyPublicKey {
16221622
///
16231623
/// ```rust
16241624
/// # # [cfg(any(test, feature = "rand-std"))] {
1625-
/// # use secp256k1::rand::{thread_rng, RngCore};
1625+
/// # use secp256k1::rand::{rng, RngCore};
16261626
/// # use secp256k1::{Secp256k1, SecretKey, Keypair, PublicKey, pubkey_sort};
16271627
/// # let secp = Secp256k1::new();
1628-
/// # let sk1 = SecretKey::new(&mut thread_rng());
1628+
/// # let sk1 = SecretKey::new(&mut rng());
16291629
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
1630-
/// # let sk2 = SecretKey::new(&mut thread_rng());
1630+
/// # let sk2 = SecretKey::new(&mut rng());
16311631
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
16321632
/// #
16331633
/// # let pubkeys = [pub_key1, pub_key2];

src/musig.rs

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub struct SessionSecretRand([u8; 32]);
4444
impl SessionSecretRand {
4545
/// Generates a new session ID using thread RNG.
4646
#[cfg(all(feature = "rand", feature = "std"))]
47-
pub fn new() -> Self { Self::from_rng(&mut rand::thread_rng()) }
47+
pub fn new() -> Self { Self::from_rng(&mut rand::rng()) }
4848

4949
/// Creates a new [`SessionSecretRand`] with random bytes from the given rng
5050
#[cfg(feature = "rand")]
@@ -137,12 +137,12 @@ impl fmt::Display for InvalidTweakErr {
137137
///
138138
/// ```rust
139139
/// # # [cfg(any(test, feature = "rand-std"))] {
140-
/// # use secp256k1::rand::{thread_rng, RngCore};
140+
/// # use secp256k1::rand::{rng, RngCore};
141141
/// # use secp256k1::{PublicKey, Secp256k1, SecretKey, new_nonce_pair, SessionSecretRand};
142142
/// # let secp = Secp256k1::new();
143143
/// // The session id must be sampled at random. Read documentation for more details.
144-
/// let session_secrand = SessionSecretRand::new(&mut thread_rng());
145-
/// let sk = SecretKey::new(&mut thread_rng());
144+
/// let session_secrand = SessionSecretRand::new(&mut rng());
145+
/// let sk = SecretKey::new(&mut rng());
146146
/// let pk = PublicKey::from_secret_key(&secp, &sk);
147147
///
148148
/// // Supply extra auxillary randomness to prevent misuse(for example, time of day)
@@ -287,12 +287,12 @@ impl KeyAggCache {
287287
///
288288
/// ```rust
289289
/// # # [cfg(any(test, feature = "rand-std"))] {
290-
/// # use secp256k1::rand::{thread_rng, RngCore};
290+
/// # use secp256k1::rand::{rng, RngCore};
291291
/// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey};
292292
/// # let secp = Secp256k1::new();
293-
/// # let sk1 = SecretKey::new(&mut thread_rng());
293+
/// # let sk1 = SecretKey::new(&mut rng());
294294
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
295-
/// # let sk2 = SecretKey::new(&mut thread_rng());
295+
/// # let sk2 = SecretKey::new(&mut rng());
296296
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
297297
/// #
298298
/// let key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
@@ -376,12 +376,12 @@ impl KeyAggCache {
376376
///
377377
/// ```rust
378378
/// # # [cfg(any(test, feature = "rand-std"))] {
379-
/// # use secp256k1::rand::{thread_rng, RngCore};
379+
/// # use secp256k1::rand::{rng, RngCore};
380380
/// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey};
381381
/// # let secp = Secp256k1::new();
382-
/// # let sk1 = SecretKey::new(&mut thread_rng());
382+
/// # let sk1 = SecretKey::new(&mut rng());
383383
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
384-
/// # let sk2 = SecretKey::new(&mut thread_rng());
384+
/// # let sk2 = SecretKey::new(&mut rng());
385385
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
386386
/// #
387387
/// let mut key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
@@ -435,12 +435,12 @@ impl KeyAggCache {
435435
///
436436
/// ```rust
437437
/// # # [cfg(any(test, feature = "rand-std"))] {
438-
/// # use secp256k1::rand::{thread_rng, RngCore};
438+
/// # use secp256k1::rand::{rng, RngCore};
439439
/// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey};
440440
/// # let secp = Secp256k1::new();
441-
/// # let sk1 = SecretKey::new(&mut thread_rng());
441+
/// # let sk1 = SecretKey::new(&mut rng());
442442
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
443-
/// # let sk2 = SecretKey::new(&mut thread_rng());
443+
/// # let sk2 = SecretKey::new(&mut rng());
444444
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
445445
///
446446
/// let mut key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
@@ -509,17 +509,17 @@ impl KeyAggCache {
509509
///
510510
/// ```rust
511511
/// # # [cfg(any(test, feature = "rand-std"))] {
512-
/// # use secp256k1::rand::{thread_rng, RngCore};
512+
/// # use secp256k1::rand::{rng, RngCore};
513513
/// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey, SessionSecretRand, Message};
514514
/// # let secp = Secp256k1::new();
515-
/// # let sk1 = SecretKey::new(&mut thread_rng());
515+
/// # let sk1 = SecretKey::new(&mut rng());
516516
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
517-
/// # let sk2 = SecretKey::new(&mut thread_rng());
517+
/// # let sk2 = SecretKey::new(&mut rng());
518518
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
519519
/// #
520520
/// let key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
521521
/// // The session id must be sampled at random. Read documentation for more details.
522-
/// let session_secrand = SessionSecretRand::new(&mut thread_rng());
522+
/// let session_secrand = SessionSecretRand::new(&mut rng());
523523
///
524524
/// let msg = Message::from_digest_slice(b"Public Message we want to sign!!").unwrap();
525525
///
@@ -697,25 +697,25 @@ impl AggregatedNonce {
697697
///
698698
/// ```rust
699699
/// # # [cfg(any(test, feature = "rand-std"))] {
700-
/// # use secp256k1::rand::{thread_rng, RngCore};
700+
/// # use secp256k1::rand::{rng, RngCore};
701701
/// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey, SessionSecretRand, Message, AggregatedNonce};
702702
/// # let secp = Secp256k1::new();
703-
/// # let sk1 = SecretKey::new(&mut thread_rng());
703+
/// # let sk1 = SecretKey::new(&mut rng());
704704
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
705-
/// # let sk2 = SecretKey::new(&mut thread_rng());
705+
/// # let sk2 = SecretKey::new(&mut rng());
706706
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
707707
///
708708
/// # let key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
709709
/// // The session id must be sampled at random. Read documentation for more details.
710710
///
711711
/// let msg = Message::from_digest_slice(b"Public Message we want to sign!!").unwrap();
712712
///
713-
/// let session_secrand1 = SessionSecretRand::new(&mut thread_rng());
713+
/// let session_secrand1 = SessionSecretRand::new(&mut rng());
714714
/// let (_sec_nonce1, pub_nonce1) = key_agg_cache.nonce_gen(&secp, session_secrand1, pub_key1, msg, None)
715715
/// .expect("non zero session id");
716716
///
717717
/// // Signer two does the same: Possibly on a different device
718-
/// let session_secrand2 = SessionSecretRand::new(&mut thread_rng());
718+
/// let session_secrand2 = SessionSecretRand::new(&mut rng());
719719
/// let (_sec_nonce2, pub_nonce2) = key_agg_cache.nonce_gen(&secp, session_secrand2, pub_key2, msg, None)
720720
/// .expect("non zero session id");
721721
///
@@ -859,12 +859,12 @@ impl Session {
859859
///
860860
/// ```rust
861861
/// # # [cfg(any(test, feature = "rand-std"))] {
862-
/// # use secp256k1::rand::{thread_rng, RngCore};
862+
/// # use secp256k1::rand::{rng, RngCore};
863863
/// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey, SessionSecretRand, Message, AggregatedNonce, Session};
864864
/// # let secp = Secp256k1::new();
865-
/// # let sk1 = SecretKey::new(&mut thread_rng());
865+
/// # let sk1 = SecretKey::new(&mut rng());
866866
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
867-
/// # let sk2 = SecretKey::new(&mut thread_rng());
867+
/// # let sk2 = SecretKey::new(&mut rng());
868868
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
869869
///
870870
/// # let key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
@@ -873,13 +873,13 @@ impl Session {
873873
/// let msg = Message::from_digest_slice(b"Public Message we want to sign!!").unwrap();
874874
///
875875
/// // Provide the current time for mis-use resistance
876-
/// let session_secrand1 = SessionSecretRand::new(&mut thread_rng());
876+
/// let session_secrand1 = SessionSecretRand::new(&mut rng());
877877
/// let extra_rand1 : Option<[u8; 32]> = None;
878878
/// let (_sec_nonce1, pub_nonce1) = key_agg_cache.nonce_gen(&secp, session_secrand1, pub_key1, msg, extra_rand1)
879879
/// .expect("non zero session id");
880880
///
881881
/// // Signer two does the same. Possibly on a different device
882-
/// let session_secrand2 = SessionSecretRand::new(&mut thread_rng());
882+
/// let session_secrand2 = SessionSecretRand::new(&mut rng());
883883
/// let extra_rand2 : Option<[u8; 32]> = None;
884884
/// let (_sec_nonce2, pub_nonce2) = key_agg_cache.nonce_gen(&secp, session_secrand2, pub_key2, msg, extra_rand2)
885885
/// .expect("non zero session id");
@@ -995,12 +995,12 @@ impl Session {
995995
///
996996
/// ```rust
997997
/// # # [cfg(any(test, feature = "rand-std"))] {
998-
/// # use secp256k1::rand::{thread_rng, RngCore};
998+
/// # use secp256k1::rand::{rng, RngCore};
999999
/// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey, SessionSecretRand, Message, AggregatedNonce, Session};
10001000
/// # let secp = Secp256k1::new();
1001-
/// # let sk1 = SecretKey::new(&mut thread_rng());
1001+
/// # let sk1 = SecretKey::new(&mut rng());
10021002
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
1003-
/// # let sk2 = SecretKey::new(&mut thread_rng());
1003+
/// # let sk2 = SecretKey::new(&mut rng());
10041004
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
10051005
///
10061006
/// # let key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
@@ -1009,12 +1009,12 @@ impl Session {
10091009
/// let msg = Message::from_digest_slice(b"Public Message we want to sign!!").unwrap();
10101010
///
10111011
/// // Provide the current time for mis-use resistance
1012-
/// let session_secrand1 = SessionSecretRand::new(&mut thread_rng());
1012+
/// let session_secrand1 = SessionSecretRand::new(&mut rng());
10131013
/// let (mut sec_nonce1, pub_nonce1) = key_agg_cache.nonce_gen(&secp, session_secrand1, pub_key1, msg, None)
10141014
/// .expect("non zero session id");
10151015
///
10161016
/// // Signer two does the same. Possibly on a different device
1017-
/// let session_secrand2 = SessionSecretRand::new(&mut thread_rng());
1017+
/// let session_secrand2 = SessionSecretRand::new(&mut rng());
10181018
/// let (_sec_nonce2, pub_nonce2) = key_agg_cache.nonce_gen(&secp, session_secrand2, pub_key2, msg, None)
10191019
/// .expect("non zero session id");
10201020
///
@@ -1078,12 +1078,12 @@ impl Session {
10781078
///
10791079
/// ```rust
10801080
/// # # [cfg(any(test, feature = "rand-std"))] {
1081-
/// # use secp256k1::rand::{thread_rng, RngCore};
1081+
/// # use secp256k1::rand::{rng, RngCore};
10821082
/// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey, SessionSecretRand, Message, AggregatedNonce, Session};
10831083
/// # let secp = Secp256k1::new();
1084-
/// # let sk1 = SecretKey::new(&mut thread_rng());
1084+
/// # let sk1 = SecretKey::new(&mut rng());
10851085
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
1086-
/// # let sk2 = SecretKey::new(&mut thread_rng());
1086+
/// # let sk2 = SecretKey::new(&mut rng());
10871087
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
10881088
///
10891089
/// let key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
@@ -1092,12 +1092,12 @@ impl Session {
10921092
/// let msg = Message::from_digest_slice(b"Public Message we want to sign!!").unwrap();
10931093
///
10941094
/// // Provide the current time for mis-use resistance
1095-
/// let session_secrand1 = SessionSecretRand::new(&mut thread_rng());
1095+
/// let session_secrand1 = SessionSecretRand::new(&mut rng());
10961096
/// let (mut sec_nonce1, pub_nonce1) = key_agg_cache.nonce_gen(&secp, session_secrand1, pub_key1, msg, None)
10971097
/// .expect("non zero session id");
10981098
///
10991099
/// // Signer two does the same. Possibly on a different device
1100-
/// let session_secrand2 = SessionSecretRand::new(&mut thread_rng());
1100+
/// let session_secrand2 = SessionSecretRand::new(&mut rng());
11011101
/// let (mut sec_nonce2, pub_nonce2) = key_agg_cache.nonce_gen(&secp, session_secrand2, pub_key2, msg, None)
11021102
/// .expect("non zero session id");
11031103
///

0 commit comments

Comments
 (0)