* [PATCH] crypto/virtio: fix DER encoding for positive RSA param
@ 2025-05-10 10:44 Gowrishankar Muthukrishnan
0 siblings, 0 replies; only message in thread
From: Gowrishankar Muthukrishnan @ 2025-05-10 10:44 UTC (permalink / raw)
To: dev, Jay Zhou; +Cc: anoobj, Akhil Goyal, Gowrishankar Muthukrishnan
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-05-10 10:44 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-10 10:44 [PATCH] crypto/virtio: fix DER encoding for positive RSA param Gowrishankar Muthukrishnan
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).