Blame SOURCES/0019-COMMON-Dilithium-key-BER-encoding-decoding-allow-dif.patch

1f6f0c
From 76307be97a42f5a743e7cf0ef75a87dac0c0106f Mon Sep 17 00:00:00 2001
1f6f0c
From: Ingo Franzki <ifranzki@linux.ibm.com>
1f6f0c
Date: Wed, 16 Feb 2022 13:04:24 +0100
1f6f0c
Subject: [PATCH 19/34] COMMON: Dilithium key BER encoding/decoding allow
1f6f0c
 different OIDs
1f6f0c
1f6f0c
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
1f6f0c
---
1f6f0c
 usr/lib/cca_stdll/cca_stdll.mk           |   2 +-
1f6f0c
 usr/lib/common/asn1.c                    | 143 ++++++++++++++++++++-----------
1f6f0c
 usr/lib/common/globals.c                 |   8 +-
1f6f0c
 usr/lib/common/h_extern.h                |  54 ++++++------
1f6f0c
 usr/lib/common/key.c                     |  10 ++-
1f6f0c
 usr/lib/common/key_mgr.c                 |  13 ++-
1f6f0c
 usr/lib/ep11_stdll/ep11_specific.c       |   6 +-
1f6f0c
 usr/lib/ep11_stdll/ep11_stdll.mk         |   3 +-
1f6f0c
 usr/lib/ica_s390_stdll/ica_s390_stdll.mk |   2 +-
1f6f0c
 usr/lib/icsf_stdll/icsf_stdll.mk         |   2 +-
1f6f0c
 usr/lib/soft_stdll/soft_stdll.mk         |   2 +-
1f6f0c
 usr/lib/tpm_stdll/tpm_stdll.mk           |   2 +-
1f6f0c
 usr/sbin/pkcscca/pkcscca.mk              |   2 +-
1f6f0c
 13 files changed, 152 insertions(+), 97 deletions(-)
1f6f0c
1f6f0c
diff --git a/usr/lib/cca_stdll/cca_stdll.mk b/usr/lib/cca_stdll/cca_stdll.mk
1f6f0c
index 9b71085a..5963df59 100644
1f6f0c
--- a/usr/lib/cca_stdll/cca_stdll.mk
1f6f0c
+++ b/usr/lib/cca_stdll/cca_stdll.mk
1f6f0c
@@ -41,7 +41,7 @@ opencryptoki_stdll_libpkcs11_cca_la_SOURCES = usr/lib/common/asn1.c	\
1f6f0c
 	usr/lib/common/utility_common.c usr/lib/common/ec_supported.c	\
1f6f0c
 	usr/lib/api/policyhelper.c usr/lib/config/configuration.c	\
1f6f0c
 	usr/lib/config/cfgparse.y usr/lib/config/cfglex.l		\
1f6f0c
-	usr/lib/common/mech_openssl.c
1f6f0c
+	usr/lib/common/mech_openssl.c usr/lib/common/pqc_supported.c
1f6f0c
 
1f6f0c
 if ENABLE_LOCKS
1f6f0c
 opencryptoki_stdll_libpkcs11_cca_la_SOURCES +=				\
1f6f0c
diff --git a/usr/lib/common/asn1.c b/usr/lib/common/asn1.c
1f6f0c
index b3f49c41..884ef489 100644
1f6f0c
--- a/usr/lib/common/asn1.c
1f6f0c
+++ b/usr/lib/common/asn1.c
1f6f0c
@@ -24,6 +24,7 @@
1f6f0c
 #include "host_defs.h"
1f6f0c
 #include "h_extern.h"
1f6f0c
 #include "trace.h"
1f6f0c
+#include "pqc_defs.h"
1f6f0c
 
1f6f0c
 
1f6f0c
 //
1f6f0c
@@ -3616,7 +3617,7 @@ cleanup:
1f6f0c
  *
1f6f0c
  *  SEQUENCE (2 elem)
1f6f0c
  *    SEQUENCE (2 elem)
1f6f0c
- *      OBJECT IDENTIFIER 1.3.6.1.4.1.2.267.1.6.5
1f6f0c
+ *      OBJECT IDENTIFIER 1.3.6.1.4.1.2.267.xxx
1f6f0c
  *      NULL
1f6f0c
  *    BIT STRING (1 elem)
1f6f0c
  *      SEQUENCE (2 elem)
1f6f0c
@@ -3624,20 +3625,26 @@ cleanup:
1f6f0c
  *        BIT STRING (13824 bit) = 1728 bytes
1f6f0c
  */
1f6f0c
 CK_RV ber_encode_IBM_DilithiumPublicKey(CK_BBOOL length_only,
1f6f0c
-                          CK_BYTE **data, CK_ULONG *data_len,
1f6f0c
-                          CK_ATTRIBUTE *rho, CK_ATTRIBUTE *t1)
1f6f0c
+                                        CK_BYTE **data, CK_ULONG *data_len,
1f6f0c
+                                        const CK_BYTE *oid, CK_ULONG oid_len,
1f6f0c
+                                        CK_ATTRIBUTE *rho, CK_ATTRIBUTE *t1)
1f6f0c
 {
1f6f0c
     CK_BYTE *buf = NULL, *buf2 = NULL, *buf3 = NULL, *buf4 = NULL;
1f6f0c
-    CK_ULONG len = 0, len4, offset, total, total_len;
1f6f0c
+    CK_BYTE *buf5 = NULL, *algid = NULL;
1f6f0c
+    CK_ULONG len = 0, len4, offset, total, total_len, algid_len;
1f6f0c
     CK_RV rc;
1f6f0c
 
1f6f0c
     UNUSED(length_only);
1f6f0c
 
1f6f0c
     offset = 0;
1f6f0c
     rc = 0;
1f6f0c
-    total_len = ber_AlgIdDilithiumLen;
1f6f0c
+    total_len = 0;
1f6f0c
     total = 0;
1f6f0c
 
1f6f0c
+    /* Calculate storage for AlgID sequence */
1f6f0c
+    rc |= ber_encode_SEQUENCE(TRUE, NULL, &total_len, NULL,
1f6f0c
+                              oid_len + ber_NULLLen);
1f6f0c
+
1f6f0c
     /* Calculate storage for inner sequence */
1f6f0c
     rc |= ber_encode_INTEGER(TRUE, NULL, &len, NULL, rho->ulValueLen);
1f6f0c
     offset += len;
1f6f0c
@@ -3709,12 +3716,30 @@ CK_RV ber_encode_IBM_DilithiumPublicKey(CK_BBOOL length_only,
1f6f0c
 
1f6f0c
     /*
1f6f0c
      * SEQUENCE (2 elem)
1f6f0c
-     *      OBJECT IDENTIFIER 1.3.6.1.4.1.2.267.1.6.5
1f6f0c
+     *      OBJECT IDENTIFIER 1.3.6.1.4.1.2.267.xxx
1f6f0c
      *      NULL  <- no parms for this oid
1f6f0c
      */
1f6f0c
-    total_len = 0;
1f6f0c
-    memcpy(buf3 + total_len, ber_AlgIdDilithium, ber_AlgIdDilithiumLen);
1f6f0c
-    total_len += ber_AlgIdDilithiumLen;
1f6f0c
+    buf5 = (CK_BYTE *) malloc(oid_len + ber_NULLLen);
1f6f0c
+    if (!buf5) {
1f6f0c
+        TRACE_ERROR("%s Memory allocation failed\n", __func__);
1f6f0c
+        rc = CKR_HOST_MEMORY;
1f6f0c
+        goto error;
1f6f0c
+    }
1f6f0c
+    memcpy(buf5, oid, oid_len);
1f6f0c
+    memcpy(buf5 + oid_len, ber_NULL, ber_NULLLen);
1f6f0c
+
1f6f0c
+    rc = ber_encode_SEQUENCE(FALSE, &algid, &algid_len, buf5,
1f6f0c
+                             oid_len + ber_NULLLen);
1f6f0c
+    free(buf5);
1f6f0c
+    if (rc != CKR_OK) {
1f6f0c
+        TRACE_ERROR("%s ber_encode_SEQUENCE failed with rc=0x%lx\n", __func__, rc);
1f6f0c
+        goto error;
1f6f0c
+    }
1f6f0c
+
1f6f0c
+    total_len = algid_len;
1f6f0c
+    memcpy(buf3, algid, algid_len);
1f6f0c
+    free(algid);
1f6f0c
+    algid = NULL;
1f6f0c
 
1f6f0c
     /*
1f6f0c
      * BIT STRING (1 elem)
1f6f0c
@@ -3760,16 +3785,15 @@ error:
1f6f0c
 
1f6f0c
 
1f6f0c
 CK_RV ber_decode_IBM_DilithiumPublicKey(CK_BYTE *data,
1f6f0c
-                              CK_ULONG data_len,
1f6f0c
-                              CK_ATTRIBUTE **rho_attr,
1f6f0c
-                              CK_ATTRIBUTE **t1_attr)
1f6f0c
+                                        CK_ULONG data_len,
1f6f0c
+                                        CK_ATTRIBUTE **rho_attr,
1f6f0c
+                                        CK_ATTRIBUTE **t1_attr)
1f6f0c
 {
1f6f0c
     CK_ATTRIBUTE *rho_attr_temp = NULL;
1f6f0c
     CK_ATTRIBUTE *t1_attr_temp = NULL;
1f6f0c
 
1f6f0c
-    CK_BYTE *algid_DilithiumBase = NULL;
1f6f0c
-    CK_BYTE *algid = NULL;
1f6f0c
-    CK_ULONG algid_len;
1f6f0c
+    CK_BYTE *algoid = NULL;
1f6f0c
+    CK_ULONG algoid_len;
1f6f0c
     CK_BYTE *param = NULL;
1f6f0c
     CK_ULONG param_len;
1f6f0c
     CK_BYTE *val = NULL;
1f6f0c
@@ -3780,26 +3804,20 @@ CK_RV ber_decode_IBM_DilithiumPublicKey(CK_BYTE *data,
1f6f0c
     CK_ULONG rho_len;
1f6f0c
     CK_BYTE *t1;
1f6f0c
     CK_ULONG t1_len;
1f6f0c
-    CK_ULONG field_len, offset, len;
1f6f0c
+    CK_ULONG field_len, offset;
1f6f0c
     CK_RV rc;
1f6f0c
 
1f6f0c
     UNUSED(data_len); // XXX can this parameter be removed ?
1f6f0c
 
1f6f0c
-    rc = ber_decode_SPKI(data, &algid, &algid_len, &param, &param_len,
1f6f0c
+    rc = ber_decode_SPKI(data, &algoid, &algoid_len, &param, &param_len,
1f6f0c
                          &val, &val_len);
1f6f0c
     if (rc != CKR_OK) {
1f6f0c
        TRACE_DEVEL("ber_decode_SPKI failed\n");
1f6f0c
        return rc;
1f6f0c
     }
1f6f0c
 
1f6f0c
-    /* Make sure we're dealing with a Dilithium key */
1f6f0c
-    rc = ber_decode_SEQUENCE((CK_BYTE *)ber_AlgIdDilithium, &algid_DilithiumBase, &len,
1f6f0c
-                             &field_len);
1f6f0c
-    if (rc != CKR_OK) {
1f6f0c
-        TRACE_DEVEL("ber_decode_SEQUENCE failed\n");
1f6f0c
-        return rc;
1f6f0c
-    }
1f6f0c
-    if (memcmp(algid, algid_DilithiumBase, len) != 0) {
1f6f0c
+    if (algoid_len != dilithium_r2_65_len ||
1f6f0c
+        memcmp(algoid, dilithium_r2_65, dilithium_r2_65_len) != 0) {
1f6f0c
         TRACE_ERROR("%s\n", ock_err(ERR_FUNCTION_FAILED));
1f6f0c
         return CKR_FUNCTION_FAILED;
1f6f0c
     }
1f6f0c
@@ -3879,18 +3897,20 @@ cleanup:
1f6f0c
  *     }
1f6f0c
  */
1f6f0c
 CK_RV ber_encode_IBM_DilithiumPrivateKey(CK_BBOOL length_only,
1f6f0c
-                               CK_BYTE **data,
1f6f0c
-                               CK_ULONG *data_len,
1f6f0c
-                               CK_ATTRIBUTE *rho,
1f6f0c
-                               CK_ATTRIBUTE *seed,
1f6f0c
-                               CK_ATTRIBUTE *tr,
1f6f0c
-                               CK_ATTRIBUTE *s1,
1f6f0c
-                               CK_ATTRIBUTE *s2,
1f6f0c
-                               CK_ATTRIBUTE *t0,
1f6f0c
-                               CK_ATTRIBUTE *t1)
1f6f0c
+                                         CK_BYTE **data,
1f6f0c
+                                         CK_ULONG *data_len,
1f6f0c
+                                         const CK_BYTE *oid, CK_ULONG oid_len,
1f6f0c
+                                         CK_ATTRIBUTE *rho,
1f6f0c
+                                         CK_ATTRIBUTE *seed,
1f6f0c
+                                         CK_ATTRIBUTE *tr,
1f6f0c
+                                         CK_ATTRIBUTE *s1,
1f6f0c
+                                         CK_ATTRIBUTE *s2,
1f6f0c
+                                         CK_ATTRIBUTE *t0,
1f6f0c
+                                         CK_ATTRIBUTE *t1)
1f6f0c
 {
1f6f0c
     CK_BYTE *buf = NULL, *buf2 = NULL, *buf3 = NULL;
1f6f0c
-    CK_ULONG len, len2 = 0, offset;
1f6f0c
+    CK_BYTE *algid = NULL, *algid_buf = NULL;
1f6f0c
+    CK_ULONG len, len2 = 0, offset, algid_len = 0;
1f6f0c
     CK_BYTE version[] = { 0 };
1f6f0c
     CK_RV rc;
1f6f0c
 
1f6f0c
@@ -3898,6 +3918,9 @@ CK_RV ber_encode_IBM_DilithiumPrivateKey(CK_BBOOL length_only,
1f6f0c
     offset = 0;
1f6f0c
     rc = 0;
1f6f0c
 
1f6f0c
+    rc |= ber_encode_SEQUENCE(TRUE, NULL, &algid_len, NULL,
1f6f0c
+                              oid_len + ber_NULLLen);
1f6f0c
+
1f6f0c
     rc |= ber_encode_INTEGER(TRUE, NULL, &len, NULL, sizeof(version));
1f6f0c
     offset += len;
1f6f0c
     rc |= ber_encode_BIT_STRING(TRUE, NULL, &len, NULL, rho->ulValueLen, 0);
1f6f0c
@@ -3931,7 +3954,7 @@ CK_RV ber_encode_IBM_DilithiumPrivateKey(CK_BBOOL length_only,
1f6f0c
         }
1f6f0c
         rc = ber_encode_PrivateKeyInfo(TRUE,
1f6f0c
                                        NULL, data_len,
1f6f0c
-                                       NULL, ber_AlgIdDilithiumLen,
1f6f0c
+                                       NULL, algid_len,
1f6f0c
                                        NULL, len);
1f6f0c
         if (rc != CKR_OK) {
1f6f0c
             TRACE_DEVEL("ber_encode_PrivateKeyInfo failed\n");
1f6f0c
@@ -4051,10 +4074,28 @@ CK_RV ber_encode_IBM_DilithiumPrivateKey(CK_BBOOL length_only,
1f6f0c
         TRACE_ERROR("ber_encode_SEQUENCE failed\n");
1f6f0c
         goto error;
1f6f0c
     }
1f6f0c
+
1f6f0c
+    algid_buf = (CK_BYTE *) malloc(oid_len + ber_NULLLen);
1f6f0c
+    if (!algid_buf) {
1f6f0c
+        TRACE_ERROR("%s Memory allocation failed\n", __func__);
1f6f0c
+        rc = CKR_HOST_MEMORY;
1f6f0c
+        goto error;
1f6f0c
+    }
1f6f0c
+    memcpy(algid_buf, oid, oid_len);
1f6f0c
+    memcpy(algid_buf + oid_len, ber_NULL, ber_NULLLen);
1f6f0c
+
1f6f0c
+    rc = ber_encode_SEQUENCE(FALSE, &algid, &algid_len, algid_buf,
1f6f0c
+                             oid_len + ber_NULLLen);
1f6f0c
+    free(algid_buf);
1f6f0c
+    if (rc != CKR_OK) {
1f6f0c
+        TRACE_ERROR("%s ber_encode_SEQUENCE failed with rc=0x%lx\n", __func__, rc);
1f6f0c
+        goto error;
1f6f0c
+    }
1f6f0c
+
1f6f0c
     rc = ber_encode_PrivateKeyInfo(FALSE,
1f6f0c
                                    data, data_len,
1f6f0c
-                                   ber_AlgIdDilithium,
1f6f0c
-                                   ber_AlgIdDilithiumLen, buf2, len);
1f6f0c
+                                   algid, algid_len,
1f6f0c
+                                   buf2, len);
1f6f0c
     if (rc != CKR_OK) {
1f6f0c
         TRACE_ERROR("ber_encode_PrivateKeyInfo failed\n");
1f6f0c
     }
1f6f0c
@@ -4066,6 +4107,8 @@ error:
1f6f0c
         free(buf2);
1f6f0c
     if (buf)
1f6f0c
         free(buf);
1f6f0c
+    if (algid)
1f6f0c
+        free(algid);
1f6f0c
 
1f6f0c
     return rc;
1f6f0c
 }
1f6f0c
@@ -4087,19 +4130,19 @@ error:
1f6f0c
  *       }
1f6f0c
  */
1f6f0c
 CK_RV ber_decode_IBM_DilithiumPrivateKey(CK_BYTE *data,
1f6f0c
-                               CK_ULONG data_len,
1f6f0c
-                               CK_ATTRIBUTE **rho,
1f6f0c
-                               CK_ATTRIBUTE **seed,
1f6f0c
-                               CK_ATTRIBUTE **tr,
1f6f0c
-                               CK_ATTRIBUTE **s1,
1f6f0c
-                               CK_ATTRIBUTE **s2,
1f6f0c
-                               CK_ATTRIBUTE **t0,
1f6f0c
-                               CK_ATTRIBUTE **t1)
1f6f0c
+                                         CK_ULONG data_len,
1f6f0c
+                                         CK_ATTRIBUTE **rho,
1f6f0c
+                                         CK_ATTRIBUTE **seed,
1f6f0c
+                                         CK_ATTRIBUTE **tr,
1f6f0c
+                                         CK_ATTRIBUTE **s1,
1f6f0c
+                                         CK_ATTRIBUTE **s2,
1f6f0c
+                                         CK_ATTRIBUTE **t0,
1f6f0c
+                                         CK_ATTRIBUTE **t1)
1f6f0c
 {
1f6f0c
     CK_ATTRIBUTE *rho_attr = NULL, *seed_attr = NULL;
1f6f0c
     CK_ATTRIBUTE *tr_attr = NULL, *s1_attr = NULL, *s2_attr = NULL;
1f6f0c
     CK_ATTRIBUTE *t0_attr = NULL, *t1_attr = NULL;
1f6f0c
-    CK_BYTE *alg = NULL;
1f6f0c
+    CK_BYTE *algoid = NULL;
1f6f0c
     CK_BYTE *dilithium_priv_key = NULL;
1f6f0c
     CK_BYTE *buf = NULL;
1f6f0c
     CK_BYTE *tmp = NULL;
1f6f0c
@@ -4107,15 +4150,15 @@ CK_RV ber_decode_IBM_DilithiumPrivateKey(CK_BYTE *data,
1f6f0c
     CK_RV rc;
1f6f0c
 
1f6f0c
     /* Check if this is a Dilithium private key */
1f6f0c
-    rc = ber_decode_PrivateKeyInfo(data, data_len, &alg, &len,
1f6f0c
+    rc = ber_decode_PrivateKeyInfo(data, data_len, &algoid, &len,
1f6f0c
                                    &dilithium_priv_key);
1f6f0c
     if (rc != CKR_OK) {
1f6f0c
         TRACE_DEVEL("ber_decode_PrivateKeyInfo failed\n");
1f6f0c
         return rc;
1f6f0c
     }
1f6f0c
 
1f6f0c
-    if (memcmp(alg, ber_AlgIdDilithium, ber_AlgIdDilithiumLen) != 0) {
1f6f0c
-        // probably ought to use a different error
1f6f0c
+    if (len != dilithium_r2_65_len + ber_NULLLen ||
1f6f0c
+        memcmp(algoid, dilithium_r2_65, dilithium_r2_65_len) != 0) {
1f6f0c
         TRACE_ERROR("%s\n", ock_err(ERR_FUNCTION_FAILED));
1f6f0c
         return CKR_FUNCTION_FAILED;
1f6f0c
     }
1f6f0c
diff --git a/usr/lib/common/globals.c b/usr/lib/common/globals.c
1f6f0c
index 5b79e785..a7197ec6 100644
1f6f0c
--- a/usr/lib/common/globals.c
1f6f0c
+++ b/usr/lib/common/globals.c
1f6f0c
@@ -105,11 +105,7 @@ const CK_BYTE ber_AlgIdRSAEncryption[] = {
1f6f0c
 const CK_BYTE der_AlgIdECBase[] =
1f6f0c
     { 0x30, 0x09, 0x06, 0x07, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x02, 0x01 };
1f6f0c
 
1f6f0c
-const CK_BYTE ber_AlgIdDilithium[] =
1f6f0c
-    { 0x30, 0x0F, 0x06, 0x0B, 0x2B, 0x06, 0x01,
1f6f0c
-      0x04, 0x01, 0x02, 0x82, 0x0B, 0x01, 0x06,
1f6f0c
-      0x05, 0x05, 0x00
1f6f0c
-};
1f6f0c
+const CK_BYTE ber_NULL[] = { 0x05, 0x00 };
1f6f0c
 
1f6f0c
 // ID Lengths
1f6f0c
 //
1f6f0c
@@ -135,7 +131,7 @@ const CK_ULONG ber_AlgSha384Len = sizeof(ber_AlgSha384);
1f6f0c
 const CK_ULONG ber_AlgSha512Len = sizeof(ber_AlgSha512);
1f6f0c
 const CK_ULONG ber_AlgIdRSAEncryptionLen = sizeof(ber_AlgIdRSAEncryption);
1f6f0c
 const CK_ULONG der_AlgIdECBaseLen = sizeof(der_AlgIdECBase);
1f6f0c
-const CK_ULONG ber_AlgIdDilithiumLen = sizeof(ber_AlgIdDilithium);
1f6f0c
+const CK_ULONG ber_NULLLen = sizeof(ber_NULL);
1f6f0c
 
1f6f0c
 const CK_ULONG des_weak_count = 4;
1f6f0c
 const CK_ULONG des_semi_weak_count = 12;
1f6f0c
diff --git a/usr/lib/common/h_extern.h b/usr/lib/common/h_extern.h
1f6f0c
index 340ab88d..41ca12df 100644
1f6f0c
--- a/usr/lib/common/h_extern.h
1f6f0c
+++ b/usr/lib/common/h_extern.h
1f6f0c
@@ -56,16 +56,14 @@ extern const CK_BYTE ber_rsaEncryption[];
1f6f0c
 extern const CK_ULONG ber_rsaEncryptionLen;
1f6f0c
 extern const CK_BYTE der_AlgIdECBase[];
1f6f0c
 extern const CK_ULONG der_AlgIdECBaseLen;
1f6f0c
-extern const CK_BYTE ber_AlgIdDilithium[];
1f6f0c
-extern const CK_ULONG ber_AlgIdDilithiumLen;
1f6f0c
 extern const CK_BYTE ber_idDSA[];
1f6f0c
 extern const CK_ULONG ber_idDSALen;
1f6f0c
 extern const CK_BYTE ber_idDH[];
1f6f0c
 extern const CK_ULONG ber_idDHLen;
1f6f0c
 extern const CK_BYTE ber_idEC[];
1f6f0c
 extern const CK_ULONG ber_idECLen;
1f6f0c
-extern const CK_BYTE ber_idDilithium[];
1f6f0c
-extern const CK_ULONG ber_idDilithiumLen;
1f6f0c
+extern const CK_BYTE ber_NULL[];
1f6f0c
+extern const CK_ULONG ber_NULLLen;
1f6f0c
 
1f6f0c
 #if !(NOMD2)
1f6f0c
 extern const CK_BYTE ber_md2WithRSAEncryption[];
1f6f0c
@@ -2742,35 +2740,37 @@ CK_RV ber_decode_ECDHPrivateKey(CK_BYTE *data,
1f6f0c
                                 CK_ATTRIBUTE **pub_key,
1f6f0c
                                 CK_ATTRIBUTE **priv_key);
1f6f0c
 
1f6f0c
-CK_RV ber_encode_IBM_DilithiumPublicKey(CK_BBOOL length_only, CK_BYTE **data,
1f6f0c
-                              CK_ULONG *data_len, CK_ATTRIBUTE *rho,
1f6f0c
-                              CK_ATTRIBUTE *t1);
1f6f0c
+CK_RV ber_encode_IBM_DilithiumPublicKey(CK_BBOOL length_only,
1f6f0c
+                                        CK_BYTE **data, CK_ULONG *data_len,
1f6f0c
+                                        const CK_BYTE *oid, CK_ULONG oid_len,
1f6f0c
+                                        CK_ATTRIBUTE *rho, CK_ATTRIBUTE *t1);
1f6f0c
 
1f6f0c
 CK_RV ber_decode_IBM_DilithiumPublicKey(CK_BYTE *data,
1f6f0c
-                              CK_ULONG data_len,
1f6f0c
-                              CK_ATTRIBUTE **rho_attr,
1f6f0c
-                              CK_ATTRIBUTE **t1_attr);
1f6f0c
+                                        CK_ULONG data_len,
1f6f0c
+                                        CK_ATTRIBUTE **rho_attr,
1f6f0c
+                                        CK_ATTRIBUTE **t1_attr);
1f6f0c
 
1f6f0c
 CK_RV ber_encode_IBM_DilithiumPrivateKey(CK_BBOOL length_only,
1f6f0c
-                               CK_BYTE **data,
1f6f0c
-                               CK_ULONG *data_len,
1f6f0c
-                               CK_ATTRIBUTE *rho,
1f6f0c
-                               CK_ATTRIBUTE *seed,
1f6f0c
-                               CK_ATTRIBUTE *tr,
1f6f0c
-                               CK_ATTRIBUTE *s1,
1f6f0c
-                               CK_ATTRIBUTE *s2,
1f6f0c
-                               CK_ATTRIBUTE *t0,
1f6f0c
-                               CK_ATTRIBUTE *t1);
1f6f0c
+                                         CK_BYTE **data,
1f6f0c
+                                         CK_ULONG *data_len,
1f6f0c
+                                         const CK_BYTE *oid, CK_ULONG oid_len,
1f6f0c
+                                         CK_ATTRIBUTE *rho,
1f6f0c
+                                         CK_ATTRIBUTE *seed,
1f6f0c
+                                         CK_ATTRIBUTE *tr,
1f6f0c
+                                         CK_ATTRIBUTE *s1,
1f6f0c
+                                         CK_ATTRIBUTE *s2,
1f6f0c
+                                         CK_ATTRIBUTE *t0,
1f6f0c
+                                         CK_ATTRIBUTE *t1);
1f6f0c
 
1f6f0c
 CK_RV ber_decode_IBM_DilithiumPrivateKey(CK_BYTE *data,
1f6f0c
-                               CK_ULONG data_len,
1f6f0c
-                               CK_ATTRIBUTE **rho,
1f6f0c
-                               CK_ATTRIBUTE **seed,
1f6f0c
-                               CK_ATTRIBUTE **tr,
1f6f0c
-                               CK_ATTRIBUTE **s1,
1f6f0c
-                               CK_ATTRIBUTE **s2,
1f6f0c
-                               CK_ATTRIBUTE **t0,
1f6f0c
-                               CK_ATTRIBUTE **t1);
1f6f0c
+                                         CK_ULONG data_len,
1f6f0c
+                                         CK_ATTRIBUTE **rho,
1f6f0c
+                                         CK_ATTRIBUTE **seed,
1f6f0c
+                                         CK_ATTRIBUTE **tr,
1f6f0c
+                                         CK_ATTRIBUTE **s1,
1f6f0c
+                                         CK_ATTRIBUTE **s2,
1f6f0c
+                                         CK_ATTRIBUTE **t0,
1f6f0c
+                                         CK_ATTRIBUTE **t1);
1f6f0c
 
1f6f0c
 typedef CK_RV (*t_rsa_encrypt)(STDLL_TokData_t *, CK_BYTE *in_data,
1f6f0c
                                CK_ULONG in_data_len, CK_BYTE *out_data,
1f6f0c
diff --git a/usr/lib/common/key.c b/usr/lib/common/key.c
1f6f0c
index 6e9a839a..41857b97 100644
1f6f0c
--- a/usr/lib/common/key.c
1f6f0c
+++ b/usr/lib/common/key.c
1f6f0c
@@ -81,6 +81,7 @@
1f6f0c
 #include "h_extern.h"
1f6f0c
 #include "attributes.h"
1f6f0c
 #include "trace.h"
1f6f0c
+#include "pqc_defs.h"
1f6f0c
 
1f6f0c
 #include "tok_spec_struct.h"
1f6f0c
 
1f6f0c
@@ -2688,7 +2689,10 @@ CK_RV ibm_dilithium_publ_get_spki(TEMPLATE *tmpl, CK_BBOOL length_only,
1f6f0c
         return rc;
1f6f0c
     }
1f6f0c
 
1f6f0c
-    rc = ber_encode_IBM_DilithiumPublicKey(length_only, data,data_len, rho, t1);
1f6f0c
+    rc = ber_encode_IBM_DilithiumPublicKey(length_only, data, data_len,
1f6f0c
+                                           dilithium_r2_65,
1f6f0c
+                                           dilithium_r2_65_len,
1f6f0c
+                                           rho, t1);
1f6f0c
     if (rc != CKR_OK) {
1f6f0c
         TRACE_ERROR("ber_encode_IBM_DilithiumPublicKey failed.\n");
1f6f0c
         return rc;
1f6f0c
@@ -2766,7 +2770,9 @@ CK_RV ibm_dilithium_priv_wrap_get_data(TEMPLATE *tmpl,
1f6f0c
     }
1f6f0c
 
1f6f0c
     rc = ber_encode_IBM_DilithiumPrivateKey(length_only, data, data_len,
1f6f0c
-                                  rho, seed, tr, s1, s2, t0, t1);
1f6f0c
+                                            dilithium_r2_65,
1f6f0c
+                                            dilithium_r2_65_len,
1f6f0c
+                                            rho, seed, tr, s1, s2, t0, t1);
1f6f0c
     if (rc != CKR_OK) {
1f6f0c
         TRACE_DEVEL("ber_encode_IBM_DilithiumPrivateKey failed\n");
1f6f0c
     }
1f6f0c
diff --git a/usr/lib/common/key_mgr.c b/usr/lib/common/key_mgr.c
1f6f0c
index 99f2a72e..01103dc2 100644
1f6f0c
--- a/usr/lib/common/key_mgr.c
1f6f0c
+++ b/usr/lib/common/key_mgr.c
1f6f0c
@@ -35,6 +35,7 @@
1f6f0c
 #include "attributes.h"
1f6f0c
 #include "tok_spec_struct.h"
1f6f0c
 #include "trace.h"
1f6f0c
+#include "pqc_defs.h"
1f6f0c
 
1f6f0c
 #include "../api/policy.h"
1f6f0c
 #include "../api/statistics.h"
1f6f0c
@@ -1368,7 +1369,7 @@ CK_RV key_mgr_get_private_key_type(CK_BYTE *keydata,
1f6f0c
 {
1f6f0c
     CK_BYTE *alg = NULL;
1f6f0c
     CK_BYTE *priv_key = NULL;
1f6f0c
-    CK_ULONG alg_len;
1f6f0c
+    CK_ULONG alg_len, i;
1f6f0c
     CK_RV rc;
1f6f0c
 
1f6f0c
     rc = ber_decode_PrivateKeyInfo(keydata, keylen, &alg, &alg_len, &priv_key);
1f6f0c
@@ -1408,10 +1409,14 @@ CK_RV key_mgr_get_private_key_type(CK_BYTE *keydata,
1f6f0c
             return CKR_OK;
1f6f0c
         }
1f6f0c
     }
1f6f0c
-    // Check only the OBJECT IDENTIFIER for DILITHIUM
1f6f0c
+    // Check only the OBJECT IDENTIFIERs for DILITHIUM
1f6f0c
     //
1f6f0c
-    if (alg_len >= ber_idDilithiumLen) {
1f6f0c
-        if (memcmp(alg, ber_idDilithium, ber_idDilithiumLen) == 0) {
1f6f0c
+    for (i = 0; dilithium_oids[i].oid != NULL; i++) {
1f6f0c
+        if (alg_len == dilithium_oids[i].oid_len + ber_NULLLen &&
1f6f0c
+            memcmp(alg, dilithium_oids[i].oid,
1f6f0c
+                   dilithium_oids[i].oid_len) == 0 &&
1f6f0c
+            memcmp(alg + dilithium_oids[i].oid_len,
1f6f0c
+                   ber_NULL, ber_NULLLen) == 0) {
1f6f0c
             *keytype = CKK_IBM_PQC_DILITHIUM;
1f6f0c
             return CKR_OK;
1f6f0c
         }
1f6f0c
diff --git a/usr/lib/ep11_stdll/ep11_specific.c b/usr/lib/ep11_stdll/ep11_specific.c
1f6f0c
index e3451163..45069ae8 100644
1f6f0c
--- a/usr/lib/ep11_stdll/ep11_specific.c
1f6f0c
+++ b/usr/lib/ep11_stdll/ep11_specific.c
1f6f0c
@@ -37,6 +37,7 @@
1f6f0c
 #include "trace.h"
1f6f0c
 #include "ock_syslog.h"
1f6f0c
 #include "ec_defs.h"
1f6f0c
+#include "pqc_defs.h"
1f6f0c
 #include "p11util.h"
1f6f0c
 #include "events.h"
1f6f0c
 #include "cfgparser.h"
1f6f0c
@@ -3645,7 +3646,10 @@ static CK_RV import_IBM_Dilithium_key(STDLL_TokData_t *tokdata, SESSION *sess,
1f6f0c
         }
1f6f0c
 
1f6f0c
         /* Encode the public key */
1f6f0c
-        rc = ber_encode_IBM_DilithiumPublicKey(0, &data, &data_len, rho, t1);
1f6f0c
+        rc = ber_encode_IBM_DilithiumPublicKey(FALSE, &data, &data_len,
1f6f0c
+                                               dilithium_r2_65,
1f6f0c
+                                               dilithium_r2_65_len,
1f6f0c
+                                               rho, t1);
1f6f0c
         if (rc != CKR_OK) {
1f6f0c
             TRACE_ERROR("%s public key import class=0x%lx rc=0x%lx "
1f6f0c
                         "data_len=0x%lx\n", __func__, class, rc, data_len);
1f6f0c
diff --git a/usr/lib/ep11_stdll/ep11_stdll.mk b/usr/lib/ep11_stdll/ep11_stdll.mk
1f6f0c
index 9a8aa76a..11061f76 100644
1f6f0c
--- a/usr/lib/ep11_stdll/ep11_stdll.mk
1f6f0c
+++ b/usr/lib/ep11_stdll/ep11_stdll.mk
1f6f0c
@@ -43,7 +43,8 @@ opencryptoki_stdll_libpkcs11_ep11_la_SOURCES = usr/lib/common/asn1.c	\
1f6f0c
 	usr/lib/ep11_stdll/ep11_specific.c				\
1f6f0c
 	usr/lib/common/utility_common.c usr/lib/common/ec_supported.c	\
1f6f0c
 	usr/lib/api/policyhelper.c usr/lib/config/configuration.c	\
1f6f0c
-	usr/lib/config/cfgparse.y usr/lib/config/cfglex.l
1f6f0c
+	usr/lib/config/cfgparse.y usr/lib/config/cfglex.l		\
1f6f0c
+	usr/lib/common/pqc_supported.c
1f6f0c
 
1f6f0c
 if ENABLE_LOCKS
1f6f0c
 opencryptoki_stdll_libpkcs11_ep11_la_SOURCES +=				\
1f6f0c
diff --git a/usr/lib/ica_s390_stdll/ica_s390_stdll.mk b/usr/lib/ica_s390_stdll/ica_s390_stdll.mk
1f6f0c
index cb9d898f..f89cd343 100644
1f6f0c
--- a/usr/lib/ica_s390_stdll/ica_s390_stdll.mk
1f6f0c
+++ b/usr/lib/ica_s390_stdll/ica_s390_stdll.mk
1f6f0c
@@ -38,7 +38,7 @@ opencryptoki_stdll_libpkcs11_ica_la_SOURCES =				\
1f6f0c
 	usr/lib/ica_s390_stdll/ica_specific.c usr/lib/common/dlist.c	\
1f6f0c
 	usr/lib/common/mech_openssl.c					\
1f6f0c
 	usr/lib/common/utility_common.c usr/lib/common/ec_supported.c	\
1f6f0c
-	usr/lib/api/policyhelper.c
1f6f0c
+	usr/lib/api/policyhelper.c usr/lib/common/pqc_supported.c
1f6f0c
 
1f6f0c
 if ENABLE_LOCKS
1f6f0c
 opencryptoki_stdll_libpkcs11_ica_la_SOURCES +=				\
1f6f0c
diff --git a/usr/lib/icsf_stdll/icsf_stdll.mk b/usr/lib/icsf_stdll/icsf_stdll.mk
1f6f0c
index ee83f674..ebf24290 100644
1f6f0c
--- a/usr/lib/icsf_stdll/icsf_stdll.mk
1f6f0c
+++ b/usr/lib/icsf_stdll/icsf_stdll.mk
1f6f0c
@@ -43,7 +43,7 @@ opencryptoki_stdll_libpkcs11_icsf_la_SOURCES = usr/lib/common/asn1.c	\
1f6f0c
 	usr/lib/icsf_stdll/icsf_specific.c				\
1f6f0c
 	usr/lib/icsf_stdll/icsf.c usr/lib/common/utility_common.c	\
1f6f0c
 	usr/lib/common/ec_supported.c usr/lib/api/policyhelper.c	\
1f6f0c
-	usr/lib/config/configuration.c					\
1f6f0c
+	usr/lib/config/configuration.c usr/lib/common/pqc_supported.c	\
1f6f0c
 	usr/lib/config/cfgparse.y usr/lib/config/cfglex.l		\
1f6f0c
 	usr/lib/common/mech_openssl.c
1f6f0c
 
1f6f0c
diff --git a/usr/lib/soft_stdll/soft_stdll.mk b/usr/lib/soft_stdll/soft_stdll.mk
1f6f0c
index 6cdf82b8..7a842ddc 100644
1f6f0c
--- a/usr/lib/soft_stdll/soft_stdll.mk
1f6f0c
+++ b/usr/lib/soft_stdll/soft_stdll.mk
1f6f0c
@@ -36,7 +36,7 @@ opencryptoki_stdll_libpkcs11_sw_la_SOURCES =				\
1f6f0c
 	usr/lib/soft_stdll/soft_specific.c usr/lib/common/attributes.c	\
1f6f0c
 	usr/lib/common/dlist.c usr/lib/common/mech_openssl.c		\
1f6f0c
 	usr/lib/common/utility_common.c usr/lib/common/ec_supported.c	\
1f6f0c
-	usr/lib/api/policyhelper.c
1f6f0c
+	usr/lib/api/policyhelper.c usr/lib/common/pqc_supported.c
1f6f0c
 
1f6f0c
 if ENABLE_LOCKS
1f6f0c
 opencryptoki_stdll_libpkcs11_sw_la_SOURCES +=				\
1f6f0c
diff --git a/usr/lib/tpm_stdll/tpm_stdll.mk b/usr/lib/tpm_stdll/tpm_stdll.mk
1f6f0c
index 54551c1f..7fa18121 100644
1f6f0c
--- a/usr/lib/tpm_stdll/tpm_stdll.mk
1f6f0c
+++ b/usr/lib/tpm_stdll/tpm_stdll.mk
1f6f0c
@@ -38,7 +38,7 @@ opencryptoki_stdll_libpkcs11_tpm_la_SOURCES =				\
1f6f0c
 	usr/lib/tpm_stdll/tpm_openssl.c usr/lib/tpm_stdll/tpm_util.c	\
1f6f0c
 	usr/lib/common/dlist.c usr/lib/common/mech_openssl.c		\
1f6f0c
 	usr/lib/common/utility_common.c usr/lib/common/ec_supported.c	\
1f6f0c
-	usr/lib/api/policyhelper.c
1f6f0c
+	usr/lib/api/policyhelper.c usr/lib/common/pqc_supported.c
1f6f0c
 
1f6f0c
 if ENABLE_LOCKS
1f6f0c
 opencryptoki_stdll_libpkcs11_tpm_la_SOURCES +=				\
1f6f0c
diff --git a/usr/sbin/pkcscca/pkcscca.mk b/usr/sbin/pkcscca/pkcscca.mk
1f6f0c
index 187a93f2..59300ef5 100644
1f6f0c
--- a/usr/sbin/pkcscca/pkcscca.mk
1f6f0c
+++ b/usr/sbin/pkcscca/pkcscca.mk
1f6f0c
@@ -41,7 +41,7 @@ usr_sbin_pkcscca_pkcscca_SOURCES = usr/lib/common/asn1.c		\
1f6f0c
 	usr/lib/common/dlist.c usr/sbin/pkcscca/pkcscca.c		\
1f6f0c
 	usr/lib/common/utility_common.c usr/lib/common/ec_supported.c	\
1f6f0c
 	usr/lib/common/pin_prompt.c usr/lib/common/mech_openssl.c	\
1f6f0c
-	usr/lib/api/policyhelper.c
1f6f0c
+	usr/lib/api/policyhelper.c usr/lib/common/pqc_supported.c
1f6f0c
 
1f6f0c
 nodist_usr_sbin_pkcscca_pkcscca_SOURCES = usr/lib/api/mechtable.c
1f6f0c
 
1f6f0c
-- 
1f6f0c
2.16.2.windows.1
1f6f0c