This article gives an overview of the OEMiRoT solution integrated in STM32U0.
How to use it, step by step, is described in wiki pages How to start with OEMiRoT on STM32U0.
1. OEMiRoT presentation
1.1. Overview
OEMiRoT stands for OEM immutable (unchangeable) Root of Trust and acts as a first boot stage. OEMiRoT is an example based on the MCUboot open-source software (refer to mcuboot.com) provided with STM32CubeU0. OEMiRoT offers two services:
- The Secure Boot (root of trust service) is an immutable code, which is always executed after a system reset. It checks static protections (Options Bytes), activates runtime protections and then verifies the authenticity and integrity of the user application code before every execution.
- The Secure Firmware Update application is an immutable code that detects new firmware image candidate. It checks its version (version downgrade prevention), authenticity and integrity before installing it after decryption.
1.2. Protection measures and security strategy
Cryptography ensures integrity, authentication, and confidentiality. However, the use of cryptography alone is not enough: a set of measures and system-level strategies are needed for protecting critical operations and sensitive data (such as a secret key), and the execution flow, in order to resist against possible attacks. On STM32U0, the security strategy is based on (see also STM32U0 Reference manual for more description):
- RDP: Read protection level 2 achieves the highest protection level. Read protection level 2 with OEM2 password capability is used to ensure that a JTAG debugger cannot access the device, except to inject the OEM2 password. In RDP level 2, when the OEM2 password is injected on the JTAG port, the RDP level is regressed to level 1. The OEM2 password must first have been provisioned when the RDP level is 0. Refer to RDP for U0 wiki article for more details.
- Boot lock: BOOT_LOCK option byte is set to establish a chain of trust, by forcing the system to boot from the main flash memory in 0x08000000.
- Anti-tamper protection: the antitamper protection is used to protect sensitive data from physical attacks. The anti-tamper protection is activated at the start of OEMiRoT_Boot project and remains active during OEMiRoT_Appli execution. In case of tamper detection, sensitive data, caches, and cryptographic peripherals are immediately erased, and a reboot is forced. Both external active tamper pins and internal tamper events are used.
- MPU: the MPU is configured to limit the surface execution to the code area during OEMiRoT_Boot project execution then extended to the application code area after verifying its integrity and its authenticity. This protection is dynamically managed at runtime.
- HDP: HDP area is configured to cover the whole OEMiRoT_Boot project code area, the perso data area as wein order to prevent any execution out of the OEMiRoT_Boot execution and any access to OEMiRoT secrets (cryptographic keys). When jumping in the application, the temporal isolation (HDP level) is increased from HDPL1 to HDPL2 making the OEMiRoT_Boot project code no longer accessible.
- OBkeys: HDPL1 OBkeys (HDPL2 OBkeys for OEMuRoT) are a protected and isolated enclave used to store secrets such as encryption and authentication cryptographic keys. This enclave is no longer accessible when switching from HDPL1 to HDPL2 or to HDPL3. Data stored in this enclave is encrypted with a HUK derivated key.
- WRP: this protection is set on the whole OEMiRoT_Boot project code area to make it immutable.
- RAM ECC: ECC is a mechanism to prevent external attacks. A reset is generated in case of RAM ECC detection.
Note: WRP and HDP protections cannot be activated when OEMUROT_ENABLE switch is activated.
Secure software coding techniques such as doubling critical tests, doubling critical actions, random delay, checking parameter values, and flow control mechanism, are implemented to resist to double synchronized fault-injection attacks.
1.3. Cryptography operations
The OEMiRoT_Boot application example is delivered with the following cryptographic scheme:
- ECDSA-P256 asymmetric cryptography for image authentication.
- AES-CTR-128 symmetric cryptography with key ECIES-P256 encrypted for image confidentiality.
- SHA256 cryptography for image integrity check.
- AES-ECB-128 symmetric cryptography for firmware encryption/decryption of the installation slot in external flash memory using MCE1. The internal key used is derived from HUK.
- NOEKEON cryptography for firmware encryption/decryption of the execution slot in external RAM memory using MCE2 (load and run configuration). The internal key used is derived from HUK (different from MCE1 key).
1.4. OEMxRoT activation
On STM32U0, OEMxRoT activation is done by:
- Configuring the IROT_SELECT option to boot on OEMiRoT or STiRoT.
- Configuring OEMxRoT secrets. authentication and encryption keys used by OEMxRoT.
- Building OEMiRoT_Boot binary in the selected configuration (OEMiRoT or OEMuRoT).
All these operations operations are part of the provisioning process. OEMxRoT is activated in two different uses cases:
- One boot stage, OEMiRoT: OEMiRoT_Boot project binary is built in OEMiRoT configuration. OEMiRoT directly manages the user application binary.
- Two boot stages, STiRoT + OEMuRoT: OEMiRoT_Boot project binary is built in OEMuRoT configuration. STiRoT integrated inside the STM32U0 manages an updatable boot stage (OEMuRoT) located in the user flash memory, which manages the user application binary.
See also Secure Boot for STM32U0 article.
1.4.1. One boot stage: OEMiRoT
OEMiRoT is generated by compiling OEMiRoT_Boot project with OEMUROT_ENABLE switch de-activated.
At reset, OEMiRoT, located in the user flash memory, is the first application executed in temporal isolation 1 (HDPL1). After a successful verification of the authenticity and the integrity of the user application code image, OEMiRoT executes the user application in HDPL3. In case of verification failure, a reset will be triggered except if OEMIROT_DEV_MODE compilation switch is activated during OEMiRoT_Boot project generation. In this case the execution will fall into an infinite loop.
The following figure illustrates the secure boot and the secure update process by showing all the steps required to boot the user application code image located in the installation slot of the external flash memory:
- In CLOSED or LOCKED state RSS jumps into OEMiRoT if IROT_SELECT option byte is configured to boot on OEMiRoT.
- OEMiRoT checks if a new user application is stored in the download slot. If any, OEMiRoT decrypts it then controls its integrity, its authenticity and the anti-rollback version. If successful, the image is copied in the user application installation slot. The image is re-encrypted (AES) with MCE_1 encryption key.
- OEMiRoT controls the integrity and the authenticity of the user application image from the installation slot located in the external flash memory. If successful, OEMiRoT executes it from external flash or from external/internal RAM memories. In case of RAM memory execution (load and run use case) an additional copy is made before its execution with an MCE re-encryption (NOEKEON) using MCE_2 key for the external RAM memory. Refer to the Features list for more details on OEMiRoT execution modes.
Note: To avoid any risk of attack, when OEMiRoT jumps into the user application, the MPU is configured to ensure that only the user application code area is allowed to be executed (execution surface controlled via MPU configuration). It is the user application responsibility to reconfigure the MPU to fit with its security needs.
1.4.2. Two boot stages: STiRoT + OEMuRoT
OEMuRoT is generated by compiling OEMiRoT_Boot project with OEMUROT_ENABLE switch activated. OEMuRoT (updatable Root of Trust) acts as a second boot stage.
At reset, STiRoT is the first application executed in temporal isolation 1 (HDPL1). After a successful verification of the authenticity and the integrity of OEMuRoT code image, STiRoT executes OEMuRoT in HDPL2 in RAM memory. Then, OEMuRoT verifies the user application before executing it from external flash or external/internal RAM memories. In case of verification failure, a reset will be triggered except if OEMIROT_DEV_MODE compilation switch is activated during OEMiRoT_Boot project generation. In this case the execution will fall into an infinite loop. The following figure illustrates the main steps performed to execute a user application in the two boot stages configuration:
- In CLOSED or LOCKED state RSS jumps into STiRoT if IROT_SELECT option byte is configured to boot on STiRoT.
- After executing the secure firmware update process (refer to STiRoT_for_STM32H7S article for more details on STiRoT), STiRoT requests iLoader to load the OEMuRoT image from installation slot in the internal RAM memory.
- Then STiRoT controls its integrity and its authenticity. If successful, STIRoT executes OEMuRoT in internal RAM memory.
- OEMuRoT checks if a new user application is stored in the download slot. If any, OEMuRoT decrypts it then controls its integrity, its authenticity and the anti-rollback version. If successful, the image is copied in the user application installation slot. The image is re-encrypted (AES) with MCE_1 key.
- OEMuRoT controls the integrity and the authenticity of the user application from the installation slot. If successful, OEMuRoT executes it from external flash memory or from external/internal RAM memories. In case of RAM memory execution (load and run use case) an additional copy is made before its execution with an MCE re-encryption (NOEKEON) using MCE_2 key for the external RAM memory. Refer to the Features list for more details on OEMuRoT execution modes.
Note: To avoid any risk of attack, when OEMuRoT jumps into the user application, the MPU is configured to ensure that only the user application code area is allowed to be executed (execution surface controlled via MPU configuration). It is the user application responsibility to reconfigure the MPU to fit with its security needs.
2. Features list
The main features of the OEMiRoT/OEMuRoT are:
- ECDSA-P256 asymmetric cryptography for image authentication.
- SHA256 cryptography for image integrity check.
- AES-CTR-128 cryptography for image encryption with symmetric key encrypted in ECIES-P256 provided in the image itself. Refer to image generation [] for more details.
- AES-ECB-128 cryptography for image encryption with MCE_1 key after installation in external flash. MCE_1 is derived from HUK.
- NOEKEON cryptography for image encryption with MCE_2 key after transfer in external RAM memory before its execution (load and run configuration). MCE_2 is derived from HUK.
- Accelerated boot thanks to image SHA256 reference management. Image verification mainly consists of verifying the SHA256 of the image (integrity check) and then verifying the signature of this SHA256 (authentication check). If successful, the SHA256 is stored as reference for next boot. At next boot, the signature verification is skipped if the SHA256 of the image match the reference stored in OBKeys. This feature brings performance optimization (under the MCUBOOT_USE_HASH_REF compilation switch).
- Anti rollback version check based on image version counters in OBkeys.
- Image installation resistant to asynchronous power down and reset.
- Integration of the full entropy TRNG source (RNG hardware peripheral) for random numbers generation (boot seed generation, tamper protection) or random delays.
- Configurable firmware image upgrade strategy, for primary and secondary slots mode:
- Overwrite strategy, for which the image in the secondary slot overwrites the image in the primary slot.
- Swap strategy, for which the image in primary and secondary slots are swapped. After the swap, the new image in the primary slot must be confirmed by the user application, else, at the next boot, the images are swapped back.
- Note: a reset must be generated by the user application after confirmation to update the confirmation flag inside the image in the installation slot. The "read while write" feature is not managed for the external flash memory.
- Memory configuration:
- Download slot in external flash memory. The image is encrypted using MCUBoot key..
- Installation slot in external flash memory. This slot is encrypted with the MCE_1 based on a key derived from HUK.
- Execution slot from internal RAM or external RAM memories (load and run configuration). The external RAM memory slot is encrypted with the MCE_2 based on a specific key derived from HUK.
- Load and run execution modes capability configured with OEMIROT_LOAD_AND_RUN define. In addition to the standard execution mode (in place), the user application can be executed:
- from external RAM memory
- from internal RAM memory
- Integration of hardware security peripherals and mechanisms in order to implement a root of trust. Product life cycle, IROT_SELECT, MPU, WRP, HDP, and TAMPER are combined to achieve the highest security level. When connected on the HW board, external tamper can be activated with OEMIROT_TAMPER_ENABLE define.
- Image generation with STM32TrustedPackageCreator tool delivered within STM32CubeProgrammer.
Features configurability:
Feature | OEMiRoT | OEMuRoT |
---|---|---|
OEMiRoT/OEMuRoT generation |
OEMUROT_ENABLE switch deactivated |
OEMUROT_ENABLE switch activated |
Image upgrade strategy |
|
|
Flash memory configuration |
|
|
Antitamper |
|
|
3. Memories layout
The STM32CubeH7RS OEMiRoT/OEMuRoT relies on memories layout defining several regions:
- SCRATCH region: region used by OEMiRoT_Boot to store the image data temporarily during the image swap process (not used in overwrite-only mode).
- OEMiRoT_Boot code region: region to program the OEMiRoT_Boot code binary that manages the functions "Secure Boot" and "Secure Firmware Update”.
- OEMiRoT_Boot volatile data: region used to locate internal variables and call stack, during OEMiRoT_Boot code execution.
- Application installation (primary) slot region: region to program the image of an “active” firmware after installation.
- Application download (secondary) slot region: region to program the image of a “new” firmware, candidate for installation.
- Application execution slot region when load and run feature is activated.
- iLoader code region: region to program the STiRoT_iLoader code binary (specific to STiRoT/OMEuRoT use case).
- Image confirmation flag and RAM ECC handle:
Memories layout is as follow:
For both configuration, default values are:
Symbol | Execute in place | Load and run in external RAM | Load and run in internal RAM |
---|---|---|---|
FLASH_AREA_0_OFFSET | 0x00000000 | 0x00000000 | 0x00000000 |
FLASH_AREA_0_SIZE | 0x00200000 | 0x00200000 | 0x00020000 |
FLASH_AREA_2_OFFSET | 0x00200000 | 0x00200000 | 0x00020000 |
FLASH_AREA_2_SIZE | 0x00200000 | 0x00200000 | 0x00020000 |
IMAGE_PRIMARY_RUN_PARTITION_OFFSET | NA | 0x00000000 | 0x24040000 |
FLASH_AREA_SCRATCH_OFFSET | 0x00400000 | 0x00400000 | 0x00040000 |
FLASH_AREA_SCRATCH_SIZE | 0x00010000 | 0x00010000 | 0x00010000 |
FLASH_AREA_BL2_OFFSET | 0x08000000 | 0x08000000 | 0x08000000 |
FLASH_AREA_BL2_SIZE | 0x00010000 | 0x00010000 | 0x00010000 |
BL2_RAM_OFFSET* | 0x24000000 | 0x24000000 | 0x24000000 |
BL2_RAM_SIZE* | 0x00020000 | 0x00020000 | 0x00020000 |
BL2_DATA_OFFSET** | 0x20000000 | 0x20000000 | 0x20000000 |
BL2_DATA_SIZE** | 0x00020000 | 0x00020000 | 0x00020000 |
RAMECC_HANDLER_START | 0x30004000 | 0x30004000 | 0x30004000 |
RAMECC_HANDLER_SIZE | 0x40 | 0x40 | 0x40 |
CONF_FLAG_SIZE | 0x20 | 0x20 | 0x20 |
*: specific to OEMiRoT
**: specific to OEMuRoT
4. Provisioning process
4.1. OEMiRoT provisioning process
The product provisioning to activate and configure OEMiRoT is done following the three steps below:
- Configuration of OEMiRoT. At this stage, the cryptographic keys for authentication and encryption are defined.
- Generation of the firmware image.
- Programing of the OBkeys, the option bytes, the application image in the device
Note: A set of scripts is provided in Firmware/Projects/STM32H7S78-DK/ROT_Provisioning/OEMiRoT folder. It guides the user all along the provisioning process. Refer to How to start with OEMiRoT on STM32H7S article.
4.2. OEMuRoT provisioning process
The product provisioning to activate and configure OEMuRoT is done following the three steps below:
- Configuration of STiRoT. At this stage, the number of images managed (firmware code image only), the location of the image, and the STiRoT cryptographic keys are defined. Refer to article.
- Configuration of OEMuRoT. At this stage, the OEMuRoT cryptographic keys for authentication and encryption are defined.
- Generation of the OEMuRoT code images as well as the application code image.
- Programing of the OBkeys, the option bytes, the OEMuRoT code image and the application code image in the device
Note: A set of scripts is provided in Firmware/Projects/STM32H7S78-DK/ROT_Provisioning/STiROT_OEMuROT folder. It guides the user all along the provisioning process. Refer to How to start with STiRoT-OEMuRoT on STM32H7S article.
4.3. OEMiRoT/OEMuRoT configuration file
OEMiRoT/OEMuRoT configuration file (OEMiRoT_Config.obk, OEMuRoT_Config .obk) is generated using STM32TrustedPackageCreator with a template file listing all the different parameters (OEMiRoT_Config.xml, OEMuRoT_Config.xml) as input. The obk file is encrypted and saved in HDPL1 OBkeys (OEMiRoT) or HDPL2 OBkeys (OEMuRoT).
The list of the configuration parameters is the following:
Parameter | Description | Additional constraints |
---|---|---|
Encryption key | Key used to encrypt the firmware image | When this key is regenerated, firmware image must be processed with TPC “Image Gen” tab (OEMiRoT_Code_Image.xml) |
Authentication key | Key used to authenticate the firmware image | When this key is regenerated, firmware image must be processed with TPC “Image Gen” tab (OEMiRoT_Code_Image.xml) |
A detailed presentation of the format of STiROT_Config.obk file is provided in Appendix 5.3 STiROT Config.obk file format.
5. Images generation
OEMiRoT manages an image at MCUBoot format including:
- a header,
- the encrypted firmware binary,
- some metadata information (TLV format: Tags Length Value) allowing the control of the image (SHA256, ECDSA signature, encryption key …), and
- a magic to trigger the installation.
Further information about the MCUBoot open-source software is available at mcuboot.com. A PC tool STM32TrustedPackageCreator is provided to generate both firmware and data images. These images are encrypted and signed using the keys configured in OBkeys configuration file (OEMiRoT_Config.obk / OEMuRoT_Config.obk). OEMiRoT_Code_Image.xml contains all the parameters driving the image generation such as:
- The authentication and encryption keys. Keys value inherited from OEMiRoT_Config.obk or OEMuRoT_Config.obk.
- The version.
OEMiRoT_Code_Image.xml can be edited with STM32TrustedPackageCreator in order to modify the version. Keys are directly inherited from OEMiRoT_Config.xml file.
The following figure shows the firmware image generation:
6. Appendix
6.1. OEMiRoT start-up sequence
Note: When no valid firmware image is installed a reset will be triggered in loop. Debug authentication process must be executed to force the download of a new image. Refer to Debug Authentication for STM32U0 article.
Performance measured @ 380 MHz:
Configuration | User application boot time | ||
---|---|---|---|
1 Mbytes | 2 Mbytes | 3 Mbytes | |
Execution from external flash | x ms | x ms | x ms |
Execution from external RAM memory | x ms | x ms | x ms |
Exceution from internal RAM memory | x ms | x ms | x ms |
6.2. Application development phase
During development phase, it is recommended to compile OEMiRoT_Boot project with DEV_MODE defined and to select OPEN state during provisioning process :
- When DEV_MODE is defined:
- additional logs are displayed in tera term during OEMiRoT_Boot project execution.
- an infinite loop is executed instead of a reset in Error_Handler() function .
- tamper event is cleared at startup when required. No need to power off/on the board to clear this event.
- OPEN product state can be selected during provisioning process.
- When OPEN product state is selected during provisioning process, a specific script (obkey_provisioning_open.bat) is called in order to execute additional actions usually done in PROVISIONING product state :
- provision the AHKs (see STM32U0 Reference manual for more description) used to encrypt OBkeys and to encrypt images with MCE peripheral.
- initialize the OEMiRoT data area in the OBkeys containing the version of the firmware installed as well as its SHA256 used when MCUBOOT_USE_HASH_REF is activated (Refer to the Features list for more details on MCUBOOT_USE_HASH_REF.
In CLOSED or LOCKED product state, the DA process should be run to be able to connect the debugger trough JTAG. At the end of the development phase, DEV_MODE must be disabled and the product state CLOSED or LOCKED must be selected during provisioning process.
6.3. OEMiRoT_Config.obk file format
Offset | Size | Type | Description |
---|---|---|---|
0 | 1 | uint8 | sdp command header : destination OBKey index |
1 | 1 | uint8 | sdp command header : destination OBKey HDP level |
2 | 2 | uint16 | sdp command header : reserved |
4 | 4 | uint32 | sdp command header : data size address |
8 | 4 | uint32 | sdp command header : encryption disabled/enabled (0/1) |
12 | 32 | array | SHA256 of the following data content (from offset 44 to xxx) |
44 | 91 | array | Authentication public key (MCU Boot format) |
135 | 70 | array | Encryption private key (MCU Boot format) |
205 | 31 | array | Reserved |
Same applied for OEMuRoT_Config.obk
6.4. OEMiRoT_Code_image xml file format
Parameter | Updatable | Description |
---|---|---|
Authentication key | Automatic | Private key inherited from OEMiROT_Config.xml file. |
Encryption key | Automatic | Public key inherited from OEMiROT_Config.xml file. |
Endianness | No | Little endian. |
Padding | No | Add an installation magic value at the end of the image to trigger image installation. Padding with 0xFF when required. |
Firmware area size | Automatic | Firmware slot size information. This value is updated during the provisioning process based on slot configuration from flash_layout.h |
Header Size | No | 0x400 bytes |
Padding Header | No | Padding the header with 0xFF to fulfil the 0x400 bytes. |
Dependency with data image | No | This parameter is removed by setting the <enable> property to 0. |
Write Option | No | This value is updated during the provisioning process based on the installation method: overwrite or swap. |
Version | Yes | x.y.z firmware image version. |
Security Counter | No | Security counter value automatically generated based on version information. |
Align | No | 16 bytes alignment |
Firmware download area offset | Automatic | Used to generate .hex binary file format including the destination address. This value is updated during the provisioning process based on load and run configuration (execution from external flash extern, internal RAM or external RAM. |
Firmware binary input file | Automatic | Location of the firmware binary file. This parameter is updated during the provisioning process based on information from env.bat file. |
Image output file | Yes | Location of the encrypted image generated. If changed, provisioning scripts must be updated accordingly. |
Same applied for OEMuRoT_Code_Image.xml
6.5. Troubleshooting
Problem | Possible solution |
---|---|
Provisioning errors in ob_flash_programming.bat script | PC com port is connected to tera term application |
Provisioning errors. No JTAG connection. | Device is not in OPEN product state. regression.bat script must be executed |