Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Michael Brown
committed
Jan 31, 2007
1 parent
0d07657
commit 1ae70e1
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef _GPXE_AES_H | ||
#define _GPXE_AES_H | ||
|
||
struct crypto_algorithm; | ||
|
||
extern struct crypto_algorithm aes_algorithm; | ||
|
||
#endif /* _GPXE_AES_H */ |