add ECDH and CURVE25519 algorithms support for Kunpeng 930
Subsystems (7)
v7 cover add ECDH and CURVE25519 algorithms support for Kunpeng 930
1. Add some new elliptic curve parameters definitions, and reorder ECC 'Curves IDs';
2. Add interface to get elliptic curve by curve_id in "include/crypto/ecc_curve.h" by curve_id;
3. Add ECDH and CURVE25519 algorithms support for Kunpeng 930.
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, 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 (6):
crypto: hisilicon/hpre - add version adapt to new algorithms
crypto: hisilicon/hpre - add algorithm type
crypto: add ecc curve and expose them
crypto: add curve 25519 and expose them
crypto: hisilicon/hpre - add 'ECDH' algorithm
crypto: hisilicon/hpre - add 'CURVE25519' algorithm
crypto/ecc.c | 22 +- crypto/ecc.h | 37 +- crypto/ecc_curve_defs.h | 163 +++++- crypto/testmgr.h | 12 +- drivers/crypto/hisilicon/Kconfig | 1 + drivers/crypto/hisilicon/hpre/hpre.h | 25 +- drivers/crypto/hisilicon/hpre/hpre_crypto.c | 861 +++++++++++++++++++++++++++- drivers/crypto/hisilicon/hpre/hpre_main.c | 105 ++-- 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 | 5 +- 17 files changed, 1191 insertions(+), 128 deletions(-) create mode 100644 include/crypto/ecc_curve.h
Signature · 1 line
2.8.1
PATCH v7 1/7 crypto: hisilicon/hpre - add version adapt to new algorithms
A new generation of accelerator Kunpeng930 has appeared, and the corresponding driver needs to be updated to support some new algorithms of Kunpeng930. To be compatible with Kunpeng920, we add parameter 'struct hisi_qm *qm' to sec_algs_(un)register to identify the chip's version.
--- drivers/crypto/hisilicon/hpre/hpre.h | 5 +++-- drivers/crypto/hisilicon/hpre/hpre_crypto.c | 4 ++-- 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 ++-- 9 files changed, 19 insertions(+), 18 deletions(-)
drivers/crypto/hisilicon/hpre/hpre.h +3 -2
@@ -91,7 +91,8 @@ struct hpre_sqe { };struct hisi_qp *hpre_create_qp (void ); -int hpre_algs_register (void ); -void hpre_algs_unregister (void ); +int hpre_algs_register (struct hisi_qm *qm); +void hpre_algs_unregister (struct hisi_qm *qm); +#endif
drivers/crypto/hisilicon/hpre/hpre_crypto.c +2 -2
@@ -1154,7 +1154,7 @@ static struct kpp_alg dh = { };#endif -int hpre_algs_register (void ) +int hpre_algs_register (struct hisi_qm *qm) {int ret;
@@ -1171,7 +1171,7 @@ int hpre_algs_register(void)return ret; } -void hpre_algs_unregister (void ) +void hpre_algs_unregister (struct hisi_qm *qm) {crypto_unregister_akcipher (&rsa);#ifdef CONFIG_CRYPTO_DH
drivers/crypto/hisilicon/qm.c +2 -2
@@ -4015,7 +4015,7 @@ int hisi_qm_alg_register(struct hisi_qm *qm, struct hisi_qm_list *qm_list)mutex_unlock (&qm_list->lock);if (flag) { - ret = qm_list->register_to_crypto (); + ret = qm_list->register_to_crypto (qm);if (ret) {mutex_lock (&qm_list->lock);list_del (&qm->list);
@@ -4046,7 +4046,7 @@ void hisi_qm_alg_unregister(struct hisi_qm *qm, struct hisi_qm_list *qm_list)mutex_unlock (&qm_list->lock);if (list_empty (&qm_list->list)) - qm_list->unregister_from_crypto (); + qm_list->unregister_from_crypto (qm); }EXPORT_SYMBOL_GPL (hisi_qm_alg_unregister);
drivers/crypto/hisilicon/qm.h +2 -2
@@ -198,8 +198,8 @@ struct hisi_qm_err_ini {struct hisi_qm_list {struct mutex lock;struct list_head list; -int (*register_to_crypto)(void ); -void (*unregister_from_crypto)(void ); +int (*register_to_crypto)(struct hisi_qm *qm); +void (*unregister_from_crypto)(struct hisi_qm *qm); };struct hisi_qm {
drivers/crypto/hisilicon/sec2/sec.h +2 -2
@@ -183,6 +183,6 @@ struct sec_dev {void sec_destroy_qps (struct hisi_qp **qps,int qp_num);struct hisi_qp **sec_create_qps (void ); -int sec_register_to_crypto (void ); -void sec_unregister_from_crypto (void ); +int sec_register_to_crypto (struct hisi_qm *qm); +void sec_unregister_from_crypto (struct hisi_qm *qm);#endif
drivers/crypto/hisilicon/sec2/sec_crypto.c +2 -2
@@ -1634,7 +1634,7 @@ static struct aead_alg sec_aeads[] = { AES_BLOCK_SIZE, AES_BLOCK_SIZE, SHA512_DIGEST_SIZE), }; -int sec_register_to_crypto (void ) +int sec_register_to_crypto (struct hisi_qm *qm) {int ret;
@@ -1651,7 +1651,7 @@ int sec_register_to_crypto(void)return ret; } -void sec_unregister_from_crypto (void ) +void sec_unregister_from_crypto (struct hisi_qm *qm) {crypto_unregister_skciphers (sec_skciphers,ARRAY_SIZE (sec_skciphers));
drivers/crypto/hisilicon/sec2/sec_crypto.h +2 -2
@@ -211,6 +211,6 @@ struct sec_sqe { struct sec_sqe_type2 type2; }; -int sec_register_to_crypto (void ); -void sec_unregister_from_crypto (void ); +int sec_register_to_crypto (struct hisi_qm *qm); +void sec_unregister_from_crypto (struct hisi_qm *qm);#endif
drivers/crypto/hisilicon/zip/zip.h +2 -2
@@ -62,6 +62,6 @@ struct hisi_zip_sqe { };int zip_create_qps (struct hisi_qp **qps,int ctx_num,int node); -int hisi_zip_register_to_crypto (void ); -void hisi_zip_unregister_from_crypto (void ); +int hisi_zip_register_to_crypto (struct hisi_qm *qm); +void hisi_zip_unregister_from_crypto (struct hisi_qm *qm);#endif
drivers/crypto/hisilicon/zip/zip_crypto.c +2 -2
@@ -665,7 +665,7 @@ static struct acomp_alg hisi_zip_acomp_gzip = { } }; -int hisi_zip_register_to_crypto (void ) +int hisi_zip_register_to_crypto (struct hisi_qm *qm) {int ret;
@@ -684,7 +684,7 @@ int hisi_zip_register_to_crypto(void)return ret; } -void hisi_zip_unregister_from_crypto (void ) +void hisi_zip_unregister_from_crypto (struct hisi_qm *qm) {crypto_unregister_acomp (&hisi_zip_acomp_gzip);crypto_unregister_acomp (&hisi_zip_acomp_zlib);
Signature · 1 line
2.8.1
PATCH v7 2/7 crypto: hisilicon/hpre - add some updates to adapt to Kunpeng 930
In reply to Meng YuFrom: 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
@@ -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
PATCH v7 3/7 crypto: hisilicon/hpre - add algorithm type
In reply to Meng YuAlgorithm 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
@@ -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
@@ -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
@@ -223,13 +223,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
PATCH v7 4/7 crypto: add ecc curve and expose them
In reply to Meng Yu1. Add ecc curves(P224, P384, P521) for ECDH;
2. Reorder ECC 'Curves ID' in 'include/crypto/ecdh.h', and modify 'curve_id' used in 'testmgr.h';
3. Add function 'ecc_get_curve_param' in 'include/crypto/ecc_curve.h' for users, so everyone in the kernel tree can easily get ecc curve params;
--- crypto/ecc.c | 15 ++++- crypto/ecc.h | 37 +---------- crypto/ecc_curve_defs.h | 152 ++++++++++++++++++++++++++++++++++++++------- crypto/testmgr.h | 12 ++-- include/crypto/ecc_curve.h | 53 ++++++++++++++++ include/crypto/ecdh.h | 5 +- 6 files changed, 207 insertions(+), 67 deletions(-) create mode 100644 include/crypto/ecc_curve.h
crypto/ecc.c +13 -2
@@ -24,6 +24,7 @@* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include <crypto/ecc_curve.h> #include <linux/module.h> #include <linux/random.h> #include <linux/slab.h>
@@ -42,14 +43,24 @@ typedef struct {u64 m_high; } uint128_t; +/* Returns CURVE if get curve succssful, NULL otherwise */ +const struct ecc_curve *ecc_get_curve_by_id (unsigned int curve_id) +{ +if (curve_id >=ECC_CURVE_NIST_P192 && curve_id <=ECC_CURVE_NIST_P521 ) +return &ecc_curve_list[curve_id -1 ]; + +return NULL ; +} +EXPORT_SYMBOL (ecc_get_curve_by_id); +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_get_curve_by_id (curve_id);case ECC_CURVE_NIST_P256 : -return &nist_p256; +return ecc_get_curve_by_id (curve_id);default :return NULL ; }
crypto/ecc.h +2 -35
@@ -26,6 +26,8 @@#ifndef _CRYPTO_ECC_H#define _CRYPTO_ECC_H +#include <crypto/ecc_curve.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 +129 -23
164 lines not on this page · raw message
crypto/testmgr.h +6 -6
@@ -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 */ +"\x03\x00" /* curve_id */ "\x20\x00" /* key_size */#else "\x00\x02" /* type */ "\x00\x28" /* len */ -"\x00\x02" /* curve_id */ +"\x00\x03" /* curve_id */ "\x00\x20" /* key_size */#endif "\x24\xd1\x21\xeb\xe5\xcf\x2d\x83"
@@ -2351,24 +2351,24 @@ static const struct kpp_testvec ecdh_tv_template[] = {#ifdef __LITTLE_ENDIAN"\x02\x00" /* type */ "\x08\x00" /* len */ -"\x02\x00" /* curve_id */ +"\x03\x00" /* curve_id */ "\x00\x00" ,/* key_size */ #else"\x00\x02" /* type */ "\x00\x08" /* len */ -"\x00\x02" /* curve_id */ +"\x00\x03" /* curve_id */ "\x00\x00" ,/* key_size */ #endif .b_secret = #ifdef __LITTLE_ENDIAN "\x02\x00" /* type */ "\x28\x00" /* len */ - "\x02\x00" /* curve_id */ + "\x03\x00" /* curve_id */ "\x20\x00" /* key_size */ #else "\x00\x02" /* type */ "\x00\x28" /* len */ - "\x00\x02" /* curve_id */ + "\x00\x03" /* curve_id */ "\x00\x20" /* key_size */ #endif"\x24\xd1\x21\xeb\xe5\xcf\x2d\x83"
include/crypto/ecc_curve.h new file +53 -0
54 lines not on this page · raw message
include/crypto/ecdh.h +4 -1
@@ -24,7 +24,10 @@/* Curves IDs */ #define ECC_CURVE_NIST_P192 0x0001 -#define ECC_CURVE_NIST_P256 0x0002 +#define ECC_CURVE_NIST_P224 0x0002 +#define ECC_CURVE_NIST_P256 0x0003 +#define ECC_CURVE_NIST_P384 0x0004 +#define ECC_CURVE_NIST_P521 0x0005/** * struct ecdh - define an ECDH private key
Signature · 1 line
2.8.1
Herbert Xu
maintainerRe: [PATCH v7 4/7] crypto: add ecc curve and expose them
Quoted 1 line · Meng Yu
1. Add ecc
curves(P224, P384, P521)for ECDH;
OK I think this is getting unwieldy.
In light of the fact that we already have hardware that supports a specific subset of curves, I think perhaps it would be better to move the curve ID from the key into the algorithm name instead.
IOW, instead of allocating ecdh, you would allocate ecdh-nist-pXXX.
Any comments?
Thanks,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Re: [PATCH v7 4/7] crypto: add ecc curve and expose them
Quoted 6 lines · Herbert Xu
Quoted 1 line · Meng Yu
1. Add ecc
curves(P224, P384, P521)for ECDH;OK I think this is getting unwieldy.
Quoted 8 lines
In light of the fact that we already have hardware that supports a specific subset of curves, I think perhaps it would be better to move the curve ID from the key into the algorithm name instead.
IOW, instead of allocating ecdh, you would allocate ecdh-nist-pXXX.
Any comments?
Agreed. Bluetooth appears to be the only in-kernel user at the moment, and it is hard coded to use p256, so it can be easily updated.
But this also begs the question which ecdh-nist-pXXX implementations we actually need? Why are we exposing these curves in the first place?
Herbert Xu
maintainerRe: [PATCH v7 4/7] crypto: add ecc curve and expose them
Quoted 3 lines · Ard Biesheuvel
But this also begs the question which ecdh-nist-pXXX implementations we actually need? Why are we exposing these curves in the first place?
Once they're distinct algorithms, we can then make sure that only the ones that are used in the kernel is added, even if some hardware may support more curves.
Thanks,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Re: [PATCH v7 4/7] crypto: add ecc curve and expose them
Quoted 3 lines · Herbert Xu
Once they're distinct algorithms, we can then make sure that only the ones that are used in the kernel is added, even if some hardware may support more curves.
I like the idea of having different algorithms names (ecdh-nist- pXXX) for different curves, but I'm not fully convinced by the above statement.
What's the downside of letting device drivers enable all the curves supported by the HW (with the exception of obsolete curves / algorithms), even if there is (currently) no user of such curves in the kernel? Code size and maintainability?
I think that once there is support for certain curves, it's more likely that drivers / modules using them will appear.
Also, even if there are no in-tree users, there might be a few out-of- tree ones.
Herbert Xu
maintainerRe: [PATCH v7 4/7] crypto: add ecc curve and expose them
Quoted 4 lines · Daniele Alessandrelli
What's the downside of letting device drivers enable all the curves supported by the HW (with the exception of obsolete curves / algorithms), even if there is (currently) no user of such curves in the kernel? Code size and maintainability?
The issue is that we always require a software implementation for any given hardware algorithm. As otherwise kernel users cannot rely on the algorithm to work.
Of course we don't want to add every single algorithm out there to the kernel so that's why require there to be an actual in-kernel user before adding a given algorithm.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Re: [PATCH v7 4/7] crypto: add ecc curve and expose them
Quoted 3 lines · Herbert Xu
The issue is that we always require a software implementation for any given hardware algorithm. As otherwise kernel users cannot rely on the algorithm to work.
I understand. This sounds very reasonable to me.
Quoted 3 lines
Of course we don't want to add every single algorithm out there to the kernel so that's why require there to be an actual in-kernel user before adding a given algorithm.
I see. Just to clarify: does the in-kernel user requirement also apply to the case when the author of a device driver also provides the software implementation for the new algorithms supported by device driver / HW?
Herbert Xu
maintainerRe: [PATCH v7 4/7] crypto: add ecc curve and expose them
Quoted 5 lines · Daniele
I see. Just to clarify: does the in-kernel user requirement also apply to the case when the author of a device driver also provides the software implementation for the new algorithms supported by device driver / HW?
Yes we need an actual user. For example, if your algorithm is used by the Security Subsystem (IMA) that would be sufficient.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Re: [PATCH v7 4/7] crypto: add ecc curve and expose them
Quoted 10 lines · Herbert Xu
Quoted 5 lines · Daniele
I see. Just to clarify: does the in-kernel user requirement also apply
to the case when the author of a device driver also provides the software implementation for the new algorithms supported by device driver / HW?Yes we need an actual user. For example, if your algorithm is used by the Security Subsystem (IMA) that would be sufficient.
Understood, thanks!
Unrelated question: I have my Keem Bay OCS ECC patchset [1] almost ready for re-submission. Should I go ahead or should I wait for the final decision about using 'ecdh-nist-pXXX' in place of 'ecdh'?
Also, I guess I'll have to drop P-384 support from the driver, since the are no in-kernel user AFAIK.
[1] https://lore.kernel.org/linux-crypto/[email protected]/
Quoted 2 lines
Cheers,
Herbert Xu
maintainerRe: [PATCH v7 4/7] crypto: add ecc curve and expose them
Quoted 4 lines · Daniele
Unrelated question: I have my Keem Bay OCS ECC patchset [1] almost ready for re-submission. Should I go ahead or should I wait for the final decision about using 'ecdh-nist-pXXX' in place of 'ecdh'?
If we agree on going down this route, then the first step is to convert the existing ecdh generic algorithm and its users to this scheme to ensure no regressions.
After that then you can add your driver.
PS I just noticed that we already have one driver implementing ecdh, atmel so it too would need to be converted before we take on any new drivers for ecdh.
Thanks,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Stefan Berger
reviewerRe: [PATCH v7 4/7] crypto: add ecc curve and expose them
In reply to Ard BiesheuvelQuoted 11 lines · Ard Biesheuvel
Quoted 10 lines · Herbert Xu
Quoted 1 line · Meng Yu
1. Add ecc
curves(P224, P384, P521)for ECDH;OK I think this is getting unwieldy.
In light of the fact that we already have hardware that supports a specific subset of curves, I think perhaps it would be better to move the curve ID from the key into the algorithm name instead.
IOW, instead of allocating ecdh, you would allocate ecdh-nist-pXXX.
Quoted 7 lines
Quoted 2 lines
Any comments?
Agreed. Bluetooth appears to be the only in-kernel user at the moment, and it is hard coded to use p256, so it can be easily updated.
But this also begs the question which ecdh-nist-pXXX implementations we actually need? Why are we exposing these curves in the first place?
In the patch series that I just submitted I would like to expose at least NIST p256 to users. Fedora 34 is working to add signatures for files to rpms for the Integrity Measurment Architecture (IMA) to be able to enforce signatures on executables, libraries etc. The signatures are written out into security.ima extended attribute upon rpm installation. IMA accesses keys on a keyring to verify these file signatures. RSA signatures are much larger, so elliptic curve signatures are much better in terms of storage size needed for storing them in rpms. They add like 1% of size. Fedora is using a NIST P256 key.
Besides that Fedora and RHEL support only these curves here in openssl (Ubuntu supports a lot more):
$ openssl ecparam -list_curves secp224r1 : NIST/SECG curve over a 224 bit prime field secp256k1 : SECG curve over a 256 bit prime field secp384r1 : NIST/SECG curve over a 384 bit prime field secp521r1 : NIST/SECG curve over a 521 bit prime field prime256v1: X9.62/SECG curve over a 256 bit prime field
So from that perspective it makes a lot of sense to support some of these and allow users to load them into the kernel.
In my patch series I initially had registered the akciphers under the names ecc-nist-p192 and ecc-nist-p256 but now, in V4, joined them together as 'ecdsa'. This may be too generic for a name. Maybe it should be called ecsda-nist for the NIST family.
Stefan
Herbert Xu
maintainerRe: [PATCH v7 4/7] crypto: add ecc curve and expose them
Quoted 5 lines · Stefan Berger
In my patch series I initially had registered the akciphers under the names ecc-nist-p192 and ecc-nist-p256 but now, in V4, joined them together as 'ecdsa'. This may be too generic for a name. Maybe it should be called ecsda-nist for the NIST family.
What I'm proposing is specifying the curve in the name as well, i.e., ecdsa-nist-p192 instead of just ecdsa or ecdsa-nist.
This simplifies the task of handling hardware that only supports a subset of curves.
There is a parallel discussion of exactly what curves we should support in the kernel. Personally if there is a user in the kernel for it then I'm happy to see it added. In your specific case, as long as your use of the algorithm in x509 is accepted then I don't have any problems with adding support in the Crypto API.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Re: [PATCH v7 4/7] crypto: add ecc curve and expose them
Herbert,
Quoted 7 lines · Herbert Xu
Quoted 5 lines · Stefan Berger
In my patch series I initially had registered the akciphers under the names ecc-nist-p192 and ecc-nist-p256 but now, in V4, joined them together as 'ecdsa'. This may be too generic for a name. Maybe it should be called ecsda-nist for the NIST family.
Quoted 5 lines
What I'm proposing is specifying the curve in the name as well, i.e., ecdsa-nist-p192 instead of just ecdsa or ecdsa-nist.
This simplifies the task of handling hardware that only supports a subset of curves.
So, if some implementation supports multiple curves (like EC-RDSA currently supports 5 curves), it should add 5 ecrdsa-{a,b,c,..} algorithms with actually the same top level implementation? Right?
Quoted 11 lines
There is a parallel discussion of exactly what curves we should support in the kernel. Personally if there is a user in the kernel for it then I'm happy to see it added. In your specific case, as long as your use of the algorithm in x509 is accepted then I don't have any problems with adding support in the Crypto API.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Re: [PATCH v7 4/7] crypto: add ecc curve and expose them
Quoted 14 lines · Vitaly Chikunov
Herbert,
Quoted 10 lines · Herbert Xu
Quoted 5 lines · Stefan Berger
In my patch series I initially had registered the akciphers under the names ecc-nist-p192 and ecc-nist-p256 but now, in V4, joined them together as 'ecdsa'. This may be too generic for a name. Maybe it should be called ecsda-nist for the NIST family.
What I'm proposing is specifying the curve in the name as well, i.e., ecdsa-nist-p192 instead of just ecdsa or ecdsa-nist.
Quoted 8 lines
Quoted 2 lines
This simplifies the task of handling hardware that only supports a subset of curves.
So, if some implementation supports multiple curves (like EC-RDSA currently supports 5 curves), it should add 5 ecrdsa-{a,b,c,..} algorithms with actually the same top level implementation? Right?
Yes. The only difference will be the init() function, which can be used to set the TFM properties that define which curve is being used. The other routines can be generic, and refer to those properties if the behavior is curve-specific.
Quoted 12 lines
Quoted 12 lines
There is a parallel discussion of exactly what curves we should support in the kernel. Personally if there is a user in the kernel for it then I'm happy to see it added. In your specific case, as long as your use of the algorithm in x509 is accepted then I don't have any problems with adding support in the Crypto API.
Cheers,
--
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Re: [PATCH v7 4/7] crypto: add ecc curve and expose them
Ard,
Quoted 24 lines · Ard Biesheuvel
Quoted 14 lines · Vitaly Chikunov
Herbert,
Quoted 10 lines · Herbert Xu
Quoted 5 lines · Stefan Berger
In my patch series I initially had registered the akciphers under the names ecc-nist-p192 and ecc-nist-p256 but now, in V4, joined them together as 'ecdsa'. This may be too generic for a name. Maybe it should be called ecsda-nist for the NIST family.
What I'm proposing is specifying the curve in the name as well, i.e., ecdsa-nist-p192 instead of just ecdsa or ecdsa-nist.
Quoted 8 lines
Quoted 2 lines
This simplifies the task of handling hardware that only supports a subset of curves.
So, if some implementation supports multiple curves (like EC-RDSA currently supports 5 curves), it should add 5 ecrdsa-{a,b,c,..} algorithms with actually the same top level implementation? Right?
Quoted 4 lines
Yes. The only difference will be the
init()function, which can be used to set the TFM properties that define which curve is being used. The other routines can be generic, and refer to those properties if the behavior is curve-specific.
Thanks. This may be good!
JFYI. There is possible non-hardware accelerated implementations for ECC algorithms which (perhaps) may never go to the kernel source, because they are generated code. For example
https://gitlab.com/nisec/ecckiila
Re: [PATCH v7 4/7] crypto: add ecc curve and expose them
In reply to Herbert XuQuoted 9 lines · Herbert Xu
Quoted 1 line · Meng Yu
1. Add ecc
curves(P224, P384, P521)for ECDH;OK I think this is getting unwieldy.
In light of the fact that we already have hardware that supports a specific subset of curves, I think perhaps it would be better to move the curve ID from the key into the algorithm name instead.
Quoted 6 lines
IOW, instead of allocating ecdh, you would allocate ecdh-nist-pXXX.
Any comments?
Thanks,
Yes,It is a good idea, thank you!
PATCH v7 4/7 crypto: add ecc curve and expose them
In reply to Herbert XuQuoted 9 lines · Herbert Xu
Quoted 1 line · Meng Yu
1. Add ecc
curves(P224, P384, P521)for ECDH;OK I think this is getting unwieldy.
In light of the fact that we already have hardware that supports a specific subset of curves, I think perhaps it would be better to move the curve ID from the key into the algorithm name instead.
I think I understand you, I'm not using ECDH at the moment, but IMHO maybe we could use enum OID of oid_registry.h as curve ID and eliminate the duplicate ECC_CURVE_NIST_{...} from ecdh.h. Or perhaps put another param in struct ecc_curve with OID, because the name already exists.
Quoted 3 lines
IOW, instead of allocating ecdh, you would allocate ecdh-nist-pXXX.
Any comments?
I recently sent a patch for the ECDSA signature verification, that use the NIST-P curves to check elf32 binary modules and signatures in about 450k T-DRE voting machines, in the Brazilian Elections across the country. I put the other curves because we started testing them (P256, P384) for speed measurement, but we ended up using P521 in our production version since 2017 in the 4.9.xxx kernel, and now in 5.4.xxx.
In this patch I'm using akcipher allocate like ecdsa(sha1,sha256,...), because the ecdsa algo is generic, and using the curve name and ndigits inside vli_mmod_fast to discover the curve, but I agree the correct way would be allocate ecdsa-nist-p521(sha1,...) and have all params for the curve inside strut ecc_curve, remembering that we have anothers curves incoming, like Edwards.
regards,
--
Email: Saulo Alessandre <[email protected]>
Herbert Xu
maintainerRe: [PATCH v7 4/7] crypto: add ecc curve and expose them
Quoted 7 lines · Saulo Alessandre
In this patch I'm using akcipher allocate like
ecdsa(sha1,sha256,...), because the ecdsa algo is generic, and using the curve name and ndigits insidevli_mmod_fastto discover the curve, but I agree the correct way would be allocate ecdsa-nist-p521(sha1,...) and have all params for the curve inside strutecc_curve, remembering that we have anothers curves incoming, like Edwards.
I'm not sure whether we really should encode hash into the algorithm name. This may be something that we can move into setkey instead.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
PATCH v7 5/7 crypto: add curve 25519 and expose them
In reply to Meng Yu1. Add curve 25519 parameters;
2. Add curve25519 function 'ecc_get_curve25519_param', to be exposed to everyone in kernel tree.
--- crypto/ecc.c | 7 +++++++ crypto/ecc_curve_defs.h | 17 +++++++++++++++++ include/crypto/ecc_curve.h | 7 +++++++ 3 files changed, 31 insertions(+)
crypto/ecc.c +7 -0
@@ -53,6 +53,13 @@ const struct ecc_curve *ecc_get_curve_by_id(unsigned int curve_id) }EXPORT_SYMBOL (ecc_get_curve_by_id); +/* Returns curv25519 curve param */ +const struct ecc_curve *ecc_get_curve25519 (void ) +{ +return &ecc_25519; +} +EXPORT_SYMBOL (ecc_get_curve25519); +static inline const struct ecc_curve *ecc_get_curve (unsigned int curve_id) {switch (curve_id) {
crypto/ecc_curve_defs.h +17 -0
@@ -160,4 +160,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
include/crypto/ecc_curve.h +7 -0
@@ -50,4 +50,11 @@ struct ecc_curve {*/ const struct ecc_curve *ecc_get_curve_by_id (unsigned int curve_id); +/** +* ecc_get_curve25519() - get curve25519 curve; +* +* Returns curve25519 +*/ +const struct ecc_curve *ecc_get_curve25519 (void ); +#endif
Signature · 1 line
2.8.1
PATCH v7 6/7 crypto: hisilicon/hpre - add 'ECDH' algorithm
In reply to Meng Yu1. Enable 'ECDH' algorithm in Kunpeng 930;
2. HPRE ECDH Support ECC curve: P192, P224, P256, P384, P521.
--- drivers/crypto/hisilicon/hpre/hpre.h | 2 +- drivers/crypto/hisilicon/hpre/hpre_crypto.c | 493 +++++++++++++++++++++++++++- drivers/crypto/hisilicon/hpre/hpre_main.c | 1 + 3 files changed, 491 insertions(+), 5 deletions(-)
drivers/crypto/hisilicon/hpre/hpre.h +1 -1
@@ -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 +489 -4
557 lines not on this page · raw message
drivers/crypto/hisilicon/hpre/hpre_main.c +1 -0
@@ -1074,4 +1074,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" );
Signature · 1 line
2.8.1
PATCH v7 7/7 crypto: hisilicon/hpre - add 'CURVE25519' algorithm
In reply to Meng YuEnable 'CURVE25519' algorithm in Kunpeng 930.
--- drivers/crypto/hisilicon/Kconfig | 1 + drivers/crypto/hisilicon/hpre/hpre.h | 2 + drivers/crypto/hisilicon/hpre/hpre_crypto.c | 370 +++++++++++++++++++++++++++- 3 files changed, 364 insertions(+), 9 deletions(-)
drivers/crypto/hisilicon/Kconfig +1 -0
@@ -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
@@ -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 +361 -9
436 lines not on this page · raw message
Signature · 1 line
2.8.1