[crypto] Expose null crypto algorithm methods for reuse

Signed-off-by: Michael Brown <mcb30@ipxe.org>
pull/785/head
Michael Brown 2022-10-25 12:59:06 +01:00
parent 2c78242732
commit 52f72d298a
4 changed files with 54 additions and 51 deletions

View File

@ -778,23 +778,13 @@ static int aes_setkey ( void *ctx, const void *key, size_t keylen ) {
return 0; 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 */ /** Basic AES algorithm */
struct cipher_algorithm aes_algorithm = { struct cipher_algorithm aes_algorithm = {
.name = "aes", .name = "aes",
.ctxsize = sizeof ( struct aes_context ), .ctxsize = sizeof ( struct aes_context ),
.blocksize = AES_BLOCKSIZE, .blocksize = AES_BLOCKSIZE,
.setkey = aes_setkey, .setkey = aes_setkey,
.setiv = aes_setiv, .setiv = cipher_null_setiv,
.encrypt = aes_encrypt, .encrypt = aes_encrypt,
.decrypt = aes_decrypt, .decrypt = aes_decrypt,
}; };

View File

@ -96,12 +96,6 @@ static void arc4_xor ( void *ctxv, const void *srcv, void *dstv,
ctx->j = j; 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 * Perform ARC4 encryption or decryption, skipping initial keystream bytes
* *
@ -126,7 +120,7 @@ struct cipher_algorithm arc4_algorithm = {
.ctxsize = ARC4_CTX_SIZE, .ctxsize = ARC4_CTX_SIZE,
.blocksize = 1, .blocksize = 1,
.setkey = arc4_setkey, .setkey = arc4_setkey,
.setiv = arc4_setiv, .setiv = cipher_null_setiv,
.encrypt = arc4_xor, .encrypt = arc4_xor,
.decrypt = arc4_xor, .decrypt = arc4_xor,
}; };

View File

@ -32,16 +32,16 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <string.h> #include <string.h>
#include <ipxe/crypto.h> #include <ipxe/crypto.h>
static void digest_null_init ( void *ctx __unused ) { void digest_null_init ( void *ctx __unused ) {
/* Do nothing */ /* Do nothing */
} }
static void digest_null_update ( void *ctx __unused, const void *src __unused, void digest_null_update ( void *ctx __unused, const void *src __unused,
size_t len __unused ) { size_t len __unused ) {
/* Do nothing */ /* 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 */ /* Do nothing */
} }
@ -55,24 +55,23 @@ struct digest_algorithm digest_null = {
.final = digest_null_final, .final = digest_null_final,
}; };
static int cipher_null_setkey ( void *ctx __unused, const void *key __unused, int cipher_null_setkey ( void *ctx __unused, const void *key __unused,
size_t keylen __unused ) { size_t keylen __unused ) {
/* Do nothing */ /* Do nothing */
return 0; return 0;
} }
static void cipher_null_setiv ( void *ctx __unused, void cipher_null_setiv ( void *ctx __unused, const void *iv __unused ) {
const void *iv __unused ) {
/* Do nothing */ /* Do nothing */
} }
static void cipher_null_encrypt ( void *ctx __unused, const void *src, void cipher_null_encrypt ( void *ctx __unused, const void *src, void *dst,
void *dst, size_t len ) { size_t len ) {
memcpy ( dst, src, len ); memcpy ( dst, src, len );
} }
static void cipher_null_decrypt ( void *ctx __unused, const void *src, void cipher_null_decrypt ( void *ctx __unused, const void *src, void *dst,
void *dst, size_t len ) { size_t len ) {
memcpy ( dst, src, len ); memcpy ( dst, src, len );
} }
@ -86,37 +85,34 @@ struct cipher_algorithm cipher_null = {
.decrypt = cipher_null_decrypt, .decrypt = cipher_null_decrypt,
}; };
static int pubkey_null_init ( void *ctx __unused, const void *key __unused, int pubkey_null_init ( void *ctx __unused, const void *key __unused,
size_t key_len __unused ) { size_t key_len __unused ) {
return 0; return 0;
} }
static size_t pubkey_null_max_len ( void *ctx __unused ) { size_t pubkey_null_max_len ( void *ctx __unused ) {
return 0; return 0;
} }
static int pubkey_null_encrypt ( void *ctx __unused, int pubkey_null_encrypt ( void *ctx __unused, const void *plaintext __unused,
const void *plaintext __unused,
size_t plaintext_len __unused, size_t plaintext_len __unused,
void *ciphertext __unused ) { void *ciphertext __unused ) {
return 0; return 0;
} }
static int pubkey_null_decrypt ( void *ctx __unused, int pubkey_null_decrypt ( void *ctx __unused, const void *ciphertext __unused,
const void *ciphertext __unused,
size_t ciphertext_len __unused, size_t ciphertext_len __unused,
void *plaintext __unused ) { void *plaintext __unused ) {
return 0; return 0;
} }
static int pubkey_null_sign ( void *ctx __unused, int pubkey_null_sign ( void *ctx __unused,
struct digest_algorithm *digest __unused, struct digest_algorithm *digest __unused,
const void *value __unused, const void *value __unused, void *signature __unused ) {
void *signature __unused ) {
return 0; return 0;
} }
static int pubkey_null_verify ( void *ctx __unused, int pubkey_null_verify ( void *ctx __unused,
struct digest_algorithm *digest __unused, struct digest_algorithm *digest __unused,
const void *value __unused, const void *value __unused,
const void *signature __unused , const void *signature __unused ,
@ -124,7 +120,7 @@ static int pubkey_null_verify ( void *ctx __unused,
return 0; return 0;
} }
static void pubkey_null_final ( void *ctx __unused ) { void pubkey_null_final ( void *ctx __unused ) {
/* Do nothing */ /* Do nothing */
} }

View File

@ -263,6 +263,29 @@ static inline int pubkey_match ( struct pubkey_algorithm *pubkey,
public_key_len ); 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 digest_algorithm digest_null;
extern struct cipher_algorithm cipher_null; extern struct cipher_algorithm cipher_null;
extern struct pubkey_algorithm pubkey_null; extern struct pubkey_algorithm pubkey_null;