All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fiona Trahe <fiona.trahe@intel.com (fiona.trahe@intel.com)>
To: dev@dpdk.org
Cc: pablo.de.lara.guarch@intel.com, john.griffin@intel.com,
	deepak.k.jain@intel.com, arkadiuszx.kusztal@intel.com,
	fiona.trahe@intel.com
Subject: [PATCH v2 2/2] crypto/qat: adding support for 3DES cipher algorithm
Date: Fri, 26 Aug 2016 16:49:00 +0100	[thread overview]
Message-ID: <1472226540-15361-3-git-send-email-fiona.trahe@intel.com> (raw)
In-Reply-To: <1472226540-15361-1-git-send-email-fiona.trahe@intel.com>

From: Fiona Trahe <fiona.trahe@intel.com>

3DES support added to QuickAssist PMD
With CTR and CBC mode.
Both cipher-only and chained with HMAC_SHAx

This patch depends on following patch :
  crypto/qat: enable support of Kasumi F8 in QAT cryptodev
  http://dpdk.org/dev/patchwork/patch/15320/

Signed-off-by: Fiona Trahe <fiona.trahe@intel.com>
---
 doc/guides/cryptodevs/qat.rst                    |  4 +++-
 drivers/crypto/qat/qat_adf/qat_algs.h            |  5 +++++
 drivers/crypto/qat/qat_adf/qat_algs_build_desc.c | 25 ++++++++++++++++++++++--
 drivers/crypto/qat/qat_crypto.c                  | 17 +++++++++++++++-
 4 files changed, 47 insertions(+), 4 deletions(-)

diff --git a/doc/guides/cryptodevs/qat.rst b/doc/guides/cryptodevs/qat.rst
index 56f0fc4..f6d2d65 100644
--- a/doc/guides/cryptodevs/qat.rst
+++ b/doc/guides/cryptodevs/qat.rst
@@ -42,6 +42,8 @@ The QAT PMD has support for:
 
 Cipher algorithms:
 
+* ``RTE_CRYPTO_CIPHER_3DES_CBC``
+* ``RTE_CRYPTO_CIPHER_3DES_CTR``
 * ``RTE_CRYPTO_SYM_CIPHER_AES128_CBC``
 * ``RTE_CRYPTO_SYM_CIPHER_AES192_CBC``
 * ``RTE_CRYPTO_SYM_CIPHER_AES256_CBC``
@@ -72,7 +74,7 @@ Limitations
 
 * Chained mbufs are not supported.
 * Hash only is not supported except Snow3G UIA2 and KASUMI F9.
-* Cipher only is not supported except Snow3G UEA2 and KASUMI F8.
+* Cipher only is not supported except Snow3G UEA2, KASUMI F8 and 3DES.
 * Only supports the session-oriented API implementation (session-less APIs are not supported).
 * Not performance tuned.
 * Snow3g(UEA2) and KAUSMI(F8) supported only if cipher length, cipher offset fields are byte-aligned.
diff --git a/drivers/crypto/qat/qat_adf/qat_algs.h b/drivers/crypto/qat/qat_adf/qat_algs.h
index 429f44f..530b9cc 100644
--- a/drivers/crypto/qat/qat_adf/qat_algs.h
+++ b/drivers/crypto/qat/qat_adf/qat_algs.h
@@ -59,6 +59,10 @@
 
 #define KASUMI_F8_KEY_MODIFIER_4_BYTES   0x55555555
 
+/* 3DES key sizes */
+#define QAT_3DES_KEY_SZ_OPT1 24 /* Keys are independent */
+#define QAT_3DES_KEY_SZ_OPT2 16 /* K3=K1 */
+
 #define QAT_AES_HW_CONFIG_CBC_ENC(alg) \
 	ICP_QAT_HW_CIPHER_CONFIG_BUILD(ICP_QAT_HW_CIPHER_CBC_MODE, alg, \
 					ICP_QAT_HW_CIPHER_NO_CONVERT, \
@@ -138,4 +142,5 @@ void qat_alg_ablkcipher_init_dec(struct qat_alg_ablkcipher_cd *cd,
 int qat_alg_validate_aes_key(int key_len, enum icp_qat_hw_cipher_algo *alg);
 int qat_alg_validate_snow3g_key(int key_len, enum icp_qat_hw_cipher_algo *alg);
 int qat_alg_validate_kasumi_key(int key_len, enum icp_qat_hw_cipher_algo *alg);
+int qat_alg_validate_3des_key(int key_len, enum icp_qat_hw_cipher_algo *alg);
 #endif
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 e131f8b..a0161cf 100644
--- a/drivers/crypto/qat/qat_adf/qat_algs_build_desc.c
+++ b/drivers/crypto/qat/qat_adf/qat_algs_build_desc.c
@@ -513,6 +513,10 @@ int qat_alg_aead_session_create_content_desc_cipher(struct qat_session *cdesc,
 		cipher_cd_ctrl->cipher_state_sz = ICP_QAT_HW_KASUMI_BLK_SZ >> 3;
 		cipher_cd_ctrl->cipher_padding_sz =
 					(2 * ICP_QAT_HW_KASUMI_BLK_SZ) >> 3;
+	} else if (cdesc->qat_cipher_alg == ICP_QAT_HW_CIPHER_ALGO_3DES) {
+		total_key_size = ICP_QAT_HW_3DES_KEY_SZ;
+		cipher_cd_ctrl->cipher_state_sz = ICP_QAT_HW_3DES_BLK_SZ >> 3;
+		proto = ICP_QAT_FW_LA_PROTO_GET(header->serv_specif_flags);
 	} else {
 		total_key_size = cipherkeylen;
 		cipher_cd_ctrl->cipher_state_sz = ICP_QAT_HW_AES_BLK_SZ >> 3;
@@ -554,8 +558,12 @@ 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;
-
-		memset(cdesc->cd_cur_ptr, 0, padding_size);
+		if ((cdesc->qat_cipher_alg == ICP_QAT_HW_CIPHER_ALGO_3DES)
+			&& (cipherkeylen == QAT_3DES_KEY_SZ_OPT2))
+			/* K3 not provided so use K1 = K3*/
+			memcpy(cdesc->cd_cur_ptr, cipherkey, padding_size);
+		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;
@@ -846,3 +854,16 @@ int qat_alg_validate_kasumi_key(int key_len, enum icp_qat_hw_cipher_algo *alg)
 	}
 	return 0;
 }
+
+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:
+		*alg = ICP_QAT_HW_CIPHER_ALGO_3DES;
+		break;
+	default:
+		return -EINVAL;
+	}
+	return 0;
+}
diff --git a/drivers/crypto/qat/qat_crypto.c b/drivers/crypto/qat/qat_crypto.c
index 620e82e..f5e59dc 100644
--- a/drivers/crypto/qat/qat_crypto.c
+++ b/drivers/crypto/qat/qat_crypto.c
@@ -507,8 +507,23 @@ qat_crypto_sym_configure_session_cipher(struct rte_cryptodev *dev,
 		}
 		session->qat_mode = ICP_QAT_HW_CIPHER_F8_MODE;
 		break;
-	case RTE_CRYPTO_CIPHER_3DES_ECB:
 	case RTE_CRYPTO_CIPHER_3DES_CBC:
+		if (qat_alg_validate_3des_key(cipher_xform->key.length,
+				&session->qat_cipher_alg) != 0) {
+			PMD_DRV_LOG(ERR, "Invalid 3DES cipher key size");
+			goto error_out;
+		}
+		session->qat_mode = ICP_QAT_HW_CIPHER_CBC_MODE;
+		break;
+	case RTE_CRYPTO_CIPHER_3DES_CTR:
+		if (qat_alg_validate_3des_key(cipher_xform->key.length,
+				&session->qat_cipher_alg) != 0) {
+			PMD_DRV_LOG(ERR, "Invalid 3DES cipher key size");
+			goto error_out;
+		}
+		session->qat_mode = ICP_QAT_HW_CIPHER_CTR_MODE;
+		break;
+	case RTE_CRYPTO_CIPHER_3DES_ECB:
 	case RTE_CRYPTO_CIPHER_AES_ECB:
 	case RTE_CRYPTO_CIPHER_AES_CCM:
 	case RTE_CRYPTO_CIPHER_AES_F8:
-- 
2.5.0

  parent reply	other threads:[~2016-08-26 15:49 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-25 17:46 [PATCH 0/2] Add 3DES support to Quickassist PMD Fiona Trahe
2016-08-25 17:46 ` [PATCH 1/2] crypto/qat: code cleanup Fiona Trahe
2016-08-26 15:48   ` [PATCH v2 0/2] Add 3DES support to Quickassist PMD Fiona Trahe
2016-08-26 15:48     ` [PATCH v2 1/2] crypto/qat: code cleanup Fiona Trahe
2016-09-15 18:01       ` [PATCH v3 0/2] Add 3DES support to Quickassist PMD Fiona Trahe
2016-09-15 18:01       ` [PATCH v3 1/2] crypto/qat: code cleanup Fiona Trahe
2016-09-15 18:01       ` [PATCH v3 2/2] crypto/qat: adding support for 3DES cipher algorithm Fiona Trahe
2016-09-16 14:19       ` [PATCH v3 0/2] Add 3DES support to Quickassist PMD Fiona Trahe
2016-09-16 14:19       ` [PATCH v3 1/2] crypto/qat: code cleanup Fiona Trahe
2016-09-21  9:54         ` Jain, Deepak K
2016-09-21 21:10           ` De Lara Guarch, Pablo
2016-09-16 14:19       ` [PATCH v3 2/2] crypto/qat: adding support for 3DES cipher algorithm Fiona Trahe
2016-09-21 10:00         ` Jain, Deepak K
2016-09-21 21:10           ` De Lara Guarch, Pablo
2016-08-26 15:49     ` Fiona Trahe [this message]
2016-09-07 18:26     ` [PATCH v2 0/2] Add 3DES support to Quickassist PMD De Lara Guarch, Pablo
2016-08-25 17:47 ` [PATCH 2/2] crypto/qat: adding support for 3DES cipher algorithm Fiona Trahe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1472226540-15361-3-git-send-email-fiona.trahe@intel.com \
    --to=fiona.trahe@intel.com \
    --cc=arkadiuszx.kusztal@intel.com \
    --cc=deepak.k.jain@intel.com \
    --cc=dev@dpdk.org \
    --cc=john.griffin@intel.com \
    --cc=pablo.de.lara.guarch@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.