From f904031fef648b409a486bf786e5a9815d816355 Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Mon, 1 Jun 2026 21:35:37 -0400 Subject: [PATCH] Update random and cryptography crates Redo of #7800. Bumping the random and crypto crates is not trivial. Both sets of crates have had API changes which require manual updates. AI use: I wrote all of the code myself but used AI to figure out the new APIs. AI explained SHAKE's block size and why the block_size() function doesn't exist in the new crate. I confirmed the block size, which is actually represented in the new types for SHAKE. `Shake128` is actually `Shake<168>` - 168 is the block size. I cited Wikipedia as it lists the SHAKE block size in bits. I also used AI to figure out HMAC for SHA3. Assisted-by: Codex:gpt-5.4 --- .github/dependabot.yml | 2 + Cargo.lock | 149 +++++++++++++++++++---------------- Cargo.toml | 24 +++--- crates/literal/src/float.rs | 2 +- crates/stdlib/Cargo.toml | 5 +- crates/stdlib/src/hashlib.rs | 81 +++++++++++-------- crates/stdlib/src/random.rs | 6 +- 7 files changed, 147 insertions(+), 122 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 7533ce36803..e9e2041d482 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -24,6 +24,7 @@ updates: - "sha1" - "sha2" - "sha3" + - "shake" - "blake2" - "hmac" - "pbkdf2" @@ -88,6 +89,7 @@ updates: - "getrandom" - "mt19937" - "rand*" + - "chacha20" rayon: patterns: - "rayon*" diff --git a/Cargo.lock b/Cargo.lock index e388302e489..985d9083b68 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -349,11 +349,11 @@ dependencies = [ [[package]] name = "blake2" -version = "0.10.6" +version = "0.11.0-rc.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" +checksum = "061f1a09225e328e1ffbb378d2d49923c0ca5fee19fb5ac1cc9c1e9d52b93690" dependencies = [ - "digest 0.10.7", + "digest 0.11.3", ] [[package]] @@ -481,6 +481,17 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" +[[package]] +name = "chacha20" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f8d983286843e49675a4b7a2d174efe136dc93a18d69130dd18198a6c167601" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.0", + "rand_core 0.10.1", +] + [[package]] name = "chrono" version = "0.4.44" @@ -1101,7 +1112,6 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer 0.10.4", "crypto-common 0.1.7", - "subtle", ] [[package]] @@ -1111,6 +1121,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" dependencies = [ "block-buffer 0.12.0", + "const-oid 0.10.2", "crypto-common 0.2.2", "ctutils", ] @@ -1438,11 +1449,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" dependencies = [ "cfg-if", - "js-sys", "libc", "r-efi 5.3.0", "wasip2", - "wasm-bindgen", ] [[package]] @@ -1452,10 +1461,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" dependencies = [ "cfg-if", + "js-sys", "libc", "r-efi 6.0.0", + "rand_core 0.10.1", "wasip2", "wasip3", + "wasm-bindgen", ] [[package]] @@ -1582,15 +1594,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest 0.10.7", -] - [[package]] name = "hmac" version = "0.13.0" @@ -1969,11 +1972,12 @@ dependencies = [ [[package]] name = "keccak" -version = "0.1.6" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb26cec98cce3a3d96cbb7bced3c4b16e3d13f27ec56dbd62cbc8f39cfb9d653" +checksum = "9e24a010dd405bd7ed803e5253182815b41bf2e6a80cc3bfc066658e03a198aa" dependencies = [ - "cpufeatures 0.2.17", + "cfg-if", + "cpufeatures 0.3.0", ] [[package]] @@ -2323,12 +2327,12 @@ dependencies = [ [[package]] name = "md-5" -version = "0.10.6" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +checksum = "69b6441f590336821bb897fb28fc622898ccceb1d6cea3fde5ea86b090c4de98" dependencies = [ "cfg-if", - "digest 0.10.7", + "digest 0.11.3", ] [[package]] @@ -2373,11 +2377,11 @@ dependencies = [ [[package]] name = "mt19937" -version = "3.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56bc7ea7924ea1a79a9e817d0483e39295424cf2b1276cf2b968f9a6c9b63b54" +checksum = "25b4ab1a6f4b7820876af86b84adf545d53a52f59c5374856225aad9562d903e" dependencies = [ - "rand_core 0.9.5", + "rand_core 0.10.1", ] [[package]] @@ -2653,16 +2657,6 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2ee67f1008b1ba2321834326597b8e186293b049a023cdef258527550b9935b4" -[[package]] -name = "pbkdf2" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" -dependencies = [ - "digest 0.10.7", - "hmac 0.12.1", -] - [[package]] name = "pbkdf2" version = "0.13.0" @@ -2670,7 +2664,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "112d82ceb8c5bf524d9af484d4e4970c9fd5a0cc15ba14ad93dccd28873b0629" dependencies = [ "digest 0.11.3", - "hmac 0.13.0", + "hmac", ] [[package]] @@ -2787,10 +2781,10 @@ dependencies = [ "aes", "cbc", "der 0.8.0", - "pbkdf2 0.13.0", + "pbkdf2", "rand_core 0.10.1", "scrypt", - "sha2 0.11.0", + "sha2", "spki 0.8.0", ] @@ -3109,6 +3103,17 @@ dependencies = [ "rand_core 0.9.5", ] +[[package]] +name = "rand" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2e8e8bcc7961af1fdac401278c6a831614941f6164ee3bf4ce61b7edb162207" +dependencies = [ + "chacha20", + "getrandom 0.4.2", + "rand_core 0.10.1", +] + [[package]] name = "rand_chacha" version = "0.3.1" @@ -3515,7 +3520,7 @@ version = "0.5.0" dependencies = [ "ascii", "bitflags 2.11.1", - "getrandom 0.3.4", + "getrandom 0.4.2", "itertools 0.14.0", "libc", "lock_api", @@ -3602,7 +3607,7 @@ name = "rustpython-host_env" version = "0.5.0" dependencies = [ "bitflags 2.11.1", - "getrandom 0.3.4", + "getrandom 0.4.2", "junction", "libc", "libffi", @@ -3646,7 +3651,7 @@ dependencies = [ "is-macro", "lexical-parse-float", "num-traits", - "rand 0.9.4", + "rand 0.10.1", "rustpython-wtf8", ] @@ -3757,7 +3762,7 @@ dependencies = [ "crossbeam-utils", "csv-core", "der 0.8.0", - "digest 0.10.7", + "digest 0.11.3", "dns-lookup", "dyn-clone", "flame", @@ -3765,7 +3770,7 @@ dependencies = [ "foreign-types-shared", "gethostname", "hex", - "hmac 0.12.1", + "hmac", "icu_normalizer", "icu_properties", "indexmap", @@ -3790,12 +3795,12 @@ dependencies = [ "openssl-sys", "parking_lot", "paste", - "pbkdf2 0.12.2", + "pbkdf2", "pem-rfc7468 1.0.0", "phf 0.13.1", "pkcs8", "pymath", - "rand_core 0.9.5", + "rand 0.10.1", "rapidhash", "rustls", "rustls-native-certs", @@ -3810,9 +3815,10 @@ dependencies = [ "rustpython-ruff_source_file", "rustpython-ruff_text_size", "rustpython-vm", - "sha-1", - "sha2 0.10.9", + "sha1 0.11.0", + "sha2", "sha3", + "shake", "socket2", "system-configuration", "tcl-sys", @@ -4004,9 +4010,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d87af57419b594aa23fa95f09f0e06d80d84ba01c26148c43844cad6ff4485f0" dependencies = [ "cfg-if", - "pbkdf2 0.13.0", + "pbkdf2", "salsa20", - "sha2 0.11.0", + "sha2", ] [[package]] @@ -4101,17 +4107,6 @@ dependencies = [ "serde_core", ] -[[package]] -name = "sha-1" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5058ada175748e33390e40e872bd0fe59a19f265d0158daa551c5a88a76009c" -dependencies = [ - "cfg-if", - "cpufeatures 0.2.17", - "digest 0.10.7", -] - [[package]] name = "sha1" version = "0.10.6" @@ -4124,14 +4119,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.9" +name = "sha1" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +checksum = "aacc4cc499359472b4abe1bf11d0b12e688af9a805fa5e3016f9a386dc2d0214" dependencies = [ "cfg-if", - "cpufeatures 0.2.17", - "digest 0.10.7", + "cpufeatures 0.3.0", + "digest 0.11.3", ] [[package]] @@ -4147,12 +4142,24 @@ dependencies = [ [[package]] name = "sha3" -version = "0.10.9" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77fd7028345d415a4034cf8777cd4f8ab1851274233b45f84e3d955502d93874" +checksum = "bc9bad02c26382724b2d2692c6f179285e4b54eeecd7968f52a50059c3c11759" dependencies = [ - "digest 0.10.7", + "digest 0.11.3", "keccak", + "sponge-cursor", +] + +[[package]] +name = "shake" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09057cb2149ad4cbd2da1e26b351f9a4c354219421229c69c3063e6f61947c4a" +dependencies = [ + "digest 0.11.3", + "keccak", + "sponge-cursor", ] [[package]] @@ -4254,6 +4261,12 @@ dependencies = [ "der 0.8.0", ] +[[package]] +name = "sponge-cursor" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a0219bd7d979d58245a4f41f695e1ac9f8befdffadd7f61f1bae9e39abc6620" + [[package]] name = "stable_deref_trait" version = "1.2.1" @@ -5316,7 +5329,7 @@ checksum = "1301e935010a701ae5f8655edc0ad17c44bad3ac5ce8c39185f75453b720ae94" dependencies = [ "const-oid 0.9.6", "der 0.7.10", - "sha1", + "sha1 0.10.6", "signature", "spki 0.7.3", "tls_codec", diff --git a/Cargo.toml b/Cargo.toml index de2704842c3..08463ec026b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -195,7 +195,7 @@ adler32 = "1.2.0" approx = "0.5.1" ascii = "1.1" base64 = "0.22" -blake2 = "0.10.4" +blake2 = "0.11.0-rc.6" bitflags = "2.11.0" bitflagset = "0.0.3" bstr = "1" @@ -210,7 +210,7 @@ crc32fast = "1.3.2" criterion = { version = "0.8", features = ["html_reports"] } crossbeam-utils = "0.8.21" csv-core = "0.1.11" -digest = "0.10.7" +digest = "0.11" dns-lookup = "3.0" dyn-clone = "1.0.10" exitcode = "1.1.2" @@ -220,12 +220,12 @@ flate2 = { version = "1.1.9", default-features = false } # Bump only when the openssl crate bumps it foreign-types-shared = "0.1" gethostname = "1.0.2" -getrandom = { version = "0.3", features = ["std"] } +getrandom = { version = "0.4", features = ["std"] } glob = "0.3" half = "2" hex = "0.4.3" hexf-parse = "0.2.1" -hmac = "0.12" +hmac = "0.13" indexmap = { version = "2.14.0", features = ["std"] } insta = "1.47" itertools = "0.14.0" @@ -248,10 +248,10 @@ mac_address = "1.1.3" malachite-bigint = "0.9.1" malachite-q = "0.9.1" malachite-base = "0.9.1" -md-5 = "0.10.1" +md-5 = "0.11" memchr = "2.8.0" memmap2 = "0.9.10" -mt19937 = "<=3.2" # upgrade it once rand is upgraded +mt19937 = "3.3" num-complex = "0.4.6" num-integer = "0.1.46" num-traits = "0.2" @@ -264,7 +264,7 @@ openssl-probe = "0.2.1" optional = "0.5" parking_lot = "0.12.3" paste = "1.0.15" -pbkdf2 = "0.12" +pbkdf2 = "0.13" pem-rfc7468 = "1.0" pkcs8 = "0.11" proc-macro2 = "1.0.105" @@ -273,8 +273,7 @@ pymath = { version = "0.2.0", features = ["mul_add", "malachite-bigint", "comple pyo3 = "0.28" quote = "1.0.45" radium = "1.1.1" -rand = "0.9" -rand_core = { version = "0.9", features = ["os_rng"] } +rand = "0.10" rapidhash = "4.4.1" result-like = "0.5.0" rustix = { version = "1.1", features = ["event", "param", "system"] } @@ -288,9 +287,10 @@ serde = { package = "serde_core", version = "1.0.225", default-features = false, schannel = "0.1.29" scopeguard = "1" serde-wasm-bindgen = "0.6.5" -sha-1 = "0.10.0" -sha2 = "0.10.2" -sha3 = "0.10.1" +sha1 = "0.11" +sha2 = "0.11" +sha3 = "0.12" +shake = "0.1" siphasher = "1" socket2 = "0.6.3" static_assertions = "1.1" diff --git a/crates/literal/src/float.rs b/crates/literal/src/float.rs index 79caca0592c..56a2b542993 100644 --- a/crates/literal/src/float.rs +++ b/crates/literal/src/float.rs @@ -425,7 +425,7 @@ pub fn to_hex(value: f64) -> String { #[test] fn test_to_hex() { - use rand::Rng; + use rand::RngExt; assert_eq!(to_hex(f64::from_bits(1)), "0x0.0000000000001p-1022"); assert_eq!(to_hex(f64::from_bits(2)), "0x0.0000000000002p-1022"); assert_eq!(to_hex(-f64::from_bits(1)), "-0x0.0000000000001p-1022"); diff --git a/crates/stdlib/Cargo.toml b/crates/stdlib/Cargo.toml index 4547368322d..7bf82da9843 100644 --- a/crates/stdlib/Cargo.toml +++ b/crates/stdlib/Cargo.toml @@ -61,15 +61,16 @@ pymath = { workspace = true } xml = { workspace = true } # random -rand_core = { workspace = true } +rand = { workspace = true } mt19937 = { workspace = true } # Crypto: digest = { workspace = true } md-5 = { workspace = true } -sha-1 = { workspace = true } +sha1 = { workspace = true } sha2 = { workspace = true } sha3 = { workspace = true } +shake = { workspace = true } blake2 = { workspace = true } hmac = { workspace = true } pbkdf2 = { workspace = true, features = ["hmac"] } diff --git a/crates/stdlib/src/hashlib.rs b/crates/stdlib/src/hashlib.rs index bbe81cc8234..c2153b08a59 100644 --- a/crates/stdlib/src/hashlib.rs +++ b/crates/stdlib/src/hashlib.rs @@ -18,14 +18,14 @@ pub(crate) mod _hashlib { types::{Constructor, Representable}, }; use blake2::{Blake2b512, Blake2s256}; - use digest::{DynDigest, OutputSizeUser, core_api::BlockSizeUser}; - use digest::{ExtendableOutput, Update}; + use digest::{DynDigest, ExtendableOutput, OutputSizeUser, Update, block_api::BlockSizeUser}; use dyn_clone::{DynClone, clone_trait_object}; - use hmac::Mac; + use hmac::{Hmac, KeyInit, Mac, SimpleHmac}; use md5::Md5; use sha1::Sha1; use sha2::{Sha224, Sha256, Sha384, Sha512}; - use sha3::{Sha3_224, Sha3_256, Sha3_384, Sha3_512, Shake128, Shake256}; + use sha3::{Sha3_224, Sha3_256, Sha3_384, Sha3_512}; + use shake::{Shake128, Shake256}; const HASH_ALGORITHMS: &[&str] = &[ "md5", @@ -767,8 +767,8 @@ pub(crate) mod _hashlib { let msg_data = args.msg.flatten(); macro_rules! make_hmac { - ($hash_ty:ty) => {{ - let mut mac = as Mac>::new_from_slice(&key_buf) + ($hmac:ty, $hash_ty:ty) => {{ + let mut mac = <$hmac>::new_from_slice(&key_buf) .map_err(|_| vm.new_value_error("invalid key length".to_owned()))?; if let Some(ref m) = msg_data { m.with_ref(|bytes| Mac::update(&mut mac, bytes)); @@ -783,16 +783,16 @@ pub(crate) mod _hashlib { } match name.as_str() { - "md5" => make_hmac!(Md5), - "sha1" => make_hmac!(Sha1), - "sha224" => make_hmac!(Sha224), - "sha256" => make_hmac!(Sha256), - "sha384" => make_hmac!(Sha384), - "sha512" => make_hmac!(Sha512), - "sha3_224" => make_hmac!(Sha3_224), - "sha3_256" => make_hmac!(Sha3_256), - "sha3_384" => make_hmac!(Sha3_384), - "sha3_512" => make_hmac!(Sha3_512), + "md5" => make_hmac!(Hmac, Md5), + "sha1" => make_hmac!(Hmac, Sha1), + "sha224" => make_hmac!(Hmac, Sha224), + "sha256" => make_hmac!(Hmac, Sha256), + "sha384" => make_hmac!(Hmac, Sha384), + "sha512" => make_hmac!(Hmac, Sha512), + "sha3_224" => make_hmac!(SimpleHmac, Sha3_224), + "sha3_256" => make_hmac!(SimpleHmac, Sha3_256), + "sha3_384" => make_hmac!(SimpleHmac, Sha3_384), + "sha3_512" => make_hmac!(SimpleHmac, Sha3_512), _ => Err(unsupported_hash(&name, vm)), } } @@ -805,8 +805,8 @@ pub(crate) mod _hashlib { let msg_buf = args.msg.borrow_buf(); macro_rules! do_hmac { - ($hash_ty:ty) => {{ - let mut mac = as Mac>::new_from_slice(&key_buf) + ($hmac:ty) => {{ + let mut mac = <$hmac>::new_from_slice(&key_buf) .map_err(|_| vm.new_value_error("invalid key length".to_owned()))?; Mac::update(&mut mac, &msg_buf); Ok(mac.finalize().into_bytes().to_vec().into()) @@ -814,16 +814,16 @@ pub(crate) mod _hashlib { } match name.as_str() { - "md5" => do_hmac!(Md5), - "sha1" => do_hmac!(Sha1), - "sha224" => do_hmac!(Sha224), - "sha256" => do_hmac!(Sha256), - "sha384" => do_hmac!(Sha384), - "sha512" => do_hmac!(Sha512), - "sha3_224" => do_hmac!(Sha3_224), - "sha3_256" => do_hmac!(Sha3_256), - "sha3_384" => do_hmac!(Sha3_384), - "sha3_512" => do_hmac!(Sha3_512), + "md5" => do_hmac!(Hmac), + "sha1" => do_hmac!(Hmac), + "sha224" => do_hmac!(Hmac), + "sha256" => do_hmac!(Hmac), + "sha384" => do_hmac!(Hmac), + "sha512" => do_hmac!(Hmac), + "sha3_224" => do_hmac!(SimpleHmac), + "sha3_256" => do_hmac!(SimpleHmac), + "sha3_384" => do_hmac!(SimpleHmac), + "sha3_512" => do_hmac!(SimpleHmac), _ => Err(unsupported_hash(&name, vm)), } } @@ -864,6 +864,14 @@ pub(crate) mod _hashlib { }}; } + macro_rules! do_pbkdf2_sha3 { + ($hash_ty:ty) => {{ + pbkdf2::pbkdf2::>(&password_buf, &salt_buf, rounds, &mut dk) + .map_err(|_| vm.new_value_error("invalid key length."))?; + Ok(dk.into()) + }}; + } + match name.as_str() { "md5" => do_pbkdf2!(Md5), "sha1" => do_pbkdf2!(Sha1), @@ -871,10 +879,10 @@ pub(crate) mod _hashlib { "sha256" => do_pbkdf2!(Sha256), "sha384" => do_pbkdf2!(Sha384), "sha512" => do_pbkdf2!(Sha512), - "sha3_224" => do_pbkdf2!(Sha3_224), - "sha3_256" => do_pbkdf2!(Sha3_256), - "sha3_384" => do_pbkdf2!(Sha3_384), - "sha3_512" => do_pbkdf2!(Sha3_512), + "sha3_224" => do_pbkdf2_sha3!(Sha3_224), + "sha3_256" => do_pbkdf2_sha3!(Sha3_256), + "sha3_384" => do_pbkdf2_sha3!(Sha3_384), + "sha3_512" => do_pbkdf2_sha3!(Sha3_512), _ => Err(unsupported_hash(&name, vm)), } } @@ -953,10 +961,13 @@ pub(crate) mod _hashlib { } } - fn block_size(&self) -> usize { + const fn block_size(&self) -> usize { + // https://en.wikipedia.org/wiki/SHA-3#Instances + // SHAKE128: 1344 / 8 = 168 + // SHAKE256: 1088 / 8 = 136 match self { - Self::Shake128(_) => Shake128::block_size(), - Self::Shake256(_) => Shake256::block_size(), + Self::Shake128(_) => 168, + Self::Shake256(_) => 136, } } diff --git a/crates/stdlib/src/random.rs b/crates/stdlib/src/random.rs index 52d45f16b2b..3f4c4e48249 100644 --- a/crates/stdlib/src/random.rs +++ b/crates/stdlib/src/random.rs @@ -8,7 +8,6 @@ mod _random { use crate::vm::{ PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, builtins::{PyInt, PyTupleRef}, - convert::ToPyException, function::OptionalOption, types::{Constructor, Initializer}, }; @@ -16,7 +15,7 @@ mod _random { use malachite_bigint::{BigInt, BigUint, Sign}; use mt19937::MT19937; use num_traits::{Signed, Zero}; - use rand_core::{RngCore, SeedableRng}; + use rand::{Rng, SeedableRng}; use rustpython_vm::types::DefaultConstructor; #[pyattr] @@ -60,8 +59,7 @@ mod _random { let key = if key.is_empty() { &[0] } else { key.as_slice() }; MT19937::new_with_slice_seed(key) } - None => MT19937::try_from_os_rng() - .map_err(|e| std::io::Error::from(e).to_pyexception(vm))?, + None => MT19937::from_rng(&mut rand::rng()), }; Ok(()) }