Blame SOURCES/0017-COMMON-Add-defines-for-Kyber.patch

447573
From d4bb3258779d757ce6faf5b698c70af77ab7647f Mon Sep 17 00:00:00 2001
447573
From: Ingo Franzki <ifranzki@linux.ibm.com>
447573
Date: Wed, 16 Feb 2022 13:51:16 +0100
447573
Subject: [PATCH 17/34] COMMON: Add defines for Kyber
447573
447573
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
447573
---
447573
 usr/include/pkcs11types.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++
447573
 usr/lib/common/p11util.c  |  4 ++++
447573
 2 files changed, 53 insertions(+)
447573
447573
diff --git a/usr/include/pkcs11types.h b/usr/include/pkcs11types.h
447573
index 6bf9c1fa..3d967a13 100644
447573
--- a/usr/include/pkcs11types.h
447573
+++ b/usr/include/pkcs11types.h
447573
@@ -439,6 +439,11 @@ typedef CK_ULONG CK_KEY_TYPE;
447573
 #endif
447573
 #define CKK_IBM_DILITHIUM        CKK_IBM_PQC_DILITHIUM
447573
 
447573
+#ifndef OCK_NO_EP11_DEFINES
447573
+#define CKK_IBM_PQC_KYBER        CKK_VENDOR_DEFINED + 0x10024
447573
+#endif
447573
+#define CKK_IBM_KYBER            CKK_IBM_PQC_KYBER
447573
+
447573
 /* CK_CERTIFICATE_TYPE is a value that identifies a certificate
447573
  * type */
447573
 /* CK_CERTIFICATE_TYPE was changed from CK_USHORT to CK_ULONG
447573
@@ -614,6 +619,49 @@ typedef CK_ULONG CK_ATTRIBUTE_TYPE;
447573
 #define CKA_IBM_DILITHIUM_T0      (CKA_VENDOR_DEFINED + 0xd0007)
447573
 #define CKA_IBM_DILITHIUM_T1      (CKA_VENDOR_DEFINED + 0xd0008)
447573
 
447573
+#define CKA_IBM_KYBER_MODE        (CKA_VENDOR_DEFINED + 0x0000E)
447573
+
447573
+#define CKA_IBM_KYBER_KEYFORM     (CKA_VENDOR_DEFINED + 0xd0009)
447573
+#define CKA_IBM_KYBER_PK          (CKA_VENDOR_DEFINED + 0xd000A)
447573
+#define CKA_IBM_KYBER_SK          (CKA_VENDOR_DEFINED + 0xd000B)
447573
+
447573
+#define CK_IBM_KYBER_KEYFORM_ROUND2_768    1
447573
+#define CK_IBM_KYBER_KEYFORM_ROUND2_1024   2
447573
+
447573
+#define CK_IBM_KYBER_KEM_VERSION           0
447573
+
447573
+typedef CK_ULONG CK_IBM_KYBER_KEM_MODE;
447573
+
447573
+#define CK_IBM_KYBER_KEM_ENCAPSULATE       1
447573
+#define CK_IBM_KYBER_KEM_DECAPSULATE       2
447573
+
447573
+typedef CK_ULONG CK_IBM_KYBER_KDF_TYPE;
447573
+
447573
+#if !defined(CKD_VENDOR_DEFINED)
447573
+#define CKD_VENDOR_DEFINED                 0x80000000UL
447573
+#endif
447573
+
447573
+#ifndef OCK_NO_EP11_DEFINES
447573
+#define CKD_IBM_HYBRID_NULL                CKD_VENDOR_DEFINED + 0x00000001UL
447573
+#define CKD_IBM_HYBRID_SHA1_KDF            CKD_VENDOR_DEFINED + 0x00000002UL
447573
+#define CKD_IBM_HYBRID_SHA224_KDF          CKD_VENDOR_DEFINED + 0x00000003UL
447573
+#define CKD_IBM_HYBRID_SHA256_KDF          CKD_VENDOR_DEFINED + 0x00000004UL
447573
+#define CKD_IBM_HYBRID_SHA384_KDF          CKD_VENDOR_DEFINED + 0x00000005UL
447573
+#define CKD_IBM_HYBRID_SHA512_KDF          CKD_VENDOR_DEFINED + 0x00000006UL
447573
+#endif
447573
+
447573
+typedef struct CK_IBM_KYBER_PARAMS {
447573
+    CK_ULONG                ulVersion;
447573
+    CK_IBM_KYBER_KEM_MODE   mode;
447573
+    CK_IBM_KYBER_KDF_TYPE   kdf;
447573
+    CK_BBOOL                bPrepend;
447573
+    CK_BYTE                 *pCipher;
447573
+    CK_ULONG                ulCipherLen;
447573
+    CK_BYTE                 *pSharedData;
447573
+    CK_ULONG                ulSharedDataLen;
447573
+    CK_OBJECT_HANDLE        hSecret;
447573
+} CK_IBM_KYBER_PARAMS;
447573
+
447573
 /* For NSS 3.30: */
447573
 #define NSSCK_VENDOR_NSS          0x4E534350
447573
 #define CKA_NSS                   (CKA_VENDOR_DEFINED | NSSCK_VENDOR_NSS)
447573
@@ -941,6 +989,7 @@ typedef CK_ULONG CK_MECHANISM_TYPE;
447573
 #define CKM_IBM_SHA3_512               CKM_VENDOR_DEFINED + 0x00010004
447573
 #define CKM_IBM_CMAC                   CKM_VENDOR_DEFINED + 0x00010007
447573
 #define CKM_IBM_DILITHIUM              CKM_VENDOR_DEFINED + 0x00010023
447573
+#define CKM_IBM_KYBER                  CKM_VENDOR_DEFINED + 0x00010024
447573
 #define CKM_IBM_SHA3_224_HMAC          CKM_VENDOR_DEFINED + 0x00010025
447573
 #define CKM_IBM_SHA3_256_HMAC          CKM_VENDOR_DEFINED + 0x00010026
447573
 #define CKM_IBM_SHA3_384_HMAC          CKM_VENDOR_DEFINED + 0x00010027
447573
diff --git a/usr/lib/common/p11util.c b/usr/lib/common/p11util.c
447573
index f3a031e3..8b81ab42 100644
447573
--- a/usr/lib/common/p11util.c
447573
+++ b/usr/lib/common/p11util.c
447573
@@ -234,6 +234,10 @@ const char *p11_get_cka(CK_ATTRIBUTE_TYPE atype)
447573
         _sym2str(CKA_IBM_DILITHIUM_T0);
447573
         _sym2str(CKA_IBM_DILITHIUM_T1);
447573
         _sym2str(CKA_IBM_PQC_PARAMS);
447573
+        _sym2str(CKA_IBM_KYBER_KEYFORM);
447573
+        _sym2str(CKA_IBM_KYBER_MODE);
447573
+        _sym2str(CKA_IBM_KYBER_PK);
447573
+        _sym2str(CKA_IBM_KYBER_SK);
447573
     default:
447573
         sprintf(buf, "unknown attribute type 0x%08lx", atype);
447573
         return buf;
447573
-- 
447573
2.16.2.windows.1
447573