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

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