This document specifies the functionality of the OpenTitan key manager.
The key manager implements the hardware component of the identities and root keys strategy of OpenTitan.
It enables the system to shield critical assets from software directly and provides a simple model for software to use derived key and identity outputs.
Key manager behavior can be summarized by the functional model below.
In the diagram, the red boxes represent the working state and the associated secret value, the black ovals represent derivation functions, the green squares represent software inputs, and the remaining green / purple shapes represent outputs to both software and hardware.
In OpenTitan, the derivation method selected is [KMAC]({{< relref “hw/ip/kmac/doc” >}}). Each valid operation involves a KMAC invocation using the key manager working state as the “key” and other HW / SW supplied inputs as data. While KMAC can generate outputs of arbitrary length, this design fixes the size to 256b.
Effectively, the key manager behavior is divided into 3 classes of functions
Key manager state advancement
Output key generation
Identity / seed generation
In general, the key generation and seed generation functions are identical. They differ only in how software chooses to deploy the outputs.
The key manager working state (red boxes in the functional model) represents both the current state of the key manager as well as its related secret material. Each state, when valid, supplies its secret material as the “key” input to a KMAC operation. The data input is dependent on each state, see below.
The key manager working state is not directly reset to any value. This ensures there is no deterministic hamming delta upon reset. Instead at reset time, the state value is simply unknown - which is expected to be some biased value the registers settle to based on silicon corner and environment conditions.
To begin operation, the state must first transition to Initialize. The advancement from Reset
to Initialized
is irreversible during the current power cycle. Until the initialize command is invoked, the key manager rejects all other software commands.
When transitioning from Reset
to Initialized
, random values obtained from the entropy source are used to populate the working state. This ensures that the hamming delta from both the previous value and the next value are both non-deterministic. The advancement from Initialized
to CreatorRootKey
is irreversible during the current power cycle.
CreatorRootKey
is the first operational state of the key manager. When transitioning from Initialized
to this state, a KMAC operation is invoked using the RootKey
as the key (from OTP), and the remaining inputs as data.
See below:
DiversificationKey
: Secret seed from flashHealthMeasurement
: Current life cycle stateDeviceIdentifier
: Unique device identification.HardwareRevisionSecret
: A global design time constant.RomExtSecurityDescriptor
: A software digest of the ROM_ext stage.Other than the DiversificationKey
, none of the values above are considered secret. The RomExtSecurityDescriptor
is a 256b value calculated by ROM and loaded into key manager registers.
Once the CreatorRootKey
is reached, software can request key manager to advance state, generate output key or generate output identity. The key used for all 3 functions is the CreatorRootKey
.
The advancement from this state to the next is irreversible during the current power cycle.
This is the second operational state of the key manager. This state is reached through another invocation of the KMAC operation using the previous working state as the key, and other inputs as data. The output of the KMAC operation replaces the previous value of the working state, and the new value becomes the OwnerIntermediateKey
.
The relevant data inputs are:
OwnerRootSecret
: Secret seed from flash.SoftwareBinding
: A software programmed value representing the first owner code to be run.Once the OwnerIntermediateKey
is created, software can request key manager to advance state, generate output key or generate output identity. The key used for all 3 functions is the OwnerIntermediateKey
.
The advancement from this state to the next is irreversible during the current power cycle.
This is the last operational state of the key manager. This state is reached through another invocation of the KMAC operation using the previous working state as the key, and other inputs as data. The output of the KMAC operation replaces the previous value of the working state, and the new value becomes the OwnerRootKey
.
The relevant inputs are:
SoftwareBinding
- A software programmed value representing the owner kernel code.Once the OwnerRootKey
is created, software can request key manager to advance state, generate output key or generate output identity. An advance command invoked from OwnerRootKey
state simply moves the state to Disabled
.
The generate output and generate identity functions use OwnerRootKey
as the KMAC key. The advancement from this state to the next is irreversible during the current power cycle.
Disabled
is a terminal state where the key manager is no longer operational. When entering Disabled random values are used to compute a new random value.
The function of the key manager is directly tied to the life cycle controller. During specific life cycle states, the key manager is explicitly disabled.
When disabled, the following key manager behavior applies:
Disabled
.Disabled
state, the behavior is consistent with normal behavior.During each state, there are 3 valid commands software can issue:
The software is able to select a command and trigger the key manager FSM to process one of the commands. If a command is valid during the current working state, it is processed and acknowledged when complete.
If a command is invalid, the behavior depends on the current state. If the current state is Reset
, the invalid command is immediately rejected as the key manager FSM has not yet been initialized. If the current state is any other state, the key manager FSM processes with random, dummy data, but does not update working state or relevant output registers. For each valid command, a set of inputs are selected and sequenced to the KMAC module.
During Disable
state, working state and output registers are updated as usual. The only difference during Disabled
state is that random data is used and invalid operations are reported.
The generate output command is composed of 2 options
generate-output-sw
generate-output-hw
The hardware option is meant specifically for symmetric side load use cases. When this option is issued, the output of the KMAC invocation is not stored in software visible registers, but instead in hardware registers that directly output to symmetric primitives such as AES, HMAC and KMAC.
All invoked KMAC operations expect the key in two shares. This means the working states, even though functionally 256b, are maintained as 512b.
For advance-state and generate-output
commands, the KMAC emitted output are also in 2-shares. Software is responsible for determining if the key should be preserved in shares or combined, depending on the use case.
An error code register is maintained {{< regref ERR_CODE >}} to check issues that might rise while using the key manager. There are two categories of errors
Hardware fault errors - These errors indicate something fundamental has gone wrong and are errors that could not have been caused by software.
Software operation errors - These errors could have been caused by user errors and is a sign that software should examine its usage of key manager.
generate
while in Idle) was invoked.Whenever the error code changes from its previous value to a non-zero value, an interrupt is generated. Two separate alerts are also generated, one corresponding to each category above.
When these errors occur, random data is fed to the KMAC for processing. At the completion of KMAC processing, the working state is over-written with KMAC's output and the state is transitioned to Disabled
. An error interrupt and fault alert are also generated. Note the KMAC module itself may error during the derivation process. When this happens, the error is also registered as an invalid command and the same mechanisms apply.
When these errors occur, an error interrupt and fault alert are generated. Neither the working state nor the relevant output registers are updated.
When these errors occur, random data is fed to the KMAC for processing. Neither the working state nor the relevant output registers are updated. An error interrupt and operation alert are also generated.
When these errors occur, an error interrupt and fault are generated.
The effects of an invalid operation vary depending on state. The table below enumerates the legal operations in a given state. When an illegal operation is supplied, the error code is updated and the operation is flagged as done with error
. Note that even though Init
is not a legal operation in most states, it is treated as an ignored command rather as an explicit error.
Current State | Legal Operations | Outcome |
---|---|---|
Reset | Advance | Advance to Initialized state upon completion. |
Reset | Disable / Advance / Generate | Invalid operation error triggered with no other side effects. |
Initialized | Disable / Advance | Advance to next Disabled state or CreatorRootKey. |
Initialized | Generate | Invalid operation error triggered with random data, output registers are updated. |
CreatorRootKey | Disable / Advance / Generate | Behave as expected. |
OwnerIntKey | Disable / Advance / Generate | Behave as expected. |
OwnerKey | Disable / Advance / Generate | Behave as expected. |
Disabled | Disable / Advance / Generate | Invalid operation error triggered with random data, both working state and output registers are updated depending on command. |
The following is a high level block diagram of the key manager.
Key manager is primarily composed of two components:
The key manager control block manages the working state, sideload key updates, as well as what commands are valid in each state. It also handles the life cycle keymgr_en
input, which helps disable the entire key manager function in the event of an escalation.
The KMAC interface control represents the bulk of key manager logic. Based on input from key manager control, this module selects the inputs for each given command and sequences the data to KMAC.
The identities flow employs an idea called software binding to ensure that a particular key derivation scheme is only reproducible for a given software configuration. This software binding exists for every stage of key manager except for OwnerKey
. The binding is created through the secure boot flow, where each stage sets the binding used for the next verified stage before advancing to it. In order to save on storage and not have a duplicate copy per stage, the software binding registers {{< regref SOFTWARE_BINDING >}} are shared between key manager stages.
Software sets the appropriate values and locks it by clearing {{< regref SOFT_BINDING_EN >}}. When later a successful advance
call is made, the key manager then unlocks by setting {{< regref SOFT_BINDING_EN >}} to 1. An unsuccessful advance call (errors) does not unlock the binding. This allows the next stage of software to re-use the binding registers.
{{< hwcfg “hw/ip/keymgr/data/keymgr.hjson” >}}
Software selects a command and triggers a “start”. If the command is valid and successful, key manager indicates done and no errors. If the command is invalid or unsuccessful, key manager indicates done with error. Regardless of the validity of the command, the hardware sequences are triggered to avoid leaking timing information.
The software is able to read the current state of key manager, however it never has access to the associated secret value
When issuing the generate-output-hw
command, software must select a destination primitive (aes, hmac or kmac). At the conclusion of the command, key and valid signals are forwarded by the key manager to the selected destination primitive. The key and valid signals remain asserted to the selected destination until software explicitly disables the output via another command, or issues another generate-output-hw
command with a different destination primitive.
More details to come.
{{< registers “hw/ip/keymgr/data/keymgr.hjson” >}}