]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
dh_kmgmt.c: Avoid expensive public key validation for known safe-prime groups
authorTomas Mraz <tomas@openssl.org>
Mon, 5 Aug 2024 15:54:14 +0000 (17:54 +0200)
committerTomas Mraz <tomas@openssl.org>
Wed, 7 Aug 2024 17:47:00 +0000 (19:47 +0200)
The partial validation is fully sufficient to check the key validity.

Thanks to Szilárd Pfeiffer for reporting the issue.

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/25088)

providers/implementations/keymgmt/dh_kmgmt.c

index 82c3093b122c2e4257fbb3aacaa631c5e9e9ad86..ebdce767102ee5febd338fe5d402a35f9ca703c4 100644 (file)
@@ -388,9 +388,11 @@ static int dh_validate_public(const DH *dh, int checktype)
     if (pub_key == NULL)
         return 0;
 
-    /* The partial test is only valid for named group's with q = (p - 1) / 2 */
-    if (checktype == OSSL_KEYMGMT_VALIDATE_QUICK_CHECK
-        && ossl_dh_is_named_safe_prime_group(dh))
+    /*
+     * The partial test is only valid for named group's with q = (p - 1) / 2
+     * but for that case it is also fully sufficient to check the key validity.
+     */
+    if (ossl_dh_is_named_safe_prime_group(dh))
         return ossl_dh_check_pub_key_partial(dh, pub_key, &res);
 
     return DH_check_pub_key_ex(dh, pub_key);