]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
DH: Make DH_bits(), DH_size(), and DH_security_bits() check that there are key parameters
authorSahana Prasad <sahana@redhat.com>
Mon, 25 Jan 2021 13:44:29 +0000 (14:44 +0100)
committerDmitry Belyavskiy <beldmit@gmail.com>
Thu, 18 Feb 2021 11:04:35 +0000 (12:04 +0100)
Fixes #13569
Signed-off-by: Sahana Prasad <sahana@redhat.com>
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/13955)

crypto/dh/dh_lib.c
doc/man3/DH_size.pod

index e8a66878ab39c3bb0ddc81898ad1dd8acce36bfe..46aba02bad75d54ca2626f699060cf7ffb7cbf9b 100644 (file)
@@ -187,12 +187,16 @@ void *DH_get_ex_data(const DH *d, int idx)
 
 int DH_bits(const DH *dh)
 {
-    return BN_num_bits(dh->params.p);
+    if (dh->params.p != NULL)
+        return BN_num_bits(dh->params.p);
+    return -1;
 }
 
 int DH_size(const DH *dh)
 {
-    return BN_num_bytes(dh->params.p);
+    if (dh->params.p != NULL)
+        return BN_num_bytes(dh->params.p);
+    return -1;
 }
 
 int DH_security_bits(const DH *dh)
@@ -204,7 +208,9 @@ int DH_security_bits(const DH *dh)
         N = dh->length;
     else
         N = -1;
-    return BN_security_bits(BN_num_bits(dh->params.p), N);
+    if (dh->params.p != NULL)
+        return BN_security_bits(BN_num_bits(dh->params.p), N);
+    return -1;
 }
 
 void DH_get0_pqg(const DH *dh,
index 099c1bad3f8e45f312fbd1b33cc4cd8277c5fd8a..99e34034f2cbbcbec3f47cc2f1493ae0daba7afc 100644 (file)
@@ -38,11 +38,14 @@ key. See L<BN_security_bits(3)>.
 
 =head1 RETURN VALUES
 
-DH_bits() returns the number of bits in the key.
+DH_bits() returns the number of bits in the key, or -1 if
+B<dh> doesn't hold any key parameters.
 
-DH_size() returns the prime size of Diffie-Hellman in bytes.
+DH_size() returns the prime size of Diffie-Hellman in bytes, or -1 if
+B<dh> doesn't hold any key parameters.
 
-DH_security_bits() returns the number of security bits.
+DH_security_bits() returns the number of security bits, or -1 if
+B<dh> doesn't hold any key parameters.
 
 =head1 SEE ALSO