nskinkel / libredsalt

2 stars 1 forks source link

Don't create a new OsRng on every randombytes() call #23

Closed nskinkel closed 9 years ago

nskinkel commented 9 years ago

randombytes() currently does something like:

... randombytes(...) {
    let mut rng = OsRng::new().ok().expect("OsRng failed!");
    // other stuff
}

We should figure out a way to avoid creating a new instance on every call, ideally just do it once on the first randombytes() invocation.

nskinkel commented 9 years ago

After a bit of research and playing around, it seems like this will actually be a little icky to do correctly.

Some initial options:

nskinkel commented 9 years ago

As I learn more about Rust static variables, there's another wrinkle here: static variables can't implement the Drop trait...which OsRng does :(