[1/9] crypto/qat: check buffer size for oop auth-cipher
diff mbox series

Message ID 20190603145048.2596-2-damianx.nowak@intel.com
State Superseded, archived
Delegated to: akhil goyal
Headers show
Series
  • add QAT support for digest encrypted
Related show

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/intel-Performance-Testing success Performance Testing PASS
ci/Intel-compilation fail Compilation issues

Commit Message

Damian Nowak June 3, 2019, 2:50 p.m. UTC
From: Damian Nowak <damianx.nowak@intel.com>

This patch adds condition to be met when using
wireless algorithms (SNOW3G, KASUMI, ZUC) in
out-of-place auth-cipher operations. It verifies
if there is enough room for the digest in the
output buffer.

Conditions rewritten for better readibility and
possible SGL support.

Signed-off-by: Damian Nowak <damianx.nowak@intel.com>
---
 drivers/crypto/qat/qat_sym.c | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

Patch
diff mbox series

diff --git a/drivers/crypto/qat/qat_sym.c b/drivers/crypto/qat/qat_sym.c
index 8801ca5..4080c30 100644
--- a/drivers/crypto/qat/qat_sym.c
+++ b/drivers/crypto/qat/qat_sym.c
@@ -157,7 +157,7 @@  qat_sym_build_request(void *in_op, uint8_t *out_msg,
 	uint32_t min_ofs = 0;
 	uint64_t src_buf_start = 0, dst_buf_start = 0;
 	uint8_t do_sgl = 0;
-	uint8_t wireless_auth = 0, in_place = 1;
+	uint8_t wireless_auth = 0, in_place = 1, digest_in_buffer = 0;
 	struct rte_crypto_op *op = (struct rte_crypto_op *)in_op;
 	struct qat_sym_op_cookie *cookie =
 				(struct qat_sym_op_cookie *)op_cookie;
@@ -513,6 +513,7 @@  qat_sym_build_request(void *in_op, uint8_t *out_msg,
 				qat_req->comn_mid.src_data_addr =
 				cookie->qat_sgl_src_phys_addr;
 		else {
+			in_place = 0;
 			ret = qat_sgl_fill_array(op->sym->m_dst,
 				(int64_t)(dst_buf_start -
 					  rte_pktmbuf_iova(op->sym->m_dst)),
@@ -533,18 +534,21 @@  qat_sym_build_request(void *in_op, uint8_t *out_msg,
 	} else {
 		qat_req->comn_mid.src_data_addr = src_buf_start;
 		qat_req->comn_mid.dest_data_addr = dst_buf_start;
-		/* handle case of auth-gen-then-cipher with digest encrypted */
-		if (wireless_auth && in_place &&
-		    (op->sym->auth.digest.phys_addr ==
-				src_buf_start + auth_ofs + auth_len) &&
-		    (auth_ofs + auth_len + ctx->digest_length <=
-				cipher_ofs + cipher_len)) {
-			struct icp_qat_fw_comn_req_hdr *header =
-						&qat_req->comn_hdr;
-			ICP_QAT_FW_LA_DIGEST_IN_BUFFER_SET(
-				header->serv_specif_flags,
-				ICP_QAT_FW_LA_DIGEST_IN_BUFFER);
-		}
+	}
+
+	/* Handle case of auth-gen-then-cipher with digest encrypted */
+	if (wireless_auth &&
+			(auth_ofs + auth_len + ctx->digest_length <=
+				cipher_ofs + cipher_len) &&
+			(op->sym->auth.digest.phys_addr ==
+				(in_place ? src_buf_start : dst_buf_start) +
+				auth_ofs + auth_len))
+		digest_in_buffer = 1;
+	if (digest_in_buffer) {
+		struct icp_qat_fw_comn_req_hdr *header = &qat_req->comn_hdr;
+		ICP_QAT_FW_LA_DIGEST_IN_BUFFER_SET(
+			header->serv_specif_flags,
+			ICP_QAT_FW_LA_DIGEST_IN_BUFFER);
 	}
 
 #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG