Skip to content

Commit c97ecac

Browse files
hellesvik-nordicnordicjm
authored andcommitted
tf-m: Add Attestation support for nRF54L15
Add support for PSA Attestation to the nRF54L15. Ref: NCSDK-22598 Signed-off-by: Sigurd Hellesvik <[email protected]>
1 parent 868ce2c commit c97ecac

File tree

12 files changed

+79
-5
lines changed

12 files changed

+79
-5
lines changed

lib/identity_key/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,12 @@ config IDENTITY_KEY_DUMMY
3636
testing purposes.
3737

3838
endif # IDENTITY_KEY
39+
40+
config IDENTITY_KEY_TFM
41+
bool "Identity key support in TF-M"
42+
depends on HAS_HW_NRF_CC3XX
43+
depends on TRUSTED_EXECUTION_NONSECURE
44+
help
45+
This option adds support for an identity key stored in the KMU to TF-M.
46+
The key is stored in an encrypted form and is decrypted by the identity key library.
47+
The identity key is an ECC secp256r1 key pair.

modules/trusted-firmware-m/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,13 @@ if(CONFIG_NRF_SECURE_APPROTECT_USER_HANDLING)
307307
)
308308
endif()
309309

310+
if(CONFIG_IDENTITY_KEY_TFM)
311+
set_property(TARGET zephyr_property_target
312+
APPEND PROPERTY TFM_CMAKE_OPTIONS
313+
-DCONFIG_IDENTITY_KEY_TFM=ON
314+
)
315+
endif()
316+
310317
zephyr_include_directories(${ZEPHYR_NRF_MODULE_DIR}/include/tfm)
311318

312319
# Default values from config_base.h in TF-M.

modules/trusted-firmware-m/Kconfig.tfm.defconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ config TFM_PARTITION_INITIAL_ATTESTATION
6666
select PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT
6767
select PSA_WANT_ALG_ECDSA
6868
select PSA_WANT_ECC_SECP_R1_256
69-
select SECURE_BOOT_STORAGE
69+
select SECURE_BOOT_STORAGE if TRUSTED_EXECUTION_SECURE
7070

7171
config TFM_PARTITION_PROTECTED_STORAGE
7272
bool

modules/trusted-firmware-m/tfm_boards/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ if (${TFM_PARTITION_CRYPTO})
116116
tfm_sprt
117117
)
118118

119-
if (${TFM_PARTITION_INITIAL_ATTESTATION})
119+
if((${TFM_PARTITION_INITIAL_ATTESTATION}) AND CONFIG_IDENTITY_KEY_TFM)
120120
target_sources(platform_s
121121
PRIVATE
122122
${ZEPHYR_NRF_MODULE_DIR}/lib/identity_key/identity_key.c

modules/trusted-firmware-m/tfm_boards/common/attest_hal.c

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,27 @@
88

99
#include <stddef.h>
1010
#include <stdint.h>
11+
#include <psa/error.h>
12+
#include <psa/crypto.h>
1113
#include "tfm_attest_hal.h"
1214
#include "tfm_plat_boot_seed.h"
1315
#include "tfm_plat_device_id.h"
14-
#include <nrf_cc3xx_platform.h>
1516
#include "tfm_strnlen.h"
1617
#include "nrf_provisioning.h"
17-
#include <nrfx_nvmc.h>
1818
#include <bl_storage.h>
1919

20+
#ifdef CONFIG_NRFX_NVMC
21+
#include <nrfx_nvmc.h>
22+
#endif
23+
#ifdef CONFIG_HAS_HW_NRF_CC3XX
24+
#include <nrf_cc3xx_platform.h>
25+
#endif
26+
27+
#if defined(CONFIG_CRACEN_HW_PRESENT)
28+
static bool boot_seed_set;
29+
static uint8_t boot_seed[BOOT_SEED_SIZE];
30+
#endif
31+
2032
static enum tfm_security_lifecycle_t map_bl_storage_lcs_to_tfm_slc(enum lcs lcs)
2133
{
2234
switch (lcs) {
@@ -101,8 +113,11 @@ enum tfm_plat_err_t tfm_attest_hal_get_profile_definition(uint32_t *size, uint8_
101113

102114
enum tfm_plat_err_t tfm_plat_get_boot_seed(uint32_t size, uint8_t *buf)
103115
{
116+
#if defined(CONFIG_HAS_HW_NRF_CC3XX)
104117
int nrf_err;
105118

119+
_Static_assert(NRF_CC3XX_PLATFORM_TFM_BOOT_SEED_SIZE == BOOT_SEED_SIZE,
120+
"NRF_CC3XX_PLATFORM_TFM_BOOT_SEED_SIZE must match BOOT_SEED_SIZE");
106121
if (size != NRF_CC3XX_PLATFORM_TFM_BOOT_SEED_SIZE) {
107122
return TFM_PLAT_ERR_INVALID_INPUT;
108123
}
@@ -111,6 +126,24 @@ enum tfm_plat_err_t tfm_plat_get_boot_seed(uint32_t size, uint8_t *buf)
111126
if (nrf_err != NRF_CC3XX_PLATFORM_SUCCESS) {
112127
return TFM_PLAT_ERR_SYSTEM_ERR;
113128
}
129+
#elif defined(CONFIG_CRACEN_HW_PRESENT)
130+
if (!boot_seed_set) {
131+
psa_status_t psa_err = psa_generate_random(boot_seed, sizeof(boot_seed));
132+
133+
if (psa_err != PSA_SUCCESS) {
134+
return TFM_PLAT_ERR_SYSTEM_ERR;
135+
}
136+
137+
boot_seed_set = true;
138+
}
139+
140+
if (size != BOOT_SEED_SIZE) {
141+
return TFM_PLAT_ERR_INVALID_INPUT;
142+
}
143+
memcpy(buf, boot_seed, size);
144+
#else
145+
#error "No crypto hardware to generate boot seed available."
146+
#endif
114147

115148
return TFM_PLAT_ERR_SUCCESS;
116149
}

modules/trusted-firmware-m/tfm_boards/nrf54l15_cpuapp/config.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,11 @@ include(${PLATFORM_PATH}/common/${NRF_SOC_VARIANT}/config.cmake)
1313

1414
# Override PS_CRYPTO_KDF_ALG
1515
set(PS_CRYPTO_KDF_ALG PSA_ALG_SP800_108_COUNTER_CMAC CACHE STRING "KDF Algorithm to use")
16+
17+
# attest_hal.c includes bl_storage.h, which needs CONFIG_NRFX_RRAMC to be defined.
18+
# This is because bl_storage is a lib intended to be run from either the bootloader (Zephyr) or from TF-M.
19+
# This is independent from the NS image's CONFIG_NRFX_RRAMC, which must be disabled, so we can not inherit
20+
# this from app Kconfig.
21+
if(TFM_PARTITION_INITIAL_ATTESTATION)
22+
add_compile_definitions(CONFIG_NRFX_RRAMC)
23+
endif()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CONFIG_SPI_NOR=n
2+
CONFIG_PM_PARTITION_SIZE_TFM=0x50800
3+
4+
# Since provisioning is not supported for the nRF54L15 yet,
5+
# we will use dummy provisioning for now.
6+
CONFIG_TFM_NRF_PROVISIONING=n
7+
CONFIG_TFM_DUMMY_PROVISIONING=y

samples/tfm/tfm_psa_template/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ CONFIG_TFM_EXCEPTION_INFO_DUMP=y
1212

1313
CONFIG_TFM_PARTITION_INITIAL_ATTESTATION=y
1414
CONFIG_TFM_NRF_PROVISIONING=y
15+
CONFIG_IDENTITY_KEY_TFM=y
1516

1617
CONFIG_SECURE_BOOT=y
1718

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CONFIG_PM_PARTITION_SIZE_MCUBOOT=0xb800
2+
CONFIG_SPI_NOR=n
3+
CONFIG_BOOT_MAX_IMG_SECTORS=256
4+
5+
# FPROTECT is set in NSIB instead
6+
CONFIG_FPROTECT=n

subsys/bootloader/bl_storage/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66

77
config SECURE_BOOT_STORAGE
88
bool "Library for accessing the bootloader storage"
9-
select NRFX_RRAMC if SOC_SERIES_NRF54LX
9+
select NRFX_RRAMC if SOC_SERIES_NRF54LX && !TRUSTED_EXECUTION_NONSECURE

0 commit comments

Comments
 (0)