1*2175Sjp161948=pod 2*2175Sjp161948 3*2175Sjp161948=head1 NAME 4*2175Sjp161948 5*2175Sjp161948DH_generate_key, DH_compute_key - perform Diffie-Hellman key exchange 6*2175Sjp161948 7*2175Sjp161948=head1 SYNOPSIS 8*2175Sjp161948 9*2175Sjp161948 #include <openssl/dh.h> 10*2175Sjp161948 11*2175Sjp161948 int DH_generate_key(DH *dh); 12*2175Sjp161948 13*2175Sjp161948 int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh); 14*2175Sjp161948 15*2175Sjp161948=head1 DESCRIPTION 16*2175Sjp161948 17*2175Sjp161948DH_generate_key() performs the first step of a Diffie-Hellman key 18*2175Sjp161948exchange by generating private and public DH values. By calling 19*2175Sjp161948DH_compute_key(), these are combined with the other party's public 20*2175Sjp161948value to compute the shared key. 21*2175Sjp161948 22*2175Sjp161948DH_generate_key() expects B<dh> to contain the shared parameters 23*2175Sjp161948B<dh-E<gt>p> and B<dh-E<gt>g>. It generates a random private DH value 24*2175Sjp161948unless B<dh-E<gt>priv_key> is already set, and computes the 25*2175Sjp161948corresponding public value B<dh-E<gt>pub_key>, which can then be 26*2175Sjp161948published. 27*2175Sjp161948 28*2175Sjp161948DH_compute_key() computes the shared secret from the private DH value 29*2175Sjp161948in B<dh> and the other party's public value in B<pub_key> and stores 30*2175Sjp161948it in B<key>. B<key> must point to B<DH_size(dh)> bytes of memory. 31*2175Sjp161948 32*2175Sjp161948=head1 RETURN VALUES 33*2175Sjp161948 34*2175Sjp161948DH_generate_key() returns 1 on success, 0 otherwise. 35*2175Sjp161948 36*2175Sjp161948DH_compute_key() returns the size of the shared secret on success, -1 37*2175Sjp161948on error. 38*2175Sjp161948 39*2175Sjp161948The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>. 40*2175Sjp161948 41*2175Sjp161948=head1 SEE ALSO 42*2175Sjp161948 43*2175Sjp161948L<dh(3)|dh(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>, L<DH_size(3)|DH_size(3)> 44*2175Sjp161948 45*2175Sjp161948=head1 HISTORY 46*2175Sjp161948 47*2175Sjp161948DH_generate_key() and DH_compute_key() are available in all versions 48*2175Sjp161948of SSLeay and OpenSSL. 49*2175Sjp161948 50*2175Sjp161948=cut 51