Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entropy Stack update #153

Open
wants to merge 37 commits into
base: ot-earlgrey-9.2.0
Choose a base branch
from

Conversation

rivos-eblot
Copy link

This update contains mostly EDN IP update which has been heavily reworked based on HW simulation (Verilator traces) rather than on EDN documentation, as it has been done for the initial implementation.

It also contains several updates and fixes for the CSRNG and EntropySrc, but those IPs still require some updates, which will be delivered in a forth coming PR.

@rivos-eblot rivos-eblot requested a review from loiclefort March 25, 2025 17:17
@rivos-eblot rivos-eblot marked this pull request as draft March 25, 2025 17:17
@rivos-eblot rivos-eblot force-pushed the dev/ebl/entropy_stack_update branch from fc891c7 to 5b61a89 Compare March 25, 2025 17:20
@rivos-eblot rivos-eblot force-pushed the dev/ebl/entropy_stack_update branch from 5b61a89 to 53d3431 Compare March 25, 2025 19:37
@rivos-eblot rivos-eblot force-pushed the dev/ebl/entropy_stack_update branch from 53d3431 to 5de8cd8 Compare March 26, 2025 13:28
@rivos-eblot
Copy link
Author

Updated EDN: GENERATE command header was not parsed in SW_PORT_MODE (as it's done for Boot and Auto mode), resulting of 0 expected entropy packet, deadlocking the CSRNG comm channel. Fixed.

@luismarques
Copy link

It's going to take me a while to mentally digest all of the changes in this PR, so a review from me might take a bit, but I don't want to delay this too much. Maybe we could occasionally do review meetings where we go over the code together?

@rivos-eblot
Copy link
Author

Maybe we could occasionally do review meetings where we go over the code together?
Sure. I could take a couple of hours for such meetings, but I'm afraid it could not be much more, given how many IPs needs to be rewritten.

@rivos-eblot
Copy link
Author

rivos-eblot commented Mar 27, 2025

Some progress since last draft:

+----------------------------+---------+-----------+--------+----------------------------------------+
| Name                       |  Result |      Time | Icount |                                  Error |
+============================+=========+===========+========+========================================+
| csrng_edn_concurrency_test |    PASS | 145839 ms |      6 |                                        |
+----------------------------+---------+-----------+--------+----------------------------------------+
| csrng_kat_test             |    PASS |    267 ms |      6 |                                        |
+----------------------------+---------+-----------+--------+----------------------------------------+
| csrng_smoketest            |    PASS |    206 ms |      6 |                                        |
+----------------------------+---------+-----------+--------+----------------------------------------+
| edn_auto_mode              |    PASS |   9900 ms |      6 |                                        |
+----------------------------+---------+-----------+-------------------------------------------------+
| edn_boot_mode              |    FAIL |    200 ms |      6 | CHECK-STATUS-fail: Internal:["OBT";47] |
+----------------------------+---------+-----------+--------+----------------------------------------+
| edn_kat                    | TIMEOUT |  30002 ms |      6 |                                        |
+----------------------------+---------+-----------+--------+----------------------------------------+
| edn_sw_mode                |    PASS |   1505 ms |      6 |                                        |
+----------------------------+---------+-----------+--------+----------------------------------------+

edn_boot_mode failure is due to the OTBN not receiving the expected FIPS compliance status from the EDN, on the second round (first round is ok)

@rivos-eblot rivos-eblot force-pushed the dev/ebl/entropy_stack_update branch from 5de8cd8 to b5013e5 Compare March 27, 2025 16:41
@rivos-eblot
Copy link
Author

It might be worth splitting this PR once entropy test are passing. Entropy tests depend on so many IPs that is difficult to predict the proper set of IPs to update for now.

@rivos-eblot rivos-eblot force-pushed the dev/ebl/entropy_stack_update branch from b5013e5 to 057b9fe Compare March 27, 2025 19:13
@loiclefort loiclefort self-requested a review March 28, 2025 15:43
This departs from QEMU's fifo8 implementation, but enables to use the
OT FIFO from a const context.

Signed-off-by: Emmanuel Blot <[email protected]>
@rivos-eblot rivos-eblot force-pushed the dev/ebl/entropy_stack_update branch from 057b9fe to 1540612 Compare March 28, 2025 16:13
@rivos-eblot rivos-eblot marked this pull request as ready for review March 28, 2025 16:16
@rivos-eblot
Copy link
Author

+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| Name                                                        |  Result |      Time | Icount |                                                                       Error |
+=============================================================+=========+===========+========+=============================================================================+
| aes_entropy_test                                            |    PASS |    307 ms |      6 |                                                                             |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| aes_force_prng_reseed_test                                  | TIMEOUT |  10001 ms |      6 |                                                                             |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| aes_idle_test                                               |    PASS |    315 ms |      6 |                                                                             |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| aes_masking_off_test                                        | TIMEOUT |  10001 ms |      6 |                                                                             |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| aes_prng_reseed_test                                        | TIMEOUT |  10001 ms |      6 |                                                                             |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| aes_smoketest                                               |    PASS |    374 ms |      6 |                                                                             |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| aes_stall_test                                              |    FAIL |    339 ms |      6 | CHECK-fail: ERROR: AES module not STALLED as expected after loading block 1 |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| csrng_edn_concurrency_test                                  |    PASS | 171378 ms |      6 |                                                                             |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| csrng_kat_test                                              |    PASS |    268 ms |      6 |                                                                             |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| csrng_smoketest                                             |    PASS |    207 ms |      6 |                                                                             |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| edn_auto_mode                                               |    PASS |  14308 ms |      6 |                                                                             |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| edn_boot_mode                                               |    PASS |    846 ms |      6 |                                                                             |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| edn_kat                                                     | TIMEOUT |  10001 ms |      6 |                                                                             |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| edn_sw_mode                                                 |    PASS |   1463 ms |      6 |                                                                             |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| entropy_src_ast_rng_req_test                                |    PASS |    429 ms |      6 |                                                                             |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| entropy_src_bypass_mode_health_test                         | TIMEOUT |  10001 ms |      6 |                                                                             |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| entropy_src_csrng_test                                      | TIMEOUT |  10001 ms |        |                                                                             |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| entropy_src_edn_reqs_test                                   |   ERROR |    413 ms |      6 |                                                                             |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| entropy_src_fw_observe_many_contiguous_test                 |    FAIL |   4097 ms |      6 |                              CHECK-STATUS-fail: DeadlineExceeded:["RVC";25] |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| entropy_src_fw_override_test                                | TIMEOUT |  10002 ms |      6 |                                                                             |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| entropy_src_fw_ovr_test                                     |    PASS |    395 ms |      6 |                                                                             |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| entropy_src_kat_test                                        |    FAIL |    284 ms |      6 |                            CHECK-fail: fail_count < kKatTestTimeoutAttempts |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| entropy_src_smoketest                                       | TIMEOUT |  10001 ms |      6 |                                                                             |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| hmac_enc_idle_test                                          |    PASS |    393 ms |      6 |                                                                             |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| hmac_enc_test                                               |    PASS |    371 ms |      6 |                                                                             |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| hmac_secure_wipe_test                                       |    PASS |    405 ms |      6 |                                                                             |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| hmac_smoketest                                              |    PASS |    580 ms |      6 |                                                                             |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| otbn_irq_test                                               |    PASS |    282 ms |      6 |                                                                             |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| otbn_isa_test                                               |    PASS |   1121 ms |      6 |                                                                             |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| otbn_mem_scramble                                           |    FAIL |    539 ms |      6 |              CHECK-fail: Expecting at least 48 IMEM integrity errors; got 0 |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| otbn_randomness_test                                        |    PASS |    589 ms |      6 |                                                                             |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| otbn_rsa_test                                               |    PASS |   2042 ms |      6 |                                                                             |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+
| otbn_smoketest_silicon_creator                              |    PASS |    286 ms |      6 |                                                                             |
+-------------------------------------------------------------+---------+-----------+--------+-----------------------------------------------------------------------------+

@rivos-eblot rivos-eblot force-pushed the dev/ebl/entropy_stack_update branch 2 times, most recently from c5f0586 to cf2d9cc Compare March 28, 2025 17:10
Copy link

@AlexJones0 AlexJones0 left a comment

Choose a reason for hiding this comment

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

I'm not very familiar with the EDN and CSRNG and so can't provide a thorough review on the implementation specifics (I did find the CSRNG changes easier to review though); I've left some comments on things I noticed going over the code. On the whole the changes all look great, however, and it's nice to see more EDN/CSRNG tests passing.

Aside: it is surprising to me to see entropy_src_kat_test failing, since I have it noted as passing - I went and ran it on master on OpenTitan and to my surprise it is failing! Going back to an older OpenTitan commit 32b1337496 and running ./bazelisk.sh test //sw/device/tests:entropy_src_kat_test_sim_qemu_rom_with_fake_keys it clearly is passing, so there has been a regression at some point, though not in this PR (so it shouldn't block merging). I would guess that the implementation of this test changed during the Multitop top-level-test porting efforts, in a way that is incompatible with the QEMU model (or maybe QEMU was bumped since then and a previous change broke this)?

This enables runnning applications built for Verilator simulator on QEMU.

Signed-off-by: Emmanuel Blot <[email protected]>
…xecution.

Tracing execution massively slows down OTBN execution. Add a new option to
trace execution, while leaving logfile option to only report execution errors
when trace logging is not enabled.

Signed-off-by: Emmanuel Blot <[email protected]>
OT_SENSOR IP is no longer present on Darjeeling

Signed-off-by: Emmanuel Blot <[email protected]>
OT Sensor IP is top-specific

Signed-off-by: Emmanuel Blot <[email protected]>
A new command should never be emitted if there is a previous one on going.
Remove useless command buffer wipes.

Signed-off-by: Emmanuel Blot <[email protected]>
EDN_ENABLE is not a boolean, but a multibit boolean.

Signed-off-by: Emmanuel Blot <[email protected]>
…icit class name

QEMU assumes that the class name should be built from the instance name, however this is
not even used constantly across QEMU files. Only when abstract classes are used this
auto naming scheme is applied.

Redefine two similar macros (from the original ones) to provide the actual object class
name.

Signed-off-by: Emmanuel Blot <[email protected]>
This naming better follows other OT class naming conventions.

Signed-off-by: Emmanuel Blot <[email protected]>
Upon reset the data will be invalid with a new EDN request pending.

Signed-off-by: Emmanuel Blot <[email protected]>
1. inverted detection of a previous EDN connection
2. the filler_fn function now tracks whether an EDN is connected or not,
   the instantiation status was a left over from the initial implementation

Signed-off-by: Emmanuel Blot <[email protected]>
When an ELF file is used to store an app in the flash image, and not
binary physical file exists, the binary data is automatically generated
but no match should be attempted between the ELF metadata and the
generated binary content.

Signed-off-by: Emmanuel Blot <[email protected]>
The documented rules

1. ENTROPY_SRC may only be disabled if CSRNG is disabled.
3. Once disabled, CSRNG may only be re-enabled after ENTROPY_SRC has been disabled and re-enabled.

no longer apply: remove the related checks.

Signed-off-by: Emmanuel Blot <[email protected]>
They had not been updated when registers had.

Signed-off-by: Emmanuel Blot <[email protected]>
FIPS status should be reset after each entropy packet is delivered to the OTBN core.

Signed-off-by: Emmanuel Blot <[email protected]>
@rivos-eblot rivos-eblot force-pushed the dev/ebl/entropy_stack_update branch from cf2d9cc to b77932f Compare March 29, 2025 09:47
@rivos-eblot
Copy link
Author

#153 (comment) not yet addressed (TBD next week).
Thanks for the review @AlexJones0 The EDN has been a large rewrite and comes as a very large change, which is not easy to read. There were some many changes to do that did not found a way to split it into coherent, small change commits.

@rivos-eblot
Copy link
Author

#153 (comment) not yet addressed (TBD next week).

It turns out that the generation identifier is no longer needed with the latest Entropy Src IP.
I'll remove the whole thing, as it simplifies both the API and the error management.

@rivos-eblot rivos-eblot force-pushed the dev/ebl/entropy_stack_update branch from b77932f to 22f23c1 Compare March 31, 2025 09:15
Get rid of the generation identifier. This mechanism had initially be implemented to verify
early EarlGrey entropy source constraint, quoting:

  "CSRNG may only be enabled if ENTROPY_SRC is enabled.
   Once disabled, CSRNG may only be re-enabled after ENTROPY_SRC has been disabled and
   re-enabled."

This constraint has been removed in recent EarlGrey implementations while Darjeeling
implementation did not follow this constraint, as it did not make use of the entropy source
IP.

Generation number is therefore removed; get_random_generation API is no longer needed, neither
is the genid argument of get_random_values. Error management can be simplified accordingly.

Signed-off-by: Emmanuel Blot <[email protected]>
@rivos-eblot rivos-eblot force-pushed the dev/ebl/entropy_stack_update branch from 22f23c1 to 3838be9 Compare March 31, 2025 10:13
Copy link

@AlexJones0 AlexJones0 left a comment

Choose a reason for hiding this comment

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

This looks good to me, thank you! I'm not familiar with the hardware enough to thoroughly review all the EDN changes but the code all seems reasonable and more tests are passing, so this is definitely an improvement.

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