Fix typo.
[gpxe.git] / src / crypto / axtls_aes.c
blobac7e921d0f8f551c8e72dd458bdbd112cce23920
1 #include "crypto/axtls/crypto.h"
2 #include <string.h>
3 #include <errno.h>
4 #include <gpxe/crypto.h>
5 #include <gpxe/aes.h>
7 static int aes_setkey ( void *ctx, const void *key, size_t keylen ) {
8 AES_CTX *aesctx = ctx;
9 AES_MODE mode;
11 switch ( keylen ) {
12 case ( 128 / 8 ):
13 mode = AES_MODE_128;
14 break;
15 case ( 256 / 8 ):
16 mode = AES_MODE_256;
17 break;
18 default:
19 return -EINVAL;
22 AES_set_key ( aesctx, key, aesctx->iv, mode );
23 return 0;
26 static void aes_setiv ( void *ctx, const void *iv ) {
27 AES_CTX *aesctx = ctx;
29 memcpy ( aesctx->iv, iv, sizeof ( aesctx->iv ) );
32 static void aes_encrypt ( void *ctx, const void *data, void *dst,
33 size_t len ) {
34 AES_CTX *aesctx = ctx;
36 AES_cbc_encrypt ( aesctx, data, dst, len );
39 static void aes_decrypt ( void *ctx, const void *data, void *dst,
40 size_t len ) {
41 AES_CTX *aesctx = ctx;
43 AES_cbc_decrypt ( aesctx, data, dst, len );
46 struct crypto_algorithm aes_algorithm = {
47 .name = "aes",
48 .ctxsize = sizeof ( AES_CTX ),
49 .blocksize = 16,
50 .setkey = aes_setkey,
51 .setiv = aes_setiv,
52 .encode = aes_encrypt,
53 .decode = aes_decrypt,