From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 631F9A04A4; Tue, 1 Mar 2022 15:16:23 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 53934426DE; Tue, 1 Mar 2022 15:16:23 +0100 (CET) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mails.dpdk.org (Postfix) with ESMTP id BEEE540DF6 for ; Tue, 1 Mar 2022 15:16:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1646144180; x=1677680180; h=from:to:cc:subject:date:message-id; bh=zIH74D1FcfZipESV9TYqthYv/kUS3PCHPDuC8OMeO5g=; b=A8vtYRAhKiB+ee6F4fCAqoIJbfB+WoojLQWeMIufEhXQzO4mfhwu8njI hPYyz5Qz/Lz3iN+RIBV5MJh23MN3ptwa0WJYVvcd+/un9WAG4NP8efSvb otAuKSsdR/Jli9suEWypT9B33PTQrkUfOkgXdCbaUP+2SzAzanj2KHj2S f87nLjk8agvT+n4gB2fN1IRvhItoNkeXygy1t7uBoa6v7vAvKvh1IguEW 9J/3dPMnZj/yYa/a0hcTE61TODsVszXuCzmoYy1+Er8/e8NXVW1O+s7eu GbQNgJOj/3WE1utgj4SRAHF8B1IiiOqngLxWvLBz2D45qdqhbntpoF/Ah g==; X-IronPort-AV: E=McAfee;i="6200,9189,10272"; a="251968812" X-IronPort-AV: E=Sophos;i="5.90,146,1643702400"; d="scan'208";a="251968812" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2022 06:16:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,146,1643702400"; d="scan'208";a="545110831" Received: from silpixa00400308.ir.intel.com ([10.237.214.95]) by fmsmga007.fm.intel.com with ESMTP; 01 Mar 2022 06:16:18 -0800 From: Arek Kusztal To: dev@dpdk.org Cc: gakhil@marvell.com, roy.fan.zhang@intel.com, Arek Kusztal Subject: [PATCH] crypto/qat: fix smaller modulus cases for mod exp Date: Tue, 1 Mar 2022 14:16:16 +0000 Message-Id: <20220301141616.31821-1-arkadiuszx.kusztal@intel.com> X-Mailer: git-send-email 2.17.1 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This patches fixes not working cases when modulus is smaller than other arguments. Fixes: 109755f0a427 ("crypto/qat: refactor asymmetric crypto functions") Signed-off-by: Arek Kusztal --- drivers/common/qat/qat_adf/qat_pke.h | 24 +++++++++++++++--------- drivers/crypto/qat/qat_asym.c | 12 ++++++++++-- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/drivers/common/qat/qat_adf/qat_pke.h b/drivers/common/qat/qat_adf/qat_pke.h index 092fc373de..b5fb2a020c 100644 --- a/drivers/common/qat/qat_adf/qat_pke.h +++ b/drivers/common/qat/qat_adf/qat_pke.h @@ -17,32 +17,32 @@ struct qat_asym_function { }; static struct qat_asym_function -get_modexp_function(struct rte_crypto_asym_xform *xform) +get_modexp_function2(uint32_t bytesize) { struct qat_asym_function qat_function = { }; - if (xform->modex.modulus.length <= 64) { + if (bytesize <= 64) { qat_function.func_id = MATHS_MODEXP_L512; qat_function.bytesize = 64; - } else if (xform->modex.modulus.length <= 128) { + } else if (bytesize <= 128) { qat_function.func_id = MATHS_MODEXP_L1024; qat_function.bytesize = 128; - } else if (xform->modex.modulus.length <= 192) { + } else if (bytesize <= 192) { qat_function.func_id = MATHS_MODEXP_L1536; qat_function.bytesize = 192; - } else if (xform->modex.modulus.length <= 256) { + } else if (bytesize <= 256) { qat_function.func_id = MATHS_MODEXP_L2048; qat_function.bytesize = 256; - } else if (xform->modex.modulus.length <= 320) { + } else if (bytesize <= 320) { qat_function.func_id = MATHS_MODEXP_L2560; qat_function.bytesize = 320; - } else if (xform->modex.modulus.length <= 384) { + } else if (bytesize <= 384) { qat_function.func_id = MATHS_MODEXP_L3072; qat_function.bytesize = 384; - } else if (xform->modex.modulus.length <= 448) { + } else if (bytesize <= 448) { qat_function.func_id = MATHS_MODEXP_L3584; qat_function.bytesize = 448; - } else if (xform->modex.modulus.length <= 512) { + } else if (bytesize <= 512) { qat_function.func_id = MATHS_MODEXP_L4096; qat_function.bytesize = 512; } @@ -50,6 +50,12 @@ get_modexp_function(struct rte_crypto_asym_xform *xform) } static struct qat_asym_function +get_modexp_function(struct rte_crypto_asym_xform *xform) +{ + return get_modexp_function2(xform->modex.modulus.length); +} + +static struct qat_asym_function get_modinv_function(struct rte_crypto_asym_xform *xform) { struct qat_asym_function qat_function = { }; diff --git a/drivers/crypto/qat/qat_asym.c b/drivers/crypto/qat/qat_asym.c index badf018f13..25694e52b5 100644 --- a/drivers/crypto/qat/qat_asym.c +++ b/drivers/crypto/qat/qat_asym.c @@ -205,7 +205,7 @@ modexp_set_input(struct rte_crypto_asym_op *asym_op, struct rte_crypto_asym_xform *xform) { struct qat_asym_function qat_function; - uint32_t alg_bytesize, func_id; + uint32_t alg_bytesize, func_id, in_bytesize; int status = 0; CHECK_IF_NOT_EMPTY(xform->modex.modulus, "mod exp", @@ -215,7 +215,15 @@ modexp_set_input(struct rte_crypto_asym_op *asym_op, if (status) return status; - qat_function = get_asym_function(xform); + if (asym_op->modex.base.length > xform->modex.exponent.length && + asym_op->modex.base.length > xform->modex.modulus.length) { + in_bytesize = asym_op->modex.base.length; + } else if (xform->modex.exponent.length > xform->modex.modulus.length) + in_bytesize = xform->modex.exponent.length; + else + in_bytesize = xform->modex.modulus.length; + + qat_function = get_modexp_function2(in_bytesize); func_id = qat_function.func_id; if (qat_function.func_id == 0) { QAT_LOG(ERR, "Cannot obtain functionality id"); -- 2.13.6