Merge from vendor branch BINUTILS:
[dragonfly.git] / secure / lib / libcrypto / man / bn.3
1 .\" Automatically generated by Pod::Man version 1.15
2 .\" Wed Feb 19 16:43:01 2003
3 .\"
4 .\" Standard preamble:
5 .\" ======================================================================
6 .de Sh \" Subsection heading
7 .br
8 .if t .Sp
9 .ne 5
10 .PP
11 \fB\\$1\fR
12 .PP
13 ..
14 .de Sp \" Vertical space (when we can't use .PP)
15 .if t .sp .5v
16 .if n .sp
17 ..
18 .de Ip \" List item
19 .br
20 .ie \\n(.$>=3 .ne \\$3
21 .el .ne 3
22 .IP "\\$1" \\$2
23 ..
24 .de Vb \" Begin verbatim text
25 .ft CW
26 .nf
27 .ne \\$1
28 ..
29 .de Ve \" End verbatim text
30 .ft R
31
32 .fi
33 ..
34 .\" Set up some character translations and predefined strings.  \*(-- will
35 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
36 .\" double quote, and \*(R" will give a right double quote.  | will give a
37 .\" real vertical bar.  \*(C+ will give a nicer C++.  Capital omega is used
38 .\" to do unbreakable dashes and therefore won't be available.  \*(C` and
39 .\" \*(C' expand to `' in nroff, nothing in troff, for use with C<>
40 .tr \(*W-|\(bv\*(Tr
41 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
42 .ie n \{\
43 .    ds -- \(*W-
44 .    ds PI pi
45 .    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
46 .    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
47 .    ds L" ""
48 .    ds R" ""
49 .    ds C` ""
50 .    ds C' ""
51 'br\}
52 .el\{\
53 .    ds -- \|\(em\|
54 .    ds PI \(*p
55 .    ds L" ``
56 .    ds R" ''
57 'br\}
58 .\"
59 .\" If the F register is turned on, we'll generate index entries on stderr
60 .\" for titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and
61 .\" index entries marked with X<> in POD.  Of course, you'll have to process
62 .\" the output yourself in some meaningful fashion.
63 .if \nF \{\
64 .    de IX
65 .    tm Index:\\$1\t\\n%\t"\\$2"
66 ..
67 .    nr % 0
68 .    rr F
69 .\}
70 .\"
71 .\" For nroff, turn off justification.  Always turn off hyphenation; it
72 .\" makes way too many mistakes in technical documents.
73 .hy 0
74 .if n .na
75 .\"
76 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
77 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
78 .bd B 3
79 .    \" fudge factors for nroff and troff
80 .if n \{\
81 .    ds #H 0
82 .    ds #V .8m
83 .    ds #F .3m
84 .    ds #[ \f1
85 .    ds #] \fP
86 .\}
87 .if t \{\
88 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
89 .    ds #V .6m
90 .    ds #F 0
91 .    ds #[ \&
92 .    ds #] \&
93 .\}
94 .    \" simple accents for nroff and troff
95 .if n \{\
96 .    ds ' \&
97 .    ds ` \&
98 .    ds ^ \&
99 .    ds , \&
100 .    ds ~ ~
101 .    ds /
102 .\}
103 .if t \{\
104 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
105 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
106 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
107 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
108 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
109 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
110 .\}
111 .    \" troff and (daisy-wheel) nroff accents
112 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
113 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
114 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
115 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
116 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
117 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
118 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
119 .ds ae a\h'-(\w'a'u*4/10)'e
120 .ds Ae A\h'-(\w'A'u*4/10)'E
121 .    \" corrections for vroff
122 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
123 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
124 .    \" for low resolution devices (crt and lpr)
125 .if \n(.H>23 .if \n(.V>19 \
126 \{\
127 .    ds : e
128 .    ds 8 ss
129 .    ds o a
130 .    ds d- d\h'-1'\(ga
131 .    ds D- D\h'-1'\(hy
132 .    ds th \o'bp'
133 .    ds Th \o'LP'
134 .    ds ae ae
135 .    ds Ae AE
136 .\}
137 .rm #[ #] #H #V #F C
138 .\" ======================================================================
139 .\"
140 .IX Title "bn 3"
141 .TH bn 3 "0.9.7a" "2003-02-19" "OpenSSL"
142 .UC
143 .SH "NAME"
144 bn \- multiprecision integer arithmetics
145 .SH "SYNOPSIS"
146 .IX Header "SYNOPSIS"
147 .Vb 1
148 \& #include <openssl/bn.h>
149 .Ve
150 .Vb 5
151 \& BIGNUM *BN_new(void);
152 \& void BN_free(BIGNUM *a);
153 \& void BN_init(BIGNUM *);
154 \& void BN_clear(BIGNUM *a);
155 \& void BN_clear_free(BIGNUM *a);
156 .Ve
157 .Vb 3
158 \& BN_CTX *BN_CTX_new(void);
159 \& void BN_CTX_init(BN_CTX *c);
160 \& void BN_CTX_free(BN_CTX *c);
161 .Ve
162 .Vb 2
163 \& BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b);
164 \& BIGNUM *BN_dup(const BIGNUM *a);
165 .Ve
166 .Vb 1
167 \& BIGNUM *BN_swap(BIGNUM *a, BIGNUM *b);
168 .Ve
169 .Vb 3
170 \& int BN_num_bytes(const BIGNUM *a);
171 \& int BN_num_bits(const BIGNUM *a);
172 \& int BN_num_bits_word(BN_ULONG w);
173 .Ve
174 .Vb 19
175 \& int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
176 \& int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
177 \& int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
178 \& int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx);
179 \& int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *a, const BIGNUM *d,
180 \&         BN_CTX *ctx);
181 \& int BN_mod(BIGNUM *rem, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
182 \& int BN_nnmod(BIGNUM *rem, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
183 \& int BN_mod_add(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
184 \&         BN_CTX *ctx);
185 \& int BN_mod_sub(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
186 \&         BN_CTX *ctx);
187 \& int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
188 \&         BN_CTX *ctx);
189 \& int BN_mod_sqr(BIGNUM *ret, BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
190 \& int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BN_CTX *ctx);
191 \& int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
192 \&         const BIGNUM *m, BN_CTX *ctx);
193 \& int BN_gcd(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
194 .Ve
195 .Vb 5
196 \& int BN_add_word(BIGNUM *a, BN_ULONG w);
197 \& int BN_sub_word(BIGNUM *a, BN_ULONG w);
198 \& int BN_mul_word(BIGNUM *a, BN_ULONG w);
199 \& BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w);
200 \& BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w);
201 .Ve
202 .Vb 6
203 \& int BN_cmp(BIGNUM *a, BIGNUM *b);
204 \& int BN_ucmp(BIGNUM *a, BIGNUM *b);
205 \& int BN_is_zero(BIGNUM *a);
206 \& int BN_is_one(BIGNUM *a);
207 \& int BN_is_word(BIGNUM *a, BN_ULONG w);
208 \& int BN_is_odd(BIGNUM *a);
209 .Ve
210 .Vb 5
211 \& int BN_zero(BIGNUM *a);
212 \& int BN_one(BIGNUM *a);
213 \& const BIGNUM *BN_value_one(void);
214 \& int BN_set_word(BIGNUM *a, unsigned long w);
215 \& unsigned long BN_get_word(BIGNUM *a);
216 .Ve
217 .Vb 4
218 \& int BN_rand(BIGNUM *rnd, int bits, int top, int bottom);
219 \& int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom);
220 \& int BN_rand_range(BIGNUM *rnd, BIGNUM *range);
221 \& int BN_pseudo_rand_range(BIGNUM *rnd, BIGNUM *range);
222 .Ve
223 .Vb 4
224 \& BIGNUM *BN_generate_prime(BIGNUM *ret, int bits,int safe, BIGNUM *add,
225 \&         BIGNUM *rem, void (*callback)(int, int, void *), void *cb_arg);
226 \& int BN_is_prime(const BIGNUM *p, int nchecks,
227 \&         void (*callback)(int, int, void *), BN_CTX *ctx, void *cb_arg);
228 .Ve
229 .Vb 8
230 \& int BN_set_bit(BIGNUM *a, int n);
231 \& int BN_clear_bit(BIGNUM *a, int n);
232 \& int BN_is_bit_set(const BIGNUM *a, int n);
233 \& int BN_mask_bits(BIGNUM *a, int n);
234 \& int BN_lshift(BIGNUM *r, const BIGNUM *a, int n);
235 \& int BN_lshift1(BIGNUM *r, BIGNUM *a);
236 \& int BN_rshift(BIGNUM *r, BIGNUM *a, int n);
237 \& int BN_rshift1(BIGNUM *r, BIGNUM *a);
238 .Ve
239 .Vb 10
240 \& int BN_bn2bin(const BIGNUM *a, unsigned char *to);
241 \& BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret);
242 \& char *BN_bn2hex(const BIGNUM *a);
243 \& char *BN_bn2dec(const BIGNUM *a);
244 \& int BN_hex2bn(BIGNUM **a, const char *str);
245 \& int BN_dec2bn(BIGNUM **a, const char *str);
246 \& int BN_print(BIO *fp, const BIGNUM *a);
247 \& int BN_print_fp(FILE *fp, const BIGNUM *a);
248 \& int BN_bn2mpi(const BIGNUM *a, unsigned char *to);
249 \& BIGNUM *BN_mpi2bn(unsigned char *s, int len, BIGNUM *ret);
250 .Ve
251 .Vb 2
252 \& BIGNUM *BN_mod_inverse(BIGNUM *r, BIGNUM *a, const BIGNUM *n,
253 \&     BN_CTX *ctx);
254 .Ve
255 .Vb 6
256 \& BN_RECP_CTX *BN_RECP_CTX_new(void);
257 \& void BN_RECP_CTX_init(BN_RECP_CTX *recp);
258 \& void BN_RECP_CTX_free(BN_RECP_CTX *recp);
259 \& int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *m, BN_CTX *ctx);
260 \& int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *a, BIGNUM *b,
261 \&        BN_RECP_CTX *recp, BN_CTX *ctx);
262 .Ve
263 .Vb 11
264 \& BN_MONT_CTX *BN_MONT_CTX_new(void);
265 \& void BN_MONT_CTX_init(BN_MONT_CTX *ctx);
266 \& void BN_MONT_CTX_free(BN_MONT_CTX *mont);
267 \& int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *m, BN_CTX *ctx);
268 \& BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from);
269 \& int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b,
270 \&         BN_MONT_CTX *mont, BN_CTX *ctx);
271 \& int BN_from_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont,
272 \&         BN_CTX *ctx);
273 \& int BN_to_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont,
274 \&         BN_CTX *ctx);
275 .Ve
276 .SH "DESCRIPTION"
277 .IX Header "DESCRIPTION"
278 This library performs arithmetic operations on integers of arbitrary
279 size. It was written for use in public key cryptography, such as \s-1RSA\s0
280 and Diffie-Hellman.
281 .PP
282 It uses dynamic memory allocation for storing its data structures.
283 That means that there is no limit on the size of the numbers
284 manipulated by these functions, but return values must always be
285 checked in case a memory allocation error has occurred.
286 .PP
287 The basic object in this library is a \fB\s-1BIGNUM\s0\fR. It is used to hold a
288 single large integer. This type should be considered opaque and fields
289 should not be modified or accessed directly.
290 .PP
291 The creation of \fB\s-1BIGNUM\s0\fR objects is described in BN_new(3);
292 BN_add(3) describes most of the arithmetic operations.
293 Comparison is described in BN_cmp(3); BN_zero(3)
294 describes certain assignments, BN_rand(3) the generation of
295 random numbers, BN_generate_prime(3) deals with prime
296 numbers and BN_set_bit(3) with bit operations. The conversion
297 of \fB\s-1BIGNUM\s0\fRs to external formats is described in BN_bn2bin(3).
298 .SH "SEE ALSO"
299 .IX Header "SEE ALSO"
300 bn_internal(3),
301 dh(3), err(3), rand(3), rsa(3),
302 BN_new(3), BN_CTX_new(3),
303 BN_copy(3), BN_swap(3), BN_num_bytes(3),
304 BN_add(3), BN_add_word(3),
305 BN_cmp(3), BN_zero(3), BN_rand(3),
306 BN_generate_prime(3), BN_set_bit(3),
307 BN_bn2bin(3), BN_mod_inverse(3),
308 BN_mod_mul_reciprocal(3),
309 BN_mod_mul_montgomery(3)