diff mbox series

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

Message ID 1620801602-49287-2-git-send-email-tanghui20@huawei.com (mailing list archive)
State Changes Requested
Delegated to: Herbert Xu
Headers show
Series crypto: ecdh - register NIST P384 | expand

Commit Message

Hui Tang May 12, 2021, 6:40 a.m. UTC
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>
---
 crypto/ecdh.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

Comments

Herbert Xu May 21, 2021, 7:45 a.m. UTC | #1
On Wed, May 12, 2021 at 02:40:00PM +0800, Hui Tang wrote:
> 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>
> ---
>  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,
Hui Tang May 21, 2021, 8:08 a.m. UTC | #2
On 2021/5/21 15:45, Herbert Xu wrote:
> On Wed, May 12, 2021 at 02:40:00PM +0800, Hui Tang wrote:
>> 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>
>> ---
>>  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.
>

Okay, I will fix it in next version, and 'ecdsa_init' should
do the same thing too?

>
Herbert Xu May 21, 2021, 8:13 a.m. UTC | #3
On Fri, May 21, 2021 at 04:08:10PM +0800, Hui Tang wrote:
> 
> On 2021/5/21 15:45, Herbert Xu wrote:
> > On Wed, May 12, 2021 at 02:40:00PM +0800, Hui Tang wrote:
> > > 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>
> > > ---
> > >  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.
> 
> 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,
Stephan Mueller May 21, 2021, 9:36 a.m. UTC | #4
Am Freitag, dem 21.05.2021 um 16:13 +0800 schrieb Herbert Xu:
> On Fri, May 21, 2021 at 04:08:10PM +0800, Hui Tang wrote:
> 
> 
> 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
diff mbox series

Patch

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)