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