summaryrefslogtreecommitdiffstats
path: root/src/crypto
diff options
context:
space:
mode:
authorMichael Brown2009-02-18 22:56:02 +0100
committerMichael Brown2009-02-18 23:17:41 +0100
commita3219b24a8ea4699e7b04cf1f1131aade9fcd855 (patch)
treedf3d4cc515e6a02203e8560ff881351daf48111d /src/crypto
parent[crypto] Move AES_convert_key() hack into axtls_aes.c (diff)
downloadipxe-a3219b24a8ea4699e7b04cf1f1131aade9fcd855.tar.gz
ipxe-a3219b24a8ea4699e7b04cf1f1131aade9fcd855.tar.xz
ipxe-a3219b24a8ea4699e7b04cf1f1131aade9fcd855.zip
[crypto] Split crypto_algorithm into {digest,cipher,pubkey}_algorithm
The various types of cryptographic algorithm are fundamentally different, and it was probably a mistake to try to handle them via a single common type. pubkey_algorithm is a placeholder type for now.
Diffstat (limited to 'src/crypto')
-rw-r--r--src/crypto/axtls_aes.c6
-rw-r--r--src/crypto/axtls_sha1.c7
-rw-r--r--src/crypto/chap.c2
-rw-r--r--src/crypto/cipher.c12
-rw-r--r--src/crypto/crypto_null.c62
-rw-r--r--src/crypto/hmac.c6
-rw-r--r--src/crypto/md5.c7
7 files changed, 58 insertions, 44 deletions
diff --git a/src/crypto/axtls_aes.c b/src/crypto/axtls_aes.c
index 278f9334..a19ad3c4 100644
--- a/src/crypto/axtls_aes.c
+++ b/src/crypto/axtls_aes.c
@@ -59,12 +59,12 @@ static void aes_cbc_decrypt ( void *ctx, const void *data, void *dst,
AES_cbc_decrypt ( &aesctx->ctx, data, dst, len );
}
-struct crypto_algorithm aes_cbc_algorithm = {
+struct cipher_algorithm aes_cbc_algorithm = {
.name = "aes_cbc",
.ctxsize = sizeof ( struct aes_cbc_context ),
.blocksize = 16,
.setkey = aes_cbc_setkey,
.setiv = aes_cbc_setiv,
- .encode = aes_cbc_encrypt,
- .decode = aes_cbc_decrypt,
+ .encrypt = aes_cbc_encrypt,
+ .decrypt = aes_cbc_decrypt,
};
diff --git a/src/crypto/axtls_sha1.c b/src/crypto/axtls_sha1.c
index 62ff878a..841e193b 100644
--- a/src/crypto/axtls_sha1.c
+++ b/src/crypto/axtls_sha1.c
@@ -6,8 +6,7 @@ static void sha1_init ( void *ctx ) {
SHA1Init ( ctx );
}
-static void sha1_update ( void *ctx, const void *data, void *dst __unused,
- size_t len ) {
+static void sha1_update ( void *ctx, const void *data, size_t len ) {
SHA1Update ( ctx, data, len );
}
@@ -15,12 +14,12 @@ static void sha1_final ( void *ctx, void *out ) {
SHA1Final ( ctx, out );
}
-struct crypto_algorithm sha1_algorithm = {
+struct digest_algorithm sha1_algorithm = {
.name = "sha1",
.ctxsize = SHA1_CTX_SIZE,
.blocksize = 64,
.digestsize = SHA1_DIGEST_SIZE,
.init = sha1_init,
- .encode = sha1_update,
+ .update = sha1_update,
.final = sha1_final,
};
diff --git a/src/crypto/chap.c b/src/crypto/chap.c
index 59b70e39..d0784d25 100644
--- a/src/crypto/chap.c
+++ b/src/crypto/chap.c
@@ -42,7 +42,7 @@
* eventually be freed by a call to chap_finish().
*/
int chap_init ( struct chap_response *chap,
- struct crypto_algorithm *digest ) {
+ struct digest_algorithm *digest ) {
size_t state_len;
void *state;
diff --git a/src/crypto/cipher.c b/src/crypto/cipher.c
index 9c392009..f83a6d0f 100644
--- a/src/crypto/cipher.c
+++ b/src/crypto/cipher.c
@@ -2,23 +2,23 @@
#include <errno.h>
#include <gpxe/crypto.h>
-int cipher_encrypt ( struct crypto_algorithm *crypto,
+int cipher_encrypt ( struct cipher_algorithm *cipher,
void *ctx, const void *src, void *dst,
size_t len ) {
- if ( ( len & ( crypto->blocksize - 1 ) ) ) {
+ if ( ( len & ( cipher->blocksize - 1 ) ) ) {
return -EINVAL;
}
- crypto->encode ( ctx, src, dst, len );
+ cipher->encrypt ( ctx, src, dst, len );
return 0;
}
-int cipher_decrypt ( struct crypto_algorithm *crypto,
+int cipher_decrypt ( struct cipher_algorithm *cipher,
void *ctx, const void *src, void *dst,
size_t len ) {
- if ( ( len & ( crypto->blocksize - 1 ) ) ) {
+ if ( ( len & ( cipher->blocksize - 1 ) ) ) {
return -EINVAL;
}
- crypto->decode ( ctx, src, dst, len );
+ cipher->decrypt ( ctx, src, dst, len );
return 0;
}
diff --git a/src/crypto/crypto_null.c b/src/crypto/crypto_null.c
index 120ef0a6..8cc9217a 100644
--- a/src/crypto/crypto_null.c
+++ b/src/crypto/crypto_null.c
@@ -25,45 +25,61 @@
#include <string.h>
#include <gpxe/crypto.h>
-static void null_init ( void *ctx __unused ) {
+static void digest_null_init ( void *ctx __unused ) {
/* Do nothing */
}
-static int null_setkey ( void *ctx __unused, const void *key __unused,
- size_t keylen __unused ) {
+static void digest_null_update ( void *ctx __unused, const void *src __unused,
+ size_t len __unused ) {
/* Do nothing */
- return 0;
}
-static void null_setiv ( void *ctx __unused, const void *iv __unused ) {
+static void digest_null_final ( void *ctx __unused, void *out __unused ) {
/* Do nothing */
}
-static void null_encode ( void *ctx __unused, const void *src,
- void *dst, size_t len ) {
- if ( dst )
- memcpy ( dst, src, len );
-}
+struct digest_algorithm digest_null = {
+ .name = "null",
+ .ctxsize = 0,
+ .blocksize = 1,
+ .digestsize = 0,
+ .init = digest_null_init,
+ .update = digest_null_update,
+ .final = digest_null_final,
+};
-static void null_decode ( void *ctx __unused, const void *src,
- void *dst, size_t len ) {
- if ( dst )
- memcpy ( dst, src, len );
+static int cipher_null_setkey ( void *ctx __unused, const void *key __unused,
+ size_t keylen __unused ) {
+ /* Do nothing */
+ return 0;
}
-static void null_final ( void *ctx __unused, void *out __unused ) {
+static void cipher_null_setiv ( void *ctx __unused,
+ const void *iv __unused ) {
/* Do nothing */
}
-struct crypto_algorithm crypto_null = {
+static void cipher_null_encrypt ( void *ctx __unused, const void *src,
+ void *dst, size_t len ) {
+ memcpy ( dst, src, len );
+}
+
+static void cipher_null_decrypt ( void *ctx __unused, const void *src,
+ void *dst, size_t len ) {
+ memcpy ( dst, src, len );
+}
+
+struct cipher_algorithm cipher_null = {
.name = "null",
.ctxsize = 0,
.blocksize = 1,
- .digestsize = 0,
- .init = null_init,
- .setkey = null_setkey,
- .setiv = null_setiv,
- .encode = null_encode,
- .decode = null_decode,
- .final = null_final,
+ .setkey = cipher_null_setkey,
+ .setiv = cipher_null_setiv,
+ .encrypt = cipher_null_encrypt,
+ .decrypt = cipher_null_decrypt,
+};
+
+struct pubkey_algorithm pubkey_null = {
+ .name = "null",
+ .ctxsize = 0,
};
diff --git a/src/crypto/hmac.c b/src/crypto/hmac.c
index 6884bde9..be0298a7 100644
--- a/src/crypto/hmac.c
+++ b/src/crypto/hmac.c
@@ -35,7 +35,7 @@
* @v key Key
* @v key_len Length of key
*/
-static void hmac_reduce_key ( struct crypto_algorithm *digest,
+static void hmac_reduce_key ( struct digest_algorithm *digest,
void *key, size_t *key_len ) {
uint8_t digest_ctx[digest->ctxsize];
@@ -58,7 +58,7 @@ static void hmac_reduce_key ( struct crypto_algorithm *digest,
* will be replaced with its own digest, and key_len will be updated
* accordingly).
*/
-void hmac_init ( struct crypto_algorithm *digest, void *digest_ctx,
+void hmac_init ( struct digest_algorithm *digest, void *digest_ctx,
void *key, size_t *key_len ) {
unsigned char k_ipad[digest->blocksize];
unsigned int i;
@@ -93,7 +93,7 @@ void hmac_init ( struct crypto_algorithm *digest, void *digest_ctx,
* will be replaced with its own digest, and key_len will be updated
* accordingly).
*/
-void hmac_final ( struct crypto_algorithm *digest, void *digest_ctx,
+void hmac_final ( struct digest_algorithm *digest, void *digest_ctx,
void *key, size_t *key_len, void *hmac ) {
unsigned char k_opad[digest->blocksize];
unsigned int i;
diff --git a/src/crypto/md5.c b/src/crypto/md5.c
index 1fed24fc..76fb8a69 100644
--- a/src/crypto/md5.c
+++ b/src/crypto/md5.c
@@ -167,8 +167,7 @@ static void md5_init(void *context)
mctx->byte_count = 0;
}
-static void md5_update(void *context, const void *data, void *dst __unused,
- size_t len)
+static void md5_update(void *context, const void *data, size_t len)
{
struct md5_ctx *mctx = context;
const u32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f);
@@ -224,12 +223,12 @@ static void md5_final(void *context, void *out)
memset(mctx, 0, sizeof(*mctx));
}
-struct crypto_algorithm md5_algorithm = {
+struct digest_algorithm md5_algorithm = {
.name = "md5",
.ctxsize = MD5_CTX_SIZE,
.blocksize = ( MD5_BLOCK_WORDS * 4 ),
.digestsize = MD5_DIGEST_SIZE,
.init = md5_init,
- .encode = md5_update,
+ .update = md5_update,
.final = md5_final,
};