DH_GENERATE_PARAMETERS(3)
π DH_GENERATE_PARAMETERS(3) π
okay so bestie, this one's from the Library Functions Manual and it's literally all about generating and checking Diffie-Hellman parameters β¨ (yes the crypto kind, not the "parameters of my life" kind π)
β¨ SYNOPSIS β¨
#include <openssl/dh.h>
int
DH_generate_parameters_ex(DH *dh, int prime_len, int generator,
BN_GENCB *cb);
int
DH_check(DH *dh, int *codes);
int
DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *codes);
Deprecated: π«
DH *
DH_generate_parameters(int prime_len, int generator,
void (*callback)(int, int, void *), void *cb_arg);
πΈ DESCRIPTION πΈ
So DH_generate_parameters_ex() is the main character here β it generates Diffie-Hellman parameters that can be shared among a whole group of users, and it stashes them in the DH structure you hand it. very "community property" of it π
prime_len is the length in bits of the safe prime it's gonna generate. and generator is a small number > 1, typically 2 or 5 β no cap.
A callback function can be used to give you feedback on how the key generation is going (because bestie, it's gonna take a while β see CAVEATS π). If cb is not NULL, it gets called as described in BN_generate_prime(3) while a random prime number is generated, and when a prime has been found, BN_GENCB_call(cb, 3, 0) is called; see BN_GENCB_call(3). iconic little progress bar energy π
Then there's DH_check() β it validates your Diffie-Hellman parameters. If no problems are found, *codes is set to zero. Otherwise, one or more of these bits get set:
DH_CHECK_P_NOT_PRIMEβ the parameterdh->pis not prime. rude.DH_CHECK_P_NOT_SAFE_PRIMEβ the parameterdh->pis not a safe prime. πDH_UNABLE_TO_CHECK_GENERATORβ the generatordh->gcan't even be checked for suitability: it's neither2nor5.DH_NOT_SUITABLE_GENERATORβ the generatordh->gis just... not suitable. it's giving wrong vibe π
And DH_check_pub_key() checks whether pub_key is a valid public key when you're using the domain parameters contained in dh. If no problems are found, *codes is set to zero. Otherwise, one or more of these bits are set:
DH_CHECK_PUBKEY_TOO_SMALLβpub_keyis less than or equal to1. tiny.DH_CHECK_PUBKEY_TOO_LARGEβpub_keyis greater than or equal todh->p - 1. too much going on.DH_CHECK_PUBKEY_INVALIDβdh->qis set butpub_keyto the power ofdh->qis not1modulodh->p. π§ math said no.
π₯ RETURN VALUES π₯
DH_generate_parameters_ex(), DH_check(), and DH_check_pub_key() return 1 if the check could be performed, or 0 otherwise. slay or flop, no in between π«Ά
DH_generate_parameters() (the deprecated one, boo π) returns a pointer to the DH structure, or NULL if the parameter generation fails.
The error codes can be obtained by ERR_get_error(3) β go look them up if you need the lore.
π¦ SEE ALSO π¦
π HISTORY π
DH_check()andDH_generate_parameters()first appeared in SSLeay 0.5.1 and have been available since OpenBSD 2.4. ancient. elders. π- The
cb_argargument toDH_generate_parameters()was added in SSLeay 0.9.0. DH_check_pub_key()first appeared in OpenSSL 0.9.8a and has been available since OpenBSD 4.0.DH_generate_parameters_ex()first appeared in OpenSSL 0.9.8 and has been available since OpenBSD 4.5.
π CAVEATS π
DH_generate_parameters_ex()andDH_generate_parameters()may run for several hours before finding a suitable prime. πππ like genuinely go touch grass, go get a snack, it'll be there when you get back.
Also!! The parameters generated byDH_generate_parameters_ex()andDH_generate_parameters()are not to be used in signature schemes. do not do it. i'm serious. π
π BUGS π
If generator is not 2 or 5, dh->g=generator is not a usable generator. that's just how it is bestie, no notes π
mwah π written with love from the Debian crew β page dated July 13, 2022, and this is DH_GENERATE_PARAMETERS(3) signing off. ily, go generate some primes responsibly πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: libressl-devel-doc 4.1.0-bp160.1.1 Β· OpenSSL
- Copyright (c) 2022 Ingo Schwarze <schwarze@openbsd.org>
- Copyright (c) 2000, 2016 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