diff options
Diffstat (limited to 'src/lib/libcrypto/man/BN_generate_prime.3')
| -rw-r--r-- | src/lib/libcrypto/man/BN_generate_prime.3 | 375 |
1 files changed, 0 insertions, 375 deletions
diff --git a/src/lib/libcrypto/man/BN_generate_prime.3 b/src/lib/libcrypto/man/BN_generate_prime.3 deleted file mode 100644 index d9144155c6..0000000000 --- a/src/lib/libcrypto/man/BN_generate_prime.3 +++ /dev/null | |||
| @@ -1,375 +0,0 @@ | |||
| 1 | .\" $OpenBSD: BN_generate_prime.3,v 1.25 2023/12/29 19:12:46 tb Exp $ | ||
| 2 | .\" full merge up to: OpenSSL f987a4dd Jun 27 10:12:08 2019 +0200 | ||
| 3 | .\" | ||
| 4 | .\" This file is a derived work. | ||
| 5 | .\" The changes are covered by the following Copyright and license: | ||
| 6 | .\" | ||
| 7 | .\" Copyright (c) 2022 Ingo Schwarze <schwarze@openbsd.org> | ||
| 8 | .\" | ||
| 9 | .\" Permission to use, copy, modify, and distribute this software for any | ||
| 10 | .\" purpose with or without fee is hereby granted, provided that the above | ||
| 11 | .\" copyright notice and this permission notice appear in all copies. | ||
| 12 | .\" | ||
| 13 | .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 14 | .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 15 | .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 16 | .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 17 | .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 18 | .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 19 | .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 20 | .\" | ||
| 21 | .\" The original file was written by Ulf Moeller <ulf@openssl.org> | ||
| 22 | .\" Bodo Moeller <bodo@openssl.org>, and Matt Caswell <matt@openssl.org>. | ||
| 23 | .\" Copyright (c) 2000, 2003, 2013, 2014, 2018 The OpenSSL Project. | ||
| 24 | .\" 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: December 29 2023 $ | ||
| 71 | .Dt BN_GENERATE_PRIME 3 | ||
| 72 | .Os | ||
| 73 | .Sh NAME | ||
| 74 | .Nm BN_is_prime_ex , | ||
| 75 | .Nm BN_is_prime_fasttest_ex , | ||
| 76 | .Nm BN_generate_prime_ex , | ||
| 77 | .Nm BN_GENCB_call , | ||
| 78 | .Nm BN_GENCB_new , | ||
| 79 | .Nm BN_GENCB_free , | ||
| 80 | .Nm BN_GENCB_set , | ||
| 81 | .Nm BN_GENCB_get_arg , | ||
| 82 | .Nm BN_GENCB_set_old | ||
| 83 | .\" Nm BN_prime_checks_for_size is intentionally undocumented | ||
| 84 | .\" because it should not be used outside of libcrypto. | ||
| 85 | .Nd generate primes and test for primality | ||
| 86 | .Sh SYNOPSIS | ||
| 87 | .In openssl/bn.h | ||
| 88 | .Ft int | ||
| 89 | .Fo BN_is_prime_ex | ||
| 90 | .Fa "const BIGNUM *a" | ||
| 91 | .Fa "int nchecks" | ||
| 92 | .Fa "BN_CTX *ctx" | ||
| 93 | .Fa "BN_GENCB *cb" | ||
| 94 | .Fc | ||
| 95 | .Ft int | ||
| 96 | .Fo BN_is_prime_fasttest_ex | ||
| 97 | .Fa "const BIGNUM *a" | ||
| 98 | .Fa "int nchecks" | ||
| 99 | .Fa "BN_CTX *ctx" | ||
| 100 | .Fa "int do_trial_division" | ||
| 101 | .Fa "BN_GENCB *cb" | ||
| 102 | .Fc | ||
| 103 | .Ft int | ||
| 104 | .Fo BN_generate_prime_ex | ||
| 105 | .Fa "BIGNUM *ret" | ||
| 106 | .Fa "int bits" | ||
| 107 | .Fa "int safe" | ||
| 108 | .Fa "const BIGNUM *modulus" | ||
| 109 | .Fa "const BIGNUM *remainder" | ||
| 110 | .Fa "BN_GENCB *cb" | ||
| 111 | .Fc | ||
| 112 | .Ft int | ||
| 113 | .Fo BN_GENCB_call | ||
| 114 | .Fa "BN_GENCB *cb" | ||
| 115 | .Fa "int state_code" | ||
| 116 | .Fa "int serial_number" | ||
| 117 | .Fc | ||
| 118 | .Ft BN_GENCB * | ||
| 119 | .Fn BN_GENCB_new void | ||
| 120 | .Ft void | ||
| 121 | .Fo BN_GENCB_free | ||
| 122 | .Fa "BN_GENCB *cb" | ||
| 123 | .Fc | ||
| 124 | .Ft void | ||
| 125 | .Fo BN_GENCB_set | ||
| 126 | .Fa "BN_GENCB *cb" | ||
| 127 | .Fa "int (*cb_fp)(int, int, BN_GENCB *)" | ||
| 128 | .Fa "void *cb_arg" | ||
| 129 | .Fc | ||
| 130 | .Ft void * | ||
| 131 | .Fo BN_GENCB_get_arg | ||
| 132 | .Fa "BN_GENCB *cb" | ||
| 133 | .Fc | ||
| 134 | .Pp | ||
| 135 | Deprecated: | ||
| 136 | .Pp | ||
| 137 | .Ft void | ||
| 138 | .Fo BN_GENCB_set_old | ||
| 139 | .Fa "BN_GENCB *cb" | ||
| 140 | .Fa "void (*cb_fp)(int, int, void *)" | ||
| 141 | .Fa "void *cb_arg" | ||
| 142 | .Fc | ||
| 143 | .Sh DESCRIPTION | ||
| 144 | .Fn BN_is_prime_ex | ||
| 145 | and | ||
| 146 | .Fn BN_is_prime_fasttest_ex | ||
| 147 | test whether the number | ||
| 148 | .Fa a | ||
| 149 | is prime. | ||
| 150 | In LibreSSL, both functions behave identically | ||
| 151 | and use the Baillie-Pomerance-Selfridge-Wagstaff algorithm | ||
| 152 | combined with | ||
| 153 | .Fa checks | ||
| 154 | Miller-Rabin rounds. | ||
| 155 | The | ||
| 156 | .Fa do_trial_division | ||
| 157 | argument is ignored. | ||
| 158 | .Pp | ||
| 159 | It is unknown whether any composite number exists that the | ||
| 160 | Baillie-PSW algorithm misclassifies as a prime. | ||
| 161 | Some suspect that there may be infinitely many such numbers, | ||
| 162 | but not a single one is currently known. | ||
| 163 | It is known that no such number exists below 2\(ha64. | ||
| 164 | .Pp | ||
| 165 | In order to reduce the likelihood of a composite number | ||
| 166 | passing the primality tests | ||
| 167 | .Fn BN_is_prime_fasttest_ex | ||
| 168 | and | ||
| 169 | .Fn BN_is_prime_ex , | ||
| 170 | a number of rounds of the probabilistic Miller-Rabin test is performed. | ||
| 171 | If | ||
| 172 | .Fa checks | ||
| 173 | is positive, it is used as the number of rounds; | ||
| 174 | if it is zero or the special value | ||
| 175 | .Dv BN_prime_checks , | ||
| 176 | a suitable number of rounds is calculated from the bit length of | ||
| 177 | .Fa a . | ||
| 178 | .Pp | ||
| 179 | If | ||
| 180 | .Dv NULL | ||
| 181 | is passed for the | ||
| 182 | .Fa ctx | ||
| 183 | argument, these function allocate a | ||
| 184 | .Vt BN_CTX | ||
| 185 | object internally when they need one and free it before returning. | ||
| 186 | Alternatively, to save the overhead of allocating and freeing | ||
| 187 | that object for each call, the caller can pre-allocate a | ||
| 188 | .Vt BN_CTX | ||
| 189 | object and pass it in the | ||
| 190 | .Fa ctx | ||
| 191 | argument. | ||
| 192 | .Pp | ||
| 193 | .Fn BN_generate_prime_ex | ||
| 194 | generates a pseudo-random prime number of at least bit length | ||
| 195 | .Fa bits | ||
| 196 | and places it in | ||
| 197 | .Fa ret . | ||
| 198 | Primality of | ||
| 199 | .Fa ret | ||
| 200 | is tested internally using | ||
| 201 | .Fn BN_is_prime_ex . | ||
| 202 | Consequently, for | ||
| 203 | .Fa bits | ||
| 204 | larger than 64, it is theoretically possible | ||
| 205 | that this function might place a composite number into | ||
| 206 | .Fa ret ; | ||
| 207 | the probability of such an event is unknown but very small. | ||
| 208 | .Pp | ||
| 209 | The prime may have to fulfill additional requirements for use in | ||
| 210 | Diffie-Hellman key exchange: | ||
| 211 | .Bl -bullet | ||
| 212 | .It | ||
| 213 | If | ||
| 214 | .Fa modulus | ||
| 215 | is not | ||
| 216 | .Dv NULL , | ||
| 217 | a prime is generated that fulfills the condition | ||
| 218 | .Fa ret No % Fa modulus No = Fa remainder . | ||
| 219 | If the | ||
| 220 | .Fa remainder | ||
| 221 | argument is | ||
| 222 | .Dv NULL , | ||
| 223 | 1 is used as the desired remainder. | ||
| 224 | .It | ||
| 225 | If the | ||
| 226 | .Fa safe | ||
| 227 | argument is non-zero, a safe prime is generated, that is, | ||
| 228 | .Po Fa ret No \- 1 Pc Ns /2 | ||
| 229 | is also prime. | ||
| 230 | .El | ||
| 231 | .Pp | ||
| 232 | If | ||
| 233 | .Fa cb | ||
| 234 | is not | ||
| 235 | .Dv NULL , | ||
| 236 | it is used as follows: | ||
| 237 | .Bl -bullet | ||
| 238 | .It | ||
| 239 | .Fn BN_GENCB_call cb 0 serial_number | ||
| 240 | is called after generating a potential prime number. | ||
| 241 | .It | ||
| 242 | The | ||
| 243 | .Fa state_code | ||
| 244 | of 1 is reserved for callbacks during primality testing, | ||
| 245 | but LibreSSL performs no such callbacks. | ||
| 246 | .It | ||
| 247 | When | ||
| 248 | .Fa safe | ||
| 249 | is non-zero and a safe prime has been found, | ||
| 250 | .Fn BN_GENCB_call cb 2 serial_number | ||
| 251 | is called. | ||
| 252 | .It | ||
| 253 | The callers of | ||
| 254 | .Fn BN_generate_prime_ex | ||
| 255 | may call | ||
| 256 | .Fn BN_GENCB_call | ||
| 257 | with other values as described in their respective manual pages; see | ||
| 258 | .Sx SEE ALSO . | ||
| 259 | .El | ||
| 260 | .Pp | ||
| 261 | In all cases, the | ||
| 262 | .Fa serial_number | ||
| 263 | is the number of candidates that have already been discarded | ||
| 264 | for not being prime; that is, | ||
| 265 | .Fa serial_number | ||
| 266 | is 0 for the first candidate | ||
| 267 | and then incremented whenever a new candidate is generated. | ||
| 268 | .Pp | ||
| 269 | .Fn BN_GENCB_call | ||
| 270 | calls the callback function held in | ||
| 271 | .Fa cb | ||
| 272 | and passes the | ||
| 273 | .Fa state_code | ||
| 274 | and the | ||
| 275 | .Fa serial_number | ||
| 276 | as arguments. | ||
| 277 | If | ||
| 278 | .Fa cb | ||
| 279 | is | ||
| 280 | .Dv NULL | ||
| 281 | or does not contain a callback function, no action occurs. | ||
| 282 | .Pp | ||
| 283 | .Fn BN_GENCB_new | ||
| 284 | allocates a new | ||
| 285 | .Vt BN_GENCB | ||
| 286 | object. | ||
| 287 | .Pp | ||
| 288 | .Fn BN_GENCB_free | ||
| 289 | frees | ||
| 290 | .Fa cb . | ||
| 291 | If | ||
| 292 | .Fa cb | ||
| 293 | is | ||
| 294 | .Dv NULL , | ||
| 295 | no action occurs. | ||
| 296 | .Pp | ||
| 297 | .Fn BN_GENCB_set | ||
| 298 | initialises | ||
| 299 | .Fa cb | ||
| 300 | to use the callback function pointer | ||
| 301 | .Fa cb_fp | ||
| 302 | and the additional callback argument | ||
| 303 | .Fa cb_arg . | ||
| 304 | .Pp | ||
| 305 | The deprecated function | ||
| 306 | .Fn BN_GENCB_set_old | ||
| 307 | initialises | ||
| 308 | .Fa cb | ||
| 309 | to use the old-style callback function pointer | ||
| 310 | .Fa cb_fp | ||
| 311 | and the additional callback argument | ||
| 312 | .Fa cb_arg . | ||
| 313 | .Sh RETURN VALUES | ||
| 314 | .Fn BN_is_prime_ex | ||
| 315 | and | ||
| 316 | .Fn BN_is_prime_fasttest_ex | ||
| 317 | return 0 if the number is composite, 1 if it is prime with a very small | ||
| 318 | error probability, or \-1 on error. | ||
| 319 | .Pp | ||
| 320 | .Fn BN_generate_prime_ex | ||
| 321 | returns 1 on success or 0 on error. | ||
| 322 | .Pp | ||
| 323 | .Fn BN_GENCB_call | ||
| 324 | returns 1 on success, including when | ||
| 325 | .Fa cb | ||
| 326 | is | ||
| 327 | .Dv NULL | ||
| 328 | or does not contain a callback function, | ||
| 329 | or 0 on error. | ||
| 330 | .Pp | ||
| 331 | .Fn BN_GENCB_new | ||
| 332 | returns a pointer to the newly allocated | ||
| 333 | .Vt BN_GENCB | ||
| 334 | object or | ||
| 335 | .Dv NULL | ||
| 336 | if memory allocation fails. | ||
| 337 | .Pp | ||
| 338 | The callback functions pointed to by the | ||
| 339 | .Fa cb_fp | ||
| 340 | arguments are supposed to return 1 on success or 0 on error. | ||
| 341 | .Pp | ||
| 342 | .Fn BN_GENCB_get_arg | ||
| 343 | returns the | ||
| 344 | .Fa cb_arg | ||
| 345 | pointer that was previously stored in | ||
| 346 | .Fa cb | ||
| 347 | using | ||
| 348 | .Fn BN_GENCB_set | ||
| 349 | or | ||
| 350 | .Fn BN_GENCB_set_old . | ||
| 351 | .Pp | ||
| 352 | In some cases, error codes can be obtained by | ||
| 353 | .Xr ERR_get_error 3 . | ||
| 354 | .Sh SEE ALSO | ||
| 355 | .Xr BN_new 3 , | ||
| 356 | .Xr DH_generate_parameters 3 , | ||
| 357 | .Xr DSA_generate_parameters_ex 3 , | ||
| 358 | .Xr RSA_generate_key 3 | ||
| 359 | .Sh HISTORY | ||
| 360 | .Fn BN_generate_prime_ex , | ||
| 361 | .Fn BN_is_prime_ex , | ||
| 362 | .Fn BN_is_prime_fasttest_ex , | ||
| 363 | .Fn BN_GENCB_call , | ||
| 364 | .Fn BN_GENCB_set_old , | ||
| 365 | and | ||
| 366 | .Fn BN_GENCB_set | ||
| 367 | first appeared in OpenSSL 0.9.8 and have been available since | ||
| 368 | .Ox 4.5 . | ||
| 369 | .Pp | ||
| 370 | .Fn BN_GENCB_new , | ||
| 371 | .Fn BN_GENCB_free , | ||
| 372 | and | ||
| 373 | .Fn BN_GENCB_get_arg | ||
| 374 | first appeared in OpenSSL 1.1.0 and have been available since | ||
| 375 | .Ox 6.3 . | ||
