diff mbox series

[v2] crypto/qat: add support for 8 byte 3DES

Message ID 20180704102024.28783-1-marko.kovacevic@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Pablo de Lara Guarch
Headers show
Series [v2] crypto/qat: add support for 8 byte 3DES | expand

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail apply issues

Commit Message

Kovacevic, Marko July 4, 2018, 10:20 a.m. UTC
Added extra case to support 8 byte key size
for 3DES CBC. Also changed capabilities to reflect
the change.

Signed-off-by: Marko Kovacevic <marko.kovacevic@intel.com>
---

V2: Fixed implementation (Fiona)
---
 drivers/crypto/qat/qat_adf/qat_algs.h            |  1 +
 drivers/crypto/qat/qat_adf/qat_algs_build_desc.c | 15 ++++++++++++---
 drivers/crypto/qat/qat_crypto_capabilities.h     |  2 +-
 test/test/test_cryptodev_des_test_vectors.h      |  6 ++++--
 4 files changed, 18 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/drivers/crypto/qat/qat_adf/qat_algs.h b/drivers/crypto/qat/qat_adf/qat_algs.h
index 88bd5f0..a3a3545 100644
--- a/drivers/crypto/qat/qat_adf/qat_algs.h
+++ b/drivers/crypto/qat/qat_adf/qat_algs.h
@@ -21,6 +21,7 @@ 
 /* 3DES key sizes */
 #define QAT_3DES_KEY_SZ_OPT1 24 /* Keys are independent */
 #define QAT_3DES_KEY_SZ_OPT2 16 /* K3=K1 */
+#define QAT_3DES_KEY_SZ_OPT3 8 /* K1=K2=K3 */
 
 #define QAT_AES_HW_CONFIG_CBC_ENC(alg) \
 	ICP_QAT_HW_CIPHER_CONFIG_BUILD(ICP_QAT_HW_CIPHER_CBC_MODE, alg, \
diff --git a/drivers/crypto/qat/qat_adf/qat_algs_build_desc.c b/drivers/crypto/qat/qat_adf/qat_algs_build_desc.c
index c87ed40..f8b3ec7 100644
--- a/drivers/crypto/qat/qat_adf/qat_algs_build_desc.c
+++ b/drivers/crypto/qat/qat_adf/qat_algs_build_desc.c
@@ -8,7 +8,6 @@ 
 #include <rte_log.h>
 #include <rte_malloc.h>
 #include <rte_crypto_sym.h>
-
 #include "../qat_logs.h"
 
 #include <openssl/sha.h>	/* Needed to calculate pre-compute values */
@@ -618,11 +617,20 @@  int qat_alg_aead_session_create_content_desc_cipher(struct qat_session *cdesc,
 	if (total_key_size > cipherkeylen) {
 		uint32_t padding_size =  total_key_size-cipherkeylen;
 		if ((cdesc->qat_cipher_alg == ICP_QAT_HW_CIPHER_ALGO_3DES)
-			&& (cipherkeylen == QAT_3DES_KEY_SZ_OPT2))
+			&& (cipherkeylen == QAT_3DES_KEY_SZ_OPT2)) {
 			/* K3 not provided so use K1 = K3*/
 			memcpy(cdesc->cd_cur_ptr, cipherkey, padding_size);
-		else
+
+		} else if ((cdesc->qat_cipher_alg == ICP_QAT_HW_CIPHER_ALGO_3DES)
+				&& (cipherkeylen == QAT_3DES_KEY_SZ_OPT3)) {
+			/* K2 and K3 not provided so use K1 = K2 = K3*/
+			memcpy(cdesc->cd_cur_ptr, cipherkey,
+				cipherkeylen);
+			memcpy(cdesc->cd_cur_ptr+cipherkeylen,
+				cipherkey, cipherkeylen);
+		} else
 			memset(cdesc->cd_cur_ptr, 0, padding_size);
+
 		cdesc->cd_cur_ptr += padding_size;
 	}
 	cd_size = cdesc->cd_cur_ptr-(uint8_t *)&cdesc->cd;
@@ -994,6 +1002,7 @@  int qat_alg_validate_3des_key(int key_len, enum icp_qat_hw_cipher_algo *alg)
 	switch (key_len) {
 	case QAT_3DES_KEY_SZ_OPT1:
 	case QAT_3DES_KEY_SZ_OPT2:
+	case QAT_3DES_KEY_SZ_OPT3:
 		*alg = ICP_QAT_HW_CIPHER_ALGO_3DES;
 		break;
 	default:
diff --git a/drivers/crypto/qat/qat_crypto_capabilities.h b/drivers/crypto/qat/qat_crypto_capabilities.h
index 001c32c..1d61109 100644
--- a/drivers/crypto/qat/qat_crypto_capabilities.h
+++ b/drivers/crypto/qat/qat_crypto_capabilities.h
@@ -434,7 +434,7 @@ 
 				.algo = RTE_CRYPTO_CIPHER_3DES_CBC,	\
 				.block_size = 8,			\
 				.key_size = {				\
-					.min = 16,			\
+					.min = 8,			\
 					.max = 24,			\
 					.increment = 8			\
 				},					\
diff --git a/test/test/test_cryptodev_des_test_vectors.h b/test/test/test_cryptodev_des_test_vectors.h
index 7479e70..1033456 100644
--- a/test/test/test_cryptodev_des_test_vectors.h
+++ b/test/test/test_cryptodev_des_test_vectors.h
@@ -1233,14 +1233,16 @@  static const struct blockcipher_test_case triple_des_cipheronly_test_cases[] = {
 		.test_data = &triple_des64cbc_test_vector,
 		.op_mask = BLOCKCIPHER_TEST_OP_ENCRYPT,
 		.pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_MB |
-			BLOCKCIPHER_TEST_TARGET_PMD_OPENSSL
+			BLOCKCIPHER_TEST_TARGET_PMD_OPENSSL |
+			BLOCKCIPHER_TEST_TARGET_PMD_QAT
 	},
 	{
 		.test_descr = "3DES-64-CBC Decryption",
 		.test_data = &triple_des64cbc_test_vector,
 		.op_mask = BLOCKCIPHER_TEST_OP_DECRYPT,
 		.pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_MB |
-			BLOCKCIPHER_TEST_TARGET_PMD_OPENSSL
+			BLOCKCIPHER_TEST_TARGET_PMD_OPENSSL |
+			BLOCKCIPHER_TEST_TARGET_PMD_QAT
 	},
 	{
 		.test_descr = "3DES-128-CBC Encryption",