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

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