SEFile
Userspace drivers to manage a secure filesystem
 All Data Structures Files Functions Variables Typedefs Enumerator Macros Groups
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];
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
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.c:1621
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.c:1268
int32_t B5_CmacAes256_Reset(B5_tCmacAesCtx *ctx)
Reset the current CMAC-AES context.
Definition: aes256.c:1725
int32_t B5_Aes256_SetIV(B5_tAesCtx *ctx, const uint8_t *IV)
Set the IV for the current AES context.
Definition: aes256.c:1245
int32_t B5_CmacAes256_Finit(B5_tCmacAesCtx *ctx, uint8_t *rSignature)
De-initialize the current CMAC-AES context.
Definition: aes256.c:1682
#define B5_AES_BLK_SIZE
Definition: aes256.h:46
Definition: aes256.h:179
int32_t B5_Aes256_Finit(B5_tAesCtx *ctx)
De-initialize the current AES context.
Definition: aes256.c:1455
Definition: aes256.h:75
uint8_t Nr
Definition: aes256.h:77
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.c:1473
int32_t B5_CmacAes256_Init(B5_tCmacAesCtx *ctx, const uint8_t *Key, int16_t keySize)
Initialize the CMAC-AES context.
Definition: aes256.c:1565
int32_t B5_Aes256_Init(B5_tAesCtx *ctx, const uint8_t *Key, int16_t keySize, uint8_t aesMode)
Initialize the AES context.
Definition: aes256.c:1193
uint8_t mode
Definition: aes256.h:79