Skip to content

Commit

Permalink
Return OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY
Browse files Browse the repository at this point in the history
We already have the value and a function to compute it from EC_POINT if
needed, just return it when requested. It is sometimes used by openssl
to get the public point for ECDH.

Signed-off-by: Simo Sorce <[email protected]>
  • Loading branch information
simo5 committed Jul 22, 2024
1 parent a550306 commit 4a00497
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
23 changes: 22 additions & 1 deletion src/keymgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1590,6 +1590,27 @@ static int p11prov_ec_get_params(void *keydata, OSSL_PARAM params[])
p->data_size = pub_y->ulValueLen;
}
}
p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY);
if (p) {
CK_ATTRIBUTE *pub_key;

if (p->data_type != OSSL_PARAM_OCTET_STRING) {
return RET_OSSL_ERR;
}

pub_key = p11prov_obj_get_ec_public_raw(key);
if (!pub_key) {
return RET_OSSL_ERR;
}

p->return_size = pub_key->ulValueLen;
if (p->data) {
if (p->data_size < pub_key->ulValueLen) {
return RET_OSSL_ERR;
}
memcpy(p->data, pub_key->pValue, pub_key->ulValueLen);
}
}

return RET_OSSL_OK;
}
Expand All @@ -1604,8 +1625,8 @@ static const OSSL_PARAM *p11prov_ec_gettable_params(void *provctx)
OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_DEFAULT_DIGEST, NULL, 0),
OSSL_PARAM_BN(OSSL_PKEY_PARAM_EC_PUB_X, NULL, 0),
OSSL_PARAM_BN(OSSL_PKEY_PARAM_EC_PUB_Y, NULL, 0),
OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY, NULL, 0),
/*
* OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY
* OSSL_PKEY_PARAM_EC_DECODED_FROM_EXPLICIT_PARAM
* OSSL_PKEY_PARAM_EC_ENCODING
* OSSL_PKEY_PARAM_EC_POINT_CONVERSION_FORMAT
Expand Down
6 changes: 3 additions & 3 deletions src/objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -2180,17 +2180,17 @@ CK_ATTRIBUTE *p11prov_obj_get_ec_public_raw(P11PROV_OBJ *key)
CK_ATTRIBUTE *pub_key;

if (!key) {
return RET_OSSL_ERR;
return NULL;
}

if (key->data.key.type != CKK_EC) {
P11PROV_raise(key->ctx, CKR_GENERAL_ERROR, "Unsupported key type");
return RET_OSSL_ERR;
return NULL;
}

if (key->class != CKO_PRIVATE_KEY && key->class != CKO_PUBLIC_KEY) {
P11PROV_raise(key->ctx, CKR_GENERAL_ERROR, "Invalid Object Class");
return RET_OSSL_ERR;
return NULL;
}

pub_key = p11prov_obj_get_attr(key, CKA_P11PROV_PUB_KEY);
Expand Down

0 comments on commit 4a00497

Please sign in to comment.