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