Skip to contentSkip to conversation

add ECDSA support

PATCH Superseded Anoob Joseph 4 participants 19 messages Dec 5, 2019 – Jan 15, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover add ECDSA support

This series adds support for ECDSA asymmetric operations. Library changes and PMD changes for crypto_octeontx & crypto_octoentx2 is added. The final patch adds the required test vectors and verification routines.

Ayuj Verma (2):
lib/crypto: add support for ECDSA
app/test: add ECDSA sign/verify tests

Sunila Sahu (2):
crypto/octeontx: add ECDSA support
crypto/octeontx2: add ECDSA support

 app/test/test_cryptodev_asym.c                     |  219 +++-
 app/test/test_cryptodev_asym_util.h                |   11 +
 app/test/test_cryptodev_ecdsa_test_vectors.h       |  501 +++++++++
 doc/guides/cryptodevs/features/default.ini         |   11 +-
 doc/guides/cryptodevs/features/octeontx.ini        |    8 +-
 doc/guides/cryptodevs/features/octeontx2.ini       |    8 +-
 drivers/common/cpt/Makefile                        |    1 +
 drivers/common/cpt/cpt_fpm_tables.c                | 1138 ++++++++++++++++++++
 drivers/common/cpt/cpt_mcode_defines.h             |   38 +
 drivers/common/cpt/cpt_pmd_ops_helper.h            |   19 +
 drivers/common/cpt/cpt_ucode_asym.h                |  378 +++++++
 drivers/common/cpt/meson.build                     |    3 +-
 drivers/common/cpt/rte_common_cpt_version.map      |    9 +
 .../crypto/octeontx/otx_cryptodev_capabilities.c   |   11 +
 drivers/crypto/octeontx/otx_cryptodev_ops.c        |   43 +-
 .../crypto/octeontx2/otx2_cryptodev_capabilities.c |   11 +
 drivers/crypto/octeontx2/otx2_cryptodev_ops.c      |   39 +-
 lib/librte_cryptodev/rte_crypto_asym.h             |   83 ++
 lib/librte_cryptodev/rte_cryptodev.c               |    1 +
 19 files changed, 2517 insertions(+), 15 deletions(-)
 create mode 100644 app/test/test_cryptodev_ecdsa_test_vectors.h
 create mode 100644 drivers/common/cpt/cpt_fpm_tables.c
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/4 lib/crypto: add support for ECDSA

From: Ayuj Verma <[email protected]>

Elliptic curve xform and ECDSA op params are added.

---
 doc/guides/cryptodevs/features/default.ini | 11 ++--
 lib/librte_cryptodev/rte_crypto_asym.h     | 83 ++++++++++++++++++++++++++++++
 lib/librte_cryptodev/rte_cryptodev.c       |  1 +
 3 files changed, 90 insertions(+), 5 deletions(-)
doc/guides/cryptodevs/features/default.ini +6 -5
index b7f9a0a..2f6c785 100644
@@ -103,8 +103,9 @@ AES CCM (256) =
 ; Supported Asymmetric algorithms of a default crypto driver.
 ;
 [Asymmetric]
-RSA =
-DSA =
-Modular Exponentiation =
-Modular Inversion =
-Diffie-hellman =
\ No newline at end of file
+RSA                     =
+DSA                     =
+Modular Exponentiation  =
+Modular Inversion       =
+Diffie-hellman          =
+ECDSA                   =
lib/librte_cryptodev/rte_crypto_asym.h +83 -0

113 lines not on this page · raw message

lib/librte_cryptodev/rte_cryptodev.c +1 -0
index 89aa2ed..0d6babb 100644
@@ -173,6 +173,7 @@ const char *rte_crypto_asym_xform_strings[] = {
 	[RTE_CRYPTO_ASYM_XFORM_MODINV]	= "modinv",
 	[RTE_CRYPTO_ASYM_XFORM_DH]	= "dh",
 	[RTE_CRYPTO_ASYM_XFORM_DSA]	= "dsa",
+	[RTE_CRYPTO_ASYM_XFORM_ECDSA]	= "ecdsa",
 };
 
 /**
Signature · 1 line
2.7.4
#2 lore raw

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

Hi Anoob,

Few suggestions inline.

Quoted 40 lines

;
[Asymmetric]

doc/guides/cryptodevs/features/default.ini +6 -5
-RSA =
-DSA =
-Modular Exponentiation =
-Modular Inversion =
-Diffie-hellman =
\ No newline at end of file
+RSA                     =
+DSA                     =
+Modular Exponentiation  =
+Modular Inversion       =
+Diffie-hellman          =
+ECDSA                   =
lib/librte_cryptodev/rte_crypto_asym.h +11 -0
index 0d34ce8..dd5e6e3 100644
@@ -81,6 +81,10 @@ enum rte_crypto_asym_xform_type {
 	/**< Modular Exponentiation
 	 * Perform Modular Exponentiation b^e mod n
 	 */
+	RTE_CRYPTO_ASYM_XFORM_ECDSA,
+	/**< Elliptic Curve Digital Signature Algorithm
+	 * Perform Signature Generation and Verification.
+	 */
 	RTE_CRYPTO_ASYM_XFORM_TYPE_LIST_END
 	/**< End of list */
 };
@@ -319,6 +323,46 @@ struct rte_crypto_dsa_xform {  };
 
 /**
+ * TLS named curves
+ * https://www.iana.org/assignments/tls-parameters/
+ * tls-parameters.xhtml#tls-parameters-8
+ * secp192r1 = 19,
+ * secp224r1 = 21,
+ * secp256r1 = 23,
+ * secp384r1 = 24,

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_xform { }; · line 341

Quoted 10 lines
lib/librte_cryptodev/rte_crypto_asym.h +10 -0
+ * secp521r1 = 25,
+ */
+enum rte_crypto_ec_group {
+	RTE_CRYPTO_EC_GROUP_UNKNOWN  = 0,
+	RTE_CRYPTO_EC_GROUP_NISTP192 = 19,
+	RTE_CRYPTO_EC_GROUP_NISTP224 = 21,
+	RTE_CRYPTO_EC_GROUP_NISTP256 = 23,
+	RTE_CRYPTO_EC_GROUP_NISTP384 = 24,
+	RTE_CRYPTO_EC_GROUP_NISTP521 = 25,
+};

[Arek] Since in comment we use SECG naming maybe enum should follow to avoid confusion?

Quoted 39 lines
lib/librte_cryptodev/rte_crypto_asym.h +28 -0
+
+/**
+ * Structure for elliptic curve point
+ */
+struct rte_crypto_ec_point {
+	rte_crypto_param x;
+	/**< X coordinate */
+	rte_crypto_param y;
+	/**< Y coordinate */
+};
+
+/**
+ * Asymmetric elliptic curve transform data
+ *
+ * Structure describing all EC based xform params
+ *
+ */
+struct rte_crypto_ec_xform {
+	enum rte_crypto_ec_group curve_id;
+	/**< Pre-defined ec groups */
+};
+
+/**
  * Operations params for modular operations:
  * exponentiation and multiplicative inverse
  *
@@ -372,6 +416,11 @@ struct rte_crypto_asym_xform {
 
 		struct rte_crypto_dsa_xform dsa;
 		/**< DSA xform parameters */
+
+		struct rte_crypto_ec_xform ec;
+		/**< EC xform parameters, used by elliptic curve based
+		 * operations.
+		 */
 	};
 };
 

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_op_param { }; · line 574

Quoted 10 lines
lib/librte_cryptodev/rte_crypto_asym.h +8 -0
@@ -516,6 +565,39 @@ struct rte_crypto_dsa_op_param {  };
 
 /**
+ * ECDSA operation params
+ */
+struct rte_crypto_ecdsa_op_param {
+	enum rte_crypto_asym_op_type op_type;
+	/**< Signature generation or verification */
+
+	rte_crypto_param pkey;
+	/**< Private key of the signer for signature generation */

[Arek] - for DSA we have private key in xform, why this inconsistency?

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_op_param { · line 581

Quoted 6 lines
lib/librte_cryptodev/rte_crypto_asym.h +6 -0
+
+	struct rte_crypto_ec_point q;
+	/**< Public key of the signer for verification */
+
+	rte_crypto_param message;
+	/**< Input message to be signed or verified */

[Arek] - This I expect should be message digest instead of message itself?

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_op_param { · line 586

Quoted 5 lines
lib/librte_cryptodev/rte_crypto_asym.h +5 -0
+
+	rte_crypto_param k;
+	/**< The ECDSA per-message secret number, which is an integer
+	 * in the interval (1, n-1)
+	 */

[Arek] - If pmd can generate 'k' internally we could do something like:
'if k.data == NULL => PMD will generate 'k' internally, k.data remains untouched.'
Another option is to provide user with some callback function to generate CSRN which could be useful for RSA PSS, OAEP as well (we already discussed that internally in Intel, I will elaborate on this bit more in different thread).

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_op_param { · line 597

Quoted 11 lines
lib/librte_cryptodev/rte_crypto_asym.h +11 -0
+
+	rte_crypto_param r;
+	/**< r component of elliptic curve signature
+	 *     output : for signature generation
+	 *     input  : for signature verification
+	 */
+	rte_crypto_param s;
+	/**< s component of elliptic curve signature
+	 *     output : for signature generation
+	 *     input  : for signature verification
+	 */

[Arek] - Do we want to add any constraints like 'this field should be big enough to hold...'

Quoted 28 lines
lib/librte_cryptodev/rte_crypto_asym.h +4 -0
+};
+
+/**
  * Asymmetric Cryptographic Operation.
  *
  * Structure describing asymmetric crypto operation params.
@@ -537,6 +619,7 @@ struct rte_crypto_asym_op {
 		struct rte_crypto_mod_op_param modinv;
 		struct rte_crypto_dh_op_param dh;
 		struct rte_crypto_dsa_op_param dsa;
+		struct rte_crypto_ecdsa_op_param ecdsa;
 	};
 };
 
lib/librte_cryptodev/rte_cryptodev.c +1 -1
index 89aa2ed..0d6babb 100644
@@ -173,6 +173,7 @@ const char *rte_crypto_asym_xform_strings[] = {
 	[RTE_CRYPTO_ASYM_XFORM_MODINV]	= "modinv",
 	[RTE_CRYPTO_ASYM_XFORM_DH]	= "dh",
 	[RTE_CRYPTO_ASYM_XFORM_DSA]	= "dsa",
+	[RTE_CRYPTO_ASYM_XFORM_ECDSA]	= "ecdsa",
 };
 
 /**
--
Quoted 1 line

2.7.4

Regards,
Arek

#3 lore raw

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

Hi Arek,

Please see inline.

Thanks,
Anoob

Quoted 74 lines

-----Original Message-----
From: Kusztal, ArkadiuszX <[email protected]>
Sent: Friday, December 20, 2019 9:36 PM
To: Anoob Joseph <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Cc: Ayuj Verma <[email protected]>; Trahe, Fiona <[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 ECDSA

External Email

----------------------------------------------------------------------
Hi Anoob,

Few suggestions inline.

Quoted 31 lines

;
[Asymmetric]

doc/guides/cryptodevs/features/default.ini +6 -5
-RSA =
-DSA =
-Modular Exponentiation =
-Modular Inversion =
-Diffie-hellman =
\ No newline at end of file
+RSA                     =
+DSA                     =
+Modular Exponentiation  =
+Modular Inversion       =
+Diffie-hellman          =
+ECDSA                   =
lib/librte_cryptodev/rte_crypto_asym.h +4 -0
index 0d34ce8..dd5e6e3 100644
@@ -81,6 +81,10 @@ enum rte_crypto_asym_xform_type {
 	/**< Modular Exponentiation
 	 * Perform Modular Exponentiation b^e mod n
 	 */
+	RTE_CRYPTO_ASYM_XFORM_ECDSA,
+	/**< Elliptic Curve Digital Signature Algorithm
+	 * Perform Signature Generation and Verification.
+	 */
 	RTE_CRYPTO_ASYM_XFORM_TYPE_LIST_END
 	/**< End of list */
 };

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_xform { }; · line 327

Quoted 5 lines
lib/librte_cryptodev/rte_crypto_asym.h +3 -0
@@ -319,6 +323,46 @@ struct rte_crypto_dsa_xform {  };
 
 /**
+ * TLS named curves
+ *
+https://urldefense.proofpoint.com/v2/url?u=https-

3A__www.iana.org_ass

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_xform { }; · line 328

Quoted 1 line
lib/librte_cryptodev/rte_crypto_asym.h +1 -0
+ignments_tls-

2Dparameters_&d=DwIFAg&c=nKjWec2b6R0mOyPaz7xtfQ&r=jPfB8r

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_xform { }; · line 329

Quoted 1 line
lib/librte_cryptodev/rte_crypto_asym.h +1 -0
+wwviRSxyLWs2n6B-WYLn1v9SyTMrT5EQqh2TU&m=nYBsHHO1NEdu-

JmNULDH0kx7auwQd

Quoted 1 line

+SbI0VYNVNxmm1w&s=RKZgomFiHpm9Yp8AYEn4FjlPpzbdavkMv5cRUggVid A&e=

Quoted 10 lines

+ * tls-parameters.xhtml#tls-parameters-8
+ * secp192r1 = 19,
+ * secp224r1 = 21,
+ * secp256r1 = 23,
+ * secp384r1 = 24,
+ * secp521r1 = 25,
+ */

lib/librte_cryptodev/rte_crypto_asym.h +3 -0
+enum rte_crypto_ec_group {
+	RTE_CRYPTO_EC_GROUP_UNKNOWN  = 0,
+	RTE_CRYPTO_EC_GROUP_NISTP192 = 19,
Quoted 8 lines

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_xform { · line 342

Quoted 5 lines
lib/librte_cryptodev/rte_crypto_asym.h +5 -0
+	RTE_CRYPTO_EC_GROUP_NISTP224 = 21,
+	RTE_CRYPTO_EC_GROUP_NISTP256 = 23,
+	RTE_CRYPTO_EC_GROUP_NISTP384 = 24,
+	RTE_CRYPTO_EC_GROUP_NISTP521 = 25,
+};

[Arek] Since in comment we use SECG naming maybe enum should follow to avoid confusion?

[Anoob] How about RTE_CRYPTO_EC_GROUP_SECP521R1 and so on?

Quoted 39 lines
Quoted 39 lines
lib/librte_cryptodev/rte_crypto_asym.h +27 -0
+
+/**
+ * Structure for elliptic curve point  */ struct rte_crypto_ec_point
+{
+	rte_crypto_param x;
+	/**< X coordinate */
+	rte_crypto_param y;
+	/**< Y coordinate */
+};
+
+/**
+ * Asymmetric elliptic curve transform data
+ *
+ * Structure describing all EC based xform params
+ *
+ */
+struct rte_crypto_ec_xform {
+	enum rte_crypto_ec_group curve_id;
+	/**< Pre-defined ec groups */
+};
+
+/**
  * Operations params for modular operations:
  * exponentiation and multiplicative inverse
  *
@@ -372,6 +416,11 @@ struct rte_crypto_asym_xform {
 
 		struct rte_crypto_dsa_xform dsa;
 		/**< DSA xform parameters */
+
+		struct rte_crypto_ec_xform ec;
+		/**< EC xform parameters, used by elliptic curve based
+		 * operations.
+		 */
 	};
 };
 
@@ -516,6 +565,39 @@ struct rte_crypto_dsa_op_param {  };
 
Quoted 10 lines

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_op_param { · line 575

Quoted 9 lines
lib/librte_cryptodev/rte_crypto_asym.h +8 -0
 /**
+ * ECDSA operation params
+ */
+struct rte_crypto_ecdsa_op_param {
+	enum rte_crypto_asym_op_type op_type;
+	/**< Signature generation or verification */
+
+	rte_crypto_param pkey;
+	/**< Private key of the signer for signature generation */

[Arek] - for DSA we have private key in xform, why this inconsistency?

[Anoob] Putting key in the session would limit the number of ops we can perform with one session. In regular use cases, the number of ops done with one key is very minimal. But the number of ops using same EC group is more. So if we define the session to one per EC group, then we will have better usage of session. Otherwise, the session need to be created and destroyed every few operations.

Quoted 7 lines

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_op_param { · line 581

Quoted 6 lines
lib/librte_cryptodev/rte_crypto_asym.h +6 -0
+
+	struct rte_crypto_ec_point q;
+	/**< Public key of the signer for verification */
+
+	rte_crypto_param message;
+	/**< Input message to be signed or verified */

[Arek] - This I expect should be message digest instead of message itself?

[Anoob] Yes. Message digest is what is expected. This is following what is done with DSA & RSA. Do you recommend any changes? Variable name or description.

Quoted 8 lines

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_op_param { · line 586

Quoted 5 lines
lib/librte_cryptodev/rte_crypto_asym.h +5 -0
+
+	rte_crypto_param k;
+	/**< The ECDSA per-message secret number, which is an integer
+	 * in the interval (1, n-1)
+	 */

[Arek] - If pmd can generate 'k' internally we could do something like:
'if k.data == NULL => PMD will generate 'k' internally, k.data remains untouched.'

[Anoob] So that will be exposed as a new capability, right? Do you suggest any changes here to accommodate that?

Quoted 3 lines

Another option is to provide user with some callback function to generate CSRN which could be useful for RSA PSS, OAEP as well (we already discussed that internally in Intel, I will elaborate on this bit more in different thread).

[Anoob] Do you intend to keep the generated CSRN hidden in the PMD?

Quoted 14 lines

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_op_param { · line 597

Quoted 12 lines
lib/librte_cryptodev/rte_crypto_asym.h +11 -0
+
+	rte_crypto_param r;
+	/**< r component of elliptic curve signature
+	 *     output : for signature generation
+	 *     input  : for signature verification
+	 */
+	rte_crypto_param s;
+	/**< s component of elliptic curve signature
+	 *     output : for signature generation
+	 *     input  : for signature verification
+	 */

[Arek] - Do we want to add any constraints like 'this field should be big enough to hold...'

[Anoob] For every case where rte_crypto_param is used for 'output', application should make sure the buffers are large enough. Do you think we could document it somewhere common instead of adding per operation?

Quoted 32 lines
Quoted 28 lines
lib/librte_cryptodev/rte_crypto_asym.h +4 -0
+};
+
+/**
  * Asymmetric Cryptographic Operation.
  *
  * Structure describing asymmetric crypto operation params.
@@ -537,6 +619,7 @@ struct rte_crypto_asym_op {
 		struct rte_crypto_mod_op_param modinv;
 		struct rte_crypto_dh_op_param dh;
 		struct rte_crypto_dsa_op_param dsa;
+		struct rte_crypto_ecdsa_op_param ecdsa;
 	};
 };
 
lib/librte_cryptodev/rte_cryptodev.c +1 -1
index 89aa2ed..0d6babb 100644
@@ -173,6 +173,7 @@ const char *rte_crypto_asym_xform_strings[] = {
 	[RTE_CRYPTO_ASYM_XFORM_MODINV]	= "modinv",
 	[RTE_CRYPTO_ASYM_XFORM_DH]	= "dh",
 	[RTE_CRYPTO_ASYM_XFORM_DSA]	= "dsa",
+	[RTE_CRYPTO_ASYM_XFORM_ECDSA]	= "ecdsa",
 };
 
 /**
--
Quoted 1 line

2.7.4

Regards,
Arek

#4 lore raw

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

Hi Anoob,

Quoted 102 lines

-----Original Message-----
From: Anoob Joseph <[email protected]>
Sent: Thursday, January 2, 2020 8:55 AM
To: Kusztal, ArkadiuszX <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Cc: Ayuj Verma <[email protected]>; Trahe, Fiona <[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: RE: [PATCH 1/4] lib/crypto: add support for ECDSA

Hi Arek,

Please see inline.

Thanks,
Anoob

Quoted 58 lines

-----Original Message-----
From: Kusztal, ArkadiuszX <[email protected]>
Sent: Friday, December 20, 2019 9:36 PM
To: Anoob Joseph <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Cc: Ayuj Verma <[email protected]>; Trahe, Fiona <[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 ECDSA

External Email

----------------------------------------------------------------------
Hi Anoob,

Few suggestions inline.

Quoted 31 lines

;
[Asymmetric]

doc/guides/cryptodevs/features/default.ini +6 -5
-RSA =
-DSA =
-Modular Exponentiation =
-Modular Inversion =
-Diffie-hellman =
\ No newline at end of file
+RSA                     =
+DSA                     =
+Modular Exponentiation  =
+Modular Inversion       =
+Diffie-hellman          =
+ECDSA                   =
lib/librte_cryptodev/rte_crypto_asym.h +4 -0
index 0d34ce8..dd5e6e3 100644
@@ -81,6 +81,10 @@ enum rte_crypto_asym_xform_type {
 	/**< Modular Exponentiation
 	 * Perform Modular Exponentiation b^e mod n
 	 */
+	RTE_CRYPTO_ASYM_XFORM_ECDSA,
+	/**< Elliptic Curve Digital Signature Algorithm
+	 * Perform Signature Generation and Verification.
+	 */
 	RTE_CRYPTO_ASYM_XFORM_TYPE_LIST_END
 	/**< End of list */
 };

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_xform { }; · line 327

Quoted 5 lines
lib/librte_cryptodev/rte_crypto_asym.h +3 -0
@@ -319,6 +323,46 @@ struct rte_crypto_dsa_xform {  };
 
 /**
+ * TLS named curves
+ *
+https://urldefense.proofpoint.com/v2/url?u=https-

3A__www.iana.org_ass

Quoted 6 lines

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_xform { }; · line 328

Quoted 1 line
lib/librte_cryptodev/rte_crypto_asym.h +1 -0
+ignments_tls-

2Dparameters_&d=DwIFAg&c=nKjWec2b6R0mOyPaz7xtfQ&r=jPfB8r

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_xform { }; · line 329

Quoted 1 line
lib/librte_cryptodev/rte_crypto_asym.h +1 -0
+wwviRSxyLWs2n6B-WYLn1v9SyTMrT5EQqh2TU&m=nYBsHHO1NEdu-

JmNULDH0kx7auwQd

Quoted 1 line

+SbI0VYNVNxmm1w&s=RKZgomFiHpm9Yp8AYEn4FjlPpzbdavkMv5cRUggVid

Quoted 17 lines

A&e=

Quoted 7 lines

+ * tls-parameters.xhtml#tls-parameters-8
+ * secp192r1 = 19,
+ * secp224r1 = 21,
+ * secp256r1 = 23,
+ * secp384r1 = 24,
+ * secp521r1 = 25,
+ */

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_xform {

Quoted 7 lines
lib/librte_cryptodev/rte_crypto_asym.h +7 -0
+enum rte_crypto_ec_group {
+	RTE_CRYPTO_EC_GROUP_UNKNOWN  = 0,
+	RTE_CRYPTO_EC_GROUP_NISTP192 = 19,
+	RTE_CRYPTO_EC_GROUP_NISTP224 = 21,
+	RTE_CRYPTO_EC_GROUP_NISTP256 = 23,
+	RTE_CRYPTO_EC_GROUP_NISTP384 = 24,
+	RTE_CRYPTO_EC_GROUP_NISTP521 = 25, };

[Arek] Since in comment we use SECG naming maybe enum should follow

Quoted 4 lines

to

Quoted 1 line

avoid confusion?

[Anoob] How about RTE_CRYPTO_EC_GROUP_SECP521R1 and so on?

[Arek] Iam ok with that.

Quoted 51 lines
Quoted 40 lines
Quoted 40 lines
lib/librte_cryptodev/rte_crypto_asym.h +27 -0
+
+/**
+ * Structure for elliptic curve point  */ struct
+rte_crypto_ec_point {
+	rte_crypto_param x;
+	/**< X coordinate */
+	rte_crypto_param y;
+	/**< Y coordinate */
+};
+
+/**
+ * Asymmetric elliptic curve transform data
+ *
+ * Structure describing all EC based xform params
+ *
+ */
+struct rte_crypto_ec_xform {
+	enum rte_crypto_ec_group curve_id;
+	/**< Pre-defined ec groups */
+};
+
+/**
  * Operations params for modular operations:
  * exponentiation and multiplicative inverse
  *
@@ -372,6 +416,11 @@ struct rte_crypto_asym_xform {
 
 		struct rte_crypto_dsa_xform dsa;
 		/**< DSA xform parameters */
+
+		struct rte_crypto_ec_xform ec;
+		/**< EC xform parameters, used by elliptic curve based
+		 * operations.
+		 */
 	};
 };
 
@@ -516,6 +565,39 @@ struct rte_crypto_dsa_op_param {  };
 
Quoted 10 lines

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_op_param { · line 575

Quoted 9 lines
lib/librte_cryptodev/rte_crypto_asym.h +8 -0
 /**
+ * ECDSA operation params
+ */
+struct rte_crypto_ecdsa_op_param {
+	enum rte_crypto_asym_op_type op_type;
+	/**< Signature generation or verification */
+
+	rte_crypto_param pkey;
+	/**< Private key of the signer for signature generation */

[Arek] - for DSA we have private key in xform, why this inconsistency?

Quoted 6 lines

[Anoob] Putting key in the session would limit the number of ops we can perform with one session. In regular use cases, the number of ops done with one key is very minimal. But the number of ops using same EC group is more. So if we define the session to one per EC group, then we will have better usage of session. Otherwise, the session need to be created and destroyed every few operations.

[Arek] I agree with that, so maybe we could change DSA similar way (leave only group params?)

Quoted 9 lines
Quoted 8 lines

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_op_param { · line 581

Quoted 7 lines
lib/librte_cryptodev/rte_crypto_asym.h +6 -0
+
+	struct rte_crypto_ec_point q;
+	/**< Public key of the signer for verification */
+
+	rte_crypto_param message;
+	/**< Input message to be signed or verified */

[Arek] - This I expect should be message digest instead of message itself?

Quoted 3 lines

[Anoob] Yes. Message digest is what is expected. This is following what is done with DSA & RSA. Do you recommend any changes? Variable name or description.

[Arek] Some information would be good I think.

Quoted 10 lines
Quoted 9 lines

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_op_param { · line 586

Quoted 6 lines
lib/librte_cryptodev/rte_crypto_asym.h +5 -0
+
+	rte_crypto_param k;
+	/**< The ECDSA per-message secret number, which is an integer
+	 * in the interval (1, n-1)
+	 */

[Arek] - If pmd can generate 'k' internally we could do something like:
'if k.data == NULL => PMD will generate 'k' internally, k.data remains untouched.'

Quoted 2 lines

[Anoob] So that will be exposed as a new capability, right? Do you suggest any changes here to accommodate that?

[Arek] Or maybe feature flag, it would apply to DSA as well.

Quoted 7 lines
Quoted 4 lines

Another option is to provide user with some callback function to generate CSRN which could be useful for RSA PSS, OAEP as well (we already discussed that internally in Intel, I will elaborate on this bit more in

different thread).

[Anoob] Do you intend to keep the generated CSRN hidden in the PMD?

[Arek] Openssl PMD does that with DSA but iam not a fan of that. But if some hw can do DSA/ECDSA by generating 'k' by itself it would have to be added anyway. Other option is to add aforementioned callbacks (for HW that not generate 'k' by itself)

Quoted 16 lines
Quoted 15 lines

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_op_param { · line 597

Quoted 13 lines
lib/librte_cryptodev/rte_crypto_asym.h +11 -0
+
+	rte_crypto_param r;
+	/**< r component of elliptic curve signature
+	 *     output : for signature generation
+	 *     input  : for signature verification
+	 */
+	rte_crypto_param s;
+	/**< s component of elliptic curve signature
+	 *     output : for signature generation
+	 *     input  : for signature verification
+	 */

[Arek] - Do we want to add any constraints like 'this field should be big enough to hold...'

Quoted 3 lines

[Anoob] For every case where rte_crypto_param is used for 'output', application should make sure the buffers are large enough. Do you think we could document it somewhere common instead of adding per operation?

[Arek]
Both options look good to me.

Quoted 33 lines
Quoted 33 lines
Quoted 29 lines
lib/librte_cryptodev/rte_crypto_asym.h +4 -0
+};
+
+/**
  * Asymmetric Cryptographic Operation.
  *
  * Structure describing asymmetric crypto operation params.
@@ -537,6 +619,7 @@ struct rte_crypto_asym_op {
 		struct rte_crypto_mod_op_param modinv;
 		struct rte_crypto_dh_op_param dh;
 		struct rte_crypto_dsa_op_param dsa;
+		struct rte_crypto_ecdsa_op_param ecdsa;
 	};
 };
 
lib/librte_cryptodev/rte_cryptodev.c +1 -1
index 89aa2ed..0d6babb 100644
@@ -173,6 +173,7 @@ const char *rte_crypto_asym_xform_strings[] = {
 	[RTE_CRYPTO_ASYM_XFORM_MODINV]	= "modinv",
 	[RTE_CRYPTO_ASYM_XFORM_DH]	= "dh",
 	[RTE_CRYPTO_ASYM_XFORM_DSA]	= "dsa",
+	[RTE_CRYPTO_ASYM_XFORM_ECDSA]	= "ecdsa",
 };
 
 /**
--
Quoted 1 line

2.7.4

Regards,
Arek

#5 lore raw

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

Hi Anoob,

Could you please send the updated patch with the changes suggested?

We need to merge it by Wednesday(15th Jan).

Thanks,
Akhil

#6 lore raw

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

In reply to Kusztal, ArkadiuszX

Hi Akhil,

Do you suggest any change for the title here? As in, should I make it,

cryptodev: support ECDSA

@Arek, please see inline for responses.

Thanks,
Anoob

Quoted 122 lines

-----Original Message-----
From: Kusztal, ArkadiuszX <[email protected]>
Sent: Thursday, January 9, 2020 6:34 PM
To: Anoob Joseph <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Cc: Ayuj Verma <[email protected]>; Trahe, Fiona <[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 ECDSA

External Email

----------------------------------------------------------------------
Hi Anoob,

Quoted 104 lines

-----Original Message-----
From: Anoob Joseph <[email protected]>
Sent: Thursday, January 2, 2020 8:55 AM
To: Kusztal, ArkadiuszX <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Cc: Ayuj Verma <[email protected]>; Trahe, Fiona <[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: RE: [PATCH 1/4] lib/crypto: add support for ECDSA

Hi Arek,

Please see inline.

Thanks,
Anoob

Quoted 59 lines

-----Original Message-----
From: Kusztal, ArkadiuszX <[email protected]>
Sent: Friday, December 20, 2019 9:36 PM
To: Anoob Joseph <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Cc: Ayuj Verma <[email protected]>; Trahe, Fiona <[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 ECDSA

External Email

--------------------------------------------------------------------
--
Hi Anoob,

Few suggestions inline.

Quoted 31 lines

;
[Asymmetric]

doc/guides/cryptodevs/features/default.ini +6 -5
-RSA =
-DSA =
-Modular Exponentiation =
-Modular Inversion =
-Diffie-hellman =
\ No newline at end of file
+RSA                     =
+DSA                     =
+Modular Exponentiation  =
+Modular Inversion       =
+Diffie-hellman          =
+ECDSA                   =
lib/librte_cryptodev/rte_crypto_asym.h +4 -0
index 0d34ce8..dd5e6e3 100644
@@ -81,6 +81,10 @@ enum rte_crypto_asym_xform_type {
 	/**< Modular Exponentiation
 	 * Perform Modular Exponentiation b^e mod n
 	 */
+	RTE_CRYPTO_ASYM_XFORM_ECDSA,
+	/**< Elliptic Curve Digital Signature Algorithm
+	 * Perform Signature Generation and Verification.
+	 */
 	RTE_CRYPTO_ASYM_XFORM_TYPE_LIST_END
 	/**< End of list */
 };

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_xform { }; · line 327

Quoted 5 lines
lib/librte_cryptodev/rte_crypto_asym.h +3 -0
@@ -319,6 +323,46 @@ struct rte_crypto_dsa_xform {  };
 
 /**
+ * TLS named curves
+ *
+https://urldefense.proofpoint.com/v2/url?u=https-

3A__www.iana.org_ass

Quoted 6 lines

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_xform { }; · line 328

Quoted 1 line
lib/librte_cryptodev/rte_crypto_asym.h +1 -0
+ignments_tls-

2Dparameters_&d=DwIFAg&c=nKjWec2b6R0mOyPaz7xtfQ&r=jPfB8r

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_xform { }; · line 329

Quoted 1 line
lib/librte_cryptodev/rte_crypto_asym.h +1 -0
+wwviRSxyLWs2n6B-WYLn1v9SyTMrT5EQqh2TU&m=nYBsHHO1NEdu-

JmNULDH0kx7auwQd

Quoted 1 line

+SbI0VYNVNxmm1w&s=RKZgomFiHpm9Yp8AYEn4FjlPpzbdavkMv5cRUggVid

Quoted 17 lines

A&e=

Quoted 7 lines

+ * tls-parameters.xhtml#tls-parameters-8
+ * secp192r1 = 19,
+ * secp224r1 = 21,
+ * secp256r1 = 23,
+ * secp384r1 = 24,
+ * secp521r1 = 25,
+ */

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_xform {

Quoted 7 lines
lib/librte_cryptodev/rte_crypto_asym.h +7 -0
+enum rte_crypto_ec_group {
+	RTE_CRYPTO_EC_GROUP_UNKNOWN  = 0,
+	RTE_CRYPTO_EC_GROUP_NISTP192 = 19,
+	RTE_CRYPTO_EC_GROUP_NISTP224 = 21,
+	RTE_CRYPTO_EC_GROUP_NISTP256 = 23,
+	RTE_CRYPTO_EC_GROUP_NISTP384 = 24,
+	RTE_CRYPTO_EC_GROUP_NISTP521 = 25, };

[Arek] Since in comment we use SECG naming maybe enum should follow

Quoted 5 lines
Quoted 4 lines

to

Quoted 1 line

avoid confusion?

[Anoob] How about RTE_CRYPTO_EC_GROUP_SECP521R1 and so on?

[Arek] Iam ok with that.

[Anoob] Will update in v2.

Quoted 54 lines
Quoted 51 lines
Quoted 40 lines
Quoted 40 lines
lib/librte_cryptodev/rte_crypto_asym.h +27 -0
+
+/**
+ * Structure for elliptic curve point  */ struct
+rte_crypto_ec_point {
+	rte_crypto_param x;
+	/**< X coordinate */
+	rte_crypto_param y;
+	/**< Y coordinate */
+};
+
+/**
+ * Asymmetric elliptic curve transform data
+ *
+ * Structure describing all EC based xform params
+ *
+ */
+struct rte_crypto_ec_xform {
+	enum rte_crypto_ec_group curve_id;
+	/**< Pre-defined ec groups */
+};
+
+/**
  * Operations params for modular operations:
  * exponentiation and multiplicative inverse
  *
@@ -372,6 +416,11 @@ struct rte_crypto_asym_xform {
 
 		struct rte_crypto_dsa_xform dsa;
 		/**< DSA xform parameters */
+
+		struct rte_crypto_ec_xform ec;
+		/**< EC xform parameters, used by elliptic curve based
+		 * operations.
+		 */
 	};
 };
 
@@ -516,6 +565,39 @@ struct rte_crypto_dsa_op_param {  };
 
Quoted 10 lines

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_op_param { · line 575

Quoted 9 lines
lib/librte_cryptodev/rte_crypto_asym.h +8 -0
 /**
+ * ECDSA operation params
+ */
+struct rte_crypto_ecdsa_op_param {
+	enum rte_crypto_asym_op_type op_type;
+	/**< Signature generation or verification */
+
+	rte_crypto_param pkey;
+	/**< Private key of the signer for signature generation */

[Arek] - for DSA we have private key in xform, why this inconsistency?

Quoted 3 lines

[Anoob] Putting key in the session would limit the number of ops we can perform with one session. In regular use cases, the number of ops done with one key is very minimal. But the number of ops using same EC group

Quoted 6 lines

is more.

Quoted 3 lines

So if we define the session to one per EC group, then we will have better usage of session. Otherwise, the session need to be created and destroyed every few operations.

[Arek] I agree with that, so maybe we could change DSA similar way (leave only group params?)

[Anoob] I'm okay with that. But that will have to be taken up separately, I guess. Shall I take that you are in agreement with the proposed change here?

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_op_param { · line 581

Quoted 7 lines
lib/librte_cryptodev/rte_crypto_asym.h +6 -0
+
+	struct rte_crypto_ec_point q;
+	/**< Public key of the signer for verification */
+
+	rte_crypto_param message;
+	/**< Input message to be signed or verified */

[Arek] - This I expect should be message digest instead of message itself?

Quoted 4 lines
Quoted 3 lines

[Anoob] Yes. Message digest is what is expected. This is following what is done with DSA & RSA. Do you recommend any changes? Variable name or description.

[Arek] Some information would be good I think.

[Anoob] I'll update the comment to state the same

/**< Input message digest to be signed or verified */

Is this fine?

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_op_param { · line 586

Quoted 6 lines
lib/librte_cryptodev/rte_crypto_asym.h +5 -0
+
+	rte_crypto_param k;
+	/**< The ECDSA per-message secret number, which is an integer
+	 * in the interval (1, n-1)
+	 */

[Arek] - If pmd can generate 'k' internally we could do something like:
'if k.data == NULL => PMD will generate 'k' internally, k.data remains untouched.'

Quoted 3 lines
Quoted 2 lines

[Anoob] So that will be exposed as a new capability, right? Do you suggest any changes here to accommodate that?

[Arek] Or maybe feature flag, it would apply to DSA as well.

[Anoob] I meant feature flag only! Capability is for net devs etc.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Another option is to provide user with some callback function to generate CSRN which could be useful for RSA PSS, OAEP as well (we already discussed that internally in Intel, I will elaborate on this bit more in

Quoted 7 lines
Quoted 3 lines

different thread).

[Anoob] Do you intend to keep the generated CSRN hidden in the PMD?

[Arek] Openssl PMD does that with DSA but iam not a fan of that. But if some hw can do DSA/ECDSA by generating 'k' by itself it would have to be added anyway. Other option is to add aforementioned callbacks (for HW that not generate 'k' by itself)

[Anoob] I think we can support either case. Our h/w also can generate CSRN and so are open to ideas. Can you explain the proposed callback function? Also, we can defer that discussion to a separate thread, if we have an agreement on the approach here.

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_op_param { · line 597

Quoted 13 lines
lib/librte_cryptodev/rte_crypto_asym.h +11 -0
+
+	rte_crypto_param r;
+	/**< r component of elliptic curve signature
+	 *     output : for signature generation
+	 *     input  : for signature verification
+	 */
+	rte_crypto_param s;
+	/**< s component of elliptic curve signature
+	 *     output : for signature generation
+	 *     input  : for signature verification
+	 */

[Arek] - Do we want to add any constraints like 'this field should be big enough to hold...'

Quoted 6 lines
Quoted 3 lines

[Anoob] For every case where rte_crypto_param is used for 'output', application should make sure the buffers are large enough. Do you think we could document it somewhere common instead of adding per

operation?
[Arek]
Both options look good to me.

[Anoob] How about updating the description of 'rte_crypto_param' to reflect the same? I can update it in v2, if you can confirm.

Quoted 33 lines
Quoted 33 lines
Quoted 33 lines
Quoted 29 lines
lib/librte_cryptodev/rte_crypto_asym.h +4 -0
+};
+
+/**
  * Asymmetric Cryptographic Operation.
  *
  * Structure describing asymmetric crypto operation params.
@@ -537,6 +619,7 @@ struct rte_crypto_asym_op {
 		struct rte_crypto_mod_op_param modinv;
 		struct rte_crypto_dh_op_param dh;
 		struct rte_crypto_dsa_op_param dsa;
+		struct rte_crypto_ecdsa_op_param ecdsa;
 	};
 };
 
lib/librte_cryptodev/rte_cryptodev.c +1 -1
index 89aa2ed..0d6babb 100644
@@ -173,6 +173,7 @@ const char *rte_crypto_asym_xform_strings[] = {
 	[RTE_CRYPTO_ASYM_XFORM_MODINV]	= "modinv",
 	[RTE_CRYPTO_ASYM_XFORM_DH]	= "dh",
 	[RTE_CRYPTO_ASYM_XFORM_DSA]	= "dsa",
+	[RTE_CRYPTO_ASYM_XFORM_ECDSA]	= "ecdsa",
 };
 
 /**
--
Quoted 1 line

2.7.4

Regards,
Arek

#7 lore raw

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

Hi Anoob, Akhil

Quoted 13 lines

-----Original Message-----
From: Anoob Joseph <[email protected]>
Sent: Monday, January 13, 2020 10:07 PM
To: Kusztal, ArkadiuszX <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Cc: Ayuj Verma <[email protected]>; Trahe, Fiona <[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: RE: [PATCH 1/4] lib/crypto: add support for ECDSA

....

Quoted 29 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_op_param {

Quoted 5 lines
lib/librte_cryptodev/rte_crypto_asym.h +3 -0
+
+	rte_crypto_param k;
+	/**< The ECDSA per-message secret number, which is an

integer

Quoted 9 lines
Quoted 8 lines
Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	 * in the interval (1, n-1)
+	 */

[Arek] - If pmd can generate 'k' internally we could do something like:
'if k.data == NULL => PMD will generate 'k' internally, k.data remains untouched.'

[Anoob] So that will be exposed as a new capability, right? Do you suggest any changes here to accommodate that?

[Arek] Or maybe feature flag, it would apply to DSA as well.

[Anoob] I meant feature flag only! Capability is for net devs etc.

Quoted 10 lines
Quoted 8 lines
Quoted 5 lines

Another option is to provide user with some callback function to generate CSRN which could be useful for RSA PSS, OAEP as well (we already discussed that internally in Intel, I will elaborate on this bit more in

different thread).

[Anoob] Do you intend to keep the generated CSRN hidden in the PMD?

[Arek] Openssl PMD does that with DSA but iam not a fan of that. But if some hw can do DSA/ECDSA by generating 'k' by itself it would have to be

added anyway.

Quoted 9 lines
Quoted 1 line

Other option is to add aforementioned callbacks (for HW that not generate

'k'

Quoted 1 line

by itself)

[Anoob] I think we can support either case. Our h/w also can generate CSRN and so are open to ideas. Can you explain the proposed callback function? Also, we can defer that discussion to a separate thread, if we have an agreement on the approach here.

[Shally] Just a thought here. It can also be supported by exposing an API to application, like pre-compute / pre-setup which can generate 'k' or 'PRF' for other algo usage purpose. If PMD support it, return will be success with relevant o/p.. if not, return will be failure. Or no offload at all. In any case, generation of prf or 'k' is heavy on data path... app can call these pre-setup APIs to save cycles on actual sign op.

Shally

Quoted 60 lines
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_op_param { · line 597

Quoted 13 lines
lib/librte_cryptodev/rte_crypto_asym.h +11 -0
+
+	rte_crypto_param r;
+	/**< r component of elliptic curve signature
+	 *     output : for signature generation
+	 *     input  : for signature verification
+	 */
+	rte_crypto_param s;
+	/**< s component of elliptic curve signature
+	 *     output : for signature generation
+	 *     input  : for signature verification
+	 */

[Arek] - Do we want to add any constraints like 'this field should be big enough to hold...'

Quoted 6 lines
Quoted 3 lines

[Anoob] For every case where rte_crypto_param is used for 'output', application should make sure the buffers are large enough. Do you think we could document it somewhere common instead of adding per

operation?
[Arek]
Both options look good to me.

[Anoob] How about updating the description of 'rte_crypto_param' to reflect the same? I can update it in v2, if you can confirm.

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
lib/librte_cryptodev/rte_crypto_asym.h +4 -0
+};
+
+/**
  * Asymmetric Cryptographic Operation.
  *
  * Structure describing asymmetric crypto operation params.
@@ -537,6 +619,7 @@ struct rte_crypto_asym_op {
 		struct rte_crypto_mod_op_param modinv;
 		struct rte_crypto_dh_op_param dh;
 		struct rte_crypto_dsa_op_param dsa;
+		struct rte_crypto_ecdsa_op_param ecdsa;
 	};
 };
 
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

lib/librte_cryptodev/rte_cryptodev.c const char *rte_crypto_asym_xform_strings[]

Quoted 6 lines
lib/librte_cryptodev/rte_cryptodev.c +0 -0
index 89aa2ed..0d6babb 100644
@@ -173,6 +173,7 @@ const char *rte_crypto_asym_xform_strings[]

= {

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 9 lines
lib/librte_cryptodev/rte_cryptodev.c +1 -1
 	[RTE_CRYPTO_ASYM_XFORM_MODINV]	= "modinv",
 	[RTE_CRYPTO_ASYM_XFORM_DH]	= "dh",
 	[RTE_CRYPTO_ASYM_XFORM_DSA]	= "dsa",
+	[RTE_CRYPTO_ASYM_XFORM_ECDSA]	= "ecdsa",
 };
 
 /**
--

2.7.4

Regards,
Arek

#8 lore raw

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

Hi guys,

Quoted 41 lines
Quoted 29 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_op_param {

Quoted 5 lines
lib/librte_cryptodev/rte_crypto_asym.h +3 -0
+
+	rte_crypto_param k;
+	/**< The ECDSA per-message secret number, which is an

integer

Quoted 9 lines
Quoted 8 lines
Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	 * in the interval (1, n-1)
+	 */

[Arek] - If pmd can generate 'k' internally we could do something like:
'if k.data == NULL => PMD will generate 'k' internally, k.data remains untouched.'

[Anoob] So that will be exposed as a new capability, right? Do you suggest any changes here to accommodate that?

[Arek] Or maybe feature flag, it would apply to DSA as well.

[Anoob] I meant feature flag only! Capability is for net devs etc.

Quoted 11 lines
Quoted 8 lines
Quoted 5 lines

Another option is to provide user with some callback function to generate CSRN which could be useful for RSA PSS, OAEP as well (we already discussed that internally in Intel, I will elaborate on this bit more in

different thread).

[Anoob] Do you intend to keep the generated CSRN hidden in the PMD?

[Arek] Openssl PMD does that with DSA but iam not a fan of that. But if some hw can do DSA/ECDSA by generating 'k' by itself it would have to be

Quoted 8 lines

added anyway.

Quoted 2 lines

Other option is to add aforementioned callbacks (for HW that not generate

'k'

Quoted 1 line

by itself)

[Anoob] I think we can support either case. Our h/w also can generate CSRN and so are open to ideas. Can you explain the proposed callback

function?

Quoted 3 lines

Also, we can defer that discussion to a separate thread, if we have an agreement on the approach here.

Quoted 6 lines

[Shally] Just a thought here. It can also be supported by exposing an API to application, like pre-compute / pre-setup which can generate 'k' or 'PRF' for other algo usage purpose. If PMD support it, return will be success with relevant o/p.. if not, return will be failure. Or no offload at all. In any case, generation of prf or 'k' is heavy on data path... app can call these pre-setup APIs to save cycles on actual sign op.

[AK] - We can start another thread on that. For now this implementation is good too, we can extend API by PMD CSRN option later.

Quoted 18 lines

Shally

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines

lib/librte_cryptodev/rte_crypto_asym.h struct rte_crypto_dsa_op_param { · line 597

Quoted 13 lines
lib/librte_cryptodev/rte_crypto_asym.h +11 -0
+
+	rte_crypto_param r;
+	/**< r component of elliptic curve signature
+	 *     output : for signature generation
+	 *     input  : for signature verification
+	 */
+	rte_crypto_param s;
+	/**< s component of elliptic curve signature
+	 *     output : for signature generation
+	 *     input  : for signature verification
+	 */

[Arek] - Do we want to add any constraints like 'this field should be big enough to hold...'

Quoted 11 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

[Anoob] For every case where rte_crypto_param is used for 'output', application should make sure the buffers are large enough. Do you think we could document it somewhere common

instead

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

of adding per

operation?
[Arek]
Both options look good to me.

[Anoob] How about updating the description of 'rte_crypto_param' to reflect the same? I can update it in v2, if you can confirm.

[AK] It is ok to me.

Quoted 36 lines
Quoted 36 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
lib/librte_cryptodev/rte_crypto_asym.h +4 -0
+};
+
+/**
  * Asymmetric Cryptographic Operation.
  *
  * Structure describing asymmetric crypto operation params.
@@ -537,6 +619,7 @@ struct rte_crypto_asym_op {
 		struct rte_crypto_mod_op_param modinv;
 		struct rte_crypto_dh_op_param dh;
 		struct rte_crypto_dsa_op_param dsa;
+		struct rte_crypto_ecdsa_op_param ecdsa;
 	};
 };
 
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

lib/librte_cryptodev/rte_cryptodev.c const char · line 173

Quoted 7 lines
lib/librte_cryptodev/rte_cryptodev.c +0 -0
index 89aa2ed..0d6babb 100644
@@ -173,6 +173,7 @@ const char
 *rte_crypto_asym_xform_strings[]

= {

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 9 lines
lib/librte_cryptodev/rte_cryptodev.c +1 -0
 	[RTE_CRYPTO_ASYM_XFORM_MODINV]	= "modinv",
 	[RTE_CRYPTO_ASYM_XFORM_DH]	= "dh",
 	[RTE_CRYPTO_ASYM_XFORM_DSA]	= "dsa",
+	[RTE_CRYPTO_ASYM_XFORM_ECDSA]	= "ecdsa",
 };
 

/**
--
2.7.4

Regards,
Arek

#9 lore raw

PATCH 2/4 crypto/octeontx: add ECDSA support

In reply to Anoob Joseph

From: Sunila Sahu <[email protected]>

Adding support for ECDSA operations in crypto_octeontx PMD.

---
 doc/guides/cryptodevs/features/octeontx.ini        |    8 +-
 drivers/common/cpt/Makefile                        |    1 +
 drivers/common/cpt/cpt_fpm_tables.c                | 1138 ++++++++++++++++++++
 drivers/common/cpt/cpt_mcode_defines.h             |   38 +
 drivers/common/cpt/cpt_pmd_ops_helper.h            |   19 +
 drivers/common/cpt/cpt_ucode_asym.h                |  378 +++++++
 drivers/common/cpt/meson.build                     |    3 +-
 drivers/common/cpt/rte_common_cpt_version.map      |    9 +
 .../crypto/octeontx/otx_cryptodev_capabilities.c   |   11 +
 drivers/crypto/octeontx/otx_cryptodev_ops.c        |   43 +-
 10 files changed, 1643 insertions(+), 5 deletions(-)
 create mode 100644 drivers/common/cpt/cpt_fpm_tables.c
doc/guides/cryptodevs/features/octeontx.ini +6 -2
index 1c036c5..544bb46 100644
@@ -67,5 +67,9 @@ AES GCM (256) = Y
 ; Supported Asymmetric algorithms of the 'octeontx' crypto driver.
 ;
 [Asymmetric]
-RSA                    = Y
-Modular Exponentiation = Y
+RSA                     = Y
+DSA                     =
+Modular Exponentiation  = Y
+Modular Inversion       =
+Diffie-hellman          =
+ECDSA                   = Y
drivers/common/cpt/Makefile +1 -0
index 8594432..cab9da7 100644
@@ -16,6 +16,7 @@ EXPORT_MAP := rte_common_cpt_version.map
 #
 # all source are stored in SRCS-y
 #
+SRCS-y += cpt_fpm_tables.c
 SRCS-y += cpt_pmd_ops_helper.c
 
 LDLIBS += -lrte_eal
drivers/common/cpt/cpt_fpm_tables.c new file +1138 -0

1,138 lines not on this page · raw message

drivers/common/cpt/cpt_mcode_defines.h +38 -0
index f356e62..64d3e8c 100644
@@ -23,12 +23,15 @@
 
 /* AE opcodes */
 #define CPT_MAJOR_OP_MODEX	0x03
+#define CPT_MAJOR_OP_ECDSA	0x04
 #define CPT_MINOR_OP_MODEX	0x01
 #define CPT_MINOR_OP_PKCS_ENC	0x02
 #define CPT_MINOR_OP_PKCS_ENC_CRT	0x03
 #define CPT_MINOR_OP_PKCS_DEC	0x04
 #define CPT_MINOR_OP_PKCS_DEC_CRT	0x05
 #define CPT_MINOR_OP_MODEX_CRT	0x06
+#define CPT_MINOR_OP_ECDSA_SIGN	0x01
+#define CPT_MINOR_OP_ECDSA_VERIFY	0x02
 
 #define CPT_BLOCK_TYPE1 0
 #define CPT_BLOCK_TYPE2 1
@@ -203,6 +206,20 @@ typedef enum {
 	CPT_8X_COMP_E_LAST_ENTRY = (0xFF)
 } cpt_comp_e_t;
 
+/**
+ * Enumeration cpt_ec_id
+ *
+ * Enumerates supported elliptic curves
+ */
+typedef enum {
+	CPT_EC_ID_P192 = 0,
+	CPT_EC_ID_P224 = 1,
+	CPT_EC_ID_P256 = 2,
+	CPT_EC_ID_P384 = 3,
+	CPT_EC_ID_P521 = 4,
+	CPT_EC_ID_PMAX = 5
+} cpt_ec_id_t;
+
 typedef struct sglist_comp {
 	union {
 		uint64_t len;
@@ -329,11 +346,32 @@ struct cpt_ctx {
 	uint8_t  auth_key[64];
 };
 
+/* Prime and order fields of built-in elliptic curves */
+struct cpt_ec_group {
+	struct {
+		/* P521 maximum length */
+		uint8_t data[66];
+		unsigned int length;
+	} prime;
+
+	struct {
+		/* P521 maximum length */
+		uint8_t data[66];
+		unsigned int length;
+	} order;
+};
+
+struct cpt_asym_ec_ctx {
+	/* Prime length defined by microcode for EC operations */
+	uint8_t curveid;
+};
+
 struct cpt_asym_sess_misc {
 	enum rte_crypto_asym_xform_type xfrm_type;
 	union {
 		struct rte_crypto_rsa_xform rsa_ctx;
 		struct rte_crypto_modex_xform mod_ctx;
+		struct cpt_asym_ec_ctx ec_ctx;
 	};
 };
 
drivers/common/cpt/cpt_pmd_ops_helper.h +19 -0
index 24c3559..716ae94 100644
@@ -40,4 +40,23 @@ cpt_pmd_ops_helper_get_mlen_sg_mode(void);
  */
 int
 cpt_pmd_ops_helper_asym_get_mlen(void);
+
+/*
+ * Initialize ECC FMUL precomputed table
+ *
+ * @param
+ *  - pointer to fpm_table iova address
+ *
+ * @return
+ *  - 0 on success, negative on error
+ */
+__rte_experimental
+int cpt_fpm_init(uint64_t *fpm_table_iova);
+
+/*
+ * Clear ECC FMUL precomputed table
+ */
+__rte_experimental
+void cpt_fpm_clear(void);
+
 #endif /* _CPT_PMD_OPS_HELPER_H_ */
drivers/common/cpt/cpt_ucode_asym.h +378 -0

400 lines not on this page · raw message

drivers/common/cpt/meson.build +2 -1
index 0a905aa..d2e84ff 100644
@@ -1,7 +1,8 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2018 Cavium, Inc
 
-sources = files('cpt_pmd_ops_helper.c')
+sources = files('cpt_fpm_tables.c',
+		'cpt_pmd_ops_helper.c')
 
 deps = ['kvargs', 'pci', 'cryptodev']
 includes += include_directories('../../crypto/octeontx')
drivers/common/cpt/rte_common_cpt_version.map +9 -0
index 7f1929d..8c65cde 100644
@@ -7,3 +7,12 @@ DPDK_20.0 {
 
 	local: *;
 };
+
+EXPERIMENTAL {
+	global:
+
+	cpt_fpm_clear;
+	cpt_fpm_init;
+
+	local: *;
+};
drivers/crypto/octeontx/otx_cryptodev_capabilities.c +11 -0
index 8c0358f..6418ad2 100644
@@ -630,6 +630,17 @@ static const struct rte_cryptodev_capabilities otx_asym_capabilities[] = {
 			}
 		}, }
 	},
+	{	/* ECDSA */
+		.op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
+		{.asym = {
+			.xform_capa = {
+				.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA,
+				.op_types = ((1 << RTE_CRYPTO_ASYM_OP_SIGN) |
+					(1 << RTE_CRYPTO_ASYM_OP_VERIFY)),
+				}
+			},
+		}
+	},
 	/* End of asymmetric capabilities */
 	RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
 };
drivers/crypto/octeontx/otx_cryptodev_ops.c +41 -2

85 lines not on this page · raw message

Signature · 1 line
2.7.4
#10 lore raw

PATCH 3/4 crypto/octeontx2: add ECDSA support

In reply to Anoob Joseph

From: Sunila Sahu <[email protected]>

Adding support for ECDSA operations in crypto_octeontx2 PMD.

---
 doc/guides/cryptodevs/features/octeontx2.ini       |  8 +++--
 .../crypto/octeontx2/otx2_cryptodev_capabilities.c | 11 ++++++
 drivers/crypto/octeontx2/otx2_cryptodev_ops.c      | 39 ++++++++++++++++++++--
 3 files changed, 54 insertions(+), 4 deletions(-)
doc/guides/cryptodevs/features/octeontx2.ini +6 -2
index 7d07053..dd6369b 100644
@@ -67,5 +67,9 @@ AES GCM (256) = Y
 ; Supported Asymmetric algorithms of the 'octeontx2' crypto driver.
 ;
 [Asymmetric]
-RSA                    = Y
-Modular Exponentiation = Y
+RSA                     = Y
+DSA                     =
+Modular Exponentiation  = Y
+Modular Inversion       =
+Diffie-hellman          =
+ECDSA                   = Y
drivers/crypto/octeontx2/otx2_cryptodev_capabilities.c +11 -0
index b9e3fe3..f2079e2 100644
@@ -628,6 +628,17 @@ rte_cryptodev_capabilities otx2_cpt_capabilities[] = {
 			}
 		}, }
 	},
+	{	/* ECDSA */
+		.op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
+		{.asym = {
+			.xform_capa = {
+				.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA,
+				.op_types = ((1 << RTE_CRYPTO_ASYM_OP_SIGN) |
+					(1 << RTE_CRYPTO_ASYM_OP_VERIFY)),
+				}
+			},
+		}
+	},
 	/* End of asymmetric capabilities */
 	RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
 };
drivers/crypto/octeontx2/otx2_cryptodev_ops.c +37 -2
index 65101b0..17c755d 100644
@@ -22,6 +22,8 @@
 
 #define METABUF_POOL_CACHE_SIZE	512
 
+static uint64_t otx2_fpm_iova[CPT_EC_ID_PMAX];
+
 /* Forward declarations */
 
 static int
@@ -440,6 +442,11 @@ otx2_cpt_enqueue_asym(struct otx2_cpt_qp *qp,
 		if (unlikely(ret))
 			goto req_fail;
 		break;
+	case RTE_CRYPTO_ASYM_XFORM_ECDSA:
+		ret = cpt_enqueue_ecdsa_op(op, &params, sess, otx2_fpm_iova);
+		if (unlikely(ret))
+			goto req_fail;
+		break;
 	default:
 		op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
 		ret = -EINVAL;
@@ -641,6 +648,23 @@ otx2_cpt_asym_rsa_op(struct rte_crypto_op *cop, struct cpt_request_info *req,
 	}
 }
 
+static __rte_always_inline void
+otx2_cpt_asym_dequeue_ecdsa_op(struct rte_crypto_ecdsa_op_param *ecdsa,
+			       struct cpt_request_info *req,
+			       struct cpt_asym_ec_ctx *ec)
+{
+	int prime_len = ec_grp[ec->curveid].prime.length;
+
+	if (ecdsa->op_type == RTE_CRYPTO_ASYM_OP_VERIFY)
+		return;
+
+	/* Separate out sign r and s components */
+	memcpy(ecdsa->r.data, req->rptr, prime_len);
+	memcpy(ecdsa->s.data, req->rptr + ROUNDUP8(prime_len), prime_len);
+	ecdsa->r.length = prime_len;
+	ecdsa->s.length = prime_len;
+}
+
 static void
 otx2_cpt_asym_post_process(struct rte_crypto_op *cop,
 			   struct cpt_request_info *req)
@@ -660,6 +684,9 @@ otx2_cpt_asym_post_process(struct rte_crypto_op *cop,
 		memcpy(op->modex.result.data, req->rptr,
 		       op->modex.result.length);
 		break;
+	case RTE_CRYPTO_ASYM_XFORM_ECDSA:
+		otx2_cpt_asym_dequeue_ecdsa_op(&op->ecdsa, req, &sess->ec_ctx);
+		break;
 	default:
 		CPT_LOG_DP_DEBUG("Invalid crypto xform type");
 		cop->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
@@ -824,6 +851,13 @@ otx2_cpt_dev_config(struct rte_cryptodev *dev,
 
 	dev->feature_flags &= ~conf->ff_disable;
 
+	if (dev->feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) {
+		/* Initialize shared FPM table */
+		ret = cpt_fpm_init(otx2_fpm_iova);
+		if (ret)
+			return ret;
+	}
+
 	/* Unregister error interrupts */
 	if (vf->err_intr_registered)
 		otx2_cpt_err_intr_unregister(dev);
@@ -881,9 +915,10 @@ otx2_cpt_dev_start(struct rte_cryptodev *dev)
 static void
 otx2_cpt_dev_stop(struct rte_cryptodev *dev)
 {
-	RTE_SET_USED(dev);
-
 	CPT_PMD_INIT_FUNC_TRACE();
+
+	if (dev->feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)
+		cpt_fpm_clear();
 }
 
 static int
Signature · 1 line
2.7.4
#11 lore raw

PATCH 4/4 app/test: add ECDSA sign/verify tests

In reply to Anoob Joseph

From: Ayuj Verma <[email protected]>

This patch adds ECDSA sign and verify test routine and test vectors.

---
 app/test/test_cryptodev_asym.c               | 219 +++++++++++-
 app/test/test_cryptodev_asym_util.h          |  11 +
 app/test/test_cryptodev_ecdsa_test_vectors.h | 501 +++++++++++++++++++++++++++
 3 files changed, 730 insertions(+), 1 deletion(-)
 create mode 100644 app/test/test_cryptodev_ecdsa_test_vectors.h
app/test/test_cryptodev_asym.c +218 -1
index 69df293..b913a7d 100644
@@ -18,6 +18,7 @@
 #include "test_cryptodev.h"
 #include "test_cryptodev_dh_test_vectors.h"
 #include "test_cryptodev_dsa_test_vectors.h"
+#include "test_cryptodev_ecdsa_test_vectors.h"
 #include "test_cryptodev_mod_test_vectors.h"
 #include "test_cryptodev_rsa_test_vectors.h"
 #include "test_cryptodev_asym_util.h"
@@ -1037,14 +1038,16 @@ static inline void print_asym_capa(
 		case RTE_CRYPTO_ASYM_XFORM_MODEX:
 		case RTE_CRYPTO_ASYM_XFORM_DH:
 		case RTE_CRYPTO_ASYM_XFORM_DSA:
-			printf(" modlen: min %d max %d increment %d\n",
+			printf(" modlen: min %d max %d increment %d",
 					capa->modlen.min,
 					capa->modlen.max,
 					capa->modlen.increment);
 		break;
+		case RTE_CRYPTO_ASYM_XFORM_ECDSA:
 		default:
 			break;
 		}
+		printf("\n");
 }
 
 static int
@@ -1892,6 +1895,218 @@ test_dsa(void)
 	return status;
 }
 
+static int
+test_ecdsa_sign_verify(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_ecdsa_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_r[TEST_DATA_SIZE];
+	uint8_t output_buf_s[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 = ecdsa_param_p192;
+		break;
+	case P224:
+		input_params = ecdsa_param_p224;
+		break;
+	case P256:
+		input_params = ecdsa_param_p256;
+		break;
+	case P384:
+		input_params = ecdsa_param_p384;
+		break;
+	case P521:
+		input_params = ecdsa_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_ECDSA;
+	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);
+
+	/* Compute sign */
+
+	/* Populate op with operational details */
+	op->asym->ecdsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
+	op->asym->ecdsa.message.data = input_params.digest.data;
+	op->asym->ecdsa.message.length = input_params.digest.length;
+	op->asym->ecdsa.k.data = input_params.scalar.data;
+	op->asym->ecdsa.k.length = input_params.scalar.length;
+	op->asym->ecdsa.pkey.data = input_params.pkey.data;
+	op->asym->ecdsa.pkey.length = input_params.pkey.length;
+
+	/* Init out buf */
+	op->asym->ecdsa.r.data = output_buf_r;
+	op->asym->ecdsa.s.data = output_buf_s;
+
+	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:",
+			asym_op->ecdsa.r.data, asym_op->ecdsa.r.length);
+	debug_hexdump(stdout, "s:",
+			asym_op->ecdsa.s.data, asym_op->ecdsa.s.length);
+
+	ret = verify_ecdsa_sign(input_params.sign_r.data,
+				input_params.sign_s.data, result_op);
+	if (ret) {
+		status = TEST_FAILED;
+		RTE_LOG(ERR, USER1,
+				"line %u FAILED: %s", __LINE__,
+				"ECDSA sign failed.\n");
+		goto exit;
+	}
+
+	/* Verify sign */
+
+	/* Populate op with operational details */
+	op->asym->ecdsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
+	op->asym->ecdsa.q.x.data = input_params.pubkey_qx.data;
+	op->asym->ecdsa.q.x.length = input_params.pubkey_qx.length;
+	op->asym->ecdsa.q.y.data = input_params.pubkey_qy.data;
+	op->asym->ecdsa.q.y.length = input_params.pubkey_qx.length;
+	op->asym->ecdsa.r.data = asym_op->ecdsa.r.data;
+	op->asym->ecdsa.r.length = asym_op->ecdsa.r.length;
+	op->asym->ecdsa.s.data = asym_op->ecdsa.s.data;
+	op->asym->ecdsa.s.length = asym_op->ecdsa.s.length;
+
+	/* Enqueue sign result for verify */
+	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
+		status = TEST_FAILED;
+		RTE_LOG(ERR, USER1,
+				"line %u FAILED: %s", __LINE__,
+				"Error sending packet for operation\n");
+		goto exit;
+	}
+
+	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
+		rte_pause();
+
+	if (result_op == NULL) {
+		status = TEST_FAILED;
+		goto exit;
+	}
+	if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
+		status = TEST_FAILED;
+		RTE_LOG(ERR, USER1,
+				"line %u FAILED: %s", __LINE__,
+				"ECDSA verify 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_ecdsa_sign_verify_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_ecdsa_sign_verify(curve_id);
+		if (status == TEST_SUCCESS) {
+			msg = "succeeded";
+		} else {
+			msg = "failed";
+			overall_status = status;
+		}
+		printf("  %u) TestCase Sign/Veriy 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",
@@ -1931,6 +2146,8 @@ static struct unit_test_suite cryptodev_octeontx_asym_testsuite  = {
 		TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_enc_dec_crt),
 		TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_sign_verify_crt),
 		TEST_CASE_ST(ut_setup, ut_teardown, test_mod_exp),
+		TEST_CASE_ST(ut_setup, ut_teardown,
+			     test_ecdsa_sign_verify_all_curve),
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	}
 };
app/test/test_cryptodev_asym_util.h +11 -0
index f2a8e6c..bddeda0 100644
@@ -35,4 +35,15 @@ static inline int verify_modexp(uint8_t *mod_exp,
 	return 0;
 }
 
+static inline int verify_ecdsa_sign(uint8_t *sign_r,
+		uint8_t *sign_s, struct rte_crypto_op *result_op)
+{
+	if (memcmp(sign_r, result_op->asym->ecdsa.r.data,
+		   result_op->asym->ecdsa.r.length) ||
+		   memcmp(sign_s, result_op->asym->ecdsa.s.data,
+		   result_op->asym->ecdsa.s.length))
+		return -1;
+	return 0;
+}
+
 #endif /* TEST_CRYPTODEV_ASYM_TEST_UTIL_H__ */
app/test/test_cryptodev_ecdsa_test_vectors.h new file +501 -0

501 lines not on this page · raw message

Signature · 1 line
2.7.4
#12 lore raw

v2 cover add ECDSA support

In reply to Anoob Joseph

This series adds support for ECDSA asymmetric operations. Library changes and PMD changes for crypto_octeontx & crypto_octoentx2 is added. The final patch adds the required test vectors and verification routines.

v2:
* Changed all NIST references to use SECP.
* Minor updates to documentation/comments as suggested by Arek
* Updated release notes

Ayuj Verma (2):
cryptodev: support ECDSA
app/test: add ECDSA sign/verify tests

Sunila Sahu (2):
crypto/octeontx: add ECDSA support
crypto/octeontx2: add ECDSA support

 app/test/test_cryptodev_asym.c                     |  219 +++-
 app/test/test_cryptodev_asym_util.h                |   11 +
 app/test/test_cryptodev_ecdsa_test_vectors.h       |  505 +++++++++
 doc/guides/cryptodevs/features/default.ini         |   11 +-
 doc/guides/cryptodevs/features/octeontx.ini        |    8 +-
 doc/guides/cryptodevs/features/octeontx2.ini       |    8 +-
 doc/guides/rel_notes/release_20_02.rst             |    4 +
 drivers/common/cpt/Makefile                        |    1 +
 drivers/common/cpt/cpt_fpm_tables.c                | 1138 ++++++++++++++++++++
 drivers/common/cpt/cpt_mcode_defines.h             |   38 +
 drivers/common/cpt/cpt_pmd_ops_helper.h            |   19 +
 drivers/common/cpt/cpt_ucode_asym.h                |  378 +++++++
 drivers/common/cpt/meson.build                     |    3 +-
 drivers/common/cpt/rte_common_cpt_version.map      |    9 +
 .../crypto/octeontx/otx_cryptodev_capabilities.c   |   11 +
 drivers/crypto/octeontx/otx_cryptodev_ops.c        |   43 +-
 .../crypto/octeontx2/otx2_cryptodev_capabilities.c |   11 +
 drivers/crypto/octeontx2/otx2_cryptodev_ops.c      |   39 +-
 lib/librte_cryptodev/rte_crypto_asym.h             |   84 ++
 lib/librte_cryptodev/rte_cryptodev.c               |    1 +
 20 files changed, 2526 insertions(+), 15 deletions(-)
 create mode 100644 app/test/test_cryptodev_ecdsa_test_vectors.h
 create mode 100644 drivers/common/cpt/cpt_fpm_tables.c
Signature · 1 line
2.7.4
#13 lore raw

PATCH v2 1/4 cryptodev: support ECDSA

From: Ayuj Verma <[email protected]>

Asymmetric crypto library is extended to add ECDSA. Elliptic curve xform and ECDSA op params are introduced.

---
 doc/guides/cryptodevs/features/default.ini | 11 ++--
 doc/guides/rel_notes/release_20_02.rst     |  4 ++
 lib/librte_cryptodev/rte_crypto_asym.h     | 84 ++++++++++++++++++++++++++++++
 lib/librte_cryptodev/rte_cryptodev.c       |  1 +
 4 files changed, 95 insertions(+), 5 deletions(-)
doc/guides/cryptodevs/features/default.ini +6 -5
index b7f9a0a..2f6c785 100644
@@ -103,8 +103,9 @@ AES CCM (256) =
 ; Supported Asymmetric algorithms of a default crypto driver.
 ;
 [Asymmetric]
-RSA =
-DSA =
-Modular Exponentiation =
-Modular Inversion =
-Diffie-hellman =
\ No newline at end of file
+RSA                     =
+DSA                     =
+Modular Exponentiation  =
+Modular Inversion       =
+Diffie-hellman          =
+ECDSA                   =
doc/guides/rel_notes/release_20_02.rst +4 -0
index 0eaa45a..2e97c60 100644
@@ -56,6 +56,10 @@ New Features
      Also, make sure to start the actual text at the margin.
      =========================================================
 
+* **Added support for ECDSA.**
+
+  Added ECDSA(Elliptic Curve Digital Signature Algorithm) support to asymmetric
+  crypto library specifications.
 
 Removed Items
 -------------
lib/librte_cryptodev/rte_crypto_asym.h +84 -0

120 lines not on this page · raw message

lib/librte_cryptodev/rte_cryptodev.c +1 -0
index 89aa2ed..0d6babb 100644
@@ -173,6 +173,7 @@ const char *rte_crypto_asym_xform_strings[] = {
 	[RTE_CRYPTO_ASYM_XFORM_MODINV]	= "modinv",
 	[RTE_CRYPTO_ASYM_XFORM_DH]	= "dh",
 	[RTE_CRYPTO_ASYM_XFORM_DSA]	= "dsa",
+	[RTE_CRYPTO_ASYM_XFORM_ECDSA]	= "ecdsa",
 };
 
 /**
Signature · 1 line
2.7.4
#15 lore raw

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

In reply to Anoob Joseph

From: Sunila Sahu <[email protected]>

Adding support for ECDSA operations in crypto_octeontx PMD.

---
 doc/guides/cryptodevs/features/octeontx.ini        |    8 +-
 drivers/common/cpt/Makefile                        |    1 +
 drivers/common/cpt/cpt_fpm_tables.c                | 1138 ++++++++++++++++++++
 drivers/common/cpt/cpt_mcode_defines.h             |   38 +
 drivers/common/cpt/cpt_pmd_ops_helper.h            |   19 +
 drivers/common/cpt/cpt_ucode_asym.h                |  378 +++++++
 drivers/common/cpt/meson.build                     |    3 +-
 drivers/common/cpt/rte_common_cpt_version.map      |    9 +
 .../crypto/octeontx/otx_cryptodev_capabilities.c   |   11 +
 drivers/crypto/octeontx/otx_cryptodev_ops.c        |   43 +-
 10 files changed, 1643 insertions(+), 5 deletions(-)
 create mode 100644 drivers/common/cpt/cpt_fpm_tables.c
doc/guides/cryptodevs/features/octeontx.ini +6 -2
index 1c036c5..544bb46 100644
@@ -67,5 +67,9 @@ AES GCM (256) = Y
 ; Supported Asymmetric algorithms of the 'octeontx' crypto driver.
 ;
 [Asymmetric]
-RSA                    = Y
-Modular Exponentiation = Y
+RSA                     = Y
+DSA                     =
+Modular Exponentiation  = Y
+Modular Inversion       =
+Diffie-hellman          =
+ECDSA                   = Y
drivers/common/cpt/Makefile +1 -0
index 8594432..cab9da7 100644
@@ -16,6 +16,7 @@ EXPORT_MAP := rte_common_cpt_version.map
 #
 # all source are stored in SRCS-y
 #
+SRCS-y += cpt_fpm_tables.c
 SRCS-y += cpt_pmd_ops_helper.c
 
 LDLIBS += -lrte_eal
drivers/common/cpt/cpt_fpm_tables.c new file +1138 -0

1,138 lines not on this page · raw message

drivers/common/cpt/cpt_mcode_defines.h +38 -0
index f356e62..64d3e8c 100644
@@ -23,12 +23,15 @@
 
 /* AE opcodes */
 #define CPT_MAJOR_OP_MODEX	0x03
+#define CPT_MAJOR_OP_ECDSA	0x04
 #define CPT_MINOR_OP_MODEX	0x01
 #define CPT_MINOR_OP_PKCS_ENC	0x02
 #define CPT_MINOR_OP_PKCS_ENC_CRT	0x03
 #define CPT_MINOR_OP_PKCS_DEC	0x04
 #define CPT_MINOR_OP_PKCS_DEC_CRT	0x05
 #define CPT_MINOR_OP_MODEX_CRT	0x06
+#define CPT_MINOR_OP_ECDSA_SIGN	0x01
+#define CPT_MINOR_OP_ECDSA_VERIFY	0x02
 
 #define CPT_BLOCK_TYPE1 0
 #define CPT_BLOCK_TYPE2 1
@@ -203,6 +206,20 @@ typedef enum {
 	CPT_8X_COMP_E_LAST_ENTRY = (0xFF)
 } cpt_comp_e_t;
 
+/**
+ * Enumeration cpt_ec_id
+ *
+ * Enumerates supported elliptic curves
+ */
+typedef enum {
+	CPT_EC_ID_P192 = 0,
+	CPT_EC_ID_P224 = 1,
+	CPT_EC_ID_P256 = 2,
+	CPT_EC_ID_P384 = 3,
+	CPT_EC_ID_P521 = 4,
+	CPT_EC_ID_PMAX = 5
+} cpt_ec_id_t;
+
 typedef struct sglist_comp {
 	union {
 		uint64_t len;
@@ -329,11 +346,32 @@ struct cpt_ctx {
 	uint8_t  auth_key[64];
 };
 
+/* Prime and order fields of built-in elliptic curves */
+struct cpt_ec_group {
+	struct {
+		/* P521 maximum length */
+		uint8_t data[66];
+		unsigned int length;
+	} prime;
+
+	struct {
+		/* P521 maximum length */
+		uint8_t data[66];
+		unsigned int length;
+	} order;
+};
+
+struct cpt_asym_ec_ctx {
+	/* Prime length defined by microcode for EC operations */
+	uint8_t curveid;
+};
+
 struct cpt_asym_sess_misc {
 	enum rte_crypto_asym_xform_type xfrm_type;
 	union {
 		struct rte_crypto_rsa_xform rsa_ctx;
 		struct rte_crypto_modex_xform mod_ctx;
+		struct cpt_asym_ec_ctx ec_ctx;
 	};
 };
 
drivers/common/cpt/cpt_pmd_ops_helper.h +19 -0
index 24c3559..716ae94 100644
@@ -40,4 +40,23 @@ cpt_pmd_ops_helper_get_mlen_sg_mode(void);
  */
 int
 cpt_pmd_ops_helper_asym_get_mlen(void);
+
+/*
+ * Initialize ECC FMUL precomputed table
+ *
+ * @param
+ *  - pointer to fpm_table iova address
+ *
+ * @return
+ *  - 0 on success, negative on error
+ */
+__rte_experimental
+int cpt_fpm_init(uint64_t *fpm_table_iova);
+
+/*
+ * Clear ECC FMUL precomputed table
+ */
+__rte_experimental
+void cpt_fpm_clear(void);
+
 #endif /* _CPT_PMD_OPS_HELPER_H_ */
drivers/common/cpt/cpt_ucode_asym.h +378 -0

400 lines not on this page · raw message

drivers/common/cpt/meson.build +2 -1
index 0a905aa..d2e84ff 100644
@@ -1,7 +1,8 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2018 Cavium, Inc
 
-sources = files('cpt_pmd_ops_helper.c')
+sources = files('cpt_fpm_tables.c',
+		'cpt_pmd_ops_helper.c')
 
 deps = ['kvargs', 'pci', 'cryptodev']
 includes += include_directories('../../crypto/octeontx')
drivers/common/cpt/rte_common_cpt_version.map +9 -0
index 7f1929d..8c65cde 100644
@@ -7,3 +7,12 @@ DPDK_20.0 {
 
 	local: *;
 };
+
+EXPERIMENTAL {
+	global:
+
+	cpt_fpm_clear;
+	cpt_fpm_init;
+
+	local: *;
+};
drivers/crypto/octeontx/otx_cryptodev_capabilities.c +11 -0
index 8c0358f..6418ad2 100644
@@ -630,6 +630,17 @@ static const struct rte_cryptodev_capabilities otx_asym_capabilities[] = {
 			}
 		}, }
 	},
+	{	/* ECDSA */
+		.op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
+		{.asym = {
+			.xform_capa = {
+				.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA,
+				.op_types = ((1 << RTE_CRYPTO_ASYM_OP_SIGN) |
+					(1 << RTE_CRYPTO_ASYM_OP_VERIFY)),
+				}
+			},
+		}
+	},
 	/* End of asymmetric capabilities */
 	RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
 };
drivers/crypto/octeontx/otx_cryptodev_ops.c +41 -2

85 lines not on this page · raw message

Signature · 1 line
2.7.4
#16 lore raw

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

In reply to Anoob Joseph

From: Sunila Sahu <[email protected]>

Adding support for ECDSA operations in crypto_octeontx2 PMD.

---
 doc/guides/cryptodevs/features/octeontx2.ini       |  8 +++--
 .../crypto/octeontx2/otx2_cryptodev_capabilities.c | 11 ++++++
 drivers/crypto/octeontx2/otx2_cryptodev_ops.c      | 39 ++++++++++++++++++++--
 3 files changed, 54 insertions(+), 4 deletions(-)
doc/guides/cryptodevs/features/octeontx2.ini +6 -2
index 7d07053..dd6369b 100644
@@ -67,5 +67,9 @@ AES GCM (256) = Y
 ; Supported Asymmetric algorithms of the 'octeontx2' crypto driver.
 ;
 [Asymmetric]
-RSA                    = Y
-Modular Exponentiation = Y
+RSA                     = Y
+DSA                     =
+Modular Exponentiation  = Y
+Modular Inversion       =
+Diffie-hellman          =
+ECDSA                   = Y
drivers/crypto/octeontx2/otx2_cryptodev_capabilities.c +11 -0
index b9e3fe3..f2079e2 100644
@@ -628,6 +628,17 @@ rte_cryptodev_capabilities otx2_cpt_capabilities[] = {
 			}
 		}, }
 	},
+	{	/* ECDSA */
+		.op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
+		{.asym = {
+			.xform_capa = {
+				.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA,
+				.op_types = ((1 << RTE_CRYPTO_ASYM_OP_SIGN) |
+					(1 << RTE_CRYPTO_ASYM_OP_VERIFY)),
+				}
+			},
+		}
+	},
 	/* End of asymmetric capabilities */
 	RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
 };
drivers/crypto/octeontx2/otx2_cryptodev_ops.c +37 -2
index 65101b0..17c755d 100644
@@ -22,6 +22,8 @@
 
 #define METABUF_POOL_CACHE_SIZE	512
 
+static uint64_t otx2_fpm_iova[CPT_EC_ID_PMAX];
+
 /* Forward declarations */
 
 static int
@@ -440,6 +442,11 @@ otx2_cpt_enqueue_asym(struct otx2_cpt_qp *qp,
 		if (unlikely(ret))
 			goto req_fail;
 		break;
+	case RTE_CRYPTO_ASYM_XFORM_ECDSA:
+		ret = cpt_enqueue_ecdsa_op(op, &params, sess, otx2_fpm_iova);
+		if (unlikely(ret))
+			goto req_fail;
+		break;
 	default:
 		op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
 		ret = -EINVAL;
@@ -641,6 +648,23 @@ otx2_cpt_asym_rsa_op(struct rte_crypto_op *cop, struct cpt_request_info *req,
 	}
 }
 
+static __rte_always_inline void
+otx2_cpt_asym_dequeue_ecdsa_op(struct rte_crypto_ecdsa_op_param *ecdsa,
+			       struct cpt_request_info *req,
+			       struct cpt_asym_ec_ctx *ec)
+{
+	int prime_len = ec_grp[ec->curveid].prime.length;
+
+	if (ecdsa->op_type == RTE_CRYPTO_ASYM_OP_VERIFY)
+		return;
+
+	/* Separate out sign r and s components */
+	memcpy(ecdsa->r.data, req->rptr, prime_len);
+	memcpy(ecdsa->s.data, req->rptr + ROUNDUP8(prime_len), prime_len);
+	ecdsa->r.length = prime_len;
+	ecdsa->s.length = prime_len;
+}
+
 static void
 otx2_cpt_asym_post_process(struct rte_crypto_op *cop,
 			   struct cpt_request_info *req)
@@ -660,6 +684,9 @@ otx2_cpt_asym_post_process(struct rte_crypto_op *cop,
 		memcpy(op->modex.result.data, req->rptr,
 		       op->modex.result.length);
 		break;
+	case RTE_CRYPTO_ASYM_XFORM_ECDSA:
+		otx2_cpt_asym_dequeue_ecdsa_op(&op->ecdsa, req, &sess->ec_ctx);
+		break;
 	default:
 		CPT_LOG_DP_DEBUG("Invalid crypto xform type");
 		cop->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
@@ -824,6 +851,13 @@ otx2_cpt_dev_config(struct rte_cryptodev *dev,
 
 	dev->feature_flags &= ~conf->ff_disable;
 
+	if (dev->feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) {
+		/* Initialize shared FPM table */
+		ret = cpt_fpm_init(otx2_fpm_iova);
+		if (ret)
+			return ret;
+	}
+
 	/* Unregister error interrupts */
 	if (vf->err_intr_registered)
 		otx2_cpt_err_intr_unregister(dev);
@@ -881,9 +915,10 @@ otx2_cpt_dev_start(struct rte_cryptodev *dev)
 static void
 otx2_cpt_dev_stop(struct rte_cryptodev *dev)
 {
-	RTE_SET_USED(dev);
-
 	CPT_PMD_INIT_FUNC_TRACE();
+
+	if (dev->feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)
+		cpt_fpm_clear();
 }
 
 static int
Signature · 1 line
2.7.4
#17 lore raw

PATCH v2 4/4 app/test: add ECDSA sign/verify tests

In reply to Anoob Joseph

From: Ayuj Verma <[email protected]>

This patch adds ECDSA sign and verify test routine and test vectors.

---
 app/test/test_cryptodev_asym.c               | 219 +++++++++++-
 app/test/test_cryptodev_asym_util.h          |  11 +
 app/test/test_cryptodev_ecdsa_test_vectors.h | 505 +++++++++++++++++++++++++++
 3 files changed, 734 insertions(+), 1 deletion(-)
 create mode 100644 app/test/test_cryptodev_ecdsa_test_vectors.h
app/test/test_cryptodev_asym.c +218 -1
index 69df293..08479bb 100644
@@ -18,6 +18,7 @@
 #include "test_cryptodev.h"
 #include "test_cryptodev_dh_test_vectors.h"
 #include "test_cryptodev_dsa_test_vectors.h"
+#include "test_cryptodev_ecdsa_test_vectors.h"
 #include "test_cryptodev_mod_test_vectors.h"
 #include "test_cryptodev_rsa_test_vectors.h"
 #include "test_cryptodev_asym_util.h"
@@ -1037,14 +1038,16 @@ static inline void print_asym_capa(
 		case RTE_CRYPTO_ASYM_XFORM_MODEX:
 		case RTE_CRYPTO_ASYM_XFORM_DH:
 		case RTE_CRYPTO_ASYM_XFORM_DSA:
-			printf(" modlen: min %d max %d increment %d\n",
+			printf(" modlen: min %d max %d increment %d",
 					capa->modlen.min,
 					capa->modlen.max,
 					capa->modlen.increment);
 		break;
+		case RTE_CRYPTO_ASYM_XFORM_ECDSA:
 		default:
 			break;
 		}
+		printf("\n");
 }
 
 static int
@@ -1892,6 +1895,218 @@ test_dsa(void)
 	return status;
 }
 
+static int
+test_ecdsa_sign_verify(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_ecdsa_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_r[TEST_DATA_SIZE];
+	uint8_t output_buf_s[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 = ecdsa_param_secp192r1;
+		break;
+	case SECP224R1:
+		input_params = ecdsa_param_secp224r1;
+		break;
+	case SECP256R1:
+		input_params = ecdsa_param_secp256r1;
+		break;
+	case SECP384R1:
+		input_params = ecdsa_param_secp384r1;
+		break;
+	case SECP521R1:
+		input_params = ecdsa_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_ECDSA;
+	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);
+
+	/* Compute sign */
+
+	/* Populate op with operational details */
+	op->asym->ecdsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
+	op->asym->ecdsa.message.data = input_params.digest.data;
+	op->asym->ecdsa.message.length = input_params.digest.length;
+	op->asym->ecdsa.k.data = input_params.scalar.data;
+	op->asym->ecdsa.k.length = input_params.scalar.length;
+	op->asym->ecdsa.pkey.data = input_params.pkey.data;
+	op->asym->ecdsa.pkey.length = input_params.pkey.length;
+
+	/* Init out buf */
+	op->asym->ecdsa.r.data = output_buf_r;
+	op->asym->ecdsa.s.data = output_buf_s;
+
+	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:",
+			asym_op->ecdsa.r.data, asym_op->ecdsa.r.length);
+	debug_hexdump(stdout, "s:",
+			asym_op->ecdsa.s.data, asym_op->ecdsa.s.length);
+
+	ret = verify_ecdsa_sign(input_params.sign_r.data,
+				input_params.sign_s.data, result_op);
+	if (ret) {
+		status = TEST_FAILED;
+		RTE_LOG(ERR, USER1,
+				"line %u FAILED: %s", __LINE__,
+				"ECDSA sign failed.\n");
+		goto exit;
+	}
+
+	/* Verify sign */
+
+	/* Populate op with operational details */
+	op->asym->ecdsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
+	op->asym->ecdsa.q.x.data = input_params.pubkey_qx.data;
+	op->asym->ecdsa.q.x.length = input_params.pubkey_qx.length;
+	op->asym->ecdsa.q.y.data = input_params.pubkey_qy.data;
+	op->asym->ecdsa.q.y.length = input_params.pubkey_qx.length;
+	op->asym->ecdsa.r.data = asym_op->ecdsa.r.data;
+	op->asym->ecdsa.r.length = asym_op->ecdsa.r.length;
+	op->asym->ecdsa.s.data = asym_op->ecdsa.s.data;
+	op->asym->ecdsa.s.length = asym_op->ecdsa.s.length;
+
+	/* Enqueue sign result for verify */
+	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
+		status = TEST_FAILED;
+		RTE_LOG(ERR, USER1,
+				"line %u FAILED: %s", __LINE__,
+				"Error sending packet for operation\n");
+		goto exit;
+	}
+
+	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
+		rte_pause();
+
+	if (result_op == NULL) {
+		status = TEST_FAILED;
+		goto exit;
+	}
+	if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
+		status = TEST_FAILED;
+		RTE_LOG(ERR, USER1,
+				"line %u FAILED: %s", __LINE__,
+				"ECDSA verify 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_ecdsa_sign_verify_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_ecdsa_sign_verify(curve_id);
+		if (status == TEST_SUCCESS) {
+			msg = "succeeded";
+		} else {
+			msg = "failed";
+			overall_status = status;
+		}
+		printf("  %u) TestCase Sign/Veriy 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",
@@ -1931,6 +2146,8 @@ static struct unit_test_suite cryptodev_octeontx_asym_testsuite  = {
 		TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_enc_dec_crt),
 		TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_sign_verify_crt),
 		TEST_CASE_ST(ut_setup, ut_teardown, test_mod_exp),
+		TEST_CASE_ST(ut_setup, ut_teardown,
+			     test_ecdsa_sign_verify_all_curve),
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	}
 };
app/test/test_cryptodev_asym_util.h +11 -0
index f2a8e6c..bddeda0 100644
@@ -35,4 +35,15 @@ static inline int verify_modexp(uint8_t *mod_exp,
 	return 0;
 }
 
+static inline int verify_ecdsa_sign(uint8_t *sign_r,
+		uint8_t *sign_s, struct rte_crypto_op *result_op)
+{
+	if (memcmp(sign_r, result_op->asym->ecdsa.r.data,
+		   result_op->asym->ecdsa.r.length) ||
+		   memcmp(sign_s, result_op->asym->ecdsa.s.data,
+		   result_op->asym->ecdsa.s.length))
+		return -1;
+	return 0;
+}
+
 #endif /* TEST_CRYPTODEV_ASYM_TEST_UTIL_H__ */
app/test/test_cryptodev_ecdsa_test_vectors.h new file +505 -0

505 lines not on this page · raw message

Signature · 1 line
2.7.4
Applied
#18 lore raw
In reply to Anoob Joseph
Quoted 34 lines

This series adds support for ECDSA asymmetric operations. Library changes and PMD changes for crypto_octeontx & crypto_octoentx2 is added. The final patch adds the required test vectors and verification routines.

v2:
* Changed all NIST references to use SECP.
* Minor updates to documentation/comments as suggested by Arek
* Updated release notes

Ayuj Verma (2):
cryptodev: support ECDSA
app/test: add ECDSA sign/verify tests

Sunila Sahu (2):
crypto/octeontx: add ECDSA support
crypto/octeontx2: add ECDSA support

 app/test/test_cryptodev_asym.c                     |  219 +++-
 app/test/test_cryptodev_asym_util.h                |   11 +
 app/test/test_cryptodev_ecdsa_test_vectors.h       |  505 +++++++++
 doc/guides/cryptodevs/features/default.ini         |   11 +-
 doc/guides/cryptodevs/features/octeontx.ini        |    8 +-
 doc/guides/cryptodevs/features/octeontx2.ini       |    8 +-
 doc/guides/rel_notes/release_20_02.rst             |    4 +
 drivers/common/cpt/Makefile                        |    1 +
 drivers/common/cpt/cpt_fpm_tables.c                | 1138 ++++++++++++++++++++
 drivers/common/cpt/cpt_mcode_defines.h             |   38 +
 drivers/common/cpt/cpt_pmd_ops_helper.h            |   19 +
 drivers/common/cpt/cpt_ucode_asym.h                |  378 +++++++
 drivers/common/cpt/meson.build                     |    3 +-
 drivers/common/cpt/rte_common_cpt_version.map      |    9 +
 .../crypto/octeontx/otx_cryptodev_capabilities.c   |   11 +
Quoted 9 lines
 drivers/crypto/octeontx/otx_cryptodev_ops.c        |   43 +-
 .../crypto/octeontx2/otx2_cryptodev_capabilities.c |   11 +
 drivers/crypto/octeontx2/otx2_cryptodev_ops.c      |   39 +-
 lib/librte_cryptodev/rte_crypto_asym.h             |   84 ++
 lib/librte_cryptodev/rte_cryptodev.c               |    1 +
 20 files changed, 2526 insertions(+), 15 deletions(-)
 create mode 100644 app/test/test_cryptodev_ecdsa_test_vectors.h
 create mode 100644 drivers/common/cpt/cpt_fpm_tables.c

Applied to dpdk-next-crypto

Thanks.