]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - secure/lib/libcrypto/man/bn.3
This commit was generated by cvs2svn to compensate for changes in r102780,
[FreeBSD/FreeBSD.git] / secure / lib / libcrypto / man / bn.3
1 .\" Automatically generated by Pod::Man version 1.15
2 .\" Tue Jul 30 09:21:58 2002
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.6e" "2002-01-26" "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 3
167 \& int BN_num_bytes(const BIGNUM *a);
168 \& int BN_num_bits(const BIGNUM *a);
169 \& int BN_num_bits_word(BN_ULONG w);
170 .Ve
171 .Vb 13
172 \& int BN_add(BIGNUM *r, BIGNUM *a, BIGNUM *b);
173 \& int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
174 \& int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
175 \& int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *a, const BIGNUM *d,
176 \&         BN_CTX *ctx);
177 \& int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx);
178 \& int BN_mod(BIGNUM *rem, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
179 \& int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
180 \&         BN_CTX *ctx);
181 \& int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BN_CTX *ctx);
182 \& int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
183 \&         const BIGNUM *m, BN_CTX *ctx);
184 \& int BN_gcd(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
185 .Ve
186 .Vb 5
187 \& int BN_add_word(BIGNUM *a, BN_ULONG w);
188 \& int BN_sub_word(BIGNUM *a, BN_ULONG w);
189 \& int BN_mul_word(BIGNUM *a, BN_ULONG w);
190 \& BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w);
191 \& BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w);
192 .Ve
193 .Vb 6
194 \& int BN_cmp(BIGNUM *a, BIGNUM *b);
195 \& int BN_ucmp(BIGNUM *a, BIGNUM *b);
196 \& int BN_is_zero(BIGNUM *a);
197 \& int BN_is_one(BIGNUM *a);
198 \& int BN_is_word(BIGNUM *a, BN_ULONG w);
199 \& int BN_is_odd(BIGNUM *a);
200 .Ve
201 .Vb 5
202 \& int BN_zero(BIGNUM *a);
203 \& int BN_one(BIGNUM *a);
204 \& BIGNUM *BN_value_one(void);
205 \& int BN_set_word(BIGNUM *a, unsigned long w);
206 \& unsigned long BN_get_word(BIGNUM *a);
207 .Ve
208 .Vb 4
209 \& int BN_rand(BIGNUM *rnd, int bits, int top, int bottom);
210 \& int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom);
211 \& int BN_rand_range(BIGNUM *rnd, BIGNUM *range);
212 \& int BN_pseudo_rand_range(BIGNUM *rnd, BIGNUM *range);
213 .Ve
214 .Vb 4
215 \& BIGNUM *BN_generate_prime(BIGNUM *ret, int bits,int safe, BIGNUM *add,
216 \&         BIGNUM *rem, void (*callback)(int, int, void *), void *cb_arg);
217 \& int BN_is_prime(const BIGNUM *p, int nchecks,
218 \&         void (*callback)(int, int, void *), BN_CTX *ctx, void *cb_arg);
219 .Ve
220 .Vb 8
221 \& int BN_set_bit(BIGNUM *a, int n);
222 \& int BN_clear_bit(BIGNUM *a, int n);
223 \& int BN_is_bit_set(const BIGNUM *a, int n);
224 \& int BN_mask_bits(BIGNUM *a, int n);
225 \& int BN_lshift(BIGNUM *r, const BIGNUM *a, int n);
226 \& int BN_lshift1(BIGNUM *r, BIGNUM *a);
227 \& int BN_rshift(BIGNUM *r, BIGNUM *a, int n);
228 \& int BN_rshift1(BIGNUM *r, BIGNUM *a);
229 .Ve
230 .Vb 10
231 \& int BN_bn2bin(const BIGNUM *a, unsigned char *to);
232 \& BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret);
233 \& char *BN_bn2hex(const BIGNUM *a);
234 \& char *BN_bn2dec(const BIGNUM *a);
235 \& int BN_hex2bn(BIGNUM **a, const char *str);
236 \& int BN_dec2bn(BIGNUM **a, const char *str);
237 \& int BN_print(BIO *fp, const BIGNUM *a);
238 \& int BN_print_fp(FILE *fp, const BIGNUM *a);
239 \& int BN_bn2mpi(const BIGNUM *a, unsigned char *to);
240 \& BIGNUM *BN_mpi2bn(unsigned char *s, int len, BIGNUM *ret);
241 .Ve
242 .Vb 2
243 \& BIGNUM *BN_mod_inverse(BIGNUM *r, BIGNUM *a, const BIGNUM *n,
244 \&     BN_CTX *ctx);
245 .Ve
246 .Vb 6
247 \& BN_RECP_CTX *BN_RECP_CTX_new(void);
248 \& void BN_RECP_CTX_init(BN_RECP_CTX *recp);
249 \& void BN_RECP_CTX_free(BN_RECP_CTX *recp);
250 \& int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *m, BN_CTX *ctx);
251 \& int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *a, BIGNUM *b,
252 \&        BN_RECP_CTX *recp, BN_CTX *ctx);
253 .Ve
254 .Vb 11
255 \& BN_MONT_CTX *BN_MONT_CTX_new(void);
256 \& void BN_MONT_CTX_init(BN_MONT_CTX *ctx);
257 \& void BN_MONT_CTX_free(BN_MONT_CTX *mont);
258 \& int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *m, BN_CTX *ctx);
259 \& BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from);
260 \& int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b,
261 \&         BN_MONT_CTX *mont, BN_CTX *ctx);
262 \& int BN_from_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont,
263 \&         BN_CTX *ctx);
264 \& int BN_to_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont,
265 \&         BN_CTX *ctx);
266 .Ve
267 .SH "DESCRIPTION"
268 .IX Header "DESCRIPTION"
269 This library performs arithmetic operations on integers of arbitrary
270 size. It was written for use in public key cryptography, such as \s-1RSA\s0
271 and Diffie-Hellman.
272 .PP
273 It uses dynamic memory allocation for storing its data structures.
274 That means that there is no limit on the size of the numbers
275 manipulated by these functions, but return values must always be
276 checked in case a memory allocation error has occurred.
277 .PP
278 The basic object in this library is a \fB\s-1BIGNUM\s0\fR. It is used to hold a
279 single large integer. This type should be considered opaque and fields
280 should not be modified or accessed directly.
281 .PP
282 The creation of \fB\s-1BIGNUM\s0\fR objects is described in BN_new(3);
283 BN_add(3) describes most of the arithmetic operations.
284 Comparison is described in BN_cmp(3); BN_zero(3)
285 describes certain assignments, BN_rand(3) the generation of
286 random numbers, BN_generate_prime(3) deals with prime
287 numbers and BN_set_bit(3) with bit operations. The conversion
288 of \fB\s-1BIGNUM\s0\fRs to external formats is described in BN_bn2bin(3).
289 .SH "SEE ALSO"
290 .IX Header "SEE ALSO"
291 bn_internal(3),
292 dh(3), err(3), rand(3), rsa(3),
293 BN_new(3), BN_CTX_new(3),
294 BN_copy(3), BN_num_bytes(3),
295 BN_add(3), BN_add_word(3),
296 BN_cmp(3), BN_zero(3), BN_rand(3),
297 BN_generate_prime(3), BN_set_bit(3),
298 BN_bn2bin(3), BN_mod_inverse(3),
299 BN_mod_mul_reciprocal(3),
300 BN_mod_mul_montgomery(3)