diff options
Diffstat (limited to 'crypto/evp/exchange.c')
| -rw-r--r-- | crypto/evp/exchange.c | 107 |
1 files changed, 50 insertions, 57 deletions
diff --git a/crypto/evp/exchange.c b/crypto/evp/exchange.c index dae3a2c5a85c..088d2fdc6e73 100644 --- a/crypto/evp/exchange.c +++ b/crypto/evp/exchange.c @@ -14,7 +14,7 @@ #include "internal/refcount.h" #include "internal/provider.h" #include "internal/core.h" -#include "internal/numbers.h" /* includes SIZE_MAX */ +#include "internal/numbers.h" /* includes SIZE_MAX */ #include "crypto/evp.h" #include "evp_local.h" @@ -47,8 +47,8 @@ static EVP_KEYEXCH *evp_keyexch_new(OSSL_PROVIDER *prov) } static void *evp_keyexch_from_algorithm(int name_id, - const OSSL_ALGORITHM *algodef, - OSSL_PROVIDER *prov) + const OSSL_ALGORITHM *algodef, + OSSL_PROVIDER *prov) { const OSSL_DISPATCH *fns = algodef->implementation; EVP_KEYEXCH *exchange = NULL; @@ -129,8 +129,8 @@ static void *evp_keyexch_from_algorithm(int name_id, } } if (fncnt != 4 - || (gparamfncnt != 0 && gparamfncnt != 2) - || (sparamfncnt != 0 && sparamfncnt != 2)) { + || (gparamfncnt != 0 && gparamfncnt != 2) + || (sparamfncnt != 0 && sparamfncnt != 2)) { /* * In order to be a consistent set of functions we must have at least * a complete set of "exchange" functions: init, derive, newctx, @@ -145,7 +145,7 @@ static void *evp_keyexch_from_algorithm(int name_id, return exchange; - err: +err: EVP_KEYEXCH_free(exchange); return NULL; } @@ -179,23 +179,23 @@ OSSL_PROVIDER *EVP_KEYEXCH_get0_provider(const EVP_KEYEXCH *exchange) } EVP_KEYEXCH *EVP_KEYEXCH_fetch(OSSL_LIB_CTX *ctx, const char *algorithm, - const char *properties) + const char *properties) { return evp_generic_fetch(ctx, OSSL_OP_KEYEXCH, algorithm, properties, - evp_keyexch_from_algorithm, - evp_keyexch_up_ref, - evp_keyexch_free); + evp_keyexch_from_algorithm, + evp_keyexch_up_ref, + evp_keyexch_free); } EVP_KEYEXCH *evp_keyexch_fetch_from_prov(OSSL_PROVIDER *prov, - const char *algorithm, - const char *properties) + const char *algorithm, + const char *properties) { return evp_generic_fetch_from_prov(prov, OSSL_OP_KEYEXCH, - algorithm, properties, - evp_keyexch_from_algorithm, - evp_keyexch_up_ref, - evp_keyexch_free); + algorithm, properties, + evp_keyexch_from_algorithm, + evp_keyexch_up_ref, + evp_keyexch_free); } int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx) @@ -248,20 +248,19 @@ int EVP_PKEY_derive_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]) * Try to derive the supported exch from |ctx->keymgmt|. */ if (!ossl_assert(ctx->pkey->keymgmt == NULL - || ctx->pkey->keymgmt == ctx->keymgmt)) { + || ctx->pkey->keymgmt == ctx->keymgmt)) { ERR_clear_last_mark(); ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR); goto err; } supported_exch = evp_keymgmt_util_query_operation_name(ctx->keymgmt, - OSSL_OP_KEYEXCH); + OSSL_OP_KEYEXCH); if (supported_exch == NULL) { ERR_clear_last_mark(); ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR); goto err; } - /* * We perform two iterations: * @@ -292,16 +291,14 @@ int EVP_PKEY_derive_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]) switch (iter) { case 1: - exchange = - EVP_KEYEXCH_fetch(ctx->libctx, supported_exch, ctx->propquery); + exchange = EVP_KEYEXCH_fetch(ctx->libctx, supported_exch, ctx->propquery); if (exchange != NULL) tmp_prov = EVP_KEYEXCH_get0_provider(exchange); break; case 2: tmp_prov = EVP_KEYMGMT_get0_provider(ctx->keymgmt); - exchange = - evp_keyexch_fetch_from_prov((OSSL_PROVIDER *)tmp_prov, - supported_exch, ctx->propquery); + exchange = evp_keyexch_fetch_from_prov((OSSL_PROVIDER *)tmp_prov, + supported_exch, ctx->propquery); if (exchange == NULL) goto legacy; break; @@ -318,13 +315,12 @@ int EVP_PKEY_derive_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]) * to it (evp_pkey_export_to_provider() is smart enough to only actually * export it if |tmp_keymgmt| is different from |ctx->pkey|'s keymgmt) */ - tmp_keymgmt_tofree = tmp_keymgmt = - evp_keymgmt_fetch_from_prov((OSSL_PROVIDER *)tmp_prov, - EVP_KEYMGMT_get0_name(ctx->keymgmt), - ctx->propquery); + tmp_keymgmt_tofree = tmp_keymgmt = evp_keymgmt_fetch_from_prov((OSSL_PROVIDER *)tmp_prov, + EVP_KEYMGMT_get0_name(ctx->keymgmt), + ctx->propquery); if (tmp_keymgmt != NULL) provkey = evp_pkey_export_to_provider(ctx->pkey, ctx->libctx, - &tmp_keymgmt, ctx->propquery); + &tmp_keymgmt, ctx->propquery); if (tmp_keymgmt == NULL) EVP_KEYMGMT_free(tmp_keymgmt_tofree); } @@ -353,13 +349,13 @@ int EVP_PKEY_derive_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]) EVP_KEYMGMT_free(tmp_keymgmt); return ret ? 1 : 0; - err: +err: evp_pkey_ctx_free_old_ops(ctx); ctx->operation = EVP_PKEY_OP_UNDEFINED; EVP_KEYMGMT_free(tmp_keymgmt); return 0; - legacy: +legacy: /* * If we don't have the full support we need with provided methods, * let's go see if legacy does. @@ -385,7 +381,7 @@ int EVP_PKEY_derive_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]) } int EVP_PKEY_derive_set_peer_ex(EVP_PKEY_CTX *ctx, EVP_PKEY *peer, - int validate_peer) + int validate_peer) { int ret = 0, check; void *provkey = NULL; @@ -424,16 +420,15 @@ int EVP_PKEY_derive_set_peer_ex(EVP_PKEY_CTX *ctx, EVP_PKEY *peer, * to it (evp_pkey_export_to_provider() is smart enough to only actually * export it if |tmp_keymgmt| is different from |peer|'s keymgmt) */ - tmp_keymgmt_tofree = tmp_keymgmt = - evp_keymgmt_fetch_from_prov((OSSL_PROVIDER *) - EVP_KEYEXCH_get0_provider(ctx->op.kex.exchange), - EVP_KEYMGMT_get0_name(ctx->keymgmt), - ctx->propquery); + tmp_keymgmt_tofree = tmp_keymgmt = evp_keymgmt_fetch_from_prov((OSSL_PROVIDER *) + EVP_KEYEXCH_get0_provider(ctx->op.kex.exchange), + EVP_KEYMGMT_get0_name(ctx->keymgmt), + ctx->propquery); if (tmp_keymgmt != NULL) /* A Coverity issue with up_ref/down_ref and free */ /* coverity[pass_freed_arg] */ provkey = evp_pkey_export_to_provider(peer, ctx->libctx, - &tmp_keymgmt, ctx->propquery); + &tmp_keymgmt, ctx->propquery); EVP_KEYMGMT_free(tmp_keymgmt_tofree); /* @@ -447,14 +442,14 @@ int EVP_PKEY_derive_set_peer_ex(EVP_PKEY_CTX *ctx, EVP_PKEY *peer, return ret; goto common; - legacy: +legacy: #ifdef FIPS_MODULE return ret; #else if (ctx->pmeth == NULL || !(ctx->pmeth->derive != NULL - || ctx->pmeth->encrypt != NULL - || ctx->pmeth->decrypt != NULL) + || ctx->pmeth->encrypt != NULL + || ctx->pmeth->decrypt != NULL) || ctx->pmeth->ctrl == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); return -2; @@ -491,8 +486,7 @@ int EVP_PKEY_derive_set_peer_ex(EVP_PKEY_CTX *ctx, EVP_PKEY *peer, * (different key types) is impossible here because it is checked earlier. * -2 is OK for us here, as well as 1, so we can check for 0 only. */ - if (!EVP_PKEY_missing_parameters(peer) && - !EVP_PKEY_parameters_eq(ctx->pkey, peer)) { + if (!EVP_PKEY_missing_parameters(peer) && !EVP_PKEY_parameters_eq(ctx->pkey, peer)) { ERR_raise(ERR_LIB_EVP, EVP_R_DIFFERENT_PARAMETERS); return -1; } @@ -502,7 +496,7 @@ int EVP_PKEY_derive_set_peer_ex(EVP_PKEY_CTX *ctx, EVP_PKEY *peer, return ret; #endif - common: +common: if (!EVP_PKEY_up_ref(peer)) return -1; @@ -535,17 +529,16 @@ int EVP_PKEY_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *pkeylen) goto legacy; ret = ctx->op.kex.exchange->derive(ctx->op.kex.algctx, key, pkeylen, - key != NULL ? *pkeylen : 0); + key != NULL ? *pkeylen : 0); return ret; - legacy: +legacy: if (ctx->pmeth == NULL || ctx->pmeth->derive == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); return -2; } - M_check_autoarg(ctx, key, pkeylen, EVP_F_EVP_PKEY_DERIVE) - return ctx->pmeth->derive(ctx, key, pkeylen); + M_check_autoarg(ctx, key, pkeylen, EVP_F_EVP_PKEY_DERIVE) return ctx->pmeth->derive(ctx, key, pkeylen); } int evp_keyexch_get_number(const EVP_KEYEXCH *keyexch) @@ -566,23 +559,23 @@ const char *EVP_KEYEXCH_get0_description(const EVP_KEYEXCH *keyexch) int EVP_KEYEXCH_is_a(const EVP_KEYEXCH *keyexch, const char *name) { return keyexch != NULL - && evp_is_a(keyexch->prov, keyexch->name_id, NULL, name); + && evp_is_a(keyexch->prov, keyexch->name_id, NULL, name); } void EVP_KEYEXCH_do_all_provided(OSSL_LIB_CTX *libctx, - void (*fn)(EVP_KEYEXCH *keyexch, void *arg), - void *arg) + void (*fn)(EVP_KEYEXCH *keyexch, void *arg), + void *arg) { evp_generic_do_all(libctx, OSSL_OP_KEYEXCH, - (void (*)(void *, void *))fn, arg, - evp_keyexch_from_algorithm, - evp_keyexch_up_ref, - evp_keyexch_free); + (void (*)(void *, void *))fn, arg, + evp_keyexch_from_algorithm, + evp_keyexch_up_ref, + evp_keyexch_free); } int EVP_KEYEXCH_names_do_all(const EVP_KEYEXCH *keyexch, - void (*fn)(const char *name, void *data), - void *data) + void (*fn)(const char *name, void *data), + void *data) { if (keyexch->prov != NULL) return evp_names_do_all(keyexch->prov, keyexch->name_id, fn, data); |
