Blame SOURCES/0031-p11sak-Add-support-for-IBM-Kyber-key-type.patch

971d89
From d257df88500b3e55156d198ec305042799e2bff9 Mon Sep 17 00:00:00 2001
971d89
From: Ingo Franzki <ifranzki@linux.ibm.com>
971d89
Date: Tue, 8 Nov 2022 17:03:11 +0100
971d89
Subject: [PATCH 31/34] p11sak: Add support for IBM Kyber key type
971d89
971d89
Support the following Kyber versions to be specified with the
971d89
generate-key command: r2_768, r2_1024.
971d89
971d89
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
971d89
---
971d89
 man/man1/p11sak.1.in                      |  65 ++++++++++++--
971d89
 usr/sbin/p11sak/p11sak.c                  | 141 +++++++++++++++++++++++++-----
971d89
 usr/sbin/p11sak/p11sak.h                  |   1 +
971d89
 usr/sbin/p11sak/p11sak_defined_attrs.conf |   6 +-
971d89
 4 files changed, 183 insertions(+), 30 deletions(-)
971d89
971d89
diff --git a/man/man1/p11sak.1.in b/man/man1/p11sak.1.in
971d89
index 6938b203..2b75b117 100644
971d89
--- a/man/man1/p11sak.1.in
971d89
+++ b/man/man1/p11sak.1.in
971d89
@@ -16,7 +16,7 @@ p11sak \- generate and list token keys in an openCryptoki token repository.
971d89
 
971d89
 .SH DESCRIPTION
971d89
 .B p11sak can be used to generate, list and delete the token keys in an openCryptoki token repository.
971d89
-The utility provides a flexible key management tool in openCryptoki to list and generate symmetric (DES; 3DES, AES) and asymetric (RSA, EC) keys.
971d89
+The utility provides a flexible key management tool in openCryptoki to list and generate symmetric (DES, 3DES, AES) and asymmetric (RSA, EC, IBM Dilithium, IBM Kyber) keys.
971d89
 This tool is especially capable of a well defined listing of keys with their PKCS #11 attributes.
971d89
 .
971d89
 .
971d89
@@ -282,11 +282,54 @@ attribute of the key and
971d89
 can be used to set the binary attributes of the key (see below for detailed description of the attributes). 
971d89
 .
971d89
 .PP
971d89
+.SS "Generating IBM Kyber keys"
971d89
+.
971d89
+.B p11sak
971d89
+.BR generate-key | gen-key | gen
971d89
+.BR ibm-kyber
971d89
+.BR VERSION
971d89
+.B \-\-slot
971d89
+.IR SLOTID
971d89
+.B \-\-pin
971d89
+.IR PIN
971d89
+.B \-\-label
971d89
+.IR LABEL
971d89
+.B \-\-attr
971d89
+.I [M R L S E D G V W U A X N T]
971d89
+.B \-\-help | \-h
971d89
+.PP
971d89
+Use the
971d89
+.B generate-key
971d89
+.B ibm-kyber
971d89
+.B VERSION
971d89
+command and key argument to generate an IBM Kyber key, where
971d89
+.I VERSION
971d89
+specifies the version of the IBM Kyber keypair. The following arguments can be used for respective keys:
971d89
+.B r2_768 | r2_1024
971d89
+.PP
971d89
+The
971d89
+.B \-\-slot
971d89
+.IR SLOTID
971d89
+and
971d89
+.B \-\-pin
971d89
+.IR PIN
971d89
+options are required to set the token to
971d89
+.IR SLOTID
971d89
+and the token PIN. The
971d89
+.B \-\-label
971d89
+option allows the user to set the
971d89
+.IR LABEL
971d89
+attribute of the key and
971d89
+.B \-\-attr
971d89
+.I [M R L S E D G V W U A X N T]
971d89
+can be used to set the binary attributes of the key (see below for detailed description of the attributes). 
971d89
+.
971d89
+.PP
971d89
 .SS "Listing symmetric and asymmetric keys"
971d89
 .
971d89
 .B p11sak
971d89
 .BR list-key | ls-key | ls
971d89
-.BR des | 3des | aes | rsa | ec | ibm-dilithium | public | private | secret | all
971d89
+.BR des | 3des | aes | rsa | ec | ibm-dilithium | ibm-kyber | public | private | secret | all
971d89
 .B \-\-slot
971d89
 .IR SLOTID
971d89
 .B \-\-pin
971d89
@@ -298,14 +341,14 @@ can be used to set the binary attributes of the key (see below for detailed desc
971d89
 .PP
971d89
 Use the
971d89
 .B list-key | ls-key | ls
971d89
-command and key argument to list DES, 3DES, AES, RSA, EC, or IBM Dilithium keys, respectively. Public, private, secret, or all keys can also be listed irrespective of key type.
971d89
+command and key argument to list DES, 3DES, AES, RSA, EC, IBM Dilithium, or IBM Kyber keys, respectively. Public, private, secret, or all keys can also be listed irrespective of key type.
971d89
 .
971d89
 .PP
971d89
 .SS "Deleting symmetric and asymmetric keys"
971d89
 .
971d89
 .B p11sak
971d89
 .BR remove-key | rm-key | rm
971d89
-.BR des | 3des | aes | rsa | ec | ibm-dilithium
971d89
+.BR des | 3des | aes | rsa | ec | ibm-dilithium | ibm-kyber
971d89
 .B \-\-slot
971d89
 .IR SLOTID
971d89
 .B \-\-pin
971d89
@@ -317,7 +360,7 @@ command and key argument to list DES, 3DES, AES, RSA, EC, or IBM Dilithium keys,
971d89
 .PP
971d89
 Use the
971d89
 .B remove-key | rm-key | rm
971d89
-command and key argument to delete DES, 3DES, AES, RSA, EC, or IBM Dilithium keys, respectively. All specified cipher keys will be prompted to be deleted unless 
971d89
+command and key argument to delete DES, 3DES, AES, RSA, EC, IBM Dilithium, or IBM Kyber keys, respectively. All specified cipher keys will be prompted to be deleted unless 
971d89
 a specific key with the 
971d89
 .B \-\-label
971d89
 .IR LABEL
971d89
@@ -331,7 +374,7 @@ option.
971d89
 .
971d89
 .SH ARGS
971d89
 .
971d89
-.SS "des | 3des | aes | rsa | ec | ibm-dilithium | public | private | secret | all"
971d89
+.SS "des | 3des | aes | rsa | ec | ibm-dilithium | ibm-kyber | public | private | secret | all"
971d89
 
971d89
 selects the respective symmetric or asymetric key to be generated or listed. The
971d89
 .B public|private|secret|all
971d89
@@ -378,6 +421,16 @@ to select the IBM dilithium version used to generate the key.
971d89
 .
971d89
 .
971d89
 .
971d89
+.SS "r2_768|r2_1024"
971d89
+the
971d89
+.B ibm-kyber
971d89
+argument has to be followed by either of these
971d89
+.I VERSION
971d89
+to select the IBM kyber version used to generate the key.
971d89
+.PP
971d89
+.
971d89
+.
971d89
+.
971d89
 .SH OPTIONS
971d89
 
971d89
 .SS "\-\-slot SLOTID"
971d89
diff --git a/usr/sbin/p11sak/p11sak.c b/usr/sbin/p11sak/p11sak.c
971d89
index 5ceb145b..38564155 100644
971d89
--- a/usr/sbin/p11sak/p11sak.c
971d89
+++ b/usr/sbin/p11sak/p11sak.c
971d89
@@ -130,6 +130,8 @@ static const char* kt2str(p11sak_kt ktype)
971d89
         return "EC";
971d89
     case kt_IBM_DILITHIUM:
971d89
         return "IBM DILITHIUM";
971d89
+    case kt_IBM_KYBER:
971d89
+        return "IBM KYBER";
971d89
     case kt_GENERIC:
971d89
         return "GENERIC";
971d89
     case kt_SECRET:
971d89
@@ -170,6 +172,9 @@ static CK_RV kt2CKK(p11sak_kt ktype, CK_KEY_TYPE *a_key_type)
971d89
     case kt_IBM_DILITHIUM:
971d89
         *a_key_type = CKK_IBM_PQC_DILITHIUM;
971d89
         break; 
971d89
+    case kt_IBM_KYBER:
971d89
+        *a_key_type = CKK_IBM_PQC_KYBER;
971d89
+        break;
971d89
     case kt_GENERIC:
971d89
         *a_key_type = CKK_GENERIC_SECRET;
971d89
         break;
971d89
@@ -277,6 +282,8 @@ static const char* CKK2a(CK_KEY_TYPE t)
971d89
         return "EC";
971d89
     case CKK_IBM_PQC_DILITHIUM:
971d89
         return "IBM DILILTHIUM";
971d89
+    case CKK_IBM_PQC_KYBER:
971d89
+        return "IBM KYBER";
971d89
     case CKK_RSA:
971d89
         return "RSA";
971d89
     case CKK_DH:
971d89
@@ -358,6 +365,7 @@ static void print_listkeys_help(void)
971d89
     printf("      rsa\n");
971d89
     printf("      ec\n");
971d89
     printf("      ibm-dilithium\n");
971d89
+    printf("      ibm-kyber\n");
971d89
     printf("      public\n");
971d89
     printf("      private\n");
971d89
     printf("      secret\n");
971d89
@@ -388,6 +396,7 @@ static void print_gen_help(void)
971d89
     printf("          brainpoolP512r1 | brainpoolP512t1 | curve25519 | curve448 | ed25519 | \n");
971d89
     printf("          ed448]\n");
971d89
     printf("      ibm-dilithium [r2_65 | r2_87 | r3_44 | r3_65 | r3_87]\n");
971d89
+    printf("      ibm-kyber [r2_768 | r2_1024]\n");
971d89
     printf("\n Options:\n");
971d89
     printf(
971d89
             "      --slot SLOTID                           openCryptoki repository token SLOTID.\n");
971d89
@@ -415,6 +424,7 @@ static void print_removekeys_help(void)
971d89
     printf("      rsa\n");
971d89
     printf("      ec\n");
971d89
     printf("      ibm-dilithium\n");
971d89
+    printf("      ibm-kyber\n");
971d89
     printf("\n Options:\n");
971d89
     printf(
971d89
             "      --slot SLOTID                           openCryptoki repository token SLOTID.\n");
971d89
@@ -545,6 +555,25 @@ static void print_gen_ibm_dilithium_help(void)
971d89
     printf("      -h, --help                              Show this help\n\n");
971d89
 }
971d89
 
971d89
+static void print_gen_ibm_kyber_help(void)
971d89
+{
971d89
+    printf("\n Usage: p11sak generate-key ibm-kyber [ARGS] [OPTIONS]\n");
971d89
+    printf("\n Args:\n");
971d89
+    printf("      r2_768\n");
971d89
+    printf("      r2_1024\n");
971d89
+    printf("\n Options:\n");
971d89
+    printf("      --slot SLOTID                           openCryptoki repository token SLOTID.\n");
971d89
+    printf("      --pin PIN                               pkcs11 user PIN\n");
971d89
+    printf("      --force-pin-prompt                      enforce user PIN prompt\n");
971d89
+    printf("      --label LABEL                           key label LABEL to be listed\n");
971d89
+    printf("      --label PUB_LABEL:PRIV_LABEL\n");
971d89
+    printf("              for asymmetric keys: set individual labels for public and private key\n");
971d89
+    printf("      --attr [M R L S E D G V W U A X N]      set key attributes\n");
971d89
+    printf("      --attr [[pub_attrs]:[priv_attrs]] \n");
971d89
+    printf("             for asymmetric keys: set individual key attributes, values see above\n");
971d89
+    printf("      -h, --help                              Show this help\n\n");
971d89
+}
971d89
+
971d89
 /**
971d89
  * Print help for generate-key command
971d89
  */
971d89
@@ -572,6 +601,9 @@ static CK_RV print_gen_keys_help(p11sak_kt *kt)
971d89
     case kt_IBM_DILITHIUM:
971d89
         print_gen_ibm_dilithium_help();
971d89
         break;
971d89
+    case kt_IBM_KYBER:
971d89
+        print_gen_ibm_kyber_help();
971d89
+        break;
971d89
     case no_key_type:
971d89
         print_gen_help();
971d89
         break;
971d89
@@ -797,6 +829,29 @@ static CK_RV read_dilithium_args(const char *dilithium_ver, CK_ULONG *keyform,
971d89
 
971d89
     return CKR_OK;
971d89
 }
971d89
+/**
971d89
+ * Builds the CKA_IBM_KYBER_KEYFORM attribute from the given version.
971d89
+ */
971d89
+static CK_RV read_kyber_args(const char *kyber_ver, CK_ULONG *keyform,
971d89
+                             CK_ATTRIBUTE *pubattr, CK_ULONG *pubcount)
971d89
+{
971d89
+    if (strcasecmp(kyber_ver, "r2_768") == 0) {
971d89
+        *keyform = CK_IBM_KYBER_KEYFORM_ROUND2_768;
971d89
+    } else if (strcasecmp(kyber_ver, "r2_1024") == 0) {
971d89
+        *keyform = CK_IBM_KYBER_KEYFORM_ROUND2_1024;
971d89
+    } else {
971d89
+        fprintf(stderr, "Unexpected case while parsing kyber version.\n");
971d89
+        fprintf(stderr, "Note: not all tokens support all versions.\n");
971d89
+        return CKR_ARGUMENTS_BAD;
971d89
+    }
971d89
+
971d89
+    pubattr[*pubcount].type = CKA_IBM_KYBER_KEYFORM;
971d89
+    pubattr[*pubcount].ulValueLen = sizeof(CK_ULONG);
971d89
+    pubattr[*pubcount].pValue = keyform;
971d89
+    (*pubcount)++;
971d89
+
971d89
+    return CKR_OK;
971d89
+}
971d89
 /**
971d89
  * Builds two CKA_LABEL attributes from given label.
971d89
  */
971d89
@@ -860,6 +915,9 @@ static CK_RV key_pair_gen_mech(p11sak_kt kt, CK_MECHANISM *pmech)
971d89
     case kt_IBM_DILITHIUM:
971d89
         pmech->mechanism = CKM_IBM_DILITHIUM;
971d89
         break;
971d89
+    case kt_IBM_KYBER:
971d89
+        pmech->mechanism = CKM_IBM_KYBER;
971d89
+        break;
971d89
     default:
971d89
         return CKR_MECHANISM_INVALID;
971d89
         break;
971d89
@@ -1131,6 +1189,8 @@ static CK_RV key_pair_gen(CK_SESSION_HANDLE session, CK_SLOT_ID slot,
971d89
             fprintf(stderr, "Key pair generation rejected by policy\n");
971d89
         else if (kt == kt_IBM_DILITHIUM && rc == CKR_KEY_SIZE_RANGE)
971d89
             fprintf(stderr, "IBM Dilithum version is not supported\n");
971d89
+        else if (kt == kt_IBM_KYBER && rc == CKR_KEY_SIZE_RANGE)
971d89
+            fprintf(stderr, "IBM Kyber version is not supported\n");
971d89
         else
971d89
             fprintf(stderr, "Key pair generation failed (error code 0x%lX: %s)\n", rc,
971d89
                     p11_get_ckr(rc));
971d89
@@ -1191,6 +1251,7 @@ static CK_RV tok_key_list_init(CK_SESSION_HANDLE session, p11sak_kt kt,
971d89
     case kt_RSAPKCS:
971d89
     case kt_EC:
971d89
     case kt_IBM_DILITHIUM:
971d89
+    case kt_IBM_KYBER:
971d89
         tmplt[count].type = CKA_KEY_TYPE;
971d89
         tmplt[count].pValue = &a_key_type;
971d89
         tmplt[count].ulValueLen = sizeof(CK_KEY_TYPE);
971d89
@@ -1871,27 +1932,42 @@ static CK_RV tok_key_get_key_type(CK_SESSION_HANDLE session, CK_OBJECT_HANDLE hk
971d89
  * Check args for gen_key command.
971d89
  */
971d89
 static CK_RV check_args_gen_key(p11sak_kt *kt, CK_ULONG keylength,
971d89
-                                char *ECcurve, char *dilithium_ver)
971d89
+                                char *ECcurve, char *pqc_ver)
971d89
 {
971d89
     switch (*kt) {
971d89
     case kt_DES:
971d89
     case kt_3DES:
971d89
         break;
971d89
     case kt_IBM_DILITHIUM:
971d89
-        if (dilithium_ver == NULL) {
971d89
+        if (pqc_ver == NULL) {
971d89
             fprintf(stderr,
971d89
                     "Cipher key type [%d] supported but Dilithium version not set in arguments. Try adding argument <r2_65>, <r2_87>, <r3_44>, <r3_65>, or <r3_87>\n",
971d89
                     *kt);
971d89
             return CKR_ARGUMENTS_BAD;
971d89
         }
971d89
-        if (strcasecmp(dilithium_ver, "r2_65") == 0 ||
971d89
-            strcasecmp(dilithium_ver, "r2_87") == 0 ||
971d89
-            strcasecmp(dilithium_ver, "r3_44") == 0 ||
971d89
-            strcasecmp(dilithium_ver, "r3_65") == 0 ||
971d89
-            strcasecmp(dilithium_ver, "r3_87") == 0) {
971d89
+        if (strcasecmp(pqc_ver, "r2_65") == 0 ||
971d89
+            strcasecmp(pqc_ver, "r2_87") == 0 ||
971d89
+            strcasecmp(pqc_ver, "r3_44") == 0 ||
971d89
+            strcasecmp(pqc_ver, "r3_65") == 0 ||
971d89
+            strcasecmp(pqc_ver, "r3_87") == 0) {
971d89
             break;
971d89
         } else {
971d89
-            fprintf(stderr, "IBM Dilithium version [%s] not supported \n", dilithium_ver);
971d89
+            fprintf(stderr, "IBM Dilithium version [%s] not supported \n", pqc_ver);
971d89
+            return CKR_ARGUMENTS_BAD;
971d89
+        }
971d89
+        break;
971d89
+    case kt_IBM_KYBER:
971d89
+        if (pqc_ver == NULL) {
971d89
+            fprintf(stderr,
971d89
+                    "Cipher key type [%d] supported but Kyber version not set in arguments. Try adding argument <r2_1024> or <r2_1024>\n",
971d89
+                    *kt);
971d89
+            return CKR_ARGUMENTS_BAD;
971d89
+        }
971d89
+        if (strcasecmp(pqc_ver, "r2_768") == 0 ||
971d89
+            strcasecmp(pqc_ver, "r2_1024") == 0) {
971d89
+            break;
971d89
+        } else {
971d89
+            fprintf(stderr, "IBM Kyber version [%s] not supported \n", pqc_ver);
971d89
             return CKR_ARGUMENTS_BAD;
971d89
         }
971d89
         break;
971d89
@@ -1947,6 +2023,7 @@ static CK_RV check_args_list_key(p11sak_kt *kt)
971d89
     case kt_3DES:
971d89
     case kt_EC:
971d89
     case kt_IBM_DILITHIUM:
971d89
+    case kt_IBM_KYBER:
971d89
     case kt_GENERIC:
971d89
     case kt_SECRET:
971d89
     case kt_PUBLIC:
971d89
@@ -1973,6 +2050,7 @@ static CK_RV check_args_remove_key(p11sak_kt *kt)
971d89
     case kt_RSAPKCS:
971d89
     case kt_EC:
971d89
     case kt_IBM_DILITHIUM:
971d89
+    case kt_IBM_KYBER:
971d89
     case kt_GENERIC:
971d89
     case kt_SECRET:
971d89
     case kt_PUBLIC:
971d89
@@ -2069,6 +2147,8 @@ static CK_RV parse_list_key_args(char *argv[], int argc, p11sak_kt *kt,
971d89
             *kt = kt_EC;
971d89
         } else if (strcasecmp(argv[i], "ibm-dilithium") == 0) {
971d89
             *kt = kt_IBM_DILITHIUM;
971d89
+        } else if (strcasecmp(argv[i], "ibm-kyber") == 0) {
971d89
+            *kt = kt_IBM_KYBER;
971d89
         } else if (strcasecmp(argv[i], "generic") == 0) {
971d89
             *kt = kt_GENERIC;
971d89
         } else if (strcasecmp(argv[i], "secret") == 0) {
971d89
@@ -2158,7 +2238,7 @@ static CK_RV parse_gen_key_args(char *argv[], int argc, p11sak_kt *kt,
971d89
                                 CK_ULONG *keylength, char **ECcurve,
971d89
                                 CK_SLOT_ID *slot, const char **pin,
971d89
                                 CK_ULONG *exponent, char **label,
971d89
-                                char **attr_string, char **dilithium_ver,
971d89
+                                char **attr_string, char **pqc_ver,
971d89
                                 int *force_pin_prompt)
971d89
 {
971d89
     CK_RV rc;
971d89
@@ -2190,7 +2270,11 @@ static CK_RV parse_gen_key_args(char *argv[], int argc, p11sak_kt *kt,
971d89
             i++;
971d89
         } else if (strcasecmp(argv[i], "ibm-dilithium") == 0) {
971d89
             *kt = kt_IBM_DILITHIUM;
971d89
-            *dilithium_ver = get_string_arg(i + 1, argv, argc);
971d89
+            *pqc_ver = get_string_arg(i + 1, argv, argc);
971d89
+            i++;
971d89
+        } else if (strcasecmp(argv[i], "ibm-kyber") == 0) {
971d89
+            *kt = kt_IBM_KYBER;
971d89
+            *pqc_ver = get_string_arg(i + 1, argv, argc);
971d89
             i++;
971d89
             /* Get options */
971d89
         } else if (strcmp(argv[i], "--slot") == 0) {
971d89
@@ -2281,7 +2365,7 @@ static CK_RV parse_gen_key_args(char *argv[], int argc, p11sak_kt *kt,
971d89
     }
971d89
 
971d89
     /* Check args */
971d89
-    rc = check_args_gen_key(kt, *keylength, *ECcurve, *dilithium_ver);
971d89
+    rc = check_args_gen_key(kt, *keylength, *ECcurve, *pqc_ver);
971d89
 
971d89
     /* Check required options */
971d89
     if (*label == NULL) {
971d89
@@ -2331,6 +2415,8 @@ static CK_RV parse_remove_key_args(char *argv[], int argc, p11sak_kt *kt,
971d89
             *kt = kt_EC;
971d89
         } else if (strcasecmp(argv[i], "ibm-dilithium") == 0) {
971d89
             *kt = kt_IBM_DILITHIUM;
971d89
+        } else if (strcasecmp(argv[i], "ibm-kyber") == 0) {
971d89
+            *kt = kt_IBM_KYBER;
971d89
             /* Get options */
971d89
         } else if (strcmp(argv[i], "--slot") == 0) {
971d89
             if (i + 1 < argc) {
971d89
@@ -2415,7 +2501,7 @@ static CK_RV parse_cmd_args(p11sak_cmd cmd, char *argv[], int argc,
971d89
                             CK_SLOT_ID *slot, const char **pin,
971d89
                             CK_ULONG *exponent, char **label,
971d89
                             char **attr_string, int *long_print, int *full_uri,
971d89
-                            CK_BBOOL *forceAll, char **dilithium_ver,
971d89
+                            CK_BBOOL *forceAll, char **pqc_ver,
971d89
                             int *force_pin_prompt)
971d89
 {
971d89
     CK_RV rc;
971d89
@@ -2423,7 +2509,7 @@ static CK_RV parse_cmd_args(p11sak_cmd cmd, char *argv[], int argc,
971d89
     switch (cmd) {
971d89
     case gen_key:
971d89
         rc = parse_gen_key_args(argv, argc, kt, keylength, ECcurve, slot, pin,
971d89
-                exponent, label, attr_string, dilithium_ver, force_pin_prompt);
971d89
+                exponent, label, attr_string, pqc_ver, force_pin_prompt);
971d89
         break;
971d89
     case list_key:
971d89
         rc = parse_list_key_args(argv, argc, kt, keylength, slot, pin,
971d89
@@ -2481,7 +2567,7 @@ done:
971d89
 static CK_RV generate_asymmetric_key(CK_SESSION_HANDLE session, CK_SLOT_ID slot,
971d89
                                      p11sak_kt kt, CK_ULONG keylength,
971d89
                                      CK_ULONG exponent, char *ECcurve,
971d89
-                                     char *label, char *attr_string, char *dilithium_ver)
971d89
+                                     char *label, char *attr_string, char *pqc_ver)
971d89
 {
971d89
     CK_OBJECT_HANDLE pub_keyh, prv_keyh;
971d89
     CK_ATTRIBUTE pub_attr[KEY_MAX_BOOL_ATTR_COUNT + 2];
971d89
@@ -2514,13 +2600,21 @@ static CK_RV generate_asymmetric_key(CK_SESSION_HANDLE session, CK_SLOT_ID slot,
971d89
         }
971d89
         break;
971d89
     case kt_IBM_DILITHIUM:
971d89
-        rc = read_dilithium_args(dilithium_ver, &keyform,
971d89
+        rc = read_dilithium_args(pqc_ver, &keyform,
971d89
                                  pub_attr, &pub_acount);
971d89
         if (rc) {
971d89
             fprintf(stderr, "Error parsing Dilithium parameters!\n");
971d89
             goto done;
971d89
         }
971d89
-        printf("Generating Dilithium keypair with %s\n", dilithium_ver);
971d89
+        printf("Generating Dilithium keypair with %s\n", pqc_ver);
971d89
+        break;
971d89
+    case kt_IBM_KYBER:
971d89
+        rc = read_kyber_args(pqc_ver, &keyform, pub_attr, &pub_acount);
971d89
+        if (rc) {
971d89
+            fprintf(stderr, "Error parsing Kyber parameters!\n");
971d89
+            goto done;
971d89
+        }
971d89
+        printf("Generating Kyber keypair with %s\n", pqc_ver);
971d89
         break;
971d89
     default:
971d89
         fprintf(stderr, "The key type %d is not yet supported.\n", kt);
971d89
@@ -2626,7 +2720,7 @@ done:
971d89
 static CK_RV generate_ckey(CK_SESSION_HANDLE session, CK_SLOT_ID slot,
971d89
                            p11sak_kt kt, CK_ULONG keylength, char *ECcurve,
971d89
                            CK_ULONG exponent, char *label, char *attr_string,
971d89
-                           char *dilithium_ver)
971d89
+                           char *pqc_ver)
971d89
 {
971d89
     switch (kt) {
971d89
     case kt_DES:
971d89
@@ -2637,8 +2731,9 @@ static CK_RV generate_ckey(CK_SESSION_HANDLE session, CK_SLOT_ID slot,
971d89
     case kt_RSAPKCS:
971d89
     case kt_EC:
971d89
     case kt_IBM_DILITHIUM:
971d89
+    case kt_IBM_KYBER:
971d89
         return generate_asymmetric_key(session, slot, kt, keylength, exponent,
971d89
-                ECcurve, label, attr_string, dilithium_ver);
971d89
+                ECcurve, label, attr_string, pqc_ver);
971d89
     default:
971d89
         fprintf(stderr, "Error: cannot create a key of type %i (%s)\n", kt, kt2str(kt));
971d89
         return CKR_ARGUMENTS_BAD;
971d89
@@ -3030,13 +3125,13 @@ static CK_RV execute_cmd(CK_SESSION_HANDLE session, CK_SLOT_ID slot,
971d89
                          p11sak_cmd cmd, p11sak_kt kt, CK_ULONG keylength,
971d89
                          CK_ULONG exponent, char *ECcurve, char *label,
971d89
                          char *attr_string, int long_print, int full_uri,
971d89
-                         CK_BBOOL *forceAll, char *dilithium_ver)
971d89
+                         CK_BBOOL *forceAll, char *pqc_ver)
971d89
 {
971d89
     CK_RV rc;
971d89
     switch (cmd) {
971d89
     case gen_key:
971d89
         rc = generate_ckey(session, slot, kt, keylength, ECcurve, exponent,
971d89
-                label, attr_string, dilithium_ver);
971d89
+                label, attr_string, pqc_ver);
971d89
         break;
971d89
     case list_key:
971d89
         rc = list_ckey(session, slot, kt, long_print, label, full_uri);
971d89
@@ -3177,7 +3272,7 @@ int main(int argc, char *argv[])
971d89
     char *ECcurve = NULL;
971d89
     char *attr_string = NULL;
971d89
     CK_ULONG keylength = 0;
971d89
-    char *dilithium_ver = NULL;
971d89
+    char *pqc_ver = NULL;
971d89
     CK_RV rc = CKR_OK;
971d89
     CK_SESSION_HANDLE session;
971d89
     const char *pin = NULL;
971d89
@@ -3203,7 +3298,7 @@ int main(int argc, char *argv[])
971d89
     /* Parse command args */
971d89
     rc = parse_cmd_args(cmd, argv, argc, &kt, &keylength, &ECcurve, &slot, &pin,
971d89
             &exponent, &label, &attr_string, &long_print, &full_uri, &forceAll,
971d89
-            &dilithium_ver, &force_pin_prompt);
971d89
+            &pqc_ver, &force_pin_prompt);
971d89
     if (rc != CKR_OK) {
971d89
         goto done;
971d89
     }
971d89
@@ -3240,7 +3335,7 @@ int main(int argc, char *argv[])
971d89
 
971d89
     /* Execute command */
971d89
     rc = execute_cmd(session, slot, cmd, kt, keylength, exponent, ECcurve,
971d89
-            label, attr_string, long_print, full_uri, &forceAll, dilithium_ver);
971d89
+            label, attr_string, long_print, full_uri, &forceAll, pqc_ver);
971d89
     if (rc == CKR_CANCEL) {
971d89
         fprintf(stderr, "Cancel execution: p11sak %s command (error code 0x%lX: %s)\n", cmd2str(cmd), rc,
971d89
                 p11_get_ckr(rc));
971d89
diff --git a/usr/sbin/p11sak/p11sak.h b/usr/sbin/p11sak/p11sak.h
971d89
index 2b7e9c64..9d5a461a 100644
971d89
--- a/usr/sbin/p11sak/p11sak.h
971d89
+++ b/usr/sbin/p11sak/p11sak.h
971d89
@@ -25,6 +25,7 @@ typedef enum {
971d89
     kt_RSAPKCS,
971d89
     kt_EC,
971d89
     kt_IBM_DILITHIUM,
971d89
+    kt_IBM_KYBER,
971d89
     kt_GENERIC,
971d89
     kt_SECRET,
971d89
     kt_PUBLIC,
971d89
diff --git a/usr/sbin/p11sak/p11sak_defined_attrs.conf b/usr/sbin/p11sak/p11sak_defined_attrs.conf
971d89
index 520d28d5..53080ef5 100644
971d89
--- a/usr/sbin/p11sak/p11sak_defined_attrs.conf
971d89
+++ b/usr/sbin/p11sak/p11sak_defined_attrs.conf
971d89
@@ -33,10 +33,14 @@ attribute {
971d89
    id = 0x00000120
971d89
    type = CK_BYTE
971d89
 }
971d89
-
971d89
 attribute {
971d89
    name = CKA_IBM_DILITHIUM_KEYFORM
971d89
    id = 0x800d0001
971d89
    type = CK_ULONG
971d89
 }
971d89
+attribute {
971d89
+   name = CKA_IBM_KYBER_KEYFORM
971d89
+   id = 0x800d0009
971d89
+   type = CK_ULONG
971d89
+}
971d89
 
971d89
-- 
971d89
2.16.2.windows.1
971d89