TRNG.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018, 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  */
288 #ifndef ti_drivers_TRNG__include
289 #define ti_drivers_TRNG__include
290 
291 #ifdef __cplusplus
292 extern "C" {
293 #endif
294 
295 #include <stdbool.h>
296 #include <stddef.h>
297 #include <stdint.h>
298 
300 
318 #define TRNG_CMD_RESERVED (32)
319 
332 #define TRNG_STATUS_RESERVED (-32)
333 
347 #define TRNG_STATUS_SUCCESS (0)
348 
355 #define TRNG_STATUS_ERROR (-1)
356 
364 #define TRNG_STATUS_UNDEFINEDCMD (-2)
365 
374 #define TRNG_STATUS_RESOURCE_UNAVAILABLE (-3)
375 
388 /* Add TRNG_CMD_<commands> here */
389 
397 typedef struct TRNG_Config_ *TRNG_Handle;
398 
420 typedef enum TRNG_ReturnBehavior_ {
436 
448 typedef struct TRNG_Config_ {
450  void *object;
451 
453  void const *hwAttrs;
454 } TRNG_Config;
455 
467 typedef void (*TRNG_CallbackFxn) (TRNG_Handle handle,
468  int_fast16_t returnValue,
469  CryptoKey *entropy);
470 
479 typedef struct TRNG_Params_ {
482  uint32_t timeout;
485  void *custom;
488 } TRNG_Params;
489 
495 extern const TRNG_Params TRNG_defaultParams;
496 
505 void TRNG_init(void);
506 
519 void TRNG_Params_init(TRNG_Params *params);
520 
538 TRNG_Handle TRNG_open(uint_least8_t index, TRNG_Params *params);
539 
549 void TRNG_close(TRNG_Handle handle);
550 
588 int_fast16_t TRNG_control(TRNG_Handle handle, uint32_t cmd, void *args);
589 
609 int_fast16_t TRNG_generateEntropyLessThan(TRNG_Handle handle, CryptoKey *entropy, const uint8_t *upperBound);
610 
630 int_fast16_t TRNG_generateEntropyNonZeroLessThan(TRNG_Handle handle, CryptoKey *entropy, const uint8_t *upperBound);
631 
647 int_fast16_t TRNG_generateEntropy(TRNG_Handle handle, CryptoKey *entropy);
648 
649 
650 
651 
652 #ifdef __cplusplus
653 }
654 #endif
655 
656 #endif /* ti_drivers_TRNG__include */
int_fast16_t TRNG_control(TRNG_Handle handle, uint32_t cmd, void *args)
Function performs implementation specific features on a given TRNG_Handle.
TRNG_Handle TRNG_open(uint_least8_t index, TRNG_Params *params)
This function opens a given TRNG peripheral.
enum TRNG_ReturnBehavior_ TRNG_ReturnBehavior
The way in which TRNG function calls return after generating the requested entropy.
struct TRNG_Config_ * TRNG_Handle
A handle that is returned from a TRNG_open() call.
Definition: TRNG.h:397
The CryptoKey type is an opaque representation of a cryptographic key.
int_fast16_t TRNG_generateEntropy(TRNG_Handle handle, CryptoKey *entropy)
Generate a random number.
struct TRNG_Params_ TRNG_Params
TRNG Parameters.
CryptoKey datastructure.
Definition: CryptoKey.h:210
void * object
Definition: TRNG.h:450
struct TRNG_Config_ TRNG_Config
TRNG Global configuration.
void TRNG_close(TRNG_Handle handle)
Function to close a TRNG peripheral specified by the TRNG handle.
TRNG_ReturnBehavior_
The way in which TRNG function calls return after generating the requested entropy.
Definition: TRNG.h:420
int_fast16_t TRNG_generateEntropyNonZeroLessThan(TRNG_Handle handle, CryptoKey *entropy, const uint8_t *upperBound)
Generate a random number smaller than a number but greater than 0.
const TRNG_Params TRNG_defaultParams
Default TRNG_Params structure.
void TRNG_Params_init(TRNG_Params *params)
Function to initialize the TRNG_Params struct to its defaults.
void * custom
Definition: TRNG.h:485
void TRNG_init(void)
This function initializes the TRNG module.
TRNG Global configuration.
Definition: TRNG.h:448
Definition: TRNG.h:427
TRNG Parameters.
Definition: TRNG.h:479
Definition: TRNG.h:431
TRNG_CallbackFxn callbackFxn
Definition: TRNG.h:481
void(* TRNG_CallbackFxn)(TRNG_Handle handle, int_fast16_t returnValue, CryptoKey *entropy)
The definition of a callback function used by the TRNG driver when used in TRNG_RETURN_BEHAVIOR_CALLB...
Definition: TRNG.h:467
int_fast16_t TRNG_generateEntropyLessThan(TRNG_Handle handle, CryptoKey *entropy, const uint8_t *upperBound)
Generate a random number smaller than a number.
Definition: TRNG.h:421
void const * hwAttrs
Definition: TRNG.h:453
uint32_t timeout
Definition: TRNG.h:482
TRNG_ReturnBehavior returnBehavior
Definition: TRNG.h:480
Copyright 2018, Texas Instruments Incorporated