Skip to content

[crypto/entropy] Make the entropy source ready for use#29615

Open
siemen11 wants to merge 4 commits intolowRISC:earlgrey_1.0.0from
siemen11:entropy_src_config
Open

[crypto/entropy] Make the entropy source ready for use#29615
siemen11 wants to merge 4 commits intolowRISC:earlgrey_1.0.0from
siemen11:entropy_src_config

Conversation

@siemen11
Copy link
Copy Markdown
Contributor

This PR does the following:

  • Open the entropy init and check to the user. The user HAS to use this function since the ROM_EXT does NOT enable FIPS mode at plan of record. While it was originally planned for the ROM_EXT to drive this config, the entropy driver was not using correct thresholds while the ROM_EXT is now frozen. Hence, we need to move this to the firmware.
  • Add in basic fault injection protection by rereading the registers.
  • Prevent infinite timeouts by adding a timeout to all polling to improve reliability.
  • Set FIPS thresholds for the entropy source, leave the EDN config unchanged
  • Adapt all tests to use the new user exposed entropy functions with FIPS thresholds

@siemen11 siemen11 requested a review from a team as a code owner March 29, 2026 11:32
@siemen11 siemen11 requested review from andrea-caforio, cfrantz, johannheyszl, moidx, nasahlpa, pamaury and vsukhoml and removed request for a team and pamaury March 29, 2026 11:32
@siemen11 siemen11 added the CherryPick:master This PR should be cherry-picked to master label Mar 29, 2026
@siemen11 siemen11 requested a review from timothytrippel March 29, 2026 12:05
@siemen11
Copy link
Copy Markdown
Contributor Author

A question: the entropy_complex_init now changed to new FIPS thresholds. Does this have an impact in provisioning or silicon_creator?

@siemen11 siemen11 force-pushed the entropy_src_config branch 5 times, most recently from 0912e5f to d33fd99 Compare March 30, 2026 09:26
@siemen11 siemen11 added the CI:Rerun Rerun failed CI jobs label Mar 30, 2026
.adaptp_lo_threshold = 2048 - 1591, // 457
.bucket_threshold = 201,
.markov_hi_threshold = 824,
.markov_lo_threshold = 1024 - 824, // 200
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This configuration is made under assumption that OpenTitan implements analogue part of entropy source with H=0.5. It may not be true for other implementations.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean to leave this setting specifically for earlgrey_1.0.0? I will add a comment on this

@siemen11 siemen11 force-pushed the entropy_src_config branch from d33fd99 to 9cca2bb Compare March 31, 2026 07:58
Originally, the idea was to call entropy_complex_init in the ROM_EXT to
instantiate the RNG in a final FIPS state. However, the ROM_EXT is in
its frozen final version and the entropy_complex_init still has dummy
threshold values. Hence, the entropy_complex_init should be called from
firmware instead. However, the entropy_complex_init is only a driver
function returning a regular status_t, it is not an impl function with
an otcrypto_status_t. Hence, it is not opened up to the user. Instead,
make a wrapper to the functions needed by the user and add them in the
include folder.
Switch all functests to use the wrapper instead (since ideally to ingest
impl functions).

Collateral: looks like the driver was some glue for missing Bazel
dependencies, add rv_core_ibex to the random_order function.

Signed-off-by: Siemen Dhooghe <sdhooghe@google.com>
The TODOs in entropy specified to ensure fault protection. With the
entropy source configure, reread the registers to ensure the
configuration written is the expected one. Remove the TODOs. The entropy
check is presumed to be called multiple times, hence it does not need
additional protection.

Signed-off-by: Siemen Dhooghe <sdhooghe@google.com>
Add timeouts to all polling of registers. This is just to add
reliability in situations where the chips experiences a malfunction.

Signed-off-by: Siemen Dhooghe <sdhooghe@google.com>
Set the entropy source driver to align with certified
NIST SP 800-90B requirements.

Specific changes include:

- NIST 800-90B Health Test Thresholds: Increased the `fips_test_window_size` to 2048 bits to comply with
        FIPS standards for binary noise sources.
- Bypass Register Configuration: Updated the `SET_FIPS_THRESH` and `VERIFY_FIPS_THRESH` macros to
        write and verify both the `FIPS_THRESH` and `BYPASS_THRESH` fields
        simultaneously.

Note: CSRNG `FIPS_FORCE_ENABLE` and EDN continuous polling rates remain at
their defaults to ensure the FIFO does not run empty with, for exmaple, the OTBN during the initial TRNG FIPS warm-up phase.

Signed-off-by: Siemen Dhooghe <sdhooghe@google.com>
@siemen11 siemen11 force-pushed the entropy_src_config branch from 9cca2bb to fce0466 Compare March 31, 2026 15:59
@siemen11 siemen11 removed CherryPick:master This PR should be cherry-picked to master CI:Rerun Rerun failed CI jobs labels Mar 31, 2026
@siemen11 siemen11 added the CI:Rerun Rerun failed CI jobs label Apr 1, 2026
@github-actions github-actions bot removed the CI:Rerun Rerun failed CI jobs label Apr 1, 2026
},
// All cut off values are calculated with the assumption that:
// H=0.5 per bit => H=2 for 4-bit symbols
// α = 2⁻⁴⁰ (alpha = 2^-40), false positive probability
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// α = 2⁻⁴⁰ (alpha = 2^-40), false positive probability
// α = 2⁻⁴⁰ (alpha = 2^-40), false positive probability
// Please note that entropy H per bit will depend on silicon and will likely need to be adapted.

},
},
// All cut off values are calculated with the assumption that:
// H=0.5 per bit => H=2 for 4-bit symbols
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// H=0.5 per bit => H=2 for 4-bit symbols
// H = 0.5 per bit => H = 2 for 4-bit symbols

Copy link
Copy Markdown
Contributor

@johannheyszl johannheyszl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @siemen11 this lgtm - important we can call this from user

otcrypto_status_t otcrypto_entropy_init(void);

/**
* Ensures that the entropy complex is ready for use and verify the health
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Ensures that the entropy complex is ready for use and verify the health
* Ensures that the entropy complex is ready for use and runs the health


/**
* Ensures that the entropy complex is ready for use and verify the health
* checks of the generated randomness.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* checks of the generated randomness.
* checks for the generated randomness.

* Ensures that the entropy complex is running and that `entropy_src` is in
* FIPS mode, and verifies the thresholds for health tests in `entropy_src`.
* This function should be called periodically while the entropy complex is in
* use, because the threshold registers are not shadowed.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* use, because the threshold registers are not shadowed.
* use, to prevent FI because the threshold registers are not shadowed.

* use, because the threshold registers are not shadowed.
*
* The test also verifies the health checks of the generated randomness
* providing a status error if a health test jumped.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* providing a status error if a health test jumped.
* providing a status error if a health test failed.

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

Successfully merging this pull request may close these issues.

4 participants