diff options
author | Michael Brown <mcb30@etherboot.org> | 2007-01-31 18:09:20 +0000 |
---|---|---|
committer | Michael Brown <mcb30@etherboot.org> | 2007-01-31 18:09:20 +0000 |
commit | 1ae70e12e539804c1c5cba50609c18ad44c6f46a (patch) | |
tree | e10f51c6997ef744192b5db5c01b7dcfce3206e4 /src/crypto | |
parent | 0d07657296ca9a5dc323d4fc3b2856dd9fdd9e4e (diff) | |
download | ipxe-1ae70e12e539804c1c5cba50609c18ad44c6f46a.tar.gz |
Added wrapper for AXTLS AES code
Diffstat (limited to 'src/crypto')
-rw-r--r-- | src/crypto/axtls_aes.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/crypto/axtls_aes.c b/src/crypto/axtls_aes.c new file mode 100644 index 000000000..a587c5cb7 --- /dev/null +++ b/src/crypto/axtls_aes.c @@ -0,0 +1,53 @@ +#include "crypto/axtls/crypto.h" +#include <string.h> +#include <gpxe/crypto.h> +#include <gpxe/aes.h> + +static int aes_setkey ( void *ctx, const void *key, size_t keylen ) { + 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_setiv ( void *ctx, const void *iv ) { + AES_CTX *aesctx = ctx; + + memcpy ( aesctx->iv, iv, sizeof ( aesctx->iv ) ); +} + +static void aes_encrypt ( void *ctx, const void *data, void *dst, + size_t len ) { + AES_CTX *aesctx = ctx; + + AES_cbc_encrypt ( aesctx, data, dst, len ); +} + +static void aes_decrypt ( void *ctx, const void *data, void *dst, + size_t len ) { + AES_CTX *aesctx = ctx; + + AES_cbc_decrypt ( aesctx, data, dst, len ); +} + +struct crypto_algorithm aes_algorithm = { + .name = "aes", + .ctxsize = sizeof ( AES_CTX ), + .blocksize = 16, + .setkey = aes_setkey, + .setiv = aes_setiv, + .encode = aes_encrypt, + .decode = aes_decrypt, +}; |