|
@@ -0,0 +1,53 @@
|
|
1
|
+#include "crypto/axtls/crypto.h"
|
|
2
|
+#include <string.h>
|
|
3
|
+#include <gpxe/crypto.h>
|
|
4
|
+#include <gpxe/aes.h>
|
|
5
|
+
|
|
6
|
+static int aes_setkey ( void *ctx, const void *key, size_t keylen ) {
|
|
7
|
+ AES_CTX *aesctx = ctx;
|
|
8
|
+ AES_MODE mode;
|
|
9
|
+
|
|
10
|
+ switch ( keylen ) {
|
|
11
|
+ case ( 128 / 8 ):
|
|
12
|
+ mode = AES_MODE_128;
|
|
13
|
+ break;
|
|
14
|
+ case ( 256 / 8 ):
|
|
15
|
+ mode = AES_MODE_256;
|
|
16
|
+ break;
|
|
17
|
+ default:
|
|
18
|
+ return -EINVAL;
|
|
19
|
+ }
|
|
20
|
+
|
|
21
|
+ AES_set_key ( aesctx, key, aesctx->iv, mode );
|
|
22
|
+ return 0;
|
|
23
|
+}
|
|
24
|
+
|
|
25
|
+static void aes_setiv ( void *ctx, const void *iv ) {
|
|
26
|
+ AES_CTX *aesctx = ctx;
|
|
27
|
+
|
|
28
|
+ memcpy ( aesctx->iv, iv, sizeof ( aesctx->iv ) );
|
|
29
|
+}
|
|
30
|
+
|
|
31
|
+static void aes_encrypt ( void *ctx, const void *data, void *dst,
|
|
32
|
+ size_t len ) {
|
|
33
|
+ AES_CTX *aesctx = ctx;
|
|
34
|
+
|
|
35
|
+ AES_cbc_encrypt ( aesctx, data, dst, len );
|
|
36
|
+}
|
|
37
|
+
|
|
38
|
+static void aes_decrypt ( void *ctx, const void *data, void *dst,
|
|
39
|
+ size_t len ) {
|
|
40
|
+ AES_CTX *aesctx = ctx;
|
|
41
|
+
|
|
42
|
+ AES_cbc_decrypt ( aesctx, data, dst, len );
|
|
43
|
+}
|
|
44
|
+
|
|
45
|
+struct crypto_algorithm aes_algorithm = {
|
|
46
|
+ .name = "aes",
|
|
47
|
+ .ctxsize = sizeof ( AES_CTX ),
|
|
48
|
+ .blocksize = 16,
|
|
49
|
+ .setkey = aes_setkey,
|
|
50
|
+ .setiv = aes_setiv,
|
|
51
|
+ .encode = aes_encrypt,
|
|
52
|
+ .decode = aes_decrypt,
|
|
53
|
+};
|