SEC: Add AES implementation.
[bertos.git] / bertos / sec / cipher / aes.h
1 #ifndef SEC_CIPHER_AES_H
2 #define SEC_CIPHER_AES_H
3
4 #include <sec/cipher.h>
5 #include <alloca.h>
6
7 typedef struct
8 {
9         BlockCipher c;
10         int num_rounds;
11         uint8_t expkey[44*4];
12 } AES128_Context;
13
14 typedef struct
15 {
16         BlockCipher c;
17         int num_rounds;
18         uint8_t expkey[52*4];
19 } AES192_Context;
20
21 typedef struct
22 {
23         BlockCipher c;
24         int num_rounds;
25         uint8_t expkey[60*4];
26 } AES256_Context;
27
28 void AES128_init(AES128_Context *c);
29 void AES192_init(AES192_Context *c);
30 void AES256_init(AES256_Context *c);
31
32 #define AES128_stackinit(...) \
33         ({ AES128_Context *ctx = alloca(sizeof(AES128_Context)); AES128_init(ctx, ##__VA_ARGS__); &ctx->c; })
34
35 #define AES192_stackinit(...) \
36         ({ AES192_Context *ctx = alloca(sizeof(AES192_Context)); AES192_init(ctx, ##__VA_ARGS__); &ctx->c; })
37
38 #define AES256_stackinit(...) \
39         ({ AES256_Context *ctx = alloca(sizeof(AES256_Context)); AES256_init(ctx, ##__VA_ARGS__); &ctx->c; })
40
41 int AES_testSetup(void);
42 int AES_testRun(void);
43 int AES_testTearDown(void);
44
45 #endif /* SEC_CIPHER_AES_H */