crypto: ecdh - register NIST P384
Subsystems (2)
cover crypto: ecdh - register NIST P384
Register NIST P384 tfm and extend the testmgr with NIST P384 test vectors.
Summary of changes:
* crypto/ecdh.c
- fix 'ecdh_init' not unregistering NIST P192
- add ecdh_nist_p384_init_tfm
- register and unregister P384 tfm
* crypto/testmgr.c
- add test vector for P384 on vector of tests
* crypto/testmgr.h
- add test vector params for P384
Hui Tang (3):
crypto: ecdh - fix 'ecdh_init'
crypto: ecdh - register NIST P384 tfm
crypto: ecdh - add test suite for NIST P384
crypto/ecdh.c | 44 +++++++++++++++++++++++++++++++++++++++- crypto/testmgr.c | 7 +++++++ crypto/testmgr.h | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 1 deletion(-)
--
2.8.1
PATCH 1/3 crypto: ecdh - fix 'ecdh_init'
NIST P192 is not unregistered if failed to register NIST P256, actually it need to unregister the algorithms already registered.
--- crypto/ecdh.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
crypto/ecdh.c +10 -1
@@ -182,7 +182,16 @@ static int ecdh_init(void) ret =crypto_register_kpp (&ecdh_nist_p192); ecdh_nist_p192_registered = ret ==0 ; -return crypto_register_kpp (&ecdh_nist_p256); + ret =crypto_register_kpp (&ecdh_nist_p256); +if (ret) + goto nist_p256_error; + +return 0 ; + +nist_p256_error: +if (ecdh_nist_p192_registered) +crypto_unregister_kpp (&ecdh_nist_p192); +return ret; }static void ecdh_exit (void )
Signature · 1 line
2.8.1
PATCH 2/3 crypto: ecdh - register NIST P384 tfm
In reply to Hui TangAdd ecdh_nist_p384_init_tfm and register and unregister P384 tfm.
--- crypto/ecdh.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
crypto/ecdh.c +33 -0
@@ -173,6 +173,31 @@ static struct kpp_alg ecdh_nist_p256 = { }, }; +static int ecdh_nist_p384_init_tfm (struct crypto_kpp *tfm) +{ +struct ecdh_ctx *ctx =ecdh_get_ctx (tfm); + + ctx->curve_id =ECC_CURVE_NIST_P384 ; + ctx->ndigits =ECC_CURVE_NIST_P384_DIGITS ; + +return 0 ; +} + +static struct kpp_alg ecdh_nist_p384 = { + .set_secret = ecdh_set_secret, + .generate_public_key = ecdh_compute_value, + .compute_shared_secret = ecdh_compute_value, + .max_size = ecdh_max_size, + .init = ecdh_nist_p384_init_tfm, + .base = { + .cra_name ="ecdh-nist-p384" , + .cra_driver_name ="ecdh-nist-p384-generic" , + .cra_priority =100 , + .cra_module =THIS_MODULE , + .cra_ctxsize =sizeof (struct ecdh_ctx ), + }, +}; +static bool ecdh_nist_p192_registered;static int ecdh_init (void )
@@ -186,8 +211,15 @@ static int ecdh_init(void)if (ret) goto nist_p256_error; + ret =crypto_register_kpp (&ecdh_nist_p384); +if (ret) + goto nist_p384_error; +return 0 ; +nist_p384_error: +crypto_unregister_kpp (&ecdh_nist_p256); + nist_p256_error:if (ecdh_nist_p192_registered)crypto_unregister_kpp (&ecdh_nist_p192);
@@ -199,6 +231,7 @@ static void ecdh_exit(void)if (ecdh_nist_p192_registered)crypto_unregister_kpp (&ecdh_nist_p192);crypto_unregister_kpp (&ecdh_nist_p256); +crypto_unregister_kpp (&ecdh_nist_p384); }subsys_initcall (ecdh_init);
Signature · 1 line
2.8.1
PATCH 3/3 crypto: ecdh - add test suite for NIST P384
In reply to Hui TangAdd test vector params for NIST P384, add test vector for NIST P384 on vector of tests.
Vector param from:
https://datatracker.ietf.org/doc/html/rfc5903#section-3.1
--- crypto/testmgr.c | 7 +++++++ crypto/testmgr.h | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+)
crypto/testmgr.c +7 -0
@@ -4915,6 +4915,13 @@ static const struct alg_test_desc alg_test_descs[] = { .kpp = __VECS(ecdh_p256_tv_template) } }, { + .alg = "ecdh-nist-p384", + .test = alg_test_kpp, + .fips_allowed = 1, + .suite = { + .kpp = __VECS(ecdh_p384_tv_template) + } + }, { .alg = "ecdsa-nist-p192", .test = alg_test_akcipher, .suite = {
crypto/testmgr.h +61 -0
67 lines not on this page · raw message
Signature · 1 line
2.8.1
Herbert Xu
maintainerRe: [PATCH 1/3] crypto: ecdh - fix 'ecdh_init'
In reply to Hui TangQuoted 7 lines · Hui Tang
NIST P192 is not unregistered if failed to register NIST P256, actually it need to unregister the algorithms already registered.
Signed-off-by Hui Tang <[email protected]>--- crypto/ecdh.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
Thanks for catching this. The variable ecdh_nist_p192_registered is bogus. You should just make it so that if p192 fails to register then the init function aborts. There would then be no need to check for the registered state in the exit function.
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 1/3] crypto: ecdh - fix 'ecdh_init'
Quoted 9 lines · Herbert Xu
Quoted 7 lines · Hui Tang
NIST P192 is not unregistered if failed to register NIST P256, actually it need to unregister the algorithms already registered.
Signed-off-by Hui Tang <[email protected]>--- crypto/ecdh.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
Quoted 5 lines
Thanks for catching this. The variable
ecdh_nist_p192_registeredis bogus. You should just make it so that if p192 fails to register then the init function aborts. There would then be no need to check for the registered state in the exit function.
Okay, I will fix it in next version, and 'ecdsa_init' should do the same thing too?
Quoted 1 line
Herbert Xu
maintainerRe: [PATCH 1/3] crypto: ecdh - fix 'ecdh_init'
Quoted 11 lines · Hui Tang
Quoted 9 lines · Herbert Xu
Quoted 7 lines · Hui Tang
NIST P192 is not unregistered if failed to register NIST P256, actually it need to unregister the algorithms already registered.
Signed-off-by Hui Tang <[email protected]>--- crypto/ecdh.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
Quoted 7 lines
Quoted 4 lines
Thanks for catching this. The variable
ecdh_nist_p192_registeredis bogus. You should just make it so that if p192 fails to register then the init function aborts. There would then be no need to check for the registered state in the exit function.Okay, I will fix it in next version, and '
ecdsa_init' should do the same thing too?
Actually, it looks like it is needed for FIPS. We should add a comment that p192 will fail to register in FIPS mode and that's why there is a check for it.
Funnily enough, ecdsa has the FIPS comment but testmgr doesn't set fips_allowed for any of them while ecdh is set but has no comment.
Stephan, can you confirm that both ecdh-nist-p192 and ecdsa-nist-p192 should be disabled in FIPS mode?
Also, we should fix ecdh-nist-p192's entry in testmgr by removing the ifdefs and not setting fips_allowed.
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 1/3] crypto: ecdh - fix 'ecdh_init'
Am Freitag, dem 21.05.2021 um 16:13 +0800 schrieb Herbert Xu:
Quoted 5 lines · Hui Tang
Stephan, can you confirm that both ecdh-nist-p192 and ecdsa-nist-p192 should be disabled in FIPS mode?
Confirmed with the following caveat: sigver is allowed due to legacy considerations. Siggen / ECDH is only allowed for curves P-224 and higher.
As we introduce ECDSA today, I would not consider a legacy mode and thus disable P-192.
Ciao
Stephan