DPDK patches and discussions
 help / color / mirror / Atom feed
From: Arek Kusztal <arkadiuszx.kusztal@intel.com>
To: dev@dpdk.org
Cc: akhil.goyal@nxp.com, fiona.trahe@intel.com,
	shally.verma@caviumnetworks.com,
	Arek Kusztal <arkadiuszx.kusztal@intel.com>
Subject: [dpdk-dev] [PATCH v2 2/3] crypto/openssl: rework openssl rsa implementation
Date: Wed,  3 Jul 2019 17:37:58 +0200	[thread overview]
Message-ID: <20190703153759.1508-3-arkadiuszx.kusztal@intel.com> (raw)
In-Reply-To: <20190703153759.1508-1-arkadiuszx.kusztal@intel.com>

This commit reworks implementation of RSA algorithm
in OPENSSL PMD to be conformant to API changes.

Signed-off-by: Arek Kusztal <arkadiuszx.kusztal@intel.com>
---
 drivers/crypto/openssl/rte_openssl_pmd.c | 67 ++++++++++++++++++--------------
 1 file changed, 38 insertions(+), 29 deletions(-)

diff --git a/drivers/crypto/openssl/rte_openssl_pmd.c b/drivers/crypto/openssl/rte_openssl_pmd.c
index 7c8bf0d..642580b 100644
--- a/drivers/crypto/openssl/rte_openssl_pmd.c
+++ b/drivers/crypto/openssl/rte_openssl_pmd.c
@@ -1842,15 +1842,13 @@ process_openssl_rsa_op(struct rte_crypto_op *cop,
 	int ret = 0;
 	struct rte_crypto_asym_op *op = cop->asym;
 	RSA *rsa = sess->u.r.rsa;
-	uint32_t pad = (op->rsa.pad);
+	uint32_t pad = (op->rsa.padding);
 	uint8_t *tmp;
 
 	cop->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
 
 	switch (pad) {
-	case RTE_CRYPTO_RSA_PKCS1_V1_5_BT0:
-	case RTE_CRYPTO_RSA_PKCS1_V1_5_BT1:
-	case RTE_CRYPTO_RSA_PKCS1_V1_5_BT2:
+	case RTE_CRYPTO_RSA_PADDING_PKCS1:
 		pad = RSA_PKCS1_PADDING;
 		break;
 	case RTE_CRYPTO_RSA_PADDING_NONE:
@@ -1867,19 +1865,19 @@ process_openssl_rsa_op(struct rte_crypto_op *cop,
 	case RTE_CRYPTO_ASYM_OP_ENCRYPT:
 		ret = RSA_public_encrypt(op->rsa.message.length,
 				op->rsa.message.data,
-				op->rsa.message.data,
+				op->rsa.cipher.data,
 				rsa,
 				pad);
 
 		if (ret > 0)
-			op->rsa.message.length = ret;
+			op->rsa.cipher.length = ret;
 		OPENSSL_LOG(DEBUG,
 				"length of encrypted text %d\n", ret);
 		break;
 
 	case RTE_CRYPTO_ASYM_OP_DECRYPT:
-		ret = RSA_private_decrypt(op->rsa.message.length,
-				op->rsa.message.data,
+		ret = RSA_private_decrypt(op->rsa.cipher.length,
+				op->rsa.cipher.data,
 				op->rsa.message.data,
 				rsa,
 				pad);
@@ -1898,28 +1896,39 @@ process_openssl_rsa_op(struct rte_crypto_op *cop,
 		break;
 
 	case RTE_CRYPTO_ASYM_OP_VERIFY:
-		tmp = rte_malloc(NULL, op->rsa.sign.length, 0);
-		if (tmp == NULL) {
-			OPENSSL_LOG(ERR, "Memory allocation failed");
-			cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
-			break;
-		}
-		ret = RSA_public_decrypt(op->rsa.sign.length,
-				op->rsa.sign.data,
-				tmp,
-				rsa,
-				pad);
-
-		OPENSSL_LOG(DEBUG,
-				"Length of public_decrypt %d "
-				"length of message %zd\n",
-				ret, op->rsa.message.length);
-		if ((ret <= 0) || (CRYPTO_memcmp(tmp, op->rsa.message.data,
-				op->rsa.message.length))) {
-			OPENSSL_LOG(ERR, "RSA sign Verification failed");
-			cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
+		if (pad == RSA_NO_PADDING) {
+			ret = RSA_public_decrypt(op->rsa.sign.length,
+					op->rsa.sign.data,
+					op->rsa.message_to_verify.data,
+					rsa,
+					pad);
+
+			if (ret > 0)
+				op->rsa.message_to_verify.length = ret;
+		} else {
+			tmp = rte_malloc(NULL, op->rsa.sign.length, 0);
+			if (tmp == NULL) {
+				OPENSSL_LOG(ERR, "Memory allocation failed");
+				cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
+				break;
+			}
+			ret = RSA_public_decrypt(op->rsa.sign.length,
+					op->rsa.sign.data,
+					tmp,
+					rsa,
+					pad);
+
+			OPENSSL_LOG(DEBUG,
+					"Length of public_decrypt %d "
+					"length of message %zd\n",
+					ret, op->rsa.message.length);
+			if ((ret <= 0) || (CRYPTO_memcmp(tmp, op->rsa.message.data,
+					op->rsa.message.length))) {
+				OPENSSL_LOG(ERR, "RSA sign Verification failed");
+				cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
+			}
+			rte_free(tmp);
 		}
-		rte_free(tmp);
 		break;
 
 	default:
-- 
2.1.0


  parent reply	other threads:[~2019-07-03 15:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-03 15:37 [dpdk-dev] [PATCH v2 0/3]Rework API for RSA algorithm in asymmetric crypto Arek Kusztal
2019-07-03 15:37 ` [dpdk-dev] [PATCH v2 1/3] cryptodev: rework api of rsa algorithm Arek Kusztal
2019-07-04 12:40   ` Kusztal, ArkadiuszX
2019-07-06 13:14     ` Shally Verma
2019-07-08 17:44       ` Kusztal, ArkadiuszX
2019-07-09 10:02         ` Kusztal, ArkadiuszX
2019-07-16 13:51           ` Akhil Goyal
2019-07-16 14:16             ` Kusztal, ArkadiuszX
2019-07-16 14:27               ` Trahe, Fiona
2019-07-03 15:37 ` Arek Kusztal [this message]
2019-07-04 12:44   ` [dpdk-dev] [PATCH v2 2/3] crypto/openssl: rework openssl rsa implementation Kusztal, ArkadiuszX
2019-07-03 15:37 ` [dpdk-dev] [PATCH v2 3/3] test: rework rsa test implementation Arek Kusztal
2019-07-04 15:13 ` [dpdk-dev] [PATCH v2 0/3]Rework API for RSA algorithm in asymmetric crypto Trahe, Fiona

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=20190703153759.1508-3-arkadiuszx.kusztal@intel.com \
    --to=arkadiuszx.kusztal@intel.com \
    --cc=akhil.goyal@nxp.com \
    --cc=dev@dpdk.org \
    --cc=fiona.trahe@intel.com \
    --cc=shally.verma@caviumnetworks.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).