DH_GET0_PQG(3ossl)

πŸ’– DH_GET0_PQG(3ossl) β€” the OpenSSL girlies' guide πŸ’–

okay so bestie, this is DH_GET0_PQG(3ossl), a page straight out of the OpenSSL manual, and it's literally all about the routines for getting and setting data inside a DH object. yes, that DH. Diffie–Hellman. the whole vibe. πŸ¦‹


✨ NAME ✨

DH_get0_pqg, DH_set0_pqg, DH_get0_key, DH_set0_key, DH_get0_p, DH_get0_q, DH_get0_g, DH_get0_priv_key, DH_get0_pub_key, DH_clear_flags, DH_test_flags, DH_set_flags, DH_get0_engine, DH_get_length, DH_set_length β€” routines for getting and setting data in a DH object. that's the whole squad right there. πŸ‘‘


🌸 SYNOPSIS 🌸

#include <openssl/dh.h>

the following functions have been deprecated since OpenSSL 3.0, and can be hidden entirely by defining OPENSSL_API_COMPAT with a suitable version value, see openssl_user_macros(7):

void DH_get0_pqg(const DH *dh,
                 const BIGNUM **p, const BIGNUM **q, const BIGNUM **g);
int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g);
void DH_get0_key(const DH *dh,
                 const BIGNUM **pub_key, const BIGNUM **priv_key);
int DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key);
const BIGNUM *DH_get0_p(const DH *dh);
const BIGNUM *DH_get0_q(const DH *dh);
const BIGNUM *DH_get0_g(const DH *dh);
const BIGNUM *DH_get0_priv_key(const DH *dh);
const BIGNUM *DH_get0_pub_key(const DH *dh);
void DH_clear_flags(DH *dh, int flags);
int DH_test_flags(const DH *dh, int flags);
void DH_set_flags(DH *dh, int flags);

long DH_get_length(const DH *dh);
int DH_set_length(DH *dh, long length);

ENGINE *DH_get0_engine(DH *d);
🚨 bestie listen. ALL of the functions described on this page are deprecated. every single one. don't be the main character who builds new stuff on them, okay?

πŸ’… DESCRIPTION πŸ’…

so, all of the functions on this page are deprecated, periodt. if your app needs something that returns a BIGNUM, use EVP_PKEY_get_bn_param(3) instead. and for more info, go read EVP_PKEY-DH(7). 🫢

a DH object holds the parameters p, q and g. and like β€” note that the q parameter is optional, she's not mandatory. it also contains a public key (pub_key) and, optionally, a private key (priv_key).

you can grab the p, q and g parameters by calling DH_get0_pqg(). if they haven't been set yet, then *p, *q and *g get set to NULL. otherwise they're set to pointers to their respective values. and these point directly at the internal representations of the values, so do NOT free them directly, ok?? πŸ™ˆ any of the out parameters p, q, and g can be NULL, and in that case no value gets returned for that parameter. nbd.

you can set the p, q and g values by calling DH_set0_pqg() and passing the new values for p, q and g as parameters to the function. calling this function transfers the memory management of the values over to the DH object, so the values you passed in should not be freed directly after this function has been called. the q parameter may be NULL. DH_set0_pqg() also checks if the parameters associated with p and g and optionally q are associated with known safe prime groups. if it's a safe prime group, then the value of q will be set to q = (p - 1) / 2 if q is NULL. and the optional length parameter will be set to BN_num_bits(q) if q is not NULL. iconic behaviour honestly. ✨

to get the public and private key values, use the DH_get0_key() function. a pointer to the public key gets stored in *pub_key, and a pointer to the private key gets stored in *priv_key. either may be NULL if they haven't been set yet β€” although if the private key has been set, then the public key must be. the values point to the internal representation of the public key and private key values, so this memory should not be freed directly. any of the out parameters pub_key and priv_key can be NULL, in which case no value will be returned for that parameter.

you can set the public and private key values using DH_set0_key(). either parameter may be NULL, which means the corresponding DH field is left untouched. as with DH_set0_pqg(), this function transfers the memory management of the key values to the DH object, and therefore they should not be freed directly after this function has been called. don't do it. i'm watching. πŸ‘€

any of the values p, q, g, priv_key, and pub_key can also be retrieved separately by the corresponding function DH_get0_p(), DH_get0_q(), DH_get0_g(), DH_get0_priv_key(), and DH_get0_pub_key(), respectively. one value, one function, very demure, very mindful. πŸŽ€

DH_set_flags() sets the flags in the flags parameter on the DH object. multiple flags can be passed in one go (bitwise ORed together). any flags that are already set are left set. DH_test_flags() tests to see whether the flags passed in the flags parameter are currently set in the DH object. multiple flags can be tested in one go. all flags that are currently set are returned, or zero if none of the flags are set. DH_clear_flags() clears the specified flags within the DH object. so set, test, clear β€” the full cycle. πŸ’«

DH_get0_engine() returns a handle to the ENGINE that has been set for this DH object, or NULL if no such ENGINE has been set. this function is deprecated. all engines should be replaced by providers. ok bye engines πŸ‘‹

the DH_get_length() and DH_set_length() functions get and set the optional length parameter associated with this DH object. if the length is nonzero then it's used, otherwise it's ignored. the length parameter indicates the length of the secret exponent (private key) in bits. for safe prime groups the optional length parameter length can be set to a value greater or equal to 2 * maximum_target_security_strength(BN_num_bits(p)) as listed in SP800-56Ar3 Table(s) 25 & 26. these functions are deprecated and should be replaced with EVP_PKEY_CTX_set_params() and EVP_PKEY_get_int_param() using the parameter key OSSL_PKEY_PARAM_DH_PRIV_LEN as described in EVP_PKEY-DH(7). 😌


πŸ¦‹ NOTES πŸ¦‹

values retrieved with DH_get0_key() are owned by the DH object used in the call and may therefore not be passed to DH_set0_key(). if you need to, duplicate the received value using BN_dup() and pass the duplicate. same energy applies to DH_get0_pqg() and DH_set0_pqg(). don't be passing borrowed values around, it's giving chaos. 😭


🌈 RETURN VALUES 🌈

  • DH_set0_pqg() and DH_set0_key() return 1 on success or 0 on failure. simple as.
  • DH_get0_p(), DH_get0_q(), DH_get0_g(), DH_get0_priv_key(), and DH_get0_pub_key() return the respective value, or NULL if it is unset.
  • DH_test_flags() returns the current state of the flags in the DH object.
  • DH_get0_engine() returns the ENGINE set for the DH object or NULL if no ENGINE has been set.
  • DH_get_length() returns the length of the secret exponent (private key) in bits, or zero if no such length has been explicitly set.

πŸ‘‘ SEE ALSO πŸ‘‘

DH_new(3), DH_new(3), DH_generate_parameters(3), DH_generate_key(3), DH_set_method(3), DH_size(3), DH_meth_new(3)

yes, DH_new(3) is listed twice. no, that's not a typo on my part, that's just how the original rolls. keeping it exactly as-is bestie, we don't edit the source πŸ’–

🧚 HISTORY 🧚

the functions described here were added in OpenSSL 1.1.0.

all of these functions were deprecated in OpenSSL 3.0. the glow-up was real but the deprecation was realer. πŸ’€


Copyright 2016-2022 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>.


and that's the whole page bestie, we ate and left absolutely no crumbs πŸ“βœ¨ this was DH_GET0_PQG(3ossl) from OpenSSL 3.5.9, dated 2026-09-29 β€” mwah, go forth and don't free those internal pointers, love u πŸ’œπŸ«Ά

πŸ“¦ where this page comes from