rust-lang / rust-lang/rust

ESP-IDF's `esp_fill_random` is not always cryptographically secure

Open
#157,566 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs-triage O-ESP-IDF T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

std currently uses esp_fill_random as random number generator on ESP-IDF. Unfortunately, Espressif's platform documentation says that

The entropy source enabled during the boot process by the ESP-IDF Second Stage Bootloader seeds the internal RNG state with some entropy. However, the internal hardware RNG state is not large enough to provide a continuous stream of true random numbers. This is why a continuous entropy source must be enabled whenever true random numbers are required.

with "continuous entropy sources" referring to the radio system and an internal entropy source. And thus

the output of the RNG should be considered as pseudo-random only.

without these sources being enabled. Unfortunately, there does not appear to exist an API for detecting whether said continuous entropy sources are enabled.

Ideally, Espressif would implement their own CSPRNG in their HAL, and properly seed it in the bootloader (or at the first call to esp_fill_random). But until that happens, I see three ways to deal with this on our end:

  1. Disable random data generation on ESP-IDF entirely, until Espressif fix their API.
  2. Provide a certify_rng_available (name bikesheddable!) function in std::os::random, and only call esp_fill_random if that function has been called.
  3. Call it a day, as our documentation already states that: "If security is a concern, consult the platform documentation below for the specific guarantees your target provides.". I'm not a fan of this "solution".

CC @ivmarkov @MabezDev @SergioGasquez

Also see:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at std's ESP-IDF use of esp_fill_random and review the Espressif random API documentation linked in the issue. Compare the three proposed policies, including whether std::os::random needs a certify_rng_available entry point; done requires an agreed security guarantee and an implementation or documentation change that matches it.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
embedded-iot, security
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.