[rom_ext,kmac] Switch KMAC driver to EDN entropy mode - #31145
Conversation
vogelpi
left a comment
There was a problem hiding this comment.
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 .
@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. |
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
Yes, there's only a few KMAC mode usage in ROM_EXT and won't exceed this limit.
Yes, please :)
I think this PR completely removes the sw case? |
vogelpi
left a comment
There was a problem hiding this comment.
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.
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. |
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
|
LGTM |
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:
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