|
|
971d89 |
From 27088567f4375578e39c5b75b4ceae9dff231962 Mon Sep 17 00:00:00 2001
|
|
|
971d89 |
From: Ingo Franzki <ifranzki@linux.ibm.com>
|
|
|
971d89 |
Date: Tue, 11 Oct 2022 13:46:08 +0200
|
|
|
971d89 |
Subject: [PATCH 01/34] EP11: Unify key-pair generation functions
|
|
|
971d89 |
|
|
|
971d89 |
Unify the DSA and DH key-pair generation functions with those for
|
|
|
971d89 |
RSA, EC and Dilithium. Make sure that the attribute handling is done
|
|
|
971d89 |
in the same sequence for all those functions.
|
|
|
971d89 |
|
|
|
971d89 |
Also remove obsolete parameters for all the key-pair generation functions.
|
|
|
971d89 |
|
|
|
971d89 |
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
|
|
|
971d89 |
---
|
|
|
971d89 |
usr/lib/ep11_stdll/ep11_specific.c | 494 ++++++++++++++-----------------------
|
|
|
971d89 |
1 file changed, 187 insertions(+), 307 deletions(-)
|
|
|
971d89 |
|
|
|
971d89 |
diff --git a/usr/lib/ep11_stdll/ep11_specific.c b/usr/lib/ep11_stdll/ep11_specific.c
|
|
|
971d89 |
index a6a33719..5d7c5607 100644
|
|
|
971d89 |
--- a/usr/lib/ep11_stdll/ep11_specific.c
|
|
|
971d89 |
+++ b/usr/lib/ep11_stdll/ep11_specific.c
|
|
|
971d89 |
@@ -5374,15 +5374,10 @@ error:
|
|
|
971d89 |
|
|
|
971d89 |
|
|
|
971d89 |
|
|
|
971d89 |
-static CK_RV dh_generate_keypair(STDLL_TokData_t * tokdata,
|
|
|
971d89 |
- SESSION * sess,
|
|
|
971d89 |
+static CK_RV dh_generate_keypair(STDLL_TokData_t *tokdata,
|
|
|
971d89 |
+ SESSION *sess,
|
|
|
971d89 |
CK_MECHANISM_PTR pMechanism,
|
|
|
971d89 |
- TEMPLATE * publ_tmpl, TEMPLATE * priv_tmpl,
|
|
|
971d89 |
- CK_ATTRIBUTE_PTR pPublicKeyTemplate,
|
|
|
971d89 |
- CK_ULONG ulPublicKeyAttributeCount,
|
|
|
971d89 |
- CK_ATTRIBUTE_PTR pPrivateKeyTemplate,
|
|
|
971d89 |
- CK_ULONG ulPrivateKeyAttributeCount,
|
|
|
971d89 |
- CK_SESSION_HANDLE h)
|
|
|
971d89 |
+ TEMPLATE *publ_tmpl, TEMPLATE *priv_tmpl)
|
|
|
971d89 |
{
|
|
|
971d89 |
CK_RV rc;
|
|
|
971d89 |
CK_BYTE publblob[MAX_BLOBSIZE];
|
|
|
971d89 |
@@ -5399,9 +5394,6 @@ static CK_RV dh_generate_keypair(STDLL_TokData_t * tokdata,
|
|
|
971d89 |
CK_ULONG dh_ulPublicKeyAttributeCount = 0;
|
|
|
971d89 |
CK_ATTRIBUTE_PTR dh_pPrivateKeyTemplate = NULL;
|
|
|
971d89 |
CK_ULONG dh_ulPrivateKeyAttributeCount = 0;
|
|
|
971d89 |
- size_t p_len = 0, g_len = 0;
|
|
|
971d89 |
- int new_public_attr;
|
|
|
971d89 |
- CK_ULONG i;
|
|
|
971d89 |
CK_ULONG data_len;
|
|
|
971d89 |
CK_ULONG field_len;
|
|
|
971d89 |
CK_BYTE *data;
|
|
|
971d89 |
@@ -5421,149 +5413,122 @@ static CK_RV dh_generate_keypair(STDLL_TokData_t * tokdata,
|
|
|
971d89 |
unsigned char *pg;
|
|
|
971d89 |
} dh_pgs;
|
|
|
971d89 |
|
|
|
971d89 |
- UNUSED(h);
|
|
|
971d89 |
-
|
|
|
971d89 |
memset(&dh_pgs, 0, sizeof(dh_pgs));
|
|
|
971d89 |
memset(publblob, 0, sizeof(publblob));
|
|
|
971d89 |
memset(privblob, 0, sizeof(privblob));
|
|
|
971d89 |
|
|
|
971d89 |
- /* card does not want CKA_PRIME/CKA_BASE in template but in dh_pgs */
|
|
|
971d89 |
- pPublicKeyTemplate_new =
|
|
|
971d89 |
- (CK_ATTRIBUTE *) malloc(sizeof(CK_ATTRIBUTE) *
|
|
|
971d89 |
- ulPublicKeyAttributeCount);
|
|
|
971d89 |
- if (!pPublicKeyTemplate_new) {
|
|
|
971d89 |
- TRACE_ERROR("%s Memory allocation failed\n", __func__);
|
|
|
971d89 |
- return CKR_HOST_MEMORY;
|
|
|
971d89 |
- }
|
|
|
971d89 |
- memset(pPublicKeyTemplate_new, 0,
|
|
|
971d89 |
- sizeof(CK_ATTRIBUTE) * ulPublicKeyAttributeCount);
|
|
|
971d89 |
-
|
|
|
971d89 |
- for (i = 0, new_public_attr = 0; i < ulPublicKeyAttributeCount; i++) {
|
|
|
971d89 |
- /* filter out CKA_PRIME/CKA_BASE,
|
|
|
971d89 |
- * but remember where they can be found
|
|
|
971d89 |
- */
|
|
|
971d89 |
- switch (pPublicKeyTemplate[i].type) {
|
|
|
971d89 |
- case CKA_PRIME:
|
|
|
971d89 |
- prime_attr = &(pPublicKeyTemplate[i]);
|
|
|
971d89 |
- p_len = pPublicKeyTemplate[i].ulValueLen;
|
|
|
971d89 |
- break;
|
|
|
971d89 |
- case CKA_BASE:
|
|
|
971d89 |
- base_attr = &(pPublicKeyTemplate[i]);
|
|
|
971d89 |
- g_len = pPublicKeyTemplate[i].ulValueLen;
|
|
|
971d89 |
- break;
|
|
|
971d89 |
- default:
|
|
|
971d89 |
- /* copy all other attributes */
|
|
|
971d89 |
- memcpy(&pPublicKeyTemplate_new[new_public_attr],
|
|
|
971d89 |
- &(pPublicKeyTemplate[i]), sizeof(CK_ATTRIBUTE));
|
|
|
971d89 |
- new_public_attr++;
|
|
|
971d89 |
- }
|
|
|
971d89 |
+ rc = build_ep11_attrs(tokdata, publ_tmpl, &dh_pPublicKeyTemplate,
|
|
|
971d89 |
+ &dh_ulPublicKeyAttributeCount,
|
|
|
971d89 |
+ CKK_DH, CKO_PUBLIC_KEY, -1, pMechanism);
|
|
|
971d89 |
+ if (rc != CKR_OK) {
|
|
|
971d89 |
+ TRACE_ERROR("%s build_ep11_attrs failed with rc=0x%lx\n", __func__, rc);
|
|
|
971d89 |
+ goto dh_generate_keypair_end;
|
|
|
971d89 |
}
|
|
|
971d89 |
|
|
|
971d89 |
- if (prime_attr == NULL || base_attr == NULL) {
|
|
|
971d89 |
- TRACE_ERROR("%s Incomplete template prime_attr=%p base_attr=%p\n",
|
|
|
971d89 |
- __func__, (void *)prime_attr, (void *)base_attr);
|
|
|
971d89 |
- rc = CKR_TEMPLATE_INCOMPLETE;
|
|
|
971d89 |
+ rc = build_ep11_attrs(tokdata, priv_tmpl, &dh_pPrivateKeyTemplate,
|
|
|
971d89 |
+ &dh_ulPrivateKeyAttributeCount,
|
|
|
971d89 |
+ CKK_DH, CKO_PRIVATE_KEY, -1, pMechanism);
|
|
|
971d89 |
+ if (rc != CKR_OK) {
|
|
|
971d89 |
+ TRACE_ERROR("%s build_ep11_attrs failed with rc=0x%lx\n", __func__, rc);
|
|
|
971d89 |
goto dh_generate_keypair_end;
|
|
|
971d89 |
}
|
|
|
971d89 |
|
|
|
971d89 |
- /* copy CKA_PRIME/CKA_BASE to private template */
|
|
|
971d89 |
- rc = build_attribute(CKA_PRIME, prime_attr->pValue,
|
|
|
971d89 |
- prime_attr->ulValueLen, &attr);
|
|
|
971d89 |
+ rc = check_key_attributes(tokdata, CKK_DH, CKO_PUBLIC_KEY,
|
|
|
971d89 |
+ dh_pPublicKeyTemplate,
|
|
|
971d89 |
+ dh_ulPublicKeyAttributeCount,
|
|
|
971d89 |
+ &new_publ_attrs, &new_publ_attrs_len, -1);
|
|
|
971d89 |
if (rc != CKR_OK) {
|
|
|
971d89 |
- TRACE_ERROR("%s build_attribute failed with rc=0x%lx\n", __func__, rc);
|
|
|
971d89 |
+ TRACE_ERROR("%s DH check public key attributes failed with "
|
|
|
971d89 |
+ "rc=0x%lx\n", __func__, rc);
|
|
|
971d89 |
goto dh_generate_keypair_end;
|
|
|
971d89 |
}
|
|
|
971d89 |
- rc = template_update_attribute(priv_tmpl, attr);
|
|
|
971d89 |
+
|
|
|
971d89 |
+ rc = check_key_attributes(tokdata, CKK_DH, CKO_PRIVATE_KEY,
|
|
|
971d89 |
+ dh_pPrivateKeyTemplate,
|
|
|
971d89 |
+ dh_ulPrivateKeyAttributeCount,
|
|
|
971d89 |
+ &new_priv_attrs, &new_priv_attrs_len, -1);
|
|
|
971d89 |
if (rc != CKR_OK) {
|
|
|
971d89 |
- TRACE_ERROR("%s template_update_attribute failed with rc=0x%lx\n",
|
|
|
971d89 |
- __func__, rc);
|
|
|
971d89 |
- free(attr);
|
|
|
971d89 |
+ TRACE_ERROR("%s DH check private key attributes failed with "
|
|
|
971d89 |
+ "rc=0x%lx\n", __func__, rc);
|
|
|
971d89 |
goto dh_generate_keypair_end;
|
|
|
971d89 |
}
|
|
|
971d89 |
- rc = build_attribute(CKA_BASE, base_attr->pValue,
|
|
|
971d89 |
- base_attr->ulValueLen, &attr);
|
|
|
971d89 |
+
|
|
|
971d89 |
+ /* card does not want CKA_PRIME/CKA_BASE in template but in dh_pgs */
|
|
|
971d89 |
+ rc = template_attribute_get_non_empty(publ_tmpl, CKA_PRIME,
|
|
|
971d89 |
+ &prime_attr);
|
|
|
971d89 |
if (rc != CKR_OK) {
|
|
|
971d89 |
- TRACE_ERROR("%s build_attribute failed with rc=0x%lx\n", __func__, rc);
|
|
|
971d89 |
+ TRACE_ERROR("%s DH No CKA_PRIME attribute found\n", __func__);
|
|
|
971d89 |
goto dh_generate_keypair_end;
|
|
|
971d89 |
}
|
|
|
971d89 |
- rc = template_update_attribute(priv_tmpl, attr);
|
|
|
971d89 |
+
|
|
|
971d89 |
+ rc = template_attribute_get_non_empty(publ_tmpl, CKA_BASE,
|
|
|
971d89 |
+ &base_attr);
|
|
|
971d89 |
if (rc != CKR_OK) {
|
|
|
971d89 |
- TRACE_ERROR("%s template_update_attribute failed with rc=0x%lx\n",
|
|
|
971d89 |
- __func__, rc);
|
|
|
971d89 |
- free(attr);
|
|
|
971d89 |
+ TRACE_ERROR("%s DH No CKA_BASE attribute found\n", __func__);
|
|
|
971d89 |
goto dh_generate_keypair_end;
|
|
|
971d89 |
}
|
|
|
971d89 |
|
|
|
971d89 |
- /* copy CKA_PRIME/CKA_BASE values */
|
|
|
971d89 |
- dh_pgs.pg = malloc(p_len * 2);
|
|
|
971d89 |
+ dh_pgs.pg = malloc(prime_attr->ulValueLen * 2);
|
|
|
971d89 |
if (!dh_pgs.pg) {
|
|
|
971d89 |
TRACE_ERROR("%s Memory allocation failed\n", __func__);
|
|
|
971d89 |
rc = CKR_HOST_MEMORY;
|
|
|
971d89 |
goto dh_generate_keypair_end;
|
|
|
971d89 |
}
|
|
|
971d89 |
- memset(dh_pgs.pg, 0, p_len * 2);
|
|
|
971d89 |
- memcpy(dh_pgs.pg, prime_attr->pValue, p_len); /* copy CKA_PRIME value */
|
|
|
971d89 |
+
|
|
|
971d89 |
+ memset(dh_pgs.pg, 0, prime_attr->ulValueLen * 2);
|
|
|
971d89 |
+ /* copy CKA_PRIME value */
|
|
|
971d89 |
+ memcpy(dh_pgs.pg, prime_attr->pValue, prime_attr->ulValueLen);
|
|
|
971d89 |
/* copy CKA_BASE value, it must have leading zeros
|
|
|
971d89 |
* if it is shorter than CKA_PRIME
|
|
|
971d89 |
*/
|
|
|
971d89 |
- memcpy(dh_pgs.pg + p_len + (p_len - g_len), base_attr->pValue, g_len);
|
|
|
971d89 |
- dh_pgs.pg_bytes = p_len * 2;
|
|
|
971d89 |
+ memcpy(dh_pgs.pg + prime_attr->ulValueLen +
|
|
|
971d89 |
+ (prime_attr->ulValueLen - base_attr->ulValueLen),
|
|
|
971d89 |
+ base_attr->pValue, base_attr->ulValueLen);
|
|
|
971d89 |
+ dh_pgs.pg_bytes = prime_attr->ulValueLen * 2;
|
|
|
971d89 |
|
|
|
971d89 |
#ifdef DEBUG
|
|
|
971d89 |
TRACE_DEBUG("%s P:\n", __func__);
|
|
|
971d89 |
- TRACE_DEBUG_DUMP(" ", &dh_pgs.pg[0], p_len);
|
|
|
971d89 |
+ TRACE_DEBUG_DUMP(" ", &dh_pgs.pg[0], prime_attr->ulValueLen);
|
|
|
971d89 |
TRACE_DEBUG("%s G:\n", __func__);
|
|
|
971d89 |
- TRACE_DEBUG_DUMP(" ", &dh_pgs.pg[p_len], p_len);
|
|
|
971d89 |
+ TRACE_DEBUG_DUMP(" ", &dh_pgs.pg[prime_attr->ulValueLen],
|
|
|
971d89 |
+ prime_attr->ulValueLen);
|
|
|
971d89 |
#endif
|
|
|
971d89 |
|
|
|
971d89 |
- /* add special attribute, do not add it to ock's pPublicKeyTemplate */
|
|
|
971d89 |
- CK_ATTRIBUTE pgs[] = { {CKA_IBM_STRUCT_PARAMS, (CK_VOID_PTR) dh_pgs.pg,
|
|
|
971d89 |
- dh_pgs.pg_bytes}
|
|
|
971d89 |
- };
|
|
|
971d89 |
- memcpy(&(pPublicKeyTemplate_new[new_public_attr]),
|
|
|
971d89 |
- &(pgs[0]), sizeof(CK_ATTRIBUTE));
|
|
|
971d89 |
-
|
|
|
971d89 |
- rc = check_key_attributes(tokdata, CKK_DH, CKO_PUBLIC_KEY,
|
|
|
971d89 |
- pPublicKeyTemplate_new, new_public_attr + 1,
|
|
|
971d89 |
- &dh_pPublicKeyTemplate,
|
|
|
971d89 |
- &dh_ulPublicKeyAttributeCount, -1);
|
|
|
971d89 |
+ rc = add_to_attribute_array(&new_publ_attrs, &new_publ_attrs_len,
|
|
|
971d89 |
+ CKA_IBM_STRUCT_PARAMS, dh_pgs.pg,
|
|
|
971d89 |
+ dh_pgs.pg_bytes);
|
|
|
971d89 |
if (rc != CKR_OK) {
|
|
|
971d89 |
- TRACE_ERROR("%s DH check public key attributes failed with "
|
|
|
971d89 |
- "rc=0x%lx\n", __func__, rc);
|
|
|
971d89 |
+ TRACE_ERROR("%s add_to_attribute_array failed with rc=0x%lx\n",
|
|
|
971d89 |
+ __func__, rc);
|
|
|
971d89 |
goto dh_generate_keypair_end;
|
|
|
971d89 |
}
|
|
|
971d89 |
|
|
|
971d89 |
- rc = check_key_attributes(tokdata, CKK_DH, CKO_PRIVATE_KEY,
|
|
|
971d89 |
- pPrivateKeyTemplate, ulPrivateKeyAttributeCount,
|
|
|
971d89 |
- &dh_pPrivateKeyTemplate,
|
|
|
971d89 |
- &dh_ulPrivateKeyAttributeCount, -1);
|
|
|
971d89 |
+ /* copy CKA_PRIME/CKA_BASE to private template */
|
|
|
971d89 |
+ rc = build_attribute(CKA_PRIME, prime_attr->pValue,
|
|
|
971d89 |
+ prime_attr->ulValueLen, &attr);
|
|
|
971d89 |
if (rc != CKR_OK) {
|
|
|
971d89 |
- TRACE_ERROR("%s DH check private key attributes failed with "
|
|
|
971d89 |
- "rc=0x%lx\n", __func__, rc);
|
|
|
971d89 |
+ TRACE_ERROR("%s build_attribute failed with rc=0x%lx\n", __func__, rc);
|
|
|
971d89 |
goto dh_generate_keypair_end;
|
|
|
971d89 |
}
|
|
|
971d89 |
-
|
|
|
971d89 |
- rc = build_ep11_attrs(tokdata, publ_tmpl,
|
|
|
971d89 |
- &new_publ_attrs, &new_publ_attrs_len,
|
|
|
971d89 |
- CKK_DH, CKO_PUBLIC_KEY, -1, pMechanism);
|
|
|
971d89 |
+ rc = template_update_attribute(priv_tmpl, attr);
|
|
|
971d89 |
if (rc != CKR_OK) {
|
|
|
971d89 |
- TRACE_ERROR("%s build_ep11_attrs failed with rc=0x%lx\n", __func__, rc);
|
|
|
971d89 |
+ TRACE_ERROR("%s template_update_attribute failed with rc=0x%lx\n",
|
|
|
971d89 |
+ __func__, rc);
|
|
|
971d89 |
+ free(attr);
|
|
|
971d89 |
goto dh_generate_keypair_end;
|
|
|
971d89 |
}
|
|
|
971d89 |
|
|
|
971d89 |
- rc = add_to_attribute_array(&new_publ_attrs, &new_publ_attrs_len,
|
|
|
971d89 |
- CKA_IBM_STRUCT_PARAMS, (CK_VOID_PTR) dh_pgs.pg,
|
|
|
971d89 |
- dh_pgs.pg_bytes);
|
|
|
971d89 |
+ rc = build_attribute(CKA_BASE, base_attr->pValue,
|
|
|
971d89 |
+ base_attr->ulValueLen, &attr);
|
|
|
971d89 |
if (rc != CKR_OK) {
|
|
|
971d89 |
- TRACE_ERROR("%s add_to_attribute_array failed with rc=0x%lx\n", __func__, rc);
|
|
|
971d89 |
+ TRACE_ERROR("%s build_attribute failed with rc=0x%lx\n", __func__, rc);
|
|
|
971d89 |
goto dh_generate_keypair_end;
|
|
|
971d89 |
}
|
|
|
971d89 |
-
|
|
|
971d89 |
- rc = build_ep11_attrs(tokdata, priv_tmpl,
|
|
|
971d89 |
- &new_priv_attrs, &new_priv_attrs_len,
|
|
|
971d89 |
- CKK_DH, CKO_PRIVATE_KEY, -1, pMechanism);
|
|
|
971d89 |
+ rc = template_update_attribute(priv_tmpl, attr);
|
|
|
971d89 |
if (rc != CKR_OK) {
|
|
|
971d89 |
- TRACE_ERROR("%s build_ep11_attrs failed with rc=0x%lx\n", __func__, rc);
|
|
|
971d89 |
+ TRACE_ERROR("%s template_update_attribute failed with rc=0x%lx\n",
|
|
|
971d89 |
+ __func__, rc);
|
|
|
971d89 |
+ free(attr);
|
|
|
971d89 |
goto dh_generate_keypair_end;
|
|
|
971d89 |
}
|
|
|
971d89 |
|
|
|
971d89 |
@@ -5573,10 +5538,10 @@ static CK_RV dh_generate_keypair(STDLL_TokData_t * tokdata,
|
|
|
971d89 |
new_priv_attrs, new_priv_attrs_len);
|
|
|
971d89 |
|
|
|
971d89 |
ep11_get_pin_blob(ep11_session,
|
|
|
971d89 |
- (ep11_is_session_object
|
|
|
971d89 |
- (pPublicKeyTemplate, ulPublicKeyAttributeCount)
|
|
|
971d89 |
- || ep11_is_session_object(pPrivateKeyTemplate,
|
|
|
971d89 |
- ulPrivateKeyAttributeCount)),
|
|
|
971d89 |
+ (ep11_is_session_object(new_publ_attrs,
|
|
|
971d89 |
+ new_publ_attrs_len) ||
|
|
|
971d89 |
+ ep11_is_session_object(new_priv_attrs,
|
|
|
971d89 |
+ new_priv_attrs_len)),
|
|
|
971d89 |
&ep11_pin_blob, &ep11_pin_blob_len);
|
|
|
971d89 |
|
|
|
971d89 |
RETRY_START(rc, tokdata)
|
|
|
971d89 |
@@ -5595,7 +5560,7 @@ static CK_RV dh_generate_keypair(STDLL_TokData_t * tokdata,
|
|
|
971d89 |
}
|
|
|
971d89 |
|
|
|
971d89 |
TRACE_INFO("%s rc=0x%lx plen=%zd publblobsize=0x%zx privblobsize=0x%zx\n",
|
|
|
971d89 |
- __func__, rc, p_len, publblobsize, privblobsize);
|
|
|
971d89 |
+ __func__, rc, prime_attr->ulValueLen, publblobsize, privblobsize);
|
|
|
971d89 |
|
|
|
971d89 |
if (check_expected_mkvp(tokdata, privblob, privblobsize) != CKR_OK) {
|
|
|
971d89 |
TRACE_ERROR("%s\n", ock_err(ERR_DEVICE_ERROR));
|
|
|
971d89 |
@@ -5700,15 +5665,10 @@ dh_generate_keypair_end:
|
|
|
971d89 |
return rc;
|
|
|
971d89 |
}
|
|
|
971d89 |
|
|
|
971d89 |
-static CK_RV dsa_generate_keypair(STDLL_TokData_t * tokdata,
|
|
|
971d89 |
- SESSION * sess,
|
|
|
971d89 |
+static CK_RV dsa_generate_keypair(STDLL_TokData_t *tokdata,
|
|
|
971d89 |
+ SESSION *sess,
|
|
|
971d89 |
CK_MECHANISM_PTR pMechanism,
|
|
|
971d89 |
- TEMPLATE * publ_tmpl, TEMPLATE * priv_tmpl,
|
|
|
971d89 |
- CK_ATTRIBUTE_PTR pPublicKeyTemplate,
|
|
|
971d89 |
- CK_ULONG ulPublicKeyAttributeCount,
|
|
|
971d89 |
- CK_ATTRIBUTE_PTR pPrivateKeyTemplate,
|
|
|
971d89 |
- CK_ULONG ulPrivateKeyAttributeCount,
|
|
|
971d89 |
- CK_SESSION_HANDLE h)
|
|
|
971d89 |
+ TEMPLATE *publ_tmpl, TEMPLATE *priv_tmpl)
|
|
|
971d89 |
{
|
|
|
971d89 |
CK_RV rc;
|
|
|
971d89 |
CK_BYTE publblob[MAX_BLOBSIZE];
|
|
|
971d89 |
@@ -5721,9 +5681,6 @@ static CK_RV dsa_generate_keypair(STDLL_TokData_t * tokdata,
|
|
|
971d89 |
CK_ATTRIBUTE *opaque_attr = NULL;
|
|
|
971d89 |
CK_ATTRIBUTE *value_attr = NULL;
|
|
|
971d89 |
CK_ATTRIBUTE *attr = NULL;
|
|
|
971d89 |
- size_t p_len = 0, q_len = 0, g_len = 0;
|
|
|
971d89 |
- int new_public_attr;
|
|
|
971d89 |
- CK_ULONG i;
|
|
|
971d89 |
CK_ATTRIBUTE *pPublicKeyTemplate_new = NULL;
|
|
|
971d89 |
CK_BYTE *key;
|
|
|
971d89 |
CK_BYTE *data, *oid, *parm;
|
|
|
971d89 |
@@ -5737,8 +5694,6 @@ static CK_RV dsa_generate_keypair(STDLL_TokData_t * tokdata,
|
|
|
971d89 |
ep11_session_t *ep11_session = (ep11_session_t *) sess->private_data;
|
|
|
971d89 |
CK_ATTRIBUTE *new_publ_attrs = NULL, *new_priv_attrs = NULL;
|
|
|
971d89 |
CK_ULONG new_publ_attrs_len = 0, new_priv_attrs_len = 0;
|
|
|
971d89 |
- CK_ATTRIBUTE *new_publ_attrs2 = NULL, *new_priv_attrs2 = NULL;
|
|
|
971d89 |
- CK_ULONG new_publ_attrs2_len = 0, new_priv_attrs2_len = 0;
|
|
|
971d89 |
|
|
|
971d89 |
/* ep11 accepts CKA_PRIME,CKA_SUBPRIME,CKA_BASE only in this format */
|
|
|
971d89 |
struct {
|
|
|
971d89 |
@@ -5746,95 +5701,68 @@ static CK_RV dsa_generate_keypair(STDLL_TokData_t * tokdata,
|
|
|
971d89 |
unsigned char *pqg;
|
|
|
971d89 |
} dsa_pqgs;
|
|
|
971d89 |
|
|
|
971d89 |
- UNUSED(h);
|
|
|
971d89 |
-
|
|
|
971d89 |
memset(&dsa_pqgs, 0, sizeof(dsa_pqgs));
|
|
|
971d89 |
memset(publblob, 0, sizeof(publblob));
|
|
|
971d89 |
memset(privblob, 0, sizeof(privblob));
|
|
|
971d89 |
|
|
|
971d89 |
- /* card does not want CKA_PRIME/CKA_BASE/CKA_SUBPRIME
|
|
|
971d89 |
- * in template but in dsa_pqgs
|
|
|
971d89 |
- */
|
|
|
971d89 |
- pPublicKeyTemplate_new =
|
|
|
971d89 |
- (CK_ATTRIBUTE *) malloc(sizeof(CK_ATTRIBUTE) *
|
|
|
971d89 |
- ulPublicKeyAttributeCount);
|
|
|
971d89 |
- if (!pPublicKeyTemplate_new) {
|
|
|
971d89 |
- TRACE_ERROR("%s Memory allocation failed\n", __func__);
|
|
|
971d89 |
- return CKR_HOST_MEMORY;
|
|
|
971d89 |
- }
|
|
|
971d89 |
- memset(pPublicKeyTemplate_new, 0,
|
|
|
971d89 |
- sizeof(CK_ATTRIBUTE) * ulPublicKeyAttributeCount);
|
|
|
971d89 |
-
|
|
|
971d89 |
- for (i = 0, new_public_attr = 0; i < ulPublicKeyAttributeCount; i++) {
|
|
|
971d89 |
- switch (pPublicKeyTemplate[i].type) {
|
|
|
971d89 |
- case CKA_PRIME:
|
|
|
971d89 |
- prime_attr = &(pPublicKeyTemplate[i]);
|
|
|
971d89 |
- p_len = pPublicKeyTemplate[i].ulValueLen;
|
|
|
971d89 |
- break;
|
|
|
971d89 |
- case CKA_SUBPRIME:
|
|
|
971d89 |
- sub_prime_attr = &(pPublicKeyTemplate[i]);
|
|
|
971d89 |
- q_len = pPublicKeyTemplate[i].ulValueLen;
|
|
|
971d89 |
- break;
|
|
|
971d89 |
- case CKA_BASE:
|
|
|
971d89 |
- base_attr = &(pPublicKeyTemplate[i]);
|
|
|
971d89 |
- g_len = pPublicKeyTemplate[i].ulValueLen;
|
|
|
971d89 |
- break;
|
|
|
971d89 |
- default:
|
|
|
971d89 |
- /* copy all other attributes */
|
|
|
971d89 |
- memcpy(&pPublicKeyTemplate_new[new_public_attr],
|
|
|
971d89 |
- &(pPublicKeyTemplate[i]), sizeof(CK_ATTRIBUTE));
|
|
|
971d89 |
- new_public_attr++;
|
|
|
971d89 |
- }
|
|
|
971d89 |
- }
|
|
|
971d89 |
-
|
|
|
971d89 |
- if (prime_attr == NULL || sub_prime_attr == NULL || base_attr == NULL) {
|
|
|
971d89 |
- rc = CKR_TEMPLATE_INCOMPLETE;
|
|
|
971d89 |
+ rc = build_ep11_attrs(tokdata, publ_tmpl, &dsa_pPublicKeyTemplate,
|
|
|
971d89 |
+ &dsa_ulPublicKeyAttributeCount,
|
|
|
971d89 |
+ CKK_DSA, CKO_PUBLIC_KEY, -1, pMechanism);
|
|
|
971d89 |
+ if (rc != CKR_OK) {
|
|
|
971d89 |
+ TRACE_ERROR("%s build_ep11_attrs failed with rc=0x%lx\n", __func__, rc);
|
|
|
971d89 |
goto dsa_generate_keypair_end;
|
|
|
971d89 |
}
|
|
|
971d89 |
|
|
|
971d89 |
- /* copy CKA_PRIME/CKA_BASE/CKA_SUBPRIME to private template */
|
|
|
971d89 |
- rc = build_attribute(CKA_PRIME, prime_attr->pValue,
|
|
|
971d89 |
- prime_attr->ulValueLen, &attr);
|
|
|
971d89 |
+ rc = build_ep11_attrs(tokdata, priv_tmpl, &dsa_pPrivateKeyTemplate,
|
|
|
971d89 |
+ &dsa_ulPrivateKeyAttributeCount,
|
|
|
971d89 |
+ CKK_DSA, CKO_PRIVATE_KEY, -1, pMechanism);
|
|
|
971d89 |
if (rc != CKR_OK) {
|
|
|
971d89 |
- TRACE_ERROR("%s build_attribute failed with rc=0x%lx\n", __func__, rc);
|
|
|
971d89 |
+ TRACE_ERROR("%s build_ep11_attrs failed with rc=0x%lx\n", __func__, rc);
|
|
|
971d89 |
goto dsa_generate_keypair_end;
|
|
|
971d89 |
}
|
|
|
971d89 |
|
|
|
971d89 |
- rc = template_update_attribute(priv_tmpl, attr);
|
|
|
971d89 |
+ rc = check_key_attributes(tokdata, CKK_DSA, CKO_PUBLIC_KEY,
|
|
|
971d89 |
+ dsa_pPublicKeyTemplate,
|
|
|
971d89 |
+ dsa_ulPublicKeyAttributeCount,
|
|
|
971d89 |
+ &new_publ_attrs, &new_publ_attrs_len, -1);
|
|
|
971d89 |
if (rc != CKR_OK) {
|
|
|
971d89 |
- TRACE_ERROR("%s template_update_attribute failed with rc=0x%lx\n",
|
|
|
971d89 |
- __func__, rc);
|
|
|
971d89 |
- free(attr);
|
|
|
971d89 |
+ TRACE_ERROR("%s DSA check public key attributes failed with "
|
|
|
971d89 |
+ "rc=0x%lx\n", __func__, rc);
|
|
|
971d89 |
goto dsa_generate_keypair_end;
|
|
|
971d89 |
}
|
|
|
971d89 |
|
|
|
971d89 |
- rc = build_attribute(CKA_BASE, base_attr->pValue,
|
|
|
971d89 |
- base_attr->ulValueLen, &attr);
|
|
|
971d89 |
+ rc = check_key_attributes(tokdata, CKK_DSA, CKO_PRIVATE_KEY,
|
|
|
971d89 |
+ dsa_pPrivateKeyTemplate,
|
|
|
971d89 |
+ dsa_ulPrivateKeyAttributeCount,
|
|
|
971d89 |
+ &new_priv_attrs, &new_priv_attrs_len, -1);
|
|
|
971d89 |
if (rc != CKR_OK) {
|
|
|
971d89 |
- TRACE_ERROR("%s build_attribute failed with rc=0x%lx\n", __func__, rc);
|
|
|
971d89 |
+ TRACE_ERROR("%s DSA check private key attributes failed with "
|
|
|
971d89 |
+ "rc=0x%lx\n", __func__, rc);
|
|
|
971d89 |
goto dsa_generate_keypair_end;
|
|
|
971d89 |
}
|
|
|
971d89 |
|
|
|
971d89 |
- rc = template_update_attribute(priv_tmpl, attr);
|
|
|
971d89 |
+ /*
|
|
|
971d89 |
+ * card does not want CKA_PRIME/CKA_BASE/CKA_SUBPRIME in template but in
|
|
|
971d89 |
+ * dsa_pqgs
|
|
|
971d89 |
+ */
|
|
|
971d89 |
+ rc = template_attribute_get_non_empty(publ_tmpl, CKA_PRIME,
|
|
|
971d89 |
+ &prime_attr);
|
|
|
971d89 |
if (rc != CKR_OK) {
|
|
|
971d89 |
- TRACE_ERROR("%s template_update_attribute failed with rc=0x%lx\n",
|
|
|
971d89 |
- __func__, rc);
|
|
|
971d89 |
- free(attr);
|
|
|
971d89 |
+ TRACE_ERROR("%s DSA No CKA_PRIME attribute found\n", __func__);
|
|
|
971d89 |
goto dsa_generate_keypair_end;
|
|
|
971d89 |
}
|
|
|
971d89 |
|
|
|
971d89 |
- rc = build_attribute(CKA_SUBPRIME, sub_prime_attr->pValue,
|
|
|
971d89 |
- sub_prime_attr->ulValueLen, &attr);
|
|
|
971d89 |
+ rc = template_attribute_get_non_empty(publ_tmpl, CKA_SUBPRIME,
|
|
|
971d89 |
+ &sub_prime_attr);
|
|
|
971d89 |
if (rc != CKR_OK) {
|
|
|
971d89 |
- TRACE_ERROR("%s build_attribute failed with rc=0x%lx\n", __func__, rc);
|
|
|
971d89 |
+ TRACE_ERROR("%s DSA No CKA_SUBPRIME attribute found\n", __func__);
|
|
|
971d89 |
goto dsa_generate_keypair_end;
|
|
|
971d89 |
}
|
|
|
971d89 |
|
|
|
971d89 |
- rc = template_update_attribute(priv_tmpl, attr);
|
|
|
971d89 |
+ rc = template_attribute_get_non_empty(publ_tmpl, CKA_BASE,
|
|
|
971d89 |
+ &base_attr);
|
|
|
971d89 |
if (rc != CKR_OK) {
|
|
|
971d89 |
- TRACE_ERROR("%s template_update_attribute failed with rc=0x%lx\n",
|
|
|
971d89 |
- __func__, rc);
|
|
|
971d89 |
- free(attr);
|
|
|
971d89 |
+ TRACE_ERROR("%s DSA No CKA_BASE attribute found\n", __func__);
|
|
|
971d89 |
goto dsa_generate_keypair_end;
|
|
|
971d89 |
}
|
|
|
971d89 |
|
|
|
971d89 |
@@ -5842,95 +5770,102 @@ static CK_RV dsa_generate_keypair(STDLL_TokData_t * tokdata,
|
|
|
971d89 |
* then they are extented by leading zeros till they have
|
|
|
971d89 |
* the size of CKA_PRIME
|
|
|
971d89 |
*/
|
|
|
971d89 |
- dsa_pqgs.pqg = malloc(p_len * 3);
|
|
|
971d89 |
+ dsa_pqgs.pqg = malloc(prime_attr->ulValueLen * 3);
|
|
|
971d89 |
if (!dsa_pqgs.pqg) {
|
|
|
971d89 |
TRACE_ERROR("%s Memory allocation failed\n", __func__);
|
|
|
971d89 |
rc = CKR_HOST_MEMORY;
|
|
|
971d89 |
goto dsa_generate_keypair_end;
|
|
|
971d89 |
}
|
|
|
971d89 |
- memset(dsa_pqgs.pqg, 0, p_len * 3);
|
|
|
971d89 |
- memcpy(dsa_pqgs.pqg, prime_attr->pValue, p_len);
|
|
|
971d89 |
- memcpy(dsa_pqgs.pqg + p_len + (p_len - q_len),
|
|
|
971d89 |
- sub_prime_attr->pValue, q_len);
|
|
|
971d89 |
- memcpy(dsa_pqgs.pqg + 2 * p_len + (p_len - g_len),
|
|
|
971d89 |
- base_attr->pValue, g_len);
|
|
|
971d89 |
- dsa_pqgs.pqg_bytes = p_len * 3;
|
|
|
971d89 |
+
|
|
|
971d89 |
+ memset(dsa_pqgs.pqg, 0, prime_attr->ulValueLen * 3);
|
|
|
971d89 |
+ memcpy(dsa_pqgs.pqg, prime_attr->pValue, prime_attr->ulValueLen);
|
|
|
971d89 |
+ memcpy(dsa_pqgs.pqg + prime_attr->ulValueLen +
|
|
|
971d89 |
+ (prime_attr->ulValueLen - sub_prime_attr->ulValueLen),
|
|
|
971d89 |
+ sub_prime_attr->pValue, sub_prime_attr->ulValueLen);
|
|
|
971d89 |
+ memcpy(dsa_pqgs.pqg + 2 * prime_attr->ulValueLen +
|
|
|
971d89 |
+ (prime_attr->ulValueLen - base_attr->ulValueLen),
|
|
|
971d89 |
+ base_attr->pValue, base_attr->ulValueLen);
|
|
|
971d89 |
+ dsa_pqgs.pqg_bytes = prime_attr->ulValueLen * 3;
|
|
|
971d89 |
|
|
|
971d89 |
#ifdef DEBUG
|
|
|
971d89 |
TRACE_DEBUG("%s P:\n", __func__);
|
|
|
971d89 |
- TRACE_DEBUG_DUMP(" ", &dsa_pqgs.pqg[0], p_len);
|
|
|
971d89 |
+ TRACE_DEBUG_DUMP(" ", &dsa_pqgs.pqg[0], prime_attr->ulValueLen);
|
|
|
971d89 |
TRACE_DEBUG("%s Q:\n", __func__);
|
|
|
971d89 |
- TRACE_DEBUG_DUMP(" ", &dsa_pqgs.pqg[p_len], p_len);
|
|
|
971d89 |
+ TRACE_DEBUG_DUMP(" ", &dsa_pqgs.pqg[prime_attr->ulValueLen],
|
|
|
971d89 |
+ prime_attr->ulValueLen);
|
|
|
971d89 |
TRACE_DEBUG("%s G:\n", __func__);
|
|
|
971d89 |
- TRACE_DEBUG_DUMP(" ", &dsa_pqgs.pqg[2 * p_len], p_len);
|
|
|
971d89 |
+ TRACE_DEBUG_DUMP(" ", &dsa_pqgs.pqg[2 * prime_attr->ulValueLen],
|
|
|
971d89 |
+ prime_attr->ulValueLen);
|
|
|
971d89 |
#endif
|
|
|
971d89 |
|
|
|
971d89 |
- CK_ATTRIBUTE pqgs[] = { {CKA_IBM_STRUCT_PARAMS,
|
|
|
971d89 |
- (CK_VOID_PTR) dsa_pqgs.pqg, dsa_pqgs.pqg_bytes}
|
|
|
971d89 |
- };
|
|
|
971d89 |
-
|
|
|
971d89 |
- /* add special attribute, do not add it to ock's pPublicKeyTemplate */
|
|
|
971d89 |
- memcpy(&(pPublicKeyTemplate_new[new_public_attr]),
|
|
|
971d89 |
- &(pqgs[0]), sizeof(CK_ATTRIBUTE));
|
|
|
971d89 |
-
|
|
|
971d89 |
- rc = build_ep11_attrs(tokdata, publ_tmpl,
|
|
|
971d89 |
- &new_publ_attrs, &new_publ_attrs_len,
|
|
|
971d89 |
- CKK_DSA, CKO_PUBLIC_KEY, -1, pMechanism);
|
|
|
971d89 |
+ rc = add_to_attribute_array(&new_publ_attrs, &new_publ_attrs_len,
|
|
|
971d89 |
+ CKA_IBM_STRUCT_PARAMS, dsa_pqgs.pqg,
|
|
|
971d89 |
+ dsa_pqgs.pqg_bytes);
|
|
|
971d89 |
if (rc != CKR_OK) {
|
|
|
971d89 |
- TRACE_ERROR("%s build_ep11_attrs failed with rc=0x%lx\n", __func__, rc);
|
|
|
971d89 |
+ TRACE_ERROR("%s add_to_attribute_array failed with rc=0x%lx\n",
|
|
|
971d89 |
+ __func__, rc);
|
|
|
971d89 |
goto dsa_generate_keypair_end;
|
|
|
971d89 |
}
|
|
|
971d89 |
|
|
|
971d89 |
- rc = check_key_attributes(tokdata, CKK_DSA, CKO_PUBLIC_KEY,
|
|
|
971d89 |
- new_publ_attrs, new_publ_attrs_len,
|
|
|
971d89 |
- &new_publ_attrs2, &new_publ_attrs2_len, -1);
|
|
|
971d89 |
+ /* copy CKA_PRIME/CKA_BASE/CKA_SUBPRIME to private template */
|
|
|
971d89 |
+ rc = build_attribute(CKA_PRIME, prime_attr->pValue,
|
|
|
971d89 |
+ prime_attr->ulValueLen, &attr);
|
|
|
971d89 |
if (rc != CKR_OK) {
|
|
|
971d89 |
- TRACE_ERROR("%s DSA check public key attributes failed with "
|
|
|
971d89 |
- "rc=0x%lx\n", __func__, rc);
|
|
|
971d89 |
+ TRACE_ERROR("%s build_attribute failed with rc=0x%lx\n", __func__, rc);
|
|
|
971d89 |
goto dsa_generate_keypair_end;
|
|
|
971d89 |
}
|
|
|
971d89 |
-
|
|
|
971d89 |
- rc = add_to_attribute_array(&new_publ_attrs2, &new_publ_attrs2_len,
|
|
|
971d89 |
- CKA_IBM_STRUCT_PARAMS, (CK_VOID_PTR) dsa_pqgs.pqg,
|
|
|
971d89 |
- dsa_pqgs.pqg_bytes);
|
|
|
971d89 |
+ rc = template_update_attribute(priv_tmpl, attr);
|
|
|
971d89 |
if (rc != CKR_OK) {
|
|
|
971d89 |
- TRACE_ERROR("%s add_to_attribute_array failed with rc=0x%lx\n", __func__, rc);
|
|
|
971d89 |
+ TRACE_ERROR("%s template_update_attribute failed with rc=0x%lx\n",
|
|
|
971d89 |
+ __func__, rc);
|
|
|
971d89 |
+ free(attr);
|
|
|
971d89 |
goto dsa_generate_keypair_end;
|
|
|
971d89 |
}
|
|
|
971d89 |
|
|
|
971d89 |
- rc = build_ep11_attrs(tokdata, priv_tmpl,
|
|
|
971d89 |
- &new_priv_attrs, &new_priv_attrs_len,
|
|
|
971d89 |
- CKK_DSA, CKO_PRIVATE_KEY, -1, pMechanism);
|
|
|
971d89 |
+ rc = build_attribute(CKA_SUBPRIME, sub_prime_attr->pValue,
|
|
|
971d89 |
+ sub_prime_attr->ulValueLen, &attr);
|
|
|
971d89 |
if (rc != CKR_OK) {
|
|
|
971d89 |
- TRACE_ERROR("%s build_ep11_attrs failed with rc=0x%lx\n", __func__, rc);
|
|
|
971d89 |
+ TRACE_ERROR("%s build_attribute failed with rc=0x%lx\n", __func__, rc);
|
|
|
971d89 |
+ goto dsa_generate_keypair_end;
|
|
|
971d89 |
+ }
|
|
|
971d89 |
+ rc = template_update_attribute(priv_tmpl, attr);
|
|
|
971d89 |
+ if (rc != CKR_OK) {
|
|
|
971d89 |
+ TRACE_ERROR("%s template_update_attribute failed with rc=0x%lx\n",
|
|
|
971d89 |
+ __func__, rc);
|
|
|
971d89 |
+ free(attr);
|
|
|
971d89 |
goto dsa_generate_keypair_end;
|
|
|
971d89 |
}
|
|
|
971d89 |
|
|
|
971d89 |
- rc = check_key_attributes(tokdata, CKK_DSA, CKO_PRIVATE_KEY,
|
|
|
971d89 |
- new_priv_attrs, new_priv_attrs_len,
|
|
|
971d89 |
- &new_priv_attrs2, &new_priv_attrs2_len, -1);
|
|
|
971d89 |
+ rc = build_attribute(CKA_BASE, base_attr->pValue,
|
|
|
971d89 |
+ base_attr->ulValueLen, &attr);
|
|
|
971d89 |
if (rc != CKR_OK) {
|
|
|
971d89 |
- TRACE_ERROR("%s DSA check private key attributes failed with "
|
|
|
971d89 |
- "rc=0x%lx\n", __func__, rc);
|
|
|
971d89 |
+ TRACE_ERROR("%s build_attribute failed with rc=0x%lx\n", __func__, rc);
|
|
|
971d89 |
+ goto dsa_generate_keypair_end;
|
|
|
971d89 |
+ }
|
|
|
971d89 |
+ rc = template_update_attribute(priv_tmpl, attr);
|
|
|
971d89 |
+ if (rc != CKR_OK) {
|
|
|
971d89 |
+ TRACE_ERROR("%s template_update_attribute failed with rc=0x%lx\n",
|
|
|
971d89 |
+ __func__, rc);
|
|
|
971d89 |
+ free(attr);
|
|
|
971d89 |
goto dsa_generate_keypair_end;
|
|
|
971d89 |
}
|
|
|
971d89 |
|
|
|
971d89 |
trace_attributes(__func__, "DSA public key attributes:",
|
|
|
971d89 |
- new_publ_attrs2, new_publ_attrs2_len);
|
|
|
971d89 |
+ new_publ_attrs, new_publ_attrs_len);
|
|
|
971d89 |
trace_attributes(__func__, "DSA private key attributes:",
|
|
|
971d89 |
- new_priv_attrs2, new_priv_attrs2_len);
|
|
|
971d89 |
+ new_priv_attrs, new_priv_attrs_len);
|
|
|
971d89 |
|
|
|
971d89 |
ep11_get_pin_blob(ep11_session,
|
|
|
971d89 |
- (ep11_is_session_object
|
|
|
971d89 |
- (pPublicKeyTemplate, ulPublicKeyAttributeCount)
|
|
|
971d89 |
- || ep11_is_session_object(pPrivateKeyTemplate,
|
|
|
971d89 |
- ulPrivateKeyAttributeCount)),
|
|
|
971d89 |
+ (ep11_is_session_object(new_publ_attrs,
|
|
|
971d89 |
+ new_publ_attrs_len) ||
|
|
|
971d89 |
+ ep11_is_session_object(new_priv_attrs,
|
|
|
971d89 |
+ new_priv_attrs_len)),
|
|
|
971d89 |
&ep11_pin_blob, &ep11_pin_blob_len);
|
|
|
971d89 |
|
|
|
971d89 |
RETRY_START(rc, tokdata)
|
|
|
971d89 |
rc = dll_m_GenerateKeyPair(pMechanism,
|
|
|
971d89 |
- new_publ_attrs2, new_publ_attrs2_len,
|
|
|
971d89 |
- new_priv_attrs2, new_priv_attrs2_len,
|
|
|
971d89 |
+ new_publ_attrs, new_publ_attrs_len,
|
|
|
971d89 |
+ new_priv_attrs, new_priv_attrs_len,
|
|
|
971d89 |
ep11_pin_blob, ep11_pin_blob_len, privblob,
|
|
|
971d89 |
&privblobsize, publblob, &publblobsize,
|
|
|
971d89 |
target_info->target);
|
|
|
971d89 |
@@ -5943,10 +5878,8 @@ static CK_RV dsa_generate_keypair(STDLL_TokData_t * tokdata,
|
|
|
971d89 |
goto dsa_generate_keypair_end;
|
|
|
971d89 |
}
|
|
|
971d89 |
|
|
|
971d89 |
- TRACE_INFO("%s rc=0x%lx p_len=%zd publblobsize=0x%zx privblobsize=0x%zx "
|
|
|
971d89 |
- "npattr=0x%x\n",
|
|
|
971d89 |
- __func__, rc, p_len, publblobsize, privblobsize,
|
|
|
971d89 |
- new_public_attr + 1);
|
|
|
971d89 |
+ TRACE_INFO("%s rc=0x%lx plen=%zd publblobsize=0x%zx privblobsize=0x%zx\n",
|
|
|
971d89 |
+ __func__, rc, prime_attr->ulValueLen, publblobsize, privblobsize);
|
|
|
971d89 |
|
|
|
971d89 |
if (check_expected_mkvp(tokdata, privblob, privblobsize) != CKR_OK) {
|
|
|
971d89 |
TRACE_ERROR("%s\n", ock_err(ERR_DEVICE_ERROR));
|
|
|
971d89 |
@@ -6030,22 +5963,13 @@ dsa_generate_keypair_end:
|
|
|
971d89 |
free_attribute_array(new_publ_attrs, new_publ_attrs_len);
|
|
|
971d89 |
if (new_priv_attrs)
|
|
|
971d89 |
free_attribute_array(new_priv_attrs, new_priv_attrs_len);
|
|
|
971d89 |
- if (new_publ_attrs2)
|
|
|
971d89 |
- free_attribute_array(new_publ_attrs2, new_publ_attrs2_len);
|
|
|
971d89 |
- if (new_priv_attrs)
|
|
|
971d89 |
- free_attribute_array(new_priv_attrs2, new_priv_attrs2_len);
|
|
|
971d89 |
return rc;
|
|
|
971d89 |
}
|
|
|
971d89 |
|
|
|
971d89 |
-static CK_RV rsa_ec_generate_keypair(STDLL_TokData_t * tokdata,
|
|
|
971d89 |
- SESSION * sess,
|
|
|
971d89 |
+static CK_RV rsa_ec_generate_keypair(STDLL_TokData_t *tokdata,
|
|
|
971d89 |
+ SESSION *sess,
|
|
|
971d89 |
CK_MECHANISM_PTR pMechanism,
|
|
|
971d89 |
- TEMPLATE * publ_tmpl, TEMPLATE * priv_tmpl,
|
|
|
971d89 |
- CK_ATTRIBUTE_PTR pPublicKeyTemplate,
|
|
|
971d89 |
- CK_ULONG ulPublicKeyAttributeCount,
|
|
|
971d89 |
- CK_ATTRIBUTE_PTR pPrivateKeyTemplate,
|
|
|
971d89 |
- CK_ULONG ulPrivateKeyAttributeCount,
|
|
|
971d89 |
- CK_SESSION_HANDLE h)
|
|
|
971d89 |
+ TEMPLATE *publ_tmpl, TEMPLATE *priv_tmpl)
|
|
|
971d89 |
{
|
|
|
971d89 |
CK_RV rc;
|
|
|
971d89 |
CK_ATTRIBUTE *attr = NULL;
|
|
|
971d89 |
@@ -6054,7 +5978,6 @@ static CK_RV rsa_ec_generate_keypair(STDLL_TokData_t * tokdata,
|
|
|
971d89 |
size_t privkey_blob_len = sizeof(privkey_blob);
|
|
|
971d89 |
unsigned char spki[MAX_BLOBSIZE];
|
|
|
971d89 |
size_t spki_len = sizeof(spki);
|
|
|
971d89 |
- CK_ULONG i;
|
|
|
971d89 |
CK_ULONG bit_str_len;
|
|
|
971d89 |
CK_BYTE *key;
|
|
|
971d89 |
CK_BYTE *data, *oid, *parm;
|
|
|
971d89 |
@@ -6074,8 +5997,6 @@ static CK_RV rsa_ec_generate_keypair(STDLL_TokData_t * tokdata,
|
|
|
971d89 |
CK_ULONG new_publ_attrs2_len = 0, new_priv_attrs2_len = 0;
|
|
|
971d89 |
const struct _ec *curve = NULL;
|
|
|
971d89 |
|
|
|
971d89 |
- UNUSED(h);
|
|
|
971d89 |
-
|
|
|
971d89 |
if (pMechanism->mechanism == CKM_EC_KEY_PAIR_GEN) {
|
|
|
971d89 |
ktype = CKK_EC;
|
|
|
971d89 |
} else if ((pMechanism->mechanism == CKM_RSA_PKCS_KEY_PAIR_GEN) ||
|
|
|
971d89 |
@@ -6132,24 +6053,16 @@ static CK_RV rsa_ec_generate_keypair(STDLL_TokData_t * tokdata,
|
|
|
971d89 |
goto error;
|
|
|
971d89 |
}
|
|
|
971d89 |
|
|
|
971d89 |
- /* debug */
|
|
|
971d89 |
- for (i = 0; i < new_ulPrivateKeyAttributeCount; i++) {
|
|
|
971d89 |
- TRACE_INFO("%s gen priv attr type=0x%lx valuelen=0x%lx attrcnt=0x%lx\n",
|
|
|
971d89 |
- __func__, new_pPrivateKeyTemplate[i].type,
|
|
|
971d89 |
- new_pPrivateKeyTemplate[i].ulValueLen,
|
|
|
971d89 |
- new_ulPrivateKeyAttributeCount);
|
|
|
971d89 |
- }
|
|
|
971d89 |
-
|
|
|
971d89 |
trace_attributes(__func__, "RSA/EC public key attributes:",
|
|
|
971d89 |
new_publ_attrs2, new_publ_attrs2_len);
|
|
|
971d89 |
trace_attributes(__func__, "RSA/EC private key attributes:",
|
|
|
971d89 |
new_priv_attrs2, new_priv_attrs2_len);
|
|
|
971d89 |
|
|
|
971d89 |
ep11_get_pin_blob(ep11_session,
|
|
|
971d89 |
- (ep11_is_session_object
|
|
|
971d89 |
- (pPublicKeyTemplate, ulPublicKeyAttributeCount)
|
|
|
971d89 |
- || ep11_is_session_object(pPrivateKeyTemplate,
|
|
|
971d89 |
- ulPrivateKeyAttributeCount)),
|
|
|
971d89 |
+ (ep11_is_session_object(new_publ_attrs2,
|
|
|
971d89 |
+ new_publ_attrs2_len) ||
|
|
|
971d89 |
+ ep11_is_session_object(new_priv_attrs2,
|
|
|
971d89 |
+ new_priv_attrs2_len)),
|
|
|
971d89 |
&ep11_pin_blob, &ep11_pin_blob_len);
|
|
|
971d89 |
|
|
|
971d89 |
RETRY_START(rc, tokdata)
|
|
|
971d89 |
@@ -6406,15 +6319,10 @@ error:
|
|
|
971d89 |
return rc;
|
|
|
971d89 |
}
|
|
|
971d89 |
|
|
|
971d89 |
-static CK_RV ibm_dilithium_generate_keypair(STDLL_TokData_t * tokdata,
|
|
|
971d89 |
- SESSION * sess,
|
|
|
971d89 |
+static CK_RV ibm_dilithium_generate_keypair(STDLL_TokData_t *tokdata,
|
|
|
971d89 |
+ SESSION *sess,
|
|
|
971d89 |
CK_MECHANISM_PTR pMechanism,
|
|
|
971d89 |
- TEMPLATE * publ_tmpl, TEMPLATE * priv_tmpl,
|
|
|
971d89 |
- CK_ATTRIBUTE_PTR pPublicKeyTemplate,
|
|
|
971d89 |
- CK_ULONG ulPublicKeyAttributeCount,
|
|
|
971d89 |
- CK_ATTRIBUTE_PTR pPrivateKeyTemplate,
|
|
|
971d89 |
- CK_ULONG ulPrivateKeyAttributeCount,
|
|
|
971d89 |
- CK_SESSION_HANDLE h)
|
|
|
971d89 |
+ TEMPLATE *publ_tmpl, TEMPLATE *priv_tmpl)
|
|
|
971d89 |
{
|
|
|
971d89 |
CK_RV rc;
|
|
|
971d89 |
CK_ATTRIBUTE *attr = NULL;
|
|
|
971d89 |
@@ -6422,7 +6330,6 @@ static CK_RV ibm_dilithium_generate_keypair(STDLL_TokData_t * tokdata,
|
|
|
971d89 |
size_t privkey_blob_len = sizeof(privkey_blob);
|
|
|
971d89 |
unsigned char spki[MAX_BLOBSIZE];
|
|
|
971d89 |
size_t spki_len = sizeof(spki);
|
|
|
971d89 |
- CK_ULONG i;
|
|
|
971d89 |
CK_ULONG bit_str_len;
|
|
|
971d89 |
CK_BYTE *key;
|
|
|
971d89 |
CK_BYTE *data, *oid, *parm;
|
|
|
971d89 |
@@ -6444,8 +6351,6 @@ static CK_RV ibm_dilithium_generate_keypair(STDLL_TokData_t * tokdata,
|
|
|
971d89 |
const CK_BYTE dilithium_oid[] = { 0x06, 0x0b, 0x2b, 0x06, 0x01, 0x04, 0x01,
|
|
|
971d89 |
0x02, 0x82, 0x0b, 0x01, 0x06, 0x05 };
|
|
|
971d89 |
|
|
|
971d89 |
- UNUSED(h);
|
|
|
971d89 |
-
|
|
|
971d89 |
if (pMechanism->mechanism != CKM_IBM_DILITHIUM) {
|
|
|
971d89 |
TRACE_ERROR("Invalid mechanism provided for %s\n ", __func__);
|
|
|
971d89 |
return CKR_MECHANISM_INVALID;
|
|
|
971d89 |
@@ -6503,24 +6408,16 @@ static CK_RV ibm_dilithium_generate_keypair(STDLL_TokData_t * tokdata,
|
|
|
971d89 |
goto error;
|
|
|
971d89 |
}
|
|
|
971d89 |
|
|
|
971d89 |
- /* debug */
|
|
|
971d89 |
- for (i = 0; i < new_ulPrivateKeyAttributeCount; i++) {
|
|
|
971d89 |
- TRACE_INFO("%s gen priv attr type=0x%lx valuelen=0x%lx attrcnt=0x%lx\n",
|
|
|
971d89 |
- __func__, new_pPrivateKeyTemplate[i].type,
|
|
|
971d89 |
- new_pPrivateKeyTemplate[i].ulValueLen,
|
|
|
971d89 |
- new_ulPrivateKeyAttributeCount);
|
|
|
971d89 |
- }
|
|
|
971d89 |
-
|
|
|
971d89 |
trace_attributes(__func__, "Dilithium public key attributes:",
|
|
|
971d89 |
new_publ_attrs2, new_publ_attrs2_len);
|
|
|
971d89 |
trace_attributes(__func__, "Dilithium private key attributes:",
|
|
|
971d89 |
new_priv_attrs2, new_priv_attrs2_len);
|
|
|
971d89 |
|
|
|
971d89 |
ep11_get_pin_blob(ep11_session,
|
|
|
971d89 |
- (ep11_is_session_object
|
|
|
971d89 |
- (pPublicKeyTemplate, ulPublicKeyAttributeCount)
|
|
|
971d89 |
- || ep11_is_session_object(pPrivateKeyTemplate,
|
|
|
971d89 |
- ulPrivateKeyAttributeCount)),
|
|
|
971d89 |
+ (ep11_is_session_object(new_publ_attrs2,
|
|
|
971d89 |
+ new_publ_attrs2_len) ||
|
|
|
971d89 |
+ ep11_is_session_object(new_priv_attrs2,
|
|
|
971d89 |
+ new_priv_attrs2_len)),
|
|
|
971d89 |
&ep11_pin_blob, &ep11_pin_blob_len);
|
|
|
971d89 |
|
|
|
971d89 |
RETRY_START(rc, tokdata)
|
|
|
971d89 |
@@ -6763,42 +6660,25 @@ CK_RV ep11tok_generate_key_pair(STDLL_TokData_t * tokdata, SESSION * sess,
|
|
|
971d89 |
case CKM_DH_PKCS_KEY_PAIR_GEN:
|
|
|
971d89 |
rc = dh_generate_keypair(tokdata, sess, pMechanism,
|
|
|
971d89 |
public_key_obj->template,
|
|
|
971d89 |
- private_key_obj->template,
|
|
|
971d89 |
- pPublicKeyTemplate,
|
|
|
971d89 |
- ulPublicKeyAttributeCount,
|
|
|
971d89 |
- pPrivateKeyTemplate,
|
|
|
971d89 |
- ulPrivateKeyAttributeCount, sess->handle);
|
|
|
971d89 |
+ private_key_obj->template);
|
|
|
971d89 |
break;
|
|
|
971d89 |
case CKM_EC_KEY_PAIR_GEN: /* takes same parameters as RSA */
|
|
|
971d89 |
case CKM_RSA_PKCS_KEY_PAIR_GEN:
|
|
|
971d89 |
case CKM_RSA_X9_31_KEY_PAIR_GEN:
|
|
|
971d89 |
rc = rsa_ec_generate_keypair(tokdata, sess, pMechanism,
|
|
|
971d89 |
public_key_obj->template,
|
|
|
971d89 |
- private_key_obj->template,
|
|
|
971d89 |
- pPublicKeyTemplate,
|
|
|
971d89 |
- ulPublicKeyAttributeCount,
|
|
|
971d89 |
- pPrivateKeyTemplate,
|
|
|
971d89 |
- ulPrivateKeyAttributeCount, sess->handle);
|
|
|
971d89 |
+ private_key_obj->template);
|
|
|
971d89 |
break;
|
|
|
971d89 |
case CKM_DSA_PARAMETER_GEN:
|
|
|
971d89 |
case CKM_DSA_KEY_PAIR_GEN:
|
|
|
971d89 |
rc = dsa_generate_keypair(tokdata, sess, pMechanism,
|
|
|
971d89 |
public_key_obj->template,
|
|
|
971d89 |
- private_key_obj->template,
|
|
|
971d89 |
- pPublicKeyTemplate,
|
|
|
971d89 |
- ulPublicKeyAttributeCount,
|
|
|
971d89 |
- pPrivateKeyTemplate,
|
|
|
971d89 |
- ulPrivateKeyAttributeCount, sess->handle);
|
|
|
971d89 |
+ private_key_obj->template);
|
|
|
971d89 |
break;
|
|
|
971d89 |
case CKM_IBM_DILITHIUM:
|
|
|
971d89 |
rc = ibm_dilithium_generate_keypair(tokdata, sess, pMechanism,
|
|
|
971d89 |
public_key_obj->template,
|
|
|
971d89 |
- private_key_obj->template,
|
|
|
971d89 |
- pPublicKeyTemplate,
|
|
|
971d89 |
- ulPublicKeyAttributeCount,
|
|
|
971d89 |
- pPrivateKeyTemplate,
|
|
|
971d89 |
- ulPrivateKeyAttributeCount,
|
|
|
971d89 |
- sess->handle);
|
|
|
971d89 |
+ private_key_obj->template);
|
|
|
971d89 |
break;
|
|
|
971d89 |
default:
|
|
|
971d89 |
TRACE_ERROR("%s invalid mech %s\n", __func__,
|
|
|
971d89 |
--
|
|
|
971d89 |
2.16.2.windows.1
|
|
|
971d89 |
|