diff options
author | schwarze <> | 2022-11-24 19:06:38 +0000 |
---|---|---|
committer | schwarze <> | 2022-11-24 19:06:38 +0000 |
commit | 71826d76dc702ad60f7f3e5d48effe1f17dfac1a (patch) | |
tree | 3dd4a18192ef63590ed5b7f3785c2822b330f33e /src/lib | |
parent | 28e36c79110ac315df0015ad3a0e74d5be6a8e97 (diff) | |
download | openbsd-71826d76dc702ad60f7f3e5d48effe1f17dfac1a.tar.gz openbsd-71826d76dc702ad60f7f3e5d48effe1f17dfac1a.tar.bz2 openbsd-71826d76dc702ad60f7f3e5d48effe1f17dfac1a.zip |
Major overhaul.
Remove many statements that are no longer true after tb@, in July,
massively improved the algorithms used by these functions
and also did some cleanup of the interface. Instead, explain
many aspects that were missing. Also use more descriptive argument
names, drop some redundancy, and improve ordering in various respects.
Feedback and enthusiastic OK from tb@.
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libcrypto/man/BN_generate_prime.3 | 426 |
1 files changed, 216 insertions, 210 deletions
diff --git a/src/lib/libcrypto/man/BN_generate_prime.3 b/src/lib/libcrypto/man/BN_generate_prime.3 index 764ea6f873..df28d3775c 100644 --- a/src/lib/libcrypto/man/BN_generate_prime.3 +++ b/src/lib/libcrypto/man/BN_generate_prime.3 | |||
@@ -1,7 +1,24 @@ | |||
1 | .\" $OpenBSD: BN_generate_prime.3,v 1.19 2020/06/24 18:15:00 jmc Exp $ | 1 | .\" $OpenBSD: BN_generate_prime.3,v 1.20 2022/11/24 19:06:38 schwarze Exp $ |
2 | .\" full merge up to: OpenSSL f987a4dd Jun 27 10:12:08 2019 +0200 | 2 | .\" full merge up to: OpenSSL f987a4dd Jun 27 10:12:08 2019 +0200 |
3 | .\" | 3 | .\" |
4 | .\" This file was written by Ulf Moeller <ulf@openssl.org> | 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> | ||
5 | .\" Bodo Moeller <bodo@openssl.org>, and Matt Caswell <matt@openssl.org>. | 22 | .\" Bodo Moeller <bodo@openssl.org>, and Matt Caswell <matt@openssl.org>. |
6 | .\" Copyright (c) 2000, 2003, 2013, 2014, 2018 The OpenSSL Project. | 23 | .\" Copyright (c) 2000, 2003, 2013, 2014, 2018 The OpenSSL Project. |
7 | .\" All rights reserved. | 24 | .\" All rights reserved. |
@@ -50,54 +67,56 @@ | |||
50 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | 67 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
51 | .\" OF THE POSSIBILITY OF SUCH DAMAGE. | 68 | .\" OF THE POSSIBILITY OF SUCH DAMAGE. |
52 | .\" | 69 | .\" |
53 | .Dd $Mdocdate: June 24 2020 $ | 70 | .Dd $Mdocdate: November 24 2022 $ |
54 | .Dt BN_GENERATE_PRIME 3 | 71 | .Dt BN_GENERATE_PRIME 3 |
55 | .Os | 72 | .Os |
56 | .Sh NAME | 73 | .Sh NAME |
57 | .Nm BN_generate_prime_ex , | ||
58 | .Nm BN_is_prime_ex , | 74 | .Nm BN_is_prime_ex , |
59 | .Nm BN_is_prime_fasttest_ex , | 75 | .Nm BN_is_prime_fasttest_ex , |
76 | .Nm BN_generate_prime_ex , | ||
60 | .Nm BN_GENCB_call , | 77 | .Nm BN_GENCB_call , |
61 | .Nm BN_GENCB_new , | 78 | .Nm BN_GENCB_new , |
62 | .Nm BN_GENCB_free , | 79 | .Nm BN_GENCB_free , |
63 | .Nm BN_GENCB_set_old , | ||
64 | .Nm BN_GENCB_set , | 80 | .Nm BN_GENCB_set , |
65 | .Nm BN_GENCB_get_arg , | 81 | .Nm BN_GENCB_get_arg , |
82 | .Nm BN_GENCB_set_old , | ||
66 | .Nm BN_generate_prime , | 83 | .Nm BN_generate_prime , |
67 | .Nm BN_is_prime , | 84 | .Nm BN_is_prime , |
68 | .Nm BN_is_prime_fasttest | 85 | .Nm BN_is_prime_fasttest |
86 | .\" Nm BN_prime_checks_for_size is intentionally undocumented | ||
87 | .\" because it is no longer used by LibreSSL. | ||
69 | .Nd generate primes and test for primality | 88 | .Nd generate primes and test for primality |
70 | .Sh SYNOPSIS | 89 | .Sh SYNOPSIS |
71 | .In openssl/bn.h | 90 | .In openssl/bn.h |
72 | .Ft int | 91 | .Ft int |
73 | .Fo BN_generate_prime_ex | ||
74 | .Fa "BIGNUM *ret" | ||
75 | .Fa "int bits" | ||
76 | .Fa "int safe" | ||
77 | .Fa "const BIGNUM *add" | ||
78 | .Fa "const BIGNUM *rem" | ||
79 | .Fa "BN_GENCB *cb" | ||
80 | .Fc | ||
81 | .Ft int | ||
82 | .Fo BN_is_prime_ex | 92 | .Fo BN_is_prime_ex |
83 | .Fa "const BIGNUM *p" | 93 | .Fa "const BIGNUM *a" |
84 | .Fa "int nchecks" | 94 | .Fa "int nchecks" |
85 | .Fa "BN_CTX *ctx" | 95 | .Fa "BN_CTX *ctx" |
86 | .Fa "BN_GENCB *cb" | 96 | .Fa "BN_GENCB *cb" |
87 | .Fc | 97 | .Fc |
88 | .Ft int | 98 | .Ft int |
89 | .Fo BN_is_prime_fasttest_ex | 99 | .Fo BN_is_prime_fasttest_ex |
90 | .Fa "const BIGNUM *p" | 100 | .Fa "const BIGNUM *a" |
91 | .Fa "int nchecks" | 101 | .Fa "int nchecks" |
92 | .Fa "BN_CTX *ctx" | 102 | .Fa "BN_CTX *ctx" |
93 | .Fa "int do_trial_division" | 103 | .Fa "int do_trial_division" |
94 | .Fa "BN_GENCB *cb" | 104 | .Fa "BN_GENCB *cb" |
95 | .Fc | 105 | .Fc |
96 | .Ft int | 106 | .Ft int |
107 | .Fo BN_generate_prime_ex | ||
108 | .Fa "BIGNUM *ret" | ||
109 | .Fa "int bits" | ||
110 | .Fa "int safe" | ||
111 | .Fa "const BIGNUM *modulus" | ||
112 | .Fa "const BIGNUM *remainder" | ||
113 | .Fa "BN_GENCB *cb" | ||
114 | .Fc | ||
115 | .Ft int | ||
97 | .Fo BN_GENCB_call | 116 | .Fo BN_GENCB_call |
98 | .Fa "BN_GENCB *cb" | 117 | .Fa "BN_GENCB *cb" |
99 | .Fa "int a" | 118 | .Fa "int state_code" |
100 | .Fa "int b" | 119 | .Fa "int serial_number" |
101 | .Fc | 120 | .Fc |
102 | .Ft BN_GENCB * | 121 | .Ft BN_GENCB * |
103 | .Fn BN_GENCB_new void | 122 | .Fn BN_GENCB_new void |
@@ -106,15 +125,9 @@ | |||
106 | .Fa "BN_GENCB *cb" | 125 | .Fa "BN_GENCB *cb" |
107 | .Fc | 126 | .Fc |
108 | .Ft void | 127 | .Ft void |
109 | .Fo BN_GENCB_set_old | ||
110 | .Fa "BN_GENCB *gencb" | ||
111 | .Fa "void (*callback)(int, int, void *)" | ||
112 | .Fa "void *cb_arg" | ||
113 | .Fc | ||
114 | .Ft void | ||
115 | .Fo BN_GENCB_set | 128 | .Fo BN_GENCB_set |
116 | .Fa "BN_GENCB *gencb" | 129 | .Fa "BN_GENCB *cb" |
117 | .Fa "int (*callback)(int, int, BN_GENCB *)" | 130 | .Fa "int (*cb_fp)(int, int, BN_GENCB *)" |
118 | .Fa "void *cb_arg" | 131 | .Fa "void *cb_arg" |
119 | .Fc | 132 | .Fc |
120 | .Ft void * | 133 | .Ft void * |
@@ -124,21 +137,27 @@ | |||
124 | .Pp | 137 | .Pp |
125 | Deprecated: | 138 | Deprecated: |
126 | .Pp | 139 | .Pp |
140 | .Ft void | ||
141 | .Fo BN_GENCB_set_old | ||
142 | .Fa "BN_GENCB *cb" | ||
143 | .Fa "void (*cb_fp)(int, int, void *)" | ||
144 | .Fa "void *cb_arg" | ||
145 | .Fc | ||
127 | .Ft BIGNUM * | 146 | .Ft BIGNUM * |
128 | .Fo BN_generate_prime | 147 | .Fo BN_generate_prime |
129 | .Fa "BIGNUM *ret" | 148 | .Fa "BIGNUM *ret" |
130 | .Fa "int num" | 149 | .Fa "int num" |
131 | .Fa "int safe" | 150 | .Fa "int safe" |
132 | .Fa "BIGNUM *add" | 151 | .Fa "BIGNUM *modulus" |
133 | .Fa "BIGNUM *rem" | 152 | .Fa "BIGNUM *remainder" |
134 | .Fa "void (*callback)(int, int, void *)" | 153 | .Fa "void (*cb_fp)(int, int, void *)" |
135 | .Fa "void *cb_arg" | 154 | .Fa "void *cb_arg" |
136 | .Fc | 155 | .Fc |
137 | .Ft int | 156 | .Ft int |
138 | .Fo BN_is_prime | 157 | .Fo BN_is_prime |
139 | .Fa "const BIGNUM *a" | 158 | .Fa "const BIGNUM *a" |
140 | .Fa "int checks" | 159 | .Fa "int checks" |
141 | .Fa "void (*callback)(int, int, void *)" | 160 | .Fa "void (*cb_fp)(int, int, void *)" |
142 | .Fa "BN_CTX *ctx" | 161 | .Fa "BN_CTX *ctx" |
143 | .Fa "void *cb_arg" | 162 | .Fa "void *cb_arg" |
144 | .Fc | 163 | .Fc |
@@ -146,22 +165,84 @@ Deprecated: | |||
146 | .Fo BN_is_prime_fasttest | 165 | .Fo BN_is_prime_fasttest |
147 | .Fa "const BIGNUM *a" | 166 | .Fa "const BIGNUM *a" |
148 | .Fa "int checks" | 167 | .Fa "int checks" |
149 | .Fa "void (*callback)(int, int, void *)" | 168 | .Fa "void (*cb_fp)(int, int, void *)" |
150 | .Fa "BN_CTX *ctx" | 169 | .Fa "BN_CTX *ctx" |
151 | .Fa "void *cb_arg" | 170 | .Fa "void *cb_arg" |
152 | .Fa "int do_trial_division" | 171 | .Fa "int do_trial_division" |
153 | .Fc | 172 | .Fc |
154 | .Sh DESCRIPTION | 173 | .Sh DESCRIPTION |
174 | .Fn BN_is_prime_ex | ||
175 | and | ||
176 | .Fn BN_is_prime_fasttest_ex | ||
177 | test whether the number | ||
178 | .Fa a | ||
179 | is prime. | ||
180 | In LibreSSL, both functions behave identically, | ||
181 | use the Baillie-Pomerance-Selfridge-Wagstaff algorithm, | ||
182 | and ignore the | ||
183 | .Fa checks | ||
184 | and | ||
185 | .Fa do_trial_division | ||
186 | arguments. | ||
187 | .Pp | ||
188 | It is unknown whether any composite number exists that the | ||
189 | Baillie-PSW algorithm misclassifies as a prime. | ||
190 | Some suspect that there may be infinitely many such numbers, | ||
191 | but not a single one is currently known. | ||
192 | It is known that no such number exists below 2\(ha64. | ||
193 | .Pp | ||
194 | If | ||
195 | .Dv NULL | ||
196 | is passed for the | ||
197 | .Fa ctx | ||
198 | argument, these function allocate a | ||
199 | .Vt BN_CTX | ||
200 | object internally when they need one and free it before returning. | ||
201 | Alternatively, to save the overhead of allocating and freeing | ||
202 | that object for each call, the caller can pre-allocate a | ||
203 | .Vt BN_CTX | ||
204 | object and pass it in the | ||
205 | .Fa ctx | ||
206 | argument. | ||
207 | .Pp | ||
155 | .Fn BN_generate_prime_ex | 208 | .Fn BN_generate_prime_ex |
156 | generates a pseudo-random prime number of at least bit length | 209 | generates a pseudo-random prime number of at least bit length |
157 | .Fa bits . | 210 | .Fa bits |
158 | The returned number is probably prime, but there is a very small | 211 | and places it in |
159 | probability of returning a non-prime number. | 212 | .Fa ret . |
160 | If | 213 | Primality of |
161 | .Fa ret | 214 | .Fa ret |
215 | is tested internally using | ||
216 | .Fn BN_is_prime_ex . | ||
217 | Consequently, for | ||
218 | .Fa bits | ||
219 | larger than 64, it is theoretically possible | ||
220 | that this function might place a composite number into | ||
221 | .Fa ret ; | ||
222 | the probability of such an event is unknown but very small. | ||
223 | .Pp | ||
224 | The prime may have to fulfill additional requirements for use in | ||
225 | Diffie-Hellman key exchange: | ||
226 | .Bl -bullet | ||
227 | .It | ||
228 | If | ||
229 | .Fa modulus | ||
162 | is not | 230 | is not |
163 | .Dv NULL , | 231 | .Dv NULL , |
164 | it will be used to store the number. | 232 | a prime is generated that fulfills the condition |
233 | .Fa ret No % Fa modulus No = Fa remainder . | ||
234 | If the | ||
235 | .Fa remainder | ||
236 | argument is | ||
237 | .Dv NULL , | ||
238 | 1 is used as the desired remainder. | ||
239 | .It | ||
240 | If the | ||
241 | .Fa safe | ||
242 | argument is non-zero, a safe prime is generated, that is, | ||
243 | .Po Fa ret No \- 1 Pc Ns /2 | ||
244 | is also prime. | ||
245 | .El | ||
165 | .Pp | 246 | .Pp |
166 | If | 247 | If |
167 | .Fa cb | 248 | .Fa cb |
@@ -170,15 +251,18 @@ is not | |||
170 | it is used as follows: | 251 | it is used as follows: |
171 | .Bl -bullet | 252 | .Bl -bullet |
172 | .It | 253 | .It |
173 | .Fn BN_GENCB_call cb 0 i | 254 | .Fn BN_GENCB_call cb 0 serial_number |
174 | is called after generating the i-th potential prime number. | 255 | is called after generating a potential prime number. |
175 | .It | 256 | .It |
176 | While the number is being tested for primality, | 257 | The |
177 | .Fn BN_GENCB_call cb 1 j | 258 | .Fa state_code |
178 | is called as described below. | 259 | of 1 is reserved for callbacks during primality testing, |
260 | but LibreSSL performs no such callbacks. | ||
179 | .It | 261 | .It |
180 | When a prime has been found, | 262 | When |
181 | .Fn BN_GENCB_call cb 2 i | 263 | .Fa safe |
264 | is non-zero and a safe prime has been found, | ||
265 | .Fn BN_GENCB_call cb 2 serial_number | ||
182 | is called. | 266 | is called. |
183 | .It | 267 | .It |
184 | The callers of | 268 | The callers of |
@@ -189,207 +273,129 @@ with other values as described in their respective manual pages; see | |||
189 | .Sx SEE ALSO . | 273 | .Sx SEE ALSO . |
190 | .El | 274 | .El |
191 | .Pp | 275 | .Pp |
192 | The prime may have to fulfill additional requirements for use in | 276 | In all cases, the |
193 | Diffie-Hellman key exchange: | 277 | .Fa serial_number |
194 | .Pp | 278 | is the number of candidates that have already been discarded |
195 | If | 279 | for not being prime; that is, |
196 | .Fa add | 280 | .Fa serial_number |
197 | is not | 281 | is 0 for the first candidate |
198 | .Dv NULL , | 282 | and then incremented whenever a new candidate is generated. |
199 | the prime will fulfill the condition p % | ||
200 | .Fa add | ||
201 | == | ||
202 | .Fa rem | ||
203 | (p % | ||
204 | .Fa add | ||
205 | == 1 if | ||
206 | .Fa rem | ||
207 | == | ||
208 | .Dv NULL ) | ||
209 | in order to suit a given generator. | ||
210 | .Pp | ||
211 | If | ||
212 | .Fa safe | ||
213 | is true, it will be a safe prime (i.e. a prime p so that (p-1)/2 | ||
214 | is also prime). | ||
215 | .Pp | ||
216 | .Fn BN_is_prime_ex | ||
217 | and | ||
218 | .Fn BN_is_prime_fasttest_ex | ||
219 | test if the number | ||
220 | .Fa p | ||
221 | is prime. | ||
222 | The following tests are performed until one of them shows that | ||
223 | .Fa p | ||
224 | is composite; if | ||
225 | .Fa p | ||
226 | passes all these tests, it is considered prime. | ||
227 | .Pp | 283 | .Pp |
228 | .Fn BN_is_prime_fasttest_ex , | 284 | .Fn BN_GENCB_call |
229 | when called with | 285 | calls the callback function held in |
230 | .Fa do_trial_division | ||
231 | == 1, first attempts trial division by a number of small primes; | ||
232 | if no divisors are found by this test and | ||
233 | .Fa cb | 286 | .Fa cb |
234 | is not | 287 | and passes the |
235 | .Dv NULL , | 288 | .Fa state_code |
236 | .Sy BN_GENCB_call(cb, 1, -1) | 289 | and the |
237 | is called. | 290 | .Fa serial_number |
238 | If | 291 | as arguments. |
239 | .Fa do_trial_division | ||
240 | == 0, this test is skipped. | ||
241 | .Pp | ||
242 | Both | ||
243 | .Fn BN_is_prime_ex | ||
244 | and | ||
245 | .Fn BN_is_prime_fasttest_ex | ||
246 | perform a Miller-Rabin probabilistic primality test with | ||
247 | .Fa nchecks | ||
248 | iterations. | ||
249 | If | 292 | If |
250 | .Fa nchecks | 293 | .Fa cb |
251 | == | 294 | is |
252 | .Dv BN_prime_checks , | 295 | .Dv NULL |
253 | a number of iterations is used that yields a false positive rate | 296 | or does not contain a callback function, no action occurs. |
254 | of at most 2\(ha-64 for random input. | ||
255 | The error rate depends on the size of the prime | ||
256 | and goes down for bigger primes. | ||
257 | The rate is 2\(ha-80 starting at 308 bits, 2\(ha-112 at 852 bits, | ||
258 | 2\(ha-128 at 1080 bits, 2\(ha-192 at 3747 bits | ||
259 | and 2\(ha-256 at 6394 bits. | ||
260 | .Pp | 297 | .Pp |
261 | When the source of the prime is not random or not trusted, the | 298 | .Fn BN_GENCB_new |
262 | number of checks needs to be much higher to reach the same level | 299 | allocates a new |
263 | of assurance: It should equal half of the targeted security level | 300 | .Vt BN_GENCB |
264 | in bits (rounded up to the next integer if necessary). | 301 | object. |
265 | For instance, to reach the 128-bit security level, | ||
266 | .Fa nchecks | ||
267 | should be set to 64. | ||
268 | .Pp | 302 | .Pp |
303 | .Fn BN_GENCB_free | ||
304 | frees | ||
305 | .Fa cb . | ||
269 | If | 306 | If |
270 | .Fa cb | 307 | .Fa cb |
271 | is not | 308 | is |
272 | .Dv NULL , | 309 | .Dv NULL , |
273 | .Fa BN_GENCB_call cb 1 j | 310 | no action occurs. |
274 | is called after the j-th iteration (j = 0, 1, ...). | ||
275 | .Fa ctx | ||
276 | is a pre-allocated | ||
277 | .Vt BN_CTX | ||
278 | (to save the overhead of allocating and freeing the structure in a | ||
279 | loop), or | ||
280 | .Dv NULL . | ||
281 | .Pp | 311 | .Pp |
282 | .Fn BN_GENCB_call | 312 | .Fn BN_GENCB_set |
283 | calls the callback function held in the | 313 | initialises |
284 | .Vt BN_GENCB | 314 | .Fa cb |
285 | structure and passes the ints | 315 | to use the callback function pointer |
286 | .Fa a | 316 | .Fa cb_fp |
287 | and | 317 | and the additional callback argument |
288 | .Fa b | 318 | .Fa cb_arg . |
289 | as arguments. | ||
290 | There are two types of | ||
291 | .Vt BN_GENCB | ||
292 | structures that are supported: "new" style and "old" style. | ||
293 | New programs should prefer the "new" style, whilst the "old" style is | ||
294 | provided for backwards compatibility purposes. | ||
295 | .Pp | 319 | .Pp |
296 | A | 320 | The deprecated function |
297 | .Vt BN_GENCB | 321 | .Fn BN_GENCB_set_old |
298 | structure should be created through a call to | 322 | initialises |
299 | .Fn BN_GENCB_new | 323 | .Fa cb |
300 | and freed through a call to | 324 | to use the old-style callback function pointer |
301 | .Fn BN_GENCB_free . | 325 | .Fa cb_fp |
326 | and the additional callback argument | ||
327 | .Fa cb_arg . | ||
302 | .Pp | 328 | .Pp |
303 | For "new" style callbacks a | 329 | .Fn BN_generate_prime |
304 | .Vt BN_GENCB | 330 | is a deprecated wrapper around |
305 | structure should be initialised with a call to | ||
306 | .Fn BN_GENCB_set , | ||
307 | where | ||
308 | .Fa gencb | ||
309 | is a | ||
310 | .Vt BN_GENCB * , | ||
311 | .Fa callback | ||
312 | is of type | ||
313 | .Vt int (*callback)(int, int, BN_GENCB *) | ||
314 | and | ||
315 | .Fa cb_arg | ||
316 | is a | ||
317 | .Vt void * . | ||
318 | "Old" style callbacks are the same except they are initialised with a | ||
319 | call to | ||
320 | .Fn BN_GENCB_set_old | 331 | .Fn BN_GENCB_set_old |
321 | and | 332 | and |
322 | .Fa callback | 333 | .Fn BN_generate_prime_ex . |
323 | is of type | 334 | In contrast to |
324 | .Vt void (*callback)(int, int, void *) . | 335 | .Fn BN_generate_prime_ex , |
325 | .Pp | 336 | if |
326 | A callback is invoked through a call to | 337 | .Dv NULL |
327 | .Fn BN_GENCB_call . | 338 | is passed for the |
328 | This will check the type of the callback and will invoke | 339 | .Fa ret |
329 | .Fn callback a b gencb | 340 | argument, a new |
330 | for new style callbacks or | 341 | .Vt BIGNUM |
331 | .Fn callback a b cb_arg | 342 | object is allocated and returned. |
332 | for old style. | ||
333 | .Pp | ||
334 | It is possible to obtain the argument associated with a | ||
335 | .Vt BN_GENCB | ||
336 | structure (set via a call to | ||
337 | .Fn BN_GENCB_set | ||
338 | or | ||
339 | .Fn BN_GENCB_set_old ) | ||
340 | using | ||
341 | .Fn BN_GENCB_get_arg . | ||
342 | .Pp | 343 | .Pp |
343 | .Fn BN_generate_prime | 344 | Similarly, |
344 | (deprecated) works in the same way as | ||
345 | .Fn BN_generate_prime_ex | ||
346 | but expects an old style callback function directly in the | ||
347 | .Fa callback | ||
348 | parameter, and an argument to pass to it in the | ||
349 | .Fa cb_arg . | ||
350 | Similarly | ||
351 | .Fn BN_is_prime | 345 | .Fn BN_is_prime |
352 | and | 346 | and |
353 | .Fn BN_is_prime_fasttest | 347 | .Fn BN_is_prime_fasttest |
354 | are deprecated and can be compared to | 348 | are deprecated wrappers around |
355 | .Fn BN_is_prime_ex | 349 | .Fn BN_GENCB_set_old |
356 | and | 350 | and |
357 | .Fn BN_is_prime_fasttest_ex | 351 | .Fn BN_is_prime_ex . |
358 | respectively. | ||
359 | .Sh RETURN VALUES | 352 | .Sh RETURN VALUES |
360 | .Fn BN_generate_prime_ex | ||
361 | returns 1 on success or 0 on error. | ||
362 | .Pp | ||
363 | .Fn BN_is_prime_ex , | 353 | .Fn BN_is_prime_ex , |
364 | .Fn BN_is_prime_fasttest_ex , | 354 | .Fn BN_is_prime_fasttest_ex , |
365 | .Fn BN_is_prime , | 355 | .Fn BN_is_prime , |
366 | and | 356 | and |
367 | .Fn BN_is_prime_fasttest | 357 | .Fn BN_is_prime_fasttest |
368 | return 0 if the number is composite, 1 if it is prime with an error | 358 | return 0 if the number is composite, 1 if it is prime with a very small |
369 | probability of less than | 359 | error probability, or \-1 on error. |
370 | .Pf 0.25^ Fa nchecks , | ||
371 | and -1 on error. | ||
372 | .Pp | 360 | .Pp |
373 | .Fn BN_generate_prime | 361 | .Fn BN_generate_prime_ex |
374 | returns the prime number on success, | 362 | returns 1 on success or 0 on error. |
363 | .Pp | ||
364 | .Fn BN_GENCB_call | ||
365 | returns 1 on success, including when | ||
366 | .Fa cb | ||
367 | is | ||
375 | .Dv NULL | 368 | .Dv NULL |
376 | otherwise. | 369 | or does not contain a callback function, |
370 | or 0 on error. | ||
377 | .Pp | 371 | .Pp |
378 | .Fn BN_GENCB_new | 372 | .Fn BN_GENCB_new |
379 | returns a pointer to a | 373 | returns a pointer to the newly allocated |
380 | .Vt BN_GENCB | 374 | .Vt BN_GENCB |
381 | structure on success, or | 375 | object or |
382 | .Dv NULL | 376 | .Dv NULL |
383 | otherwise. | 377 | if memory allocation fails. |
378 | .Pp | ||
379 | The callback functions pointed to by the | ||
380 | .Fa cb_fp | ||
381 | arguments are supposed to return 1 on success or 0 on error. | ||
384 | .Pp | 382 | .Pp |
385 | .Fn BN_GENCB_get_arg | 383 | .Fn BN_GENCB_get_arg |
386 | returns the argument previously associated with a | 384 | returns the |
387 | .Vt BN_GENCB | 385 | .Fa cb_arg |
388 | structure. | 386 | pointer that was previously stored in |
387 | .Fa cb | ||
388 | using | ||
389 | .Fn BN_GENCB_set | ||
390 | or | ||
391 | .Fn BN_GENCB_set_old . | ||
389 | .Pp | 392 | .Pp |
390 | Callback functions should return 1 on success or 0 on error. | 393 | .Fn BN_generate_prime |
394 | returns the prime number on success or | ||
395 | .Dv NULL | ||
396 | on failure. | ||
391 | .Pp | 397 | .Pp |
392 | The error codes can be obtained by | 398 | In some cases, error codes can be obtained by |
393 | .Xr ERR_get_error 3 . | 399 | .Xr ERR_get_error 3 . |
394 | .Sh SEE ALSO | 400 | .Sh SEE ALSO |
395 | .Xr BN_new 3 , | 401 | .Xr BN_new 3 , |