mirror of
https://github.com/ipxe/ipxe
synced 2026-04-04 03:00:20 +03:00
[crypto] Remove the concept of a public-key algorithm reusable context
Instances of cipher and digest algorithms tend to get called repeatedly to process substantial amounts of data. This is not true for public-key algorithms, which tend to get called only once or twice for a given key. Simplify the public-key algorithm API so that there is no reusable algorithm context. In particular, this allows callers to omit the error handling currently required to handle memory allocation (or key parsing) errors from pubkey_init(), and to omit the cleanup calls to pubkey_final(). This change does remove the ability for a caller to distinguish between a verification failure due to a memory allocation failure and a verification failure due to a bad signature. This difference is not material in practice: in both cases, for whatever reason, the caller was unable to verify the signature and so cannot proceed further, and the cause of the error will be visible to the user via the return status code. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -93,34 +93,31 @@ struct cipher_algorithm cipher_null = {
|
||||
.auth = cipher_null_auth,
|
||||
};
|
||||
|
||||
int pubkey_null_init ( void *ctx __unused,
|
||||
const struct asn1_cursor *key __unused ) {
|
||||
size_t pubkey_null_max_len ( const struct asn1_cursor *key __unused ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t pubkey_null_max_len ( void *ctx __unused ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pubkey_null_encrypt ( void *ctx __unused, const void *plaintext __unused,
|
||||
int pubkey_null_encrypt ( const struct asn1_cursor *key __unused,
|
||||
const void *plaintext __unused,
|
||||
size_t plaintext_len __unused,
|
||||
void *ciphertext __unused ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pubkey_null_decrypt ( void *ctx __unused, const void *ciphertext __unused,
|
||||
int pubkey_null_decrypt ( const struct asn1_cursor *key __unused,
|
||||
const void *ciphertext __unused,
|
||||
size_t ciphertext_len __unused,
|
||||
void *plaintext __unused ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pubkey_null_sign ( void *ctx __unused,
|
||||
int pubkey_null_sign ( const struct asn1_cursor *key __unused,
|
||||
struct digest_algorithm *digest __unused,
|
||||
const void *value __unused, void *signature __unused ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pubkey_null_verify ( void *ctx __unused,
|
||||
int pubkey_null_verify ( const struct asn1_cursor *key __unused,
|
||||
struct digest_algorithm *digest __unused,
|
||||
const void *value __unused,
|
||||
const void *signature __unused ,
|
||||
@@ -128,18 +125,11 @@ int pubkey_null_verify ( void *ctx __unused,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void pubkey_null_final ( void *ctx __unused ) {
|
||||
/* Do nothing */
|
||||
}
|
||||
|
||||
struct pubkey_algorithm pubkey_null = {
|
||||
.name = "null",
|
||||
.ctxsize = 0,
|
||||
.init = pubkey_null_init,
|
||||
.max_len = pubkey_null_max_len,
|
||||
.encrypt = pubkey_null_encrypt,
|
||||
.decrypt = pubkey_null_decrypt,
|
||||
.sign = pubkey_null_sign,
|
||||
.verify = pubkey_null_verify,
|
||||
.final = pubkey_null_final,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user