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 of RSA public key
Date: Sat, 10 May 2025 16:10:58 +0530 [thread overview]
Message-ID: <20250510104103.2081-1-gmuthukrishn@marvell.com> (raw)
As per RFC 8017, RSA public key in ASN.1 should have only
modulus and exponent values. Add a separate encoding function
to follow this standard.
Fixes: 6fe6a7f7bcf ("crypto/virtio: add asymmetric RSA support")
Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
---
drivers/crypto/virtio/virtio_cryptodev.c | 31 +++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/drivers/crypto/virtio/virtio_cryptodev.c b/drivers/crypto/virtio/virtio_cryptodev.c
index bc737f1e68..b01e97c988 100644
--- a/drivers/crypto/virtio/virtio_cryptodev.c
+++ b/drivers/crypto/virtio/virtio_cryptodev.c
@@ -1524,6 +1524,29 @@ virtio_crypto_asym_rsa_xform_to_der(
return len;
}
+static int
+virtio_crypto_asym_rsa_xform_to_public_der(
+ struct rte_crypto_asym_xform *xform,
+ uint8_t *der)
+{
+ uint8_t data[VIRTIO_CRYPTO_MAX_CTRL_DATA];
+ size_t tlen = 0, len;
+ uint8_t *tlv;
+
+ if (xform->xform_type != RTE_CRYPTO_ASYM_XFORM_RSA)
+ return -EINVAL;
+
+ tlv = data;
+ len = tlv_encode(tlv, 0x02, xform->rsa.n.data, xform->rsa.n.length);
+ tlen += len;
+ len = tlv_encode(tlv + tlen, 0x02, xform->rsa.e.data, xform->rsa.e.length);
+ tlen += len;
+
+ RTE_ASSERT(tlen < VIRTIO_CRYPTO_MAX_CTRL_DATA);
+ len = tlv_encode(der, 0x30, data, tlen);
+ return len;
+}
+
static int
virtio_crypto_asym_rsa_configure_session(
struct rte_crypto_rsa_xform *rsa,
@@ -1607,7 +1630,13 @@ virtio_crypto_asym_configure_session(
return ret;
}
- ret = virtio_crypto_asym_rsa_xform_to_der(xform, ctrl->data);
+ if (xform->rsa.key_type == RTE_RSA_KEY_TYPE_EXP) {
+ ret = virtio_crypto_asym_rsa_xform_to_public_der(
+ xform, ctrl->data);
+ } else {
+ ret = virtio_crypto_asym_rsa_xform_to_der(xform,
+ ctrl->data);
+ }
if (ret <= 0) {
VIRTIO_CRYPTO_SESSION_LOG_ERR("Invalid RSA primitives");
return ret;
--
2.25.1
reply other threads:[~2025-05-10 10:41 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=20250510104103.2081-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).