CryptoKey.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2023, 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  */
81 #ifndef ti_drivers_cryptoutils_cyptokey_CryptoKey__include
82 #define ti_drivers_cryptoutils_cyptokey_CryptoKey__include
83 
84 #include <stdint.h>
85 #include <stdbool.h>
86 
87 #ifdef __cplusplus
88 extern "C" {
89 #endif
90 
113 #define CryptoKey_STATUS_RESERVED (-32)
114 
128 #define CryptoKey_STATUS_SUCCESS (0)
129 
136 #define CryptoKey_STATUS_ERROR (-1)
137 
144 #define CryptoKey_STATUS_UNDEFINED_ENCODING (-2)
145 
150 /*
151  * CRYPTOKEY_HSM is being used to mask bit 6 which determines which accelerator to use.
152  * Any encoding that is ORed with CRYPTOKEY_HSM indicates that the HSM is the engine of choice for the operation
153  */
154 #define CRYPTOKEY_HSM 0x20U
155 
156 #define CRYPTOKEY_PLAINTEXT 0x02U
157 #define CRYPTOKEY_BLANK_PLAINTEXT 0x04U
158 #define CRYPTOKEY_KEYSTORE 0x08U
159 #define CRYPTOKEY_BLANK_KEYSTORE 0x10U
160 
165 typedef uint8_t CryptoKey_Encoding;
166 static const CryptoKey_Encoding CryptoKey_PLAINTEXT = CRYPTOKEY_PLAINTEXT;
167 static const CryptoKey_Encoding CryptoKey_BLANK_PLAINTEXT = CRYPTOKEY_BLANK_PLAINTEXT;
168 static const CryptoKey_Encoding CryptoKey_KEYSTORE = CRYPTOKEY_KEYSTORE;
169 static const CryptoKey_Encoding CryptoKey_BLANK_KEYSTORE = CRYPTOKEY_BLANK_KEYSTORE;
170 static const CryptoKey_Encoding CryptoKey_PLAINTEXT_HSM = CRYPTOKEY_PLAINTEXT | CRYPTOKEY_HSM;
171 
178 typedef struct
179 {
180  uint8_t *keyMaterial;
181  uint32_t keyLength;
183 
194 typedef struct
195 {
196  uint32_t keyLength;
197  uint32_t keyID;
200 
208 typedef struct
209 {
210  CryptoKey_Encoding encoding;
211  union
212  {
215  } u;
216 } CryptoKey;
217 
228 typedef struct CryptoKey_SecurityPolicy_ CryptoKey_SecurityPolicy;
229 
238 int_fast16_t CryptoKey_getCryptoKeyType(const CryptoKey *keyHandle, CryptoKey_Encoding *keyType);
239 
248 int_fast16_t CryptoKey_isBlank(const CryptoKey *keyHandle, bool *isBlank);
249 
260 
274 int_fast16_t CryptoKey_verifySecureInputKey(const CryptoKey *secureKey);
275 
289 int_fast16_t CryptoKey_verifySecureOutputKey(const CryptoKey *secureKey);
290 
308 int_fast16_t CryptoKey_copySecureInputKey(CryptoKey *dst, const CryptoKey **src);
309 
327 int_fast16_t CryptoKey_copySecureOutputKey(CryptoKey *dst, CryptoKey **src);
328 
329 #ifdef __cplusplus
330 }
331 #endif
332 
333 #endif /* ti_drivers_cryptoutils_cyptokey_CryptoKey__include */
CryptoKey_Plaintext plaintext
Definition: CryptoKey.h:213
static const CryptoKey_Encoding CryptoKey_KEYSTORE
Definition: CryptoKey.h:168
uint8_t CryptoKey_Encoding
List of the different types of CryptoKey. _HSM encodings are only available for select devices...
Definition: CryptoKey.h:165
#define CRYPTOKEY_HSM
Definition: CryptoKey.h:154
#define CRYPTOKEY_KEYSTORE
Definition: CryptoKey.h:158
#define CRYPTOKEY_BLANK_PLAINTEXT
Definition: CryptoKey.h:157
static const CryptoKey_Encoding CryptoKey_BLANK_PLAINTEXT
Definition: CryptoKey.h:167
CryptoKey datastructure.
Definition: CryptoKey.h:208
int_fast16_t CryptoKey_copySecureOutputKey(CryptoKey *dst, CryptoKey **src)
Function to copy and verify a secure output CryptoKey.
Key store CryptoKey datastructure.
Definition: CryptoKey.h:194
uint32_t keyID
Definition: CryptoKey.h:197
int_fast16_t CryptoKey_verifySecureOutputKey(const CryptoKey *secureKey)
Function to verify a secure output CryptoKey.
int_fast16_t CryptoKey_getCryptoKeyType(const CryptoKey *keyHandle, CryptoKey_Encoding *keyType)
Gets the key type of the CryptoKey.
static const CryptoKey_Encoding CryptoKey_PLAINTEXT
Definition: CryptoKey.h:166
uint32_t keyLength
Definition: CryptoKey.h:196
static const CryptoKey_Encoding CryptoKey_PLAINTEXT_HSM
Definition: CryptoKey.h:170
#define CRYPTOKEY_BLANK_KEYSTORE
Definition: CryptoKey.h:159
int_fast16_t CryptoKey_isBlank(const CryptoKey *keyHandle, bool *isBlank)
Whether the CryptoKey is &#39;blank&#39; or represents valid keying material.
int_fast16_t CryptoKey_verifySecureInputKey(const CryptoKey *secureKey)
Function to verify a secure CryptoKey.
#define CRYPTOKEY_PLAINTEXT
Definition: CryptoKey.h:156
CryptoKey_Encoding encoding
Definition: CryptoKey.h:210
int_fast16_t CryptoKey_copySecureInputKey(CryptoKey *dst, const CryptoKey **src)
Function to copy and verify a secure input CryptoKey.
Plaintext CryptoKey datastructure.
Definition: CryptoKey.h:178
int_fast16_t CryptoKey_initSecurityPolicy(CryptoKey_SecurityPolicy *policy)
Function to initialize the CryptoKey_SecurityPolicy struct to its defaults.
void * keyAttributes
Definition: CryptoKey.h:198
CryptoKey_KeyStore keyStore
Definition: CryptoKey.h:214
struct CryptoKey_SecurityPolicy_ CryptoKey_SecurityPolicy
Structure that specifies the restrictions on a CryptoKey.
Definition: CryptoKey.h:228
static const CryptoKey_Encoding CryptoKey_BLANK_KEYSTORE
Definition: CryptoKey.h:169
uint8_t * keyMaterial
Definition: CryptoKey.h:180
uint32_t keyLength
Definition: CryptoKey.h:181
© Copyright 1995-2024, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale