Skip to content

Conversation

AlexJones0
Copy link

@AlexJones0 AlexJones0 commented Sep 16, 2025

This PR is the third of a series of 4 PRs to implement OpenTitan's keymgr IP, as used in Earlgrey, split to ease review. You can see all the relevant keymgr commits in #188.

This PR implements the main advancement logic for the keymgr, allowing it to progress from its initial state through the different keymgr key stages (CREATOR, OWNER_INTERMEDIATE and OWNER). To support this, KMAC connectivity is added to offload cryptographic KDF operations to KMAC and advancement for all CDIs (in all stages) is implemented. The remainder of the main keymgr FSM states are also implemented, but a future PR will implement the stubbed generate operations that are currently missing.

As seen in the last commit, this is now enough functionality to at least see the keymgr_functest passing.

See the commit messages for more details about each change.

@AlexJones0
Copy link
Author

Progresses lowRISC/opentitan#27894

@AlexJones0
Copy link
Author

Also see #188 which is the final keymgr PR - this shows all the new passing keymgr tests.

@AlexJones0 AlexJones0 force-pushed the eg-keymgr-advancement branch 2 times, most recently from e9b34a5 to 677077b Compare September 17, 2025 14:00
These device links will be needed for retrieving values used in the KDF
(key derivation function) for keymgr advance operations.

Signed-off-by: Alex Jones <alex.jones@lowrisc.org>
This commit introduces the logic relevant to computing the KDF `AdvData`
input for the `Advance` operation, which depends on both the current
keymgr stage and the CDI.

This logic is adapted from the keymgr_dpe, but with many differences:
 - `keymgr` has no slots, and encodes stages in its main FSM states.
 - `keymgr` has 2 CDIs: one for sealing and one for attestation.
 Normally, you can select the CDI, but advance operations advance
 both (sealing, then attestation).
 - `keymgr` uses different KDF inputs to `keymgr_dpe`. It only has 1
 ROM digest, uses creator/owner seeds in different phases, and
 concatenates its inputs in a different order.
 - `keymgr` gets creator/owner seeds from flash, instead of OTP.
 - `keymgr` chooses to use either sealing or attestation SW bindings
   based on the CDI, `keymgr_dpe` only has 1 SW binding.

For now, many parts are still stubbed out - we do not yet send the KDF
request to KMAC, and we do not properly handle wiping data on
disablement, or invalid inputs.

This commit also adds minimal handling for the `disable` operation.

Signed-off-by: Alex Jones <alex.jones@lowrisc.org>
@AlexJones0 AlexJones0 force-pushed the eg-keymgr-advancement branch from 677077b to 5411c5e Compare September 17, 2025 15:35
@AlexJones0 AlexJones0 marked this pull request as ready for review September 17, 2025 15:37
This is mostly based on the equivalent keymgr_dpe implementation.

Adds a connection from the keymgr to the KMAC via the KMAC app
interface, and add logic for sending a KMAC request containing the
contents of the KDF buffer. Also stub out a function for handling
the KMAC response - the resulting logic will depend on the current
operation, but for now is stubbed.

Signed-off-by: Alex Jones <alex.jones@lowrisc.org>
@AlexJones0 AlexJones0 force-pushed the eg-keymgr-advancement branch from 5411c5e to 1c2e69e Compare September 17, 2025 15:39
Copy link

@jwnrt jwnrt left a comment

Choose a reason for hiding this comment

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

Although I'm not a keymgr expert, the logic looks correct to me

Connect sideloading key sinks for AES, KMAC and OTBN to allow the keymgr
to send keys to these blocks. This commit only introduces logic to push
keys to the key sink interfaces, and does not yet implement any
sideloading behaviour or related software register interfaces.

Signed-off-by: Alex Jones <alex.jones@lowrisc.org>
Finishes the implementation of the keymgr's `Advance` operation, with
logic for all key stages (still pending FSM key states). When an
`Advance` operation is issued, the current key state is sideloaded to
the KMAC, and the contents of the computed KDF buffer are processed to
derive the next key state.

One key difference from `keymgr_dpe` is that both CDIs must be advanced
in a single advance operation, and so after receiving the KMAC response
and storing the key state, we send another KMAC app request to advance
the sealing key also. This continues for all CDIs (currently only 2).

One other key difference to note is that `keymgr` does not unlock the
max key version REGWENs on advancement, whereas the `keymgr_dpe` does
(see the `keymgr.sv` and `keymgr_dpe.sv` RTL).

Signed-off-by: Alex Jones <alex.jones@lowrisc.org>
This commit implements all remaining `keymgr` FSM states, almost all of
which are unique to `keymgr` and not in `keymgr_dpe`. Advancing and
disabling is now supported for all key stage states.

To reduce duplication, the different key FSM states are abstracted into
a generic `ot_keymgr_fsm_key_stage(...)` function.

Signed-off-by: Alex Jones <alex.jones@lowrisc.org>
Now that the `keymgr` is partially implemented, with the option to
advance through all of its main FSM states (but no ability to generate
output keys or sideload keys), this is sufficient to get the
`keymgr_functest` passing.

Signed-off-by: Alex Jones <alex.jones@lowrisc.org>
@AlexJones0 AlexJones0 force-pushed the eg-keymgr-advancement branch from 1c2e69e to e2265b4 Compare September 18, 2025 10:43
@jwnrt jwnrt merged commit f727163 into lowRISC:ot-earlgrey-9.2.0 Sep 18, 2025
8 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.

2 participants