1.\" $OpenBSD: DH_generate_parameters.3,v 1.14 2022/07/13 13:47:59 schwarze Exp $ 2.\" full merge up to: OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100 3.\" selective merge up to: OpenSSL b0edda11 Mar 20 13:00:17 2018 +0000 4.\" 5.\" This file is a derived work. 6.\" The changes are covered by the following Copyright and license: 7.\" 8.\" Copyright (c) 2022 Ingo Schwarze <schwarze@openbsd.org> 9.\" 10.\" Permission to use, copy, modify, and distribute this software for any 11.\" purpose with or without fee is hereby granted, provided that the above 12.\" copyright notice and this permission notice appear in all copies. 13.\" 14.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 15.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 16.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 17.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 18.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 19.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 20.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 21.\" 22.\" The original file was written by Ulf Moeller <ulf@openssl.org> 23.\" and Matt Caswell <matt@openssl.org>. 24.\" Copyright (c) 2000, 2016 The OpenSSL Project. All rights reserved. 25.\" 26.\" Redistribution and use in source and binary forms, with or without 27.\" modification, are permitted provided that the following conditions 28.\" are met: 29.\" 30.\" 1. Redistributions of source code must retain the above copyright 31.\" notice, this list of conditions and the following disclaimer. 32.\" 33.\" 2. Redistributions in binary form must reproduce the above copyright 34.\" notice, this list of conditions and the following disclaimer in 35.\" the documentation and/or other materials provided with the 36.\" distribution. 37.\" 38.\" 3. All advertising materials mentioning features or use of this 39.\" software must display the following acknowledgment: 40.\" "This product includes software developed by the OpenSSL Project 41.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 42.\" 43.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 44.\" endorse or promote products derived from this software without 45.\" prior written permission. For written permission, please contact 46.\" openssl-core@openssl.org. 47.\" 48.\" 5. Products derived from this software may not be called "OpenSSL" 49.\" nor may "OpenSSL" appear in their names without prior written 50.\" permission of the OpenSSL Project. 51.\" 52.\" 6. Redistributions of any form whatsoever must retain the following 53.\" acknowledgment: 54.\" "This product includes software developed by the OpenSSL Project 55.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)" 56.\" 57.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 58.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 59.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 60.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 61.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 62.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 63.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 64.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 65.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 66.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 67.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 68.\" OF THE POSSIBILITY OF SUCH DAMAGE. 69.\" 70.Dd $Mdocdate: July 13 2022 $ 71.Dt DH_GENERATE_PARAMETERS 3 72.Os 73.Sh NAME 74.Nm DH_generate_parameters_ex , 75.Nm DH_check , 76.Nm DH_check_pub_key , 77.Nm DH_generate_parameters 78.Nd generate and check Diffie-Hellman parameters 79.Sh SYNOPSIS 80.In openssl/dh.h 81.Ft int 82.Fo DH_generate_parameters_ex 83.Fa "DH *dh" 84.Fa "int prime_len" 85.Fa "int generator" 86.Fa "BN_GENCB *cb" 87.Fc 88.Ft int 89.Fo DH_check 90.Fa "DH *dh" 91.Fa "int *codes" 92.Fc 93.Ft int 94.Fo DH_check_pub_key 95.Fa "const DH *dh" 96.Fa "const BIGNUM *pub_key" 97.Fa "int *codes" 98.Fc 99.Pp 100Deprecated: 101.Pp 102.Ft DH * 103.Fo DH_generate_parameters 104.Fa "int prime_len" 105.Fa "int generator" 106.Fa "void (*callback)(int, int, void *)" 107.Fa "void *cb_arg" 108.Fc 109.Sh DESCRIPTION 110.Fn DH_generate_parameters_ex 111generates Diffie-Hellman parameters that can be shared among a group of 112users, and stores them in the provided 113.Vt DH 114structure. 115.Pp 116.Fa prime_len 117is the length in bits of the safe prime to be generated. 118.Fa generator 119is a small number > 1, typically 2 or 5. 120.Pp 121A callback function may be used to provide feedback about the progress 122of the key generation. 123If 124.Fa cb 125is not 126.Dv NULL , 127it will be called as described in 128.Xr BN_generate_prime 3 129while a random prime number is generated, and when a prime has been 130found, 131.Fn BN_GENCB_call cb 3 0 132is called; see 133.Xr BN_GENCB_call 3 . 134.Pp 135.Fn DH_check 136validates Diffie-Hellman parameters. 137If no problems are found, 138.Pf * Ar codes 139is set to zero. 140Otherwise, one or more of the following bits are set: 141.Bl -tag -width Ds 142.It Dv DH_CHECK_P_NOT_PRIME 143The parameter 144.Fa dh->p 145is not prime. 146.It Dv DH_CHECK_P_NOT_SAFE_PRIME 147The parameter 148.Fa dh->p 149is not a safe prime. 150.It Dv DH_UNABLE_TO_CHECK_GENERATOR 151The generator 152.Fa dh->g 153cannot be checked for suitability: it is neither 2 nor 5. 154.It Dv DH_NOT_SUITABLE_GENERATOR 155The generator 156.Fa dh->g 157is not suitable. 158.El 159.Pp 160.Fn DH_check_pub_key 161checks whether 162.Fa pub_key 163is a valid public key when using the domain parameters contained in 164.Fa dh . 165If no problems are found, 166.Pf * Ar codes 167is set to zero. 168Otherwise, one or more of the following bits are set: 169.Bl -tag -width Ds 170.It Dv DH_CHECK_PUBKEY_TOO_SMALL 171.Fa pub_key 172is less than or equal to 1. 173.It Dv DH_CHECK_PUBKEY_TOO_LARGE 174.Fa pub_key 175is greater than or equal to 176.Fa dh->p No \- 1 . 177.It DH_CHECK_PUBKEY_INVALID 178.Fa dh->q 179is set but 180.Fa pub_key 181to the power of 182.Fa dh->q 183is not 1 modulo 184.Fa dh->p . 185.El 186.Sh RETURN VALUES 187.Fn DH_generate_parameters_ex , 188.Fn DH_check , 189and 190.Fn DH_check_pub_key 191return 1 if the check could be performed or 0 otherwise. 192.Pp 193.Fn DH_generate_parameters 194(deprecated) returns a pointer to the 195.Vt DH 196structure, or 197.Dv NULL 198if the parameter generation fails. 199.Pp 200The error codes can be obtained by 201.Xr ERR_get_error 3 . 202.Sh SEE ALSO 203.Xr DH_get0_pqg 3 , 204.Xr DH_new 3 205.Sh HISTORY 206.Fn DH_check 207and 208.Fn DH_generate_parameters 209first appeared in SSLeay 0.5.1 and have been available since 210.Ox 2.4 . 211.Pp 212The 213.Fa cb_arg 214argument to 215.Fn DH_generate_parameters 216was added in SSLeay 0.9.0. 217.Pp 218.Fn DH_check_pub_key 219first appeared in OpenSSL 0.9.8a and has been available since 220.Ox 4.0 . 221.Pp 222.Fn DH_generate_parameters_ex 223first appeared in OpenSSL 0.9.8 and has been available since 224.Ox 4.5 . 225.Sh CAVEATS 226.Fn DH_generate_parameters_ex 227and 228.Fn DH_generate_parameters 229may run for several hours before finding a suitable prime. 230.Pp 231The parameters generated by 232.Fn DH_generate_parameters_ex 233and 234.Fn DH_generate_parameters 235are not to be used in signature schemes. 236.Sh BUGS 237If 238.Fa generator 239is not 2 or 5, 240.Fa dh->g Ns = Ns Fa generator 241is not a usable generator. 242