DH_SIZE(3ossl)
π DH_SIZE(3ossl) β get Diffie-Hellman prime size and security bits
okay bestie, so this is one of those pages from the OpenSSL corner of the manual β the <pink>3ossl</pink> vibe, iykyk. It's about three little functions that peek at your Diffie-Hellman key and tell you how big it is. Cute, tiny, and alsoβ¦ deprecated π. We'll get to that.
β¨ SYNOPSIS β¨
First, the include (manifesting that header):
#include <openssl/dh.h>
π¨ heads up babes: the following functions have been<red>deprecated</red>since OpenSSL 3.0, and you can hide them entirely by definingOPENSSL_API_COMPATwith a suitable version value β peepopenssl_user_macros(7)for the deets β¨
int DH_bits(const DH *dh);
int DH_size(const DH *dh);
int DH_security_bits(const DH *dh);
That's literally the whole cast π
π¦ DESCRIPTION π¦
Okay so first thing's first, and I need you to hear me on this: the functions described on this page are deprecated. Not me being dramatic, that's just facts. Applications should instead use EVP_PKEY_get_bits(3), EVP_PKEY_get_security_bits(3) and EVP_PKEY_get_size(3). Slay, moving on π
DH_bits()β returns the number of significant bits. That's it, that's the whole function, she's simple and she knows it β¨DH_size()β returns the Diffie-Hellman prime size in bytes. Super useful bestie, because you can use it to figure out how much memory you need to allocate for the shared secret computed byDH_compute_key(3). No guessing, no vibes-basedmalloc, we love to see it π«ΆDH_security_bits()β returns the number of security bits of the givendhkey. SeeBN_security_bits(3)for the lore π
β οΈ also, important:dhanddh->pmust not beNULL. Like, do not do that. That's not the move. π
π RETURN VALUES π
DH_bits()β returns the number of bits in the key, or-1ifdhdoesn't hold any key parameters.DH_size()β returns the prime size of Diffie-Hellman in bytes, or-1ifdhdoesn't hold any key parameters.DH_security_bits()β returns the number of security bits, or-1ifdhdoesn't hold any key parameters.
so likeβ¦ -1 three times, it's giving "no key parameters, no thoughts, head empty" π but at least it tells you honestly instead of making something up π
π SEE ALSO π
the friend group π
π HISTORY π
All functions were deprecated in OpenSSL 3.0. Periodt. π
π COPYRIGHT π
Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
okay that's the whole page bestie, go forth and check your DH sizes responsibly π§π
mwah π β this was 3.5.0, dated 2026-09-25, and yes it's still called DH_SIZE(3ossl) π
π¦ where this page comes from
- opensuse-leap 16.0: openssl-3-doc 3.5.0-160000.11.1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms