DPDK patches and discussions
 help / color / mirror / Atom feed
From: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
To: <dev@dpdk.org>, Jay Zhou <jianjay.zhou@huawei.com>
Cc: <anoobj@marvell.com>, Akhil Goyal <gakhil@marvell.com>,
	"Gowrishankar Muthukrishnan" <gmuthukrishn@marvell.com>
Subject: [PATCH] crypto/virtio: fix DER encoding for positive RSA param
Date: Sat, 10 May 2025 16:14:07 +0530	[thread overview]
Message-ID: <20250510104412.2154-1-gmuthukrishn@marvell.com> (raw)

As per RFC 8017, RSA parameter needs to be positive integer.
This patch fixes TLV encoding function appropriately.

Fixes: 6fe6a7f7bcf ("crypto/virtio: add asymmetric RSA support")

Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
---
 drivers/crypto/virtio/virtio_cryptodev.c | 30 ++++++++++++++++--------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/drivers/crypto/virtio/virtio_cryptodev.c b/drivers/crypto/virtio/virtio_cryptodev.c
index b01e97c988..4440e02dc9 100644
--- a/drivers/crypto/virtio/virtio_cryptodev.c
+++ b/drivers/crypto/virtio/virtio_cryptodev.c
@@ -1459,27 +1459,37 @@ tlv_encode(uint8_t *tlv, uint8_t type, uint8_t *data, size_t len)
 {
 	uint8_t *lenval = tlv;
 	size_t lenval_n = 0;
+	size_t dlen = len;
+	uint8_t off = 0;
+
+	if (data != NULL && data[0] & 0x80) {
+		dlen += 1;
+		off = 1;
+	}
 
 	if (len > 65535) {
 		goto _exit;
 	} else if (len > 255) {
-		lenval_n = 4 + len;
+		lenval_n = 4 + dlen;
 		lenval[0] = type;
 		lenval[1] = 0x82;
-		lenval[2] = (len & 0xFF00) >> 8;
-		lenval[3] = (len & 0xFF);
-		rte_memcpy(&lenval[4], data, len);
+		lenval[2] = (dlen & 0xFF00) >> 8;
+		lenval[3] = (dlen & 0xFF);
+		lenval += (4 + off);
+		rte_memcpy(lenval, data, len);
 	} else if (len > 127) {
-		lenval_n = 3 + len;
+		lenval_n = 3 + dlen;
 		lenval[0] = type;
 		lenval[1] = 0x81;
-		lenval[2] = len;
-		rte_memcpy(&lenval[3], data, len);
+		lenval[2] = dlen;
+		lenval += (3 + off);
+		rte_memcpy(lenval, data, len);
 	} else {
-		lenval_n = 2 + len;
+		lenval_n = 2 + dlen;
 		lenval[0] = type;
-		lenval[1] = len;
-		rte_memcpy(&lenval[2], data, len);
+		lenval[1] = dlen;
+		lenval += (2 + off);
+		rte_memcpy(lenval, data, len);
 	}
 
 _exit:
-- 
2.25.1


                 reply	other threads:[~2025-05-10 10:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20250510104412.2154-1-gmuthukrishn@marvell.com \
    --to=gmuthukrishn@marvell.com \
    --cc=anoobj@marvell.com \
    --cc=dev@dpdk.org \
    --cc=gakhil@marvell.com \
    --cc=jianjay.zhou@huawei.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).