From: Pauli Date: Tue, 22 Jul 2025 02:09:12 +0000 (+1000) Subject: sm2: update sm asymmetric cipher to use generated param parser X-Git-Tag: openssl-3.6.0-alpha1~158 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ffe236850c31ea882d70e3969002aff53c85b4e3;p=thirdparty%2Fopenssl.git sm2: update sm asymmetric cipher to use generated param parser Reviewed-by: Paul Yang Reviewed-by: Shane Lontis Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/28145) --- diff --git a/providers/implementations/asymciphers/sm2_enc.c.in b/providers/implementations/asymciphers/sm2_enc.c.in index 747190f3f9b..bb99370bd69 100644 --- a/providers/implementations/asymciphers/sm2_enc.c.in +++ b/providers/implementations/asymciphers/sm2_enc.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); +-} #include "internal/deprecated.h" @@ -17,6 +20,7 @@ #include #include #include "crypto/sm2.h" +#include "internal/cryptlib.h" #include "prov/provider_ctx.h" #include "prov/implementations.h" #include "prov/providercommon.h" @@ -154,64 +158,60 @@ static void *sm2_dupctx(void *vpsm2ctx) return dstctx; } +{- produce_param_decoder('sm2_get_ctx_params', + (['ASYM_CIPHER_PARAM_DIGEST', 'digest', 'utf8_string'], + )); -} + static int sm2_get_ctx_params(void *vpsm2ctx, OSSL_PARAM *params) { PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx; - OSSL_PARAM *p; + struct sm2_get_ctx_params_st p; - if (vpsm2ctx == NULL) + if (psm2ctx == NULL || !sm2_get_ctx_params_decoder(params, &p)) return 0; - p = OSSL_PARAM_locate(params, OSSL_ASYM_CIPHER_PARAM_DIGEST); - if (p != NULL) { + if (p.digest != NULL) { const EVP_MD *md = ossl_prov_digest_md(&psm2ctx->md); - if (!OSSL_PARAM_set_utf8_string(p, md == NULL ? "" - : EVP_MD_get0_name(md))) + if (!OSSL_PARAM_set_utf8_string(p.digest, + md == NULL ? "" : EVP_MD_get0_name(md))) return 0; } return 1; } -static const OSSL_PARAM known_gettable_ctx_params[] = { - OSSL_PARAM_utf8_string(OSSL_ASYM_CIPHER_PARAM_DIGEST, NULL, 0), - OSSL_PARAM_END -}; - static const OSSL_PARAM *sm2_gettable_ctx_params(ossl_unused void *vpsm2ctx, ossl_unused void *provctx) { - return known_gettable_ctx_params; + return sm2_get_ctx_params_list; } +{- produce_param_decoder('sm2_set_ctx_params', + (['ASYM_CIPHER_PARAM_DIGEST', 'digest', 'utf8_string'], + ['ASYM_CIPHER_PARAM_PROPERTIES', 'propq', 'utf8_string'], + ['ASYM_CIPHER_PARAM_ENGINE', 'engine', 'utf8_string', 'hidden'], + )); -} + static int sm2_set_ctx_params(void *vpsm2ctx, const OSSL_PARAM params[]) { PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx; + struct sm2_set_ctx_params_st p; - if (psm2ctx == NULL) + if (psm2ctx == NULL || !sm2_set_ctx_params_decoder(params, &p)) return 0; - if (ossl_param_is_empty(params)) - return 1; - if (!ossl_prov_digest_load_from_params(&psm2ctx->md, params, - psm2ctx->libctx)) + if (!ossl_prov_digest_load(&psm2ctx->md, p.digest, p.propq, p.engine, + psm2ctx->libctx)) return 0; return 1; } -static const OSSL_PARAM known_settable_ctx_params[] = { - OSSL_PARAM_utf8_string(OSSL_ASYM_CIPHER_PARAM_DIGEST, NULL, 0), - OSSL_PARAM_utf8_string(OSSL_ASYM_CIPHER_PARAM_PROPERTIES, NULL, 0), - OSSL_PARAM_utf8_string(OSSL_ASYM_CIPHER_PARAM_ENGINE, NULL, 0), - OSSL_PARAM_END -}; - static const OSSL_PARAM *sm2_settable_ctx_params(ossl_unused void *vpsm2ctx, ossl_unused void *provctx) { - return known_settable_ctx_params; + return sm2_set_ctx_params_list; } const OSSL_DISPATCH ossl_sm2_asym_cipher_functions[] = {