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