From 0c6310399911e4edde103074703f41dc59dcc659 Mon Sep 17 00:00:00 2001
From: Joerg Schmidbauer <jschmidb@de.ibm.com>
Date: Mon, 17 Jun 2019 13:39:03 +0200
Subject: [PATCH 006/184] Introduce symbolic constants for ICA properties.

Introduce and use symbolic constants for already existing AES
and RSA properties. Add and use new constants for EC-related
properties.

Signed-off-by: Joerg Schmidbauer <jschmidb@de.ibm.com>
---
 include/ica_api.h | 18 ++++++++++++++++++
 src/s390_crypto.c | 21 +++++++++++----------
 2 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/include/ica_api.h b/include/ica_api.h
index 3413acc..3c4067b 100644
--- a/include/ica_api.h
+++ b/include/ica_api.h
@@ -68,10 +68,28 @@ typedef ica_adapter_handle_t ICA_ADAPTER_HANDLE;
 #define ICA_CBCCS_VARIANT2	2
 #define ICA_CBCCS_VARIANT3	3
 
+/**
+ * ICA flags
+ */
 #define ICA_FLAG_SHW 4 /* static hardware support (symmetric ops - CPACF) */
 #define ICA_FLAG_DHW 2 /* dynamic hardware support (asymmetric ops - CEX) */
 #define ICA_FLAG_SW  1 /* software implementation (fallback / backup) */
 
+/**
+ * ICA properties: key lengths
+ */
+#define ICA_PROPERTY_AES_128		0x00000001
+#define ICA_PROPERTY_AES_192		0x00000002
+#define ICA_PROPERTY_AES_256		0x00000004
+
+#define ICA_PROPERTY_RSA_ALL		0x0000000F /* All RSA key lengths */
+#define ICA_PROPERTY_EC_BP			0x00000001 /* Brainpool curves */
+#define ICA_PROPERTY_EC_NIST		0x00000002 /* NIST curves */
+#define ICA_PROPERTY_EC_ED			0x00000004 /* Edwards curves */
+
+/**
+ * Algorithms
+ */
 #define SHA1            1
 #define SHA224          2
 #define SHA256          3
diff --git a/src/s390_crypto.c b/src/s390_crypto.c
index 13e60f8..bab7d1e 100644
--- a/src/s390_crypto.c
+++ b/src/s390_crypto.c
@@ -530,27 +530,27 @@ int s390_initialize_functionlist()
 			e->flags |= *s390_kmc_functions[e->id].enabled ? ICA_FLAG_SHW : 0;
 			if (e->id == AES_128_ENCRYPT) { // check for the maximum size
 				if (*s390_kmc_functions[icaList[AES_256_ENCRYPT].id].enabled)
-					e->property |= 4; // 256 bit
+					e->property |= ICA_PROPERTY_AES_256;
 				if (*s390_kmc_functions[icaList[AES_192_ENCRYPT].id].enabled)
-					e->property |= 2; // 192 bit
+					e->property |= ICA_PROPERTY_AES_192;
 				if (*s390_kmc_functions[icaList[AES_128_ENCRYPT].id].enabled)
-					e->property |= 1; // 128 bit
+					e->property |= ICA_PROPERTY_AES_128;
 			}
 			break;
 		case MSA4:
 			e->flags |= *s390_msa4_functions[e->id].enabled ? ICA_FLAG_SHW : 0;
 			if (e->id == AES_128_ENCRYPT) { // check for the maximum size
 				if (*s390_msa4_functions[icaList[AES_256_ENCRYPT].id].enabled)
-					e->property |= 4; // 256 bit
+					e->property |= ICA_PROPERTY_AES_256;
 				if (*s390_msa4_functions[icaList[AES_192_ENCRYPT].id].enabled)
-					e->property |= 2; // 192 bit
+					e->property |= ICA_PROPERTY_AES_192;
 				if (*s390_msa4_functions[icaList[AES_128_ENCRYPT].id].enabled)
-					e->property |= 1; // 128 bit
+					e->property |= ICA_PROPERTY_AES_128;
 			} else if (e->id == AES_128_XTS_ENCRYPT) { // check for the maximum size
 				if (*s390_msa4_functions[icaList[AES_256_XTS_ENCRYPT].id].enabled)
-					e->property |= 2; // 256 bit
+					e->property |= ICA_PROPERTY_AES_256;
 				if (*s390_msa4_functions[icaList[AES_128_XTS_ENCRYPT].id].enabled)
-					e->property |= 1; // 128 bit
+					e->property |= ICA_PROPERTY_AES_128;
 			}
 			break;
 		case PPNO:
@@ -565,6 +565,7 @@ int s390_initialize_functionlist()
 				e->flags |= *s390_pcc_functions[e->id].enabled ? ICA_FLAG_SHW : 0;
 			else
 				e->flags |= *s390_kdsa_functions[e->id].enabled ? ICA_FLAG_SHW : 0;
+			e->property |= ICA_PROPERTY_EC_ED;
 			break;
 		default:
 			/* Do nothing. */
@@ -578,7 +579,7 @@ int s390_initialize_functionlist()
 		case EC_KGEN:
 			if (ecc_via_online_card) {
 				e->flags |= ICA_FLAG_DHW;
-				e->property = 0x0F;
+				e->property |= ICA_PROPERTY_EC_BP | ICA_PROPERTY_EC_NIST;
 			}
 			e->flags |= *s390_kdsa_functions[e->id].enabled ? ICA_FLAG_SHW : 0;
 			break;
@@ -586,7 +587,7 @@ int s390_initialize_functionlist()
 		case RSA_CRT:
 			if (any_card_online) {
 				e->flags |= ICA_FLAG_DHW;
-				e->property = 0x0F;
+				e->property |= ICA_PROPERTY_RSA_ALL;
 			}
 			break;
 		default:
-- 
2.35.3

