2019-04-09 13:35:44 +01:00
|
|
|
#ifndef AES_H
|
|
|
|
#define AES_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2019-04-10 12:24:42 +01:00
|
|
|
#include <stdlib.h>
|
2019-04-09 13:35:44 +01:00
|
|
|
|
|
|
|
#define AES128_KEYBYTES 16
|
|
|
|
#define AES192_KEYBYTES 24
|
|
|
|
#define AES256_KEYBYTES 32
|
|
|
|
#define AESCTR_NONCEBYTES 12
|
2019-04-10 16:50:23 +01:00
|
|
|
#define AES_BLOCKBYTES 16
|
2019-04-09 13:35:44 +01:00
|
|
|
|
2020-02-11 10:15:14 +00:00
|
|
|
// We've put these states on the heap to make sure ctx_release is used.
|
|
|
|
#define PQC_AES128_STATESIZE 88
|
2019-04-09 13:35:44 +01:00
|
|
|
typedef struct {
|
2020-02-11 10:15:14 +00:00
|
|
|
uint64_t* sk_exp;
|
2019-04-09 13:35:44 +01:00
|
|
|
} aes128ctx;
|
|
|
|
|
2020-02-11 10:15:14 +00:00
|
|
|
#define PQC_AES192_STATESIZE 104
|
2019-04-09 13:35:44 +01:00
|
|
|
typedef struct {
|
2020-02-11 10:15:14 +00:00
|
|
|
uint64_t* sk_exp;
|
2019-04-09 13:35:44 +01:00
|
|
|
} aes192ctx;
|
|
|
|
|
2020-02-11 10:15:14 +00:00
|
|
|
#define PQC_AES256_STATESIZE 120
|
2019-04-09 13:35:44 +01:00
|
|
|
typedef struct {
|
2020-02-11 10:15:14 +00:00
|
|
|
uint64_t* sk_exp;
|
2019-04-09 13:35:44 +01:00
|
|
|
} aes256ctx;
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-11 10:15:14 +00:00
|
|
|
/** Initializes the context **/
|
2019-04-09 13:35:44 +01:00
|
|
|
void aes128_keyexp(aes128ctx *r, const unsigned char *key);
|
|
|
|
|
2019-04-09 14:41:44 +01:00
|
|
|
void aes128_ecb(unsigned char *out, const unsigned char *in, size_t nblocks, const aes128ctx *ctx);
|
2019-04-09 13:35:44 +01:00
|
|
|
|
2019-04-09 14:41:44 +01:00
|
|
|
void aes128_ctr(unsigned char *out, size_t outlen, const unsigned char *iv, const aes128ctx *ctx);
|
2019-04-09 13:35:44 +01:00
|
|
|
|
2020-02-11 10:15:14 +00:00
|
|
|
/** Frees the context **/
|
2019-06-21 02:07:03 +01:00
|
|
|
void aes128_ctx_release(aes128ctx *r);
|
|
|
|
|
2019-04-09 13:35:44 +01:00
|
|
|
|
2020-02-11 10:15:14 +00:00
|
|
|
/** Initializes the context **/
|
2019-04-09 13:35:44 +01:00
|
|
|
void aes192_keyexp(aes192ctx *r, const unsigned char *key);
|
|
|
|
|
2019-04-09 14:41:44 +01:00
|
|
|
void aes192_ecb(unsigned char *out, const unsigned char *in, size_t nblocks, const aes192ctx *ctx);
|
2019-04-09 13:35:44 +01:00
|
|
|
|
2019-04-09 14:41:44 +01:00
|
|
|
void aes192_ctr(unsigned char *out, size_t outlen, const unsigned char *iv, const aes192ctx *ctx);
|
2019-04-09 13:35:44 +01:00
|
|
|
|
2019-06-21 02:07:03 +01:00
|
|
|
void aes192_ctx_release(aes192ctx *r);
|
|
|
|
|
2019-04-09 13:35:44 +01:00
|
|
|
|
2020-02-11 10:15:14 +00:00
|
|
|
/** Initializes the context **/
|
2019-04-09 13:35:44 +01:00
|
|
|
void aes256_keyexp(aes256ctx *r, const unsigned char *key);
|
|
|
|
|
2019-04-09 14:41:44 +01:00
|
|
|
void aes256_ecb(unsigned char *out, const unsigned char *in, size_t nblocks, const aes256ctx *ctx);
|
2019-04-09 13:35:44 +01:00
|
|
|
|
2019-04-09 14:41:44 +01:00
|
|
|
void aes256_ctr(unsigned char *out, size_t outlen, const unsigned char *iv, const aes256ctx *ctx);
|
2019-04-09 13:35:44 +01:00
|
|
|
|
2020-02-11 10:15:14 +00:00
|
|
|
/** Frees the context **/
|
2019-06-21 02:07:03 +01:00
|
|
|
void aes256_ctx_release(aes256ctx *r);
|
|
|
|
|
2019-04-09 13:35:44 +01:00
|
|
|
|
|
|
|
#endif
|