From a8aad913ecc632405096b2b61942b2c782cc74f4 Mon Sep 17 00:00:00 2001 From: Oliver Mihatsch Date: Thu, 2 Feb 2023 12:15:14 +0100 Subject: New function EC_GROUP_to_params to convert an EC_GROUP to an array of OSSL_PARAM. Reviewed-by: Tomas Mraz Reviewed-by: Matt Caswell Reviewed-by: Todd Short (Merged from https://github.com/openssl/openssl/pull/20205) --- crypto/ec/ec_lib.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'crypto/ec') diff --git a/crypto/ec/ec_lib.c b/crypto/ec/ec_lib.c index 2e7139cbdd..9e262b427d 100644 --- a/crypto/ec/ec_lib.c +++ b/crypto/ec/ec_lib.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "crypto/ec.h" #include "internal/nelem.h" #include "ec_local.h" @@ -1748,3 +1749,38 @@ EC_GROUP *EC_GROUP_new_from_params(const OSSL_PARAM params[], return group; #endif /* FIPS_MODULE */ } + +OSSL_PARAM *EC_GROUP_to_params(const EC_GROUP *group, OSSL_LIB_CTX *libctx, + const char *propq, BN_CTX *bnctx) +{ + OSSL_PARAM_BLD *tmpl = NULL; + BN_CTX *new_bnctx = NULL; + unsigned char *gen_buf = NULL; + OSSL_PARAM *params = NULL; + + if (group == NULL) + goto err; + + tmpl = OSSL_PARAM_BLD_new(); + if (tmpl == NULL) + goto err; + + if (bnctx == NULL) + bnctx = new_bnctx = BN_CTX_new_ex(libctx); + if (bnctx == NULL) + goto err; + BN_CTX_start(bnctx); + + if (!ossl_ec_group_todata( + group, tmpl, NULL, libctx, propq, bnctx, &gen_buf)) + goto err; + + params = OSSL_PARAM_BLD_to_param(tmpl); + + err: + OSSL_PARAM_BLD_free(tmpl); + OPENSSL_free(gen_buf); + BN_CTX_end(bnctx); + BN_CTX_free(new_bnctx); + return params; +} -- cgit v1.2.3