crypto: ecdh - fix 'ecdh_init'
authorHui Tang <tanghui20@huawei.com>
Sat, 22 May 2021 02:44:29 +0000 (10:44 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 28 May 2021 07:11:47 +0000 (15:11 +0800)
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@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/ecdh.c

index 1974675..b6f493e 100644 (file)
@@ -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)