DH_SET_METHOD(3SSL)

πŸ’– DH_SET_METHOD β€” okay bestie, let's talk about picking your DH method πŸ’–

So this is the OpenSSL manual page DH_set_default_method(3ssl) and it's giving "legacy but make it cute" energy. Buckle up, we're doing cryptography selection drama ✨


🌸 NAME 🌸

DH_set_default_method, DH_get_default_method, DH_set_method, DH_new_method, DH_OpenSSL β€” select DH method πŸ’…


✨ SYNOPSIS ✨

First things first, you gotta include the header:

#include <openssl/dh.h>

Okay so important tea β˜• β€” the following functions have been deprecated since OpenSSL 3.0, and you can hide them entirely by defining OPENSSL_API_COMPAT with a suitable version value. Check openssl_user_macros(7) for the deets πŸ’€

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 πŸ¦‹

Okay so, real talk: all of the functions described on this page are deprecated. Applications should instead use the provider APIs. Not a vibe, but that's the law 🫢

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. Fancy, right? πŸ‘‘

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. So like… don't do that. Fr fr 😭
  • 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) 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)).


πŸŽ€ RETURN VALUES πŸŽ€

  • DH_OpenSSL() and DH_get_default_method() β€” return pointers to the respective DH_METHODs. 🫢
  • DH_set_default_method() β€” returns no value. It's giving silent, mysterious, no follow-up text energy πŸ’…
  • 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) if the allocation fails. Otherwise it returns a pointer to the newly allocated structure. So like, check for NULL, bestie, don't be naive πŸ™ˆ

🌈 SEE ALSO 🌈

(yes, DH_new(3) is listed twice, and honestly? iconic. it said "say it again for the people in the back" πŸ‘‘)


πŸ’œ HISTORY πŸ’œ

All of these functions were deprecated in OpenSSL 3.0. That's the whole history lesson, short and shady ⭐


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 <https://www.openssl.org/source/license.html>.


okay that's the whole page, you ate that πŸ’… This was version 4.0.3, dated 2026-09-29, straight from the OpenSSL crew β€” mwah, take care of your keys, hydrate, and never call DH_set_default_method() in a thread race πŸ«Άβœ¨πŸ’–

πŸ“¦ where this page comes from