|
@@ -21,6 +21,7 @@ void __CheckFunc__(bool iFlag, const char* const file, int line, const uint8_t* |
|
|
// Some useful defines |
|
|
// Some useful defines |
|
|
#define MIN(a,b) a<b ? a : b |
|
|
#define MIN(a,b) a<b ? a : b |
|
|
#define ROUNDUP_16_BYTES(X) (((X+15)/16) * 16) |
|
|
#define ROUNDUP_16_BYTES(X) (((X+15)/16) * 16) |
|
|
|
|
|
#define AES_BLOCK_SIZE 16 |
|
|
|
|
|
|
|
|
#define OP_CHECK(exp) \ |
|
|
#define OP_CHECK(exp) \ |
|
|
do { \ |
|
|
do { \ |
|
@@ -47,6 +48,28 @@ typedef enum { |
|
|
kPadding_PKCS7 |
|
|
kPadding_PKCS7 |
|
|
} PaddingType; |
|
|
} PaddingType; |
|
|
|
|
|
|
|
|
|
|
|
typedef struct CtrCtx_t { |
|
|
|
|
|
uint8_t nonce[8]; |
|
|
|
|
|
uint8_t counter[8]; |
|
|
|
|
|
uint8_t encrypted_counter[AES_BLOCK_SIZE]; |
|
|
|
|
|
} CtrCtx_t; |
|
|
|
|
|
|
|
|
|
|
|
typedef struct ModeCtx_t { |
|
|
|
|
|
uint8_t iv[AES_BLOCK_SIZE]; |
|
|
|
|
|
CtrCtx_t ctr; |
|
|
|
|
|
} ModeCtx_t; |
|
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- |
|
|
|
|
|
Structure for key passing |
|
|
|
|
|
-------------------------------------------------------------------------*/ |
|
|
|
|
|
typedef struct Key_t { |
|
|
|
|
|
uint8_t* key; |
|
|
|
|
|
size_t len; |
|
|
|
|
|
|
|
|
|
|
|
static void Init(Key_t* ctx); |
|
|
|
|
|
static void Free(Key_t* ctx); |
|
|
|
|
|
} Key_t; |
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- |
|
|
/* ------------------------------------------------------------------------- |
|
|
Struct used for symmetric encryption |
|
|
Struct used for symmetric encryption |
|
|
-------------------------------------------------------------------------*/ |
|
|
-------------------------------------------------------------------------*/ |
|
@@ -57,25 +80,18 @@ struct CryptoAttribs_t { |
|
|
size_t output_len; |
|
|
size_t output_len; |
|
|
uint8_t* iv; |
|
|
uint8_t* iv; |
|
|
size_t iv_len; |
|
|
size_t iv_len; |
|
|
|
|
|
uint64_t output_cursor; |
|
|
|
|
|
|
|
|
CryptoOperation operation; |
|
|
CryptoOperation operation; |
|
|
|
|
|
ModeCtx_t mode; |
|
|
// If requested, padding will align produced block size with key size |
|
|
// If requested, padding will align produced block size with key size |
|
|
PaddingType padding; |
|
|
PaddingType padding; |
|
|
|
|
|
Key_t key; |
|
|
|
|
|
|
|
|
static void Init(CryptoAttribs_t* ctx); |
|
|
static void Init(CryptoAttribs_t* ctx); |
|
|
static void Free(CryptoAttribs_t* ctx); |
|
|
static void Free(CryptoAttribs_t* ctx); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- |
|
|
|
|
|
Structure for key passing |
|
|
|
|
|
-------------------------------------------------------------------------*/ |
|
|
|
|
|
struct Key_t { |
|
|
|
|
|
uint8_t* key; |
|
|
|
|
|
size_t len; |
|
|
|
|
|
|
|
|
|
|
|
static void Init(Key_t* ctx); |
|
|
|
|
|
static void Free(Key_t* ctx); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
struct int24 { |
|
|
struct int24 { |
|
|
unsigned int data:24; |
|
|
unsigned int data:24; |
|
|
}; |
|
|
}; |
|
|