Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DH: Make DH_bits(), DH_size(), and DH_security_bits() check that there are key parameters #13955

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions crypto/dh/dh_lib.c
Expand Up @@ -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)
Expand All @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions doc/man3/DH_size.pod
Expand Up @@ -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

Expand Down