X-Git-Url: https://git.openssl.org/?p=openssl.git;a=blobdiff_plain;f=providers%2Fimplementations%2Fkeymgmt%2Fecx_kmgmt.c;h=221287bff2becd0673b74f0797850fb9c91686a9;hp=121980e277fe7b3f925c7d1562a9514f784debd5;hb=0abae1636d7054266dd20724c0d5e06617d9f679;hpb=ff7262b4f4dfade7d2d6e05dcd3727ecc2bc7a5c diff --git a/providers/implementations/keymgmt/ecx_kmgmt.c b/providers/implementations/keymgmt/ecx_kmgmt.c index 121980e277..221287bff2 100644 --- a/providers/implementations/keymgmt/ecx_kmgmt.c +++ b/providers/implementations/keymgmt/ecx_kmgmt.c @@ -74,9 +74,8 @@ static int ecx_has(void *keydata, int selection) static int ecx_import(void *keydata, int selection, const OSSL_PARAM params[]) { ECX_KEY *key = keydata; - size_t privkeylen = 0, pubkeylen; - const OSSL_PARAM *param_priv_key = NULL, *param_pub_key; - unsigned char *pubkey; + int ok = 1; + int include_private = 0; if (key == NULL) return 0; @@ -84,38 +83,11 @@ static int ecx_import(void *keydata, int selection, const OSSL_PARAM params[]) if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) == 0) return 0; - param_pub_key = - OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PUB_KEY); - - if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) - param_priv_key = - OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PRIV_KEY); - /* - * If a private key is present then a public key must also be present. - * Alternatively we've just got a public key. - */ - if (param_pub_key == NULL) - return 0; - - if (param_priv_key != NULL - && !OSSL_PARAM_get_octet_string(param_priv_key, - (void **)&key->privkey, key->keylen, - &privkeylen)) - return 0; - - pubkey = key->pubkey; - if (!OSSL_PARAM_get_octet_string(param_pub_key, - (void **)&pubkey, - sizeof(key->pubkey), &pubkeylen)) - return 0; - - if (pubkeylen != key->keylen - || (param_priv_key != NULL && privkeylen != key->keylen)) - return 0; - - key->haspubkey = 1; + include_private = ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0); + if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) + ok = ok && ecx_key_fromdata(key, params, include_private); - return 1; + return ok; } static int key_to_params(ECX_KEY *key, OSSL_PARAM_BLD *tmpl)