SEcube open-source SDK
aes256.h
1 #pragma once
2 /* LICENSE */
3 
11 #include <stdint.h>
12 #include <string.h>
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 
23 #define B5_AES256_RES_OK ( 0)
25 #define B5_AES256_RES_INVALID_CONTEXT (-1)
26 #define B5_AES256_RES_CANNOT_ALLOCATE_CONTEXT (-2)
27 #define B5_AES256_RES_INVALID_KEY_SIZE (-3)
28 #define B5_AES256_RES_INVALID_ARGUMENT (-4)
29 #define B5_AES256_RES_INVALID_MODE (-5)
30 
41 #define B5_AES_256 32
43 #define B5_AES_192 24
44 #define B5_AES_128 16
45 #define B5_AES_IV_SIZE 16
46 #define B5_AES_BLK_SIZE 16
47 
55 #define B5_AES256_OFB 1
57 #define B5_AES256_ECB_ENC 2
58 #define B5_AES256_ECB_DEC 3
59 #define B5_AES256_CBC_ENC 4
60 #define B5_AES256_CBC_DEC 5
61 #define B5_AES256_CFB_ENC 6
62 #define B5_AES256_CFB_DEC 7
63 #define B5_AES256_CTR 8
64 
74 typedef struct {
76  uint32_t rk[4*(14 + 1)];
77  uint8_t Nr;
78  uint8_t InitVector[16];
79  uint8_t mode;
80  uint32_t const *Te0;
81  uint32_t const *Te1;
82  uint32_t const *Te2;
83  uint32_t const *Te3;
84  uint32_t const *Te4;
85  uint32_t const *Td0;
86  uint32_t const *Td1;
87  uint32_t const *Td2;
88  uint32_t const *Td3;
89  uint32_t const *Td4;
90 } B5_tAesCtx;
92 
99 
110 int32_t B5_Aes256_Init (B5_tAesCtx *ctx, const uint8_t *Key, int16_t keySize, uint8_t aesMode);
111 
119 int32_t B5_Aes256_SetIV (B5_tAesCtx *ctx, const uint8_t *IV);
120 
130 int32_t B5_Aes256_Update (B5_tAesCtx *ctx, uint8_t *encData, uint8_t *clrData, int16_t nBlk);
131 
138 int32_t B5_Aes256_Finit (B5_tAesCtx *ctx);
139 
141 
151 #define B5_CMAC_AES_256 32
153 #define B5_CMAC_AES_192 24
154 #define B5_CMAC_AES_128 16
155 #define B5_CMAC_AES_BLK_SIZE 16
156 
164 #define B5_CMAC_AES256_RES_OK ( 0)
166 #define B5_CMAC_AES256_RES_INVALID_CONTEXT (-1)
167 #define B5_CMAC_AES256_RES_CANNOT_ALLOCATE_CONTEXT (-2)
168 #define B5_CMAC_AES256_RES_INVALID_KEY_SIZE (-3)
169 #define B5_CMAC_AES256_RES_INVALID_ARGUMENT (-4)
170 
178 typedef struct {
180  B5_tAesCtx aesCtx;
181 
182  uint8_t K1[32];
183  uint8_t K2[32];
184 
185  uint8_t tmpBlk[B5_AES_BLK_SIZE];
186  uint8_t tmpBlkLen;
187 
188  uint8_t C[B5_AES_BLK_SIZE];
189 } B5_tCmacAesCtx;
191 
199 
208 int32_t B5_CmacAes256_Init (B5_tCmacAesCtx *ctx, const uint8_t *Key, int16_t keySize);
209 
218 int32_t B5_CmacAes256_Update (B5_tCmacAesCtx *ctx, const uint8_t *data, int32_t dataLen);
219 
227 int32_t B5_CmacAes256_Finit (B5_tCmacAesCtx *ctx, uint8_t *rSignature);
228 
235 int32_t B5_CmacAes256_Reset (B5_tCmacAesCtx *ctx);
236 
247 int32_t B5_CmacAes256_Sign (const uint8_t *data, int32_t dataLen, const uint8_t *Key, int16_t keySize, uint8_t *rSignature);
248 
250 
254 #ifdef __cplusplus
255 }
256 #endif
B5_Aes256_Update
int32_t B5_Aes256_Update(B5_tAesCtx *ctx, uint8_t *encData, uint8_t *clrData, int16_t nBlk)
Encrypt/Decrypt data based on the status of current AES context.
Definition: aes256.cpp:1268
B5_CmacAes256_Update
int32_t B5_CmacAes256_Update(B5_tCmacAesCtx *ctx, const uint8_t *data, int32_t dataLen)
Compute the CMAC-AES algorithm on input data depending on the current status of the CMAC-AES context.
Definition: aes256.cpp:1621
B5_AES256_OFB
#define B5_AES256_OFB
Definition: aes256.h:56
B5_AES_256
#define B5_AES_256
Definition: aes256.h:42
B5_AES256_CBC_ENC
#define B5_AES256_CBC_ENC
Definition: aes256.h:59
B5_AES256_CBC_DEC
#define B5_AES256_CBC_DEC
Definition: aes256.h:60
B5_AES256_ECB_DEC
#define B5_AES256_ECB_DEC
Definition: aes256.h:58
B5_AES_128
#define B5_AES_128
Definition: aes256.h:44
B5_CmacAes256_Init
int32_t B5_CmacAes256_Init(B5_tCmacAesCtx *ctx, const uint8_t *Key, int16_t keySize)
Initialize the CMAC-AES context.
Definition: aes256.cpp:1565
B5_AES256_CFB_DEC
#define B5_AES256_CFB_DEC
Definition: aes256.h:62
B5_Aes256_SetIV
int32_t B5_Aes256_SetIV(B5_tAesCtx *ctx, const uint8_t *IV)
Set the IV for the current AES context.
Definition: aes256.cpp:1245
B5_AES_IV_SIZE
#define B5_AES_IV_SIZE
Definition: aes256.h:45
B5_AES256_ECB_ENC
#define B5_AES256_ECB_ENC
Definition: aes256.h:57
B5_CmacAes256_Reset
int32_t B5_CmacAes256_Reset(B5_tCmacAesCtx *ctx)
Reset the current CMAC-AES context.
Definition: aes256.cpp:1728
B5_AES_192
#define B5_AES_192
Definition: aes256.h:43
B5_CMAC_AES_128
#define B5_CMAC_AES_128
Definition: aes256.h:154
B5_CmacAes256_Sign
int32_t B5_CmacAes256_Sign(const uint8_t *data, int32_t dataLen, const uint8_t *Key, int16_t keySize, uint8_t *rSignature)
Compute the signature through the CMAC-AES algorithm.
Definition: aes256.cpp:1473
B5_AES_BLK_SIZE
#define B5_AES_BLK_SIZE
Definition: aes256.h:46
B5_Aes256_Finit
int32_t B5_Aes256_Finit(B5_tAesCtx *ctx)
De-initialize the current AES context.
Definition: aes256.cpp:1455
B5_CMAC_AES_256
#define B5_CMAC_AES_256
Definition: aes256.h:152
B5_Aes256_Init
int32_t B5_Aes256_Init(B5_tAesCtx *ctx, const uint8_t *Key, int16_t keySize, uint8_t aesMode)
Initialize the AES context.
Definition: aes256.cpp:1193
B5_AES256_CTR
#define B5_AES256_CTR
Definition: aes256.h:63
B5_AES256_CFB_ENC
#define B5_AES256_CFB_ENC
Definition: aes256.h:61
B5_CmacAes256_Finit
int32_t B5_CmacAes256_Finit(B5_tCmacAesCtx *ctx, uint8_t *rSignature)
De-initialize the current CMAC-AES context.
Definition: aes256.cpp:1682
B5_CMAC_AES_192
#define B5_CMAC_AES_192
Definition: aes256.h:153