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 1D722A0548; Wed, 1 Jun 2022 12:11:22 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0EA9142B78; Wed, 1 Jun 2022 12:10:55 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mails.dpdk.org (Postfix) with ESMTP id EEE5D42B71 for ; Wed, 1 Jun 2022 12:10:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1654078252; x=1685614252; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=VjVFbWxn+Bh/YHCXneYTs1y2sin6BXomKSzYuNqbBp8=; b=dkYJpl8CFGRdwzVcs6ygpTj1kvyXZC0SD/lEaKPlwinaNZmsPRYU3GfB AtEZ6xkmXoRUdkRHB3/rIgtgnsw4H6r4QjZ9dGB3GM1bZvFKF4g4kRphI vsIyLNecnliuarOPYbHs3vvvxqGQXJzi3fMOJxV501W+n4Zp5N0BxYO5L y1tz7z5jVl7IkYB/ffPZqZegkdIa+QjLZtUIlozAAA9Nup20pYSRwPIfS cUmDp0Xi7f3r5F+HkJ2367nNp5rPJIqypwzEi6tBUyANh7Kq+XNth1BZQ dj863TXkY/FTfIcUneQPlEeTIL9t6KhL5sn0bcf9YHeVUt3rVdFAl45rp A==; X-IronPort-AV: E=McAfee;i="6400,9594,10364"; a="275616418" X-IronPort-AV: E=Sophos;i="5.91,266,1647327600"; d="scan'208";a="275616418" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jun 2022 03:10:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,266,1647327600"; d="scan'208";a="606185920" Received: from silpixa00399302.ir.intel.com ([10.237.214.136]) by orsmga008.jf.intel.com with ESMTP; 01 Jun 2022 03:10:36 -0700 From: Arek Kusztal To: dev@dpdk.org Cc: gakhil@marvell.com, roy.fan.zhang@intel.com, Arek Kusztal Subject: [PATCH v5 05/12] cryptodev: move dh type from xform to dh op Date: Wed, 1 Jun 2022 10:02:42 +0100 Message-Id: <20220601090249.86865-6-arkadiuszx.kusztal@intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20220601090249.86865-1-arkadiuszx.kusztal@intel.com> References: <20220601090249.86865-1-arkadiuszx.kusztal@intel.com> 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 - Moved dh operation type to dh operation struct. Operation type (PUBLIC_KEY_GENERATION, SHARED_SECRET) should be free to choose for any operation. One xform/session should be enough to perform both DH operations, if op_type would be xform member, session would have to be to be created twice for the same group. Similar problem would be observed in sessionless case. Additionally, it will help extend DH to support Elliptic Curves. - Changed order of Diffie-Hellman operation phases. Now it corresponds with the order of operations. Signed-off-by: Arek Kusztal --- app/test/test_cryptodev_asym.c | 11 +++++----- drivers/crypto/openssl/rte_openssl_pmd.c | 15 ++++++-------- drivers/crypto/openssl/rte_openssl_pmd_ops.c | 27 ------------------------- lib/cryptodev/rte_crypto_asym.h | 30 +++++++++++++--------------- 4 files changed, 25 insertions(+), 58 deletions(-) diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c index 491ba2c1b9..9d044c65b2 100644 --- a/app/test/test_cryptodev_asym.c +++ b/app/test/test_cryptodev_asym.c @@ -1067,8 +1067,8 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm) asym_op = op->asym; /* Setup a xform and op to generate private key only */ - xform.dh.ke_type = RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE; xform.next = NULL; + asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE; asym_op->dh.priv_key.data = dh_test_params.priv_key.data; asym_op->dh.priv_key.length = dh_test_params.priv_key.length; asym_op->dh.pub_key.data = (uint8_t *)peer; @@ -1149,8 +1149,8 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm) asym_op = op->asym; /* Setup a xform and op to generate private key only */ - xform.dh.ke_type = RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE; xform.next = NULL; + asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE; asym_op->dh.priv_key.data = output; asym_op->dh.priv_key.length = sizeof(output); @@ -1232,9 +1232,9 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm) * using test private key * */ - xform.dh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE; xform.next = NULL; + asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE; asym_op->dh.pub_key.data = output; asym_op->dh.pub_key.length = sizeof(output); /* load pre-defined private key */ @@ -1323,15 +1323,14 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm) * private key first followed by * public key */ - xform.dh.ke_type = RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE; pub_key_xform.xform_type = RTE_CRYPTO_ASYM_XFORM_DH; - pub_key_xform.dh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE; xform.next = &pub_key_xform; + asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE; asym_op->dh.pub_key.data = out_pub_key; asym_op->dh.pub_key.length = sizeof(out_pub_key); asym_op->dh.priv_key.data = out_prv_key; - asym_op->dh.priv_key.length = sizeof(out_prv_key); + asym_op->dh.priv_key.length = 0; ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess); if (ret < 0) { diff --git a/drivers/crypto/openssl/rte_openssl_pmd.c b/drivers/crypto/openssl/rte_openssl_pmd.c index 1a2bb0c34e..8270b01517 100644 --- a/drivers/crypto/openssl/rte_openssl_pmd.c +++ b/drivers/crypto/openssl/rte_openssl_pmd.c @@ -1694,12 +1694,12 @@ process_openssl_dh_op(struct rte_crypto_op *cop, struct openssl_asym_session *sess) { struct rte_crypto_dh_op_param *op = &cop->asym->dh; + struct rte_crypto_asym_op *asym_op = cop->asym; DH *dh_key = sess->u.dh.dh_key; BIGNUM *priv_key = NULL; int ret = 0; - if (sess->u.dh.key_op & - (1 << RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE)) { + if (asym_op->dh.ke_type == RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE) { /* compute shared secret using peer public key * and current private key * shared secret = peer_key ^ priv_key mod p @@ -1755,10 +1755,8 @@ process_openssl_dh_op(struct rte_crypto_op *cop, * if user provides private key, * then first set DH with user provided private key */ - if ((sess->u.dh.key_op & - (1 << RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE)) && - !(sess->u.dh.key_op & - (1 << RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE))) { + if (asym_op->dh.ke_type == RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE && + op->priv_key.length) { /* generate public key using user-provided private key * pub_key = g ^ priv_key mod p */ @@ -1792,7 +1790,7 @@ process_openssl_dh_op(struct rte_crypto_op *cop, return 0; } - if (sess->u.dh.key_op & (1 << RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE)) { + if (asym_op->dh.ke_type == RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE) { const BIGNUM *pub_key = NULL; OPENSSL_LOG(DEBUG, "%s:%d update public key\n", @@ -1806,8 +1804,7 @@ process_openssl_dh_op(struct rte_crypto_op *cop, op->pub_key.data); } - if (sess->u.dh.key_op & - (1 << RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE)) { + if (asym_op->dh.ke_type == RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE) { const BIGNUM *priv_key = NULL; OPENSSL_LOG(DEBUG, "%s:%d updated priv key\n", diff --git a/drivers/crypto/openssl/rte_openssl_pmd_ops.c b/drivers/crypto/openssl/rte_openssl_pmd_ops.c index 182111424d..7d0da52a33 100644 --- a/drivers/crypto/openssl/rte_openssl_pmd_ops.c +++ b/drivers/crypto/openssl/rte_openssl_pmd_ops.c @@ -1001,33 +1001,6 @@ static int openssl_set_asym_session_parameters( DH_free(dh); goto err_dh; } - - /* - * setup xfrom for - * public key generate, or - * DH Priv key generate, or both - * public and private key generate - */ - asym_session->u.dh.key_op = (1 << xform->dh.ke_type); - - if (xform->dh.ke_type == - RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE) { - /* check if next is pubkey */ - if ((xform->next != NULL) && - (xform->next->xform_type == - RTE_CRYPTO_ASYM_XFORM_DH) && - (xform->next->dh.ke_type == - RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE) - ) { - /* - * setup op as pub/priv key - * pair generationi - */ - asym_session->u.dh.key_op |= - (1 << - RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE); - } - } asym_session->u.dh.dh_key = dh; asym_session->xfrm_type = RTE_CRYPTO_ASYM_XFORM_DH; break; diff --git a/lib/cryptodev/rte_crypto_asym.h b/lib/cryptodev/rte_crypto_asym.h index 619c0614bf..88bc34dc8c 100644 --- a/lib/cryptodev/rte_crypto_asym.h +++ b/lib/cryptodev/rte_crypto_asym.h @@ -270,8 +270,6 @@ struct rte_crypto_modinv_xform { * */ struct rte_crypto_dh_xform { - enum rte_crypto_asym_ke_type ke_type; - /**< Setup xform for key generate or shared secret compute */ rte_crypto_uint p; /**< Prime modulus data */ rte_crypto_uint g; @@ -399,33 +397,33 @@ struct rte_crypto_rsa_op_param { * @note: */ struct rte_crypto_dh_op_param { - rte_crypto_uint pub_key; - /**< - * Output - generated public key, when dh xform ke_type is - * RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE. - * - * Input - peer's public key, when dh xform ke_type is - * RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE. - */ - + enum rte_crypto_asym_ke_type ke_type; + /**< Key exchange operation type */ rte_crypto_uint priv_key; /**< - * Output - generated private key, when dh xform ke_type is + * Output - generated private key when ke_type is * RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE. * - * Input - private key, when dh xform ke_type is one of: + * Input - private key when ke_type is one of: * RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE, * RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE. * - * In case priv_key.length is 0 and xform type is set with + * In case priv_key.length is 0 and ke_type is set with * RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE, CSRNG capable * device will generate a private key and use it for public * key generation. */ - + rte_crypto_uint pub_key; + /**< + * Output - generated public key when ke_type is + * RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE. + * + * Input - peer's public key when ke_type is + * RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE. + */ rte_crypto_uint shared_secret; /**< - * Output - calculated shared secret when dh xform ke_type is + * Output - calculated shared secret when ke_type is * RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE. */ }; -- 2.13.6