From: Pauli Date: Fri, 25 Jul 2025 03:15:26 +0000 (+1000) Subject: ec kem: convert to using generated param decoders X-Git-Tag: openssl-3.6.0-alpha1~147 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c90eb152687f0f6023b14c05faef887a1fa225fd;p=thirdparty%2Fopenssl.git ec kem: convert to using generated param decoders Reviewed-by: Paul Yang Reviewed-by: Shane Lontis Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/28149) --- diff --git a/providers/implementations/kem/ec_kem.c.in b/providers/implementations/kem/ec_kem.c.in index 86fe6b73b03..ef73e9ceb30 100644 --- a/providers/implementations/kem/ec_kem.c.in +++ b/providers/implementations/kem/ec_kem.c.in @@ -6,6 +6,9 @@ * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ +{- +use OpenSSL::paramnames qw(produce_param_decoder); +-} /* * The following implementation is part of RFC 9180 related to DHKEM using @@ -25,6 +28,7 @@ #include #include #include +#include "internal/cryptlib.h" #include "prov/provider_ctx.h" #include "prov/implementations.h" #include "prov/securitycheck.h" @@ -284,22 +288,27 @@ static int eckem_auth_decapsulate_init(void *vctx, void *vecx, void *vauthpub, return eckem_init(vctx, EVP_PKEY_OP_DECAPSULATE, vecx, vauthpub, params); } + +{- produce_param_decoder('eckem_set_ctx_params', + (['KEM_PARAM_OPERATION', 'op', 'utf8_string'], + ['KEM_PARAM_IKME', 'ikme', 'octet_string'], + )); -} + static int eckem_set_ctx_params(void *vctx, const OSSL_PARAM params[]) { PROV_EC_CTX *ctx = (PROV_EC_CTX *)vctx; - const OSSL_PARAM *p; + struct eckem_set_ctx_params_st p; int mode; - if (ossl_param_is_empty(params)) - return 1; + if (ctx == NULL || !eckem_set_ctx_params_decoder(params, &p)) + return 0; - p = OSSL_PARAM_locate_const(params, OSSL_KEM_PARAM_IKME); - if (p != NULL) { + if (p.ikme != NULL) { void *tmp = NULL; size_t tmplen = 0; - if (p->data != NULL && p->data_size != 0) { - if (!OSSL_PARAM_get_octet_string(p, &tmp, 0, &tmplen)) + if (p.ikme->data != NULL && p.ikme->data_size != 0) { + if (!OSSL_PARAM_get_octet_string(p.ikme, &tmp, 0, &tmplen)) return 0; } OPENSSL_clear_free(ctx->ikm, ctx->ikmlen); @@ -308,11 +317,10 @@ static int eckem_set_ctx_params(void *vctx, const OSSL_PARAM params[]) ctx->ikmlen = tmplen; } - p = OSSL_PARAM_locate_const(params, OSSL_KEM_PARAM_OPERATION); - if (p != NULL) { - if (p->data_type != OSSL_PARAM_UTF8_STRING) + if (p.op != NULL) { + if (p.op->data_type != OSSL_PARAM_UTF8_STRING) return 0; - mode = ossl_eckem_modename2id(p->data); + mode = ossl_eckem_modename2id(p.op->data); if (mode == KEM_MODE_UNDEFINED) return 0; ctx->mode = mode; @@ -320,16 +328,10 @@ static int eckem_set_ctx_params(void *vctx, const OSSL_PARAM params[]) return 1; } -static const OSSL_PARAM known_settable_eckem_ctx_params[] = { - OSSL_PARAM_utf8_string(OSSL_KEM_PARAM_OPERATION, NULL, 0), - OSSL_PARAM_octet_string(OSSL_KEM_PARAM_IKME, NULL, 0), - OSSL_PARAM_END -}; - static const OSSL_PARAM *eckem_settable_ctx_params(ossl_unused void *vctx, ossl_unused void *provctx) { - return known_settable_eckem_ctx_params; + return eckem_set_ctx_params_list; } /*