TRNGCC26XX.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2020, 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 TRNGCC26XX.h
34  *
35  * @brief TRNG driver implementation for the CC26XX family
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 CC26XX family has a dedicated hardware TRNG based on sampling multiple
43  * free running oscillators. With all FROs enabled, the TRNG hardware generates
44  * 64 bits of entropy approximately every 5ms. The driver implementation
45  * chains multiple 64-bit entropy generation operations together to generate
46  * an arbitrary amount of entropy.
47  *
48  * # Behaviour
49  *
50  * The driver keeps a global pool of entropy available to service any requests
51  * immediately. If the pool is not sufficiently large or is too depleted to
52  * service a request, entropy will be generated until the request is serviced.
53  * If there is an ongoing TRNG request that the hardware is generating entropy
54  * for, the driver will queue any other requests and work them off in FIFO
55  * order.
56  *
57  * Requests issued by driver instances with polling return behaviour will
58  * preempt any executing requests and be serviced immediately.
59  *
60  * After the request queue is emptied, the driver will start an asynchronous
61  * operation in the background to refill the depleted entropy pool.
62  *
63  * # Samples Per Cycle
64  *
65  * The EIP-75t HW takes 240,000 clock cycles in the default setting to generate
66  * one round of output (i.e. 64 bits). This comes to 5ms on a 48MHz clock. The
67  * clock cycles per round can be configured to be as low as 2^8 (256) to as high
68  * as 2^24 (16,777,216).
69  * Entropy re-generation time can be tailored in a trade-off between speed of
70  * random number generation and amount of entropy in each of those random numbers.
71  */
72 
73 #ifndef ti_drivers_TRNG_TRNGCC26XX__include
74 #define ti_drivers_TRNG_TRNGCC26XX__include
75 
76 #include <stdint.h>
77 #include <stdbool.h>
78 
79 #include <ti/drivers/Power.h>
80 #include <ti/drivers/TRNG.h>
82 
83 #include <ti/drivers/dpl/HwiP.h>
84 #include <ti/drivers/dpl/SemaphoreP.h>
85 
86 #ifdef __cplusplus
87 extern "C" {
88 #endif
89 
91 #define TRNGCC26XX_SAMPLES_PER_CYCLE_MIN 256
92 
95 #define TRNGCC26XX_SAMPLES_PER_CYCLE_DEFAULT 240000
96 
97 #define TRNGCC26XX_SAMPLES_PER_CYCLE_MAX 16777216
98 
107 #define TRNGCC26XX_MIN_BYTES_PER_ITERATION (2 * sizeof(uint32_t))
108 
117 #ifndef TRNGCC26XX_ENTROPY_POOL_SIZE
118  #define TRNGCC26XX_ENTROPY_POOL_SIZE (32 / sizeof(uint64_t))
119 #endif
120 
127 typedef struct
128 {
142  uint8_t intPriority;
149  uint32_t swiPriority;
155  uint32_t samplesPerCycle;
157 
163 typedef struct
164 {
165  List_Elem listElement; /* Must start with a List_Elem
166  * to allow casting of List_Elem
167  * pointer returned by List APIs
168  * to TRNGCC26XX_Object pointers.
169  */
170  TRNG_Handle handle;
171  TRNG_CryptoKeyCallbackFxn cryptoKeyCallbackFxn;
172  TRNG_RandomBytesCallbackFxn randomBytesCallbackFxn;
173  uint32_t samplesPerCycle;
174  CryptoKey *entropyKey;
175  uint8_t *entropyBuffer;
176  uint32_t semaphoreTimeout;
177  size_t entropyGenerated;
178  size_t entropyRequested;
179  int_fast16_t returnStatus;
180  TRNG_ReturnBehavior returnBehavior;
181  bool isOpen;
182  bool isEnqueued;
183  SemaphoreP_Struct operationSemaphore;
184 } TRNGCC26XX_Object;
185 
201 extern int_fast16_t TRNGCC26XX_setSamplesPerCycle(TRNG_Handle handle, uint32_t samplesPerCycle);
202 
203 #ifdef __cplusplus
204 }
205 #endif
206 
207 #endif /* ti_drivers_TRNG_TRNGCC26XX__include */
The CryptoKey type is an opaque representation of a cryptographic key.
TRNGCC26XX Hardware Attributes.
Definition: TRNGCC26XX.h:127
Power Manager.
TRNG Global configuration.
Definition: TRNG.h:320
CryptoKey datastructure.
Definition: CryptoKey.h:192
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:386
TRNG_ReturnBehavior
The way in which TRNG function calls return after generating the requested entropy.
Definition: TRNG.h:355
int_fast16_t TRNGCC26XX_setSamplesPerCycle(TRNG_Handle handle, uint32_t samplesPerCycle)
Sets the number of entropy generation cycles before the results are returned.
uint32_t samplesPerCycle
TRNG Maximum Samples per Cycle. Changes the maximum number of randomness samples in each entropy gene...
Definition: TRNGCC26XX.h:155
TRNG driver header.
uint32_t swiPriority
TRNG SWI priority. The higher the number, the higher the priority. The minimum is 0 and the maximum i...
Definition: TRNGCC26XX.h:149
Definition: List.h:126
uint8_t intPriority
Crypto Peripheral&#39;s interrupt priority.
Definition: TRNGCC26XX.h:142
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:401
© Copyright 1995-2022, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale