DH_SET_METHOD(3)
π NAME π
Okay so this is DH_SET_METHOD(3) from the Library Functions Manual, and it's literally all about picking a DH method, bestie. The crew is DH_set_default_method, DH_get_default_method, DH_set_method, DH_new_method, DH_OpenSSL β select DH method. Periodt π
πΈ SYNOPSIS πΈ
Here's the exact shape of it, no cap:
library βlibcryptoβ #include <openssl/dh.h>
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 π¦
A DH_METHOD object is basically a little bundle of function pointers used for Diffie-Hellman operations. By default, the internal implementation returned by DH_OpenSSL() is used. But if you select another method, alternative implementations such as hardware accelerators may be used β and that's the whole point, iykyk β¨
DH_set_default_method()β selectsmethas the default method for allDHstructures created later. Set it and forget it, bestie.DH_get_default_method()β returns a pointer to the current default method. It's giving "who's the main character right now" energy.DH_set_method()β selectsmethto perform all operations using the keydh. This replaces theDH_METHODused by thedhkey. It is possible to haveDHkeys that only work with certainDH_METHODimplementations, and in such cases attempting to change theDH_METHODfor the key can have unexpected results.DH_new_method()β allocates and initializes aDHstructure. Theengineargument is ignored and the default method controlled byDH_set_default_method()is used.
β οΈ Heads up, bestie: someDHkeys only work with certainDH_METHODimplementations, and if you try to change theDH_METHODfor one of those keys, expect unexpected results. No cap, that's literally what the page says π
The DH_METHOD structure is defined as follows:
typedef struct dh_meth_st
{
/* name of the implementation */
const char *name;
/* generate private and public DH values for key agreement */
int (*generate_key)(DH *dh);
/* compute shared secret */
int (*compute_key)(unsigned char *key, BIGNUM *pub_key, DH *dh);
/* compute r = a ^ p mod m (May be NULL for some implementations) */
int (*bn_mod_exp)(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
const BIGNUM *m, BN_CTX *ctx,
BN_MONT_CTX *m_ctx);
/* called at DH_new */
int (*init)(DH *dh);
/* called at DH_free */
int (*finish)(DH *dh);
int flags;
char *app_data; /* ?? */
} DH_METHOD;
π RETURN VALUES π
DH_OpenSSL()andDH_get_default_method()β return pointers to the respectiveDH_METHOD. Iconic behavior, fr fr.DH_set_method()β returns1on success or0on failure. Currently, it cannot fail. Slay.DH_new_method()β returnsNULLand sets an error code that can be obtained byERR_get_error(3)if the allocation fails. Otherwise it returns a pointer to the newly allocated structure. Lowkey important, ngl.
π SEE ALSO π
DH_new(3)β go read it, bestie π«Ά
β HISTORY β
DH_set_default_method(), DH_get_default_method(), DH_set_method(), DH_new_method() and DH_OpenSSL() first appeared in OpenSSL 0.9.5 and have been available since OpenBSD 2.7. Vintage but still iconic π
Signed, sealed, delivered by Debian on June 8, 2025 β page tag DH_SET_METHOD(3) π
β¨
π¦ where this page comes from
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2000, 2002, 2007 The OpenSSL Project. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms