You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

70 lines
1.8 KiB

  1. #ifndef AES_H
  2. #define AES_H
  3. #include <stdint.h>
  4. #include <stdlib.h>
  5. #define AES128_KEYBYTES 16
  6. #define AES192_KEYBYTES 24
  7. #define AES256_KEYBYTES 32
  8. #define AESCTR_NONCEBYTES 12
  9. #define AES_BLOCKBYTES 16
  10. // We've put these states on the heap to make sure ctx_release is used.
  11. #define PQC_AES128_STATESIZE 88
  12. typedef struct {
  13. uint64_t* sk_exp;
  14. } aes128ctx;
  15. #define PQC_AES192_STATESIZE 104
  16. typedef struct {
  17. uint64_t* sk_exp;
  18. } aes192ctx;
  19. #define PQC_AES256_STATESIZE 120
  20. typedef struct {
  21. uint64_t* sk_exp;
  22. } aes256ctx;
  23. /** Initializes the context **/
  24. void aes128_ecb_keyexp(aes128ctx *r, const unsigned char *key);
  25. void aes128_ctr_keyexp(aes128ctx *r, const unsigned char *key);
  26. void aes128_ecb(unsigned char *out, const unsigned char *in, size_t nblocks, const aes128ctx *ctx);
  27. void aes128_ctr(unsigned char *out, size_t outlen, const unsigned char *iv, const aes128ctx *ctx);
  28. /** Frees the context **/
  29. void aes128_ctx_release(aes128ctx *r);
  30. /** Initializes the context **/
  31. void aes192_ecb_keyexp(aes192ctx *r, const unsigned char *key);
  32. void aes192_ctr_keyexp(aes192ctx *r, const unsigned char *key);
  33. void aes192_ecb(unsigned char *out, const unsigned char *in, size_t nblocks, const aes192ctx *ctx);
  34. void aes192_ctr(unsigned char *out, size_t outlen, const unsigned char *iv, const aes192ctx *ctx);
  35. void aes192_ctx_release(aes192ctx *r);
  36. /** Initializes the context **/
  37. void aes256_ecb_keyexp(aes256ctx *r, const unsigned char *key);
  38. void aes256_ctr_keyexp(aes256ctx *r, const unsigned char *key);
  39. void aes256_ecb(unsigned char *out, const unsigned char *in, size_t nblocks, const aes256ctx *ctx);
  40. void aes256_ctr(unsigned char *out, size_t outlen, const unsigned char *iv, const aes256ctx *ctx);
  41. /** Frees the context **/
  42. void aes256_ctx_release(aes256ctx *r);
  43. #endif