Skip to contentSkip to conversation

add ECDH and CURVE25519 algorithms support for Kunpeng 930

PATCH Superseded Meng Yu 3 participants 15 messages Dec 11, 2020 – Dec 19, 2020 3 messages not in the archive

Subsystems (6)

v4 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Meng Yu

author
#0 lore raw

v4 cover add ECDH and CURVE25519 algorithms support for Kunpeng 930

1. Move elliptic curve parameter definitions out to "include/crypto";
2. Add some new elliptic curve parameters definitions, and reorder ECC 'Curves IDs';
3. Add ECDH and CURVE25519 algorithms support for Kunpeng 930.

These patches depend on:
[v2,1/6] crypto: hisilicon/hpre - add version adapt to new algorithms,
https://patchwork.kernel.org/project/linux-crypto/patch/1607598607-8728-
[email protected]/

v3 -> v4:
- patch #3: add new, move ecc_curve params to "include/crypto"

v2 -> v3:
- patch #5: fix sparse warnings
- patch #5: add 'CRYPTO_LIB_CURVE25519_GENERIC' in 'Kconfig'

v1 -> v2:
- patch #5: delete `curve25519_null_point'

Hui Tang (1):
crypto: hisilicon/hpre - add some updates to adapt to Kunpeng 930

Meng Yu (4):
crypto: hisilicon/hpre - add algorithm type
crypto: expose elliptic curve parameters as Crypto APIs
crypto: hisilicon/hpre - add 'ECDH' algorithm
crypto: hisilicon/hpre - add 'CURVE25519' algorithm

 crypto/ecc.c                                |   5 +-
 crypto/ecc.h                                |  37 +-
 crypto/ecc_curve_defs.h                     |  57 --
 crypto/ecrdsa_defs.h                        |   2 +-
 crypto/testmgr.h                            |  12 +-
 drivers/crypto/hisilicon/Kconfig            |   1 +
 drivers/crypto/hisilicon/hpre/hpre.h        |  22 +-
 drivers/crypto/hisilicon/hpre/hpre_crypto.c | 868 +++++++++++++++++++++++++++-
 drivers/crypto/hisilicon/hpre/hpre_main.c   | 105 +++-
 include/crypto/ecc_curve_defs.h             | 261 +++++++++
 include/crypto/ecdh.h                       |   9 +-
 11 files changed, 1228 insertions(+), 151 deletions(-)
 delete mode 100644 crypto/ecc_curve_defs.h
 create mode 100644 include/crypto/ecc_curve_defs.h
Signature · 1 line
2.8.1
author
#1 lore raw

PATCH v4 1/5 crypto: hisilicon/hpre - add some updates to adapt to Kunpeng 930

From: Hui Tang <[email protected]>

HPRE of Kunpeng 930 is updated on cluster numbers and configurations of Kunpeng 920 HPRE, so we try to update this driver to make it running okay on both chips.

---
 drivers/crypto/hisilicon/hpre/hpre.h      |  8 ++-
 drivers/crypto/hisilicon/hpre/hpre_main.c | 93 +++++++++++++++++++++----------
 2 files changed, 68 insertions(+), 33 deletions(-)
drivers/crypto/hisilicon/hpre/hpre.h +5 -3
index e784712..cc50f23 100644
@@ -14,8 +14,7 @@ enum {
 	HPRE_CLUSTER0,
 	HPRE_CLUSTER1,
 	HPRE_CLUSTER2,
-	HPRE_CLUSTER3,
-	HPRE_CLUSTERS_NUM,
+	HPRE_CLUSTER3
 };
 
 enum hpre_ctrl_dbgfs_file {
@@ -36,7 +35,10 @@ enum hpre_dfx_dbgfs_file {
 	HPRE_DFX_FILE_NUM
 };
 
-#define HPRE_DEBUGFS_FILE_NUM    (HPRE_DEBUG_FILE_NUM + HPRE_CLUSTERS_NUM - 1)
+#define HPRE_CLUSTERS_NUM_V2		(HPRE_CLUSTER3 + 1)
+#define HPRE_CLUSTERS_NUM_V3		1
+#define HPRE_CLUSTERS_NUM_MAX		HPRE_CLUSTERS_NUM_V2
+#define HPRE_DEBUGFS_FILE_NUM (HPRE_DEBUG_FILE_NUM + HPRE_CLUSTERS_NUM_MAX - 1)
 
 struct hpre_debugfs_file {
 	int index;
drivers/crypto/hisilicon/hpre/hpre_main.c +63 -30

163 lines not on this page · raw message

Signature · 1 line
2.8.1
author
#2 lore raw

PATCH v4 2/5 crypto: hisilicon/hpre - add algorithm type

In reply to Meng Yu

Algorithm type is brought in to get hardware HPRE queue to support different algorithms.

---
 drivers/crypto/hisilicon/hpre/hpre.h        | 10 +++++++++-
 drivers/crypto/hisilicon/hpre/hpre_crypto.c | 12 ++++++------
 drivers/crypto/hisilicon/hpre/hpre_main.c   | 11 +++++++++--
 3 files changed, 24 insertions(+), 9 deletions(-)
drivers/crypto/hisilicon/hpre/hpre.h +9 -1
index cc50f23..02193e1 100644
@@ -10,6 +10,14 @@
 #define HPRE_PF_DEF_Q_NUM		64
 #define HPRE_PF_DEF_Q_BASE		0
 
+/*
+ * type used in qm sqc DW6.
+ * 0 - Algorithm which has been supported in V2, like RSA, DH and so on;
+ * 1 - ECC algorithm in V3.
+ */
+#define HPRE_V2_ALG_TYPE	0
+#define HPRE_V3_ECC_ALG_TYPE	1
+
 enum {
 	HPRE_CLUSTER0,
 	HPRE_CLUSTER1,
@@ -92,7 +100,7 @@ struct hpre_sqe {
 	__le32 rsvd1[_HPRE_SQE_ALIGN_EXT];
 };
 
-struct hisi_qp *hpre_create_qp(void);
+struct hisi_qp *hpre_create_qp(u8 type);
 int hpre_algs_register(struct hisi_qm *qm);
 void hpre_algs_unregister(struct hisi_qm *qm);
 
drivers/crypto/hisilicon/hpre/hpre_crypto.c +6 -6
index d89b2f5..712bea9 100644
@@ -152,12 +152,12 @@ static void hpre_rm_req_from_ctx(struct hpre_asym_request *hpre_req)
 	}
 }
 
-static struct hisi_qp *hpre_get_qp_and_start(void)
+static struct hisi_qp *hpre_get_qp_and_start(u8 type)
 {
 	struct hisi_qp *qp;
 	int ret;
 
-	qp = hpre_create_qp();
+	qp = hpre_create_qp(type);
 	if (!qp) {
 		pr_err("Can not create hpre qp!\n");
 		return ERR_PTR(-ENODEV);
@@ -422,11 +422,11 @@ static void hpre_alg_cb(struct hisi_qp *qp, void *resp)
 	req->cb(ctx, resp);
 }
 
-static int hpre_ctx_init(struct hpre_ctx *ctx)
+static int hpre_ctx_init(struct hpre_ctx *ctx, u8 type)
 {
 	struct hisi_qp *qp;
 
-	qp = hpre_get_qp_and_start();
+	qp = hpre_get_qp_and_start(type);
 	if (IS_ERR(qp))
 		return PTR_ERR(qp);
 
@@ -674,7 +674,7 @@ static int hpre_dh_init_tfm(struct crypto_kpp *tfm)
 {
 	struct hpre_ctx *ctx = kpp_tfm_ctx(tfm);
 
-	return hpre_ctx_init(ctx);
+	return hpre_ctx_init(ctx, HPRE_V2_ALG_TYPE);
 }
 
 static void hpre_dh_exit_tfm(struct crypto_kpp *tfm)
@@ -1100,7 +1100,7 @@ static int hpre_rsa_init_tfm(struct crypto_akcipher *tfm)
 		return PTR_ERR(ctx->rsa.soft_tfm);
 	}
 
-	ret = hpre_ctx_init(ctx);
+	ret = hpre_ctx_init(ctx, HPRE_V2_ALG_TYPE);
 	if (ret)
 		crypto_free_akcipher(ctx->rsa.soft_tfm);
 
drivers/crypto/hisilicon/hpre/hpre_main.c +9 -2
index fc7173a..1ae8fa1 100644
@@ -209,13 +209,20 @@ static u32 vfs_num;
 module_param_cb(vfs_num, &vfs_num_ops, &vfs_num, 0444);
 MODULE_PARM_DESC(vfs_num, "Number of VFs to enable(1-63), 0(default)");
 
-struct hisi_qp *hpre_create_qp(void)
+struct hisi_qp *hpre_create_qp(u8 type)
 {
 	int node = cpu_to_node(smp_processor_id());
 	struct hisi_qp *qp = NULL;
 	int ret;
 
-	ret = hisi_qm_alloc_qps_node(&hpre_devices, 1, 0, node, &qp);
+	if (type != HPRE_V2_ALG_TYPE && type != HPRE_V3_ECC_ALG_TYPE)
+		return NULL;
+
+	/*
+	 * type: 0 - RSA/DH. algorithm supported in V2,
+	 *       1 - ECC algorithm in V3.
+	 */
+	ret = hisi_qm_alloc_qps_node(&hpre_devices, 1, type, node, &qp);
 	if (!ret)
 		return qp;
 
Signature · 1 line
2.8.1
author
#3 lore raw

PATCH v4 3/5 crypto: expose elliptic curve parameters as Crypto APIs

In reply to Meng Yu

Move elliptic curves definition to 'include/crypto/ecc_curve_defs.h', so all can use it,

---
 crypto/ecc.c                    |  1 -
 crypto/ecc.h                    | 37 +----------------
 crypto/ecc_curve_defs.h         | 57 -------------------------
 crypto/ecrdsa_defs.h            |  2 +-
 include/crypto/ecc_curve_defs.h | 92 +++++++++++++++++++++++++++++++++++++++++
 5 files changed, 95 insertions(+), 94 deletions(-)
 delete mode 100644 crypto/ecc_curve_defs.h
 create mode 100644 include/crypto/ecc_curve_defs.h
crypto/ecc.c +0 -1
index c80aa25..f23efdd 100644
@@ -35,7 +35,6 @@
 #include <linux/ratelimit.h>
 
 #include "ecc.h"
-#include "ecc_curve_defs.h"
 
 typedef struct {
 	u64 m_low;
crypto/ecc.h +2 -35
index d4e546b..e5afaf3 100644
@@ -26,6 +26,8 @@
 #ifndef _CRYPTO_ECC_H
 #define _CRYPTO_ECC_H
 
+#include <crypto/ecc_curve_defs.h>
+
 /* One digit is u64 qword. */
 #define ECC_CURVE_NIST_P192_DIGITS  3
 #define ECC_CURVE_NIST_P256_DIGITS  4
@@ -33,44 +35,9 @@
 
 #define ECC_DIGITS_TO_BYTES_SHIFT 3
 
-/**
- * struct ecc_point - elliptic curve point in affine coordinates
- *
- * @x:		X coordinate in vli form.
- * @y:		Y coordinate in vli form.
- * @ndigits:	Length of vlis in u64 qwords.
- */
-struct ecc_point {
-	u64 *x;
-	u64 *y;
-	u8 ndigits;
-};
-
 #define ECC_POINT_INIT(x, y, ndigits)	(struct ecc_point) { x, y, ndigits }
 
 /**
- * struct ecc_curve - definition of elliptic curve
- *
- * @name:	Short name of the curve.
- * @g:		Generator point of the curve.
- * @p:		Prime number, if Barrett's reduction is used for this curve
- *		pre-calculated value 'mu' is appended to the @p after ndigits.
- *		Use of Barrett's reduction is heuristically determined in
- *		vli_mmod_fast().
- * @n:		Order of the curve group.
- * @a:		Curve parameter a.
- * @b:		Curve parameter b.
- */
-struct ecc_curve {
-	char *name;
-	struct ecc_point g;
-	u64 *p;
-	u64 *n;
-	u64 *a;
-	u64 *b;
-};
-
-/**
  * ecc_is_key_valid() - Validate a given ECDH private key
  *
  * @curve_id:		id representing the curve to use
crypto/ecc_curve_defs.h deleted +0 -57

57 lines not on this page · raw message

crypto/ecrdsa_defs.h +1 -1
index 170baf0..2074099 100644
@@ -13,7 +13,7 @@
 #ifndef _CRYTO_ECRDSA_DEFS_H
 #define _CRYTO_ECRDSA_DEFS_H
 
-#include "ecc.h"
+#include <crypto/ecc_curve_defs.h>
 
 #define ECRDSA_MAX_SIG_SIZE (2 * 512 / 8)
 #define ECRDSA_MAX_DIGITS (512 / 64)
include/crypto/ecc_curve_defs.h new file +92 -0

92 lines not on this page · raw message

Signature · 1 line
2.8.1
#4 lore raw

Re: [PATCH v4 3/5] crypto: expose elliptic curve parameters as Crypto APIs

Meng,

It looks like not just definitions but some static data is moved to includes. Why?

Thanks,

Quoted 261 lines · Meng Yu

Move elliptic curves definition to 'include/crypto/ecc_curve_defs.h', so all can use it,

---
 crypto/ecc.c                    |  1 -
 crypto/ecc.h                    | 37 +----------------
 crypto/ecc_curve_defs.h         | 57 -------------------------
 crypto/ecrdsa_defs.h            |  2 +-
 include/crypto/ecc_curve_defs.h | 92 +++++++++++++++++++++++++++++++++++++++++
 5 files changed, 95 insertions(+), 94 deletions(-)
 delete mode 100644 crypto/ecc_curve_defs.h
 create mode 100644 include/crypto/ecc_curve_defs.h
crypto/ecc.c +0 -1
index c80aa25..f23efdd 100644
@@ -35,7 +35,6 @@
 #include <linux/ratelimit.h>
 
 #include "ecc.h"
-#include "ecc_curve_defs.h"
 
 typedef struct {
 	u64 m_low;
crypto/ecc.h +2 -35
index d4e546b..e5afaf3 100644
@@ -26,6 +26,8 @@
 #ifndef _CRYPTO_ECC_H
 #define _CRYPTO_ECC_H
 
+#include <crypto/ecc_curve_defs.h>
+
 /* One digit is u64 qword. */
 #define ECC_CURVE_NIST_P192_DIGITS  3
 #define ECC_CURVE_NIST_P256_DIGITS  4
@@ -33,44 +35,9 @@
 
 #define ECC_DIGITS_TO_BYTES_SHIFT 3
 
-/**
- * struct ecc_point - elliptic curve point in affine coordinates
- *
- * @x:		X coordinate in vli form.
- * @y:		Y coordinate in vli form.
- * @ndigits:	Length of vlis in u64 qwords.
- */
-struct ecc_point {
-	u64 *x;
-	u64 *y;
-	u8 ndigits;
-};
-
 #define ECC_POINT_INIT(x, y, ndigits)	(struct ecc_point) { x, y, ndigits }
 
 /**
- * struct ecc_curve - definition of elliptic curve
- *
- * @name:	Short name of the curve.
- * @g:		Generator point of the curve.
- * @p:		Prime number, if Barrett's reduction is used for this curve
- *		pre-calculated value 'mu' is appended to the @p after ndigits.
- *		Use of Barrett's reduction is heuristically determined in
- *		vli_mmod_fast().
- * @n:		Order of the curve group.
- * @a:		Curve parameter a.
- * @b:		Curve parameter b.
- */
-struct ecc_curve {
-	char *name;
-	struct ecc_point g;
-	u64 *p;
-	u64 *n;
-	u64 *a;
-	u64 *b;
-};
-
-/**
  * ecc_is_key_valid() - Validate a given ECDH private key
  *
  * @curve_id:		id representing the curve to use
crypto/ecc_curve_defs.h deleted +0 -57
deleted file mode 100644
index 69be6c7..0000000
@@ -1,57 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _CRYTO_ECC_CURVE_DEFS_H
-#define _CRYTO_ECC_CURVE_DEFS_H
-
-/* NIST P-192: a = p - 3 */
-static u64 nist_p192_g_x[] = { 0xF4FF0AFD82FF1012ull, 0x7CBF20EB43A18800ull,
-				0x188DA80EB03090F6ull };
-static u64 nist_p192_g_y[] = { 0x73F977A11E794811ull, 0x631011ED6B24CDD5ull,
-				0x07192B95FFC8DA78ull };
-static u64 nist_p192_p[] = { 0xFFFFFFFFFFFFFFFFull, 0xFFFFFFFFFFFFFFFEull,
-				0xFFFFFFFFFFFFFFFFull };
-static u64 nist_p192_n[] = { 0x146BC9B1B4D22831ull, 0xFFFFFFFF99DEF836ull,
-				0xFFFFFFFFFFFFFFFFull };
-static u64 nist_p192_a[] = { 0xFFFFFFFFFFFFFFFCull, 0xFFFFFFFFFFFFFFFEull,
-				0xFFFFFFFFFFFFFFFFull };
-static u64 nist_p192_b[] = { 0xFEB8DEECC146B9B1ull, 0x0FA7E9AB72243049ull,
-				0x64210519E59C80E7ull };
-static struct ecc_curve nist_p192 = {
-	.name = "nist_192",
-	.g = {
-		.x = nist_p192_g_x,
-		.y = nist_p192_g_y,
-		.ndigits = 3,
-	},
-	.p = nist_p192_p,
-	.n = nist_p192_n,
-	.a = nist_p192_a,
-	.b = nist_p192_b
-};
-
-/* NIST P-256: a = p - 3 */
-static u64 nist_p256_g_x[] = { 0xF4A13945D898C296ull, 0x77037D812DEB33A0ull,
-				0xF8BCE6E563A440F2ull, 0x6B17D1F2E12C4247ull };
-static u64 nist_p256_g_y[] = { 0xCBB6406837BF51F5ull, 0x2BCE33576B315ECEull,
-				0x8EE7EB4A7C0F9E16ull, 0x4FE342E2FE1A7F9Bull };
-static u64 nist_p256_p[] = { 0xFFFFFFFFFFFFFFFFull, 0x00000000FFFFFFFFull,
-				0x0000000000000000ull, 0xFFFFFFFF00000001ull };
-static u64 nist_p256_n[] = { 0xF3B9CAC2FC632551ull, 0xBCE6FAADA7179E84ull,
-				0xFFFFFFFFFFFFFFFFull, 0xFFFFFFFF00000000ull };
-static u64 nist_p256_a[] = { 0xFFFFFFFFFFFFFFFCull, 0x00000000FFFFFFFFull,
-				0x0000000000000000ull, 0xFFFFFFFF00000001ull };
-static u64 nist_p256_b[] = { 0x3BCE3C3E27D2604Bull, 0x651D06B0CC53B0F6ull,
-				0xB3EBBD55769886BCull, 0x5AC635D8AA3A93E7ull };
-static struct ecc_curve nist_p256 = {
-	.name = "nist_256",
-	.g = {
-		.x = nist_p256_g_x,
-		.y = nist_p256_g_y,
-		.ndigits = 4,
-	},
-	.p = nist_p256_p,
-	.n = nist_p256_n,
-	.a = nist_p256_a,
-	.b = nist_p256_b
-};
-
-#endif
crypto/ecrdsa_defs.h +1 -1
index 170baf0..2074099 100644
@@ -13,7 +13,7 @@
 #ifndef _CRYTO_ECRDSA_DEFS_H
 #define _CRYTO_ECRDSA_DEFS_H
 
-#include "ecc.h"
+#include <crypto/ecc_curve_defs.h>
 
 #define ECRDSA_MAX_SIG_SIZE (2 * 512 / 8)
 #define ECRDSA_MAX_DIGITS (512 / 64)
include/crypto/ecc_curve_defs.h new file +92 -0
new file mode 100644
index 0000000..1080766
@@ -0,0 +1,92 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _CRYTO_ECC_CURVE_DEFS_H
+#define _CRYTO_ECC_CURVE_DEFS_H
+
+/**
+ * struct ecc_point - elliptic curve point in affine coordinates
+ *
+ * @x:		X coordinate in vli form.
+ * @y:		Y coordinate in vli form.
+ * @ndigits:	Length of vlis in u64 qwords.
+ */
+struct ecc_point {
+	u64 *x;
+	u64 *y;
+	u8 ndigits;
+};
+
+/**
+ * struct ecc_curve - definition of elliptic curve
+ *
+ * @name:	Short name of the curve.
+ * @g:		Generator point of the curve.
+ * @p:		Prime number, if Barrett's reduction is used for this curve
+ *		pre-calculated value 'mu' is appended to the @p after ndigits.
+ *		Use of Barrett's reduction is heuristically determined in
+ *		vli_mmod_fast().
+ * @n:		Order of the curve group.
+ * @a:		Curve parameter a.
+ * @b:		Curve parameter b.
+ */
+struct ecc_curve {
+	char *name;
+	struct ecc_point g;
+	u64 *p;
+	u64 *n;
+	u64 *a;
+	u64 *b;
+};
+
+/* NIST P-192: a = p - 3 */
+static u64 nist_p192_g_x[] = { 0xF4FF0AFD82FF1012ull, 0x7CBF20EB43A18800ull,
+				0x188DA80EB03090F6ull };
+static u64 nist_p192_g_y[] = { 0x73F977A11E794811ull, 0x631011ED6B24CDD5ull,
+				0x07192B95FFC8DA78ull };
+static u64 nist_p192_p[] = { 0xFFFFFFFFFFFFFFFFull, 0xFFFFFFFFFFFFFFFEull,
+				0xFFFFFFFFFFFFFFFFull };
+static u64 nist_p192_n[] = { 0x146BC9B1B4D22831ull, 0xFFFFFFFF99DEF836ull,
+				0xFFFFFFFFFFFFFFFFull };
+static u64 nist_p192_a[] = { 0xFFFFFFFFFFFFFFFCull, 0xFFFFFFFFFFFFFFFEull,
+				0xFFFFFFFFFFFFFFFFull };
+static u64 nist_p192_b[] = { 0xFEB8DEECC146B9B1ull, 0x0FA7E9AB72243049ull,
+				0x64210519E59C80E7ull };
+static struct ecc_curve nist_p192 = {
+	.name = "nist_192",
+	.g = {
+		.x = nist_p192_g_x,
+		.y = nist_p192_g_y,
+		.ndigits = 3,
+	},
+	.p = nist_p192_p,
+	.n = nist_p192_n,
+	.a = nist_p192_a,
+	.b = nist_p192_b
+};
+
+/* NIST P-256: a = p - 3 */
+static u64 nist_p256_g_x[] = { 0xF4A13945D898C296ull, 0x77037D812DEB33A0ull,
+				0xF8BCE6E563A440F2ull, 0x6B17D1F2E12C4247ull };
+static u64 nist_p256_g_y[] = { 0xCBB6406837BF51F5ull, 0x2BCE33576B315ECEull,
+				0x8EE7EB4A7C0F9E16ull, 0x4FE342E2FE1A7F9Bull };
+static u64 nist_p256_p[] = { 0xFFFFFFFFFFFFFFFFull, 0x00000000FFFFFFFFull,
+				0x0000000000000000ull, 0xFFFFFFFF00000001ull };
+static u64 nist_p256_n[] = { 0xF3B9CAC2FC632551ull, 0xBCE6FAADA7179E84ull,
+				0xFFFFFFFFFFFFFFFFull, 0xFFFFFFFF00000000ull };
+static u64 nist_p256_a[] = { 0xFFFFFFFFFFFFFFFCull, 0x00000000FFFFFFFFull,
+				0x0000000000000000ull, 0xFFFFFFFF00000001ull };
+static u64 nist_p256_b[] = { 0x3BCE3C3E27D2604Bull, 0x651D06B0CC53B0F6ull,
+				0xB3EBBD55769886BCull, 0x5AC635D8AA3A93E7ull };
+static struct ecc_curve nist_p256 = {
+	.name = "nist_256",
+	.g = {
+		.x = nist_p256_g_x,
+		.y = nist_p256_g_y,
+		.ndigits = 4,
+	},
+	.p = nist_p256_p,
+	.n = nist_p256_n,
+	.a = nist_p256_a,
+	.b = nist_p256_b
+};
+
+#endif
Signature · 1 line
2.8.1

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#6 lore raw

Re: Fwd: Re: [PATCH v4 3/5] crypto: expose elliptic curve parameters as Crypto APIs

Quoted 7 lines

Meng,

It looks like not just definitions but some static data is moved to includes. Why?

Thanks,

Yes, as both 'crypto' and HPRE use elliptic curves parameters, once we keep them in 'include/crypto/ecc_curve_defs.h', crypto drivers can use curves parameters without redefining them.

Thanks,

Quoted 264 lines · Meng Yu
Quoted 261 lines

Move elliptic curves definition to 'include/crypto/ecc_curve_defs.h', so all can use it,

---
 crypto/ecc.c                    |  1 -
 crypto/ecc.h                    | 37 +----------------
 crypto/ecc_curve_defs.h         | 57 -------------------------
 crypto/ecrdsa_defs.h            |  2 +-
 include/crypto/ecc_curve_defs.h | 92 +++++++++++++++++++++++++++++++++++++++++
 5 files changed, 95 insertions(+), 94 deletions(-)
 delete mode 100644 crypto/ecc_curve_defs.h
 create mode 100644 include/crypto/ecc_curve_defs.h
crypto/ecc.c +0 -1
index c80aa25..f23efdd 100644
@@ -35,7 +35,6 @@
 #include <linux/ratelimit.h>
 
 #include "ecc.h"
-#include "ecc_curve_defs.h"
 
 typedef struct {
 	u64 m_low;
crypto/ecc.h +2 -35
index d4e546b..e5afaf3 100644
@@ -26,6 +26,8 @@
 #ifndef _CRYPTO_ECC_H
 #define _CRYPTO_ECC_H
 
+#include <crypto/ecc_curve_defs.h>
+
 /* One digit is u64 qword. */
 #define ECC_CURVE_NIST_P192_DIGITS  3
 #define ECC_CURVE_NIST_P256_DIGITS  4
@@ -33,44 +35,9 @@
 
 #define ECC_DIGITS_TO_BYTES_SHIFT 3
 
-/**
- * struct ecc_point - elliptic curve point in affine coordinates
- *
- * @x:		X coordinate in vli form.
- * @y:		Y coordinate in vli form.
- * @ndigits:	Length of vlis in u64 qwords.
- */
-struct ecc_point {
-	u64 *x;
-	u64 *y;
-	u8 ndigits;
-};
-
 #define ECC_POINT_INIT(x, y, ndigits)	(struct ecc_point) { x, y, ndigits }
 
 /**
- * struct ecc_curve - definition of elliptic curve
- *
- * @name:	Short name of the curve.
- * @g:		Generator point of the curve.
- * @p:		Prime number, if Barrett's reduction is used for this curve
- *		pre-calculated value 'mu' is appended to the @p after ndigits.
- *		Use of Barrett's reduction is heuristically determined in
- *		vli_mmod_fast().
- * @n:		Order of the curve group.
- * @a:		Curve parameter a.
- * @b:		Curve parameter b.
- */
-struct ecc_curve {
-	char *name;
-	struct ecc_point g;
-	u64 *p;
-	u64 *n;
-	u64 *a;
-	u64 *b;
-};
-
-/**
  * ecc_is_key_valid() - Validate a given ECDH private key
  *
  * @curve_id:		id representing the curve to use
crypto/ecc_curve_defs.h deleted +0 -57
deleted file mode 100644
index 69be6c7..0000000
@@ -1,57 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _CRYTO_ECC_CURVE_DEFS_H
-#define _CRYTO_ECC_CURVE_DEFS_H
-
-/* NIST P-192: a = p - 3 */
-static u64 nist_p192_g_x[] = { 0xF4FF0AFD82FF1012ull, 0x7CBF20EB43A18800ull,
-				0x188DA80EB03090F6ull };
-static u64 nist_p192_g_y[] = { 0x73F977A11E794811ull, 0x631011ED6B24CDD5ull,
-				0x07192B95FFC8DA78ull };
-static u64 nist_p192_p[] = { 0xFFFFFFFFFFFFFFFFull, 0xFFFFFFFFFFFFFFFEull,
-				0xFFFFFFFFFFFFFFFFull };
-static u64 nist_p192_n[] = { 0x146BC9B1B4D22831ull, 0xFFFFFFFF99DEF836ull,
-				0xFFFFFFFFFFFFFFFFull };
-static u64 nist_p192_a[] = { 0xFFFFFFFFFFFFFFFCull, 0xFFFFFFFFFFFFFFFEull,
-				0xFFFFFFFFFFFFFFFFull };
-static u64 nist_p192_b[] = { 0xFEB8DEECC146B9B1ull, 0x0FA7E9AB72243049ull,
-				0x64210519E59C80E7ull };
-static struct ecc_curve nist_p192 = {
-	.name = "nist_192",
-	.g = {
-		.x = nist_p192_g_x,
-		.y = nist_p192_g_y,
-		.ndigits = 3,
-	},
-	.p = nist_p192_p,
-	.n = nist_p192_n,
-	.a = nist_p192_a,
-	.b = nist_p192_b
-};
-
-/* NIST P-256: a = p - 3 */
-static u64 nist_p256_g_x[] = { 0xF4A13945D898C296ull, 0x77037D812DEB33A0ull,
-				0xF8BCE6E563A440F2ull, 0x6B17D1F2E12C4247ull };
-static u64 nist_p256_g_y[] = { 0xCBB6406837BF51F5ull, 0x2BCE33576B315ECEull,
-				0x8EE7EB4A7C0F9E16ull, 0x4FE342E2FE1A7F9Bull };
-static u64 nist_p256_p[] = { 0xFFFFFFFFFFFFFFFFull, 0x00000000FFFFFFFFull,
-				0x0000000000000000ull, 0xFFFFFFFF00000001ull };
-static u64 nist_p256_n[] = { 0xF3B9CAC2FC632551ull, 0xBCE6FAADA7179E84ull,
-				0xFFFFFFFFFFFFFFFFull, 0xFFFFFFFF00000000ull };
-static u64 nist_p256_a[] = { 0xFFFFFFFFFFFFFFFCull, 0x00000000FFFFFFFFull,
-				0x0000000000000000ull, 0xFFFFFFFF00000001ull };
-static u64 nist_p256_b[] = { 0x3BCE3C3E27D2604Bull, 0x651D06B0CC53B0F6ull,
-				0xB3EBBD55769886BCull, 0x5AC635D8AA3A93E7ull };
-static struct ecc_curve nist_p256 = {
-	.name = "nist_256",
-	.g = {
-		.x = nist_p256_g_x,
-		.y = nist_p256_g_y,
-		.ndigits = 4,
-	},
-	.p = nist_p256_p,
-	.n = nist_p256_n,
-	.a = nist_p256_a,
-	.b = nist_p256_b
-};
-
-#endif
crypto/ecrdsa_defs.h +1 -1
index 170baf0..2074099 100644
@@ -13,7 +13,7 @@
 #ifndef _CRYTO_ECRDSA_DEFS_H
 #define _CRYTO_ECRDSA_DEFS_H
 
-#include "ecc.h"
+#include <crypto/ecc_curve_defs.h>
 
 #define ECRDSA_MAX_SIG_SIZE (2 * 512 / 8)
 #define ECRDSA_MAX_DIGITS (512 / 64)
include/crypto/ecc_curve_defs.h new file +92 -0
new file mode 100644
index 0000000..1080766
@@ -0,0 +1,92 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _CRYTO_ECC_CURVE_DEFS_H
+#define _CRYTO_ECC_CURVE_DEFS_H
+
+/**
+ * struct ecc_point - elliptic curve point in affine coordinates
+ *
+ * @x:		X coordinate in vli form.
+ * @y:		Y coordinate in vli form.
+ * @ndigits:	Length of vlis in u64 qwords.
+ */
+struct ecc_point {
+	u64 *x;
+	u64 *y;
+	u8 ndigits;
+};
+
+/**
+ * struct ecc_curve - definition of elliptic curve
+ *
+ * @name:	Short name of the curve.
+ * @g:		Generator point of the curve.
+ * @p:		Prime number, if Barrett's reduction is used for this curve
+ *		pre-calculated value 'mu' is appended to the @p after ndigits.
+ *		Use of Barrett's reduction is heuristically determined in
+ *		vli_mmod_fast().
+ * @n:		Order of the curve group.
+ * @a:		Curve parameter a.
+ * @b:		Curve parameter b.
+ */
+struct ecc_curve {
+	char *name;
+	struct ecc_point g;
+	u64 *p;
+	u64 *n;
+	u64 *a;
+	u64 *b;
+};
+
+/* NIST P-192: a = p - 3 */
+static u64 nist_p192_g_x[] = { 0xF4FF0AFD82FF1012ull, 0x7CBF20EB43A18800ull,
+				0x188DA80EB03090F6ull };
+static u64 nist_p192_g_y[] = { 0x73F977A11E794811ull, 0x631011ED6B24CDD5ull,
+				0x07192B95FFC8DA78ull };
+static u64 nist_p192_p[] = { 0xFFFFFFFFFFFFFFFFull, 0xFFFFFFFFFFFFFFFEull,
+				0xFFFFFFFFFFFFFFFFull };
+static u64 nist_p192_n[] = { 0x146BC9B1B4D22831ull, 0xFFFFFFFF99DEF836ull,
+				0xFFFFFFFFFFFFFFFFull };
+static u64 nist_p192_a[] = { 0xFFFFFFFFFFFFFFFCull, 0xFFFFFFFFFFFFFFFEull,
+				0xFFFFFFFFFFFFFFFFull };
+static u64 nist_p192_b[] = { 0xFEB8DEECC146B9B1ull, 0x0FA7E9AB72243049ull,
+				0x64210519E59C80E7ull };
+static struct ecc_curve nist_p192 = {
+	.name = "nist_192",
+	.g = {
+		.x = nist_p192_g_x,
+		.y = nist_p192_g_y,
+		.ndigits = 3,
+	},
+	.p = nist_p192_p,
+	.n = nist_p192_n,
+	.a = nist_p192_a,
+	.b = nist_p192_b
+};
+
+/* NIST P-256: a = p - 3 */
+static u64 nist_p256_g_x[] = { 0xF4A13945D898C296ull, 0x77037D812DEB33A0ull,
+				0xF8BCE6E563A440F2ull, 0x6B17D1F2E12C4247ull };
+static u64 nist_p256_g_y[] = { 0xCBB6406837BF51F5ull, 0x2BCE33576B315ECEull,
+				0x8EE7EB4A7C0F9E16ull, 0x4FE342E2FE1A7F9Bull };
+static u64 nist_p256_p[] = { 0xFFFFFFFFFFFFFFFFull, 0x00000000FFFFFFFFull,
+				0x0000000000000000ull, 0xFFFFFFFF00000001ull };
+static u64 nist_p256_n[] = { 0xF3B9CAC2FC632551ull, 0xBCE6FAADA7179E84ull,
+				0xFFFFFFFFFFFFFFFFull, 0xFFFFFFFF00000000ull };
+static u64 nist_p256_a[] = { 0xFFFFFFFFFFFFFFFCull, 0x00000000FFFFFFFFull,
+				0x0000000000000000ull, 0xFFFFFFFF00000001ull };
+static u64 nist_p256_b[] = { 0x3BCE3C3E27D2604Bull, 0x651D06B0CC53B0F6ull,
+				0xB3EBBD55769886BCull, 0x5AC635D8AA3A93E7ull };
+static struct ecc_curve nist_p256 = {
+	.name = "nist_256",
+	.g = {
+		.x = nist_p256_g_x,
+		.y = nist_p256_g_y,
+		.ndigits = 4,
+	},
+	.p = nist_p256_p,
+	.n = nist_p256_n,
+	.a = nist_p256_a,
+	.b = nist_p256_b
+};
+
+#endif
Signature · 1 line
2.8.1

.

author
#7 lore raw

PATCH v4 4/5 crypto: hisilicon/hpre - add 'ECDH' algorithm

In reply to Meng Yu

1. Add some new 'ECDH' curve parameter definitions to 'include/crypto/ecc_curve_defs.h', and reorder ECC 'Curves IDs' in 'include/crypto/ecdh.h';
2. Enable 'ECDH' algorithm in Kunpeng 930.

---
 crypto/ecc.c                                |   4 +-
 crypto/testmgr.h                            |  12 +-
 drivers/crypto/hisilicon/hpre/hpre.h        |   2 +-
 drivers/crypto/hisilicon/hpre/hpre_crypto.c | 510 +++++++++++++++++++++++++++-
 drivers/crypto/hisilicon/hpre/hpre_main.c   |   1 +
 include/crypto/ecc_curve_defs.h             | 198 +++++++++--
 include/crypto/ecdh.h                       |   9 +-
 7 files changed, 698 insertions(+), 38 deletions(-)
crypto/ecc.c +2 -2
index f23efdd..6adcae2 100644
@@ -46,9 +46,9 @@ static inline const struct ecc_curve *ecc_get_curve(unsigned int curve_id)
 	switch (curve_id) {
 	/* In FIPS mode only allow P256 and higher */
 	case ECC_CURVE_NIST_P192:
-		return fips_enabled ? NULL : &nist_p192;
+		return fips_enabled ? NULL : &ecc_curve_list[ECC_CURVE_NIST_P192 - 1];
 	case ECC_CURVE_NIST_P256:
-		return &nist_p256;
+		return &ecc_curve_list[ECC_CURVE_NIST_P256 - 1];
 	default:
 		return NULL;
 	}
crypto/testmgr.h +6 -6
index 8c83811..371692e 100644
@@ -2268,12 +2268,12 @@ static const struct kpp_testvec ecdh_tv_template[] = {
 #ifdef __LITTLE_ENDIAN
 	"\x02\x00" /* type */
 	"\x20\x00" /* len */
-	"\x01\x00" /* curve_id */
+	"\x02\x00" /* curve_id */
 	"\x18\x00" /* key_size */
 #else
 	"\x00\x02" /* type */
 	"\x00\x20" /* len */
-	"\x00\x01" /* curve_id */
+	"\x00\x02" /* curve_id */
 	"\x00\x18" /* key_size */
 #endif
 	"\xb5\x05\xb1\x71\x1e\xbf\x8c\xda"
@@ -2307,12 +2307,12 @@ static const struct kpp_testvec ecdh_tv_template[] = {
 #ifdef __LITTLE_ENDIAN
 	"\x02\x00" /* type */
 	"\x28\x00" /* len */
-	"\x02\x00" /* curve_id */
+	"\x04\x00" /* curve_id */
 	"\x20\x00" /* key_size */
 #else
 	"\x00\x02" /* type */
 	"\x00\x28" /* len */
-	"\x00\x02" /* curve_id */
+	"\x00\x04" /* curve_id */
 	"\x00\x20" /* key_size */
 #endif
 	"\x24\xd1\x21\xeb\xe5\xcf\x2d\x83"
@@ -2351,12 +2351,12 @@ static const struct kpp_testvec ecdh_tv_template[] = {
 #ifdef __LITTLE_ENDIAN
 	"\x02\x00" /* type */
 	"\x08\x00" /* len */
-	"\x02\x00" /* curve_id */
+	"\x04\x00" /* curve_id */
 	"\x00\x00", /* key_size */
 #else
 	"\x00\x02" /* type */
 	"\x00\x08" /* len */
-	"\x00\x02" /* curve_id */
+	"\x00\x04" /* curve_id */
 	"\x00\x00", /* key_size */
 #endif
 	.b_secret =
drivers/crypto/hisilicon/hpre/hpre.h +1 -1
index 02193e1..50e6b2e 100644
@@ -83,6 +83,7 @@ enum hpre_alg_type {
 	HPRE_ALG_KG_CRT = 0x3,
 	HPRE_ALG_DH_G2 = 0x4,
 	HPRE_ALG_DH = 0x5,
+	HPRE_ALG_ECC_MUL = 0xD,
 };
 
 struct hpre_sqe {
@@ -104,5 +105,4 @@ struct hisi_qp *hpre_create_qp(u8 type);
 int hpre_algs_register(struct hisi_qm *qm);
 void hpre_algs_unregister(struct hisi_qm *qm);
 
-
 #endif
drivers/crypto/hisilicon/hpre/hpre_crypto.c +506 -4

574 lines not on this page · raw message

drivers/crypto/hisilicon/hpre/hpre_main.c +1 -0
index 1ae8fa1..2ccc3dc 100644
@@ -1020,4 +1020,5 @@ module_exit(hpre_exit);
 
 MODULE_LICENSE("GPL v2");
 MODULE_AUTHOR("Zaibo Xu <[email protected]>");
+MODULE_AUTHOR("Meng Yu <[email protected]>");
 MODULE_DESCRIPTION("Driver for HiSilicon HPRE accelerator");
include/crypto/ecc_curve_defs.h +175 -23

216 lines not on this page · raw message

include/crypto/ecdh.h +7 -2
index a5b805b..7d4fd3a 100644
@@ -23,8 +23,13 @@
  */
 
 /* Curves IDs */
-#define ECC_CURVE_NIST_P192	0x0001
-#define ECC_CURVE_NIST_P256	0x0002
+#define ECC_CURVE_NIST_P128	0x0001
+#define ECC_CURVE_NIST_P192	0x0002
+#define ECC_CURVE_NIST_P224	0x0003
+#define ECC_CURVE_NIST_P256	0x0004
+#define ECC_CURVE_NIST_P320	0x0005
+#define ECC_CURVE_NIST_P384	0x0006
+#define ECC_CURVE_NIST_P521	0x0007
 
 /**
  * struct ecdh - define an ECDH private key
Signature · 1 line
2.8.1
#8 lore raw

Re: [PATCH v4 4/5] crypto: hisilicon/hpre - add 'ECDH' algorithm

Am Freitag, den 11.12.2020, 14:30 +0800 schrieb Meng Yu:

drivers/crypto/hisilicon/hpre/hpre_crypto.c struct hpre_ctx; · line 42

Quoted 3 lines
drivers/crypto/hisilicon/hpre/hpre_crypto.c +2 -0
+/* size in bytes of the n prime */
+#define HPRE_ECC_NIST_P128_N_SIZE      16

Do we truly need P-128? Besides, I do not see that curve being defined in contemporary cipher specs.

drivers/crypto/hisilicon/hpre/hpre_crypto.c struct hpre_ctx; · line 46

Quoted 4 lines
drivers/crypto/hisilicon/hpre/hpre_crypto.c +4 -0
+#define HPRE_ECC_NIST_P192_N_SIZE      24
+#define HPRE_ECC_NIST_P224_N_SIZE      28
+#define HPRE_ECC_NIST_P256_N_SIZE      32
+#define HPRE_ECC_NIST_P320_N_SIZE      40

Do we truly need P-320? Besides, I do not see that curve being defined in contemporary cipher specs.

drivers/crypto/hisilicon/hpre/hpre_crypto.c struct hpre_ctx;

Quoted 9 lines
drivers/crypto/hisilicon/hpre/hpre_crypto.c +9 -0
+#define HPRE_ECC_NIST_P384_N_SIZE      48
+#define HPRE_ECC_NIST_P521_N_SIZE      66
+
+/* size in bytes */
+#define HPRE_ECC_HW256_KSZ_B   32
+#define HPRE_ECC_HW384_KSZ_B   48
+#define HPRE_ECC_HW576_KSZ_B   72
+
+#define HPRE_ECDH_MAX_SZ       HPRE_ECC_HW576_KSZ_B]

Ciao
Stephan

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#10 lore raw

Re: [PATCH v4 4/5] crypto: hisilicon/hpre - add 'ECDH' algorithm

Quoted 11 lines

Am Freitag, den 11.12.2020, 14:30 +0800 schrieb Meng Yu:

drivers/crypto/hisilicon/hpre/hpre_crypto.c struct hpre_ctx; · line 42

Quoted 3 lines
drivers/crypto/hisilicon/hpre/hpre_crypto.c +2 -0
+/* size in bytes of the n prime */
+#define HPRE_ECC_NIST_P128_N_SIZE      16

Do we truly need P-128? Besides, I do not see that curve being defined in contemporary cipher specs.

Quoted 7 lines

drivers/crypto/hisilicon/hpre/hpre_crypto.c struct hpre_ctx; · line 46

Quoted 4 lines
drivers/crypto/hisilicon/hpre/hpre_crypto.c +4 -0
+#define HPRE_ECC_NIST_P192_N_SIZE      24
+#define HPRE_ECC_NIST_P224_N_SIZE      28
+#define HPRE_ECC_NIST_P256_N_SIZE      32
+#define HPRE_ECC_NIST_P320_N_SIZE      40

Do we truly need P-320? Besides, I do not see that curve being defined in contemporary cipher specs.

Yes, in rfc 5903, only P-256, P-384 and P-521 is defined, but in 'rfc5639' and "SEC 2: Recommended Elliptic Curve Domain Parameters", other curves like P-128, P-192, P-224, and P-320 curve parameters are found, and they are used in 'openssl';
How about your idea?

Thanks,

Quoted 15 lines

drivers/crypto/hisilicon/hpre/hpre_crypto.c struct hpre_ctx;

Quoted 9 lines
drivers/crypto/hisilicon/hpre/hpre_crypto.c +9 -0
+#define HPRE_ECC_NIST_P384_N_SIZE      48
+#define HPRE_ECC_NIST_P521_N_SIZE      66
+
+/* size in bytes */
+#define HPRE_ECC_HW256_KSZ_B   32
+#define HPRE_ECC_HW384_KSZ_B   48
+#define HPRE_ECC_HW576_KSZ_B   72
+
+#define HPRE_ECDH_MAX_SZ       HPRE_ECC_HW576_KSZ_B]

Ciao
Stephan

.

#11 lore raw

Re: [PATCH v4 4/5] crypto: hisilicon/hpre - add 'ECDH' algorithm

Am Mittwoch, dem 16.12.2020 um 10:39 +0800 schrieb yumeng:

Quoted 19 lines
Quoted 11 lines

Am Freitag, den 11.12.2020, 14:30 +0800 schrieb Meng Yu:

drivers/crypto/hisilicon/hpre/hpre_crypto.c struct hpre_ctx; · line 42

Quoted 3 lines
drivers/crypto/hisilicon/hpre/hpre_crypto.c +2 -0
+/* size in bytes of the n prime */
+#define HPRE_ECC_NIST_P128_N_SIZE      16

Do we truly need P-128? Besides, I do not see that curve being defined in contemporary cipher specs.

Quoted 7 lines

drivers/crypto/hisilicon/hpre/hpre_crypto.c struct hpre_ctx; · line 46

Quoted 4 lines
drivers/crypto/hisilicon/hpre/hpre_crypto.c +4 -0
+#define HPRE_ECC_NIST_P192_N_SIZE      24
+#define HPRE_ECC_NIST_P224_N_SIZE      28
+#define HPRE_ECC_NIST_P256_N_SIZE      32
+#define HPRE_ECC_NIST_P320_N_SIZE      40

Do we truly need P-320? Besides, I do not see that curve being defined in contemporary cipher specs.

Quoted 5 lines

Yes, in rfc 5903, only P-256, P-384 and P-521 is defined, but in 'rfc5639' and  "SEC 2: Recommended Elliptic Curve Domain Parameters", other curves like P-128, P-192, P-224, and P-320 curve parameters are found, and they are used in 'openssl';
How about your idea?

Who is going to use that curve considering that common protocols that are implemented in the kernel do not use it?

Thanks
Stephan

author
#12 lore raw

Re: [PATCH v4 4/5] crypto: hisilicon/hpre - add 'ECDH' algorithm

Quoted 26 lines · Stephan Mueller

Am Mittwoch, dem 16.12.2020 um 10:39 +0800 schrieb yumeng:

Quoted 19 lines
Quoted 11 lines

Am Freitag, den 11.12.2020, 14:30 +0800 schrieb Meng Yu:

drivers/crypto/hisilicon/hpre/hpre_crypto.c struct hpre_ctx; · line 42

Quoted 3 lines
drivers/crypto/hisilicon/hpre/hpre_crypto.c +2 -0
+/* size in bytes of the n prime */
+#define HPRE_ECC_NIST_P128_N_SIZE      16

Do we truly need P-128? Besides, I do not see that curve being defined in contemporary cipher specs.

Quoted 7 lines

drivers/crypto/hisilicon/hpre/hpre_crypto.c struct hpre_ctx; · line 46

Quoted 4 lines
drivers/crypto/hisilicon/hpre/hpre_crypto.c +4 -0
+#define HPRE_ECC_NIST_P192_N_SIZE      24
+#define HPRE_ECC_NIST_P224_N_SIZE      28
+#define HPRE_ECC_NIST_P256_N_SIZE      32
+#define HPRE_ECC_NIST_P320_N_SIZE      40

Do we truly need P-320? Besides, I do not see that curve being defined in contemporary cipher specs.

Quoted 5 lines

Yes, in rfc 5903, only P-256, P-384 and P-521 is defined, but in 'rfc5639' and  "SEC 2: Recommended Elliptic Curve Domain Parameters", other curves like P-128, P-192, P-224, and P-320 curve parameters are found, and they are used in 'openssl';
How about your idea?

Quoted 6 lines

Who is going to use that curve considering that common protocols that are implemented in the kernel do not use it?

Thanks
Stephan

I see in "SEC 2: Recommended Elliptic Curve Domain ParametersVersion2.0" that 'Recommend Elliptic Curve Domain Parameters over Fp' are secp192, secp224, secp256, secp384, and secp521, secp128 and secp320 are not recommended.
So you mean it's better not to include secp128 and secp320, right?

Thanks,

#13 lore raw

Re: [PATCH v4 4/5] crypto: hisilicon/hpre - add 'ECDH' algorithm

Am Donnerstag, 17. Dezember 2020, 04:07:30 CET schrieb yumeng:

Hi yumeng,

Quoted 6 lines

I see in "SEC 2: Recommended Elliptic Curve Domain ParametersVersion2.0" that 'Recommend Elliptic Curve Domain Parameters over Fp' are secp192, secp224, secp256, secp384, and secp521, secp128 and secp320 are not recommended.
So you mean it's better not to include secp128 and secp320, right?

Precisely because I do not see the use case in the kernel.

Quoted 2 lines

Thanks,

Ciao
Stephan

author
#14 lore raw

PATCH v4 5/5 crypto: hisilicon/hpre - add 'CURVE25519' algorithm

In reply to Meng Yu

1. Add 'CURVE25519' curve parameter definition to
'include/crypto/ecc_curve_defs.h';
2. Enable 'CURVE25519' algorithm in Kunpeng 930.

---
 drivers/crypto/hisilicon/Kconfig            |   1 +
 drivers/crypto/hisilicon/hpre/hpre.h        |   2 +
 drivers/crypto/hisilicon/hpre/hpre_crypto.c | 364 +++++++++++++++++++++++++++-
 include/crypto/ecc_curve_defs.h             |  17 ++
 4 files changed, 375 insertions(+), 9 deletions(-)
drivers/crypto/hisilicon/Kconfig +1 -0
index 8431926..c45adb1 100644
@@ -65,6 +65,7 @@ config CRYPTO_DEV_HISI_HPRE
 	depends on UACCE || UACCE=n
 	depends on ARM64 || (COMPILE_TEST && 64BIT)
 	depends on ACPI
+	select CRYPTO_LIB_CURVE25519_GENERIC
 	select CRYPTO_DEV_HISI_QM
 	select CRYPTO_DH
 	select CRYPTO_RSA
drivers/crypto/hisilicon/hpre/hpre.h +2 -0
index 50e6b2e..92892e3 100644
@@ -84,6 +84,8 @@ enum hpre_alg_type {
 	HPRE_ALG_DH_G2 = 0x4,
 	HPRE_ALG_DH = 0x5,
 	HPRE_ALG_ECC_MUL = 0xD,
+	/* shared by x25519 and x448, but x448 is not supported now */
+	HPRE_ALG_CURVE25519_MUL = 0x10,
 };
 
 struct hpre_sqe {
drivers/crypto/hisilicon/hpre/hpre_crypto.c +355 -9

430 lines not on this page · raw message

include/crypto/ecc_curve_defs.h +17 -0
index bf30338..7a2a4aa 100644
@@ -241,4 +241,21 @@ static const struct ecc_curve ecc_curve_list[] = {
 	}
 };
 
+/* curve25519 */
+static u64 curve25519_g_x[] = { 0x0000000000000009, 0x0000000000000000,
+				0x0000000000000000, 0x0000000000000000 };
+static u64 curve25519_p[] = { 0xffffffffffffffed, 0xffffffffffffffff,
+				0xffffffffffffffff, 0x7fffffffffffffff };
+static u64 curve25519_a[] = { 0x000000000001DB41, 0x0000000000000000,
+				0x0000000000000000, 0x0000000000000000 };
+static const struct ecc_curve ecc_25519 = {
+	.name = "curve25519",
+	.g = {
+		.x = curve25519_g_x,
+		.ndigits = 4,
+	},
+	.p = curve25519_p,
+	.a = curve25519_a,
+};
+
 #endif
Signature · 1 line
2.8.1
#15 lore raw

Re: [PATCH v4 5/5] crypto: hisilicon/hpre - add 'CURVE25519' algorithm

Am Freitag, den 11.12.2020, 14:30 +0800 schrieb Meng Yu:

Quoted 7 lines

include/crypto/ecc_curve_defs.h +6 -0
+/* curve25519 */
+static u64 curve25519_g_x[] = { 0x0000000000000009, 0x0000000000000000,
+                               0x0000000000000000, 0x0000000000000000 };
+static u64 curve25519_p[] = { 0xffffffffffffffed, 0xffffffffffffffff,
+                               0xffffffffffffffff, 0x7fffffffffffffff };
+static u64 curve25519_a[] = { 0x000000000001DB41, 0x0000000000000000,

include/crypto/ecc_curve_defs.h static const struct ecc_curve ecc_curve_list[] = { · line 259

Quoted 10 lines
include/crypto/ecc_curve_defs.h +10 -0
+                               0x0000000000000000, 0x0000000000000000 };
+static const struct ecc_curve ecc_25519 = {
+       .name = "curve25519",
+       .g = {
+               .x = curve25519_g_x,
+               .ndigits = 4,
+       },
+       .p = curve25519_p,
+       .a = curve25519_a,
+};

With this definition, I am not sure whether ecc_is_pubkey_valid_partial would work correctly. At least it *seems* that there would be a NULL-pointer dereference in vli_add with the undefined .b value. Did you test and can you confirm?

Thanks
Stephan

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#17 lore raw

Re: [PATCH v4 5/5] crypto: hisilicon/hpre - add 'CURVE25519' algorithm

Quoted 25 lines

Am Freitag, den 11.12.2020, 14:30 +0800 schrieb Meng Yu:

Quoted 7 lines
include/crypto/ecc_curve_defs.h +6 -0
+/* curve25519 */
+static u64 curve25519_g_x[] = { 0x0000000000000009, 0x0000000000000000,
+                               0x0000000000000000, 0x0000000000000000 };
+static u64 curve25519_p[] = { 0xffffffffffffffed, 0xffffffffffffffff,
+                               0xffffffffffffffff, 0x7fffffffffffffff };
+static u64 curve25519_a[] = { 0x000000000001DB41, 0x0000000000000000,

include/crypto/ecc_curve_defs.h static const struct ecc_curve ecc_curve_list[] = { · line 259

Quoted 10 lines
include/crypto/ecc_curve_defs.h +10 -0
+                               0x0000000000000000, 0x0000000000000000 };
+static const struct ecc_curve ecc_25519 = {
+       .name = "curve25519",
+       .g = {
+               .x = curve25519_g_x,
+               .ndigits = 4,
+       },
+       .p = curve25519_p,
+       .a = curve25519_a,
+};

With this definition, I am not sure whether ecc_is_pubkey_valid_partial would work correctly. At least it *seems* that there would be a NULL-pointer dereference in vli_add with the undefined .b value. Did you test and can you confirm?

Quoted 3 lines

Thanks
Stephan

'static const struct ecc_curve ecc_25519' is curve25519's parameters, only used in 'curve25519', not used by 'ECDH';

Thanks,