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

Integration into std #21

Closed
dhardy opened this issue Apr 19, 2019 · 5 comments
Closed

Integration into std #21

dhardy opened this issue Apr 19, 2019 · 5 comments

Comments

@dhardy
Copy link
Member

dhardy commented Apr 19, 2019

It has been proposed to include roughly this code into the std lib. This is an issue to summarise the proposal and track future development.

Draft RFC: https:/dhardy/rfcs/blob/system-random/text/0000-system-random.md

Discussions:

@tarcieri
Copy link

I think it'd be nice to have something that no_std users can also leverage (even if gated behind a nightly-only feature flag), although that might be out-of-scope for this particular RFC.

"Isn't that what the rand crate is for?" you might ask? Well I'm thinking something a little global_allocator perhaps. Here's a handwavy example:

// If this seems too hard to stabilize, feature gate it?
#[feature(global_rng)]

#[global_rng]
pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
    [...]
}

The idea being that embedded packages can plug in a proprietary global RNG.

I'd love to use getrandom for cryptography projects, but there needs to be a way for these projects to support no_std. I've started switching to getrandom on my std-dependent projects, but I'm hesitant to do so on my projects which support no_std for these reasons.

@dhardy
Copy link
Member Author

dhardy commented May 21, 2019

If getrandom remains as a crate, this isn't too hard: I proposed a couple of solutions in #4.

On the other hand, if this were integrated into the standard library, it would need to be included in core as a wrapper around some inner function like you listed. I'm not really sure how much sense this makes and don't have much interest in pushing for integration myself.

(Note: in both cases, another crate implementing some kind of entropy pool may be needed to implement getrandom_inner with the limited functionality available on some platforms.)

@newpavlov
Copy link
Member

IIUC with inclusion into core we will not need a separate inner function. getrandom function can be a weak lang item (akin global allocator), which will have an always erroring default implementation overwritable by applications.

I think it will be reasonable to first start with #4 and move with std inclusion RFC later.

@tarcieri
Copy link

@newpavlov yeah, something to the effect of a lang item was exactly what I was thinking, but I'm not really aware of the difficulty involved in adding a new one, and I know a lot of people think there are too many already

@newpavlov
Copy link
Member

Closing in favor of rust-lang/rust#62079.

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

No branches or pull requests

3 participants