DH_NEW(3)
π 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 aDHstructure, and sets the reference count to1. it's literally equivalent toDH_new_method(3)with aNULLargument. no cap, that's the exact same thing. β¨DH_up_ref()β increments the reference count by1. that's it. that's the whole job. keep it alive bestie πDH_free()β decrements the reference count by1. and if it hits0? it frees theDHstructure 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 ifdhis aNULLpointer, 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()returnsNULLand sets an error code that you can grab withERR_get_error(3). so if you see aNULL, go check the error stack, bestie. otherwise it returns a pointer to the newly allocated structure π DH_up_ref()returns1for success or0for 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()andDH_free()first appeared in SSLeay0.5.1and have been available since OpenBSD2.4. vintage. iconic. they've been doing this since before we were born πDH_up_ref()first appeared in OpenSSL0.9.7and has been available since OpenBSD3.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
- opensuse-leap 16.0: libressl-devel-doc 4.1.0-bp160.1.1 Β· OpenSSL
- Copyright (c) 2000 The OpenSSL Project. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms