]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - secure/lib/libcrypto/man/BN_generate_prime.3
MFV r325013,r325034: 640 number_to_scaled_string is duplicated in several commands
[FreeBSD/FreeBSD.git] / secure / lib / libcrypto / man / BN_generate_prime.3
1 .\" Automatically generated by Pod::Man 4.07 (Pod::Simple 3.35)
2 .\"
3 .\" Standard preamble:
4 .\" ========================================================================
5 .de Sp \" Vertical space (when we can't use .PP)
6 .if t .sp .5v
7 .if n .sp
8 ..
9 .de Vb \" Begin verbatim text
10 .ft CW
11 .nf
12 .ne \\$1
13 ..
14 .de Ve \" End verbatim text
15 .ft R
16 .fi
17 ..
18 .\" Set up some character translations and predefined strings.  \*(-- will
19 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
20 .\" double quote, and \*(R" will give a right double quote.  \*(C+ will
21 .\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
22 .\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
23 .\" nothing in troff, for use with C<>.
24 .tr \(*W-
25 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
26 .ie n \{\
27 .    ds -- \(*W-
28 .    ds PI pi
29 .    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
30 .    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
31 .    ds L" ""
32 .    ds R" ""
33 .    ds C` ""
34 .    ds C' ""
35 'br\}
36 .el\{\
37 .    ds -- \|\(em\|
38 .    ds PI \(*p
39 .    ds L" ``
40 .    ds R" ''
41 .    ds C`
42 .    ds C'
43 'br\}
44 .\"
45 .\" Escape single quotes in literal strings from groff's Unicode transform.
46 .ie \n(.g .ds Aq \(aq
47 .el       .ds Aq '
48 .\"
49 .\" If the F register is >0, we'll generate index entries on stderr for
50 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
51 .\" entries marked with X<> in POD.  Of course, you'll have to process the
52 .\" output yourself in some meaningful fashion.
53 .\"
54 .\" Avoid warning from groff about undefined register 'F'.
55 .de IX
56 ..
57 .if !\nF .nr F 0
58 .if \nF>0 \{\
59 .    de IX
60 .    tm Index:\\$1\t\\n%\t"\\$2"
61 ..
62 .    if !\nF==2 \{\
63 .        nr % 0
64 .        nr F 2
65 .    \}
66 .\}
67 .\"
68 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
70 .    \" fudge factors for nroff and troff
71 .if n \{\
72 .    ds #H 0
73 .    ds #V .8m
74 .    ds #F .3m
75 .    ds #[ \f1
76 .    ds #] \fP
77 .\}
78 .if t \{\
79 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80 .    ds #V .6m
81 .    ds #F 0
82 .    ds #[ \&
83 .    ds #] \&
84 .\}
85 .    \" simple accents for nroff and troff
86 .if n \{\
87 .    ds ' \&
88 .    ds ` \&
89 .    ds ^ \&
90 .    ds , \&
91 .    ds ~ ~
92 .    ds /
93 .\}
94 .if t \{\
95 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101 .\}
102 .    \" troff and (daisy-wheel) nroff accents
103 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110 .ds ae a\h'-(\w'a'u*4/10)'e
111 .ds Ae A\h'-(\w'A'u*4/10)'E
112 .    \" corrections for vroff
113 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115 .    \" for low resolution devices (crt and lpr)
116 .if \n(.H>23 .if \n(.V>19 \
117 \{\
118 .    ds : e
119 .    ds 8 ss
120 .    ds o a
121 .    ds d- d\h'-1'\(ga
122 .    ds D- D\h'-1'\(hy
123 .    ds th \o'bp'
124 .    ds Th \o'LP'
125 .    ds ae ae
126 .    ds Ae AE
127 .\}
128 .rm #[ #] #H #V #F C
129 .\" ========================================================================
130 .\"
131 .IX Title "BN_generate_prime 3"
132 .TH BN_generate_prime 3 "2017-05-25" "1.0.2l" "OpenSSL"
133 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
134 .\" way too many mistakes in technical documents.
135 .if n .ad l
136 .nh
137 .SH "NAME"
138 BN_generate_prime_ex, BN_is_prime_ex, BN_is_prime_fasttest_ex, BN_GENCB_call,
139 BN_GENCB_set_old, BN_GENCB_set, BN_generate_prime, BN_is_prime,
140 BN_is_prime_fasttest \- generate primes and test for primality
141 .SH "SYNOPSIS"
142 .IX Header "SYNOPSIS"
143 .Vb 1
144 \& #include <openssl/bn.h>
145 \&
146 \& int BN_generate_prime_ex(BIGNUM *ret,int bits,int safe, const BIGNUM *add,
147 \&     const BIGNUM *rem, BN_GENCB *cb);
148 \&
149 \& int BN_is_prime_ex(const BIGNUM *p,int nchecks, BN_CTX *ctx, BN_GENCB *cb);
150 \&
151 \& int BN_is_prime_fasttest_ex(const BIGNUM *p,int nchecks, BN_CTX *ctx,
152 \&     int do_trial_division, BN_GENCB *cb);
153 \&
154 \& int BN_GENCB_call(BN_GENCB *cb, int a, int b);
155 \&
156 \& #define BN_GENCB_set_old(gencb, callback, cb_arg) ...
157 \&
158 \& #define BN_GENCB_set(gencb, callback, cb_arg) ...
159 .Ve
160 .PP
161 Deprecated:
162 .PP
163 .Vb 2
164 \& BIGNUM *BN_generate_prime(BIGNUM *ret, int num, int safe, BIGNUM *add,
165 \&     BIGNUM *rem, void (*callback)(int, int, void *), void *cb_arg);
166 \&
167 \& int BN_is_prime(const BIGNUM *a, int checks, void (*callback)(int, int, 
168 \&     void *), BN_CTX *ctx, void *cb_arg);
169 \&
170 \& int BN_is_prime_fasttest(const BIGNUM *a, int checks,
171 \&     void (*callback)(int, int, void *), BN_CTX *ctx, void *cb_arg,
172 \&     int do_trial_division);
173 .Ve
174 .SH "DESCRIPTION"
175 .IX Header "DESCRIPTION"
176 \&\fIBN_generate_prime_ex()\fR generates a pseudo-random prime number of
177 bit length \fBbits\fR.
178 If \fBret\fR is not \fB\s-1NULL\s0\fR, it will be used to store the number.
179 .PP
180 If \fBcb\fR is not \fB\s-1NULL\s0\fR, it is used as follows:
181 .IP "\(bu" 4
182 \&\fBBN_GENCB_call(cb, 0, i)\fR is called after generating the i\-th
183 potential prime number.
184 .IP "\(bu" 4
185 While the number is being tested for primality,
186 \&\fBBN_GENCB_call(cb, 1, j)\fR is called as described below.
187 .IP "\(bu" 4
188 When a prime has been found, \fBBN_GENCB_call(cb, 2, i)\fR is called.
189 .PP
190 The prime may have to fulfill additional requirements for use in
191 Diffie-Hellman key exchange:
192 .PP
193 If \fBadd\fR is not \fB\s-1NULL\s0\fR, the prime will fulfill the condition p % \fBadd\fR
194 == \fBrem\fR (p % \fBadd\fR == 1 if \fBrem\fR == \fB\s-1NULL\s0\fR) in order to suit a given
195 generator.
196 .PP
197 If \fBsafe\fR is true, it will be a safe prime (i.e. a prime p so
198 that (p\-1)/2 is also prime).
199 .PP
200 The \s-1PRNG\s0 must be seeded prior to calling \fIBN_generate_prime_ex()\fR.
201 The prime number generation has a negligible error probability.
202 .PP
203 \&\fIBN_is_prime_ex()\fR and \fIBN_is_prime_fasttest_ex()\fR test if the number \fBp\fR is
204 prime.  The following tests are performed until one of them shows that
205 \&\fBp\fR is composite; if \fBp\fR passes all these tests, it is considered
206 prime.
207 .PP
208 \&\fIBN_is_prime_fasttest_ex()\fR, when called with \fBdo_trial_division == 1\fR,
209 first attempts trial division by a number of small primes;
210 if no divisors are found by this test and \fBcb\fR is not \fB\s-1NULL\s0\fR,
211 \&\fBBN_GENCB_call(cb, 1, \-1)\fR is called.
212 If \fBdo_trial_division == 0\fR, this test is skipped.
213 .PP
214 Both \fIBN_is_prime_ex()\fR and \fIBN_is_prime_fasttest_ex()\fR perform a Miller-Rabin
215 probabilistic primality test with \fBnchecks\fR iterations. If
216 \&\fBnchecks == BN_prime_checks\fR, a number of iterations is used that
217 yields a false positive rate of at most 2^\-80 for random input.
218 .PP
219 If \fBcb\fR is not \fB\s-1NULL\s0\fR, \fBBN_GENCB_call(cb, 1, j)\fR is called
220 after the j\-th iteration (j = 0, 1, ...). \fBctx\fR is a
221 pre-allocated \fB\s-1BN_CTX\s0\fR (to save the overhead of allocating and
222 freeing the structure in a loop), or \fB\s-1NULL\s0\fR.
223 .PP
224 BN_GENCB_call calls the callback function held in the \fB\s-1BN_GENCB\s0\fR structure
225 and passes the ints \fBa\fR and \fBb\fR as arguments. There are two types of
226 \&\fB\s-1BN_GENCB\s0\fR structure that are supported: \*(L"new\*(R" style and \*(L"old\*(R" style. New
227 programs should prefer the \*(L"new\*(R" style, whilst the \*(L"old\*(R" style is provided
228 for backwards compatibility purposes.
229 .PP
230 For \*(L"new\*(R" style callbacks a \s-1BN_GENCB\s0 structure should be initialised with a
231 call to BN_GENCB_set, where \fBgencb\fR is a \fB\s-1BN_GENCB\s0 *\fR, \fBcallback\fR is of
232 type \fBint (*callback)(int, int, \s-1BN_GENCB\s0 *)\fR and \fBcb_arg\fR is a \fBvoid *\fR.
233 \&\*(L"Old\*(R" style callbacks are the same except they are initialised with a call
234 to BN_GENCB_set_old and \fBcallback\fR is of type
235 \&\fBvoid (*callback)(int, int, void *)\fR.
236 .PP
237 A callback is invoked through a call to \fBBN_GENCB_call\fR. This will check
238 the type of the callback and will invoke \fBcallback(a, b, gencb)\fR for new
239 style callbacks or \fBcallback(a, b, cb_arg)\fR for old style.
240 .PP
241 BN_generate_prime (deprecated) works in the same way as
242 BN_generate_prime_ex but expects an old style callback function
243 directly in the \fBcallback\fR parameter, and an argument to pass to it in
244 the \fBcb_arg\fR. Similarly BN_is_prime and BN_is_prime_fasttest are
245 deprecated and can be compared to BN_is_prime_ex and
246 BN_is_prime_fasttest_ex respectively.
247 .SH "RETURN VALUES"
248 .IX Header "RETURN VALUES"
249 \&\fIBN_generate_prime_ex()\fR return 1 on success or 0 on error.
250 .PP
251 \&\fIBN_is_prime_ex()\fR, \fIBN_is_prime_fasttest_ex()\fR, \fIBN_is_prime()\fR and
252 \&\fIBN_is_prime_fasttest()\fR return 0 if the number is composite, 1 if it is
253 prime with an error probability of less than 0.25^\fBnchecks\fR, and
254 \&\-1 on error.
255 .PP
256 \&\fIBN_generate_prime()\fR returns the prime number on success, \fB\s-1NULL\s0\fR otherwise.
257 .PP
258 Callback functions should return 1 on success or 0 on error.
259 .PP
260 The error codes can be obtained by \fIERR_get_error\fR\|(3).
261 .SH "SEE ALSO"
262 .IX Header "SEE ALSO"
263 \&\fIbn\fR\|(3), \fIERR_get_error\fR\|(3), \fIrand\fR\|(3)
264 .SH "HISTORY"
265 .IX Header "HISTORY"
266 The \fBcb_arg\fR arguments to \fIBN_generate_prime()\fR and to \fIBN_is_prime()\fR
267 were added in SSLeay 0.9.0. The \fBret\fR argument to \fIBN_generate_prime()\fR
268 was added in SSLeay 0.9.1.
269 \&\fIBN_is_prime_fasttest()\fR was added in OpenSSL 0.9.5.