1.\" $OpenBSD: DH_generate_parameters.3,v 1.13 2019/06/10 14:58:48 schwarze Exp $ 2.\" OpenSSL 05ea606a May 20 20:52:46 2016 -0400 3.\" 4.\" This file was written by Ulf Moeller <ulf@openssl.org>. 5.\" Copyright (c) 2000, 2016 The OpenSSL Project. All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 11.\" 1. Redistributions of source code must retain the above copyright 12.\" notice, this list of conditions and the following disclaimer. 13.\" 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in 16.\" the documentation and/or other materials provided with the 17.\" distribution. 18.\" 19.\" 3. All advertising materials mentioning features or use of this 20.\" software must display the following acknowledgment: 21.\" "This product includes software developed by the OpenSSL Project 22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 23.\" 24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 25.\" endorse or promote products derived from this software without 26.\" prior written permission. For written permission, please contact 27.\" openssl-core@openssl.org. 28.\" 29.\" 5. Products derived from this software may not be called "OpenSSL" 30.\" nor may "OpenSSL" appear in their names without prior written 31.\" permission of the OpenSSL Project. 32.\" 33.\" 6. Redistributions of any form whatsoever must retain the following 34.\" acknowledgment: 35.\" "This product includes software developed by the OpenSSL Project 36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)" 37.\" 38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 49.\" OF THE POSSIBILITY OF SUCH DAMAGE. 50.\" 51.Dd $Mdocdate: June 10 2019 $ 52.Dt DH_GENERATE_PARAMETERS 3 53.Os 54.Sh NAME 55.Nm DH_generate_parameters_ex , 56.Nm DH_check , 57.Nm DH_generate_parameters 58.Nd generate and check Diffie-Hellman parameters 59.Sh SYNOPSIS 60.In openssl/dh.h 61.Ft int 62.Fo DH_generate_parameters_ex 63.Fa "DH *dh" 64.Fa "int prime_len" 65.Fa "int generator" 66.Fa "BN_GENCB *cb" 67.Fc 68.Ft int 69.Fo DH_check 70.Fa "DH *dh" 71.Fa "int *codes" 72.Fc 73.Pp 74Deprecated: 75.Pp 76.Ft DH * 77.Fo DH_generate_parameters 78.Fa "int prime_len" 79.Fa "int generator" 80.Fa "void (*callback)(int, int, void *)" 81.Fa "void *cb_arg" 82.Fc 83.Sh DESCRIPTION 84.Fn DH_generate_parameters_ex 85generates Diffie-Hellman parameters that can be shared among a group of 86users, and stores them in the provided 87.Vt DH 88structure. 89.Pp 90.Fa prime_len 91is the length in bits of the safe prime to be generated. 92.Fa generator 93is a small number > 1, typically 2 or 5. 94.Pp 95A callback function may be used to provide feedback about the progress 96of the key generation. 97If 98.Fa cb 99is not 100.Dv NULL , 101it will be called as described in 102.Xr BN_generate_prime 3 103while a random prime number is generated, and when a prime has been 104found, 105.Fn BN_GENCB_call cb 3 0 106is called; see 107.Xr BN_GENCB_call 3 . 108.Pp 109.Fn DH_check 110validates Diffie-Hellman parameters. 111If no problems are found, 112.Pf * Ar codes 113is set to zero. 114Otherwise, one or more of the following bits are set: 115.Bl -tag -width Ds 116.It Dv DH_CHECK_P_NOT_PRIME 117The parameter 118.Fa dh->p 119is not prime. 120.It Dv DH_CHECK_P_NOT_SAFE_PRIME 121The parameter 122.Fa dh->p 123is not a safe prime. 124.It Dv DH_UNABLE_TO_CHECK_GENERATOR 125The generator 126.Fa dh->g 127cannot be checked for suitability: it is neither 2 nor 5. 128.It Dv DH_NOT_SUITABLE_GENERATOR 129The generator 130.Fa dh->g 131is not suitable. 132.El 133.Sh RETURN VALUES 134.Fn DH_generate_parameters_ex 135and 136.Fn DH_check 137return 1 if the check could be performed, or 0 otherwise. 138.Pp 139.Fn DH_generate_parameters 140(deprecated) returns a pointer to the 141.Vt DH 142structure, or 143.Dv NULL 144if the parameter generation fails. 145.Pp 146The error codes can be obtained by 147.Xr ERR_get_error 3 . 148.Sh SEE ALSO 149.Xr DH_get0_pqg 3 , 150.Xr DH_new 3 151.Sh HISTORY 152.Fn DH_check 153and 154.Fn DH_generate_parameters 155first appeared in SSLeay 0.5.1 and have been available since 156.Ox 2.4 . 157.Pp 158The 159.Fa cb_arg 160argument to 161.Fn DH_generate_parameters 162was added in SSLeay 0.9.0. 163.Pp 164In versions before OpenSSL 0.9.5, 165.Dv DH_CHECK_P_NOT_STRONG_PRIME 166is used instead of 167.Dv DH_CHECK_P_NOT_SAFE_PRIME . 168.Pp 169.Fn DH_generate_parameters_ex 170first appeared in OpenSSL 0.9.8 and has been available since 171.Ox 4.5 . 172.Sh CAVEATS 173.Fn DH_generate_parameters_ex 174and 175.Fn DH_generate_parameters 176may run for several hours before finding a suitable prime. 177.Pp 178The parameters generated by 179.Fn DH_generate_parameters_ex 180and 181.Fn DH_generate_parameters 182are not to be used in signature schemes. 183.Sh BUGS 184If 185.Fa generator 186is not 2 or 5, 187.Fa dh->g Ns = Ns Fa generator 188is not a usable generator. 189