NAME
SSL_CTX_set_tmp_dh_callback, SSL_CTX_set_tmp_dh, SSL_set_tmp_dh_callback, SSL_set_tmp_dh — handle DH keys for ephemeral key exchangeSYNOPSIS
#include <openssl/ssl.h>SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx, DH *(*tmp_dh_callback)(SSL *ssl, int is_export, int keylength));
SSL_CTX_set_tmp_dh(SSL_CTX *ctx, DH *dh);
SSL_set_tmp_dh_callback(SSL *ssl, DH *(*tmp_dh_callback)(SSL *ssl, int is_export, int keylength);
SSL_set_tmp_dh(SSL *ssl, DH *dh);
DESCRIPTION
SSL_CTX_set_tmp_dh_callback() sets the callback function for ctx to be used when a DH parameters are required to tmp_dh_callback. The callback is inherited by all ssl objects created from ctx.NOTES
When using a cipher with RSA authentication, an ephemeral DH key exchange can take place. Ciphers with DSA keys always use ephemeral DH keys as well. In these cases, the session data are negotiated using the ephemeral/temporary DH key and the key supplied and certified by the certificate chain is only used for signing. Anonymous ciphers (without a permanent server key) also use ephemeral DH keys.RETURN VALUES
SSL_CTX_set_tmp_dh_callback() and SSL_set_tmp_dh_callback() do not return diagnostic output.EXAMPLES
Handle DH parameters for key lengths of 512 and 1024 bits. (Error handling partly left out.)... /* Set up ephemeral DH stuff */ DH *dh_512 = NULL; DH *dh_1024 = NULL; FILE *paramfile; ... /* "openssl dhparam -out dh_param_512.pem -2 512" */ paramfile = fopen("dh_param_512.pem", "r"); if (paramfile) { dh_512 = PEM_read_DHparams(paramfile, NULL, NULL, NULL); fclose(paramfile); } /* "openssl dhparam -out dh_param_1024.pem -2 1024" */ paramfile = fopen("dh_param_1024.pem", "r"); if (paramfile) { dh_1024 = PEM_read_DHparams(paramfile, NULL, NULL, NULL); fclose(paramfile); } ... /* "openssl dhparam -C -2 512" etc... */ DH *get_dh512() { ... } DH *get_dh1024() { ... } DH * tmp_dh_callback(SSL *s, int is_export, int keylength) { DH *dh_tmp=NULL; switch (keylength) { case 512: if (!dh_512) dh_512 = get_dh512(); dh_tmp = dh_512; break; case 1024: if (!dh_1024) dh_1024 = get_dh1024(); dh_tmp = dh_1024; break; default: /* * Generating a key on the fly is very costly, * so use what is there */ setup_dh_parameters_like_above(); } return(dh_tmp); }