an5447-overview-of-secure-boot-and-secure-firmware-update-solution-on-arm-trustzone-stm32-microcontrollers-stmicroelectronics
an5447-overview-of-secure-boot-and-secure-firmware-update-solution-on-arm-trustzone-stm32-microcontrollers-stmicroelectronics
Application note
Introduction
This application note describes how to get a Secure Boot and Secure Firmware Update solution on Arm® TrustZone® STM32
microcontrollers based on the Arm® Cortex®‑M33 processor. It also provides a top-level comparison of this solution versus
the X-CUBE-SBSFU solution, which applies to non-TrustZone® STM32 microcontrollers based on the Arm® Cortex®‑M0,
Cortex®‑M3, Cortex®‑M4, or Cortex®‑M7 processors. It provides as well top-level integration guidelines for the Secure Boot and
Secure Firmware Update solution.
For Arm® TrustZone® STM32 microcontrollers, a Secure Boot and Secure Firmware Update solution is provided in the
corresponding STM32Cube MCU Package. Contrary to the solution proposed in the X-CUBE-SBSFU STM32Cube Expansion
Package, it is based on the open-source TF‑M (Trusted Firmware for Arm® Cortex®‑M) reference implementation.
This application note applies to all TrustZone® STM32 microcontrollers (refer to Table 1). However, in this document, the
STM32L5 Series is used as an example.
Depending on the TrustZone® STM32 microcontroller, TF‑M-based application available in the STM32Cube MCU Package may
differ. Refer to the user manual of the TFM application (complete implementation of TF‑M) of the considered Arm® TrustZone®
STM32 microcontroller (see Section 2 References) to get a precise description of the solution.
To get more information about the open-source TF‑M reference implementation, refer to [TF‑M].
Table 1. Applicable products
1 General information
Throughout this application note, the terminology X-CUBE-SBSFU refers to the Secure Boot and Secure
Firmware Update solution available in the X-CUBE-SBSFU STM32Cube Expansion Package, whereas the
terminology SBSFU refers to the Secure Boot and Secure Firmware Update solution available in the STM32Cube
MCU Packages of Arm® TrustZone® STM32 microcontrollers (STM32CubeL5 is used as an example).
Table 2 presents the definition of acronyms that are relevant for a better understanding of this document.
Acronym Definition
Trusted Firmware for M-class Arm® processors. TF‑M provides a reference implementation of secure
TF‑M
world software for Armv8-M
TFM Name of the TF‑M-based application with complete functionalities in the STM32Cube MCU Package
TZ TrustZone®
WRP Write protection
Note: Arm and TrustZone are registered trademarks of Arm Limited (or its subsidiaries) in the US and or elsewhere.
2 References
The resources presented in Table 3 and Table 4 below are public and available either on STMicroelectronics web
site at www.st.com or on third-parties websites.
Reference Document
Application note(1):
[AN5156]
Introduction to STM32 microcontrollers security.
User manual(1):
[UM2262]
Getting started with the X-CUBE-SBSFU STM32Cube Expansion Package.
User manual(1):
[UM2671]
Getting started with STM32CubeL5 TFM application.
User manual(1):
[UM2851]
Getting started with STM32CubeU5 TFM application.
PSA developer APIs:
[PSA_API] developer.arm.com/architectures/security-architectures/platform-security-architecture#implement
(2)
1. This URL belongs to a third party. It is active at document publication, however STMicroelectronics shall not be liable for any
change, move or inactivation of the URL or the referenced material.
Note: Mbed is a trademark of Arm Limited (or its subsidiaries) in the US and or elsewhere.
TF‑M (refer to [TF‑M]) is an Arm Limited driven open-source software framework providing a reference
implementation of the PSA standard on the Arm® Cortex®-M33 (TrustZone®) processor:
• PSA immutable RoT (Root of Trust): immutable “Secure Boot and Secure Firmware Update” application
executed after any reset. This application is based on MCUboot open source software (refer to [MCUboot]).
• PSA updatable RoT: “secure” application implementing a set of secure services isolated in the secure/
privileged environment that can be called by the non-secure application at non-secure application run-time
via the PSA APIs (refer to [PSA_API]):
– Secure storage service: TF‑M secure storage (SST) service implements PSA protected storage APIs
allowing data encryption and writing the result in a possibly untrusted storage. The SST service
implements an AES-GCM based AEAD encryption policy, as a reference, to protect data integrity and
authenticity.
– Internal trusted storage service: TF‑M internal trusted storage (ITS) service implements PSA internal
trusted storage APIs allowing the writing of data in a microcontroller built-in Flash memory region that
will be isolated from non-secure or from unprivileged applications by means of the hardware security
protection mechanisms.
– Cryptography service: the TF‑M crypto service implements the PSA Crypto APIs that allow an
application to use cryptography primitives such as symmetric and asymmetric ciphers, hash, message
authentication codes (MACs), and authenticated encryption with associated data (AEAD). It is based
on the mbed-crypto open-source software (refer to [mbed-crypto]).
– Initial attestation service: the TF‑M initial attestation service allows the application to prove the device
identity during an authentication process to a verification entity. The initial attestation service can create
a token on request, which contains a fix set of device specific data.
• Application updatable RoT: third-party secure services that are isolated in the secure/unprivileged
environment and that can be called by the non-secure application at non-secure application run-time.
Isolation Isolation
secure / non-secure privileged / unprivileged
Non-secure Secure
(such as Crypto, NONCE, RNG)
Internal trusted storage
Apps
Initial attestation
Platform drivers
Secure storage
Cryptography
3rd party
PSA API
Network Middleware
OS
TF-M Core (IPC, SPM, interrupt handling) MCU boot
Application updatable RoT PSA updatable RoT PSA immutable RoT TF-M Isolation boundary
4.1 Overview
X-CUBE-SBSFU provides an STMicroelectronics implementation of Secure Boot and Secure Firmware Update,
and optionally for some STM32 series only, secure KMS (key management services) service available at run-time
for the user application.
The TF‑M reference implementation provides Secure Boot and Secure Firmware Update services based on
open-source MCU boot, and a set of secure services available at run-time for the user application.
The high-level comparison between X-CUBE-SBSFU and TF‑M is shown in Figure 2.
X-CUBE-SBSFU TF-M
Secure Boot
SBSFU MCU boot
Secure Firmware Update
KMS*
Initial attestation
The MCU boot part of the TF‑M can be compared to X-CUBE-SBSFU (without KMS): it offers similar services.
X-CUBE-SBSFU KMS supports similar services as TF‑M secure crypto services but the lists of cryptographic
algorithms or features are not the same and APIs are different even if both are based on an opaque
key API concept. Refer to the X-CUBE-SBSFU and TF‑M APIs documents referenced in the related user
manuals ([UM2262] and TFM user manual of the concerned Arm® TrustZone® STM32Cube MCU Package; see
Section 2 References) to get more details about the supported features.
Security
X-CUBE-SBSFU in X-CUBE-SBSFU V2.4.0(1) TF‑M in STM32CubeL5 V1.4.0(1)
topic
To get an up-to-date view of the feature differences between X-CUBE-SBSFU and TF‑M-based applications for
Arm® TrustZone® STM32 microcontrollers, refer to the latest version of [UM2262] and of the TFM user manual of
the concerned Arm® TrustZone® STM32Cube MCU Package (see Section 2 References).
Figure 3. X-CUBE-SBSFU (STM32L4 Series) and TF‑M (STM32L5 Series) security strategy overview
Secure functions
Secure FW Update SFU keys Firewall + PCROP TZ + WRP + MPU + HDP + RDP L1*
Run-time
Isolation Firewall (2 domains) TZ + MPU (3 domains)
secure services
External
Anti-tamper Static tamper pin Static tamper pin
access protection
Not used in the security examples
delivered in STM32CubeL5 V1.4.0
For more details on security strategy with TF‑M, refer to the TFM user manual of the concerned Arm® TrustZone®
STM32Cube MCU Package (see Section 2 References).
5 TF‑M-based applications
This chapter presents the TF‑M-based applications in the STM32Cube MCU Packages of Arm® TrustZone®
STM32 microcontrollers.
The Arm® TrustZone® STM32Cube MCU Packages propose two different applications based on the TF‑M
reference implementation, ported onto the Arm® TrustZone® STM32 microcontrollers to take benefit of the
hardware security features.
• SBSFU: it consists of the “Secure Boot and Secure Firmware Update” application (named SBSFU_Boot)
and simple user application example (named SBSFU_Appli). A local loader application example (named
SBSFU_Loader) is also included.
• TFM: it consists of the “Secure Boot and Secure Firmware Update” application (named TFM_SBSFU_Boot)
and user application with TFM secure services at run-time (named TFM_Appli). A local loader application
example (named TFM_Loader) is also included.
Users of X-CUBE-SBSFU without KMS are advised to consider the migration to the SBSFU application in the
Arm® TrustZone® STM32Cube MCU Package of interest. Users of X-CUBE-SBSFU with KMS are advised to
consider the migration to the TFM application in the Arm® TrustZone® STM32Cube MCU Package of interest
(possibly removing some secure services or cryptographic algorithms to fit the application needs).
For each application, the memory footprint depends on the configuration (refer to the Memory layout section in the
TFM user manual of the concerned Arm® TrustZone® STM32Cube MCU Package; see Section 2 References).
By removing the TF‑M secure services at run-time and by proposing one firmware image configuration combined
with primary slot only configuration, the SBSFU application in the Arm® TrustZone® STM32Cube MCU Package
of interest maximizes the amount of internal Flash memory available for the user application as illustrated in
Figure 5.
Unused (8 Kbytes)
area 2
(144 Kbytes)
Secure services
SST area (8 Kbytes)
NV data
NV COUNTER (4 Kbytes)
HDP activation code HDP activation code
Personalized
Integrator perso data (2 Kbytes) Integrator perso data (2.2 Kbytes)
keys / data
BL2 NVCNT (4 Kbytes) BL2 NVCNT (4 Kbytes)
For more details on memory mapping, refer to the Memory layout section in the TFM user manual of the
concerned Arm® TrustZone® STM32Cube MCU Package (see Section 2 References).
6 SBSFU application
This chapter presents the SBSFU application in the STM32Cube MCU Packages of Arm® TrustZone® STM32
microcontrollers.
The two private RSA or ECDSA asymmetric keys used to sign the secure and non-secure firmware images are
not embedded in the Flash memory, whereas the two associated public RSA or ECDSA asymmetric keys are
present in the build output of the SBSFU_Boot project. They are embedded in a dedicated immutable Flash
region (personalization data area) as shown in Figure 9.
The public RSA or ECDSA asymmetric key used to encrypt the AES-CTR key is not embedded in the Flash
memory, whereas the associated private RSA or ECDSA asymmetric key is present in the build output of
SBSFU_Boot project, in the personalization data area as well, as shown in Figure 9.
Local loader
SBSFU_Boot
Public RSA or ECDSA asymmetric key for secure image signature
Public RSA or ECDSA asymmetric key for non-secure image signature
Integrator perso data Private RSA or ECDSA asymmetric key for AES-CTR key decryption
BL2 NVCNT
STM32CubeL5 SBSFU
7 TFM application
This chapter presents the TFM application in the STM32Cube MCU Packages of Arm® TrustZone® STM32
microcontrollers.
The top-level integration guidelines provided in Section 6 SBSFU application are applicable to the TFM
application in STM32Cube MCU Packages. In this section, additional top-level integration guidelines, specific
to the TFM application in STM32Cube MCU Packages, are provided.
To get more information on the TFM application in STM32Cube MCU Packages, refer to the TFM user manual of
the concerned Arm® TrustZone® STM32Cube MCU Package (see Section 2 References).
/* Configure session to encrypt message with settings included into the mechanism */
rv = C_EncryptInit(hSession, &mechanism, hKey);
…
/* Encrypt clear message */
rv = C_EncryptUpdate(hSession, &data[0], firstPieceLen, &encryptedData[0],
&ulEncryptedData1Len); PKCS#11 API
…
/* Finalize message encryption */
rv = C_EncryptFinal(hSession, &encryptedData[output_length], &ulEncryptedData3Len);
…
Opaque key ID
For more information on PSA APIs, refer to TFM user application example and [PSA_API].
Non-secure Secure
Initial attestation
Platform drivers
Secure storage
Cryptography
3rd party
PSA API
Network Middleware
OS
TF-M Core (IPC, SPM, interrupt handling) MCU boot
Application updatable RoT PSA updatable RoT PSA immutable RoT TF-M Isolation boundary
These services must be integrated in the Middlewares/trustedfirmware folder as shown in Figure 12. For
more information, refer to [TF‑M].
Location to integrate
OEM secure services
Local loader
ITS area
SST area
NV COUNTER
HDP activation code Public RSA or ECDSA asymmetric key for secure image signature
Public RSA or ECDSA asymmetric key for non-secure image signature
TFM_SBSFU_Boot Private RSA or ECDSA asymmetric key for AES-CTR key decryption
EAT key*
HUK*
Integrator perso data Instance ID*
STM32CubeL5 TFM
For more details on personalization data, refer to section Integrator role description in the TFM user manual of the
concerned Arm® TrustZone® STM32Cube MCU Package (see Section 2 References).
Revision history
Made the document generic to cover all applicable Arm® TrustZone® STM32
microcontrollers and the related STM32Cube MCU Packages, keeping the
STM32CubeL5 MCU Package as an example:
• Updated the document title
16-Aug-2021 3
• Added Table 1. Applicable products and updated Table 3. Document
references
• Updated Section 4.2 Top-level features and Section 6.3 Keys
personalization
Contents
1 General information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3
5 TF‑M-based applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
6 SBSFU application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10
6.1 User application integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
6.2 OEM secure services integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
6.3 Keys personalization. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
List of tables
Table 1. Applicable products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Table 2. List of acronyms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Table 3. Document references . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Table 4. Open-source software resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Table 5. X-CUBE-SBSFU vs. TF‑M top-level features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Table 6. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
List of figures
Figure 1. TF‑M overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Figure 2. X-CUBE-SBSFU vs. TF‑M overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Figure 3. X-CUBE-SBSFU (STM32L4 Series) and TF‑M (STM32L5 Series) security strategy overview . . . . . . . . . . . . . . 7
Figure 4. STM32CubeL5 applications based on TF‑M . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Figure 5. Memory footprint example of STM32CubeL5 applications based on TF‑M . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Figure 6. User application integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Figure 7. OEM secure services integration (SBSFU) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Figure 8. Firmware image keys personalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Figure 9. Integrator personalized data area in STM32CubeL5 SBSFU. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Figure 10. PSA API migration example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Figure 11. 3rd party secure services in TF-M . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Figure 12. OEM secure services integration (TFM) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Figure 13. Personalization data region . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17