---
name: "libressl-DH_get0_pqg"
section: "3"
platform: "linux"
package: "libressl"
version: "4.4.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libressl-DH_get0_pqg"
---

# libressl-DH\_get0\_pqg(3)

get data from and set data in a DH object

## NAME

**DH\_get0\_pqg**, **DH\_get0\_p**, **DH\_get0\_q**, **DH\_get0\_g**, **DH\_set0\_pqg**, **DH\_get0\_key**, **DH\_get0\_pub\_key**, **DH\_get0\_priv\_key**, **DH\_set0\_key**, **DH\_clear\_flags**, **DH\_test\_flags**, **DH\_set\_flags**, **DH\_get0\_engine**, **DH\_set\_length** – get data from and set data in a DH object

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

**#include \<openssl/dh.h\>**

*void*\

**DH\_get0\_pqg**(*const DH \*dh*, *const BIGNUM \*\*p*, *const BIGNUM \*\*q*, *const BIGNUM \*\*g*);

*const* *BIGNUM* *\**\

**DH\_get0\_p**(*const DH \*dh*);

*const* *BIGNUM* *\**\

**DH\_get0\_q**(*const DH \*dh*);

*const* *BIGNUM* *\**\

**DH\_get0\_g**(*const DH \*dh*);

*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*);

*const* *BIGNUM* *\**\

**DH\_get0\_pub\_key**(*const DH \*dh*);

*const* *BIGNUM* *\**\

**DH\_get0\_priv\_key**(*const DH \*dh*);

*int*\

**DH\_set0\_key**(*DH \*dh*, *BIGNUM \*pub\_key*, *BIGNUM \*priv\_key*);

*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*);

*ENGINE* *\**\

**DH\_get0\_engine**(*DH \*d*);

*int*\

**DH\_set\_length**(*DH \*dh*, *long length*);

## DESCRIPTION

A *DH* object contains the parameters *p*, *g*, and optionally *q*. It also contains a public key *pub\_key* and an optional private key *priv\_key*.

The *p*, *q*, and *g* parameters can be obtained by calling **DH\_get0\_pqg**(). If the parameters have not yet been set, then \**p*, \**q*, and \**g* are set to NULL. Otherwise, they are set to pointers to the internal representations of the values that should not be freed by the application. Any of the out parameters *p*, *q*, and *g* can be NULL, in which case no value is returned for that parameter.

The *p*, *q*, and *g* values can be set by calling **DH\_set0\_pqg**(). Calling this function transfers the memory management of the values to *dh*, and therefore they should not be freed by the caller. The *q* argument may be NULL.

The **DH\_get0\_key**() function stores pointers to the internal representations of the public key in \**pub\_key* and to the private key in \**priv\_key*. Either may be NULL if it has not yet been set. If the private key has been set, then the public key must be. Any of the out parameters *pub\_key* and *priv\_key* can be NULL, in which case no value is returned for that parameter.

The public and private key values can be set using **DH\_set0\_key**(). Either parameter may be NULL, which means the corresponding *DH* field is left untouched. This function transfers the memory management of the key values to *dh*, and therefore they should not be freed by the caller.

Values retrieved with **DH\_get0\_pqg**() and **DH\_get0\_key**() are owned by the *DH* object and may therefore not be passed to **DH\_set0\_pqg**() or **DH\_set0\_key**(). If needed, duplicate the received values using BN\_dup(3) and pass the duplicates.

Any of the values *p*, *q*, *g*, *pub\_key*, and *priv\_key* can also be retrieved separately by the corresponding functions **DH\_get0\_p**(), **DH\_get0\_q**(), **DH\_get0\_g**(), **DH\_get0\_pub\_key**(), and **DH\_get0\_priv\_key**(), respectively. The pointers are owned by the *DH* object.

**DH\_clear\_flags**() clears the specified *flags* in *dh*. **DH\_test\_flags**() tests the *flags* in *dh*. **DH\_set\_flags**() sets the *flags* in *dh*; any flags already set remain set. For all three functions, multiple flags can be passed in one call, OR'ed together bitwise.

**DH\_set\_length**() sets the optional length attribute of *dh*, indicating the length of the secret exponent (private key) in bits. If the length attribute is non-zero, it is used, otherwise it is ignored.

## RETURN VALUES

\+.Fn DH\_get0\_p , +.Fn DH\_get0\_q , +.Fn DH\_get0\_g , +.Fn DH\_get0\_pub\_key , +and +.Fn DH\_get0\_priv\_key , +return a pointer owned by the +.Vt DH +object if the corresponding value has been set, +otherwise they return +.Dv NULL . **DH\_set0\_pqg**(), **DH\_set0\_key**(), and **DH\_set\_length**() return 1 on success or 0 on failure.

**DH\_test\_flags**() return those of the given *flags* currently set in *dh* or 0 if none of the given *flags* are set.

**DH\_get0\_engine**() always returns NULL.

## SEE ALSO

DH\_generate\_key(3), DH\_generate\_parameters(3), DH\_new(3), DH\_security\_bits(3), DH\_size(3), DHparams\_print(3)

## HISTORY

**DH\_get0\_pqg**(), **DH\_set0\_pqg**(), **DH\_get0\_key**(), **DH\_set0\_key**(), **DH\_clear\_flags**(), **DH\_test\_flags**(), **DH\_set\_flags**(), **DH\_get0\_engine**(), and **DH\_set\_length**() first appeared in OpenSSL 1.1.0 and have been available since OpenBSD 6.3.

**DH\_get0\_p**(), **DH\_get0\_q**(), **DH\_get0\_g**(), **DH\_get0\_pub\_key**(), and **DH\_get0\_priv\_key**() first appeared in OpenSSL 1.1.1 and have been available since OpenBSD 7.1.
