Skip to contentSkip to conversation

crypto: ecdh - register NIST P384

PATCH In review Hui Tang 2 participants 6 messages May 22, 2021 – May 28, 2021

Subsystems (2)
lore
Share & tools
lore

Hui Tang

author
#0 lore raw

v3 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

---
v1 -> v2:
* Add patch#1:
- Fix ecdh-nist-p192's entry in testmgr.
- Add a comment for registering ecdh-nist-p192.

v2 - > v3:
* Fix patch#1 subject format.
---

Hui Tang (4):
crypto: ecdh - fix ecdh-nist-p192's entry in testmgr
crypto: ecdh - fix 'ecdh_init'
crypto: ecdh - register NIST P384 tfm
crypto: ecdh - add test suite for NIST P384

 crypto/ecdh.c    | 45 +++++++++++++++++++++++++++++++++++++++-
 crypto/testmgr.c | 10 ++++++---
 crypto/testmgr.h | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 112 insertions(+), 6 deletions(-)

--
2.8.1

author
#1 lore raw

PATCH v3 1/4 crypto: ecdh - fix ecdh-nist-p192's entry in testmgr

Add a comment that p192 will fail to register in FIPS mode.

Fix ecdh-nist-p192's entry in testmgr by removing the ifdefs and not setting fips_allowed.

---
 crypto/ecdh.c    | 1 +
 crypto/testmgr.c | 3 ---
 crypto/testmgr.h | 2 --
 3 files changed, 1 insertion(+), 5 deletions(-)
crypto/ecdh.c +1 -0
index 04a427b..4227d35 100644
@@ -179,6 +179,7 @@ static int ecdh_init(void)
 {
 	int ret;
 
+	/* NIST p192 will fail to register in FIPS mode */
 	ret = crypto_register_kpp(&ecdh_nist_p192);
 	ecdh_nist_p192_registered = ret == 0;
 
crypto/testmgr.c +0 -3
index 10c5b3b..26e40db 100644
@@ -4899,15 +4899,12 @@ static const struct alg_test_desc alg_test_descs[] = {
 		}
 	}, {
 #endif
-#ifndef CONFIG_CRYPTO_FIPS
 		.alg = "ecdh-nist-p192",
 		.test = alg_test_kpp,
-		.fips_allowed = 1,
 		.suite = {
 			.kpp = __VECS(ecdh_p192_tv_template)
 		}
 	}, {
-#endif
 		.alg = "ecdh-nist-p256",
 		.test = alg_test_kpp,
 		.fips_allowed = 1,
crypto/testmgr.h +0 -2
index 34e4a3d..fe1e59d 100644
@@ -2685,7 +2685,6 @@ static const struct kpp_testvec curve25519_tv_template[] = {
 }
 };
 
-#ifndef CONFIG_CRYPTO_FIPS
 static const struct kpp_testvec ecdh_p192_tv_template[] = {
 	{
 	.secret =
@@ -2725,7 +2724,6 @@ static const struct kpp_testvec ecdh_p192_tv_template[] = {
 	.expected_ss_size = 24
 	}
 };
-#endif
 
 static const struct kpp_testvec ecdh_p256_tv_template[] = {
 	{
Signature · 1 line
2.8.1
author
#2 lore raw

PATCH v3 2/4 crypto: ecdh - fix 'ecdh_init'

In reply to Hui Tang

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
index 4227d35..e2c4808 100644
@@ -183,7 +183,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
author
#3 lore raw

PATCH v3 3/4 crypto: ecdh - register NIST P384 tfm

In reply to Hui Tang

Add 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
index e2c4808..70f312e 100644
@@ -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)
@@ -187,8 +212,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);
@@ -200,6 +232,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
author
#4 lore raw

PATCH v3 4/4 crypto: ecdh - add test suite for NIST P384

In reply to Hui Tang

Add 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
index 26e40db..1f7f63e 100644
@@ -4912,6 +4912,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
maintainer
#5 lore raw
In reply to Hui Tang
Quoted 31 lines · Hui Tang

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

---
v1 -> v2:
* Add patch#1:
- Fix ecdh-nist-p192's entry in testmgr.
- Add a comment for registering ecdh-nist-p192.

v2 - > v3:
* Fix patch#1 subject format.
---

Hui Tang (4):
crypto: ecdh - fix ecdh-nist-p192's entry in testmgr
crypto: ecdh - fix 'ecdh_init'
crypto: ecdh - register NIST P384 tfm
crypto: ecdh - add test suite for NIST P384

Quoted 4 lines
 crypto/ecdh.c    | 45 +++++++++++++++++++++++++++++++++++++++-
 crypto/testmgr.c | 10 ++++++---
 crypto/testmgr.h | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 112 insertions(+), 6 deletions(-)

All applied. 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