[PATCH 1/3] crypto: ecdh - fix 'ecdh_init'

From: Hui Tang
Date: Wed May 12 2021 - 02:43:26 EST


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 <tanghui20@xxxxxxxxxx>
---
crypto/ecdh.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/crypto/ecdh.c b/crypto/ecdh.c
index 07eb34f..65fb685 100644
--- a/crypto/ecdh.c
+++ b/crypto/ecdh.c
@@ -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)
--
2.8.1