Skip to content

getrandom, security and fallback entropy #760

@dhardy

Description

@dhardy

Our getrandom crate is close to initial release, which means we can almost start building on it. This means:

  • rand_os::OsRng will become a thin wrapper around getrandom
  • either we have to map getrandom::Error values to rand_core::Error values, or replace the latter completely (suggested in Tracker: Rand 0.7 #715)
  • the rand_os crate will become trivially small

In #715 we have talked about other possible changes:

  • the getrandom crate should handle other sources on embedded platforms
  • we no longer appear to need a fallback in case of OS failure
  • therefore EntropyRng is no longer needed
  • we could replace rand::FromEntropy::from_entropy with rand_core::SeedableRng::from_entropy

Here I would like to add a caveat: we have no proof that a fallback entropy source is not needed. @tarcieri has pointed out in #699 that we cannot be confident of the security of JitterRng, however there is also resistance to merely switching to RDRAND (partly since it is not available on all platforms, and in part based on the belief that we shouldn't need any fallback).

What we do not want to do is remove EntropyRng only to find that we need to add it back again, meanwhile there is strong resistance to the idea of including a fallback within getrandom. This means that for now we should either keep EntropyRng (even if it is merely a wrapper) or plan to put any needed fallback within OsRng.

Additionally, it seems clear that we don't want to move the JitterRng code into rand_core, and we cannot make rand_core depend on rand_jitter circularly. The same applies to the rdrand crate. Thus the only option for including a fallback within rand_core would be a direct RDRAND implementation, which we probably also don't want.

Like it or not, this means that we cannot move OsRng or from_entropy into rand_core unless we can prove that we don't need a fallback.

Now, if we want to pursue a no-fallback entropy source, we could try removing all fallbacks for Rand 0.7 and watch for error reports. However, I'm not sure whether we want to do so (personally I agree with @cpeterso that Rand should "just work").


This means we have to look at other options for now:

  1. Keep rand_os with just OsRng even though this is essentially an empty crate
  2. Move EntropyRng to rand_os (@burdges suggestion)
  3. Drop rand_os and go back to rand::rngs::OsRng

Proposal: 2: move EntropyRng and FromEntropy to rand_os for now, keeping re-exports in rand, add rdrand as a fallback option, and put both jitter and rdrand behind feature flags (disabled by default).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions