summaryrefslogtreecommitdiff
path: root/crypto/aes/aes.h
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2021-05-20 19:06:47 +0200
committerUros Majstorovic <majstor@majstor.org>2021-05-20 19:06:47 +0200
commit3cac09c89fe0081f06188f1e9440de5d863951be (patch)
tree1987fe6544c390eaa501f04583da3feda4370bfd /crypto/aes/aes.h
parent6a17d31a8ac0e0be5dae9d865fa7097a6a8f40ad (diff)
fat filesystem with disk encryption for sd card driver
Diffstat (limited to 'crypto/aes/aes.h')
-rw-r--r--crypto/aes/aes.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/crypto/aes/aes.h b/crypto/aes/aes.h
new file mode 100644
index 0000000..f6dd079
--- /dev/null
+++ b/crypto/aes/aes.h
@@ -0,0 +1,37 @@
+#ifndef _AES_H_
+#define _AES_H_
+
+#include <stdint.h>
+#include <stddef.h>
+
+#define AES128 1
+//#define AES192 1
+//#define AES256 1
+
+#define AES_BLOCKLEN 16 // Block length in bytes - AES is 128b block only
+
+#if defined(AES256) && (AES256 == 1)
+ #define AES_KEYLEN 32
+ #define AES_KEYEXPSIZE 240
+#elif defined(AES192) && (AES192 == 1)
+ #define AES_KEYLEN 24
+ #define AES_KEYEXPSIZE 208
+#else
+ #define AES_KEYLEN 16 // Key length in bytes
+ #define AES_KEYEXPSIZE 176
+#endif
+
+typedef struct
+{
+ uint8_t RoundKey[AES_KEYEXPSIZE];
+} AESCtx;
+
+void aes_init(AESCtx *ctx, uint8_t *key);
+// buffer size is exactly AES_BLOCKLEN bytes;
+void aes_ecb_encrypt(AESCtx *ctx, uint8_t *buf);
+void aes_ecb_decrypt(AESCtx *ctx, uint8_t *buf);
+// buffer size MUST be mutile of AES_BLOCKLEN;
+void aes_cbc_encrypt(AESCtx *ctx, uint8_t *iv, uint8_t *buf, size_t length);
+void aes_cbc_decrypt(AESCtx *ctx, uint8_t *iv, uint8_t *buf, size_t length);
+
+#endif \ No newline at end of file