diff options
author | Tomas Mraz <tomas@openssl.org> | 2021-03-25 14:57:16 +0100 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2021-03-26 16:11:09 +0100 |
commit | bf5b37cedf373a6fde496e1f7bb0a63db29a6cd2 (patch) | |
tree | 97a98310fa656109df799a8311bc515cd90d7c64 /providers | |
parent | cede07dc51728edce77336f0fe5fce6d62ed7654 (diff) |
Make the SM2 group the default group for the SM2 algorithm
Fixes #14481
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14684)
Diffstat (limited to 'providers')
-rw-r--r-- | providers/implementations/keymgmt/ec_kmgmt.c | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/providers/implementations/keymgmt/ec_kmgmt.c b/providers/implementations/keymgmt/ec_kmgmt.c index b8aa518a08..ed1b412225 100644 --- a/providers/implementations/keymgmt/ec_kmgmt.c +++ b/providers/implementations/keymgmt/ec_kmgmt.c @@ -57,6 +57,8 @@ static OSSL_FUNC_keymgmt_export_types_fn ec_export_types; static OSSL_FUNC_keymgmt_query_operation_name_fn ec_query_operation_name; #ifndef FIPS_MODULE # ifndef OPENSSL_NO_SM2 +static OSSL_FUNC_keymgmt_new_fn sm2_newdata; +static OSSL_FUNC_keymgmt_gen_init_fn sm2_gen_init; static OSSL_FUNC_keymgmt_gen_fn sm2_gen; static OSSL_FUNC_keymgmt_get_params_fn sm2_get_params; static OSSL_FUNC_keymgmt_gettable_params_fn sm2_gettable_params; @@ -271,6 +273,18 @@ void *ec_newdata(void *provctx) return EC_KEY_new_ex(PROV_LIBCTX_OF(provctx), NULL); } +#ifndef FIPS_MODULE +# ifndef OPENSSL_NO_SM2 +static +void *sm2_newdata(void *provctx) +{ + if (!ossl_prov_is_running()) + return NULL; + return EC_KEY_new_by_curve_name_ex(PROV_LIBCTX_OF(provctx), NULL, NID_sm2); +} +# endif +#endif + static void ec_freedata(void *keydata) { @@ -956,6 +970,26 @@ static void *ec_gen_init(void *provctx, int selection, return gctx; } +#ifndef FIPS_MODULE +# ifndef OPENSSL_NO_SM2 +static void *sm2_gen_init(void *provctx, int selection, + const OSSL_PARAM params[]) +{ + struct ec_gen_ctx *gctx = ec_gen_init(provctx, selection, params); + + if (gctx != NULL) { + if (gctx->group_name != NULL) + return gctx; + if ((gctx->group_name = OPENSSL_strdup("sm2")) != NULL) + return gctx; + ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE); + ec_gen_cleanup(gctx); + } + return NULL; +} +# endif +#endif + static int ec_gen_set_group(void *genctx, const EC_GROUP *src) { struct ec_gen_ctx *gctx = genctx; @@ -1358,8 +1392,8 @@ const OSSL_DISPATCH ossl_ec_keymgmt_functions[] = { #ifndef FIPS_MODULE # ifndef OPENSSL_NO_SM2 const OSSL_DISPATCH ossl_sm2_keymgmt_functions[] = { - { OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))ec_newdata }, - { OSSL_FUNC_KEYMGMT_GEN_INIT, (void (*)(void))ec_gen_init }, + { OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))sm2_newdata }, + { OSSL_FUNC_KEYMGMT_GEN_INIT, (void (*)(void))sm2_gen_init }, { OSSL_FUNC_KEYMGMT_GEN_SET_TEMPLATE, (void (*)(void))ec_gen_set_template }, { OSSL_FUNC_KEYMGMT_GEN_SET_PARAMS, (void (*)(void))ec_gen_set_params }, |