File ocki-3.15.1-EP11-Dilithium-Specify-OID-of-key-strength-at-key-ge.patch of Package openCryptoki.23571

From 4187cbe18dadb5082db419a2f3f61811811b1eae Mon Sep 17 00:00:00 2001
From: Ingo Franzki <ifranzki@linux.ibm.com>
Date: Tue, 15 Mar 2022 13:11:10 +0100
Subject: [PATCH 1/2] EP11: Dilithium: Specify OID of key strength at key
 generation

Newer EP11 firmware versions require that the OID of the desired
Dilithium key strength is specified with attribute CKA_IBM_PQC_PARAMS
at key generation. Older firmware versions ignore this attribute.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
---
 usr/lib/ep11_stdll/ep11_specific.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/usr/lib/ep11_stdll/ep11_specific.c b/usr/lib/ep11_stdll/ep11_specific.c
index 12c98847..60c27141 100644
--- a/usr/lib/ep11_stdll/ep11_specific.c
+++ b/usr/lib/ep11_stdll/ep11_specific.c
@@ -545,6 +545,8 @@ typedef struct const_info {
 #define CKM_IBM_SM3                        CKM_VENDOR_DEFINED + 0x0005000e
 #define CKM_IBM_CPACF_WRAP                 CKM_VENDOR_DEFINED + 0x00060001
 
+#define CKA_IBM_PQC_PARAMS                 CKA_VENDOR_DEFINED + 0x0001000e
+
 static CK_RV cleanse_attribute(TEMPLATE *template,
                                CK_ATTRIBUTE_TYPE attr_type)
 {
@@ -4983,6 +4985,8 @@ static CK_RV ibm_dilithium_generate_keypair(STDLL_TokData_t * tokdata,
     CK_ULONG ep11_pin_blob_len = 0;
     ep11_session_t *ep11_session = (ep11_session_t *) sess->private_data;
     CK_BYTE *rho, *t1;
+    const CK_BYTE dilithium_oid[] = { 0x06, 0x0b, 0x2b, 0x06, 0x01, 0x04, 0x01,
+                                      0x02, 0x82, 0x0b, 0x01, 0x06, 0x05 };
 
     UNUSED(h);
 
@@ -5029,6 +5033,26 @@ static CK_RV ibm_dilithium_generate_keypair(STDLL_TokData_t * tokdata,
         goto error;
     }
 
+    rc = add_to_attribute_array(&new_pPublicKeyTemplate,
+                                &new_ulPublicKeyAttributeCount,
+                                CKA_IBM_PQC_PARAMS, (CK_BYTE *)dilithium_oid,
+                                sizeof(dilithium_oid));
+    if (rc != CKR_OK) {
+        TRACE_ERROR("%s add_to_attribute_array failed with rc=0x%lx\n",
+                    __func__, rc);
+        goto error;
+    }
+
+    rc = add_to_attribute_array(&new_pPrivateKeyTemplate,
+                                &new_ulPrivateKeyAttributeCount,
+                                CKA_IBM_PQC_PARAMS,(CK_BYTE *)dilithium_oid,
+                                sizeof(dilithium_oid));
+    if (rc != CKR_OK) {
+        TRACE_ERROR("%s add_to_attribute_array failed with rc=0x%lx\n",
+                    __func__, rc);
+        goto error;
+    }
+
     /* debug */
     for (i = 0; i < new_ulPrivateKeyAttributeCount; i++) {
         TRACE_INFO("%s gen priv attr type=0x%lx valuelen=0x%lx attrcnt=0x%lx\n",
-- 
2.16.2.windows.1

openSUSE Build Service is sponsored by