DH_NEW(3)

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

πŸ’– DH_NEW(3) β€” like, the whole allocate-and-free situation for DH objects πŸ’–

okay bestie, this one's from the Library Functions Manual (yes, the Library Functions Manual, we stan a classic) and it's all about the three little functions that birth a DH object, keep it alive, and yeet it into the void. let's get into it 🫢


✨ NAME ✨

DH_new, DH_up_ref, DH_free β€” allocate and free DH objects. that's the whole vibe. πŸ’…


🌸 SYNOPSIS 🌸

#include <openssl/dh.h>

DH*
DH_new(void);

int
DH_up_ref(DH *dh);

void
DH_free(DH *dh);

look at them. three little icons. πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

so the DH functions implement the Diffie-Hellman key agreement protocol β€” yes that Diffie-Hellman, the og key agreement protocol, main character energy fr fr πŸ”₯

  • DH_new() β€” allocates and initializes a DH structure, and sets the reference count to 1. it's literally equivalent to DH_new_method(3) with a NULL argument. no cap, that's the exact same thing. ✨
  • DH_up_ref() β€” increments the reference count by 1. that's it. that's the whole job. keep it alive bestie πŸ’–
  • DH_free() β€” decrements the reference count by 1. and if it hits 0? it frees the DH structure and its components. the values are erased before the memory is returned to the system (yes, they're being responsible about it, we love to see it πŸ™ˆ). and if dh is a NULL pointer, no action occurs β€” nothing happens, no drama, no crash, we simply move on. πŸ’€
lowkey important: reference counting is a whole thing, so don't go freeing stuff twice or the vibe check will fail catastrophically 😭

πŸŽ€ RETURN VALUES πŸŽ€

  • if the allocation fails, DH_new() returns NULL and sets an error code that you can grab with ERR_get_error(3). so if you see a NULL, go check the error stack, bestie. otherwise it returns a pointer to the newly allocated structure 🌈
  • DH_up_ref() returns 1 for success or 0 for failure. simple as that. πŸ“

⭐ SEE ALSO ⭐

the whole friend group, gathered together 🫢

BN_new(3), crypto(3), d2i_DHparams(3), DH_generate_key(3), DH_generate_parameters(3), DH_get0_pqg(3), DH_get_ex_new_index(3), DH_security_bits(3), DH_set_method(3), DH_size(3), DHparams_print(3), DSA_dup_DH(3), EVP_PKEY_CTX_set_dh_paramgen_prime_len(3), EVP_PKEY_set1_DH(3)

like, go read them. iykyk πŸ’œ


🧚 HISTORY 🧚

  • DH_new() and DH_free() first appeared in SSLeay 0.5.1 and have been available since OpenBSD 2.4. vintage. iconic. they've been doing this since before we were born πŸ’…
  • DH_up_ref() first appeared in OpenSSL 0.9.7 and has been available since OpenBSD 3.2. a slightly younger legend but a legend nonetheless πŸ‘‘

and that's the page, bestie!! this one's from Debian, dated July 13, 2022 β€” so go forth, allocate responsibly, and remember: every DH_new() deserves its DH_free(). mwah πŸ’‹πŸŽ€βœ¨

πŸ“¦ where this page comes from