DH_SIZE(3ossl)

πŸ“¦ version 3.5.0, in opensuse-leap 16.0

πŸ’… 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 defining OPENSSL_API_COMPAT with a suitable version value β€” peep openssl_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 by DH_compute_key(3). No guessing, no vibes-based malloc, we love to see it 🫢
  • DH_security_bits() β€” returns the number of security bits of the given dh key. See BN_security_bits(3) for the lore πŸ“–
⚠️ also, important: dh and dh->p must not be NULL. Like, do not do that. That's not the move. πŸ’€

πŸ’– RETURN VALUES πŸ’–

  • DH_bits() β€” returns the number of bits in the key, or -1 if dh doesn't hold any key parameters.
  • DH_size() β€” returns the prime size of Diffie-Hellman in bytes, or -1 if dh doesn't hold any key parameters.
  • DH_security_bits() β€” returns the number of security bits, or -1 if dh doesn'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 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