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

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