Last edited one day ago

Hardware unique key management in OP-TEE

Applicable for STM32MP13x lines, STM32MP15x lines, STM32MP21x lines, STM32MP23x lines, STM32MP25x lines

1. Article purpose[edit | edit source]

This article explains how OP-TEE manages the Hardware Unique Key.

2. API[edit | edit source]

OP-TEE provides the following function to perform a software key derivation.

 TEE_Result huk_subkey_derive(enum huk_subkey_usage usage, const void *const_data, size_t const_data_len, uint8_t *subkey, size_t subkey_len);

The function huk_subkey_derive calls the function tee_otp_get_hw_unique_key to read the HUK. The default implementation provided in OP-TEE returned a statically defined key. This function is redefined for platforms that allow the software to read the HUK (STM32MP15x lines ).

 TEE_Result tee_otp_get_hw_unique_key(struct tee_hw_unique_key *hwkey);
HUK subkey derivation overview

2.1. HUK: Hardware protected[edit | edit source]

On platforms that provide SAES (STM32MP13xC/F lines , STM32MP21xC/F lines , STM32MP23xC/F lines  or STM32MP25xC/F lines ), the key derivation is done by the hardware. Hence, the function huk_subkey_derive is redefined in the SAES driver.

Warning
If SAES is disabled or on STM32MP13xA/D lines , STM32MP21xA/D lines , STM32MP23xA/D lines  and STM32MP25xA/D lines , the HUK is no more accessible.

In this case, the default implementation of the functions huk_subkey_derive and tee_otp_get_hw_unique_key are used.

2.2. HUK: Software implementation[edit | edit source]

If a customer chooses to add an HUK, they must configure OP-TEE to indicate in which OTPs the HUK is located. The location of the HUK in the OTP can be set in the DT of OP-TEE or in the build command line.

An additional NVMEM data cell in BSEC can represent the location of the HUK in the OTP. The following code is an example of how to register a 128-bits HUK provisioned in OTPs 60 to 63.

&bsec {
 	huk_otp: huk-otp@f0 {
 		reg = <0xf0 0x10>;
	};
};

Compile OP-TEE with the following directives to read the location of the HUK in the DT:

CFG_STM32MP15_HUK=y 
CFG_STM32_HUK_FROM_DT=y

The section OP-TEE build command provides the location of HUK in the OTP. There are two possibilities :

  • The HUK is stored in contiguous OTPs. In this case, it is possible to use the first OTP that stores the HUK. The following directives locates the HUK in OTP 60 to 63.
CFG_STM32MP15_HUK=y 
CFG_STM32MP15_HUK_OTP_BASE=0xf0
  • The HUK is scattered in a non contiguous field. For example, the following directives locates the HUK in OTPs 60 63 64 65
CFG_STM32MP15_HUK=y
CFG_STM32MP15_HUK_BSEC_KEY_0=0xf0
CFG_STM32MP15_HUK_BSEC_KEY_1=0xfc
CFG_STM32MP15_HUK_BSEC_KEY_2=0x100
CFG_STM32MP15_HUK_BSEC_KEY_3=0x104