VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   33 Branches   55 Tags
author: Stephan Müller <smueller@chronox.de> 2020-07-20 19:07:48 +0200 committer: Herbert Xu <herbert@gondor.apana.org.au> 2020-07-31 18:08:58 +1000 commit: e7d2b41e5c773c1e00f0f30519b9790ba7e4a58c parent: ef19f826eceabdef3a710958cbf3549355267645
Commit Summary:
crypto: ecdh - check validity of Z before export
Diffstat:
1 file changed, 7 insertions, 2 deletions
diff --git a/crypto/ecc.c b/crypto/ecc.c
index 86c324936a2b..c8b259e59704 100644
--- a/crypto/ecc.c
+++ b/crypto/ecc.c
@@ -1495,11 +1495,16 @@ int crypto_ecdh_shared_secret(unsigned int curve_id, unsigned int ndigits,
 
 	ecc_point_mult(product, pk, priv, rand_z, curve, ndigits);
 
-	ecc_swap_digits(product->x, secret, ndigits);
-
-	if (ecc_point_is_zero(product))
+	if (ecc_point_is_zero(product)) {
 		ret = -EFAULT;
+		goto err_validity;
+	}
+
+	ecc_swap_digits(product->x, secret, ndigits);
 
+err_validity:
+	memzero_explicit(priv, sizeof(priv));
+	memzero_explicit(rand_z, sizeof(rand_z));
 	ecc_free_point(product);
 err_alloc_product:
 	ecc_free_point(pk);