Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #4709 RFC? refactor and reseed rand::Rng #4958

Merged
merged 5 commits into from
Feb 15, 2013
Merged

Issue #4709 RFC? refactor and reseed rand::Rng #4958

merged 5 commits into from
Feb 15, 2013

Conversation

cpeterso
Copy link
Contributor

For Issue #4709:

c531506 rt: rand.rs expects rust_next() to return uint32_t, not size_t

rand.rs expects rustrt::rand_next() to return u32, but the rand_next() C function returns size_t: https://github.com/mozilla/rust/blob/ca71c6ec5bb8106121cbe33eec5a6a9ca7786039/src/libcore/rand.rs#L34

f4320b6 move isaac RNG utility functions to new rust_rng.cpp file
665e900 encapsulate isaac RNG in rust_rng struct

Move isaac's randctx into a rust_rng struct to make names similar to rand::Rng function names and prepare for auto-reseeding in the next commit.

9a78dc9 reseed rust_rng after generating 32KB

Precedents from other languages:

9a76d71 don't deplete RNG entropy when there is only one runnable task

rust_sched_loop::schedule_task() unnecessarily calls isaac_rand() for the common case when there is only 1 runnable task, thus depleting RNG entropy and incurring unnecessary overhead.

@cpeterso
Copy link
Contributor Author

btw, most of this code could be deleted if the task_rng Rng was rewritten in Rust. The only other code that depends on the isaac C code is rust_schec_loop::schedule_task(), which doesn't need a strong CSPRNG or, if the task scheduler is rewritten in Rust, could use the Rust task_rng.

@graydon
Copy link
Contributor

graydon commented Feb 15, 2013

I concur that much of this stuff should move into rust at some point; but this is a helpful short-term fix for misbehavior and I greatly appreciate it!

bors added a commit that referenced this pull request Feb 15, 2013
For Issue #4709:

**c531506 rt: rand.rs expects `rust_next()` to return `uint32_t`, not `size_t`**

rand.rs expects `rustrt::rand_next()` to return `u32`, but the `rand_next()` C function returns `size_t`: https://github.com/mozilla/rust/blob/ca71c6ec5bb8106121cbe33eec5a6a9ca7786039/src/libcore/rand.rs#L34

**f4320b6 move isaac RNG utility functions to new rust_rng.cpp file**
**665e900 encapsulate isaac RNG in `rust_rng` struct**

Move isaac's `randctx` into a `rust_rng` struct to make names similar to `rand::Rng` function names and prepare for auto-reseeding in the next commit.

**9a78dc9 reseed `rust_rng` after generating 32KB**

Precedents from other languages:
* Haskell's `GenAutoReseed` generator reseeds itself after generating 32KB: http://hackage.haskell.org/packages/archive/DRBG/0.1.2/doc/html/Crypto-Random-DRBG.html#t:GenAutoReseed

* Go's RNG reseeds itself after generating 1MB: https://code.google.com/p/go/source/browse/src/pkg/crypto/rand/rand_unix.go?name=go1.0.3#94

**9a76d71 don't deplete RNG entropy when there is only one runnable task**

`rust_sched_loop::schedule_task()` unnecessarily calls `isaac_rand()` for the common case when there is only 1 runnable task, thus depleting RNG entropy and incurring unnecessary overhead.
@bors bors closed this Feb 15, 2013
@bors bors merged commit 9a76d71 into rust-lang:incoming Feb 15, 2013
bors added a commit to rust-lang-ci/rust that referenced this pull request May 2, 2020
Fix bad `explicit_into_iter_loop` suggestion

Fixes rust-lang#4958

changelog: Fix bad `explicit_into_iter_loop` suggestion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants