Skip to content

Commit eea8ff0

Browse files
committed
rust: update num-bigint to 0.4.3
1 parent 0d5b26c commit eea8ff0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+7087
-5584
lines changed

src/rust/Cargo.lock

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

src/rust/bitbox02-rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ hex = { version = "0.4", default-features = false }
3434
sha2 = { version = "0.9.2", default-features = false }
3535
sha3 = { version = "0.9.1", default-features = false, optional = true }
3636
zeroize = "1.5.5"
37-
num-bigint = { version = "0.3.1", default-features = false, optional = true }
37+
num-bigint = { version = "0.4.3", default-features = false, optional = true }
3838
bip32-ed25519 = { git = "https://github.com/digitalbitbox/rust-bip32-ed25519", tag = "v0.1.0", optional = true }
3939
bs58 = { version = "0.4.0", default-features = false, features = ["alloc", "check"], optional = true }
4040
bech32 = { version = "0.8.1", default-features = false, optional = true }

src/rust/util/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ edition = "2018"
2020
license = "Apache-2.0"
2121

2222
[dependencies]
23-
num-bigint = { version = "0.3.1", default-features = false }
23+
num-bigint = { version = "0.4.3", default-features = false }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"files":{"Cargo.toml":"7365a7f8541f6d8a889f42e4d8084786a942238ecd6688605fa6320e51e6a1db","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"6485b8ed310d3f0340bf1ad1f47645069ce4069dcc6bb46c7d5c6faf41de1fdb","README.md":"d8a18a6efa61a27d8d8e454d4aa9d03808119a7be7c378da9e200d941a74c17b","RELEASES.md":"1a0da1010ea8a1c5eca9a9566bdaae639a1bb3b450a987e98c28c03875981dfd","benches/bigint.rs":"e0388d1880c4ff508b2f871c5b70f058999dd8c6a703c16e8ea69f0a8e1ba50d","benches/factorial.rs":"ed1d276a780e7e5fe79121b941c22a00c2854dbf92fd8a5372619853ba0c13b7","benches/gcd.rs":"2b433e5699b45e5fb23e77ab025a07e16e3eb9a49c47207b477551542fc4ff1e","benches/roots.rs":"967161d58d1977452ec7fa988a41848d575008a3e148eb048bc049c884d98f5f","benches/shootout-pidigits.rs":"c2a48133f5b679928f7e3f4e764c78aaa8c5b811f58b86fe57fae8c63cb07136","build.rs":"4955639b370d3636b8c44cb7743e6c5fb129077b069d78becbc135eba37e1ece","src/algorithms.rs":"5850d2931c34b43a79047d66c8ce98093299eeb3e8cb6dd761ee2bd1a6a50e07","src/bigint.rs":"1c73cb3bf03fab04a24a0e4a1e131a2aab2d06f233ce760786502fc96dab3f23","src/bigrand.rs":"579f4da36b8378267ef4b8a73a792437eaf1b39c48b5f2d50b66fefb4f9a63d7","src/biguint.rs":"db580af66ab88990d3a060077b6f229e4029f487a7d6ccceb8e1528d1603e02d","src/lib.rs":"483bc6f1a6159df10ec9a55b886e19e9f79c7cc1becca82cc00bd46b846feed2","src/macros.rs":"800239723d637c3ea1d6beb6a62b38a2300bd4c69c20dc0d50855ad6a8b31e70","src/monty.rs":"91688835e0fd409df72c3df5e07e2a114982578f03dd62721c02f36d5fc64ac6","tests/bigint.rs":"32fc36ebbfe97f7f4b050dd787cf86df2a36b47854fae5366c47098200026b0a","tests/bigint_bitwise.rs":"e6a2f76fa1eb919e7c513d7e30a8a2a963841a295a71103462fb8ab9792419b5","tests/bigint_scalar.rs":"5d6131e021f96d476f7949fa2b302581bd9254e91efde1bf2926cdd5e8dffcdb","tests/biguint.rs":"3dbd9fc4b341e7f8106cbeb2e765dab08643fb8691c27a5719216c0c13662493","tests/biguint_scalar.rs":"f16450c0dfcaf23b6fb85669b3de7c2bb6f594a65e3cdf91014b2e49c941cc95","tests/consts/mod.rs":"e20bc49a7cc95077242cbe4016b37745ea986c779d2385cb367fbfe44f15ff94","tests/macros/mod.rs":"1a8f9f015e5caaac60ce9ccff01a75ae489801c3ede6e7b9b3c5079b6efefc9c","tests/modpow.rs":"f1e4ed4fe466b544d7c4e57d0a0dc7d1c97b430b4805cae12f0915b8c40ab66f","tests/roots.rs":"a3bc2de170a0f6297cc8d8830d608db537ca102ccf204fd4fb8e2d92675622d8"},"package":"5e9a41747ae4633fce5adffb4d2e81ffc5e89593cb19917f8fb2cc5ff76507bf"}
1+
{"files":{"Cargo.toml":"0b84600b6ebbf302c71ee1984c54477ddb94142d17f82bb3601386b57bf49922","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"6485b8ed310d3f0340bf1ad1f47645069ce4069dcc6bb46c7d5c6faf41de1fdb","README.md":"d830b9c7aa3ee607cdb87bcbd3f7c930c3c7faad7fa79312806efa0dc3bda577","RELEASES.md":"bf590b1e9d5c3235cd872fa442cb9041b4c8ea3db3622a95edcd66b554ac7cc8","benches/bigint.rs":"7efd4741f53c786bae63d1196492b5657fd0d928b37a59a08629f6efdc35c845","benches/factorial.rs":"ed1d276a780e7e5fe79121b941c22a00c2854dbf92fd8a5372619853ba0c13b7","benches/gcd.rs":"3cc1a3356f680a6fa625f0ece0c8dd778f4091a53a31177f2870ef9a6c858c7d","benches/rng/mod.rs":"38144fc8283955db4be72a1533328fded98986d6f9d0bc7da0b306f7d4b5ca43","benches/roots.rs":"b31846852a7215c26df228940f2e469aff32fa8805eccc2b5ee5e7280ef0eeb4","benches/shootout-pidigits.rs":"c2a48133f5b679928f7e3f4e764c78aaa8c5b811f58b86fe57fae8c63cb07136","build.rs":"4955639b370d3636b8c44cb7743e6c5fb129077b069d78becbc135eba37e1ece","src/bigint.rs":"0ba1f025b130517a1ce94008a4ace8e1e337a419c91f9eee181a6672e4985ecd","src/bigint/addition.rs":"440f67a80de748f418adc1f3bfbcc4d428e21bcf5ae6962e2b9f3bb82ed958a2","src/bigint/arbitrary.rs":"6679833dffb38fa81f251bf9dd35b0d5b4cecb2a368e82aac92b00cef4dfc21b","src/bigint/bits.rs":"6bfdd854de8daf5c98b8eb8f0f29aa76ae6098a39dbe12eec35fbc9b8c247602","src/bigint/convert.rs":"331f635497d429ec62d829d8d6b476ba402e6530ddbbf9d5b117ed3042e41beb","src/bigint/division.rs":"a0197386b4c6f1465db7ac13bda956dad6bf0ac75accd8f75755f5c8cd05d5fd","src/bigint/multiplication.rs":"0e3ea5982ea0748420d36381f633656ddc6b4c4bee5b97d8e7b2550e67aa3e4d","src/bigint/power.rs":"7391588452764440ae01bbcdfb5b94776018e15bb966b448fbeed693a484ddea","src/bigint/serde.rs":"8240ed79ac11ec0ec2dfc85d4657693d5b03379bdd60a42dccee4764b000e5b6","src/bigint/shift.rs":"3aca826b132a95394e16161708bb6067985a25fef684b25f9f662cf3be12d672","src/bigint/subtraction.rs":"9411b9f59bda0060d286c798e3e765a64def44ad29d9cd6879b73149b9ea4369","src/bigrand.rs":"1e3a9fea94f3be4d052d0ceb1a8de13c580028ee26695fbba1da9de51289c858","src/biguint.rs":"df931fdd6becfde3ab392218fe57b8eab215ab0a8435129e451c9d6013c506b6","src/biguint/addition.rs":"88c02a33ed47ac091b199c102a991ef494bb291771f8b38358d22bb791e66618","src/biguint/arbitrary.rs":"895fe5a9bbcf40824d1a342e089fb2aec78cb9bad0dd489cfef489a3323f6c3b","src/biguint/bits.rs":"05f56e1cd494a3cd63e418ce3d797b9e979f34c4fbacb882e977548a1f69be65","src/biguint/convert.rs":"1071e03f57fa56070e8f696417f33a2fb738afcac329984be6236e33bca37dfd","src/biguint/division.rs":"3b05da7dddeceefaa67c62f016411fa82ce2dcaf1678fdb1ee70e7d170870d9f","src/biguint/iter.rs":"c21e30f573bdf1936e72dd56a89ee662329d25e8b55e37e88e9b1aea2da48abd","src/biguint/monty.rs":"2382e59abf592d009f3f0aefcd2cfd541f21b861aac109931bca2fbc3ee37c62","src/biguint/multiplication.rs":"ee3f611add01239d4e7fc023afc87f1e8b79cb4cb3326e69a120bbee5b014fdf","src/biguint/power.rs":"729d6c4a7f3686711e4f7a86a634ddb920a02be3de1667dac8a0dc85c3b7a854","src/biguint/serde.rs":"fc16ef8f5d036085ca408e3abfef53646499959cc77b03af622e97636f03f778","src/biguint/shift.rs":"b023fad4f86516660d8c4c9328215139fbe2f13afb86ab7ce0206d0c0e04ae00","src/biguint/subtraction.rs":"abbc6e8aa7fcbf58d8444ead208a07171b377f81cab509eaba5c71509b2e472e","src/lib.rs":"113da969e9dd905b8d2b3c3f0571f79971a4517d9c96d9d6b2e4a0873d1e51a6","src/macros.rs":"800239723d637c3ea1d6beb6a62b38a2300bd4c69c20dc0d50855ad6a8b31e70","tests/bigint.rs":"267b907cdb66e62050922b68367e1135517ba0afbd453b7bec807836e9d1d2f3","tests/bigint_bitwise.rs":"e6a2f76fa1eb919e7c513d7e30a8a2a963841a295a71103462fb8ab9792419b5","tests/bigint_scalar.rs":"a87e801e370686985d44e1f020c69fceca72b9f048e0f7301d2b8d38469e5636","tests/biguint.rs":"b8109cae66582c34f2838125063ef2c7293eb31549429119eadd7fd8f95376ee","tests/biguint_scalar.rs":"b09cda9d4fe6ec519e93282653f69b57d70db73b9cb59c0ea5cd0861ca2de266","tests/consts/mod.rs":"e20bc49a7cc95077242cbe4016b37745ea986c779d2385cb367fbfe44f15ff94","tests/fuzzed.rs":"f60a84c446ea2f45d87eb4ee64682ea63fdef05bc74f482739d4e968960e8f4e","tests/macros/mod.rs":"1a8f9f015e5caaac60ce9ccff01a75ae489801c3ede6e7b9b3c5079b6efefc9c","tests/modpow.rs":"f1e4ed4fe466b544d7c4e57d0a0dc7d1c97b430b4805cae12f0915b8c40ab66f","tests/roots.rs":"a3bc2de170a0f6297cc8d8830d608db537ca102ccf204fd4fb8e2d92675622d8"},"package":"f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f"}

src/rust/vendor/num-bigint/Cargo.toml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33
# When uploading crates to the registry Cargo will automatically
44
# "normalize" Cargo.toml files for maximal compatibility
55
# with all versions of Cargo and also rewrite `path` dependencies
6-
# to registry (e.g., crates.io) dependencies
6+
# to registry (e.g., crates.io) dependencies.
77
#
8-
# If you believe there's an error in this file please file an
9-
# issue against the rust-lang/cargo repository. If you're
10-
# editing this file be aware that the upstream Cargo.toml
11-
# will likely look very different (and much more reasonable)
8+
# If you are reading this file be aware that the original Cargo.toml
9+
# will likely look very different (and much more reasonable).
10+
# See Cargo.toml.orig for the original contents.
1211

1312
[package]
1413
edition = "2018"
1514
name = "num-bigint"
16-
version = "0.3.1"
15+
version = "0.4.3"
1716
authors = ["The Rust Project Developers"]
1817
build = "build.rs"
1918
exclude = ["/bors.toml", "/ci/*", "/.github/*"]
@@ -44,7 +43,7 @@ name = "roots"
4443
name = "shootout-pidigits"
4544
harness = false
4645
[dependencies.arbitrary]
47-
version = "0.4"
46+
version = "1"
4847
optional = true
4948
default-features = false
5049

@@ -59,12 +58,12 @@ features = ["i128"]
5958
default-features = false
6059

6160
[dependencies.quickcheck]
62-
version = "0.9"
61+
version = "1"
6362
optional = true
6463
default-features = false
6564

6665
[dependencies.rand]
67-
version = "0.7"
66+
version = "0.8"
6867
optional = true
6968
default-features = false
7069

src/rust/vendor/num-bigint/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Add this to your `Cargo.toml`:
1313

1414
```toml
1515
[dependencies]
16-
num-bigint = "0.3"
16+
num-bigint = "0.4"
1717
```
1818

1919
## Features
@@ -29,12 +29,12 @@ if your compiler is not new enough.
2929
feature is enabled. To enable it include rand as
3030

3131
```toml
32-
rand = "0.7"
33-
num-bigint = { version = "0.3", features = ["rand"] }
32+
rand = "0.8"
33+
num-bigint = { version = "0.4", features = ["rand"] }
3434
```
3535

3636
Note that you must use the version of `rand` that `num-bigint` is compatible
37-
with: `0.7`.
37+
with: `0.8`.
3838

3939
## Releases
4040

src/rust/vendor/num-bigint/RELEASES.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,77 @@
1+
# Release 0.4.3 (2021-11-02)
2+
3+
- [GHSA-v935-pqmr-g8v9]: [Fix unexpected panics in multiplication.][228]
4+
5+
**Contributors**: @arvidn, @cuviper, @guidovranken
6+
7+
[228]: https://github.com/rust-num/num-bigint/pull/228
8+
[GHSA-v935-pqmr-g8v9]: https://github.com/rust-num/num-bigint/security/advisories/GHSA-v935-pqmr-g8v9
9+
10+
# Release 0.4.2 (2021-09-03)
11+
12+
- [Use explicit `Integer::div_ceil` to avoid the new unstable method.][219]
13+
14+
**Contributors**: @catenacyber, @cuviper
15+
16+
[219]: https://github.com/rust-num/num-bigint/pull/219
17+
18+
# Release 0.4.1 (2021-08-27)
19+
20+
- [Fixed scalar divide-by-zero panics.][200]
21+
- [Implemented `DoubleEndedIterator` for `U32Digits` and `U64Digits`.][208]
22+
- [Optimized multiplication to avoid unnecessary allocations.][199]
23+
- [Optimized string formatting for very large values.][216]
24+
25+
**Contributors**: @cuviper, @PatrickNorton
26+
27+
[199]: https://github.com/rust-num/num-bigint/pull/199
28+
[200]: https://github.com/rust-num/num-bigint/pull/200
29+
[208]: https://github.com/rust-num/num-bigint/pull/208
30+
[216]: https://github.com/rust-num/num-bigint/pull/216
31+
32+
# Release 0.4.0 (2021-03-05)
33+
34+
### Breaking Changes
35+
36+
- Updated public dependences on [arbitrary, quickcheck][194], and [rand][185]:
37+
- `arbitrary` support has been updated to 1.0, requiring Rust 1.40.
38+
- `quickcheck` support has been updated to 1.0, requiring Rust 1.46.
39+
- `rand` support has been updated to 0.8, requiring Rust 1.36.
40+
- [`Debug` now shows plain numeric values for `BigInt` and `BigUint`][195],
41+
rather than the raw list of internal digits.
42+
43+
**Contributors**: @cuviper, @Gelbpunkt
44+
45+
[185]: https://github.com/rust-num/num-bigint/pull/185
46+
[194]: https://github.com/rust-num/num-bigint/pull/194
47+
[195]: https://github.com/rust-num/num-bigint/pull/195
48+
49+
# Release 0.3.3 (2021-09-03)
50+
51+
- [Use explicit `Integer::div_ceil` to avoid the new unstable method.][219]
52+
53+
**Contributors**: @catenacyber, @cuviper
54+
55+
# Release 0.3.2 (2021-03-04)
56+
57+
- [The new `BigUint` methods `count_ones` and `trailing_ones`][175] return the
58+
number of `1` bits in the entire value or just its least-significant tail,
59+
respectively.
60+
- [The new `BigInt` and `BigUint` methods `bit` and `set_bit`][183] will read
61+
and write individual bits of the value. For negative `BigInt`, bits are
62+
determined as if they were in the two's complement representation.
63+
- [The `from_radix_le` and `from_radix_be` methods][187] now accept empty
64+
buffers to represent zero.
65+
- [`BigInt` and `BigUint` can now iterate digits as `u32` or `u64`][192],
66+
regardless of the actual internal digit size.
67+
68+
**Contributors**: @BartMassey, @cuviper, @janmarthedal, @sebastianv89, @Speedy37
69+
70+
[175]: https://github.com/rust-num/num-bigint/pull/175
71+
[183]: https://github.com/rust-num/num-bigint/pull/183
72+
[187]: https://github.com/rust-num/num-bigint/pull/187
73+
[192]: https://github.com/rust-num/num-bigint/pull/192
74+
175
# Release 0.3.1 (2020-11-03)
276

377
- [Addition and subtraction now uses intrinsics][141] for performance on `x86`

src/rust/vendor/num-bigint/benches/bigint.rs

Lines changed: 62 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,11 @@ extern crate test;
55

66
use num_bigint::{BigInt, BigUint, RandBigInt};
77
use num_traits::{FromPrimitive, Num, One, Zero};
8-
use rand::rngs::StdRng;
9-
use rand::SeedableRng;
108
use std::mem::replace;
119
use test::Bencher;
1210

13-
fn get_rng() -> StdRng {
14-
let mut seed = [0; 32];
15-
for i in 1..32 {
16-
seed[usize::from(i)] = i;
17-
}
18-
SeedableRng::from_seed(seed)
19-
}
11+
mod rng;
12+
use rng::get_rng;
2013

2114
fn multiply_bench(b: &mut Bencher, xbits: u64, ybits: u64) {
2215
let mut rng = get_rng();
@@ -46,7 +39,7 @@ fn factorial(n: usize) -> BigUint {
4639
let mut f: BigUint = One::one();
4740
for i in 1..=n {
4841
let bu: BigUint = FromPrimitive::from_usize(i).unwrap();
49-
f += bu;
42+
f *= bu;
5043
}
5144
f
5245
}
@@ -181,35 +174,40 @@ fn fib_to_string(b: &mut Bencher) {
181174
b.iter(|| fib.to_string());
182175
}
183176

184-
fn to_str_radix_bench(b: &mut Bencher, radix: u32) {
177+
fn to_str_radix_bench(b: &mut Bencher, radix: u32, bits: u64) {
185178
let mut rng = get_rng();
186-
let x = rng.gen_bigint(1009);
179+
let x = rng.gen_bigint(bits);
187180
b.iter(|| x.to_str_radix(radix));
188181
}
189182

190183
#[bench]
191184
fn to_str_radix_02(b: &mut Bencher) {
192-
to_str_radix_bench(b, 2);
185+
to_str_radix_bench(b, 2, 1009);
193186
}
194187

195188
#[bench]
196189
fn to_str_radix_08(b: &mut Bencher) {
197-
to_str_radix_bench(b, 8);
190+
to_str_radix_bench(b, 8, 1009);
198191
}
199192

200193
#[bench]
201194
fn to_str_radix_10(b: &mut Bencher) {
202-
to_str_radix_bench(b, 10);
195+
to_str_radix_bench(b, 10, 1009);
196+
}
197+
198+
#[bench]
199+
fn to_str_radix_10_2(b: &mut Bencher) {
200+
to_str_radix_bench(b, 10, 10009);
203201
}
204202

205203
#[bench]
206204
fn to_str_radix_16(b: &mut Bencher) {
207-
to_str_radix_bench(b, 16);
205+
to_str_radix_bench(b, 16, 1009);
208206
}
209207

210208
#[bench]
211209
fn to_str_radix_36(b: &mut Bencher) {
212-
to_str_radix_bench(b, 36);
210+
to_str_radix_bench(b, 36, 1009);
213211
}
214212

215213
fn from_str_radix_bench(b: &mut Bencher, radix: u32) {
@@ -358,6 +356,21 @@ fn pow_bench_bigexp(b: &mut Bencher) {
358356
});
359357
}
360358

359+
#[bench]
360+
fn pow_bench_1e1000(b: &mut Bencher) {
361+
b.iter(|| BigUint::from(10u32).pow(1_000));
362+
}
363+
364+
#[bench]
365+
fn pow_bench_1e10000(b: &mut Bencher) {
366+
b.iter(|| BigUint::from(10u32).pow(10_000));
367+
}
368+
369+
#[bench]
370+
fn pow_bench_1e100000(b: &mut Bencher) {
371+
b.iter(|| BigUint::from(10u32).pow(100_000));
372+
}
373+
361374
/// This modulus is the prime from the 2048-bit MODP DH group:
362375
/// https://tools.ietf.org/html/rfc3526#section-3
363376
const RFC3526_2048BIT_MODP_GROUP: &str = "\
@@ -393,3 +406,35 @@ fn modpow_even(b: &mut Bencher) {
393406

394407
b.iter(|| base.modpow(&e, &m));
395408
}
409+
410+
#[bench]
411+
fn to_u32_digits(b: &mut Bencher) {
412+
let mut rng = get_rng();
413+
let n = rng.gen_biguint(2048);
414+
415+
b.iter(|| n.to_u32_digits());
416+
}
417+
418+
#[bench]
419+
fn iter_u32_digits(b: &mut Bencher) {
420+
let mut rng = get_rng();
421+
let n = rng.gen_biguint(2048);
422+
423+
b.iter(|| n.iter_u32_digits().max());
424+
}
425+
426+
#[bench]
427+
fn to_u64_digits(b: &mut Bencher) {
428+
let mut rng = get_rng();
429+
let n = rng.gen_biguint(2048);
430+
431+
b.iter(|| n.to_u64_digits());
432+
}
433+
434+
#[bench]
435+
fn iter_u64_digits(b: &mut Bencher) {
436+
let mut rng = get_rng();
437+
let n = rng.gen_biguint(2048);
438+
439+
b.iter(|| n.iter_u64_digits().max());
440+
}

src/rust/vendor/num-bigint/benches/gcd.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,10 @@ extern crate test;
66
use num_bigint::{BigUint, RandBigInt};
77
use num_integer::Integer;
88
use num_traits::Zero;
9-
use rand::rngs::StdRng;
10-
use rand::SeedableRng;
119
use test::Bencher;
1210

13-
fn get_rng() -> StdRng {
14-
let mut seed = [0; 32];
15-
for i in 1..32 {
16-
seed[usize::from(i)] = i;
17-
}
18-
SeedableRng::from_seed(seed)
19-
}
11+
mod rng;
12+
use rng::get_rng;
2013

2114
fn bench(b: &mut Bencher, bits: u64, gcd: fn(&BigUint, &BigUint) -> BigUint) {
2215
let mut rng = get_rng();
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use rand::RngCore;
2+
3+
pub(crate) fn get_rng() -> impl RngCore {
4+
XorShiftStar {
5+
a: 0x0123_4567_89AB_CDEF,
6+
}
7+
}
8+
9+
/// Simple `Rng` for benchmarking without additional dependencies
10+
struct XorShiftStar {
11+
a: u64,
12+
}
13+
14+
impl RngCore for XorShiftStar {
15+
fn next_u32(&mut self) -> u32 {
16+
self.next_u64() as u32
17+
}
18+
19+
fn next_u64(&mut self) -> u64 {
20+
// https://en.wikipedia.org/wiki/Xorshift#xorshift*
21+
self.a ^= self.a >> 12;
22+
self.a ^= self.a << 25;
23+
self.a ^= self.a >> 27;
24+
self.a.wrapping_mul(0x2545_F491_4F6C_DD1D)
25+
}
26+
27+
fn fill_bytes(&mut self, dest: &mut [u8]) {
28+
for chunk in dest.chunks_mut(8) {
29+
let bytes = self.next_u64().to_le_bytes();
30+
let slice = &bytes[..chunk.len()];
31+
chunk.copy_from_slice(slice)
32+
}
33+
}
34+
35+
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand::Error> {
36+
Ok(self.fill_bytes(dest))
37+
}
38+
}

0 commit comments

Comments
 (0)