Skip to contentSkip to conversation

add ECPM support

PATCH Superseded Anoob Joseph 2 participants 14 messages Dec 5, 2019 – Jan 15, 2020 Crypto API

lore
Share & tools
lore
#0 lore raw

cover add ECPM support

This series adds support for ECPM (Elliptic Curve Point Multiplication) asymmetric operations. Library changes and PMD changes for crypto_octeontx & crypto_octeontx2 is added. The final patch adds the required test vectors and verification routines.

Balakrishna Bhamidipati (1):
lib/crypto: add support for EC Point Multiplication

Sunila Sahu (3):
crypto/octeontx: add EC Point Mul support
crypto/octeontx2: add EC Point Mul support
app/test: add EC point multiplication test

 app/test/test_cryptodev_asym.c                     | 177 +++++++++++
 app/test/test_cryptodev_asym_util.h                |  11 +
 app/test/test_cryptodev_ecpm_test_vectors.h        | 353 +++++++++++++++++++++
 doc/guides/cryptodevs/features/default.ini         |   1 +
 doc/guides/cryptodevs/features/octeontx.ini        |   1 +
 doc/guides/cryptodevs/features/octeontx2.ini       |   1 +
 drivers/common/cpt/cpt_mcode_defines.h             |   2 +
 drivers/common/cpt/cpt_ucode_asym.h                |  85 +++++
 .../crypto/octeontx/otx_cryptodev_capabilities.c   |  11 +
 drivers/crypto/octeontx/otx_cryptodev_ops.c        |  23 ++
 .../crypto/octeontx2/otx2_cryptodev_capabilities.c |  11 +
 drivers/crypto/octeontx2/otx2_cryptodev_ops.c      |  22 ++
 lib/librte_cryptodev/rte_crypto_asym.h             |  17 +
 lib/librte_cryptodev/rte_cryptodev.c               |   1 +
 14 files changed, 716 insertions(+)
 create mode 100644 app/test/test_cryptodev_ecpm_test_vectors.h
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/4 lib/crypto: add support for EC Point Multiplication

From: Balakrishna Bhamidipati <[email protected]>

Elliptic Curve Point Multiplication xform type and op parameters are added.

---
 doc/guides/cryptodevs/features/default.ini |  1 +
 lib/librte_cryptodev/rte_crypto_asym.h     | 17 +++++++++++++++++
 lib/librte_cryptodev/rte_cryptodev.c       |  1 +
 3 files changed, 19 insertions(+)
doc/guides/cryptodevs/features/default.ini +1 -0
index 2f6c785..3a54b07 100644
@@ -109,3 +109,4 @@ Modular Exponentiation  =
 Modular Inversion       =
 Diffie-hellman          =
 ECDSA                   =
+EC Point Multiplication =
lib/librte_cryptodev/rte_crypto_asym.h +17 -0
index dd5e6e3..b98ce6c 100644
@@ -85,6 +85,8 @@ enum rte_crypto_asym_xform_type {
 	/**< Elliptic Curve Digital Signature Algorithm
 	 * Perform Signature Generation and Verification.
 	 */
+	RTE_CRYPTO_ASYM_XFORM_EC_POINT_MUL,
+	/**< Elliptic Curve Point Multiplication */
 	RTE_CRYPTO_ASYM_XFORM_TYPE_LIST_END
 	/**< End of list */
 };
@@ -598,6 +600,20 @@ struct rte_crypto_ecdsa_op_param {
 };
 
 /**
+ * Structure for EC point operation param
+ */
+struct rte_crypto_ec_point_mul_param {
+	struct rte_crypto_ec_point p;
+	/**< x and y coordinates of input point */
+
+	struct rte_crypto_ec_point r;
+	/**< x and y coordinates of resultant point */
+
+	rte_crypto_param scalar;
+	/**< Scalar to multiply the input point */
+};
+
+/**
  * Asymmetric Cryptographic Operation.
  *
  * Structure describing asymmetric crypto operation params.
@@ -620,6 +636,7 @@ struct rte_crypto_asym_op {
 		struct rte_crypto_dh_op_param dh;
 		struct rte_crypto_dsa_op_param dsa;
 		struct rte_crypto_ecdsa_op_param ecdsa;
+		struct rte_crypto_ec_point_mul_param ecpm;
 	};
 };
 
lib/librte_cryptodev/rte_cryptodev.c +1 -0
index 0d6babb..eea57c6 100644
@@ -174,6 +174,7 @@ const char *rte_crypto_asym_xform_strings[] = {
 	[RTE_CRYPTO_ASYM_XFORM_DH]	= "dh",
 	[RTE_CRYPTO_ASYM_XFORM_DSA]	= "dsa",
 	[RTE_CRYPTO_ASYM_XFORM_ECDSA]	= "ecdsa",
+	[RTE_CRYPTO_ASYM_XFORM_EC_POINT_MUL]	= "ecpm",
 };
 
 /**
Signature · 1 line
2.7.4
#2 lore raw

Re: [dpdk-dev] [PATCH 1/4] lib/crypto: add support for EC Point Multiplication

Quoted 6 lines

From: Balakrishna Bhamidipati <[email protected]>

Elliptic Curve Point Multiplication xform type and op parameters are added.

Description should convey that it is an asymmetric crypto feature.

Quoted 4 lines

Title should be cryptodev: support ECPM

Quoted 12 lines
---
 doc/guides/cryptodevs/features/default.ini |  1 +
 lib/librte_cryptodev/rte_crypto_asym.h     | 17 +++++++++++++++++
 lib/librte_cryptodev/rte_cryptodev.c       |  1 +
 3 files changed, 19 insertions(+)
doc/guides/cryptodevs/features/default.ini +0 -0
index 2f6c785..3a54b07 100644

doc/guides/cryptodevs/features/default.ini Modular Exponentiation = · line 112

Quoted 4 lines
doc/guides/cryptodevs/features/default.ini +1 -0
@@ -109,3 +109,4 @@ Modular Exponentiation  =
 Modular Inversion       =
 Diffie-hellman          =
 ECDSA                   =
+EC Point Multiplication =

I think it is better to have ECPM instead of EC Point Multiplication as it is the case with ECDSA.

lib/librte_cryptodev/rte_crypto_asym.h enum rte_crypto_asym_xform_type { · line 88

Quoted 10 lines
lib/librte_cryptodev/rte_crypto_asym.h +1 -0
index dd5e6e3..b98ce6c 100644
@@ -85,6 +85,8 @@ enum rte_crypto_asym_xform_type {
 	/**< Elliptic Curve Digital Signature Algorithm
 	 * Perform Signature Generation and Verification.
 	 */
+	RTE_CRYPTO_ASYM_XFORM_EC_POINT_MUL,

Should be RTE_CRYPTO_ASYM_XFORM_ECPM

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_ecdsa_op_param { · line 605

Quoted 11 lines
lib/librte_cryptodev/rte_crypto_asym.h +4 -0
+	/**< Elliptic Curve Point Multiplication */
 	RTE_CRYPTO_ASYM_XFORM_TYPE_LIST_END
 	/**< End of list */
 };
@@ -598,6 +600,20 @@ struct rte_crypto_ecdsa_op_param {
 };
 
 /**
+ * Structure for EC point operation param
+ */
+struct rte_crypto_ec_point_mul_param {

Better to have rte_crypto_ecpm_param

Quoted 37 lines
lib/librte_cryptodev/rte_crypto_asym.h +12 -0
+	struct rte_crypto_ec_point p;
+	/**< x and y coordinates of input point */
+
+	struct rte_crypto_ec_point r;
+	/**< x and y coordinates of resultant point */
+
+	rte_crypto_param scalar;
+	/**< Scalar to multiply the input point */
+};
+
+/**
  * Asymmetric Cryptographic Operation.
  *
  * Structure describing asymmetric crypto operation params.
@@ -620,6 +636,7 @@ struct rte_crypto_asym_op {
 		struct rte_crypto_dh_op_param dh;
 		struct rte_crypto_dsa_op_param dsa;
 		struct rte_crypto_ecdsa_op_param ecdsa;
+		struct rte_crypto_ec_point_mul_param ecpm;
 	};
 };
 
lib/librte_cryptodev/rte_cryptodev.c +1 -1
index 0d6babb..eea57c6 100644
@@ -174,6 +174,7 @@ const char *rte_crypto_asym_xform_strings[] = {
 	[RTE_CRYPTO_ASYM_XFORM_DH]	= "dh",
 	[RTE_CRYPTO_ASYM_XFORM_DSA]	= "dsa",
 	[RTE_CRYPTO_ASYM_XFORM_ECDSA]	= "ecdsa",
+	[RTE_CRYPTO_ASYM_XFORM_EC_POINT_MUL]	= "ecpm",
 };
 
 /**
--

2.7.4

#3 lore raw

Re: [dpdk-dev] [PATCH 1/4] lib/crypto: add support for EC Point Multiplication

Hi Akhil,

Please see inline.

Thanks,
Anoob

Quoted 20 lines

-----Original Message-----
From: Akhil Goyal <[email protected]>
Sent: Monday, January 13, 2020 6:14 PM
To: Anoob Joseph <[email protected]>; Declan Doherty <[email protected]>; Pablo de Lara <[email protected]>
Cc: Balakrishna Bhamidipati <[email protected]>; Fiona Trahe <[email protected]>; Arek Kusztal <[email protected]>; Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; Shally Verma <[email protected]>; Ankur Dwivedi <[email protected]>; Sunila Sahu <[email protected]>; [email protected]
Subject: [EXT] RE: [PATCH 1/4] lib/crypto: add support for EC Point Multiplication

External Email

----------------------------------------------------------------------

Quoted 1 line
Quoted 6 lines
Quoted 4 lines

From: Balakrishna Bhamidipati <[email protected]>

Elliptic Curve Point Multiplication xform type and op parameters are added.

Description should convey that it is an asymmetric crypto feature.

[Anoob] Will update in v2.

Quoted 7 lines
Quoted 5 lines

Title should be cryptodev: support ECPM

[Anoob] Will update in v2.

Quoted 7 lines
Quoted 7 lines
---
 doc/guides/cryptodevs/features/default.ini |  1 +
 lib/librte_cryptodev/rte_crypto_asym.h     | 17 +++++++++++++++++
 lib/librte_cryptodev/rte_cryptodev.c       |  1 +
 3 files changed, 19 insertions(+)
Quoted 13 lines

doc/guides/cryptodevs/features/default.ini Modular Exponentiation = · line 112

Quoted 10 lines
doc/guides/cryptodevs/features/default.ini +1 -0
index 2f6c785..3a54b07 100644
@@ -109,3 +109,4 @@ Modular Exponentiation  =
 Modular Inversion       =
 Diffie-hellman          =
 ECDSA                   =
+EC Point Multiplication =

I think it is better to have ECPM instead of EC Point Multiplication as it is the case with ECDSA.

[Anoob] Agreed. Will update in v2.

Quoted 20 lines

lib/librte_cryptodev/rte_crypto_asym.h enum rte_crypto_asym_xform_type { · line 88

Quoted 12 lines
lib/librte_cryptodev/rte_crypto_asym.h +1 -0
index dd5e6e3..b98ce6c 100644
@@ -85,6 +85,8 @@ enum rte_crypto_asym_xform_type {
 	/**< Elliptic Curve Digital Signature Algorithm
 	 * Perform Signature Generation and Verification.
 	 */
+	RTE_CRYPTO_ASYM_XFORM_EC_POINT_MUL,

Should be RTE_CRYPTO_ASYM_XFORM_ECPM

Quoted 6 lines
lib/librte_cryptodev/rte_crypto_asym.h +1 -0
+	/**< Elliptic Curve Point Multiplication */
 	RTE_CRYPTO_ASYM_XFORM_TYPE_LIST_END
 	/**< End of list */
 };
@@ -598,6 +600,20 @@ struct rte_crypto_ecdsa_op_param {  };
 
Quoted 5 lines

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_ecdsa_op_param { }; · line 603

Quoted 3 lines
lib/librte_cryptodev/rte_crypto_asym.h +2 -0
 /**
+ * Structure for EC point operation param  */ struct
+rte_crypto_ec_point_mul_param {

Better to have rte_crypto_ecpm_param

[Anoob] Agreed. Will update in v2.

Quoted 37 lines
Quoted 37 lines
lib/librte_cryptodev/rte_crypto_asym.h +11 -0
+	struct rte_crypto_ec_point p;
+	/**< x and y coordinates of input point */
+
+	struct rte_crypto_ec_point r;
+	/**< x and y coordinates of resultant point */
+
+	rte_crypto_param scalar;
+	/**< Scalar to multiply the input point */ };
+
+/**
  * Asymmetric Cryptographic Operation.
  *
  * Structure describing asymmetric crypto operation params.
@@ -620,6 +636,7 @@ struct rte_crypto_asym_op {
 		struct rte_crypto_dh_op_param dh;
 		struct rte_crypto_dsa_op_param dsa;
 		struct rte_crypto_ecdsa_op_param ecdsa;
+		struct rte_crypto_ec_point_mul_param ecpm;
 	};
 };
 
lib/librte_cryptodev/rte_cryptodev.c +1 -1
index 0d6babb..eea57c6 100644
@@ -174,6 +174,7 @@ const char *rte_crypto_asym_xform_strings[] = {
 	[RTE_CRYPTO_ASYM_XFORM_DH]	= "dh",
 	[RTE_CRYPTO_ASYM_XFORM_DSA]	= "dsa",
 	[RTE_CRYPTO_ASYM_XFORM_ECDSA]	= "ecdsa",
+	[RTE_CRYPTO_ASYM_XFORM_EC_POINT_MUL]	= "ecpm",
 };
 
 /**
--

2.7.4

#4 lore raw

PATCH 2/4 crypto/octeontx: add EC Point Mul support

In reply to Anoob Joseph

From: Sunila Sahu <[email protected]>

Adding support for EC Point Multiplication operation in crypto_octeontx PMD.

---
 doc/guides/cryptodevs/features/octeontx.ini        |  1 +
 drivers/common/cpt/cpt_mcode_defines.h             |  2 +
 drivers/common/cpt/cpt_ucode_asym.h                | 85 ++++++++++++++++++++++
 .../crypto/octeontx/otx_cryptodev_capabilities.c   | 11 +++
 drivers/crypto/octeontx/otx_cryptodev_ops.c        | 23 ++++++
 5 files changed, 122 insertions(+)
doc/guides/cryptodevs/features/octeontx.ini +1 -0
index 544bb46..3cc807a 100644
@@ -73,3 +73,4 @@ Modular Exponentiation  = Y
 Modular Inversion       =
 Diffie-hellman          =
 ECDSA                   = Y
+EC Point Multiplication = Y
drivers/common/cpt/cpt_mcode_defines.h +2 -0
index 64d3e8c..d830bef 100644
@@ -24,6 +24,7 @@
 /* AE opcodes */
 #define CPT_MAJOR_OP_MODEX	0x03
 #define CPT_MAJOR_OP_ECDSA	0x04
+#define CPT_MAJOR_OP_ECC	0x05
 #define CPT_MINOR_OP_MODEX	0x01
 #define CPT_MINOR_OP_PKCS_ENC	0x02
 #define CPT_MINOR_OP_PKCS_ENC_CRT	0x03
@@ -32,6 +33,7 @@
 #define CPT_MINOR_OP_MODEX_CRT	0x06
 #define CPT_MINOR_OP_ECDSA_SIGN	0x01
 #define CPT_MINOR_OP_ECDSA_VERIFY	0x02
+#define CPT_MINOR_OP_ECC_UMP	0x03
 
 #define CPT_BLOCK_TYPE1 0
 #define CPT_BLOCK_TYPE2 1
drivers/common/cpt/cpt_ucode_asym.h +85 -0

101 lines not on this page · raw message

drivers/crypto/octeontx/otx_cryptodev_capabilities.c +11 -0
index 6418ad2..22f34ad 100644
@@ -641,6 +641,17 @@ static const struct rte_cryptodev_capabilities otx_asym_capabilities[] = {
 			},
 		}
 	},
+	{	/* EC POINT MUL */
+		.op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
+		{.asym = {
+			.xform_capa = {
+				.xform_type =
+					RTE_CRYPTO_ASYM_XFORM_EC_POINT_MUL,
+				.op_types = 0
+				}
+			},
+		}
+	},
 	/* End of asymmetric capabilities */
 	RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
 };
drivers/crypto/octeontx/otx_cryptodev_ops.c +23 -0
index f97ce3a..e7520d5 100644
@@ -443,6 +443,13 @@ otx_cpt_enq_single_asym(struct cpt_instance *instance,
 		if (unlikely(ret))
 			goto req_fail;
 		break;
+	case RTE_CRYPTO_ASYM_XFORM_EC_POINT_MUL:
+		ret = cpt_ecpm_prep(&asym_op->ecpm, &params,
+				    sess->ec_ctx.curveid);
+		if (unlikely(ret))
+			goto req_fail;
+		break;
+
 	default:
 		op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
 		ret = -EINVAL;
@@ -704,6 +711,19 @@ otx_cpt_asym_dequeue_ecdsa_op(struct rte_crypto_ecdsa_op_param *ecdsa,
 	ecdsa->s.length = prime_len;
 }
 
+static __rte_always_inline void
+otx_cpt_asym_dequeue_ecpm_op(struct rte_crypto_ec_point_mul_param *ecpm,
+			     struct cpt_request_info *req,
+			     struct cpt_asym_ec_ctx *ec)
+{
+	int prime_len = ec_grp[ec->curveid].prime.length;
+
+	memcpy(ecpm->r.x.data, req->rptr, prime_len);
+	memcpy(ecpm->r.y.data, req->rptr + ROUNDUP8(prime_len), prime_len);
+	ecpm->r.x.length = prime_len;
+	ecpm->r.y.length = prime_len;
+}
+
 static __rte_always_inline void __hot
 otx_cpt_asym_post_process(struct rte_crypto_op *cop,
 			  struct cpt_request_info *req)
@@ -726,6 +746,9 @@ otx_cpt_asym_post_process(struct rte_crypto_op *cop,
 	case RTE_CRYPTO_ASYM_XFORM_ECDSA:
 		otx_cpt_asym_dequeue_ecdsa_op(&op->ecdsa, req, &sess->ec_ctx);
 		break;
+	case RTE_CRYPTO_ASYM_XFORM_EC_POINT_MUL:
+		otx_cpt_asym_dequeue_ecpm_op(&op->ecpm, req, &sess->ec_ctx);
+		break;
 	default:
 		CPT_LOG_DP_DEBUG("Invalid crypto xform type");
 		cop->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
Signature · 1 line
2.7.4
#5 lore raw

PATCH 3/4 crypto/octeontx2: add EC Point Mul support

In reply to Anoob Joseph

From: Sunila Sahu <[email protected]>

Adding support for EC Point MUltiplication operation in crypto_octeontx2 PMD.

---
 doc/guides/cryptodevs/features/octeontx2.ini       |  1 +
 .../crypto/octeontx2/otx2_cryptodev_capabilities.c | 11 +++++++++++
 drivers/crypto/octeontx2/otx2_cryptodev_ops.c      | 22 ++++++++++++++++++++++
 3 files changed, 34 insertions(+)
doc/guides/cryptodevs/features/octeontx2.ini +1 -0
index dd6369b..f1625c4 100644
@@ -73,3 +73,4 @@ Modular Exponentiation  = Y
 Modular Inversion       =
 Diffie-hellman          =
 ECDSA                   = Y
+EC Point Multiplication = Y
drivers/crypto/octeontx2/otx2_cryptodev_capabilities.c +11 -0
index f2079e2..d1c9c80 100644
@@ -639,6 +639,17 @@ rte_cryptodev_capabilities otx2_cpt_capabilities[] = {
 			},
 		}
 	},
+	{	/* EC POINT MUL */
+		.op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
+		{.asym = {
+			.xform_capa = {
+				.xform_type =
+					RTE_CRYPTO_ASYM_XFORM_EC_POINT_MUL,
+				.op_types = 0
+				}
+			},
+		}
+	},
 	/* End of asymmetric capabilities */
 	RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
 };
drivers/crypto/octeontx2/otx2_cryptodev_ops.c +22 -0
index 17c755d..574873a 100644
@@ -447,6 +447,12 @@ otx2_cpt_enqueue_asym(struct otx2_cpt_qp *qp,
 		if (unlikely(ret))
 			goto req_fail;
 		break;
+	case RTE_CRYPTO_ASYM_XFORM_EC_POINT_MUL:
+		ret = cpt_ecpm_prep(&asym_op->ecpm, &params,
+				    sess->ec_ctx.curveid);
+		if (unlikely(ret))
+			goto req_fail;
+		break;
 	default:
 		op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
 		ret = -EINVAL;
@@ -665,6 +671,19 @@ otx2_cpt_asym_dequeue_ecdsa_op(struct rte_crypto_ecdsa_op_param *ecdsa,
 	ecdsa->s.length = prime_len;
 }
 
+static __rte_always_inline void
+otx2_cpt_asym_dequeue_ecpm_op(struct rte_crypto_ec_point_mul_param *ecpm,
+			     struct cpt_request_info *req,
+			     struct cpt_asym_ec_ctx *ec)
+{
+	int prime_len = ec_grp[ec->curveid].prime.length;
+
+	memcpy(ecpm->r.x.data, req->rptr, prime_len);
+	memcpy(ecpm->r.y.data, req->rptr + ROUNDUP8(prime_len), prime_len);
+	ecpm->r.x.length = prime_len;
+	ecpm->r.y.length = prime_len;
+}
+
 static void
 otx2_cpt_asym_post_process(struct rte_crypto_op *cop,
 			   struct cpt_request_info *req)
@@ -687,6 +706,9 @@ otx2_cpt_asym_post_process(struct rte_crypto_op *cop,
 	case RTE_CRYPTO_ASYM_XFORM_ECDSA:
 		otx2_cpt_asym_dequeue_ecdsa_op(&op->ecdsa, req, &sess->ec_ctx);
 		break;
+	case RTE_CRYPTO_ASYM_XFORM_EC_POINT_MUL:
+		otx2_cpt_asym_dequeue_ecpm_op(&op->ecpm, req, &sess->ec_ctx);
+		break;
 	default:
 		CPT_LOG_DP_DEBUG("Invalid crypto xform type");
 		cop->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
Signature · 1 line
2.7.4
#6 lore raw

PATCH 4/4 app/test: add EC point multiplication test

In reply to Anoob Joseph

From: Sunila Sahu <[email protected]>

Adding EC point multiplication test vectors and verify routines.

---
 app/test/test_cryptodev_asym.c              | 177 ++++++++++++++
 app/test/test_cryptodev_asym_util.h         |  11 +
 app/test/test_cryptodev_ecpm_test_vectors.h | 353 ++++++++++++++++++++++++++++
 3 files changed, 541 insertions(+)
 create mode 100644 app/test/test_cryptodev_ecpm_test_vectors.h
app/test/test_cryptodev_asym.c +177 -0
index b913a7d..b6d96d6 100644
@@ -19,6 +19,7 @@
 #include "test_cryptodev_dh_test_vectors.h"
 #include "test_cryptodev_dsa_test_vectors.h"
 #include "test_cryptodev_ecdsa_test_vectors.h"
+#include "test_cryptodev_ecpm_test_vectors.h"
 #include "test_cryptodev_mod_test_vectors.h"
 #include "test_cryptodev_rsa_test_vectors.h"
 #include "test_cryptodev_asym_util.h"
@@ -1044,6 +1045,7 @@ static inline void print_asym_capa(
 					capa->modlen.increment);
 		break;
 		case RTE_CRYPTO_ASYM_XFORM_ECDSA:
+		case RTE_CRYPTO_ASYM_XFORM_EC_POINT_MUL:
 		default:
 			break;
 		}
@@ -2108,6 +2110,179 @@ test_ecdsa_sign_verify_all_curve(void)
 	return overall_status;
 }
 
+static int
+test_ec_point_mul(enum curve curve_id)
+{
+	struct crypto_testsuite_params *ts_params = &testsuite_params;
+	struct rte_mempool *sess_mpool = ts_params->session_mpool;
+	struct rte_mempool *op_mpool = ts_params->op_mpool;
+	struct crypto_testsuite_ecpm_params input_params;
+	struct rte_cryptodev_asym_session *sess = NULL;
+	uint8_t dev_id = ts_params->valid_devs[0];
+	struct rte_crypto_op *result_op = NULL;
+	uint8_t output_buf_x[TEST_DATA_SIZE];
+	uint8_t output_buf_y[TEST_DATA_SIZE];
+	struct rte_crypto_asym_xform xform;
+	struct rte_crypto_asym_op *asym_op;
+	struct rte_cryptodev_info dev_info;
+	struct rte_crypto_op *op = NULL;
+	int status = TEST_SUCCESS, ret;
+
+	switch (curve_id) {
+	case P192:
+		input_params = ecpm_param_p192;
+		break;
+	case P224:
+		input_params = ecpm_param_p224;
+		break;
+	case P256:
+		input_params = ecpm_param_p256;
+		break;
+	case P384:
+		input_params = ecpm_param_p384;
+		break;
+	case P521:
+		input_params = ecpm_param_p521;
+		break;
+	default:
+		RTE_LOG(ERR, USER1,
+				"line %u FAILED: %s", __LINE__,
+				"Unsupported curve id\n");
+		status = TEST_FAILED;
+		goto exit;
+	}
+
+	rte_cryptodev_info_get(dev_id, &dev_info);
+
+	sess = rte_cryptodev_asym_session_create(sess_mpool);
+	if (sess == NULL) {
+		RTE_LOG(ERR, USER1,
+				"line %u FAILED: %s", __LINE__,
+				"Session creation failed\n");
+		status = TEST_FAILED;
+		goto exit;
+	}
+
+	/* Setup crypto op data structure */
+	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
+	if (op == NULL) {
+		RTE_LOG(ERR, USER1,
+				"line %u FAILED: %s", __LINE__,
+				"Failed to allocate asymmetric crypto "
+				"operation struct\n");
+		status = TEST_FAILED;
+		goto exit;
+	}
+	asym_op = op->asym;
+
+	/* Setup asym xform */
+	xform.next = NULL;
+	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_EC_POINT_MUL;
+	xform.ec.curve_id = input_params.curve;
+
+	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
+				sess_mpool) < 0) {
+		RTE_LOG(ERR, USER1,
+				"line %u FAILED: %s", __LINE__,
+				"Unable to config asym session\n");
+		status = TEST_FAILED;
+		goto exit;
+	}
+
+	/* Attach asymmetric crypto session to crypto operations */
+	rte_crypto_op_attach_asym_session(op, sess);
+
+	/* Populate op with operational details */
+	op->asym->ecpm.p.x.data = input_params.gen_x.data;
+	op->asym->ecpm.p.x.length = input_params.gen_x.length;
+	op->asym->ecpm.p.y.data = input_params.gen_y.data;
+	op->asym->ecpm.p.y.length = input_params.gen_y.length;
+	op->asym->ecpm.scalar.data = input_params.privkey.data;
+	op->asym->ecpm.scalar.length = input_params.privkey.length;
+
+	/* Init out buf */
+	op->asym->ecpm.r.x.data = output_buf_x;
+	op->asym->ecpm.r.y.data = output_buf_y;
+
+	RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
+
+	/* Process crypto operation */
+	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
+		RTE_LOG(ERR, USER1,
+				"line %u FAILED: %s", __LINE__,
+				"Error sending packet for operation\n");
+		status = TEST_FAILED;
+		goto exit;
+	}
+
+	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
+		rte_pause();
+
+	if (result_op == NULL) {
+		RTE_LOG(ERR, USER1,
+				"line %u FAILED: %s", __LINE__,
+				"Failed to process asym crypto op\n");
+		status = TEST_FAILED;
+		goto exit;
+	}
+
+	if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
+		RTE_LOG(ERR, USER1,
+				"line %u FAILED: %s", __LINE__,
+				"Failed to process asym crypto op\n");
+		status = TEST_FAILED;
+		goto exit;
+	}
+
+	asym_op = result_op->asym;
+
+	debug_hexdump(stdout, "r x:",
+			asym_op->ecpm.r.x.data, asym_op->ecpm.r.x.length);
+	debug_hexdump(stdout, "r y:",
+			asym_op->ecpm.r.y.data, asym_op->ecpm.r.y.length);
+
+	ret = verify_ecpm(input_params.pubkey_x.data,
+				input_params.pubkey_y.data, result_op);
+	if (ret) {
+		status = TEST_FAILED;
+		RTE_LOG(ERR, USER1,
+				"line %u FAILED: %s", __LINE__,
+				"EC Point Multiplication failed.\n");
+		goto exit;
+	}
+
+exit:
+	if (sess != NULL) {
+		rte_cryptodev_asym_session_clear(dev_id, sess);
+		rte_cryptodev_asym_session_free(sess);
+	}
+	if (op != NULL)
+		rte_crypto_op_free(op);
+	return status;
+}
+
+static int
+test_ec_point_mul_all_curve(void)
+{
+	int status, overall_status = TEST_SUCCESS;
+	enum curve curve_id;
+	int test_index = 0;
+	const char *msg;
+
+	for (curve_id = P192; curve_id < END_OF_CURVE_LIST; curve_id++) {
+		status = test_ec_point_mul(curve_id);
+		if (status == TEST_SUCCESS) {
+			msg = "succeeded";
+		} else {
+			msg = "failed";
+			overall_status = status;
+		}
+		printf("  %u) TestCase EC Point Mul Curve %s  %s\n",
+		       test_index ++, curve[curve_id], msg);
+	}
+	return overall_status;
+}
+
 static struct unit_test_suite cryptodev_openssl_asym_testsuite  = {
 	.suite_name = "Crypto Device OPENSSL ASYM Unit Test Suite",
 	.setup = testsuite_setup,
@@ -2148,6 +2323,8 @@ static struct unit_test_suite cryptodev_octeontx_asym_testsuite  = {
 		TEST_CASE_ST(ut_setup, ut_teardown, test_mod_exp),
 		TEST_CASE_ST(ut_setup, ut_teardown,
 			     test_ecdsa_sign_verify_all_curve),
+		TEST_CASE_ST(ut_setup, ut_teardown,
+			     test_ec_point_mul_all_curve),
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	}
 };
app/test/test_cryptodev_asym_util.h +11 -0
index bddeda0..83dc265 100644
@@ -46,4 +46,15 @@ static inline int verify_ecdsa_sign(uint8_t *sign_r,
 	return 0;
 }
 
+static inline int verify_ecpm(uint8_t *result_x, uint8_t *result_y,
+			      struct rte_crypto_op *result_op)
+{
+	if (memcmp(result_x, result_op->asym->ecpm.r.x.data,
+		   result_op->asym->ecpm.r.x.length) ||
+		   memcmp(result_y, result_op->asym->ecpm.r.y.data,
+		   result_op->asym->ecpm.r.y.length))
+		return -1;
+
+	return 0;
+}
 #endif /* TEST_CRYPTODEV_ASYM_TEST_UTIL_H__ */
app/test/test_cryptodev_ecpm_test_vectors.h new file +353 -0

353 lines not on this page · raw message

Signature · 1 line
2.7.4
#7 lore raw

v2 cover add ECPM support

In reply to Anoob Joseph

This series adds support for ECPM (Elliptic Curve Point Multiplication) asymmetric operations. Library changes and PMD changes for crypto_octeontx & crypto_octeontx2 is added. The final patch adds the required test vectors and verification routines.

v2:
* Made all references to point multiplication operation as ECPM.
* Changed all NIST references to use SECP.
* Updated release notes

Balakrishna Bhamidipati (1):
cryptodev: support ECPM

Sunila Sahu (3):
crypto/octeontx: add ECPM support
crypto/octeontx2: add ECPM support
app/test: add ECPM tests

 app/test/test_cryptodev_asym.c                     | 176 ++++++++++
 app/test/test_cryptodev_asym_util.h                |  11 +
 app/test/test_cryptodev_ecpm_test_vectors.h        | 353 +++++++++++++++++++++
 doc/guides/cryptodevs/features/default.ini         |   1 +
 doc/guides/cryptodevs/features/octeontx.ini        |   1 +
 doc/guides/cryptodevs/features/octeontx2.ini       |   1 +
 doc/guides/rel_notes/release_20_02.rst             |   5 +
 drivers/common/cpt/cpt_mcode_defines.h             |   2 +
 drivers/common/cpt/cpt_ucode_asym.h                |  85 +++++
 .../crypto/octeontx/otx_cryptodev_capabilities.c   |  10 +
 drivers/crypto/octeontx/otx_cryptodev_ops.c        |  23 ++
 .../crypto/octeontx2/otx2_cryptodev_capabilities.c |  10 +
 drivers/crypto/octeontx2/otx2_cryptodev_ops.c      |  22 ++
 lib/librte_cryptodev/rte_crypto_asym.h             |  17 +
 lib/librte_cryptodev/rte_cryptodev.c               |   1 +
 15 files changed, 718 insertions(+)
 create mode 100644 app/test/test_cryptodev_ecpm_test_vectors.h
Signature · 1 line
2.7.4
#8 lore raw

PATCH v2 1/4 cryptodev: support ECPM

From: Balakrishna Bhamidipati <[email protected]>

Asymmetric crypto library is extended to add ECPM (Elliptic Curve Point Multiplication). The required xform type and op parameters are introduced.

---
 doc/guides/cryptodevs/features/default.ini |  1 +
 doc/guides/rel_notes/release_20_02.rst     |  5 +++++
 lib/librte_cryptodev/rte_crypto_asym.h     | 17 +++++++++++++++++
 lib/librte_cryptodev/rte_cryptodev.c       |  1 +
 4 files changed, 24 insertions(+)
doc/guides/cryptodevs/features/default.ini +1 -0
index 2f6c785..f639a88 100644
@@ -109,3 +109,4 @@ Modular Exponentiation  =
 Modular Inversion       =
 Diffie-hellman          =
 ECDSA                   =
+ECPM                    =
doc/guides/rel_notes/release_20_02.rst +5 -0
index 2e97c60..4baec2b 100644
@@ -61,6 +61,11 @@ New Features
   Added ECDSA(Elliptic Curve Digital Signature Algorithm) support to asymmetric
   crypto library specifications.
 
+* **Added support for ECPM.**
+
+  Added ECPM(Elliptic Curve Point Multiplication) support to asymmetric
+  crypto library specifications.
+
 Removed Items
 -------------
 
lib/librte_cryptodev/rte_crypto_asym.h +17 -0
index e17614e..9c866f5 100644
@@ -92,6 +92,8 @@ enum rte_crypto_asym_xform_type {
 	/**< Elliptic Curve Digital Signature Algorithm
 	 * Perform Signature Generation and Verification.
 	 */
+	RTE_CRYPTO_ASYM_XFORM_ECPM,
+	/**< Elliptic Curve Point Multiplication */
 	RTE_CRYPTO_ASYM_XFORM_TYPE_LIST_END
 	/**< End of list */
 };
@@ -599,6 +601,20 @@ struct rte_crypto_ecdsa_op_param {
 };
 
 /**
+ * Structure for EC point multiplication operation param
+ */
+struct rte_crypto_ecpm_op_param {
+	struct rte_crypto_ec_point p;
+	/**< x and y coordinates of input point */
+
+	struct rte_crypto_ec_point r;
+	/**< x and y coordinates of resultant point */
+
+	rte_crypto_param scalar;
+	/**< Scalar to multiply the input point */
+};
+
+/**
  * Asymmetric Cryptographic Operation.
  *
  * Structure describing asymmetric crypto operation params.
@@ -621,6 +637,7 @@ struct rte_crypto_asym_op {
 		struct rte_crypto_dh_op_param dh;
 		struct rte_crypto_dsa_op_param dsa;
 		struct rte_crypto_ecdsa_op_param ecdsa;
+		struct rte_crypto_ecpm_op_param ecpm;
 	};
 };
 
lib/librte_cryptodev/rte_cryptodev.c +1 -0
index 0d6babb..ab4b231 100644
@@ -174,6 +174,7 @@ const char *rte_crypto_asym_xform_strings[] = {
 	[RTE_CRYPTO_ASYM_XFORM_DH]	= "dh",
 	[RTE_CRYPTO_ASYM_XFORM_DSA]	= "dsa",
 	[RTE_CRYPTO_ASYM_XFORM_ECDSA]	= "ecdsa",
+	[RTE_CRYPTO_ASYM_XFORM_ECPM]	= "ecpm",
 };
 
 /**
Signature · 1 line
2.7.4
Acked-by on v2 1/4
#9 lore raw

Re: [dpdk-dev] [PATCH v2 1/4] cryptodev: support ECPM

Quoted 11 lines

From: Balakrishna Bhamidipati <[email protected]>

Asymmetric crypto library is extended to add ECPM (Elliptic Curve Point Multiplication). The required xform type and op parameters are introduced.

---

#10 lore raw

PATCH v2 2/4 crypto/octeontx: add ECPM support

In reply to Anoob Joseph

From: Sunila Sahu <[email protected]>

Add support for asymmetric opertion EC Point Multiplication, in crypto_octeontx PMD.

---
 doc/guides/cryptodevs/features/octeontx.ini        |  1 +
 drivers/common/cpt/cpt_mcode_defines.h             |  2 +
 drivers/common/cpt/cpt_ucode_asym.h                | 85 ++++++++++++++++++++++
 .../crypto/octeontx/otx_cryptodev_capabilities.c   | 10 +++
 drivers/crypto/octeontx/otx_cryptodev_ops.c        | 23 ++++++
 5 files changed, 121 insertions(+)
doc/guides/cryptodevs/features/octeontx.ini +1 -0
index 544bb46..f0ed3ed 100644
@@ -73,3 +73,4 @@ Modular Exponentiation  = Y
 Modular Inversion       =
 Diffie-hellman          =
 ECDSA                   = Y
+ECPM                    = Y
drivers/common/cpt/cpt_mcode_defines.h +2 -0
index 64d3e8c..d830bef 100644
@@ -24,6 +24,7 @@
 /* AE opcodes */
 #define CPT_MAJOR_OP_MODEX	0x03
 #define CPT_MAJOR_OP_ECDSA	0x04
+#define CPT_MAJOR_OP_ECC	0x05
 #define CPT_MINOR_OP_MODEX	0x01
 #define CPT_MINOR_OP_PKCS_ENC	0x02
 #define CPT_MINOR_OP_PKCS_ENC_CRT	0x03
@@ -32,6 +33,7 @@
 #define CPT_MINOR_OP_MODEX_CRT	0x06
 #define CPT_MINOR_OP_ECDSA_SIGN	0x01
 #define CPT_MINOR_OP_ECDSA_VERIFY	0x02
+#define CPT_MINOR_OP_ECC_UMP	0x03
 
 #define CPT_BLOCK_TYPE1 0
 #define CPT_BLOCK_TYPE2 1
drivers/common/cpt/cpt_ucode_asym.h +85 -0

101 lines not on this page · raw message

drivers/crypto/octeontx/otx_cryptodev_capabilities.c +10 -0
index 6418ad2..1174ee4 100644
@@ -641,6 +641,16 @@ static const struct rte_cryptodev_capabilities otx_asym_capabilities[] = {
 			},
 		}
 	},
+	{	/* ECPM */
+		.op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
+		{.asym = {
+			.xform_capa = {
+				.xform_type = RTE_CRYPTO_ASYM_XFORM_ECPM,
+				.op_types = 0
+				}
+			},
+		}
+	},
 	/* End of asymmetric capabilities */
 	RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
 };
drivers/crypto/octeontx/otx_cryptodev_ops.c +23 -0
index f97ce3a..d7f3d08 100644
@@ -443,6 +443,13 @@ otx_cpt_enq_single_asym(struct cpt_instance *instance,
 		if (unlikely(ret))
 			goto req_fail;
 		break;
+	case RTE_CRYPTO_ASYM_XFORM_ECPM:
+		ret = cpt_ecpm_prep(&asym_op->ecpm, &params,
+				    sess->ec_ctx.curveid);
+		if (unlikely(ret))
+			goto req_fail;
+		break;
+
 	default:
 		op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
 		ret = -EINVAL;
@@ -704,6 +711,19 @@ otx_cpt_asym_dequeue_ecdsa_op(struct rte_crypto_ecdsa_op_param *ecdsa,
 	ecdsa->s.length = prime_len;
 }
 
+static __rte_always_inline void
+otx_cpt_asym_dequeue_ecpm_op(struct rte_crypto_ecpm_op_param *ecpm,
+			     struct cpt_request_info *req,
+			     struct cpt_asym_ec_ctx *ec)
+{
+	int prime_len = ec_grp[ec->curveid].prime.length;
+
+	memcpy(ecpm->r.x.data, req->rptr, prime_len);
+	memcpy(ecpm->r.y.data, req->rptr + ROUNDUP8(prime_len), prime_len);
+	ecpm->r.x.length = prime_len;
+	ecpm->r.y.length = prime_len;
+}
+
 static __rte_always_inline void __hot
 otx_cpt_asym_post_process(struct rte_crypto_op *cop,
 			  struct cpt_request_info *req)
@@ -726,6 +746,9 @@ otx_cpt_asym_post_process(struct rte_crypto_op *cop,
 	case RTE_CRYPTO_ASYM_XFORM_ECDSA:
 		otx_cpt_asym_dequeue_ecdsa_op(&op->ecdsa, req, &sess->ec_ctx);
 		break;
+	case RTE_CRYPTO_ASYM_XFORM_ECPM:
+		otx_cpt_asym_dequeue_ecpm_op(&op->ecpm, req, &sess->ec_ctx);
+		break;
 	default:
 		CPT_LOG_DP_DEBUG("Invalid crypto xform type");
 		cop->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
Signature · 1 line
2.7.4
#11 lore raw

PATCH v2 3/4 crypto/octeontx2: add ECPM support

In reply to Anoob Joseph

From: Sunila Sahu <[email protected]>

Add support asymmetric operation EC Point MUltiplication, in crypto_octeontx2 PMD.

---
 doc/guides/cryptodevs/features/octeontx2.ini       |  1 +
 .../crypto/octeontx2/otx2_cryptodev_capabilities.c | 10 ++++++++++
 drivers/crypto/octeontx2/otx2_cryptodev_ops.c      | 22 ++++++++++++++++++++++
 3 files changed, 33 insertions(+)
doc/guides/cryptodevs/features/octeontx2.ini +1 -0
index dd6369b..4693458 100644
@@ -73,3 +73,4 @@ Modular Exponentiation  = Y
 Modular Inversion       =
 Diffie-hellman          =
 ECDSA                   = Y
+ECPM                    = Y
drivers/crypto/octeontx2/otx2_cryptodev_capabilities.c +10 -0
index f2079e2..83f885c 100644
@@ -639,6 +639,16 @@ rte_cryptodev_capabilities otx2_cpt_capabilities[] = {
 			},
 		}
 	},
+	{	/* ECPM */
+		.op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
+		{.asym = {
+			.xform_capa = {
+				.xform_type = RTE_CRYPTO_ASYM_XFORM_ECPM,
+				.op_types = 0
+				}
+			},
+		}
+	},
 	/* End of asymmetric capabilities */
 	RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
 };
drivers/crypto/octeontx2/otx2_cryptodev_ops.c +22 -0
index 17c755d..ec0e58d 100644
@@ -447,6 +447,12 @@ otx2_cpt_enqueue_asym(struct otx2_cpt_qp *qp,
 		if (unlikely(ret))
 			goto req_fail;
 		break;
+	case RTE_CRYPTO_ASYM_XFORM_ECPM:
+		ret = cpt_ecpm_prep(&asym_op->ecpm, &params,
+				    sess->ec_ctx.curveid);
+		if (unlikely(ret))
+			goto req_fail;
+		break;
 	default:
 		op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
 		ret = -EINVAL;
@@ -665,6 +671,19 @@ otx2_cpt_asym_dequeue_ecdsa_op(struct rte_crypto_ecdsa_op_param *ecdsa,
 	ecdsa->s.length = prime_len;
 }
 
+static __rte_always_inline void
+otx2_cpt_asym_dequeue_ecpm_op(struct rte_crypto_ecpm_op_param *ecpm,
+			     struct cpt_request_info *req,
+			     struct cpt_asym_ec_ctx *ec)
+{
+	int prime_len = ec_grp[ec->curveid].prime.length;
+
+	memcpy(ecpm->r.x.data, req->rptr, prime_len);
+	memcpy(ecpm->r.y.data, req->rptr + ROUNDUP8(prime_len), prime_len);
+	ecpm->r.x.length = prime_len;
+	ecpm->r.y.length = prime_len;
+}
+
 static void
 otx2_cpt_asym_post_process(struct rte_crypto_op *cop,
 			   struct cpt_request_info *req)
@@ -687,6 +706,9 @@ otx2_cpt_asym_post_process(struct rte_crypto_op *cop,
 	case RTE_CRYPTO_ASYM_XFORM_ECDSA:
 		otx2_cpt_asym_dequeue_ecdsa_op(&op->ecdsa, req, &sess->ec_ctx);
 		break;
+	case RTE_CRYPTO_ASYM_XFORM_ECPM:
+		otx2_cpt_asym_dequeue_ecpm_op(&op->ecpm, req, &sess->ec_ctx);
+		break;
 	default:
 		CPT_LOG_DP_DEBUG("Invalid crypto xform type");
 		cop->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
Signature · 1 line
2.7.4
#12 lore raw

PATCH v2 4/4 app/test: add ECPM tests

In reply to Anoob Joseph

From: Sunila Sahu <[email protected]>

Add test vectors and verify routines for asymmetric operation, EC Point Multiplication.

---
 app/test/test_cryptodev_asym.c              | 176 ++++++++++++++
 app/test/test_cryptodev_asym_util.h         |  11 +
 app/test/test_cryptodev_ecpm_test_vectors.h | 353 ++++++++++++++++++++++++++++
 3 files changed, 540 insertions(+)
 create mode 100644 app/test/test_cryptodev_ecpm_test_vectors.h
app/test/test_cryptodev_asym.c +176 -0
index 08479bb..b8e0500 100644
@@ -19,6 +19,7 @@
 #include "test_cryptodev_dh_test_vectors.h"
 #include "test_cryptodev_dsa_test_vectors.h"
 #include "test_cryptodev_ecdsa_test_vectors.h"
+#include "test_cryptodev_ecpm_test_vectors.h"
 #include "test_cryptodev_mod_test_vectors.h"
 #include "test_cryptodev_rsa_test_vectors.h"
 #include "test_cryptodev_asym_util.h"
@@ -1044,6 +1045,7 @@ static inline void print_asym_capa(
 					capa->modlen.increment);
 		break;
 		case RTE_CRYPTO_ASYM_XFORM_ECDSA:
+		case RTE_CRYPTO_ASYM_XFORM_ECPM:
 		default:
 			break;
 		}
@@ -2108,6 +2110,179 @@ test_ecdsa_sign_verify_all_curve(void)
 	return overall_status;
 }
 
+static int
+test_ecpm(enum curve curve_id)
+{
+	struct crypto_testsuite_params *ts_params = &testsuite_params;
+	struct rte_mempool *sess_mpool = ts_params->session_mpool;
+	struct rte_mempool *op_mpool = ts_params->op_mpool;
+	struct crypto_testsuite_ecpm_params input_params;
+	struct rte_cryptodev_asym_session *sess = NULL;
+	uint8_t dev_id = ts_params->valid_devs[0];
+	struct rte_crypto_op *result_op = NULL;
+	uint8_t output_buf_x[TEST_DATA_SIZE];
+	uint8_t output_buf_y[TEST_DATA_SIZE];
+	struct rte_crypto_asym_xform xform;
+	struct rte_crypto_asym_op *asym_op;
+	struct rte_cryptodev_info dev_info;
+	struct rte_crypto_op *op = NULL;
+	int status = TEST_SUCCESS, ret;
+
+	switch (curve_id) {
+	case SECP192R1:
+		input_params = ecpm_param_secp192r1;
+		break;
+	case SECP224R1:
+		input_params = ecpm_param_secp224r1;
+		break;
+	case SECP256R1:
+		input_params = ecpm_param_secp256r1;
+		break;
+	case SECP384R1:
+		input_params = ecpm_param_secp384r1;
+		break;
+	case SECP521R1:
+		input_params = ecpm_param_secp521r1;
+		break;
+	default:
+		RTE_LOG(ERR, USER1,
+				"line %u FAILED: %s", __LINE__,
+				"Unsupported curve id\n");
+		status = TEST_FAILED;
+		goto exit;
+	}
+
+	rte_cryptodev_info_get(dev_id, &dev_info);
+
+	sess = rte_cryptodev_asym_session_create(sess_mpool);
+	if (sess == NULL) {
+		RTE_LOG(ERR, USER1,
+				"line %u FAILED: %s", __LINE__,
+				"Session creation failed\n");
+		status = TEST_FAILED;
+		goto exit;
+	}
+
+	/* Setup crypto op data structure */
+	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
+	if (op == NULL) {
+		RTE_LOG(ERR, USER1,
+				"line %u FAILED: %s", __LINE__,
+				"Failed to allocate asymmetric crypto "
+				"operation struct\n");
+		status = TEST_FAILED;
+		goto exit;
+	}
+	asym_op = op->asym;
+
+	/* Setup asym xform */
+	xform.next = NULL;
+	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECPM;
+	xform.ec.curve_id = input_params.curve;
+
+	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
+				sess_mpool) < 0) {
+		RTE_LOG(ERR, USER1,
+				"line %u FAILED: %s", __LINE__,
+				"Unable to config asym session\n");
+		status = TEST_FAILED;
+		goto exit;
+	}
+
+	/* Attach asymmetric crypto session to crypto operations */
+	rte_crypto_op_attach_asym_session(op, sess);
+
+	/* Populate op with operational details */
+	op->asym->ecpm.p.x.data = input_params.gen_x.data;
+	op->asym->ecpm.p.x.length = input_params.gen_x.length;
+	op->asym->ecpm.p.y.data = input_params.gen_y.data;
+	op->asym->ecpm.p.y.length = input_params.gen_y.length;
+	op->asym->ecpm.scalar.data = input_params.privkey.data;
+	op->asym->ecpm.scalar.length = input_params.privkey.length;
+
+	/* Init out buf */
+	op->asym->ecpm.r.x.data = output_buf_x;
+	op->asym->ecpm.r.y.data = output_buf_y;
+
+	RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
+
+	/* Process crypto operation */
+	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
+		RTE_LOG(ERR, USER1,
+				"line %u FAILED: %s", __LINE__,
+				"Error sending packet for operation\n");
+		status = TEST_FAILED;
+		goto exit;
+	}
+
+	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
+		rte_pause();
+
+	if (result_op == NULL) {
+		RTE_LOG(ERR, USER1,
+				"line %u FAILED: %s", __LINE__,
+				"Failed to process asym crypto op\n");
+		status = TEST_FAILED;
+		goto exit;
+	}
+
+	if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
+		RTE_LOG(ERR, USER1,
+				"line %u FAILED: %s", __LINE__,
+				"Failed to process asym crypto op\n");
+		status = TEST_FAILED;
+		goto exit;
+	}
+
+	asym_op = result_op->asym;
+
+	debug_hexdump(stdout, "r x:",
+			asym_op->ecpm.r.x.data, asym_op->ecpm.r.x.length);
+	debug_hexdump(stdout, "r y:",
+			asym_op->ecpm.r.y.data, asym_op->ecpm.r.y.length);
+
+	ret = verify_ecpm(input_params.pubkey_x.data,
+				input_params.pubkey_y.data, result_op);
+	if (ret) {
+		status = TEST_FAILED;
+		RTE_LOG(ERR, USER1,
+				"line %u FAILED: %s", __LINE__,
+				"EC Point Multiplication failed.\n");
+		goto exit;
+	}
+
+exit:
+	if (sess != NULL) {
+		rte_cryptodev_asym_session_clear(dev_id, sess);
+		rte_cryptodev_asym_session_free(sess);
+	}
+	if (op != NULL)
+		rte_crypto_op_free(op);
+	return status;
+}
+
+static int
+test_ecpm_all_curve(void)
+{
+	int status, overall_status = TEST_SUCCESS;
+	enum curve curve_id;
+	int test_index = 0;
+	const char *msg;
+
+	for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
+		status = test_ecpm(curve_id);
+		if (status == TEST_SUCCESS) {
+			msg = "succeeded";
+		} else {
+			msg = "failed";
+			overall_status = status;
+		}
+		printf("  %u) TestCase EC Point Mul Curve %s  %s\n",
+		       test_index ++, curve[curve_id], msg);
+	}
+	return overall_status;
+}
+
 static struct unit_test_suite cryptodev_openssl_asym_testsuite  = {
 	.suite_name = "Crypto Device OPENSSL ASYM Unit Test Suite",
 	.setup = testsuite_setup,
@@ -2148,6 +2323,7 @@ static struct unit_test_suite cryptodev_octeontx_asym_testsuite  = {
 		TEST_CASE_ST(ut_setup, ut_teardown, test_mod_exp),
 		TEST_CASE_ST(ut_setup, ut_teardown,
 			     test_ecdsa_sign_verify_all_curve),
+		TEST_CASE_ST(ut_setup, ut_teardown, test_ecpm_all_curve),
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	}
 };
app/test/test_cryptodev_asym_util.h +11 -0
index bddeda0..83dc265 100644
@@ -46,4 +46,15 @@ static inline int verify_ecdsa_sign(uint8_t *sign_r,
 	return 0;
 }
 
+static inline int verify_ecpm(uint8_t *result_x, uint8_t *result_y,
+			      struct rte_crypto_op *result_op)
+{
+	if (memcmp(result_x, result_op->asym->ecpm.r.x.data,
+		   result_op->asym->ecpm.r.x.length) ||
+		   memcmp(result_y, result_op->asym->ecpm.r.y.data,
+		   result_op->asym->ecpm.r.y.length))
+		return -1;
+
+	return 0;
+}
 #endif /* TEST_CRYPTODEV_ASYM_TEST_UTIL_H__ */
app/test/test_cryptodev_ecpm_test_vectors.h new file +353 -0

353 lines not on this page · raw message

Signature · 1 line
2.7.4
#13 lore raw
In reply to Anoob Joseph
Quoted 29 lines

This series adds support for ECPM (Elliptic Curve Point Multiplication) asymmetric operations. Library changes and PMD changes for crypto_octeontx & crypto_octeontx2 is added. The final patch adds the required test vectors and verification routines.

v2:
* Made all references to point multiplication operation as ECPM.
* Changed all NIST references to use SECP.
* Updated release notes

Balakrishna Bhamidipati (1):
cryptodev: support ECPM

Sunila Sahu (3):
crypto/octeontx: add ECPM support
crypto/octeontx2: add ECPM support
app/test: add ECPM tests

 app/test/test_cryptodev_asym.c                     | 176 ++++++++++
 app/test/test_cryptodev_asym_util.h                |  11 +
 app/test/test_cryptodev_ecpm_test_vectors.h        | 353
+++++++++++++++++++++
 doc/guides/cryptodevs/features/default.ini         |   1 +
 doc/guides/cryptodevs/features/octeontx.ini        |   1 +
 doc/guides/cryptodevs/features/octeontx2.ini       |   1 +
 doc/guides/rel_notes/release_20_02.rst             |   5 +
 drivers/common/cpt/cpt_mcode_defines.h             |   2 +
 drivers/common/cpt/cpt_ucode_asym.h                |  85 +++++
Quoted 9 lines
 .../crypto/octeontx/otx_cryptodev_capabilities.c   |  10 +
 drivers/crypto/octeontx/otx_cryptodev_ops.c        |  23 ++
 .../crypto/octeontx2/otx2_cryptodev_capabilities.c |  10 +
 drivers/crypto/octeontx2/otx2_cryptodev_ops.c      |  22 ++
 lib/librte_cryptodev/rte_crypto_asym.h             |  17 +
 lib/librte_cryptodev/rte_cryptodev.c               |   1 +
 15 files changed, 718 insertions(+)
 create mode 100644 app/test/test_cryptodev_ecpm_test_vectors.h

Series Applied to dpdk-next-crypto
Thanks,