david/ipxe
david
/
ipxe
Archived
1
0
Fork 0
This repository has been archived on 2020-12-06. You can view files and clone it, but cannot push or open issues or pull requests.
ipxe/src/crypto/axtls_aes.c

55 lines
1.1 KiB
C
Raw Normal View History

2007-01-31 19:09:20 +01:00
#include "crypto/axtls/crypto.h"
#include <string.h>
2007-07-24 18:11:31 +02:00
#include <errno.h>
2007-01-31 19:09:20 +01:00
#include <gpxe/crypto.h>
#include <gpxe/aes.h>
static int aes_cbc_setkey ( void *ctx, const void *key, size_t keylen ) {
2007-01-31 19:09:20 +01:00
AES_CTX *aesctx = ctx;
AES_MODE mode;
switch ( keylen ) {
case ( 128 / 8 ):
mode = AES_MODE_128;
break;
case ( 256 / 8 ):
mode = AES_MODE_256;
break;
default:
return -EINVAL;
}
AES_set_key ( aesctx, key, aesctx->iv, mode );
return 0;
}
static void aes_cbc_setiv ( void *ctx, const void *iv ) {
2007-01-31 19:09:20 +01:00
AES_CTX *aesctx = ctx;
memcpy ( aesctx->iv, iv, sizeof ( aesctx->iv ) );
}
static void aes_cbc_encrypt ( void *ctx, const void *data, void *dst,
size_t len ) {
2007-01-31 19:09:20 +01:00
AES_CTX *aesctx = ctx;
AES_cbc_encrypt ( aesctx, data, dst, len );
}
static void aes_cbc_decrypt ( void *ctx, const void *data, void *dst,
size_t len ) {
2007-01-31 19:09:20 +01:00
AES_CTX *aesctx = ctx;
AES_cbc_decrypt ( aesctx, data, dst, len );
}
struct crypto_algorithm aes_cbc_algorithm = {
.name = "aes_cbc",
2007-01-31 19:09:20 +01:00
.ctxsize = sizeof ( AES_CTX ),
.blocksize = 16,
.setkey = aes_cbc_setkey,
.setiv = aes_cbc_setiv,
.encode = aes_cbc_encrypt,
.decode = aes_cbc_decrypt,
2007-01-31 19:09:20 +01:00
};