RTEMS 6.1-rc2
Loading...
Searching...
No Matches
fsl_puf.h
1/*
2 * Copyright 2018-2021 NXP
3 * All rights reserved.
4 *
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9#ifndef _PUF_H_
10#define _PUF_H_
11
12#include <stddef.h>
13#include <stdint.h>
14
15#include "fsl_common.h"
16
17/*******************************************************************************
18 * Definitions
19 *******************************************************************************/
20
60#define FSL_PUF_DRIVER_VERSION (MAKE_VERSION(2, 1, 6))
63typedef enum _puf_key_index_register
64{
65 kPUF_KeyIndex_00 = 0x00U,
66 kPUF_KeyIndex_01 = 0x01U,
67 kPUF_KeyIndex_02 = 0x02U,
68 kPUF_KeyIndex_03 = 0x03U,
69 kPUF_KeyIndex_04 = 0x04U,
70 kPUF_KeyIndex_05 = 0x05U,
71 kPUF_KeyIndex_06 = 0x06U,
72 kPUF_KeyIndex_07 = 0x07U,
73 kPUF_KeyIndex_08 = 0x08U,
74 kPUF_KeyIndex_09 = 0x09U,
75 kPUF_KeyIndex_10 = 0x0AU,
76 kPUF_KeyIndex_11 = 0x0BU,
77 kPUF_KeyIndex_12 = 0x0CU,
78 kPUF_KeyIndex_13 = 0x0DU,
79 kPUF_KeyIndex_14 = 0x0EU,
80 kPUF_KeyIndex_15 = 0x0FU,
81} puf_key_index_register_t;
82
83typedef enum _puf_min_max
84{
85 kPUF_KeySizeMin = 8u,
86 kPUF_KeySizeMax = 512u,
87 kPUF_KeyIndexMax = kPUF_KeyIndex_15,
88} puf_min_max_t;
89
91typedef enum _puf_key_slot
92{
95#if defined(PUF_KEYMASK_COUNT) && (PUF_KEYMASK_COUNT > 2)
96 kPUF_KeySlot2 = 2U,
97 kPUF_KeySlot3 = 3U,
98#endif
100
101typedef struct
102{
103 uint32_t dischargeTimeMsec;
104 uint32_t coreClockFrequencyHz;
105#if defined(FSL_FEATURE_PUF_HAS_SRAM_CTRL) && (FSL_FEATURE_PUF_HAS_SRAM_CTRL > 0)
106 /* LPCXpresso55s16 */
107 PUF_SRAM_CTRL_Type *puf_sram_base;
108 uint8_t CKGATING;
109#endif /* FSL_FEATURE_PUF_HAS_SRAM_CTRL */
112#define PUF_GET_KEY_CODE_SIZE_FOR_KEY_SIZE(x) ((160u + (((((x) << 3) + 255u) >> 8) << 8)) >> 3)
113#define PUF_MIN_KEY_CODE_SIZE PUF_GET_KEY_CODE_SIZE_FOR_KEY_SIZE(8UL)
114#define PUF_ACTIVATION_CODE_SIZE 1192U
115#define KEYSTORE_PUF_DISCHARGE_TIME_FIRST_TRY_MS 50
116#define KEYSTORE_PUF_DISCHARGE_TIME_MAX_MS 400
117
119enum
120{
121 kStatus_EnrollNotAllowed = MAKE_STATUS(kStatusGroup_PUF, 1),
122 kStatus_StartNotAllowed = MAKE_STATUS(kStatusGroup_PUF, 2)
123};
124
126/*******************************************************************************
127 * API
128 *******************************************************************************/
129
130#if defined(__cplusplus)
131extern "C" {
132#endif /* __cplusplus */
133
142
153
162void PUF_Deinit(PUF_Type *base, puf_config_t *conf);
163
176status_t PUF_Enroll(PUF_Type *base, uint8_t *activationCode, size_t activationCodeSize);
177
190status_t PUF_Start(PUF_Type *base, const uint8_t *activationCode, size_t activationCodeSize);
191
210 PUF_Type *base, puf_key_index_register_t keyIndex, size_t keySize, uint8_t *keyCode, size_t keyCodeSize);
211
229 puf_key_index_register_t keyIndex,
230 const uint8_t *userKey,
231 size_t userKeySize,
232 uint8_t *keyCode,
233 size_t keyCodeSize);
234
250status_t PUF_GetKey(PUF_Type *base, const uint8_t *keyCode, size_t keyCodeSize, uint8_t *key, size_t keySize);
251
270 PUF_Type *base, const uint8_t *keyCode, size_t keyCodeSize, puf_key_slot_t keySlot, uint32_t keyMask);
271
281
290bool PUF_IsGetKeyAllowed(PUF_Type *base);
291
292#if defined(PUF_CFG_BLOCKKEYOUTPUT_MASK) && PUF_CFG_BLOCKKEYOUTPUT_MASK
293static inline void PUF_BlockSetKey(PUF_Type *base)
294{
295 base->CFG |= PUF_CFG_BLOCKKEYOUTPUT_MASK; /* block set key */
296}
297#endif /* PUF_CFG_BLOCKKEYOUTPUT_MASK */
298
299#if defined(PUF_CFG_PUF_BLOCK_SET_KEY_MASK) && PUF_CFG_PUF_BLOCK_SET_KEY_MASK
300static inline void PUF_BlockSetKey(PUF_Type *base)
301{
302 base->CFG |= PUF_CFG_PUF_BLOCK_SET_KEY_MASK; /* block set key */
303}
304#endif /* PUF_CFG_PUF_BLOCK_SET_KEY_MASK */
305
306#if defined(PUF_CFG_BLOCKENROLL_SETKEY_MASK) && PUF_CFG_BLOCKENROLL_SETKEY_MASK
307static inline void PUF_BlockEnroll(PUF_Type *base)
308{
309 base->CFG |= PUF_CFG_BLOCKENROLL_SETKEY_MASK; /* block enroll */
310}
311#endif /* PUF_CFG_BLOCKENROLL_SETKEY_MASK */
312
313#if defined(PUF_CFG_PUF_BLOCK_ENROLL_MASK) && PUF_CFG_PUF_BLOCK_ENROLL_MASK
314static inline void PUF_BlockEnroll(PUF_Type *base)
315{
316 base->CFG |= PUF_CFG_PUF_BLOCK_ENROLL_MASK; /* block enroll */
317}
318#endif /* PUF_CFG_PUF_BLOCK_ENROLL_MASK */
319
330
331#if defined(__cplusplus)
332}
333#endif /* __cplusplus */
334
335#endif /* _PUF_H_ */
int32_t status_t
Type used for all status and error return values.
Definition: fsl_common.h:225
#define MAKE_STATUS(group, code)
Construct a status code value from a group and code number.
Definition: fsl_common.h:47
@ kStatusGroup_PUF
Definition: fsl_common.h:160
status_t PUF_SetUserKey(PUF_Type *base, puf_key_index_register_t keyIndex, const uint8_t *userKey, size_t userKeySize, uint8_t *keyCode, size_t keyCodeSize)
Set user key.
Definition: fsl_puf.c:528
status_t PUF_PowerCycle(PUF_Type *base, puf_config_t *conf)
Powercycle PUF.
Definition: fsl_puf.c:110
status_t PUF_Zeroize(PUF_Type *base)
Zeroize PUF.
Definition: fsl_puf.c:935
status_t PUF_SetIntrinsicKey(PUF_Type *base, puf_key_index_register_t keyIndex, size_t keySize, uint8_t *keyCode, size_t keyCodeSize)
Set intrinsic key.
Definition: fsl_puf.c:438
status_t PUF_GetHwKey(PUF_Type *base, const uint8_t *keyCode, size_t keyCodeSize, puf_key_slot_t keySlot, uint32_t keyMask)
Reconstruct hw bus key from a key code.
Definition: fsl_puf.c:705
_puf_key_slot
PUF key slot.
Definition: fsl_puf.h:92
void PUF_Deinit(PUF_Type *base, puf_config_t *conf)
Denitialize PUF.
Definition: fsl_puf.c:251
bool PUF_IsGetKeyAllowed(PUF_Type *base)
Checks if Get Key operation is allowed.
Definition: fsl_puf.c:813
void PUF_GetDefaultConfig(puf_config_t *conf)
Sets the default configuration of PUF.
Definition: fsl_puf.c:174
status_t PUF_GetKey(PUF_Type *base, const uint8_t *keyCode, size_t keyCodeSize, uint8_t *key, size_t keySize)
Reconstruct key from a key code.
Definition: fsl_puf.c:839
status_t PUF_Start(PUF_Type *base, const uint8_t *activationCode, size_t activationCodeSize)
Start PUF.
Definition: fsl_puf.c:363
enum _puf_key_slot puf_key_slot_t
PUF key slot.
status_t PUF_Enroll(PUF_Type *base, uint8_t *activationCode, size_t activationCodeSize)
Enroll PUF.
Definition: fsl_puf.c:294
status_t PUF_Init(PUF_Type *base, puf_config_t *conf)
Initialize PUF.
Definition: fsl_puf.c:199
@ kPUF_KeySlot0
Definition: fsl_puf.h:93
@ kPUF_KeySlot1
Definition: fsl_puf.h:94
Definition: MIMXRT1166_cm4.h:67912
Definition: fsl_puf.h:102