nRF Connect SDK API 0.1.0
Loading...
Searching...
No Matches
hw_unique_key.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
7#ifndef HW_UNIQUE_KEY_H_
8#define HW_UNIQUE_KEY_H_
9
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26#include <stdbool.h>
27
28#if defined(__NRF_TFM__)
29#include <autoconf.h>
30#endif
31#include <zephyr/devicetree.h>
32
33#if DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_kmu) || defined(CONFIG_CRACEN_HW_PRESENT)
34#define HUK_HAS_KMU
35#endif
36#if defined(CONFIG_HAS_HW_NRF_CC310)
37#define HUK_HAS_CC310
38#endif
39#if defined(CONFIG_HAS_HW_NRF_CC312)
40#define HUK_HAS_CC312
41#endif
42
43#if defined(HUK_HAS_CC310)
44#define HUK_SIZE_WORDS 4
45#elif defined(HUK_HAS_CC312)
46#define HUK_SIZE_WORDS 8
47#elif defined(CONFIG_CRACEN_HW_PRESENT)
48#define HUK_SIZE_WORDS 12
49#else
50#error "This library requires CryptoCell or Cracen to be available."
51#endif
52
53#define HUK_SIZE_BYTES (HUK_SIZE_WORDS * 4)
54
56#define HW_UNIQUE_KEY_ERR_MISSING (0x16501)
57
59#define HW_UNIQUE_KEY_ERR_WRITE_FAILED (0x16502)
60
62#define HW_UNIQUE_KEY_ERR_GENERATION_FAILED (0x16503)
63
65#define HW_UNIQUE_KEY_ERR_DERIVE_FAILED (0x16504)
66
68#define HW_UNIQUE_KEY_ERR_GENERIC_ERROR (0x16505)
69
71#define HW_UNIQUE_KEY_SUCCESS (0x0)
72
73/* The available slots. KDR is always available, while the MKEK and MEXT
74 * keys are only stored when there is a KMU, since without a key, the key
75 * store must be locked after booting, and the KDR is the only key that can
76 * live in the CC HW for the entire boot cycle of the device.
77 */
79#ifndef HUK_HAS_KMU
80 HUK_KEYSLOT_KDR = 0, /* Device Root Key */
81#else
82 HUK_KEYSLOT_MKEK = 2, /* Master Key Encryption Key */
83 HUK_KEYSLOT_MEXT = 4, /* Master External Storage Encryption Key */
84#endif
85};
86
87#define KMU_SELECT_SLOT(KEYSLOT) (uint32_t)((KEYSLOT) + 1) /* NRF_KMU KEYSLOT are 1-indexed. */
88
100int hw_unique_key_write(enum hw_unique_key_slot key_slot, const uint8_t *key);
101
109
119
127
138
156 const uint8_t *context, size_t context_size,
157 uint8_t const *label, size_t label_size,
158 uint8_t *output, uint32_t output_size);
159
160#ifdef __cplusplus
161}
162#endif
163
168#endif /* HW_UNIQUE_KEY_H_ */
hw_unique_key_slot
Definition: hw_unique_key.h:78
@ HUK_KEYSLOT_KDR
Definition: hw_unique_key.h:80
int hw_unique_key_derive_key(enum hw_unique_key_slot key_slot, const uint8_t *context, size_t context_size, uint8_t const *label, size_t label_size, uint8_t *output, uint32_t output_size)
Derive a key from the specified HUK, using the nrf_cc3xx_platform API on CryptoCell....
bool hw_unique_key_are_any_written(void)
Check whether any Hardware Unique Keys are written to the KMU.
int hw_unique_key_write_random(void)
Read random numbers from nrf_cc3xx_platform_ctr_drbg_get and write them to all slots with hw_unique_k...
int hw_unique_key_write(enum hw_unique_key_slot key_slot, const uint8_t *key)
Write a Hardware Unique Key to the KMU.
int hw_unique_key_load_kdr(void)
Load the Hardware Unique Key (HUK) into the KDR registers of the Cryptocell.
bool hw_unique_key_is_written(enum hw_unique_key_slot key_slot)
Check whether a Hardware Unique Key has been written to the KMU.