2021-03-04 15:12:41

by Meng Yu

[permalink] [raw]
Subject: [PATCH v10 0/7] add ECDH and CURVE25519 algorithms support for Kunpeng 930

1. Move curve ID from the key into the algorithm name (like 'ecdh-nist-pxxx'
so we get its tfm like 'crypto_alloc_kpp("ecdh-nist-p256", 0, 0)'),
in 'crypto/ecc.c' (has been verified by testmgr) and 'crypto/atmel-ecc.c'
(only compiled, not do test), and modify 'testmgr.c' and 'net/bluetooth/smp.c'
(only compiled, not do test) to adapt the modification;

2. Add new file 'include/crypto/ecc_curve.h', and move 'struct ecc_point' and
'struct ecc_curve' definitions to it, also add new APIs 'ecc_get_curveXXX'
into it, with these APIs, users in kernel tree can get ECDH and
curve25519 parameters;

3. Add ECDH and CURVE25519 algorithms support for Kunpeng 930.

v9->v10:
- patch #3: delete 'atmel_ecdh_supported_curve' and 'n_sz' in atmel-ecc.c

v8->v9:
- patch #3: squash patches 3-5 in v8 into one in v9
- patch #4: delete ECDH curve parameters: P224, P384 and P521
- patch #5: delete ecdh-nist-p224, ecdh-nist-p384 and ecdh-nist-p521 support in HPRE

v7->v8:
- patch #3 and #5: move the curve ID from the key into the algorithm name instead

v6->v7:
- patch #4: add function interface to expose elliptic curve parameters
- patch #4: eliminate warning by 'kernel test robot'
- patch #5: add function interface to expose curve25519 parameters

v5->v6:
- patch #1: add a new patch (the first patch), which is the "depend on" patch before

v4->v5:
- patch #4: delete P-128 and P-320 curve, as the few using case in the kernel

v3 -> v4:
- patch #3: add new, and 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'


Meng Yu (7):
crypto: hisilicon/hpre - add version adapt to new algorithms
crypto: hisilicon/hpre - add algorithm type
crypto: move curve_id of ECDH from the key to algorithm name
crypto: and expose ecc curves
crypto: hisilicon/hpre - add 'ECDH' algorithm
crypto: add curve25519 params and expose them
crypto: hisilicon/hpre - add 'CURVE25519' algorithm

crypto/ecc.c | 11 +-
crypto/ecc.h | 37 +-
crypto/ecc_curve_defs.h | 17 +
crypto/ecdh.c | 72 ++-
crypto/ecdh_helper.c | 4 +-
crypto/testmgr.c | 13 +-
crypto/testmgr.h | 34 +-
drivers/crypto/atmel-ecc.c | 28 +-
drivers/crypto/hisilicon/Kconfig | 1 +
drivers/crypto/hisilicon/hpre/hpre.h | 17 +-
drivers/crypto/hisilicon/hpre/hpre_crypto.c | 881 +++++++++++++++++++++++++++-
drivers/crypto/hisilicon/hpre/hpre_main.c | 12 +-
drivers/crypto/hisilicon/qm.c | 4 +-
drivers/crypto/hisilicon/qm.h | 4 +-
drivers/crypto/hisilicon/sec2/sec.h | 4 +-
drivers/crypto/hisilicon/sec2/sec_crypto.c | 4 +-
drivers/crypto/hisilicon/sec2/sec_crypto.h | 4 +-
drivers/crypto/hisilicon/zip/zip.h | 4 +-
drivers/crypto/hisilicon/zip/zip_crypto.c | 4 +-
include/crypto/ecc_curve.h | 60 ++
include/crypto/ecdh.h | 2 -
net/bluetooth/ecdh_helper.c | 2 -
net/bluetooth/selftest.c | 2 +-
net/bluetooth/smp.c | 6 +-
24 files changed, 1086 insertions(+), 141 deletions(-)
create mode 100644 include/crypto/ecc_curve.h

--
2.8.1


2021-03-04 15:13:04

by Meng Yu

[permalink] [raw]
Subject: [PATCH v10 6/7] crypto: add curve25519 params and expose them

1. Add curve 25519 parameters in 'crypto/ecc_curve_defs.h';
2. Add curve25519 interface 'ecc_get_curve25519_param' in
'include/crypto/ecc_curve.h', to make its parameters be
exposed to everyone in kernel tree.

Signed-off-by: Meng Yu <[email protected]>
Reviewed-by: Zaibo Xu <[email protected]>
---
crypto/ecc.c | 6 ++++++
crypto/ecc_curve_defs.h | 17 +++++++++++++++++
include/crypto/ecc_curve.h | 7 +++++++
3 files changed, 30 insertions(+)

diff --git a/crypto/ecc.c b/crypto/ecc.c
index 4b55ad0..0798a18 100644
--- a/crypto/ecc.c
+++ b/crypto/ecc.c
@@ -43,6 +43,12 @@ typedef struct {
u64 m_high;
} uint128_t;

+/* Returns curv25519 curve param */
+const struct ecc_curve *ecc_get_curve25519(void)
+{
+ return &ecc_25519;
+}
+EXPORT_SYMBOL(ecc_get_curve25519);

const struct ecc_curve *ecc_get_curve(unsigned int curve_id)
{
diff --git a/crypto/ecc_curve_defs.h b/crypto/ecc_curve_defs.h
index 69be6c7..d7769cc 100644
--- a/crypto/ecc_curve_defs.h
+++ b/crypto/ecc_curve_defs.h
@@ -54,4 +54,21 @@ static struct ecc_curve nist_p256 = {
.b = nist_p256_b
};

+/* 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
diff --git a/include/crypto/ecc_curve.h b/include/crypto/ecc_curve.h
index 19a35da..7096478 100644
--- a/include/crypto/ecc_curve.h
+++ b/include/crypto/ecc_curve.h
@@ -50,4 +50,11 @@ struct ecc_curve {
*/
const struct ecc_curve *ecc_get_curve(unsigned int curve_id);

+/**
+ * ecc_get_curve25519() - get curve25519 curve;
+ *
+ * Returns curve25519
+ */
+const struct ecc_curve *ecc_get_curve25519(void);
+
#endif
--
2.8.1

2021-03-12 13:15:33

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH v10 0/7] add ECDH and CURVE25519 algorithms support for Kunpeng 930

On Thu, Mar 04, 2021 at 02:35:43PM +0800, Meng Yu wrote:
> 1. Move curve ID from the key into the algorithm name (like 'ecdh-nist-pxxx'
> so we get its tfm like 'crypto_alloc_kpp("ecdh-nist-p256", 0, 0)'),
> in 'crypto/ecc.c' (has been verified by testmgr) and 'crypto/atmel-ecc.c'
> (only compiled, not do test), and modify 'testmgr.c' and 'net/bluetooth/smp.c'
> (only compiled, not do test) to adapt the modification;
>
> 2. Add new file 'include/crypto/ecc_curve.h', and move 'struct ecc_point' and
> 'struct ecc_curve' definitions to it, also add new APIs 'ecc_get_curveXXX'
> into it, with these APIs, users in kernel tree can get ECDH and
> curve25519 parameters;
>
> 3. Add ECDH and CURVE25519 algorithms support for Kunpeng 930.
>
> v9->v10:
> - patch #3: delete 'atmel_ecdh_supported_curve' and 'n_sz' in atmel-ecc.c
>
> v8->v9:
> - patch #3: squash patches 3-5 in v8 into one in v9
> - patch #4: delete ECDH curve parameters: P224, P384 and P521
> - patch #5: delete ecdh-nist-p224, ecdh-nist-p384 and ecdh-nist-p521 support in HPRE
>
> v7->v8:
> - patch #3 and #5: move the curve ID from the key into the algorithm name instead
>
> v6->v7:
> - patch #4: add function interface to expose elliptic curve parameters
> - patch #4: eliminate warning by 'kernel test robot'
> - patch #5: add function interface to expose curve25519 parameters
>
> v5->v6:
> - patch #1: add a new patch (the first patch), which is the "depend on" patch before
>
> v4->v5:
> - patch #4: delete P-128 and P-320 curve, as the few using case in the kernel
>
> v3 -> v4:
> - patch #3: add new, and 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'
>
>
> Meng Yu (7):
> crypto: hisilicon/hpre - add version adapt to new algorithms
> crypto: hisilicon/hpre - add algorithm type
> crypto: move curve_id of ECDH from the key to algorithm name
> crypto: and expose ecc curves
> crypto: hisilicon/hpre - add 'ECDH' algorithm
> crypto: add curve25519 params and expose them
> crypto: hisilicon/hpre - add 'CURVE25519' algorithm
>
> crypto/ecc.c | 11 +-
> crypto/ecc.h | 37 +-
> crypto/ecc_curve_defs.h | 17 +
> crypto/ecdh.c | 72 ++-
> crypto/ecdh_helper.c | 4 +-
> crypto/testmgr.c | 13 +-
> crypto/testmgr.h | 34 +-
> drivers/crypto/atmel-ecc.c | 28 +-
> drivers/crypto/hisilicon/Kconfig | 1 +
> drivers/crypto/hisilicon/hpre/hpre.h | 17 +-
> drivers/crypto/hisilicon/hpre/hpre_crypto.c | 881 +++++++++++++++++++++++++++-
> drivers/crypto/hisilicon/hpre/hpre_main.c | 12 +-
> drivers/crypto/hisilicon/qm.c | 4 +-
> drivers/crypto/hisilicon/qm.h | 4 +-
> drivers/crypto/hisilicon/sec2/sec.h | 4 +-
> drivers/crypto/hisilicon/sec2/sec_crypto.c | 4 +-
> drivers/crypto/hisilicon/sec2/sec_crypto.h | 4 +-
> drivers/crypto/hisilicon/zip/zip.h | 4 +-
> drivers/crypto/hisilicon/zip/zip_crypto.c | 4 +-
> include/crypto/ecc_curve.h | 60 ++
> include/crypto/ecdh.h | 2 -
> net/bluetooth/ecdh_helper.c | 2 -
> net/bluetooth/selftest.c | 2 +-
> net/bluetooth/smp.c | 6 +-
> 24 files changed, 1086 insertions(+), 141 deletions(-)
> create mode 100644 include/crypto/ecc_curve.h

All applied. Thanks.
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt