TRNGLPF3HSM.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024-2025, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*!****************************************************************************
33  * @file TRNGLPF3HSM.h
34  *
35  * @brief TRNG driver implementation for CC27XX and CC35XX device families
36  *
37  * This file should only be included in the board file to fill the TRNG_config
38  * struct.
39  *
40  * # Hardware
41  *
42  * The CC27XX and CC35XX device families have a dedicated hardware engine,
43  * the Hardware Security Module (HSM) that contains TRNG capabilities based on
44  * sampling multiple free running oscillators (FROs).
45  *
46  * # Behaviour
47  *
48  * The driver submits a get random number token to the HSM. The token will indicate the
49  * destination buffer and the request size.
50  *
51  * The TRNG driver can be used as a True Random Number Generator (TRNG) or as a Cryptographically
52  * Secure Pseudo Random Number Generator (CRNG). CRNG is a deterministic (hence the pseudo)
53  * computational method to turn an input (FRO samples) into a sequence of bits that are
54  * indistinguishable from ideal randomness, with cryptographic certainty, for a computationally
55  * bounded adversary not knowing the input.
56  *
57  * By default, the HSM HW is configured and initialized to be in CRNG mode. To switch to TRNG,
58  * the user must call TRNGLPF3HSM_switchNrbgMode() API and specify TRNG_MODE_TRNG as the
59  * NRBG Mode.
60  *
61  * # Samples Per Cycle Vs. Mix Cycles
62  *
63  * # Mix Cycles
64  *
65  * When the HSM EIP-130 HW in CRNG mode, the Mix Cycles value represents the number of clock
66  * cycles before the output is sampled. The MixCycles value must be in the range [0...15].
67  * However, in the current implementation the value 0 is interpreted as not configured and
68  * therefore will be set to 15 internally, which is also the default value.
69  *
70  * # Samples Per Cycle
71  *
72  * When the HSM EIP-130 HW is in TRNG mode, the Samples Per Cycle value represents the number of
73  * (XOR-ed) FRO samples XOR-ed together to generate a single 'noise' bit. This value must be
74  * set such that the total amount of entropy in 8 'noise' bits equals at least 1 bit. The value
75  * to program here depends upon the jitter behavior of the FROs.
76  *
77  * !!!!!!!!!!!!! WARNING !!!!!!!!!!!!!
78  * The HSM HW engine is configured and initialized with the Samples Per Cycle value set to 19390
79  * and Mix Cycles value set to 15. This value is not available for the customer to configure.
80  */
81 
82 #ifndef ti_drivers_TRNG_TRNGLPF3HSM__include
83 #define ti_drivers_TRNG_TRNGLPF3HSM__include
84 
85 #include <stdint.h>
86 #include <stdbool.h>
87 
88 #include <ti/drivers/Power.h>
89 #include <ti/drivers/TRNG.h>
91 
92 #include <ti/drivers/dpl/HwiP.h>
93 #include <ti/drivers/dpl/SemaphoreP.h>
94 
95 #ifdef __cplusplus
96 extern "C" {
97 #endif
98 
99 /*
100  *
101  * !!!!!!!!!!!!! WARNING !!!!!!!!!!!!!
102  * ## TRNG Driver Limitation for CC27XX and CC35XX device families #
103  *
104  * For CC27XX and CC35XX devices, the size of random data requested must be a 32-bit multiple. The
105  * appropriate error code, TRNG_STATUS_INVALID_INPUT_SIZE, will be returned to the user in
106  * the case this rule is not adhered to and the input size is not a multiple of 4 bytes, (32-bits).
107  *
108  */
109 
116 #define TRNG_STATUS_ALREADY_IN_SPECIFIED_NRBG_TYPE ((int_fast16_t)(TRNG_STATUS_RESERVED - 0))
117 
123 #define TRNG_STATUS_INVALID_INPUT_SIZE ((int_fast16_t)(TRNG_STATUS_RESERVED - 1))
124 
130 #define TRNG_STATUS_INVALID_KEY_ENCODING ((int_fast16_t)(TRNG_STATUS_RESERVED - 2))
131 
135 typedef enum
136 {
140 
144 typedef struct
145 {
146  uint8_t reserved1;
148 
154 typedef struct
155 {
156  TRNG_Handle handle;
157  TRNG_CryptoKeyCallbackFxn cryptoKeyCallbackFxn;
158  TRNG_RandomBytesCallbackFxn randomBytesCallbackFxn;
159  CryptoKey *entropyKey;
160  uint8_t *entropyBuffer;
161  uint32_t semaphoreTimeout;
162  size_t entropyGenerated;
163  size_t entropyRequested;
164  size_t rawEntropyBlocksRequested;
165  int_fast16_t returnStatus;
166  int_fast16_t hsmStatus;
167  TRNG_ReturnBehavior returnBehavior;
168  bool isOpen;
169 } TRNGLPF3HSM_Object;
170 
173 #if (DeviceFamily_PARENT == DeviceFamily_PARENT_CC27XX)
174 
188 extern int_fast16_t TRNGLPF3HSM_reseedHSM(TRNG_Handle handle);
189 
208 extern int_fast16_t TRNGLPF3HSM_reseedHSMAsync();
209 
222 extern int_fast16_t TRNGLPF3HSM_switchNrbgMode(TRNG_Handle handle, TRNGLFP3HSM_NRBGMode nrbgMode);
223 #endif /* (DeviceFamily_PARENT == DeviceFamily_PARENT_CC27XX) */
224 
225 #ifdef __cplusplus
226 }
227 #endif
228 
229 #endif /* ti_drivers_TRNG_TRNGLPF3HSM__include */
Definition: TRNGLPF3HSM.h:138
int_fast16_t TRNGLPF3HSM_reseedHSM(TRNG_Handle handle)
Reseed the HSM IP DRBG engine.
The CryptoKey type is an opaque representation of a cryptographic key.
Definition: TRNGLPF3HSM.h:137
TRNG Global configuration.
Definition: TRNG.h:453
TRNGLPF3HSM Hardware Attributes.
Definition: TRNGLPF3HSM.h:144
CryptoKey datastructure.
Definition: CryptoKey.h:211
TRNGLFP3HSM_NRBGMode
Enum for the NRBG engine type.
Definition: TRNGLPF3HSM.h:135
void(* TRNG_CryptoKeyCallbackFxn)(TRNG_Handle handle, int_fast16_t returnValue, CryptoKey *entropy)
The definition of a callback function used by the TRNG driver when TRNG_generateKey() is called with ...
Definition: TRNG.h:519
TRNG_ReturnBehavior
The way in which TRNG function calls return after generating the requested entropy.
Definition: TRNG.h:488
TRNG driver header.
int_fast16_t TRNGLPF3HSM_switchNrbgMode(TRNG_Handle handle, TRNGLFP3HSM_NRBGMode nrbgMode)
Switches the TRNG driver NRBG Mode between CRNG-based or TRNG-based.
int_fast16_t TRNGLPF3HSM_reseedHSMAsync()
Reseed the HSM IP DRBG engine.
uint8_t reserved1
Definition: TRNGLPF3HSM.h:146
void(* TRNG_RandomBytesCallbackFxn)(TRNG_Handle handle, int_fast16_t returnValue, uint8_t *randomBytes, size_t randomBytesSize)
The definition of a callback function used by the TRNG driver when TRNG_getRandomBytes() is called wi...
Definition: TRNG.h:534
© Copyright 1995-2025, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale