Skip to contentSkip to conversation

vhost: add asymmetric crypto support

PATCH Superseded Gowrishankar Muthukrishnan 4 participants 16 messages Sep 5, 2024 – Oct 10, 2024

Subsystems (3)

v1 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

cover vhost: add asymmetric crypto support

This series of patches add asymmetric crypto support in vhost library and virtio PMD, specifically for RSA.

To verify functionality in QEMU, you would need:
https://github.com/qemu/qemu/commit/5c33f9783ace0b5e077060b220978d94fecb3e81

There is VirtIO specification change proposed for RSA support, and this series apply it at required places.
https://lists.oasis-open.org/archives/virtio-comment/202305/msg00341.html

In case, qemu crashes, check disabling VHOST_USER_PROTOCOL_F_CONFIG in virtio pmd, when the device starts. This issue was seen with older qemu.

Gowrishankar Muthukrishnan (6):
cryptodev: move RSA padding information into xform
cryptodev: fix RSA xform for ASN.1 syntax
vhost: add asymmetric RSA support crypto/virtio: add asymmetric RSA support examples/vhost_crypto: add asymmetric support app/test: add asymmetric tests for virtio pmd

 app/test/test_cryptodev_asym.c                |  46 +-
 app/test/test_cryptodev_rsa_test_vectors.h    |  28 +
 drivers/common/cpt/cpt_ucode_asym.h           |   4 +-
 drivers/crypto/cnxk/cnxk_ae.h                 |  13 +-
 drivers/crypto/octeontx/otx_cryptodev_ops.c   |   4 +-
 drivers/crypto/openssl/openssl_pmd_private.h  |   1 +
 drivers/crypto/openssl/rte_openssl_pmd.c      |   4 +-
 drivers/crypto/openssl/rte_openssl_pmd_ops.c  |   1 +
 drivers/crypto/qat/qat_asym.c                 |  17 +-
 .../virtio/virtio_crypto_capabilities.h       |  19 +
 drivers/crypto/virtio/virtio_cryptodev.c      | 388 ++++++++++--
 drivers/crypto/virtio/virtio_rxtx.c           | 233 +++++++-
 examples/fips_validation/main.c               |  52 +-
 examples/vhost_crypto/main.c                  |  50 +-
 lib/cryptodev/cryptodev_pmd.h                 |   6 +
 lib/cryptodev/rte_crypto_asym.h               |   8 +-
 lib/vhost/rte_vhost_crypto.h                  |  14 +-
 lib/vhost/vhost.c                             |  11 +-
 lib/vhost/vhost.h                             |   1 +
 lib/vhost/vhost_crypto.c                      | 550 ++++++++++++++++--
 lib/vhost/vhost_user.c                        |   4 +
 lib/vhost/vhost_user.h                        |  34 +-
 lib/vhost/virtio_crypto.h                     |  87 ++-
 23 files changed, 1378 insertions(+), 197 deletions(-)
Signature · 1 line
2.21.0
#1 lore raw

PATCH 1/6 cryptodev: move RSA padding information into xform

RSA padding information could be a xform entity rather than part of crypto op, as it seems associated with hashing algorithm used for the entire crypto session, where this algorithm is used in message digest itself. Even in virtIO standard spec, this info is associated in the asymmetric session creation. Hence, moving this info from crypto op into xform structure.

---
 app/test/test_cryptodev_asym.c               |  4 --
 app/test/test_cryptodev_rsa_test_vectors.h   |  2 +
 drivers/common/cpt/cpt_ucode_asym.h          |  4 +-
 drivers/crypto/cnxk/cnxk_ae.h                | 13 +++--
 drivers/crypto/octeontx/otx_cryptodev_ops.c  |  4 +-
 drivers/crypto/openssl/openssl_pmd_private.h |  1 +
 drivers/crypto/openssl/rte_openssl_pmd.c     |  4 +-
 drivers/crypto/openssl/rte_openssl_pmd_ops.c |  1 +
 drivers/crypto/qat/qat_asym.c                | 17 ++++---
 examples/fips_validation/main.c              | 52 +++++++++++---------
 lib/cryptodev/rte_crypto_asym.h              |  6 +--
 11 files changed, 58 insertions(+), 50 deletions(-)
app/test/test_cryptodev_asym.c +0 -4
index f0b5d38543..0928367cb0 100644
@@ -80,7 +80,6 @@ queue_ops_rsa_sign_verify(void *sess)
 	asym_op->rsa.message.length = rsaplaintext.len;
 	asym_op->rsa.sign.length = RTE_DIM(rsa_n);
 	asym_op->rsa.sign.data = output_buf;
-	asym_op->rsa.padding.type = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
 
 	debug_hexdump(stdout, "message", asym_op->rsa.message.data,
 		      asym_op->rsa.message.length);
@@ -112,7 +111,6 @@ queue_ops_rsa_sign_verify(void *sess)
 
 	/* Verify sign */
 	asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
-	asym_op->rsa.padding.type = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
 
 	/* Process crypto operation */
 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
@@ -171,7 +169,6 @@ queue_ops_rsa_enc_dec(void *sess)
 	asym_op->rsa.cipher.data = cipher_buf;
 	asym_op->rsa.cipher.length = RTE_DIM(rsa_n);
 	asym_op->rsa.message.length = rsaplaintext.len;
-	asym_op->rsa.padding.type = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
 
 	debug_hexdump(stdout, "message", asym_op->rsa.message.data,
 		      asym_op->rsa.message.length);
@@ -203,7 +200,6 @@ queue_ops_rsa_enc_dec(void *sess)
 	asym_op = result_op->asym;
 	asym_op->rsa.message.length = RTE_DIM(rsa_n);
 	asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
-	asym_op->rsa.padding.type = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
 
 	/* Process crypto operation */
 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
app/test/test_cryptodev_rsa_test_vectors.h +2 -0
index 89981f13f0..1b7b451387 100644
@@ -345,6 +345,7 @@ struct rte_crypto_asym_xform rsa_xform = {
 	.next = NULL,
 	.xform_type = RTE_CRYPTO_ASYM_XFORM_RSA,
 	.rsa = {
+		.padding.type = RTE_CRYPTO_RSA_PADDING_PKCS1_5,
 		.n = {
 			.data = rsa_n,
 			.length = sizeof(rsa_n)
@@ -366,6 +367,7 @@ struct rte_crypto_asym_xform rsa_xform_crt = {
 	.next = NULL,
 	.xform_type = RTE_CRYPTO_ASYM_XFORM_RSA,
 	.rsa = {
+		.padding.type = RTE_CRYPTO_RSA_PADDING_PKCS1_5,
 		.n = {
 			.data = rsa_n,
 			.length = sizeof(rsa_n)
drivers/common/cpt/cpt_ucode_asym.h +2 -2
index e1034bbeb4..5122378ec7 100644
@@ -327,7 +327,7 @@ cpt_rsa_prep(struct asym_op_params *rsa_params,
 	/* Result buffer */
 	rlen = mod_len;
 
-	if (rsa_op.padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
+	if (rsa->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
 		/* Use mod_exp operation for no_padding type */
 		vq_cmd_w0.s.opcode.minor = CPT_MINOR_OP_MODEX;
 		vq_cmd_w0.s.param2 = exp_len;
@@ -412,7 +412,7 @@ cpt_rsa_crt_prep(struct asym_op_params *rsa_params,
 	/* Result buffer */
 	rlen = mod_len;
 
-	if (rsa_op.padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
+	if (rsa->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
 		/*Use mod_exp operation for no_padding type */
 		vq_cmd_w0.s.opcode.minor = CPT_MINOR_OP_MODEX_CRT;
 	} else {
drivers/crypto/cnxk/cnxk_ae.h +8 -5
index ef9cb5eb91..1bb5a450c5 100644
@@ -177,6 +177,9 @@ cnxk_ae_fill_rsa_params(struct cnxk_ae_sess *sess,
 	rsa->n.length = mod_len;
 	rsa->e.length = exp_len;
 
+	/* Set padding info */
+	rsa->padding.type = xform->rsa.padding.type;
+
 	return 0;
 }
 
@@ -366,7 +369,7 @@ cnxk_ae_rsa_prep(struct rte_crypto_op *op, struct roc_ae_buf_ptr *meta_buf,
 	dptr += in_size;
 	dlen = total_key_len + in_size;
 
-	if (rsa_op.padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
+	if (rsa->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
 		/* Use mod_exp operation for no_padding type */
 		w4.s.opcode_minor = ROC_AE_MINOR_OP_MODEX;
 		w4.s.param2 = exp_len;
@@ -421,7 +424,7 @@ cnxk_ae_rsa_exp_prep(struct rte_crypto_op *op, struct roc_ae_buf_ptr *meta_buf,
 	dptr += in_size;
 	dlen = mod_len + privkey_len + in_size;
 
-	if (rsa_op.padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
+	if (rsa->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
 		/* Use mod_exp operation for no_padding type */
 		w4.s.opcode_minor = ROC_AE_MINOR_OP_MODEX;
 		w4.s.param2 = privkey_len;
@@ -479,7 +482,7 @@ cnxk_ae_rsa_crt_prep(struct rte_crypto_op *op, struct roc_ae_buf_ptr *meta_buf,
 	dptr += in_size;
 	dlen = total_key_len + in_size;
 
-	if (rsa_op.padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
+	if (rsa->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
 		/*Use mod_exp operation for no_padding type */
 		w4.s.opcode_minor = ROC_AE_MINOR_OP_MODEX_CRT;
 	} else {
@@ -1151,7 +1154,7 @@ cnxk_ae_dequeue_rsa_op(struct rte_crypto_op *cop, uint8_t *rptr,
 		memcpy(rsa->cipher.data, rptr, rsa->cipher.length);
 		break;
 	case RTE_CRYPTO_ASYM_OP_DECRYPT:
-		if (rsa->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
+		if (rsa_ctx->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
 			rsa->message.length = rsa_ctx->n.length;
 			memcpy(rsa->message.data, rptr, rsa->message.length);
 		} else {
@@ -1171,7 +1174,7 @@ cnxk_ae_dequeue_rsa_op(struct rte_crypto_op *cop, uint8_t *rptr,
 		memcpy(rsa->sign.data, rptr, rsa->sign.length);
 		break;
 	case RTE_CRYPTO_ASYM_OP_VERIFY:
-		if (rsa->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
+		if (rsa_ctx->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
 			rsa->sign.length = rsa_ctx->n.length;
 			memcpy(rsa->sign.data, rptr, rsa->sign.length);
 		} else {
drivers/crypto/octeontx/otx_cryptodev_ops.c +2 -2
index bafd0c1669..9a758cd297 100644
@@ -708,7 +708,7 @@ otx_cpt_asym_rsa_op(struct rte_crypto_op *cop, struct cpt_request_info *req,
 		memcpy(rsa->cipher.data, req->rptr, rsa->cipher.length);
 		break;
 	case RTE_CRYPTO_ASYM_OP_DECRYPT:
-		if (rsa->padding.type == RTE_CRYPTO_RSA_PADDING_NONE)
+		if (rsa_ctx->padding.type == RTE_CRYPTO_RSA_PADDING_NONE)
 			rsa->message.length = rsa_ctx->n.length;
 		else {
 			/* Get length of decrypted output */
@@ -725,7 +725,7 @@ otx_cpt_asym_rsa_op(struct rte_crypto_op *cop, struct cpt_request_info *req,
 		memcpy(rsa->sign.data, req->rptr, rsa->sign.length);
 		break;
 	case RTE_CRYPTO_ASYM_OP_VERIFY:
-		if (rsa->padding.type == RTE_CRYPTO_RSA_PADDING_NONE)
+		if (rsa_ctx->padding.type == RTE_CRYPTO_RSA_PADDING_NONE)
 			rsa->sign.length = rsa_ctx->n.length;
 		else {
 			/* Get length of decrypted output */
drivers/crypto/openssl/openssl_pmd_private.h +1 -0
index a50e4d4918..4caf1ebcb5 100644
@@ -197,6 +197,7 @@ struct __rte_cache_aligned openssl_asym_session {
 	union {
 		struct rsa {
 			RSA *rsa;
+			uint32_t pad;
 #if (OPENSSL_VERSION_NUMBER >= 0x30000000L)
 			EVP_PKEY_CTX * ctx;
 #endif
drivers/crypto/openssl/rte_openssl_pmd.c +2 -2
index 101111e85b..8877fd5d92 100644
@@ -2699,7 +2699,7 @@ process_openssl_rsa_op_evp(struct rte_crypto_op *cop,
 		struct openssl_asym_session *sess)
 {
 	struct rte_crypto_asym_op *op = cop->asym;
-	uint32_t pad = (op->rsa.padding.type);
+	uint32_t pad = sess->u.r.pad;
 	uint8_t *tmp;
 	size_t outlen = 0;
 	int ret = -1;
@@ -3082,7 +3082,7 @@ 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.padding.type);
+	uint32_t pad = sess->u.r.pad;
 	uint8_t *tmp;
 
 	cop->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
drivers/crypto/openssl/rte_openssl_pmd_ops.c +1 -0
index 1bbb855a59..4c47c3e7dd 100644
@@ -889,6 +889,7 @@ static int openssl_set_asym_session_parameters(
 		if (!n || !e)
 			goto err_rsa;
 
+		asym_session->u.r.pad = xform->rsa.padding.type;
 #if (OPENSSL_VERSION_NUMBER >= 0x30000000L)
 		OSSL_PARAM_BLD * param_bld = OSSL_PARAM_BLD_new();
 		if (!param_bld) {
drivers/crypto/qat/qat_asym.c +9 -8
index 491f5ecd5b..020c8fac5f 100644
@@ -362,7 +362,7 @@ rsa_set_pub_input(struct icp_qat_fw_pke_request *qat_req,
 	alg_bytesize = qat_function.bytesize;
 
 	if (asym_op->rsa.op_type == RTE_CRYPTO_ASYM_OP_ENCRYPT) {
-		switch (asym_op->rsa.padding.type) {
+		switch (xform->rsa.padding.type) {
 		case RTE_CRYPTO_RSA_PADDING_NONE:
 			SET_PKE_LN(asym_op->rsa.message, alg_bytesize, 0);
 			break;
@@ -374,7 +374,7 @@ rsa_set_pub_input(struct icp_qat_fw_pke_request *qat_req,
 		}
 		HEXDUMP("RSA Message", cookie->input_array[0], alg_bytesize);
 	} else {
-		switch (asym_op->rsa.padding.type) {
+		switch (xform->rsa.padding.type) {
 		case RTE_CRYPTO_RSA_PADDING_NONE:
 			SET_PKE_LN(asym_op->rsa.sign, alg_bytesize, 0);
 			break;
@@ -460,7 +460,7 @@ rsa_set_priv_input(struct icp_qat_fw_pke_request *qat_req,
 
 	if (asym_op->rsa.op_type ==
 			RTE_CRYPTO_ASYM_OP_DECRYPT) {
-		switch (asym_op->rsa.padding.type) {
+		switch (xform->rsa.padding.type) {
 		case RTE_CRYPTO_RSA_PADDING_NONE:
 			SET_PKE_LN(asym_op->rsa.cipher,	alg_bytesize, 0);
 			HEXDUMP("RSA ciphertext", cookie->input_array[0],
@@ -474,7 +474,7 @@ rsa_set_priv_input(struct icp_qat_fw_pke_request *qat_req,
 
 	} else if (asym_op->rsa.op_type ==
 			RTE_CRYPTO_ASYM_OP_SIGN) {
-		switch (asym_op->rsa.padding.type) {
+		switch (xform->rsa.padding.type) {
 		case RTE_CRYPTO_RSA_PADDING_NONE:
 			SET_PKE_LN(asym_op->rsa.message, alg_bytesize, 0);
 			HEXDUMP("RSA text to be signed", cookie->input_array[0],
@@ -514,7 +514,8 @@ rsa_set_input(struct icp_qat_fw_pke_request *qat_req,
 
 static uint8_t
 rsa_collect(struct rte_crypto_asym_op *asym_op,
-		const struct qat_asym_op_cookie *cookie)
+		const struct qat_asym_op_cookie *cookie,
+		const struct rte_crypto_asym_xform *xform)
 {
 	uint32_t alg_bytesize = cookie->alg_bytesize;
 
@@ -530,7 +531,7 @@ rsa_collect(struct rte_crypto_asym_op *asym_op,
 			HEXDUMP("RSA Encrypted data", cookie->output_array[0],
 				alg_bytesize);
 		} else {
-			switch (asym_op->rsa.padding.type) {
+			switch (xform->rsa.padding.type) {
 			case RTE_CRYPTO_RSA_PADDING_NONE:
 				rte_memcpy(asym_op->rsa.cipher.data,
 						cookie->output_array[0],
@@ -547,7 +548,7 @@ rsa_collect(struct rte_crypto_asym_op *asym_op,
 		}
 	} else {
 		if (asym_op->rsa.op_type == RTE_CRYPTO_ASYM_OP_DECRYPT) {
-			switch (asym_op->rsa.padding.type) {
+			switch (xform->rsa.padding.type) {
 			case RTE_CRYPTO_RSA_PADDING_NONE:
 				rte_memcpy(asym_op->rsa.message.data,
 					cookie->output_array[0],
@@ -1105,7 +1106,7 @@ qat_asym_collect_response(struct rte_crypto_op *op,
 	case RTE_CRYPTO_ASYM_XFORM_MODINV:
 		return modinv_collect(asym_op, cookie, xform);
 	case RTE_CRYPTO_ASYM_XFORM_RSA:
-		return rsa_collect(asym_op, cookie);
+		return rsa_collect(asym_op, cookie, xform);
 	case RTE_CRYPTO_ASYM_XFORM_ECDSA:
 		return ecdsa_collect(asym_op, cookie);
 	case RTE_CRYPTO_ASYM_XFORM_ECPM:
examples/fips_validation/main.c +28 -24

65 lines not on this page · raw message

lib/cryptodev/rte_crypto_asym.h +3 -3
index 39d3da3952..64d8a42f6a 100644
@@ -312,6 +312,9 @@ struct rte_crypto_rsa_xform {
 		struct rte_crypto_rsa_priv_key_qt qt;
 		/**< qt - Private key in quintuple format */
 	};
+
+	struct rte_crypto_rsa_padding padding;
+	/**< RSA padding information */
 };
 
 /**
@@ -447,9 +450,6 @@ struct rte_crypto_rsa_op_param {
 	 * This could be validated and overwritten by the PMD
 	 * with the signature length.
 	 */
-
-	struct rte_crypto_rsa_padding padding;
-	/**< RSA padding information */
 };
 
 /**
Signature · 1 line
2.21.0
#2 lore raw

PATCH 2/6 cryptodev: fix RSA xform for ASN.1 syntax

In reply to Gowrishankar Muthukrishnan

As per ASN.1 syntax (RFC 3447 Appendix A.1.2), RSA private key would need specification of quintuple along with private exponent. It is up to the implementation to internally handle, but not at RTE itself to make them exclusive each other. Removing union on them allows asymmetric implementation in VirtIO to benefit from the xform as per ASN.1 syntax.

---
 lib/cryptodev/rte_crypto_asym.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/cryptodev/rte_crypto_asym.h +1 -1
index 64d8a42f6a..398b6514e3 100644
@@ -306,7 +306,7 @@ struct rte_crypto_rsa_xform {
 
 	enum rte_crypto_rsa_priv_key_type key_type;
 
-	union {
+	struct {
 		rte_crypto_uint d;
 		/**< the RSA private exponent */
 		struct rte_crypto_rsa_priv_key_qt qt;
Signature · 1 line
2.21.0
#3 lore raw

PATCH 3/6 vhost: add asymmetric RSA support

In reply to Gowrishankar Muthukrishnan

Support asymmetric RSA crypto operations in vhost-user.

---
 lib/cryptodev/cryptodev_pmd.h |   6 +
 lib/vhost/rte_vhost_crypto.h  |  14 +-
 lib/vhost/vhost.c             |  11 +-
 lib/vhost/vhost.h             |   1 +
 lib/vhost/vhost_crypto.c      | 550 +++++++++++++++++++++++++++++++---
 lib/vhost/vhost_user.c        |   4 +
 lib/vhost/vhost_user.h        |  34 ++-
 lib/vhost/virtio_crypto.h     |  87 +++++-
 8 files changed, 654 insertions(+), 53 deletions(-)
lib/cryptodev/cryptodev_pmd.h +6 -0
index 6c114f7181..ff3756723d 100644
@@ -697,6 +697,12 @@ struct rte_cryptodev_asym_session {
 	uint8_t sess_private_data[];
 };
 
+/**
+ * Helper macro to get session private data
+ */
+#define CRYPTODEV_GET_ASYM_SESS_PRIV(s) \
+	((void *)(((struct rte_cryptodev_asym_session *)s)->sess_private_data))
+
 #ifdef __cplusplus
 }
 #endif
lib/vhost/rte_vhost_crypto.h +10 -4
index f962a53818..274f737990 100644
@@ -49,8 +49,10 @@ rte_vhost_crypto_driver_start(const char *path);
  * @param cryptodev_id
  *  The identifier of DPDK Cryptodev, the same cryptodev_id can be assigned to
  *  multiple Vhost-crypto devices.
- * @param sess_pool
- *  The pointer to the created cryptodev session pool.
+ * @param sym_sess_pool
+ *  The pointer to the created cryptodev sym session pool.
+ * @param asym_sess_pool
+ *  The pointer to the created cryptodev asym session pool.
  * @param socket_id
  *  NUMA Socket ID to allocate resources on. *
  * @return
@@ -59,7 +61,7 @@ rte_vhost_crypto_driver_start(const char *path);
  */
 int
 rte_vhost_crypto_create(int vid, uint8_t cryptodev_id,
-		struct rte_mempool *sess_pool,
+		struct rte_mempool *sym_sess_pool, struct rte_mempool *asym_sess_pool,
 		int socket_id);
 
 /**
@@ -113,6 +115,10 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid,
  * dequeued from the cryptodev, this function shall be called to write the
  * processed data back to the vring descriptor (if no-copy is turned off).
  *
+ * @param vid
+ *  The identifier of the vhost device.
+ * @param qid
+ *  Virtio queue index.
  * @param ops
  *  The address of an array of *rte_crypto_op* structure that was dequeued
  *  from cryptodev.
@@ -127,7 +133,7 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid,
  *  The number of ops processed.
  */
 uint16_t
-rte_vhost_crypto_finalize_requests(struct rte_crypto_op **ops,
+rte_vhost_crypto_finalize_requests(int vid, int qid, struct rte_crypto_op **ops,
 		uint16_t nb_ops, int *callfds, uint16_t *nb_callfds);
 
 #ifdef __cplusplus
lib/vhost/vhost.c +9 -2
index ac71d17784..c9048e4f24 100644
@@ -636,8 +636,12 @@ alloc_vring_queue(struct virtio_net *dev, uint32_t vring_idx)
 
 	/* Also allocate holes, if any, up to requested vring index. */
 	for (i = 0; i <= vring_idx; i++) {
-		if (dev->virtqueue[i])
+		rte_spinlock_lock(&dev->virtqueue_lock);
+		if (dev->virtqueue[i]) {
+			rte_spinlock_unlock(&dev->virtqueue_lock);
 			continue;
+		}
+		rte_spinlock_unlock(&dev->virtqueue_lock);
 
 		vq = rte_zmalloc(NULL, sizeof(struct vhost_virtqueue), 0);
 		if (vq == NULL) {
@@ -647,13 +651,15 @@ alloc_vring_queue(struct virtio_net *dev, uint32_t vring_idx)
 			return -1;
 		}
 
-		dev->virtqueue[i] = vq;
 		init_vring_queue(dev, vq, i);
 		rte_rwlock_init(&vq->access_lock);
 		rte_rwlock_init(&vq->iotlb_lock);
 		vq->avail_wrap_counter = 1;
 		vq->used_wrap_counter = 1;
 		vq->signalled_used_valid = false;
+		rte_spinlock_lock(&dev->virtqueue_lock);
+		dev->virtqueue[i] = vq;
+		rte_spinlock_unlock(&dev->virtqueue_lock);
 	}
 
 	dev->nr_vring = RTE_MAX(dev->nr_vring, vring_idx + 1);
@@ -740,6 +746,7 @@ vhost_new_device(struct vhost_backend_ops *ops)
 	dev->postcopy_ufd = -1;
 	rte_spinlock_init(&dev->backend_req_lock);
 	dev->backend_ops = ops;
+	rte_spinlock_init(&dev->virtqueue_lock);
 
 	return i;
 }
lib/vhost/vhost.h +1 -0
index cd3fa55f1b..ad33948e8b 100644
@@ -494,6 +494,7 @@ struct __rte_cache_aligned virtio_net {
 
 	int			extbuf;
 	int			linearbuf;
+	rte_spinlock_t virtqueue_lock;
 	struct vhost_virtqueue	*virtqueue[VHOST_MAX_QUEUE_PAIRS * 2];
 
 	rte_rwlock_t	iotlb_pending_lock;
lib/vhost/vhost_crypto.c +508 -42

749 lines not on this page · raw message

lib/vhost/vhost_user.c +4 -0
index 5f470da38a..b139c64a71 100644
@@ -456,7 +456,9 @@ vhost_user_set_features(struct virtio_net **pdev,
 			if (!vq)
 				continue;
 
+			rte_spinlock_lock(&dev->virtqueue_lock);
 			dev->virtqueue[dev->nr_vring] = NULL;
+			rte_spinlock_unlock(&dev->virtqueue_lock);
 			cleanup_vq(vq, 1);
 			cleanup_vq_inflight(dev, vq);
 			/* vhost_user_lock_all_queue_pairs locked all qps */
@@ -600,7 +602,9 @@ numa_realloc(struct virtio_net **pdev, struct vhost_virtqueue **pvq)
 
 	if (vq != dev->virtqueue[vq->index]) {
 		VHOST_CONFIG_LOG(dev->ifname, INFO, "reallocated virtqueue on node %d", node);
+		rte_spinlock_lock(&dev->virtqueue_lock);
 		dev->virtqueue[vq->index] = vq;
+		rte_spinlock_unlock(&dev->virtqueue_lock);
 	}
 
 	if (vq_is_packed(dev)) {
lib/vhost/vhost_user.h +30 -4
index edf7adb3c0..6174f32dcf 100644
@@ -99,11 +99,10 @@ typedef struct VhostUserLog {
 /* Comply with Cryptodev-Linux */
 #define VHOST_USER_CRYPTO_MAX_HMAC_KEY_LENGTH	512
 #define VHOST_USER_CRYPTO_MAX_CIPHER_KEY_LENGTH	64
+#define VHOST_USER_CRYPTO_MAX_KEY_LENGTH	1024
 
 /* Same structure as vhost-user backend session info */
-typedef struct VhostUserCryptoSessionParam {
-	int64_t session_id;
-	uint32_t op_code;
+typedef struct VhostUserCryptoSymSessionParam {
 	uint32_t cipher_algo;
 	uint32_t cipher_key_len;
 	uint32_t hash_algo;
@@ -114,10 +113,37 @@ typedef struct VhostUserCryptoSessionParam {
 	uint8_t dir;
 	uint8_t hash_mode;
 	uint8_t chaining_dir;
-	uint8_t *ciphe_key;
+	uint8_t *cipher_key;
 	uint8_t *auth_key;
 	uint8_t cipher_key_buf[VHOST_USER_CRYPTO_MAX_CIPHER_KEY_LENGTH];
 	uint8_t auth_key_buf[VHOST_USER_CRYPTO_MAX_HMAC_KEY_LENGTH];
+} VhostUserCryptoSymSessionParam;
+
+
+typedef struct VhostUserCryptoAsymRsaParam {
+	uint32_t padding_algo;
+	uint32_t hash_algo;
+	uint8_t private_key_type;
+} VhostUserCryptoAsymRsaParam;
+
+typedef struct VhostUserCryptoAsymSessionParam {
+	uint32_t algo;
+	uint32_t key_type;
+	uint32_t key_len;
+	uint8_t *key;
+	union {
+		VhostUserCryptoAsymRsaParam rsa;
+	} u;
+	uint8_t key_buf[VHOST_USER_CRYPTO_MAX_KEY_LENGTH];
+} VhostUserCryptoAsymSessionParam;
+
+typedef struct VhostUserCryptoSessionParam {
+	uint32_t op_code;
+	union {
+		VhostUserCryptoSymSessionParam sym_sess;
+		VhostUserCryptoAsymSessionParam asym_sess;
+	} u;
+	uint64_t session_id;
 } VhostUserCryptoSessionParam;
 
 typedef struct VhostUserVringArea {
lib/vhost/virtio_crypto.h +86 -1

141 lines not on this page · raw message

Signature · 1 line
2.21.0
#4 lore raw

PATCH 4/6 crypto/virtio: add asymmetric RSA support

In reply to Gowrishankar Muthukrishnan

Asymmetric RSA operations (SIGN, VERIFY, ENCRYPT and DECRYPT) are supported in virtio PMD.

---
 .../virtio/virtio_crypto_capabilities.h       |  19 +
 drivers/crypto/virtio/virtio_cryptodev.c      | 388 +++++++++++++++---
 drivers/crypto/virtio/virtio_rxtx.c           | 233 ++++++++++-
 3 files changed, 572 insertions(+), 68 deletions(-)
drivers/crypto/virtio/virtio_crypto_capabilities.h +19 -0
index 03c30deefd..1b26ff6720 100644
@@ -48,4 +48,23 @@
 		}, }							\
 	}
 
+#define VIRTIO_ASYM_CAPABILITIES					\
+	{       /* RSA */						\
+		.op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC,			\
+		{.asym = {						\
+			.xform_capa = {					\
+			.xform_type = RTE_CRYPTO_ASYM_XFORM_RSA,	\
+			.op_types = ((1 << RTE_CRYPTO_ASYM_OP_SIGN) |	\
+					(1 << RTE_CRYPTO_ASYM_OP_VERIFY) |  \
+					(1 << RTE_CRYPTO_ASYM_OP_ENCRYPT) | \
+					(1 << RTE_CRYPTO_ASYM_OP_DECRYPT)), \
+			{.modlen = {					\
+				.min = 1,				\
+				.max = 1024,				\
+				.increment = 1				\
+			}, }						\
+		}							\
+		 }, }							\
+	}
+
 #endif /* _VIRTIO_CRYPTO_CAPABILITIES_H_ */
drivers/crypto/virtio/virtio_cryptodev.c +336 -52

482 lines not on this page · raw message

drivers/crypto/virtio/virtio_rxtx.c +217 -16

256 lines not on this page · raw message

Signature · 1 line
2.21.0
#5 lore raw

PATCH 5/6 examples/vhost_crypto: add asymmetric support

In reply to Gowrishankar Muthukrishnan

Add symmetric support.

---
 examples/vhost_crypto/main.c | 50 +++++++++++++++++++++---------------
 1 file changed, 29 insertions(+), 21 deletions(-)
examples/vhost_crypto/main.c +29 -21
index 558c09a60f..bed7fc637d 100644
@@ -45,7 +45,8 @@ struct lcore_option {
 struct __rte_cache_aligned vhost_crypto_info {
 	int vids[MAX_NB_SOCKETS];
 	uint32_t nb_vids;
-	struct rte_mempool *sess_pool;
+	struct rte_mempool *sym_sess_pool;
+	struct rte_mempool *asym_sess_pool;
 	struct rte_mempool *cop_pool;
 	uint8_t cid;
 	uint32_t qid;
@@ -302,7 +303,8 @@ new_device(int vid)
 		return -ENOENT;
 	}
 
-	ret = rte_vhost_crypto_create(vid, info->cid, info->sess_pool,
+	ret = rte_vhost_crypto_create(vid, info->cid, info->sym_sess_pool,
+			info->asym_sess_pool,
 			rte_lcore_to_socket_id(options.los[i].lcore_id));
 	if (ret) {
 		RTE_LOG(ERR, USER1, "Cannot create vhost crypto\n");
@@ -362,8 +364,8 @@ destroy_device(int vid)
 }
 
 static const struct rte_vhost_device_ops virtio_crypto_device_ops = {
-	.new_device =  new_device,
-	.destroy_device = destroy_device,
+	.new_connection =  new_device,
+	.destroy_connection = destroy_device,
 };
 
 static int
@@ -385,7 +387,7 @@ vhost_crypto_worker(void *arg)
 
 	for (i = 0; i < NB_VIRTIO_QUEUES; i++) {
 		if (rte_crypto_op_bulk_alloc(info->cop_pool,
-				RTE_CRYPTO_OP_TYPE_SYMMETRIC, ops[i],
+				RTE_CRYPTO_OP_TYPE_UNDEFINED, ops[i],
 				burst_size) < burst_size) {
 			RTE_LOG(ERR, USER1, "Failed to alloc cops\n");
 			ret = -1;
@@ -409,20 +411,12 @@ vhost_crypto_worker(void *arg)
 						rte_cryptodev_enqueue_burst(
 						info->cid, info->qid, ops[j],
 						fetched);
-				if (unlikely(rte_crypto_op_bulk_alloc(
-						info->cop_pool,
-						RTE_CRYPTO_OP_TYPE_SYMMETRIC,
-						ops[j], fetched) < fetched)) {
-					RTE_LOG(ERR, USER1, "Failed realloc\n");
-					return -1;
-				}
-
 				fetched = rte_cryptodev_dequeue_burst(
 						info->cid, info->qid,
 						ops_deq[j], RTE_MIN(burst_size,
 						info->nb_inflight_ops));
 				fetched = rte_vhost_crypto_finalize_requests(
-						ops_deq[j], fetched, callfds,
+						info->vids[i], j, ops_deq[j], fetched, callfds,
 						&nb_callfds);
 
 				info->nb_inflight_ops -= fetched;
@@ -455,7 +449,8 @@ free_resource(void)
 			continue;
 
 		rte_mempool_free(info->cop_pool);
-		rte_mempool_free(info->sess_pool);
+		rte_mempool_free(info->sym_sess_pool);
+		rte_mempool_free(info->asym_sess_pool);
 
 		for (j = 0; j < lo->nb_sockets; j++) {
 			rte_vhost_driver_unregister(lo->socket_files[i]);
@@ -539,21 +534,34 @@ main(int argc, char *argv[])
 			goto error_exit;
 		}
 
-		snprintf(name, 127, "SESS_POOL_%u", lo->lcore_id);
-		info->sess_pool = rte_cryptodev_sym_session_pool_create(name,
+		snprintf(name, 127, "SYM_SESS_POOL_%u", lo->lcore_id);
+		info->sym_sess_pool = rte_cryptodev_sym_session_pool_create(name,
 				SESSION_MAP_ENTRIES,
 				rte_cryptodev_sym_get_private_session_size(
 				info->cid), 0, 0,
 				rte_lcore_to_socket_id(lo->lcore_id));
 
-		if (!info->sess_pool) {
-			RTE_LOG(ERR, USER1, "Failed to create mempool");
+		if (!info->sym_sess_pool) {
+			RTE_LOG(ERR, USER1, "Failed to create sym session mempool");
+			goto error_exit;
+		}
+
+		/* TODO: storing vhost_crypto_data_req (56 bytes) in user_data,
+		 * but it needs to be moved somewhere.
+		 */
+		snprintf(name, 127, "ASYM_SESS_POOL_%u", lo->lcore_id);
+		info->asym_sess_pool = rte_cryptodev_asym_session_pool_create(name,
+				SESSION_MAP_ENTRIES, 0, 64,
+				rte_lcore_to_socket_id(lo->lcore_id));
+
+		if (!info->asym_sess_pool) {
+			RTE_LOG(ERR, USER1, "Failed to create asym session mempool");
 			goto error_exit;
 		}
 
 		snprintf(name, 127, "COPPOOL_%u", lo->lcore_id);
 		info->cop_pool = rte_crypto_op_pool_create(name,
-				RTE_CRYPTO_OP_TYPE_SYMMETRIC, NB_MEMPOOL_OBJS,
+				RTE_CRYPTO_OP_TYPE_UNDEFINED, NB_MEMPOOL_OBJS,
 				NB_CACHE_OBJS, VHOST_CRYPTO_MAX_IV_LEN,
 				rte_lcore_to_socket_id(lo->lcore_id));
 
@@ -566,7 +574,7 @@ main(int argc, char *argv[])
 		options.infos[i] = info;
 
 		qp_conf.nb_descriptors = NB_CRYPTO_DESCRIPTORS;
-		qp_conf.mp_session = info->sess_pool;
+		qp_conf.mp_session = info->sym_sess_pool;
 
 		for (j = 0; j < dev_info.max_nb_queue_pairs; j++) {
 			ret = rte_cryptodev_queue_pair_setup(info->cid, j,
Signature · 1 line
2.21.0
#6 lore raw

PATCH 6/6 app/test: add asymmetric tests for virtio pmd

In reply to Gowrishankar Muthukrishnan

Add asymmetric tests for Virtio PMD.

---
 app/test/test_cryptodev_asym.c             | 42 +++++++++++++++++++---
 app/test/test_cryptodev_rsa_test_vectors.h | 26 ++++++++++++++
 2 files changed, 64 insertions(+), 4 deletions(-)
app/test/test_cryptodev_asym.c +38 -4
index 0928367cb0..b425643211 100644
@@ -475,7 +475,7 @@ testsuite_setup(void)
 	for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
 			dev_id, qp_id, &ts_params->qp_conf,
-			rte_cryptodev_socket_id(dev_id)),
+			(int8_t)rte_cryptodev_socket_id(dev_id)),
 			"Failed to setup queue pair %u on cryptodev %u ASYM",
 			qp_id, dev_id);
 	}
@@ -538,7 +538,7 @@ ut_setup_asym(void)
 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
 			ts_params->valid_devs[0], qp_id,
 			&ts_params->qp_conf,
-			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
+			(int8_t)rte_cryptodev_socket_id(ts_params->valid_devs[0])),
 			"Failed to setup queue pair %u on cryptodev %u",
 			qp_id, ts_params->valid_devs[0]);
 	}
@@ -3319,7 +3319,6 @@ rsa_encrypt(const struct rsa_test_data_2 *vector, uint8_t *cipher_buf)
 	self->op->asym->rsa.cipher.data = cipher_buf;
 	self->op->asym->rsa.cipher.length = 0;
 	SET_RSA_PARAM(self->op->asym->rsa, vector, message);
-	self->op->asym->rsa.padding.type = vector->padding;
 
 	rte_crypto_op_attach_asym_session(self->op, self->sess);
 	TEST_ASSERT_SUCCESS(send_one(),
@@ -3343,7 +3342,6 @@ rsa_decrypt(const struct rsa_test_data_2 *vector, uint8_t *plaintext,
 	self->op->asym->rsa.message.data = plaintext;
 	self->op->asym->rsa.message.length = 0;
 	self->op->asym->rsa.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
-	self->op->asym->rsa.padding.type = vector->padding;
 	rte_crypto_op_attach_asym_session(self->op, self->sess);
 	TEST_ASSERT_SUCCESS(send_one(),
 		"Failed to process crypto op (Decryption)");
@@ -3385,6 +3383,7 @@ kat_rsa_encrypt(const void *data)
 	SET_RSA_PARAM(xform.rsa, vector, n);
 	SET_RSA_PARAM(xform.rsa, vector, e);
 	SET_RSA_PARAM(xform.rsa, vector, d);
+	xform.rsa.padding.type = vector->padding;
 	xform.rsa.key_type = RTE_RSA_KEY_TYPE_EXP;
 	int ret = rsa_init_session(&xform);
 
@@ -3415,6 +3414,7 @@ kat_rsa_encrypt_crt(const void *data)
 	SET_RSA_PARAM_QT(xform.rsa, vector, dP);
 	SET_RSA_PARAM_QT(xform.rsa, vector, dQ);
 	SET_RSA_PARAM_QT(xform.rsa, vector, qInv);
+	xform.rsa.padding.type = vector->padding;
 	xform.rsa.key_type = RTE_RSA_KEY_TYPE_QT;
 	int ret = rsa_init_session(&xform);
 	if (ret) {
@@ -3440,6 +3440,7 @@ kat_rsa_decrypt(const void *data)
 	SET_RSA_PARAM(xform.rsa, vector, n);
 	SET_RSA_PARAM(xform.rsa, vector, e);
 	SET_RSA_PARAM(xform.rsa, vector, d);
+	xform.rsa.padding.type = vector->padding;
 	xform.rsa.key_type = RTE_RSA_KEY_TYPE_EXP;
 	int ret = rsa_init_session(&xform);
 
@@ -3470,6 +3471,7 @@ kat_rsa_decrypt_crt(const void *data)
 	SET_RSA_PARAM_QT(xform.rsa, vector, dP);
 	SET_RSA_PARAM_QT(xform.rsa, vector, dQ);
 	SET_RSA_PARAM_QT(xform.rsa, vector, qInv);
+	xform.rsa.padding.type = vector->padding;
 	xform.rsa.key_type = RTE_RSA_KEY_TYPE_QT;
 	int ret = rsa_init_session(&xform);
 	if (ret) {
@@ -3634,6 +3636,22 @@ static struct unit_test_suite cryptodev_octeontx_asym_testsuite  = {
 	}
 };
 
+static struct unit_test_suite cryptodev_virtio_asym_testsuite  = {
+	.suite_name = "Crypto Device VIRTIO ASYM Unit Test Suite",
+	.setup = testsuite_setup,
+	.teardown = testsuite_teardown,
+	.unit_test_cases = {
+		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_capability),
+		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
+				test_rsa_sign_verify),
+		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
+				test_rsa_sign_verify_crt),
+		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_rsa_enc_dec),
+		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_rsa_enc_dec_crt),
+		TEST_CASES_END() /**< NULL terminate unit test array */
+	}
+};
+
 static int
 test_cryptodev_openssl_asym(void)
 {
@@ -3702,6 +3720,22 @@ test_cryptodev_cn10k_asym(void)
 	return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
 }
 
+static int
+test_cryptodev_virtio_asym(void)
+{
+	gbl_driver_id = rte_cryptodev_driver_id_get(
+			RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
+	if (gbl_driver_id == -1) {
+		RTE_LOG(ERR, USER1, "virtio PMD must be loaded.\n");
+		return TEST_FAILED;
+	}
+
+	/* Use test suite registered for crypto_virtio PMD */
+	return unit_test_suite_runner(&cryptodev_virtio_asym_testsuite);
+}
+
+REGISTER_DRIVER_TEST(cryptodev_virtio_asym_autotest, test_cryptodev_virtio_asym);
+
 REGISTER_DRIVER_TEST(cryptodev_openssl_asym_autotest, test_cryptodev_openssl_asym);
 REGISTER_DRIVER_TEST(cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);
 REGISTER_DRIVER_TEST(cryptodev_octeontx_asym_autotest, test_cryptodev_octeontx_asym);
app/test/test_cryptodev_rsa_test_vectors.h +26 -0
index 1b7b451387..1c46a8117a 100644
@@ -358,6 +358,28 @@ struct rte_crypto_asym_xform rsa_xform = {
 		.d = {
 			.data = rsa_d,
 			.length = sizeof(rsa_d)
+		},
+		.qt = {
+			.p = {
+				.data = rsa_p,
+				.length = sizeof(rsa_p)
+			},
+			.q = {
+				.data = rsa_q,
+				.length = sizeof(rsa_q)
+			},
+			.dP = {
+				.data = rsa_dP,
+				.length = sizeof(rsa_dP)
+			},
+			.dQ = {
+				.data = rsa_dQ,
+				.length = sizeof(rsa_dQ)
+			},
+			.qInv = {
+				.data = rsa_qInv,
+				.length = sizeof(rsa_qInv)
+			},
 		}
 	}
 };
@@ -377,6 +399,10 @@ struct rte_crypto_asym_xform rsa_xform_crt = {
 			.length = sizeof(rsa_e)
 		},
 		.key_type = RTE_RSA_KEY_TYPE_QT,
+		.d = {
+			.data = rsa_d,
+			.length = sizeof(rsa_d)
+		},
 		.qt = {
 			.p = {
 				.data = rsa_p,
Signature · 1 line
2.21.0
#7 lore raw

Re: [PATCH 6/6] app/test: add asymmetric tests for virtio pmd

Quoted 3 lines · On Thu, 5 Sep 2024 20:26:10 +0530 Gowrishankar Muthukrishnan…

Add asymmetric tests for Virtio PMD.

This patch set has lots of build errors. See patchwork. For example:

*Build Failed #1:
OS: RHEL94-64
Target: x86_64-native-linuxapp-clang
FAILED: lib/librte_vhost.a.p/vhost_vhost_crypto.c.o
clang -Ilib/librte_vhost.a.p -Ilib -I../lib -Ilib/vhost -I../lib/vhost -I. -I.. -Iconfig -I../config -Ilib/eal/include -I../lib/eal/include -Ilib/eal/linux/include -I../lib/eal/linux/include -Ilib/eal/x86/include -I../lib/eal/x86/include -Ilib/eal/common -I../lib/eal/common -Ilib/eal -I../lib/eal -Ilib/kvargs -I../lib/kvargs -Ilib/log -I../lib/log -Ilib/metrics -I../lib/metrics -Ilib/telemetry -I../lib/telemetry -Ilib/ethdev -I../lib/ethdev -Ilib/net -I../lib/net -Ilib/mbuf -I../lib/mbuf -Ilib/mempool -I../lib/mempool -Ilib/ring -I../lib/ring -Ilib/meter -I../lib/meter -Ilib/cryptodev -I../lib/cryptodev -Ilib/rcu -I../lib/rcu -Ilib/hash -I../lib/hash -Ilib/pci -I../lib/pci -Ilib/dmadev -I../lib/dmadev -fcolor-diagnostics -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Werror -std=c11 -O3 -include rte_config.h -Wcast-qual -Wdeprecated -Wformat -Wformat-nonliteral -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wold-style-definition -Wpointer-arith -
Wsign-compare -Wstrict-prototypes -Wundef -Wwrite-strings -Wno-address-of-packed-member -Wno-missing-field-initializers -D_GNU_SOURCE -fPIC -march=native -mrtm -DALLOW_EXPERIMENTAL_API -DALLOW_INTERNAL_API -DVHOST_CLANG_UNROLL_PRAGMA -fno-strict-aliasing -DRTE_LOG_DEFAULT_LOGTYPE=lib.vhost -DRTE_ANNOTATE_LOCKS -Wthread-safety -MD -MQ lib/librte_vhost.a.p/vhost_vhost_crypto.c.o -MF lib/librte_vhost.a.p/vhost_vhost_crypto.c.o.d -o lib/librte_vhost.a.p/vhost_vhost_crypto.c.o -c ../lib/vhost/vhost_crypto.c
../lib/vhost/vhost_crypto.c:1426:24: error: calling function 'get_data_ptr' requires holding mutex 'vc_req->vq->iotlb_lock' [-Werror,-Wthread-safety-analysis]
1426 | rsa->message.data = get_data_ptr(vc_req, desc, VHOST_ACCESS_RO);
| ^
../lib/vhost/vhost_crypto.c:1437:21: error: calling function 'get_data_ptr' requires holding mutex 'vc_req->vq->iotlb_lock' [-Werror,-Wthread-safety-analysis]
1437 | rsa->sign.data = get_data_ptr(vc_req, desc, VHOST_ACCESS_RW);
| ^
../lib/vhost/vhost_crypto.c:1446:21: error: calling function 'get_data_ptr' requires holding mutex 'vc_req->vq->iotlb_lock' [-Werror,-Wthread-safety-analysis]
1446 | rsa->sign.data = get_data_ptr(vc_req, desc, VHOST_ACCESS_RO);
| ^
../lib/vhost/vhost_crypto.c:1449:24: error: calling function 'get_data_ptr' requires holding mutex 'vc_req->vq->iotlb_lock' [-Werror,-Wthread-safety-analysis]
1449 | rsa->message.data = get_data_ptr(vc_req, desc, VHOST_ACCESS_RO);
| ^
../lib/vhost/vhost_crypto.c:1454:24: error: calling function 'get_data_ptr' requires holding mutex 'vc_req->vq->iotlb_lock' [-Werror,-Wthread-safety-analysis]
1454 | rsa->message.data = get_data_ptr(vc_req, desc, VHOST_ACCESS_RO);
| ^
../lib/vhost/vhost_crypto.c:1465:23: error: calling function 'get_data_ptr' requires holding mutex 'vc_req->vq->iotlb_lock' [-Werror,-Wthread-safety-analysis]
1465 | rsa->cipher.data = get_data_ptr(vc_req, desc, VHOST_ACCESS_RW);
| ^
../lib/vhost/vhost_crypto.c:1474:23: error: calling function 'get_data_ptr' requires holding mutex 'vc_req->vq->iotlb_lock' [-Werror,-Wthread-safety-analysis]
1474 | rsa->cipher.data = get_data_ptr(vc_req, desc, VHOST_ACCESS_RO);
| ^
../lib/vhost/vhost_crypto.c:1477:24: error: calling function 'get_data_ptr' requires holding mutex 'vc_req->vq->iotlb_lock' [-Werror,-Wthread-safety-analysis]
1477 | rsa->message.data = get_data_ptr(vc_req, desc, VHOST_ACCESS_RO);
| ^
../lib/vhost/vhost_crypto.c:1493:18: error: calling function 'get_data_ptr' requires holding mutex 'vc_req->vq->iotlb_lock' [-Werror,-Wthread-safety-analysis]
1493 | vc_req->inhdr = get_data_ptr(vc_req, desc, VHOST_ACCESS_WO);
| ^
9 errors generated.
[419/3000] Generating symbol file lib/librte_mldev.so.25.0.p/librte_mldev.so.25.0.symbols
[420/3000] Compiling C object lib/librte_vhost.a.p/vhost_virtio_net_ctrl.c.o
[421/3000] Compiling C object lib/librte_vhost.a.p/vhost_vhost_user.c.o
[422/3000] Compiling C object lib/librte_vhost.a.p/vhost_vhost.c.o
[423/3000] Compiling C object lib/librte_ipsec.a.p/ipsec_esp_outb.c.o
[424/3000] Compiling C object lib/librte_ipsec.a.p/ipsec_ses.c.o
[425/3000] Compiling C object lib/librte_ipsec.a.p/ipsec_sa.c.o
[426/3000] Compiling C object lib/librte_ipsec.a.p/ipsec_esp_inb.c.o
[427/3000] Compiling C object lib/librte_vhost.a.p/vhost_virtio_net.c.o
ninja: build stopped

#8 lore raw

v2 cover cryptodev: fix RSA xform to support VirtIO standard

In reply to Gowrishankar Muthukrishnan

In this series of patches, RSA crypto xform is fixed to support VirtIO standard.

Changes:
v2:
- Decoupled spec related patches into this series from v1.

Gowrishankar Muthukrishnan (2):
cryptodev: fix RSA xform for ASN.1 syntax
cryptodev: move RSA padding information into xform

 app/test/test_cryptodev_asym.c               | 10 ++--
 app/test/test_cryptodev_rsa_test_vectors.h   |  2 +
 drivers/common/cpt/cpt_ucode_asym.h          |  4 +-
 drivers/crypto/cnxk/cnxk_ae.h                | 13 +++--
 drivers/crypto/octeontx/otx_cryptodev_ops.c  |  4 +-
 drivers/crypto/openssl/openssl_pmd_private.h |  1 +
 drivers/crypto/openssl/rte_openssl_pmd.c     |  4 +-
 drivers/crypto/openssl/rte_openssl_pmd_ops.c |  1 +
 drivers/crypto/qat/qat_asym.c                | 17 ++++---
 examples/fips_validation/main.c              | 52 +++++++++++---------
 lib/cryptodev/rte_crypto_asym.h              |  8 +--
 11 files changed, 63 insertions(+), 53 deletions(-)
Signature · 1 line
2.21.0
#9 lore raw

PATCH v2 1/2 cryptodev: fix RSA xform for ASN.1 syntax

As per ASN.1 syntax (RFC 3447 Appendix A.1.2), RSA private key would need specification of quintuple along with private exponent. It is up to the implementation to internally handle, but not at RTE itself to make them exclusive each other. Removing union on them allows asymmetric implementation in VirtIO to benefit from the xform as per ASN.1 syntax.

---
 lib/cryptodev/rte_crypto_asym.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/cryptodev/rte_crypto_asym.h +1 -1
index 39d3da3952..c33be3b155 100644
@@ -306,7 +306,7 @@ struct rte_crypto_rsa_xform {
 
 	enum rte_crypto_rsa_priv_key_type key_type;
 
-	union {
+	struct {
 		rte_crypto_uint d;
 		/**< the RSA private exponent */
 		struct rte_crypto_rsa_priv_key_qt qt;
Signature · 1 line
2.21.0
Acked-by on v2 1/2
#10 lore raw

RE: [PATCH v2 1/2] cryptodev: fix RSA xform for ASN.1 syntax

Acked with a small comment.

Quoted 22 lines

-----Original Message-----
From: Gowrishankar Muthukrishnan <[email protected]>
Sent: Friday, October 4, 2024 8:11 AM
To: [email protected]; Akhil Goyal <[email protected]>; Fan Zhang <[email protected]>
Cc: Anoob Joseph <[email protected]>; Richardson, Bruce <[email protected]>; [email protected]; Kusztal, ArkadiuszX <[email protected]>; Ji, Kai <[email protected]>; jack.bond- [email protected]; Marchand, David <[email protected]>; [email protected]; De Lara Guarch, Pablo <[email protected]>; Trahe, Fiona <[email protected]>; Doherty, Declan <[email protected]>; [email protected]; [email protected]; Gujjar, Abhinandan S <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Daly, Lee <[email protected]>; Dooley, Brian <[email protected]>; Gowrishankar Muthukrishnan <[email protected]>
Subject: [PATCH v2 1/2] cryptodev: fix RSA xform for ASN.1 syntax

Quoted 1 line

As per ASN.1 syntax (RFC 3447 Appendix A.1.2), RSA private key would need

It could be RFC 8017 instead.

Quoted 24 lines

specification of quintuple along with private exponent.
It is up to the implementation to internally handle, but not at RTE itself to make them exclusive each other. Removing union on them allows asymmetric implementation in VirtIO to benefit from the xform as per ASN.1 syntax.

---
 lib/cryptodev/rte_crypto_asym.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/cryptodev/rte_crypto_asym.h +1 -2
index 39d3da3952..c33be3b155 100644
@@ -306,7 +306,7 @@ struct rte_crypto_rsa_xform {
 
 	enum rte_crypto_rsa_priv_key_type key_type;
 
-	union {
+	struct {
 		rte_crypto_uint d;
 		/**< the RSA private exponent */
 		struct rte_crypto_rsa_priv_key_qt qt;
--
Quoted 1 line

2.21.0

#11 lore raw

RE: [PATCH v2 1/2] cryptodev: fix RSA xform for ASN.1 syntax

Quoted 23 lines

-----Original Message-----
From: Kusztal, ArkadiuszX <[email protected]>
Sent: Monday, October 7, 2024 9:20 AM
To: Gowrishankar Muthukrishnan <[email protected]>; [email protected]; Akhil Goyal <[email protected]>; Fan Zhang <[email protected]>
Cc: Anoob Joseph <[email protected]>; Richardson, Bruce <[email protected]>; [email protected]; Ji, Kai <[email protected]>; [email protected]; Marchand, David <[email protected]>; [email protected]; De Lara Guarch, Pablo <[email protected]>; Trahe, Fiona <[email protected]>; Doherty, Declan <[email protected]>; [email protected]; [email protected]; Gujjar, Abhinandan S <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Daly, Lee <[email protected]>; Dooley, Brian <[email protected]>
Subject: RE: [PATCH v2 1/2] cryptodev: fix RSA xform for ASN.1 syntax

Quoted 24 lines

Acked with a small comment.

Quoted 22 lines

-----Original Message-----
From: Gowrishankar Muthukrishnan <[email protected]>
Sent: Friday, October 4, 2024 8:11 AM
To: [email protected]; Akhil Goyal <[email protected]>; Fan Zhang <[email protected]>
Cc: Anoob Joseph <[email protected]>; Richardson, Bruce <[email protected]>; [email protected]; Kusztal, ArkadiuszX <[email protected]>; Ji, Kai <[email protected]>; jack.bond- [email protected]; Marchand, David <[email protected]>; [email protected]; De Lara Guarch, Pablo <[email protected]>; Trahe, Fiona <[email protected]>; Doherty, Declan <[email protected]>; [email protected]; [email protected]; Gujjar, Abhinandan S <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Daly, Lee <[email protected]>; Dooley, Brian <[email protected]>; Gowrishankar Muthukrishnan <[email protected]>
Subject: [PATCH v2 1/2] cryptodev: fix RSA xform for ASN.1 syntax

Additionally, it should not be a fix.
The RFC mandates usage of the ASN.1, but only in case sharing private key across the network. How the Cryptodev should interpret it, is up to the implementation.

Quoted 32 lines
Quoted 3 lines

As per ASN.1 syntax (RFC 3447 Appendix A.1.2), RSA private key would need

It could be RFC 8017 instead.

Quoted 4 lines

specification of quintuple along with private exponent.
It is up to the implementation to internally handle, but not at RTE itself to make them exclusive each other. Removing union on them allows asymmetric implementation in VirtIO to benefit from the xform as per

ASN.1 syntax.

Quoted 20 lines
---
 lib/cryptodev/rte_crypto_asym.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
(quoted diff) +0 -0

b/lib/cryptodev/rte_crypto_asym.h index 39d3da3952..c33be3b155 100644

lib/cryptodev/rte_crypto_asym.h +1 -2
@@ -306,7 +306,7 @@ struct rte_crypto_rsa_xform {
 
 	enum rte_crypto_rsa_priv_key_type key_type;
 
-	union {
+	struct {
 		rte_crypto_uint d;
 		/**< the RSA private exponent */
 		struct rte_crypto_rsa_priv_key_qt qt;
--
Quoted 1 line

2.21.0

#12 lore raw

PATCH v2 2/2 cryptodev: move RSA padding information into xform

In reply to Gowrishankar Muthukrishnan

RSA padding information could be a xform entity rather than part of crypto op, as it seems associated with hashing algorithm used for the entire crypto session, where this algorithm is used in message digest itself. Even in virtIO standard spec, this info is associated in the asymmetric session creation. Hence, moving this info from crypto op into xform structure.

---
 app/test/test_cryptodev_asym.c               | 10 ++--
 app/test/test_cryptodev_rsa_test_vectors.h   |  2 +
 drivers/common/cpt/cpt_ucode_asym.h          |  4 +-
 drivers/crypto/cnxk/cnxk_ae.h                | 13 +++--
 drivers/crypto/octeontx/otx_cryptodev_ops.c  |  4 +-
 drivers/crypto/openssl/openssl_pmd_private.h |  1 +
 drivers/crypto/openssl/rte_openssl_pmd.c     |  4 +-
 drivers/crypto/openssl/rte_openssl_pmd_ops.c |  1 +
 drivers/crypto/qat/qat_asym.c                | 17 ++++---
 examples/fips_validation/main.c              | 52 +++++++++++---------
 lib/cryptodev/rte_crypto_asym.h              |  6 +--
 11 files changed, 62 insertions(+), 52 deletions(-)
app/test/test_cryptodev_asym.c +4 -6
index f0b5d38543..6cb416ffe3 100644
@@ -80,7 +80,6 @@ queue_ops_rsa_sign_verify(void *sess)
 	asym_op->rsa.message.length = rsaplaintext.len;
 	asym_op->rsa.sign.length = RTE_DIM(rsa_n);
 	asym_op->rsa.sign.data = output_buf;
-	asym_op->rsa.padding.type = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
 
 	debug_hexdump(stdout, "message", asym_op->rsa.message.data,
 		      asym_op->rsa.message.length);
@@ -112,7 +111,6 @@ queue_ops_rsa_sign_verify(void *sess)
 
 	/* Verify sign */
 	asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
-	asym_op->rsa.padding.type = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
 
 	/* Process crypto operation */
 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
@@ -171,7 +169,6 @@ queue_ops_rsa_enc_dec(void *sess)
 	asym_op->rsa.cipher.data = cipher_buf;
 	asym_op->rsa.cipher.length = RTE_DIM(rsa_n);
 	asym_op->rsa.message.length = rsaplaintext.len;
-	asym_op->rsa.padding.type = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
 
 	debug_hexdump(stdout, "message", asym_op->rsa.message.data,
 		      asym_op->rsa.message.length);
@@ -203,7 +200,6 @@ queue_ops_rsa_enc_dec(void *sess)
 	asym_op = result_op->asym;
 	asym_op->rsa.message.length = RTE_DIM(rsa_n);
 	asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
-	asym_op->rsa.padding.type = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
 
 	/* Process crypto operation */
 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
@@ -3323,7 +3319,6 @@ rsa_encrypt(const struct rsa_test_data_2 *vector, uint8_t *cipher_buf)
 	self->op->asym->rsa.cipher.data = cipher_buf;
 	self->op->asym->rsa.cipher.length = 0;
 	SET_RSA_PARAM(self->op->asym->rsa, vector, message);
-	self->op->asym->rsa.padding.type = vector->padding;
 
 	rte_crypto_op_attach_asym_session(self->op, self->sess);
 	TEST_ASSERT_SUCCESS(send_one(),
@@ -3347,7 +3342,6 @@ rsa_decrypt(const struct rsa_test_data_2 *vector, uint8_t *plaintext,
 	self->op->asym->rsa.message.data = plaintext;
 	self->op->asym->rsa.message.length = 0;
 	self->op->asym->rsa.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
-	self->op->asym->rsa.padding.type = vector->padding;
 	rte_crypto_op_attach_asym_session(self->op, self->sess);
 	TEST_ASSERT_SUCCESS(send_one(),
 		"Failed to process crypto op (Decryption)");
@@ -3389,6 +3383,7 @@ kat_rsa_encrypt(const void *data)
 	SET_RSA_PARAM(xform.rsa, vector, n);
 	SET_RSA_PARAM(xform.rsa, vector, e);
 	SET_RSA_PARAM(xform.rsa, vector, d);
+	xform.rsa.padding.type = vector->padding;
 	xform.rsa.key_type = RTE_RSA_KEY_TYPE_EXP;
 	int ret = rsa_init_session(&xform);
 
@@ -3419,6 +3414,7 @@ kat_rsa_encrypt_crt(const void *data)
 	SET_RSA_PARAM_QT(xform.rsa, vector, dP);
 	SET_RSA_PARAM_QT(xform.rsa, vector, dQ);
 	SET_RSA_PARAM_QT(xform.rsa, vector, qInv);
+	xform.rsa.padding.type = vector->padding;
 	xform.rsa.key_type = RTE_RSA_KEY_TYPE_QT;
 	int ret = rsa_init_session(&xform);
 	if (ret) {
@@ -3444,6 +3440,7 @@ kat_rsa_decrypt(const void *data)
 	SET_RSA_PARAM(xform.rsa, vector, n);
 	SET_RSA_PARAM(xform.rsa, vector, e);
 	SET_RSA_PARAM(xform.rsa, vector, d);
+	xform.rsa.padding.type = vector->padding;
 	xform.rsa.key_type = RTE_RSA_KEY_TYPE_EXP;
 	int ret = rsa_init_session(&xform);
 
@@ -3474,6 +3471,7 @@ kat_rsa_decrypt_crt(const void *data)
 	SET_RSA_PARAM_QT(xform.rsa, vector, dP);
 	SET_RSA_PARAM_QT(xform.rsa, vector, dQ);
 	SET_RSA_PARAM_QT(xform.rsa, vector, qInv);
+	xform.rsa.padding.type = vector->padding;
 	xform.rsa.key_type = RTE_RSA_KEY_TYPE_QT;
 	int ret = rsa_init_session(&xform);
 	if (ret) {
app/test/test_cryptodev_rsa_test_vectors.h +2 -0
index 89981f13f0..1b7b451387 100644
@@ -345,6 +345,7 @@ struct rte_crypto_asym_xform rsa_xform = {
 	.next = NULL,
 	.xform_type = RTE_CRYPTO_ASYM_XFORM_RSA,
 	.rsa = {
+		.padding.type = RTE_CRYPTO_RSA_PADDING_PKCS1_5,
 		.n = {
 			.data = rsa_n,
 			.length = sizeof(rsa_n)
@@ -366,6 +367,7 @@ struct rte_crypto_asym_xform rsa_xform_crt = {
 	.next = NULL,
 	.xform_type = RTE_CRYPTO_ASYM_XFORM_RSA,
 	.rsa = {
+		.padding.type = RTE_CRYPTO_RSA_PADDING_PKCS1_5,
 		.n = {
 			.data = rsa_n,
 			.length = sizeof(rsa_n)
drivers/common/cpt/cpt_ucode_asym.h +2 -2
index e1034bbeb4..5122378ec7 100644
@@ -327,7 +327,7 @@ cpt_rsa_prep(struct asym_op_params *rsa_params,
 	/* Result buffer */
 	rlen = mod_len;
 
-	if (rsa_op.padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
+	if (rsa->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
 		/* Use mod_exp operation for no_padding type */
 		vq_cmd_w0.s.opcode.minor = CPT_MINOR_OP_MODEX;
 		vq_cmd_w0.s.param2 = exp_len;
@@ -412,7 +412,7 @@ cpt_rsa_crt_prep(struct asym_op_params *rsa_params,
 	/* Result buffer */
 	rlen = mod_len;
 
-	if (rsa_op.padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
+	if (rsa->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
 		/*Use mod_exp operation for no_padding type */
 		vq_cmd_w0.s.opcode.minor = CPT_MINOR_OP_MODEX_CRT;
 	} else {
drivers/crypto/cnxk/cnxk_ae.h +8 -5
index ef9cb5eb91..1bb5a450c5 100644
@@ -177,6 +177,9 @@ cnxk_ae_fill_rsa_params(struct cnxk_ae_sess *sess,
 	rsa->n.length = mod_len;
 	rsa->e.length = exp_len;
 
+	/* Set padding info */
+	rsa->padding.type = xform->rsa.padding.type;
+
 	return 0;
 }
 
@@ -366,7 +369,7 @@ cnxk_ae_rsa_prep(struct rte_crypto_op *op, struct roc_ae_buf_ptr *meta_buf,
 	dptr += in_size;
 	dlen = total_key_len + in_size;
 
-	if (rsa_op.padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
+	if (rsa->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
 		/* Use mod_exp operation for no_padding type */
 		w4.s.opcode_minor = ROC_AE_MINOR_OP_MODEX;
 		w4.s.param2 = exp_len;
@@ -421,7 +424,7 @@ cnxk_ae_rsa_exp_prep(struct rte_crypto_op *op, struct roc_ae_buf_ptr *meta_buf,
 	dptr += in_size;
 	dlen = mod_len + privkey_len + in_size;
 
-	if (rsa_op.padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
+	if (rsa->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
 		/* Use mod_exp operation for no_padding type */
 		w4.s.opcode_minor = ROC_AE_MINOR_OP_MODEX;
 		w4.s.param2 = privkey_len;
@@ -479,7 +482,7 @@ cnxk_ae_rsa_crt_prep(struct rte_crypto_op *op, struct roc_ae_buf_ptr *meta_buf,
 	dptr += in_size;
 	dlen = total_key_len + in_size;
 
-	if (rsa_op.padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
+	if (rsa->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
 		/*Use mod_exp operation for no_padding type */
 		w4.s.opcode_minor = ROC_AE_MINOR_OP_MODEX_CRT;
 	} else {
@@ -1151,7 +1154,7 @@ cnxk_ae_dequeue_rsa_op(struct rte_crypto_op *cop, uint8_t *rptr,
 		memcpy(rsa->cipher.data, rptr, rsa->cipher.length);
 		break;
 	case RTE_CRYPTO_ASYM_OP_DECRYPT:
-		if (rsa->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
+		if (rsa_ctx->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
 			rsa->message.length = rsa_ctx->n.length;
 			memcpy(rsa->message.data, rptr, rsa->message.length);
 		} else {
@@ -1171,7 +1174,7 @@ cnxk_ae_dequeue_rsa_op(struct rte_crypto_op *cop, uint8_t *rptr,
 		memcpy(rsa->sign.data, rptr, rsa->sign.length);
 		break;
 	case RTE_CRYPTO_ASYM_OP_VERIFY:
-		if (rsa->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
+		if (rsa_ctx->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
 			rsa->sign.length = rsa_ctx->n.length;
 			memcpy(rsa->sign.data, rptr, rsa->sign.length);
 		} else {
drivers/crypto/octeontx/otx_cryptodev_ops.c +2 -2
index bafd0c1669..9a758cd297 100644
@@ -708,7 +708,7 @@ otx_cpt_asym_rsa_op(struct rte_crypto_op *cop, struct cpt_request_info *req,
 		memcpy(rsa->cipher.data, req->rptr, rsa->cipher.length);
 		break;
 	case RTE_CRYPTO_ASYM_OP_DECRYPT:
-		if (rsa->padding.type == RTE_CRYPTO_RSA_PADDING_NONE)
+		if (rsa_ctx->padding.type == RTE_CRYPTO_RSA_PADDING_NONE)
 			rsa->message.length = rsa_ctx->n.length;
 		else {
 			/* Get length of decrypted output */
@@ -725,7 +725,7 @@ otx_cpt_asym_rsa_op(struct rte_crypto_op *cop, struct cpt_request_info *req,
 		memcpy(rsa->sign.data, req->rptr, rsa->sign.length);
 		break;
 	case RTE_CRYPTO_ASYM_OP_VERIFY:
-		if (rsa->padding.type == RTE_CRYPTO_RSA_PADDING_NONE)
+		if (rsa_ctx->padding.type == RTE_CRYPTO_RSA_PADDING_NONE)
 			rsa->sign.length = rsa_ctx->n.length;
 		else {
 			/* Get length of decrypted output */
drivers/crypto/openssl/openssl_pmd_private.h +1 -0
index 0282b3d829..27551a7999 100644
@@ -197,6 +197,7 @@ struct __rte_cache_aligned openssl_asym_session {
 	union {
 		struct rsa {
 			RSA *rsa;
+			uint32_t pad;
 #if (OPENSSL_VERSION_NUMBER >= 0x30000000L)
 			EVP_PKEY_CTX * ctx;
 #endif
drivers/crypto/openssl/rte_openssl_pmd.c +2 -2
index e10a172f46..3db90a768d 100644
@@ -2699,7 +2699,7 @@ process_openssl_rsa_op_evp(struct rte_crypto_op *cop,
 		struct openssl_asym_session *sess)
 {
 	struct rte_crypto_asym_op *op = cop->asym;
-	uint32_t pad = (op->rsa.padding.type);
+	uint32_t pad = sess->u.r.pad;
 	uint8_t *tmp;
 	size_t outlen = 0;
 	int ret = -1;
@@ -3082,7 +3082,7 @@ 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.padding.type);
+	uint32_t pad = sess->u.r.pad;
 	uint8_t *tmp;
 
 	cop->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
drivers/crypto/openssl/rte_openssl_pmd_ops.c +1 -0
index b7b612fc57..0fc125d2a3 100644
@@ -889,6 +889,7 @@ static int openssl_set_asym_session_parameters(
 		if (!n || !e)
 			goto err_rsa;
 
+		asym_session->u.r.pad = xform->rsa.padding.type;
 #if (OPENSSL_VERSION_NUMBER >= 0x30000000L)
 		OSSL_PARAM_BLD * param_bld = OSSL_PARAM_BLD_new();
 		if (!param_bld) {
drivers/crypto/qat/qat_asym.c +9 -8
index e43884e69b..9e97582e22 100644
@@ -362,7 +362,7 @@ rsa_set_pub_input(struct icp_qat_fw_pke_request *qat_req,
 	alg_bytesize = qat_function.bytesize;
 
 	if (asym_op->rsa.op_type == RTE_CRYPTO_ASYM_OP_ENCRYPT) {
-		switch (asym_op->rsa.padding.type) {
+		switch (xform->rsa.padding.type) {
 		case RTE_CRYPTO_RSA_PADDING_NONE:
 			SET_PKE_LN(asym_op->rsa.message, alg_bytesize, 0);
 			break;
@@ -374,7 +374,7 @@ rsa_set_pub_input(struct icp_qat_fw_pke_request *qat_req,
 		}
 		HEXDUMP("RSA Message", cookie->input_array[0], alg_bytesize);
 	} else {
-		switch (asym_op->rsa.padding.type) {
+		switch (xform->rsa.padding.type) {
 		case RTE_CRYPTO_RSA_PADDING_NONE:
 			SET_PKE_LN(asym_op->rsa.sign, alg_bytesize, 0);
 			break;
@@ -460,7 +460,7 @@ rsa_set_priv_input(struct icp_qat_fw_pke_request *qat_req,
 
 	if (asym_op->rsa.op_type ==
 			RTE_CRYPTO_ASYM_OP_DECRYPT) {
-		switch (asym_op->rsa.padding.type) {
+		switch (xform->rsa.padding.type) {
 		case RTE_CRYPTO_RSA_PADDING_NONE:
 			SET_PKE_LN(asym_op->rsa.cipher,	alg_bytesize, 0);
 			HEXDUMP("RSA ciphertext", cookie->input_array[0],
@@ -474,7 +474,7 @@ rsa_set_priv_input(struct icp_qat_fw_pke_request *qat_req,
 
 	} else if (asym_op->rsa.op_type ==
 			RTE_CRYPTO_ASYM_OP_SIGN) {
-		switch (asym_op->rsa.padding.type) {
+		switch (xform->rsa.padding.type) {
 		case RTE_CRYPTO_RSA_PADDING_NONE:
 			SET_PKE_LN(asym_op->rsa.message, alg_bytesize, 0);
 			HEXDUMP("RSA text to be signed", cookie->input_array[0],
@@ -514,7 +514,8 @@ rsa_set_input(struct icp_qat_fw_pke_request *qat_req,
 
 static uint8_t
 rsa_collect(struct rte_crypto_asym_op *asym_op,
-		const struct qat_asym_op_cookie *cookie)
+		const struct qat_asym_op_cookie *cookie,
+		const struct rte_crypto_asym_xform *xform)
 {
 	uint32_t alg_bytesize = cookie->alg_bytesize;
 
@@ -530,7 +531,7 @@ rsa_collect(struct rte_crypto_asym_op *asym_op,
 			HEXDUMP("RSA Encrypted data", cookie->output_array[0],
 				alg_bytesize);
 		} else {
-			switch (asym_op->rsa.padding.type) {
+			switch (xform->rsa.padding.type) {
 			case RTE_CRYPTO_RSA_PADDING_NONE:
 				rte_memcpy(asym_op->rsa.cipher.data,
 						cookie->output_array[0],
@@ -547,7 +548,7 @@ rsa_collect(struct rte_crypto_asym_op *asym_op,
 		}
 	} else {
 		if (asym_op->rsa.op_type == RTE_CRYPTO_ASYM_OP_DECRYPT) {
-			switch (asym_op->rsa.padding.type) {
+			switch (xform->rsa.padding.type) {
 			case RTE_CRYPTO_RSA_PADDING_NONE:
 				rte_memcpy(asym_op->rsa.message.data,
 					cookie->output_array[0],
@@ -1105,7 +1106,7 @@ qat_asym_collect_response(struct rte_crypto_op *op,
 	case RTE_CRYPTO_ASYM_XFORM_MODINV:
 		return modinv_collect(asym_op, cookie, xform);
 	case RTE_CRYPTO_ASYM_XFORM_RSA:
-		return rsa_collect(asym_op, cookie);
+		return rsa_collect(asym_op, cookie, xform);
 	case RTE_CRYPTO_ASYM_XFORM_ECDSA:
 		return ecdsa_collect(asym_op, cookie);
 	case RTE_CRYPTO_ASYM_XFORM_ECPM:
examples/fips_validation/main.c +28 -24

65 lines not on this page · raw message

lib/cryptodev/rte_crypto_asym.h +3 -3
index c33be3b155..398b6514e3 100644
@@ -312,6 +312,9 @@ struct rte_crypto_rsa_xform {
 		struct rte_crypto_rsa_priv_key_qt qt;
 		/**< qt - Private key in quintuple format */
 	};
+
+	struct rte_crypto_rsa_padding padding;
+	/**< RSA padding information */
 };
 
 /**
@@ -447,9 +450,6 @@ struct rte_crypto_rsa_op_param {
 	 * This could be validated and overwritten by the PMD
 	 * with the signature length.
 	 */
-
-	struct rte_crypto_rsa_padding padding;
-	/**< RSA padding information */
 };
 
 /**
Signature · 1 line
2.21.0
#13 lore raw

RE: [PATCH v2 2/2] cryptodev: move RSA padding information into xform

Hi Arek
Any objections on this patch?

Quoted 10 lines

Subject: [PATCH v2 2/2] cryptodev: move RSA padding information into xform

RSA padding information could be a xform entity rather than part of crypto op, as it seems associated with hashing algorithm used for the entire crypto session, where this algorithm is used in message digest itself. Even in virtIO standard spec, this info is associated in the asymmetric session creation. Hence, moving this info from crypto op into xform structure.

#14 lore raw

RE: [PATCH v2 2/2] cryptodev: move RSA padding information into xform

Quoted 37 lines

-----Original Message-----
From: Akhil Goyal <[email protected]>
Sent: Wednesday, October 9, 2024 5:23 PM
To: Gowrishankar Muthukrishnan <[email protected]>; [email protected]; Kusztal, ArkadiuszX <[email protected]>; Fan Zhang <[email protected]>; Anoob Joseph <[email protected]>; Ankur Dwivedi <[email protected]>; Tejasree Kondoj <[email protected]>; Ji, Kai <[email protected]>; Dooley, Brian <[email protected]>
Cc: Richardson, Bruce <[email protected]>; Jerin Jacob <[email protected]>; [email protected]; Marchand, David <[email protected]>; [email protected]; De Lara Guarch, Pablo <[email protected]>; Trahe, Fiona <[email protected]>; Doherty, Declan <[email protected]>; [email protected]; [email protected]; Gujjar, Abhinandan S <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Daly, Lee <[email protected]>
Subject: RE: [PATCH v2 2/2] cryptodev: move RSA padding information into xform

Hi Arek
Any objections on this patch?

Quoted 11 lines

Subject: [PATCH v2 2/2] cryptodev: move RSA padding information into xform

RSA padding information could be a xform entity rather than part of crypto op, as it seems associated with hashing algorithm used for the entire crypto session, where this algorithm is used in message digest itself. Even in virtIO standard spec, this info is associated in the asymmetric session creation. Hence, moving this info from crypto op into xform structure.