|
|
253609 |
From c6d6be8b7c1c1fa346af420daada56e28da5af6d Mon Sep 17 00:00:00 2001
|
|
|
253609 |
From: Ingo Franzki <ifranzki@linux.ibm.com>
|
|
|
253609 |
Date: Fri, 4 Nov 2022 09:44:35 +0100
|
|
|
253609 |
Subject: [PATCH 06/34] EP11: Pass back chain code for CKM_IBM_BTC_DERIVE
|
|
|
253609 |
|
|
|
253609 |
When deriving a key using CKM_IBM_BTC_DERIVE, the resulting chain code
|
|
|
253609 |
must be passed back in the buffer supplied by the caller in the
|
|
|
253609 |
mechanism parameter (field pChainCode in CK_IBM_BTC_DERIVE_PARAMS).
|
|
|
253609 |
This chain code can then be used to derive further keys from the just
|
|
|
253609 |
derived key.
|
|
|
253609 |
|
|
|
253609 |
Note that field ulChainCodeLen must be zero for any BTC master key
|
|
|
253609 |
derivation, but pChainCode must still point to a buffer of 32 bytes
|
|
|
253609 |
(CK_IBM_BTC_CHAINCODE_LENGTH) to receive the resulting chain code.
|
|
|
253609 |
|
|
|
253609 |
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
|
|
|
253609 |
---
|
|
|
253609 |
usr/lib/ep11_stdll/ep11_specific.c | 20 ++++++++++++++++++++
|
|
|
253609 |
1 file changed, 20 insertions(+)
|
|
|
253609 |
|
|
|
253609 |
diff --git a/usr/lib/ep11_stdll/ep11_specific.c b/usr/lib/ep11_stdll/ep11_specific.c
|
|
|
253609 |
index 432790f1..a56b5b82 100644
|
|
|
253609 |
--- a/usr/lib/ep11_stdll/ep11_specific.c
|
|
|
253609 |
+++ b/usr/lib/ep11_stdll/ep11_specific.c
|
|
|
253609 |
@@ -4988,6 +4988,7 @@ CK_RV ep11tok_derive_key(STDLL_TokData_t * tokdata, SESSION * session,
|
|
|
253609 |
CK_ULONG used_firmware_API_version;
|
|
|
253609 |
CK_MECHANISM_PTR mech_orig = mech;
|
|
|
253609 |
CK_ATTRIBUTE *ec_params;
|
|
|
253609 |
+ CK_IBM_BTC_DERIVE_PARAMS *btc_params = NULL;
|
|
|
253609 |
|
|
|
253609 |
memset(newblob, 0, sizeof(newblob));
|
|
|
253609 |
|
|
|
253609 |
@@ -5106,6 +5107,18 @@ CK_RV ep11tok_derive_key(STDLL_TokData_t * tokdata, SESSION * session,
|
|
|
253609 |
}
|
|
|
253609 |
}
|
|
|
253609 |
|
|
|
253609 |
+ if (mech->mechanism == CKM_IBM_BTC_DERIVE) {
|
|
|
253609 |
+ if (mech->ulParameterLen != sizeof(CK_IBM_BTC_DERIVE_PARAMS) ||
|
|
|
253609 |
+ mech->pParameter == NULL) {
|
|
|
253609 |
+ TRACE_ERROR("%s Param NULL or len for %s wrong: %lu\n",
|
|
|
253609 |
+ __func__, ep11_get_ckm(tokdata, mech->mechanism),
|
|
|
253609 |
+ mech->ulParameterLen);
|
|
|
253609 |
+ return CKR_MECHANISM_PARAM_INVALID;
|
|
|
253609 |
+ }
|
|
|
253609 |
+
|
|
|
253609 |
+ btc_params = (CK_IBM_BTC_DERIVE_PARAMS *)mech->pParameter;
|
|
|
253609 |
+ }
|
|
|
253609 |
+
|
|
|
253609 |
rc = h_opaque_2_blob(tokdata, hBaseKey, &keyblob, &keyblobsize,
|
|
|
253609 |
&base_key_obj, READ_LOCK);
|
|
|
253609 |
if (rc != CKR_OK) {
|
|
|
253609 |
@@ -5300,6 +5313,13 @@ CK_RV ep11tok_derive_key(STDLL_TokData_t * tokdata, SESSION * session,
|
|
|
253609 |
}
|
|
|
253609 |
opaque_attr = NULL;
|
|
|
253609 |
|
|
|
253609 |
+ if (mech->mechanism == CKM_IBM_BTC_DERIVE &&
|
|
|
253609 |
+ btc_params != NULL && btc_params->pChainCode != NULL &&
|
|
|
253609 |
+ cslen >= CK_IBM_BTC_CHAINCODE_LENGTH) {
|
|
|
253609 |
+ memcpy(btc_params->pChainCode, csum, CK_IBM_BTC_CHAINCODE_LENGTH);
|
|
|
253609 |
+ btc_params->ulChainCodeLen = CK_IBM_BTC_CHAINCODE_LENGTH;
|
|
|
253609 |
+ }
|
|
|
253609 |
+
|
|
|
253609 |
if (mech->mechanism == CKM_IBM_BTC_DERIVE && class == CKO_PUBLIC_KEY) {
|
|
|
253609 |
/* Derived blob is an SPKI, extract public EC key attributes */
|
|
|
253609 |
rc = ecdsa_priv_unwrap_get_data(key_obj->template,
|
|
|
253609 |
--
|
|
|
253609 |
2.16.2.windows.1
|
|
|
253609 |
|