TI BLE5-Stack API Documentation  2.00.04.00
tof_security.h
Go to the documentation of this file.
1 /******************************************************************************
2 
3  @file tof_security.h
4 
5  @brief This file contains methods to enable/disable and control TOF
6  Group: WCS, BTS
7  $Target Device: DEVICES $
8 
9  ******************************************************************************
10  $License: BSD3 2018 $
11  ******************************************************************************
12  $Release Name: PACKAGE NAME $
13  $Release Date: PACKAGE RELEASE DATE $
14  *****************************************************************************/
15 
25 #ifndef TOF_SECURITY_H_
26 #define TOF_SECURITY_H_
27 
28 #ifdef __cplusplus
29 extern "C"
30 {
31 #endif
32 
33 /*********************************************************************
34  * INCLUDES
35  */
36 
37 #include <ti/drivers/TRNG.h>
38 #include <ti/drivers/AESECB.h>
39 
40 #include <stdint.h>
41 
42 /*********************************************************************
43  * MACROS
44  */
46 #define NUM_ELEMENTS(x) (sizeof(x)/sizeof(x[0]))
47 
48 /*********************************************************************
49  * CONSTANTS
50  */
51 
52 // CTR-DRBG definitions
53 #define CTR_DRBG_BLOCKLEN 16
54 #define CTR_DRBG_SEEDLEN (CTR_DRBG_BLOCKLEN + CTR_DRBG_BLOCKLEN)
55 #define CTR_DRBG_INST_FLAG 0xAA
56 
57 #define TOF_SEC_FILL_BOTH_BUFFS 0x01
58 #define TOF_SEC_FILL_1ST_BUFF 0x02
59 #define TOF_SEC_FILL_2ND_BUFF 0x03
60 
61 #define TOF_SEC_SYNCWORD_SIZE 8
62 
63 #define TOF_SEC_DBL_BUFF_SIZE 16
64 
65 #define ENC_KEY_LEN 16
66 #define AES_BLOCK_LEN 16
67 
68 /*********************************************************************
69  * TYPEDEFS
70  */
71 
76 typedef enum
78 {
81 } tofSecMode_e;
82 
84 typedef enum
85 {
92 
94 typedef struct
95 {
96  uint8_t key[CTR_DRBG_BLOCKLEN];
97  uint8_t v[CTR_DRBG_BLOCKLEN];
98  uint8_t instantiatedFlag;
100 
102 typedef struct
103 {
105  uint16_t syncWordSize;
108 
110 typedef struct
111 {
112  // Counting Deterministic Random Bit Generator
114 
116 
117  // Sync Words
119  uint8_t *pSyncWordBuffer1;
120  uint8_t *pSyncWordBuffer2;
121 
122  //Seed
123  uint8_t seed[CTR_DRBG_SEEDLEN];
124 
125  //TRNG
126  TRNG_Handle trngHandle;
127 
128  // Crypto
129  AESECB_Handle encHandleECB;
130  AESECB_Params encParamsECB;
131  AESECB_Operation operationECB;
132  uint8_t enckey[ENC_KEY_LEN];
133  CryptoKey cryptoKey;
134 
135 
137 
140 /*********************************************************************
141  * PUBLIC FUNCTIONS
142  */
143 
167 int TOFSecurity_open(tofSecHandle_t *tofSecHandle, tofSecCfgPrms_t *tofSecCfgPrms);
168 
180 int TOFSecurity_close(tofSecHandle_t *tofSecHandle);
181 
195 int TOFSecurity_genSeed(tofSecHandle_t *tofSecHandle);
196 
212 int TOFSecurity_genSyncWords(tofSecHandle_t *tofSecHandle, uint8_t bufferToFill);
213 
229 int TOFSecurity_setSeed(tofSecHandle_t *tofSecHandle, uint8_t *newSeed);
230 
231 /*********************************************************************
232 *********************************************************************/
233 
234 #ifdef __cplusplus
235 }
236 #endif
237 
238 #endif // TOF_SECURITY_H_
239 
ToF Security Handle.
Definition: tof_security.h:110
Invalid parameters fail.
Definition: tof_security.h:90
#define ENC_KEY_LEN
Encryption Key size in bytes.
Definition: tof_security.h:65
TRNG_Handle trngHandle
TRNG Handle.
Definition: tof_security.h:126
uint8_t * pSyncWordBuffer1
Pointer to the sync word buffer, used in both single and double buffer mode.
Definition: tof_security.h:119
int TOFSecurity_genSyncWords(tofSecHandle_t *tofSecHandle, uint8_t bufferToFill)
Will fill each Sync Word Buffer with numOfSyncWordsPerBuffer Sync Words.
Seed Generation fail.
Definition: tof_security.h:87
ctr DRBG State
Definition: tof_security.h:94
#define CTR_DRBG_SEEDLEN
Length of CTR DRBG Seed.
Definition: tof_security.h:54
Single Buffer.
Definition: tof_security.h:79
uint16_t syncWordSize
In bytes. Defaults to 8.
Definition: tof_security.h:105
AES fail.
Definition: tof_security.h:88
Allocation fail.
Definition: tof_security.h:89
int TOFSecurity_close(tofSecHandle_t *tofSecHandle)
This function is used to close ToF Security and free buffers.
uint8_t * pSyncWordBuffer2
Pointer to the second sync word buffer, used in double buffer mode only.
Definition: tof_security.h:120
AESECB_Params encParamsECB
AESECB Encryption parameters.
Definition: tof_security.h:130
uint8_t bUseDoubleBuffer
Defaults to false.
Definition: tof_security.h:104
AESECB_Handle encHandleECB
AESECB Encryption Handle.
Definition: tof_security.h:129
uint8_t instantiatedFlag
Variable used for ctr DRBG State.
Definition: tof_security.h:98
Double Buffer.
Definition: tof_security.h:80
Success.
Definition: tof_security.h:86
#define CTR_DRBG_BLOCKLEN
Length of CTR DRBG Block.
Definition: tof_security.h:53
tofSecCfgPrms_t tofSecCfgParams
ToF Security Configuration Parameters.
Definition: tof_security.h:115
ctrDrbgState_t ctrDrbgState
ctr DRBG State
Definition: tof_security.h:113
int TOFSecurity_open(tofSecHandle_t *tofSecHandle, tofSecCfgPrms_t *tofSecCfgPrms)
This function is used to open the tof security module (to default or to presets defined in tofSecCfgP...
int TOFSecurity_genSeed(tofSecHandle_t *tofSecHandle)
use TRNG HW module to generate a true 128-bit random seed
ToF Security Configuration Parameters.
Definition: tof_security.h:102
int TOFSecurity_setSeed(tofSecHandle_t *tofSecHandle, uint8_t *newSeed)
This function is used to reseed the ctr drbg.
CryptoKey cryptoKey
AES Encryption Crypto key.
Definition: tof_security.h:133
tofSecErrRes_t
ToF Security Error Result.
Definition: tof_security.h:84
uint16_t totalNumOfSyncWords
Defaults to 64.
Definition: tof_security.h:106
tofSecMode_e
ToF Security Mode.
Definition: tof_security.h:77
uint16_t numOfSyncWordsPerBuffer
Length of double buffer, both buffers must be equal length. The number of bursts in double buffer mod...
Definition: tof_security.h:118
AESECB_Operation operationECB
AESECB Encryption operation parameters.
Definition: tof_security.h:131
© Copyright 1995-2019, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale