Skip to content

Add functions to generate DICE ML-DSA UDS TBS certificate - #31050

Merged
cfrantz merged 3 commits into
lowRISC:earlgrey_1.0.0from
xorptr:perso_ft_provisioning_add_uds_mldsa_certgen_support
Sep 4, 2026
Merged

Add functions to generate DICE ML-DSA UDS TBS certificate#31050
cfrantz merged 3 commits into
lowRISC:earlgrey_1.0.0from
xorptr:perso_ft_provisioning_add_uds_mldsa_certgen_support

Conversation

@xorptr

@xorptr xorptr commented Aug 18, 2026

Copy link
Copy Markdown

This PR adds code to generate DICE UDS ML-DSA TBS certificates with either an ML-DSA 44 or ML-DSA 87 public keys, and ML-DSA 87 signature

  • Commit 1 changes hjson template for UDS certificate generation to add selectors which choose between the public key algorithm and signature algorithm. It also adds a function that ft_personalize can use for DICE UDS ML-DSA certificate generation with ML-DSA 44 public key. Golden data tests added in PR [dice,ot_certs] Refactor: Supporting code changes for generating UDS certificate with ML-DSA algorithms #30974 are used to check the UDS certificates with EC-DSA public key and signatures are not affected
  • Commit 2 makes changes to use a different stack as compared to ROM_EXT. Perso FW will use 24 KiB stack for ML-DSA operations, and ROM_EXT will use 32 KiB stack for ML-DSA related operations. Based on discussion with @sasdf, we would prefer to keep the stacks separate so that ROM_EXT can move more stuff on its stack. Both the sizes are used in the check for stack use in runtime tests for ML-DSA 44 and ML-DSA 87 operations
  • Commit 3 adds an empty implementation for the public API added in commit 1 so that SKUs that don't need ML-DSA support for provisioning can link the empty implementation in with ft_personalize.

Changes are on top of PR #30974 and PR #31038

assert_eq!(endorsed_cert, GOLDEN_ECDSA_ENDORSED_CERT_OUTPUT_DATA);
}

// TODO: Add golden tests for MLDSA certificates once end-to-end provisioning test supports it

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed this in future PR #31056

#include "sw/device/lib/testing/test_framework/check.h"
#include "sw/device/lib/testing/test_framework/ottf_main.h"
#include "sw/device/silicon_creator/lib/cert/dice.h"
#include "sw/device/silicon_creator/lib/cert/dice_mldsa.h"

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.

I feel we messed up the deps that embedpqc test depends on DICE. It should be DICE depends on embedpqc, but not the other way around. We also shouldn't separate the header to dice_mldsa_api to workaround this.

Instead, we could define the minimum stack size in embedpqc instead, and move the check to dice-related tests.

@xorptr xorptr Aug 19, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

That seems like a good idea. The stack use should be a property of the ML-DSA implementation being used, and should be independent of the DICE module.

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.

Will you update this part?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

not in this PR probably. I think this could be done independently (by me or anybody else) in a different PR?

@xorptr
xorptr marked this pull request as ready for review August 19, 2026 22:08
@xorptr
xorptr requested review from a team and cfrantz as code owners August 19, 2026 22:08
@xorptr
xorptr requested review from engdoreis and removed request for a team August 19, 2026 22:08
@xorptr
xorptr force-pushed the perso_ft_provisioning_add_uds_mldsa_certgen_support branch from 92e7f66 to 0cf11f6 Compare August 21, 2026 01:07
@xorptr
xorptr force-pushed the perso_ft_provisioning_add_uds_mldsa_certgen_support branch from 0cf11f6 to 9df61e1 Compare August 28, 2026 17:45
@xorptr

xorptr commented Aug 28, 2026

Copy link
Copy Markdown
Author

Rebased on top of latest commit on earlgrey_1.0.0: 7d8874d9d215dc9e1221d58883691f713c1805eb

@xorptr
xorptr force-pushed the perso_ft_provisioning_add_uds_mldsa_certgen_support branch from 9df61e1 to 5887873 Compare August 28, 2026 18:00
Comment thread sw/device/silicon_creator/lib/error.h Outdated
* additional logic to run a cleanup operation in case of error. Any return
* value from the cleanup procedure is ignored
*/
#define HARDENED_RETURN_IF_ERROR_WITH_TRY_CLEANUP(expr_, try_cleanup_expr_) \

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.

This is fine, but I take exception with "TRY" in the name. Among the variety of error code types we have in opentitan, most testing code uses status_t and there is a TRY macro that operates on status_t-returning functions that works in a similar way to the ? operator in rust: TRY either yields the "value" of status_t or returns out of the function with the error value.

I don't want this macro to be confused with things that TRY.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ack. That's a fair point. Changed the identifier to HARDENED_RETURN_IF_ERROR_WITH_CLEANUP_ATTEMPT

This commit changes DICE UDS certificate template and code to support
generating ML-DSA TBS certificates

- Add selectors for public key in template: "ecdsa-p256", "mldsa-44",
  and "mldsa-87"
- Add selectors for signature in template: "ecdsa-p256", and "mldsa-87"
- Add function to fill in TBS template for UDS to generate TBS
  certificate with ML-DSA algorithms
- Update certificate generation for UDS ECDSA certificate to select
  `ecdsa-p256` for public key and signature to support existing UDS
  certificates using ECDSA algorithm
- Add a new header file specifically for ML-DSA DICE API

Tested by running
`//sw/host/provisioning/orchestrator/tests:e2e_emulation_dice_cwt_cw340_test`,
`//sw/host/provisioning/orchestrator/tests:e2e_emulation_dice_mldsa_cw340_test`,
`//sw/host/provisioning/orchestrator/tests:e2e_emulation_cw340_test`,
and `//sw/host/provisioning/orchestrator/tests:e2e_multistage_emulation_tpm_cw340_test`
targets locally

Also tested that golden test for UDS certificate generation work by
testing
`//sw/host/ot_certs:ot_certs_e2e_test_tests/uds_golden_tests_test`
target locally

Signed-off-by: Lovepreet Singh <lpsingh@google.com>
This commit creates 2 scratch stacks for DICE ML-DSA operations: 32 KiB
for ROM_EXT, and 24 KiB for perso firmware, since perso firmware
currently doesn't have enough SRAM available for 32 KiB scratch stack
and ROM_EXT might merge other data in the 32 KiB stack

ML-DSA 44 and ML-DSA 87 tiny tests are also updated to test that the
runtime stack use is less than size of both the stacks

Tested by running
`//sw/device/silicon_creator/rom_ext/e2e/attestation:print_mldsa_certs_test_fpga_cw340_rom_ext`,
`//sw/device/silicon_creator/rom_ext/e2e/attestation:print_certs_test_fpga_cw340_rom_ext`,
`//sw/device/tests/embedpqc:mldsa44_tiny_test_sim_qemu_rom_with_fake_keys`, and
`//sw/device/tests/embedpqc:mldsa87_tiny_test_sim_qemu_rom_with_fake_keys`
targets locally

Signed-off-by: Lovepreet Singh <lpsingh@google.com>
Since `ft_personalize` binary will be generated for SKUs that don't need
ML-DSA support, this commit creates an empty library that those SKUs can
link to the binary

Signed-off-by: Lovepreet Singh <lpsingh@google.com>
@xorptr
xorptr force-pushed the perso_ft_provisioning_add_uds_mldsa_certgen_support branch from 5887873 to 0cf11f6 Compare September 4, 2026 06:28
@xorptr

xorptr commented Sep 4, 2026

Copy link
Copy Markdown
Author

Pushed incorrect commit by mistake. Pushing new changes again

@xorptr
xorptr force-pushed the perso_ft_provisioning_add_uds_mldsa_certgen_support branch from 0cf11f6 to d2906f0 Compare September 4, 2026 06:33
@cfrantz
cfrantz merged commit a4addce into lowRISC:earlgrey_1.0.0 Sep 4, 2026
35 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.

3 participants