DH\_SET\_METHOD(3ossl) OpenSSL DH\_SET\_METHOD(3ossl)

# [NAME](#NAME)

DH\_set\_default\_method, DH\_get\_default\_method, DH\_set\_method, DH\_new\_method, DH\_OpenSSL - select DH method

# [SYNOPSIS](#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)](/man/os/openssl-4.0/openssl_user_macros.7):

```
 void DH_set_default_method(const DH_METHOD *meth);
 const DH_METHOD *DH_get_default_method(void);
 int DH_set_method(DH *dh, const DH_METHOD *meth);
 DH *DH_new_method(ENGINE *engine);
 const DH_METHOD *DH_OpenSSL(void);
```

# [DESCRIPTION](#DESCRIPTION)

All of the functions described on this page are deprecated. Applications should instead use the provider APIs.

A **DH\_METHOD** specifies the functions that OpenSSL uses for Diffie-Hellman operations. By modifying the method, alternative implementations such as hardware accelerators may be used.

Initially, the default DH\_METHOD is the OpenSSL internal implementation, as returned by **DH\_OpenSSL()**.

**DH\_set\_default\_method()** makes **meth** the default method for all DH structures created later. **NB**: This function is not thread-safe and should not be called at the same time as other OpenSSL functions.

**DH\_get\_default\_method()** returns a pointer to the current default DH\_METHOD.

**DH\_set\_method()** selects **meth** to perform all operations using the key **dh**. This will replace the DH\_METHOD used by the DH key. It is possible to have DH keys that only work with certain DH\_METHOD implementations, and in such cases attempting to change the DH\_METHOD for the key can have unexpected results. See [**DH\_meth\_new**(3)](/man/os/openssl-4.0/DH_meth_new.3) for information on constructing custom DH\_METHOD objects.

**DH\_new\_method()** allocates and initializes a DH structure. **engine** must be NULL and the DH\_METHOD controlled by **DH\_set\_default\_method()** is used.

A new DH\_METHOD object may be constructed using **DH\_meth\_new()** (see [**DH\_meth\_new**(3)](/man/os/openssl-4.0/DH_meth_new.3)).

# [RETURN VALUES](#RETURN_VALUES)

**DH\_OpenSSL()** and **DH\_get\_default\_method()** return pointers to the respective **DH\_METHOD**s.

**DH\_set\_default\_method()** returns no value.

**DH\_set\_method()** returns nonzero if the provided **meth** was successfully set as the method for **dh**.

**DH\_new\_method()** returns NULL and sets an error code that can be obtained by [**ERR\_get\_error**(3)](/man/os/openssl-4.0/ERR_get_error.3) if the allocation fails. Otherwise it returns a pointer to the newly allocated structure.

# [SEE ALSO](#SEE_ALSO)

[**DH\_new**(3)](/man/os/openssl-4.0/DH_new.3), [**DH\_new**(3)](/man/os/openssl-4.0/DH_new.3), [**DH\_meth\_new**(3)](/man/os/openssl-4.0/DH_meth_new.3)

# [HISTORY](#HISTORY)

All of these functions were deprecated in OpenSSL 3.0.

# [COPYRIGHT](#COPYRIGHT)

Copyright 2000-2025 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 &lt;https://www.openssl.org/source/license.html&gt;.

2026-09-29 4.0.3

---

Document: DH_OpenSSL(3ossl) from openssl-4.0 4.0.3-r5 (Chainguard OS)
