AM64x MCU+ SDK  08.01.00
crypto_aes.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018-2021 Texas Instruments Incorporated
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * 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
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
41 #ifndef CRYPTO_AES_H_
42 #define CRYPTO_AES_H_
43 
44 /* ========================================================================== */
45 /* Include Files */
46 /* ========================================================================== */
47 
48 #include <stdint.h>
49 #include <security/crypto.h>
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
55 /* ========================================================================== */
56 /* Macros & Typedefs */
57 /* ========================================================================== */
58 
65 #define CRYPTO_AES_DECRYPT (0U)
66 
67 #define CRYPTO_AES_ENCRYPT (1U)
68 
69 #define CRYPTO_AES_CMAC (2U)
70 
78 #define CRYPTO_AES_CBC_128 (0U)
79 
80 #define CRYPTO_AES_CBC_192 (1U)
81 
82 #define CRYPTO_AES_CBC_256 (2U)
83 
84 #define CRYPTO_AES_CMAC_128 (3U)
85 
86 #define CRYPTO_AES_CMAC_192 (4U)
87 
88 #define CRYPTO_AES_CMAC_256 (5U)
89 
92 #define CRYPTO_AES_IV_LENGTH (16U)
93 
95 #define CRYPTO_AES_KEY_LENGTH (32U)
96 
98 typedef void *Crypto_AesHandle;
99 
101 typedef struct Crypto_AesContext_s Crypto_AesContext;
102 
103 /* ========================================================================== */
104 /* Structure Declarations */
105 /* ========================================================================== */
106 
110 typedef struct Crypto_AesParams_s
111 {
112  uint32_t aesMode;
114  uint32_t algoType;
116  uint8_t iv[CRYPTO_AES_IV_LENGTH];
118  uint8_t key[CRYPTO_AES_KEY_LENGTH];
120  uint32_t keySizeInBits;
122  uint32_t type;
125 
127 typedef int32_t (*Crypto_AesOpenFxn)(Crypto_AesContext *ctx, const Crypto_AesParams *params);
128 typedef int32_t (*Crypto_AesCloseFxn)(Crypto_AesContext *ctx);
129 typedef int32_t (*Crypto_AesSetKeyEncFxn)(Crypto_AesContext *ctx);
130 typedef int32_t (*Crypto_AesSetKeyDecFxn)(Crypto_AesContext *ctx);
131 typedef int32_t (*Crypto_AesCbcFxn)(Crypto_AesContext *ctx, const uint8_t *input, uint32_t inputLength, uint8_t *output );
132 
134 typedef struct Crypto_AesCbcFxns_s
135 {
147 
150 {
155  uintptr_t rsv[70U];
157 };
158 
165 typedef struct
166 {
170 
172 extern Crypto_AesConfig gCryptoAesConfig[CRYPTO_NUM_TYPE];
173 
174 /* ========================================================================== */
175 /* Function Declarations */
176 /* ========================================================================== */
177 
187 
194 Crypto_AesHandle Crypto_aesOpen(Crypto_AesContext *ctx, const Crypto_AesParams *params);
195 
205 
215 
225 
242 int32_t Crypto_aesCbc(Crypto_AesHandle handle, const uint8_t *input, uint32_t ilen, uint8_t *output );
243 
244 /* ========================================================================== */
245 /* Static Function Definitions */
246 /* ========================================================================== */
247 
248 /* None */
249 
250 /* ========================================================================== */
251 /* Internal/Private Structure Declarations */
252 /* ========================================================================== */
253 
254 /* None */
255 
256 #ifdef __cplusplus
257 }
258 #endif
259 
260 #endif /* CRYPTO_AES_H_ */
261 
CRYPTO_AES_IV_LENGTH
#define CRYPTO_AES_IV_LENGTH
IV buffer length should be 16 bytes.
Definition: crypto_aes.h:92
Crypto_AesSetKeyEncFxn
int32_t(* Crypto_AesSetKeyEncFxn)(Crypto_AesContext *ctx)
Definition: crypto_aes.h:129
Crypto_aesSetKeyEnc
int32_t Crypto_aesSetKeyEnc(Crypto_AesHandle handle)
This function sets the Advance Encryption Standard (AES) encryption key.
Crypto_AesCloseFxn
int32_t(* Crypto_AesCloseFxn)(Crypto_AesContext *ctx)
Definition: crypto_aes.h:128
Crypto_AesParams::algoType
uint32_t algoType
Definition: crypto_aes.h:114
Crypto_AesOpenFxn
int32_t(* Crypto_AesOpenFxn)(Crypto_AesContext *ctx, const Crypto_AesParams *params)
callback functions declarations
Definition: crypto_aes.h:127
Crypto_AesParams::type
uint32_t type
Definition: crypto_aes.h:122
Crypto_AesContext_s
CRYPTO AES driver context.
Definition: crypto_aes.h:150
Crypto_AesCbcFxns::setKeyDecFxn
Crypto_AesSetKeyDecFxn setKeyDecFxn
Definition: crypto_aes.h:142
Crypto_aesCbc
int32_t Crypto_aesCbc(Crypto_AesHandle handle, const uint8_t *input, uint32_t ilen, uint8_t *output)
This function finishes the Advance Encryption Standard (AES) operation, and writes the result to the ...
Crypto_aesOpen
Crypto_AesHandle Crypto_aesOpen(Crypto_AesContext *ctx, const Crypto_AesParams *params)
This function gives the configuration based on type.
Crypto_AesCbcFxns::closeFxn
Crypto_AesCloseFxn closeFxn
Definition: crypto_aes.h:138
Crypto_AesSetKeyDecFxn
int32_t(* Crypto_AesSetKeyDecFxn)(Crypto_AesContext *ctx)
Definition: crypto_aes.h:130
Crypto_AesCbcFxns::openFxn
Crypto_AesOpenFxn openFxn
Definition: crypto_aes.h:136
Crypto_AesContext_s::rsv
uintptr_t rsv[70U]
Definition: crypto_aes.h:155
Crypto_AesContext_s::fxns
Crypto_AesCbcFxns * fxns
Definition: crypto_aes.h:153
gCryptoAesConfig
Crypto_AesConfig gCryptoAesConfig[CRYPTO_NUM_TYPE]
Externally defined AES driver configuration array.
Crypto_AesCbcFxns::cbcFxn
Crypto_AesCbcFxn cbcFxn
Definition: crypto_aes.h:144
Crypto_AesCbcFxn
int32_t(* Crypto_AesCbcFxn)(Crypto_AesContext *ctx, const uint8_t *input, uint32_t inputLength, uint8_t *output)
Definition: crypto_aes.h:131
Crypto_AesHandle
void * Crypto_AesHandle
Handle to the Crypto AES driver returned by Crypto_aesOpen()
Definition: crypto_aes.h:98
Crypto_AesCbcFxns
Driver implementation callbacks.
Definition: crypto_aes.h:135
Crypto_AesCbcFxns::setKeyEncFxn
Crypto_AesSetKeyEncFxn setKeyEncFxn
Definition: crypto_aes.h:140
Crypto_AesParams_init
void Crypto_AesParams_init(Crypto_AesParams *params)
Set default parameters in the Crypto_AesParams structure.
Crypto_AesParams
Parameters passed during Crypto_aesOpen()
Definition: crypto_aes.h:111
Crypto_aesClose
int32_t Crypto_aesClose(Crypto_AesHandle handle)
This function clears a Advance Encryption Standard (AES) context.
Crypto_AesContext_s::params
Crypto_AesParams params
Definition: crypto_aes.h:151
Crypto_AesParams::aesMode
uint32_t aesMode
Definition: crypto_aes.h:112
Crypto_AesConfig::fxns
Crypto_AesCbcFxns * fxns
Definition: crypto_aes.h:167
Crypto_AesConfig
CRYPTO AES global configuration array.
Definition: crypto_aes.h:166
Crypto_aesSetKeyDec
int32_t Crypto_aesSetKeyDec(Crypto_AesHandle handle)
This function sets the Advance Encryption Standard (AES) decryption key.
Crypto_AesParams::keySizeInBits
uint32_t keySizeInBits
Definition: crypto_aes.h:120
CRYPTO_AES_KEY_LENGTH
#define CRYPTO_AES_KEY_LENGTH
key buffer length, min 16 bytes and max 32 bytes
Definition: crypto_aes.h:95