AM243x 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 
131 typedef int32_t (*Crypto_AesSetKeyEncFxn)(Crypto_AesContext *ctx);
132 typedef int32_t (*Crypto_AesSetKeyDecFxn)(Crypto_AesContext *ctx);
133 typedef int32_t (*Crypto_AesCbcFxn)(Crypto_AesContext *ctx, const uint8_t *input, uint32_t inputLength, uint8_t *output );
134 
136 typedef int32_t (*Crypto_CmacSetUpFxn)(Crypto_AesContext *ctx);
137 typedef int32_t (*Crypto_CmacStartFxn)(Crypto_AesContext *ctx);
138 typedef int32_t (*Crypto_CmacUpdateFxn)(Crypto_AesContext *ctx, const uint8_t *input, uint32_t ilen);
139 typedef int32_t (*Crypto_CmacFinishFxn)(Crypto_AesContext *ctx, uint8_t *output);
140 typedef int32_t (*Crypto_CmacSingleShotFxn)(Crypto_AesContext *ctx, const uint8_t *input, uint32_t ilen, uint8_t *output);
141 
143 typedef struct Crypto_AesCommonFxns_s
144 {
150 
152 typedef struct Crypto_AesCbcFxns_s
153 {
161 
163 typedef struct Crypto_AesCmacFxns_s
164 {
176 
178 typedef struct Crypto_AesFxns_s
179 {
187 
190 {
195  uintptr_t rsv[70U];
197 };
198 
205 typedef struct
206 {
210 
212 extern Crypto_AesConfig gCryptoAesConfig[CRYPTO_NUM_TYPE];
213 
214 /* ========================================================================== */
215 /* Function Declarations */
216 /* ========================================================================== */
217 
227 
234 Crypto_AesHandle Crypto_aesOpen(Crypto_AesContext *ctx, const Crypto_AesParams *params);
235 
245 
255 
265 
282 int32_t Crypto_aesCbc(Crypto_AesHandle handle, const uint8_t *input, uint32_t ilen, uint8_t *output );
283 
293 
303 
316 int32_t Crypto_cmacUpdate(Crypto_AesHandle handle, const uint8_t *input, uint32_t ilen);
317 
328 int32_t Crypto_cmacFinish(Crypto_AesHandle handle, uint8_t *output);
329 
345 int32_t Crypto_cmacSingleShot(Crypto_AesHandle handle, const uint8_t *input, uint32_t ilen, uint8_t *output);
346 
347 /* ========================================================================== */
348 /* Static Function Definitions */
349 /* ========================================================================== */
350 
351 /* None */
352 
353 /* ========================================================================== */
354 /* Internal/Private Structure Declarations */
355 /* ========================================================================== */
356 
357 /* None */
358 
359 #ifdef __cplusplus
360 }
361 #endif
362 
363 #endif /* CRYPTO_AES_H_ */
364 
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)
aes cbc callback functions declarations
Definition: crypto_aes.h:131
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_CmacFinishFxn
int32_t(* Crypto_CmacFinishFxn)(Crypto_AesContext *ctx, uint8_t *output)
Definition: crypto_aes.h:139
Crypto_AesCommonFxns::openFxn
Crypto_AesOpenFxn openFxn
Definition: crypto_aes.h:145
Crypto_AesParams::algoType
uint32_t algoType
Definition: crypto_aes.h:114
Crypto_AesOpenFxn
int32_t(* Crypto_AesOpenFxn)(Crypto_AesContext *ctx, const Crypto_AesParams *params)
common callback functions declarations
Definition: crypto_aes.h:127
Crypto_CmacSingleShotFxn
int32_t(* Crypto_CmacSingleShotFxn)(Crypto_AesContext *ctx, const uint8_t *input, uint32_t ilen, uint8_t *output)
Definition: crypto_aes.h:140
Crypto_AesConfig::fxns
Crypto_AesFxns * fxns
Definition: crypto_aes.h:207
Crypto_AesParams::type
uint32_t type
Definition: crypto_aes.h:122
Crypto_CmacUpdateFxn
int32_t(* Crypto_CmacUpdateFxn)(Crypto_AesContext *ctx, const uint8_t *input, uint32_t ilen)
Definition: crypto_aes.h:138
Crypto_AesContext_s
CRYPTO AES driver context.
Definition: crypto_aes.h:190
Crypto_AesCbcFxns::setKeyDecFxn
Crypto_AesSetKeyDecFxn setKeyDecFxn
Definition: crypto_aes.h:156
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 Cipher Block Chaining (AES-CBC) operation,...
Crypto_AesFxns
Driver implementation callbacks.
Definition: crypto_aes.h:179
Crypto_aesOpen
Crypto_AesHandle Crypto_aesOpen(Crypto_AesContext *ctx, const Crypto_AesParams *params)
This function gives the configuration based on type.
Crypto_AesCommonFxns
Driver implementation callbacks.
Definition: crypto_aes.h:144
Crypto_AesSetKeyDecFxn
int32_t(* Crypto_AesSetKeyDecFxn)(Crypto_AesContext *ctx)
Definition: crypto_aes.h:132
Crypto_AesContext_s::rsv
uintptr_t rsv[70U]
Definition: crypto_aes.h:195
Crypto_CmacStartFxn
int32_t(* Crypto_CmacStartFxn)(Crypto_AesContext *ctx)
Definition: crypto_aes.h:137
Crypto_AesFxns::commonFxns
Crypto_AesCommonFxns * commonFxns
Definition: crypto_aes.h:180
gCryptoAesConfig
Crypto_AesConfig gCryptoAesConfig[CRYPTO_NUM_TYPE]
Externally defined AES driver configuration array.
Crypto_AesCbcFxns::cbcFxn
Crypto_AesCbcFxn cbcFxn
Definition: crypto_aes.h:158
Crypto_AesFxns::cbcFxns
Crypto_AesCbcFxns * cbcFxns
Definition: crypto_aes.h:182
Crypto_AesCbcFxn
int32_t(* Crypto_AesCbcFxn)(Crypto_AesContext *ctx, const uint8_t *input, uint32_t inputLength, uint8_t *output)
Definition: crypto_aes.h:133
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:153
Crypto_AesCbcFxns::setKeyEncFxn
Crypto_AesSetKeyEncFxn setKeyEncFxn
Definition: crypto_aes.h:154
Crypto_AesParams_init
void Crypto_AesParams_init(Crypto_AesParams *params)
Set default parameters in the Crypto_AesParams structure.
Crypto_cmacSetup
int32_t Crypto_cmacSetup(Crypto_AesHandle handle)
This function prepares a cipher context for use with the given cipher primitive.
Crypto_AesCmacFxns::finishFxn
Crypto_CmacFinishFxn finishFxn
Definition: crypto_aes.h:171
Crypto_AesParams
Parameters passed during Crypto_aesOpen()
Definition: crypto_aes.h:111
Crypto_AesCmacFxns::updateFxn
Crypto_CmacUpdateFxn updateFxn
Definition: crypto_aes.h:169
Crypto_aesClose
int32_t Crypto_aesClose(Crypto_AesHandle handle)
This function clears a Advance Encryption Standard (AES) context.
Crypto_AesContext_s::fxns
Crypto_AesFxns * fxns
Definition: crypto_aes.h:193
Crypto_AesCmacFxns::singleShotFxn
Crypto_CmacSingleShotFxn singleShotFxn
Definition: crypto_aes.h:173
Crypto_CmacSetUpFxn
int32_t(* Crypto_CmacSetUpFxn)(Crypto_AesContext *ctx)
aes cmac callback functions declarations
Definition: crypto_aes.h:136
Crypto_cmacUpdate
int32_t Crypto_cmacUpdate(Crypto_AesHandle handle, const uint8_t *input, uint32_t ilen)
This function feeds an input buffer into an ongoing CMAC computation.
Crypto_AesContext_s::params
Crypto_AesParams params
Definition: crypto_aes.h:191
Crypto_cmacSingleShot
int32_t Crypto_cmacSingleShot(Crypto_AesHandle handle, const uint8_t *input, uint32_t ilen, uint8_t *output)
This function calculates the Advance Encryption Standard Cipher-based Message Authentication Code (AE...
Crypto_AesParams::aesMode
uint32_t aesMode
Definition: crypto_aes.h:112
Crypto_AesCmacFxns::startFxn
Crypto_CmacStartFxn startFxn
Definition: crypto_aes.h:167
Crypto_cmacStarts
int32_t Crypto_cmacStarts(Crypto_AesHandle handle)
This function sets the CMAC key, and prepares to authenticate the input data.
Crypto_AesConfig
CRYPTO AES global configuration array.
Definition: crypto_aes.h:206
Crypto_AesCmacFxns
Driver implementation callbacks.
Definition: crypto_aes.h:164
Crypto_AesCommonFxns::closeFxn
Crypto_AesCloseFxn closeFxn
Definition: crypto_aes.h:147
Crypto_aesSetKeyDec
int32_t Crypto_aesSetKeyDec(Crypto_AesHandle handle)
This function sets the Advance Encryption Standard (AES) decryption key.
Crypto_AesFxns::cmacFxns
Crypto_AesCmacFxns * cmacFxns
Definition: crypto_aes.h:184
Crypto_cmacFinish
int32_t Crypto_cmacFinish(Crypto_AesHandle handle, uint8_t *output)
This function finishes the CMAC operation, and writes the result to the output buffer.
Crypto_AesParams::keySizeInBits
uint32_t keySizeInBits
Definition: crypto_aes.h:120
Crypto_AesCmacFxns::setUpFxn
Crypto_CmacSetUpFxn setUpFxn
Definition: crypto_aes.h:165
CRYPTO_AES_KEY_LENGTH
#define CRYPTO_AES_KEY_LENGTH
key buffer length, min 16 bytes and max 32 bytes
Definition: crypto_aes.h:95