---
name: "libressl-DH_new"
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_new"
---

# libressl-DH\_new(3)

allocate and free DH objects

## NAME

**DH\_new**, **DH\_up\_ref**, **DH\_free** – allocate and free DH objects

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

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

*DH\**\

**DH\_new**(*void*);

*int*\

**DH\_up\_ref**(*DH \*dh*);

*void*\

**DH\_free**(*DH \*dh*);

## DESCRIPTION

The DH functions implement the Diffie-Hellman key agreement protocol.

**DH\_new**() allocates and initializes a *DH* structure, setting the reference count to 1. It is equivalent to DH\_new\_method(3) with a NULL argument.

**DH\_up\_ref**() increments the reference count by 1.

**DH\_free**() decrements the reference count by 1. If it reaches 0, it frees the *DH* structure and its components. The values are erased before the memory is returned to the system. If *dh* is a NULL pointer, no action occurs.

## RETURN VALUES

If the allocation fails, **DH\_new**() returns NULL and sets an error code that can be obtained by ERR\_get\_error(3). Otherwise it returns a pointer to the newly allocated structure.

**DH\_up\_ref**() returns 1 for success or 0 for failure.

## SEE ALSO

BN\_new(3), [crypto(3)](/crypto/3.md), 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)

## HISTORY

**DH\_new**() and **DH\_free**() first appeared in SSLeay 0.5.1 and have been available since OpenBSD 2.4.

**DH\_up\_ref**() first appeared in OpenSSL 0.9.7 and has been available since OpenBSD 3.2.
