Skip to content

[rom_ext,kmac] Switch KMAC driver to EDN entropy mode - #31145

Merged
vogelpi merged 2 commits into
lowRISC:earlgrey_1.0.0from
sasdf:mjTmkvwoymp
Sep 1, 2026
Merged

[rom_ext,kmac] Switch KMAC driver to EDN entropy mode#31145
vogelpi merged 2 commits into
lowRISC:earlgrey_1.0.0from
sasdf:mjTmkvwoymp

Conversation

@sasdf

@sasdf sasdf commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

In the KMAC hardware block, the entropy source mode (CFG_SHADOWED.entropy_mode) is latched upon leaving the reset state and cannot be modified without resetting the IP.

Previously, the ROM_EXT KMAC driver configured KMAC in software entropy mode (sw_mode) and wrote hardcoded seeds, permanently locking KMAC into software mode and preventing downstream software/tests from using EDN mode.

To resolve this:

  • Configure KMAC to use EDN mode (KMAC_CFG_SHADOWED_ENTROPY_MODE_VALUE_EDN_MODE) and remove the software seed array and register writes.
  • Configure ENTROPY_REFRESH_THRESHOLD_SHADOWED to maximum (0x3ff) so that automatic PRNG reseed requests are not triggered unexpectedly during hashing.
  • Keep wait timer and prescaler in ENTROPY_PERIOD configured to maximum to ensure forward progress.
  • Update deadlock prevention and FIFO polling comments to align with the guidance in 27630 and 27526.
  • Update kmac_unittest mock expectations and kmac_functest to re-enable entropy before running KMAC-256 KAT tests.

Related to:

Tested manually with the kmac tests re-enabled in the ROM_EXT env:

  • //sw/device/tests:kmac_error_conditions_test_fpga_cw340_sival_rom_ext
  • //sw/device/tests:kmac_entropy_test_fpga_cw340_sival_rom_ext

@sasdf
sasdf requested review from jwnrt, moidx, nasahlpa and siemen11 August 26, 2026 13:18
@nasahlpa
nasahlpa requested review from etterli and vogelpi August 26, 2026 13:19
@sasdf
sasdf marked this pull request as ready for review August 26, 2026 13:19
@sasdf
sasdf requested a review from a team as a code owner August 26, 2026 13:19
@siemen11
siemen11 requested a review from GillonB August 26, 2026 13:21
@sasdf sasdf added the CI:Rerun Rerun failed CI jobs label Aug 27, 2026
@github-actions github-actions Bot removed the CI:Rerun Rerun failed CI jobs label Aug 27, 2026

@siemen11 siemen11 left a comment

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.

Thank you @sasdf !

@vogelpi vogelpi left a comment

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.

Thanks for taking care of this @sasdf !

My understanding is that by setting the maximum ENTROPY_REFRESH_THRESHOLD value, we can guarantee that there will be no automatically triggered EDN reseed operation in ROM_EXT, right?

I believe this is fine, but we also need to update the cryptolib accordingly where we will need to implement the manual reseeding procedure https://opentitan.org/earlgrey_1.0.0/book/hw/ip/kmac/doc/programmers_guide.html#manually-triggering-prng-reseeds or ensure we always check the message FIFO depth before pushing data @siemen11 .

Comment thread sw/device/silicon_creator/lib/drivers/kmac.c Outdated
Comment thread sw/device/silicon_creator/lib/drivers/kmac.c
@nasahlpa

Copy link
Copy Markdown
Contributor

I believe this is fine, but we also need to update the cryptolib accordingly where we will need to implement the manual reseeding procedure https://opentitan.org/earlgrey_1.0.0/book/hw/ip/kmac/doc/programmers_guide.html#manually-triggering-prng-reseeds or ensure we always check the message FIFO depth before pushing data @siemen11 .

@etterli and I just were discussing offline and we came to the same conclusion that CL needs changes as well. Fine for me to do this in a separate PR.

@OTshimeon

Copy link
Copy Markdown

@vogelpi @sasdf
Don't we also want to change the SW case code to use a build time random value instead of a code time constant value?

In the KMAC hardware block, the entropy source mode (CFG_SHADOWED.entropy_mode)
is latched upon leaving the reset state and cannot be modified without
resetting the IP.

Previously, the ROM_EXT KMAC driver configured KMAC in software entropy
mode (sw_mode) and wrote hardcoded seeds, permanently locking KMAC into
software mode and preventing downstream software/tests from using EDN mode.

To resolve this:
- Configure KMAC to use EDN mode (KMAC_CFG_SHADOWED_ENTROPY_MODE_VALUE_EDN_MODE)
  and remove the software seed array and register writes.
- Configure ENTROPY_REFRESH_THRESHOLD_SHADOWED to maximum (0x3ff) so that
  automatic PRNG reseed requests are not triggered unexpectedly during hashing.
- Keep wait timer and prescaler in ENTROPY_PERIOD configured to maximum to ensure
  forward progress.
- Update deadlock prevention and FIFO polling comments to align with the guidance
  in 27630 and 27526.
- Update kmac_unittest mock expectations and kmac_functest to re-enable entropy
  before running KMAC-256 KAT tests.

Related to 27526.

Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: Idf43b1da5c7f451f9a45f3391bcd20e16a6a6964
@sasdf

sasdf commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

My understanding is that by setting the maximum ENTROPY_REFRESH_THRESHOLD value, we can guarantee that there will be no automatically triggered EDN reseed operation in ROM_EXT, right?

Yes, there's only a few KMAC mode usage in ROM_EXT and won't exceed this limit.

@etterli and I just were discussing offline and we came to the same conclusion that CL needs changes as well. Fine for me to do this in a separate PR.

Yes, please :)

Don't we also want to change the SW case code to use a build time random value instead of a code time constant value?

I think this PR completely removes the sw case?

@sasdf
sasdf requested a review from vogelpi August 27, 2026 15:25

@vogelpi vogelpi left a comment

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.

LGTM, thanks @sasdf !

And yes, the SW mode should really not be used. It's primary purpose in Gen1 was to de-risk the chip in case of entropy failures.

As proposed in the linked issue, I will rework the interface to simplify it and to allow switching back and forth with a REGWEN to enable locking the mode.

@vogelpi

vogelpi commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

I believe this is fine, but we also need to update the cryptolib accordingly where we will need to implement the manual reseeding procedure https://opentitan.org/earlgrey_1.0.0/book/hw/ip/kmac/doc/programmers_guide.html#manually-triggering-prng-reseeds or ensure we always check the message FIFO depth before pushing data @siemen11 .

@etterli and I just were discussing offline and we came to the same conclusion that CL needs changes as well. Fine for me to do this in a separate PR.

Thanks @nasahlpa , I suggest to adopt the method where you don't need to check the FIFO but where you periodically perform a manual reseed operation.

Comment thread sw/device/tests/kmac_error_conditions_test.c Outdated
Enable the `fpga_cw340_sival_rom_ext` execution environment for
`kmac_entropy_test` and `kmac_error_conditions_test`, as it is now
feasible with the ROM_EXT setting up KMAC in EDN mode.

When running kmac_error_conditions_test under ROM_EXT (sival_rom_ext),
KMAC is already seeded and in the StRandReady state.

In test_err_wait_timer_expired(), leaving entropy_hash_threshold
uninitialized (defaulting to 0) caused KMAC to never request fresh
entropy from EDN during hashing, meaning the wait timer was never
started and the EDN timeout error was not triggered.

Set entropy_hash_threshold to 1 in test_err_wait_timer_expired() so
that an automatic EDN reseed is requested upon the first hash
invocation even when KMAC is already in StRandReady.

Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: Ifb1ccb1e765c1b9e2a86af569c60c0336a6a6964
@GillonB

GillonB commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

LGTM

@vogelpi vogelpi added the CI:Rerun Rerun failed CI jobs label Sep 1, 2026
@github-actions github-actions Bot removed the CI:Rerun Rerun failed CI jobs label Sep 1, 2026
@vogelpi
vogelpi merged commit 004be3a into lowRISC:earlgrey_1.0.0 Sep 1, 2026
67 of 70 checks passed
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.

6 participants