Skip to content

Commit 768720a

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 9ed8d02 commit 768720a

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")]
@@ -142,12 +142,12 @@ impl fmt::Display for InvalidTweakErr {
142142
///
143143
/// ```rust
144144
/// # # [cfg(any(test, feature = "rand-std"))] {
145-
/// # use secp256k1::rand::{thread_rng, RngCore};
145+
/// # use secp256k1::rand::{rng, RngCore};
146146
/// # use secp256k1::{PublicKey, Secp256k1, SecretKey, new_nonce_pair, SessionSecretRand};
147147
/// # let secp = Secp256k1::new();
148148
/// // The session id must be sampled at random. Read documentation for more details.
149-
/// let session_secrand = SessionSecretRand::new(&mut thread_rng());
150-
/// let sk = SecretKey::new(&mut thread_rng());
149+
/// let session_secrand = SessionSecretRand::new(&mut rng());
150+
/// let sk = SecretKey::new(&mut rng());
151151
/// let pk = PublicKey::from_secret_key(&secp, &sk);
152152
///
153153
/// // Supply extra auxillary randomness to prevent misuse(for example, time of day)
@@ -298,12 +298,12 @@ impl KeyAggCache {
298298
///
299299
/// ```rust
300300
/// # # [cfg(any(test, feature = "rand-std"))] {
301-
/// # use secp256k1::rand::{thread_rng, RngCore};
301+
/// # use secp256k1::rand::{rng, RngCore};
302302
/// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey};
303303
/// # let secp = Secp256k1::new();
304-
/// # let sk1 = SecretKey::new(&mut thread_rng());
304+
/// # let sk1 = SecretKey::new(&mut rng());
305305
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
306-
/// # let sk2 = SecretKey::new(&mut thread_rng());
306+
/// # let sk2 = SecretKey::new(&mut rng());
307307
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
308308
/// #
309309
/// let key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
@@ -387,12 +387,12 @@ impl KeyAggCache {
387387
///
388388
/// ```rust
389389
/// # # [cfg(any(test, feature = "rand-std"))] {
390-
/// # use secp256k1::rand::{thread_rng, RngCore};
390+
/// # use secp256k1::rand::{rng, RngCore};
391391
/// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey};
392392
/// # let secp = Secp256k1::new();
393-
/// # let sk1 = SecretKey::new(&mut thread_rng());
393+
/// # let sk1 = SecretKey::new(&mut rng());
394394
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
395-
/// # let sk2 = SecretKey::new(&mut thread_rng());
395+
/// # let sk2 = SecretKey::new(&mut rng());
396396
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
397397
/// #
398398
/// let mut key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
@@ -446,12 +446,12 @@ impl KeyAggCache {
446446
///
447447
/// ```rust
448448
/// # # [cfg(any(test, feature = "rand-std"))] {
449-
/// # use secp256k1::rand::{thread_rng, RngCore};
449+
/// # use secp256k1::rand::{rng, RngCore};
450450
/// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey};
451451
/// # let secp = Secp256k1::new();
452-
/// # let sk1 = SecretKey::new(&mut thread_rng());
452+
/// # let sk1 = SecretKey::new(&mut rng());
453453
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
454-
/// # let sk2 = SecretKey::new(&mut thread_rng());
454+
/// # let sk2 = SecretKey::new(&mut rng());
455455
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
456456
///
457457
/// let mut key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
@@ -520,17 +520,17 @@ impl KeyAggCache {
520520
///
521521
/// ```rust
522522
/// # # [cfg(any(test, feature = "rand-std"))] {
523-
/// # use secp256k1::rand::{thread_rng, RngCore};
523+
/// # use secp256k1::rand::{rng, RngCore};
524524
/// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey, SessionSecretRand, Message};
525525
/// # let secp = Secp256k1::new();
526-
/// # let sk1 = SecretKey::new(&mut thread_rng());
526+
/// # let sk1 = SecretKey::new(&mut rng());
527527
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
528-
/// # let sk2 = SecretKey::new(&mut thread_rng());
528+
/// # let sk2 = SecretKey::new(&mut rng());
529529
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
530530
/// #
531531
/// let key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
532532
/// // The session id must be sampled at random. Read documentation for more details.
533-
/// let session_secrand = SessionSecretRand::new(&mut thread_rng());
533+
/// let session_secrand = SessionSecretRand::new(&mut rng());
534534
///
535535
/// let msg = Message::from_digest_slice(b"Public Message we want to sign!!").unwrap();
536536
///
@@ -708,25 +708,25 @@ impl AggregatedNonce {
708708
///
709709
/// ```rust
710710
/// # # [cfg(any(test, feature = "rand-std"))] {
711-
/// # use secp256k1::rand::{thread_rng, RngCore};
711+
/// # use secp256k1::rand::{rng, RngCore};
712712
/// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey, SessionSecretRand, Message, AggregatedNonce};
713713
/// # let secp = Secp256k1::new();
714-
/// # let sk1 = SecretKey::new(&mut thread_rng());
714+
/// # let sk1 = SecretKey::new(&mut rng());
715715
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
716-
/// # let sk2 = SecretKey::new(&mut thread_rng());
716+
/// # let sk2 = SecretKey::new(&mut rng());
717717
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
718718
///
719719
/// # let key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
720720
/// // The session id must be sampled at random. Read documentation for more details.
721721
///
722722
/// let msg = Message::from_digest_slice(b"Public Message we want to sign!!").unwrap();
723723
///
724-
/// let session_secrand1 = SessionSecretRand::new(&mut thread_rng());
724+
/// let session_secrand1 = SessionSecretRand::new(&mut rng());
725725
/// let (_sec_nonce1, pub_nonce1) = key_agg_cache.nonce_gen(&secp, session_secrand1, pub_key1, msg, None)
726726
/// .expect("non zero session id");
727727
///
728728
/// // Signer two does the same: Possibly on a different device
729-
/// let session_secrand2 = SessionSecretRand::new(&mut thread_rng());
729+
/// let session_secrand2 = SessionSecretRand::new(&mut rng());
730730
/// let (_sec_nonce2, pub_nonce2) = key_agg_cache.nonce_gen(&secp, session_secrand2, pub_key2, msg, None)
731731
/// .expect("non zero session id");
732732
///
@@ -870,12 +870,12 @@ impl Session {
870870
///
871871
/// ```rust
872872
/// # # [cfg(any(test, feature = "rand-std"))] {
873-
/// # use secp256k1::rand::{thread_rng, RngCore};
873+
/// # use secp256k1::rand::{rng, RngCore};
874874
/// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey, SessionSecretRand, Message, AggregatedNonce, Session};
875875
/// # let secp = Secp256k1::new();
876-
/// # let sk1 = SecretKey::new(&mut thread_rng());
876+
/// # let sk1 = SecretKey::new(&mut rng());
877877
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
878-
/// # let sk2 = SecretKey::new(&mut thread_rng());
878+
/// # let sk2 = SecretKey::new(&mut rng());
879879
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
880880
///
881881
/// # let key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
@@ -884,13 +884,13 @@ impl Session {
884884
/// let msg = Message::from_digest_slice(b"Public Message we want to sign!!").unwrap();
885885
///
886886
/// // Provide the current time for mis-use resistance
887-
/// let session_secrand1 = SessionSecretRand::new(&mut thread_rng());
887+
/// let session_secrand1 = SessionSecretRand::new(&mut rng());
888888
/// let extra_rand1 : Option<[u8; 32]> = None;
889889
/// let (_sec_nonce1, pub_nonce1) = key_agg_cache.nonce_gen(&secp, session_secrand1, pub_key1, msg, extra_rand1)
890890
/// .expect("non zero session id");
891891
///
892892
/// // Signer two does the same. Possibly on a different device
893-
/// let session_secrand2 = SessionSecretRand::new(&mut thread_rng());
893+
/// let session_secrand2 = SessionSecretRand::new(&mut rng());
894894
/// let extra_rand2 : Option<[u8; 32]> = None;
895895
/// let (_sec_nonce2, pub_nonce2) = key_agg_cache.nonce_gen(&secp, session_secrand2, pub_key2, msg, extra_rand2)
896896
/// .expect("non zero session id");
@@ -1006,12 +1006,12 @@ impl Session {
10061006
///
10071007
/// ```rust
10081008
/// # # [cfg(any(test, feature = "rand-std"))] {
1009-
/// # use secp256k1::rand::{thread_rng, RngCore};
1009+
/// # use secp256k1::rand::{rng, RngCore};
10101010
/// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey, SessionSecretRand, Message, AggregatedNonce, Session};
10111011
/// # let secp = Secp256k1::new();
1012-
/// # let sk1 = SecretKey::new(&mut thread_rng());
1012+
/// # let sk1 = SecretKey::new(&mut rng());
10131013
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
1014-
/// # let sk2 = SecretKey::new(&mut thread_rng());
1014+
/// # let sk2 = SecretKey::new(&mut rng());
10151015
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
10161016
///
10171017
/// # let key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
@@ -1020,12 +1020,12 @@ impl Session {
10201020
/// let msg = Message::from_digest_slice(b"Public Message we want to sign!!").unwrap();
10211021
///
10221022
/// // Provide the current time for mis-use resistance
1023-
/// let session_secrand1 = SessionSecretRand::new(&mut thread_rng());
1023+
/// let session_secrand1 = SessionSecretRand::new(&mut rng());
10241024
/// let (mut sec_nonce1, pub_nonce1) = key_agg_cache.nonce_gen(&secp, session_secrand1, pub_key1, msg, None)
10251025
/// .expect("non zero session id");
10261026
///
10271027
/// // Signer two does the same. Possibly on a different device
1028-
/// let session_secrand2 = SessionSecretRand::new(&mut thread_rng());
1028+
/// let session_secrand2 = SessionSecretRand::new(&mut rng());
10291029
/// let (_sec_nonce2, pub_nonce2) = key_agg_cache.nonce_gen(&secp, session_secrand2, pub_key2, msg, None)
10301030
/// .expect("non zero session id");
10311031
///
@@ -1089,12 +1089,12 @@ impl Session {
10891089
///
10901090
/// ```rust
10911091
/// # # [cfg(any(test, feature = "rand-std"))] {
1092-
/// # use secp256k1::rand::{thread_rng, RngCore};
1092+
/// # use secp256k1::rand::{rng, RngCore};
10931093
/// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey, SessionSecretRand, Message, AggregatedNonce, Session};
10941094
/// # let secp = Secp256k1::new();
1095-
/// # let sk1 = SecretKey::new(&mut thread_rng());
1095+
/// # let sk1 = SecretKey::new(&mut rng());
10961096
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
1097-
/// # let sk2 = SecretKey::new(&mut thread_rng());
1097+
/// # let sk2 = SecretKey::new(&mut rng());
10981098
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
10991099
///
11001100
/// let key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
@@ -1103,12 +1103,12 @@ impl Session {
11031103
/// let msg = Message::from_digest_slice(b"Public Message we want to sign!!").unwrap();
11041104
///
11051105
/// // Provide the current time for mis-use resistance
1106-
/// let session_secrand1 = SessionSecretRand::new(&mut thread_rng());
1106+
/// let session_secrand1 = SessionSecretRand::new(&mut rng());
11071107
/// let (mut sec_nonce1, pub_nonce1) = key_agg_cache.nonce_gen(&secp, session_secrand1, pub_key1, msg, None)
11081108
/// .expect("non zero session id");
11091109
///
11101110
/// // Signer two does the same. Possibly on a different device
1111-
/// let session_secrand2 = SessionSecretRand::new(&mut thread_rng());
1111+
/// let session_secrand2 = SessionSecretRand::new(&mut rng());
11121112
/// let (mut sec_nonce2, pub_nonce2) = key_agg_cache.nonce_gen(&secp, session_secrand2, pub_key2, msg, None)
11131113
/// .expect("non zero session id");
11141114
///

0 commit comments

Comments
 (0)