aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2022-10-25 12:59:06 +0100
committerMichael Brown <mcb30@ipxe.org>2022-10-25 13:20:22 +0100
commit52f72d298abd81a6102ddddf2fff4918e4b077ce (patch)
treeccae06dfd5d708991031730871188ee37a138c62
parent2c78242732765be200f81a84cc95037ba2924e42 (diff)
downloadipxe-52f72d298abd81a6102ddddf2fff4918e4b077ce.zip
ipxe-52f72d298abd81a6102ddddf2fff4918e4b077ce.tar.gz
ipxe-52f72d298abd81a6102ddddf2fff4918e4b077ce.tar.bz2
[crypto] Expose null crypto algorithm methods for reuse
Signed-off-by: Michael Brown <mcb30@ipxe.org>
-rw-r--r--src/crypto/aes.c12
-rw-r--r--src/crypto/arc4.c8
-rw-r--r--src/crypto/crypto_null.c62
-rw-r--r--src/include/ipxe/crypto.h23
4 files changed, 54 insertions, 51 deletions
diff --git a/src/crypto/aes.c b/src/crypto/aes.c
index b9e206b..d739328 100644
--- a/src/crypto/aes.c
+++ b/src/crypto/aes.c
@@ -778,23 +778,13 @@ static int aes_setkey ( void *ctx, const void *key, size_t keylen ) {
return 0;
}
-/**
- * Set initialisation vector
- *
- * @v ctx Context
- * @v iv Initialisation vector
- */
-static void aes_setiv ( void *ctx __unused, const void *iv __unused ) {
- /* Nothing to do */
-}
-
/** Basic AES algorithm */
struct cipher_algorithm aes_algorithm = {
.name = "aes",
.ctxsize = sizeof ( struct aes_context ),
.blocksize = AES_BLOCKSIZE,
.setkey = aes_setkey,
- .setiv = aes_setiv,
+ .setiv = cipher_null_setiv,
.encrypt = aes_encrypt,
.decrypt = aes_decrypt,
};
diff --git a/src/crypto/arc4.c b/src/crypto/arc4.c
index 91a7320..0dba2fc 100644
--- a/src/crypto/arc4.c
+++ b/src/crypto/arc4.c
@@ -96,12 +96,6 @@ static void arc4_xor ( void *ctxv, const void *srcv, void *dstv,
ctx->j = j;
}
-static void arc4_setiv ( void *ctx __unused, const void *iv __unused )
-{
- /* ARC4 does not use a fixed-length IV */
-}
-
-
/**
* Perform ARC4 encryption or decryption, skipping initial keystream bytes
*
@@ -126,7 +120,7 @@ struct cipher_algorithm arc4_algorithm = {
.ctxsize = ARC4_CTX_SIZE,
.blocksize = 1,
.setkey = arc4_setkey,
- .setiv = arc4_setiv,
+ .setiv = cipher_null_setiv,
.encrypt = arc4_xor,
.decrypt = arc4_xor,
};
diff --git a/src/crypto/crypto_null.c b/src/crypto/crypto_null.c
index 15a1c53..9107717 100644
--- a/src/crypto/crypto_null.c
+++ b/src/crypto/crypto_null.c
@@ -32,16 +32,16 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <string.h>
#include <ipxe/crypto.h>
-static void digest_null_init ( void *ctx __unused ) {
+void digest_null_init ( void *ctx __unused ) {
/* Do nothing */
}
-static void digest_null_update ( void *ctx __unused, const void *src __unused,
- size_t len __unused ) {
+void digest_null_update ( void *ctx __unused, const void *src __unused,
+ size_t len __unused ) {
/* Do nothing */
}
-static void digest_null_final ( void *ctx __unused, void *out __unused ) {
+void digest_null_final ( void *ctx __unused, void *out __unused ) {
/* Do nothing */
}
@@ -55,24 +55,23 @@ struct digest_algorithm digest_null = {
.final = digest_null_final,
};
-static int cipher_null_setkey ( void *ctx __unused, const void *key __unused,
- size_t keylen __unused ) {
+int cipher_null_setkey ( void *ctx __unused, const void *key __unused,
+ size_t keylen __unused ) {
/* Do nothing */
return 0;
}
-static void cipher_null_setiv ( void *ctx __unused,
- const void *iv __unused ) {
+void cipher_null_setiv ( void *ctx __unused, const void *iv __unused ) {
/* Do nothing */
}
-static void cipher_null_encrypt ( void *ctx __unused, const void *src,
- void *dst, size_t len ) {
+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 ) {
+void cipher_null_decrypt ( void *ctx __unused, const void *src, void *dst,
+ size_t len ) {
memcpy ( dst, src, len );
}
@@ -86,45 +85,42 @@ struct cipher_algorithm cipher_null = {
.decrypt = cipher_null_decrypt,
};
-static int pubkey_null_init ( void *ctx __unused, const void *key __unused,
- size_t key_len __unused ) {
+int pubkey_null_init ( void *ctx __unused, const void *key __unused,
+ size_t key_len __unused ) {
return 0;
}
-static size_t pubkey_null_max_len ( void *ctx __unused ) {
+size_t pubkey_null_max_len ( void *ctx __unused ) {
return 0;
}
-static int pubkey_null_encrypt ( void *ctx __unused,
- const void *plaintext __unused,
- size_t plaintext_len __unused,
- void *ciphertext __unused ) {
+int pubkey_null_encrypt ( void *ctx __unused, const void *plaintext __unused,
+ size_t plaintext_len __unused,
+ void *ciphertext __unused ) {
return 0;
}
-static int pubkey_null_decrypt ( void *ctx __unused,
- const void *ciphertext __unused,
- size_t ciphertext_len __unused,
- void *plaintext __unused ) {
+int pubkey_null_decrypt ( void *ctx __unused, const void *ciphertext __unused,
+ size_t ciphertext_len __unused,
+ void *plaintext __unused ) {
return 0;
}
-static int pubkey_null_sign ( void *ctx __unused,
- struct digest_algorithm *digest __unused,
- const void *value __unused,
- void *signature __unused ) {
+int pubkey_null_sign ( void *ctx __unused,
+ struct digest_algorithm *digest __unused,
+ const void *value __unused, void *signature __unused ) {
return 0;
}
-static int pubkey_null_verify ( void *ctx __unused,
- struct digest_algorithm *digest __unused,
- const void *value __unused,
- const void *signature __unused ,
- size_t signature_len __unused ) {
+int pubkey_null_verify ( void *ctx __unused,
+ struct digest_algorithm *digest __unused,
+ const void *value __unused,
+ const void *signature __unused ,
+ size_t signature_len __unused ) {
return 0;
}
-static void pubkey_null_final ( void *ctx __unused ) {
+void pubkey_null_final ( void *ctx __unused ) {
/* Do nothing */
}
diff --git a/src/include/ipxe/crypto.h b/src/include/ipxe/crypto.h
index fc0d8b2..34ab389 100644
--- a/src/include/ipxe/crypto.h
+++ b/src/include/ipxe/crypto.h
@@ -263,6 +263,29 @@ static inline int pubkey_match ( struct pubkey_algorithm *pubkey,
public_key_len );
}
+extern void digest_null_init ( void *ctx );
+extern void digest_null_update ( void *ctx, const void *src, size_t len );
+extern void digest_null_final ( void *ctx, void *out );
+
+extern int cipher_null_setkey ( void *ctx, const void *key, size_t keylen );
+extern void cipher_null_setiv ( void *ctx, const void *iv );
+extern void cipher_null_encrypt ( void *ctx, const void *src, void *dst,
+ size_t len );
+extern void cipher_null_decrypt ( void *ctx, const void *src, void *dst,
+ size_t len );
+
+extern int pubkey_null_init ( void *ctx, const void *key, size_t key_len );
+extern size_t pubkey_null_max_len ( void *ctx );
+extern int pubkey_null_encrypt ( void *ctx, const void *plaintext,
+ size_t plaintext_len, void *ciphertext );
+extern int pubkey_null_decrypt ( void *ctx, const void *ciphertext,
+ size_t ciphertext_len, void *plaintext );
+extern int pubkey_null_sign ( void *ctx, struct digest_algorithm *digest,
+ const void *value, void *signature );
+extern int pubkey_null_verify ( void *ctx, struct digest_algorithm *digest,
+ const void *value, const void *signature ,
+ size_t signature_len );
+
extern struct digest_algorithm digest_null;
extern struct cipher_algorithm cipher_null;
extern struct pubkey_algorithm pubkey_null;