Skip to content

ChaCha20 as optional ThreadRng algorithm #1661

@zairly

Description

@zairly

Background

What is your motivation?

  • ChaCha12 is the current algorithm for ThreadRng, and there’s no simple way to change it, while keeping all the nice thread-local ergonomics, auto reseeding, and a feature rich API.
  • ChaCha20 is the IETF standard, more future-proof algorithm. It provides better security margin at the cost of slightly worse performance. For vast majority of programs, it’s overkill. But for security-sensitive programs and for peace of mind, it can be worth it.

What type of application is this? (E.g. cryptography, game, numerical simulation)
Cryptography

Feature request

Add a simple way to switch to ChaCha20 as the default ThreadRng algorithm.

This could be done with an opt-in feature flag, that, when enabled, would change the underlying ThreadRng algorithm to ChaCha20.

It could be implemented without any breaking changes. The API would stay the same, except it’d just use the other algorithm internally.

println!("{}", rng().random_range(0..100));
            // ^^^^^ uses ChaCha20 if explicitly enabled;
            //       otherwise still uses ChaCha12

Happy to make a PR if this looks good.

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