Blame SOURCES/0018-COMMON-Add-post-quantum-algorithm-OIDs.patch

447573
From 67ed25a8f7764e61647c3c31d09a1e60db38006b Mon Sep 17 00:00:00 2001
447573
From: Ingo Franzki <ifranzki@linux.ibm.com>
447573
Date: Wed, 16 Feb 2022 11:20:54 +0100
447573
Subject: [PATCH 18/34] COMMON: Add post-quantum algorithm OIDs
447573
447573
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
447573
---
447573
 usr/include/include.mk         |  2 +-
447573
 usr/include/pqc_oids.h         | 48 ++++++++++++++++++++++++++
447573
 usr/lib/common/common.mk       |  3 +-
447573
 usr/lib/common/globals.c       |  1 +
447573
 usr/lib/common/pqc_defs.h      | 48 ++++++++++++++++++++++++++
447573
 usr/lib/common/pqc_supported.c | 78 ++++++++++++++++++++++++++++++++++++++++++
447573
 6 files changed, 178 insertions(+), 2 deletions(-)
447573
 create mode 100644 usr/include/pqc_oids.h
447573
 create mode 100644 usr/lib/common/pqc_defs.h
447573
 create mode 100644 usr/lib/common/pqc_supported.c
447573
447573
diff --git a/usr/include/include.mk b/usr/include/include.mk
447573
index 79e593d7..a63e043f 100644
447573
--- a/usr/include/include.mk
447573
+++ b/usr/include/include.mk
447573
@@ -3,7 +3,7 @@ opencryptokiincludedir = ${includedir}/opencryptoki
447573
 opencryptokiinclude_HEADERS =						\
447573
 	usr/include/apiclient.h	usr/include/pkcs11types.h		\
447573
 	usr/include/pkcs11.h						\
447573
-	usr/include/ec_curves.h
447573
+	usr/include/ec_curves.h usr/include/pqc_oids.h
447573
 
447573
 noinst_HEADERS +=							\
447573
 	usr/include/apictl.h usr/include/local_types.h			\
447573
diff --git a/usr/include/pqc_oids.h b/usr/include/pqc_oids.h
447573
new file mode 100644
447573
index 00000000..0891373e
447573
--- /dev/null
447573
+++ b/usr/include/pqc_oids.h
447573
@@ -0,0 +1,48 @@
447573
+/*
447573
+ * COPYRIGHT (c) International Business Machines Corp. 2022
447573
+ *
447573
+ * This program is provided under the terms of the Common Public License,
447573
+ * version 1.0 (CPL-1.0). Any use, reproduction or distribution for this
447573
+ * software constitutes recipient's acceptance of CPL-1.0 terms which can be
447573
+ * found in the file LICENSE file or at
447573
+ * https://opensource.org/licenses/cpl1.0.php
447573
+ */
447573
+
447573
+
447573
+#ifndef _PQC_OIDS_H_
447573
+#define _PQC_OIDS_H_
447573
+
447573
+/*
447573
+ * OIDs and their DER encoding for the post-quantum crypto algorithms
447573
+ * supported by OpenCryptoki:
447573
+ */
447573
+
447573
+/* Dilithium Round 2 high-security (SHAKE-256): 1.3.6.1.4.1.2.267.1.6.5 */
447573
+#define OCK_DILITHIUM_R2_65        { 0x06, 0x0B, 0x2B, 0x06, 0x01, 0x04, \
447573
+                                     0x01, 0x02, 0x82, 0x0B, 0x01, 0x06, 0x05 }
447573
+
447573
+/* Dilithium Round 2 for outbound authentication: 1.3.6.1.4.1.2.267.1.8.7 */
447573
+#define OCK_DILITHIUM_R2_87        { 0x06, 0x0B, 0x2B, 0x06, 0x01, 0x04, \
447573
+                                     0x01, 0x02, 0x82, 0x0B, 0x01, 0x08, 0x07 }
447573
+
447573
+/* Dilithium Round 3 weak (SHAKE-256): 1.3.6.1.4.1.2.267.7.4.4 */
447573
+#define OCK_DILITHIUM_R3_44        { 0x06, 0x0B, 0x2B, 0x06, 0x01, 0x04, \
447573
+                                     0x01, 0x02, 0x82, 0x0B, 0x07, 0x04, 0x04 }
447573
+
447573
+/* Dilithium Round 3 recommended (SHAKE-256): 1.3.6.1.4.1.2.267.7.6.5 */
447573
+#define OCK_DILITHIUM_R3_65        { 0x06, 0x0B, 0x2B, 0x06, 0x01, 0x04, \
447573
+                                     0x01, 0x02, 0x82, 0x0B, 0x07, 0x06, 0x05 }
447573
+
447573
+/* Dilithium Round 3 high-security (SHAKE-256): 1.3.6.1.4.1.2.267.7.8.7 */
447573
+#define OCK_DILITHIUM_R3_87        { 0x06, 0x0B, 0x2B, 0x06, 0x01, 0x04, \
447573
+                                     0x01, 0x02, 0x82, 0x0B, 0x07, 0x08, 0x07 }
447573
+
447573
+/* Kyber Round 2 768 (SHAKE-128): 1.3.6.1.4.1.2.267.5.3.3 */
447573
+#define OCK_KYBER_R2_768           { 0x06, 0x0B, 0x2B, 0x06, 0x01, 0x04, \
447573
+                                     0x01, 0x02, 0x82, 0x0B, 0x05, 0x03, 0x03 }
447573
+
447573
+/* Kyber Round 2 1024 (SHAKE-128): 1.3.6.1.4.1.2.267.5.4.4 */
447573
+#define OCK_KYBER_R2_1024          { 0x06, 0x0B, 0x2B, 0x06, 0x01, 0x04, \
447573
+                                     0x01, 0x02, 0x82, 0x0B, 0x05, 0x04, 0x04 }
447573
+
447573
+#endif                          // _PQC_OIDS_H_
447573
diff --git a/usr/lib/common/common.mk b/usr/lib/common/common.mk
447573
index 6341cb74..93f1e21f 100644
447573
--- a/usr/lib/common/common.mk
447573
+++ b/usr/lib/common/common.mk
447573
@@ -7,4 +7,5 @@ noinst_HEADERS +=							\
447573
 	usr/lib/common/p11util.h usr/lib/common/event_client.h		\
447573
 	usr/lib/common/list.h usr/lib/common/tok_specific.h		\
447573
 	usr/lib/common/uri_enc.h usr/lib/common/uri.h 			\
447573
-	usr/lib/common/buffer.h usr/lib/common/pin_prompt.h
447573
+	usr/lib/common/buffer.h usr/lib/common/pin_prompt.h		\
447573
+	usr/lib/common/pqc_defs.h
447573
diff --git a/usr/lib/common/globals.c b/usr/lib/common/globals.c
447573
index db4d352c..5b79e785 100644
447573
--- a/usr/lib/common/globals.c
447573
+++ b/usr/lib/common/globals.c
447573
@@ -27,6 +27,7 @@
447573
 #include "defs.h"
447573
 #include "host_defs.h"
447573
 #include "h_extern.h"
447573
+#include "pqc_oids.h"
447573
 
447573
 struct ST_FCN_LIST function_list;
447573
 
447573
diff --git a/usr/lib/common/pqc_defs.h b/usr/lib/common/pqc_defs.h
447573
new file mode 100644
447573
index 00000000..51ee1200
447573
--- /dev/null
447573
+++ b/usr/lib/common/pqc_defs.h
447573
@@ -0,0 +1,48 @@
447573
+/*
447573
+ * COPYRIGHT (c) International Business Machines Corp. 2022
447573
+ *
447573
+ * This program is provided under the terms of the Common Public License,
447573
+ * version 1.0 (CPL-1.0). Any use, reproduction or distribution for this
447573
+ * software constitutes recipient's acceptance of CPL-1.0 terms which can be
447573
+ * found in the file LICENSE file or at
447573
+ * https://opensource.org/licenses/cpl1.0.php
447573
+ */
447573
+
447573
+#ifndef _PQC_DEFS
447573
+#define _PQC_DEFS
447573
+
447573
+#include <stdio.h>
447573
+
447573
+#include "pqc_oids.h"
447573
+
447573
+extern const CK_BYTE dilithium_r2_65[];
447573
+extern const CK_ULONG dilithium_r2_65_len;
447573
+extern const CK_BYTE dilithium_r2_87[];
447573
+extern const CK_ULONG dilithium_r2_87_len;
447573
+extern const CK_BYTE dilithium_r3_44[];
447573
+extern const CK_ULONG dilithium_r3_44_len;
447573
+extern const CK_BYTE dilithium_r3_56[];
447573
+extern const CK_ULONG dilithium_r3_56_len;
447573
+extern const CK_BYTE dilithium_r3_87[];
447573
+extern const CK_ULONG dilithium_r3_87_len;
447573
+
447573
+extern const CK_BYTE kyber_r2_768[];
447573
+extern const CK_ULONG kyber_r2_768_len;
447573
+extern const CK_BYTE kyber_r2_1024[];
447573
+extern const CK_ULONG kyber_r2_1024_len;
447573
+
447573
+struct pqc_oid {
447573
+    const CK_BYTE *oid;
447573
+    CK_ULONG oid_len;
447573
+    CK_ULONG keyform;
447573
+};
447573
+
447573
+extern const struct pqc_oid dilithium_oids[];
447573
+extern const struct pqc_oid kyber_oids[];
447573
+
447573
+const struct pqc_oid *find_pqc_by_keyform(const struct pqc_oid *pqcs,
447573
+                                          CK_ULONG keyform);
447573
+const struct pqc_oid *find_pqc_by_oid(const struct pqc_oid *pqcs,
447573
+                                      CK_BYTE *oid, CK_ULONG oid_len);
447573
+
447573
+#endif
447573
diff --git a/usr/lib/common/pqc_supported.c b/usr/lib/common/pqc_supported.c
447573
new file mode 100644
447573
index 00000000..4f048c33
447573
--- /dev/null
447573
+++ b/usr/lib/common/pqc_supported.c
447573
@@ -0,0 +1,78 @@
447573
+/*
447573
+ * COPYRIGHT (c) International Business Machines Corp. 2022
447573
+ *
447573
+ * This program is provided under the terms of the Common Public License,
447573
+ * version 1.0 (CPL-1.0). Any use, reproduction or distribution for this
447573
+ * software constitutes recipient's acceptance of CPL-1.0 terms which can be
447573
+ * found in the file LICENSE file or at
447573
+ * https://opensource.org/licenses/cpl1.0.php
447573
+ */
447573
+
447573
+#include <string.h>
447573
+#include "pkcs11types.h"
447573
+#include "pqc_defs.h"
447573
+
447573
+const CK_BYTE dilithium_r2_65[] = OCK_DILITHIUM_R2_65;
447573
+const CK_ULONG dilithium_r2_65_len = sizeof(dilithium_r2_65);
447573
+const CK_BYTE dilithium_r2_87[] = OCK_DILITHIUM_R2_87;
447573
+const CK_ULONG dilithium_r2_87_len = sizeof(dilithium_r2_87);
447573
+const CK_BYTE dilithium_r3_44[] = OCK_DILITHIUM_R3_44;
447573
+const CK_ULONG dilithium_r3_44_len = sizeof(dilithium_r3_44);
447573
+const CK_BYTE dilithium_r3_65[] = OCK_DILITHIUM_R3_65;
447573
+const CK_ULONG dilithium_r3_65_len = sizeof(dilithium_r3_65);
447573
+const CK_BYTE dilithium_r3_87[] = OCK_DILITHIUM_R3_87;
447573
+const CK_ULONG dilithium_r3_87_len = sizeof(dilithium_r3_87);
447573
+
447573
+const struct pqc_oid dilithium_oids[] = {
447573
+    { .oid = dilithium_r2_65, .oid_len = dilithium_r2_65_len,
447573
+      .keyform = CK_IBM_DILITHIUM_KEYFORM_ROUND2_65 },
447573
+    { .oid = dilithium_r2_87, .oid_len = dilithium_r2_87_len,
447573
+      .keyform = CK_IBM_DILITHIUM_KEYFORM_ROUND2_87 },
447573
+    { .oid = dilithium_r3_44, .oid_len = dilithium_r3_44_len,
447573
+      .keyform = CK_IBM_DILITHIUM_KEYFORM_ROUND3_44 },
447573
+    { .oid = dilithium_r3_65, .oid_len = dilithium_r3_65_len,
447573
+      .keyform = CK_IBM_DILITHIUM_KEYFORM_ROUND3_65 },
447573
+    { .oid = dilithium_r3_87, .oid_len = dilithium_r3_87_len,
447573
+      .keyform = CK_IBM_DILITHIUM_KEYFORM_ROUND3_87 },
447573
+    { .oid = NULL, .oid_len = 0, .keyform = 0 }
447573
+};
447573
+
447573
+const CK_BYTE kyber_r2_768[] = OCK_KYBER_R2_768;
447573
+const CK_ULONG kyber_r2_768_len = sizeof(kyber_r2_768);
447573
+const CK_BYTE kyber_r2_1024[] = OCK_KYBER_R2_1024;
447573
+const CK_ULONG kyber_r2_1024_len = sizeof(kyber_r2_1024);
447573
+
447573
+const struct pqc_oid kyber_oids[] = {
447573
+    { .oid = kyber_r2_768, .oid_len = kyber_r2_768_len,
447573
+       .keyform = CK_IBM_KYBER_KEYFORM_ROUND2_768 },
447573
+    { .oid = kyber_r2_1024, .oid_len = kyber_r2_1024_len,
447573
+      .keyform = CK_IBM_KYBER_KEYFORM_ROUND2_1024 },
447573
+    { .oid = NULL, .oid_len = 0, .keyform = 0 }
447573
+};
447573
+
447573
+const struct pqc_oid *find_pqc_by_keyform(const struct pqc_oid *pqcs,
447573
+                                          CK_ULONG keyform)
447573
+{
447573
+    CK_ULONG i;
447573
+
447573
+    for (i = 0; pqcs[i].oid != NULL; i++) {
447573
+        if (pqcs[i].keyform == keyform)
447573
+            return &pqcs[i];
447573
+    }
447573
+
447573
+    return NULL;
447573
+}
447573
+
447573
+const struct pqc_oid *find_pqc_by_oid(const struct pqc_oid *pqcs,
447573
+                                      CK_BYTE *oid, CK_ULONG oid_len)
447573
+{
447573
+    CK_ULONG i;
447573
+
447573
+    for (i = 0; pqcs[i].oid != NULL; i++) {
447573
+        if (pqcs[i].oid_len == oid_len &&
447573
+            memcmp(pqcs[i].oid, oid, oid_len) == 0)
447573
+            return &pqcs[i];
447573
+    }
447573
+
447573
+    return NULL;
447573
+}
447573
-- 
447573
2.16.2.windows.1
447573