1 .\" $NetBSD: openssl_bn.3,v 1.14 2015/06/12 17:01:14 christos Exp $
3 .\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28)
6 .\" ========================================================================
7 .de Sp \" Vertical space (when we can't use .PP)
11 .de Vb \" Begin verbatim text
16 .de Ve \" End verbatim text
20 .\" Set up some character translations and predefined strings. \*(-- will
21 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
22 .\" double quote, and \*(R" will give a right double quote. \*(C+ will
23 .\" give a nicer C++. Capital omega is used to do unbreakable dashes and
24 .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
25 .\" nothing in troff, for use with C<>.
27 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
31 . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
32 . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
47 .\" Escape single quotes in literal strings from groff's Unicode transform.
51 .\" If the F register is turned on, we'll generate index entries on stderr for
52 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
53 .\" entries marked with X<> in POD. Of course, you'll have to process the
54 .\" output yourself in some meaningful fashion.
56 .\" Avoid warning from groff about undefined register 'F'.
60 .if \n(.g .if rF .nr rF 1
61 .if (\n(rF:(\n(.g==0)) \{
64 . tm Index:\\$1\t\\n%\t"\\$2"
74 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
75 .\" Fear. Run. Save yourself. No user-serviceable parts.
76 . \" fudge factors for nroff and troff
85 . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
91 . \" simple accents for nroff and troff
101 . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
102 . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
103 . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
104 . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
105 . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
106 . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
108 . \" troff and (daisy-wheel) nroff accents
109 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
110 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
111 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
112 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
113 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
114 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
115 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
116 .ds ae a\h'-(\w'a'u*4/10)'e
117 .ds Ae A\h'-(\w'A'u*4/10)'E
118 . \" corrections for vroff
119 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
120 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
121 . \" for low resolution devices (crt and lpr)
122 .if \n(.H>23 .if \n(.V>19 \
135 .\" ========================================================================
138 .TH bn 3 "2009-07-19" "1.0.1n" "OpenSSL"
139 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
140 .\" way too many mistakes in technical documents.
144 bn \- multiprecision integer arithmetics
148 .IX Header "SYNOPSIS"
150 \& #include <openssl/bn.h>
152 \& BIGNUM *BN_new(void);
153 \& void BN_free(BIGNUM *a);
154 \& void BN_init(BIGNUM *);
155 \& void BN_clear(BIGNUM *a);
156 \& void BN_clear_free(BIGNUM *a);
158 \& BN_CTX *BN_CTX_new(void);
159 \& void BN_CTX_init(BN_CTX *c);
160 \& void BN_CTX_free(BN_CTX *c);
162 \& BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b);
163 \& BIGNUM *BN_dup(const BIGNUM *a);
165 \& BIGNUM *BN_swap(BIGNUM *a, BIGNUM *b);
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);
171 \& void BN_set_negative(BIGNUM *a, int n);
172 \& int BN_is_negative(const BIGNUM *a);
174 \& int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
175 \& int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
176 \& int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
177 \& int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx);
178 \& int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *a, const BIGNUM *d,
180 \& int BN_mod(BIGNUM *rem, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
181 \& int BN_nnmod(BIGNUM *rem, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
182 \& int BN_mod_add(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
184 \& int BN_mod_sub(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
186 \& int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
188 \& int BN_mod_sqr(BIGNUM *ret, BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
189 \& int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BN_CTX *ctx);
190 \& int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
191 \& const BIGNUM *m, BN_CTX *ctx);
192 \& int BN_gcd(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
194 \& int BN_add_word(BIGNUM *a, BN_ULONG w);
195 \& int BN_sub_word(BIGNUM *a, BN_ULONG w);
196 \& int BN_mul_word(BIGNUM *a, BN_ULONG w);
197 \& BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w);
198 \& BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w);
200 \& int BN_cmp(BIGNUM *a, BIGNUM *b);
201 \& int BN_ucmp(BIGNUM *a, BIGNUM *b);
202 \& int BN_is_zero(BIGNUM *a);
203 \& int BN_is_one(BIGNUM *a);
204 \& int BN_is_word(BIGNUM *a, BN_ULONG w);
205 \& int BN_is_odd(BIGNUM *a);
207 \& int BN_zero(BIGNUM *a);
208 \& int BN_one(BIGNUM *a);
209 \& const BIGNUM *BN_value_one(void);
210 \& int BN_set_word(BIGNUM *a, unsigned long w);
211 \& unsigned long BN_get_word(BIGNUM *a);
213 \& int BN_rand(BIGNUM *rnd, int bits, int top, int bottom);
214 \& int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom);
215 \& int BN_rand_range(BIGNUM *rnd, BIGNUM *range);
216 \& int BN_pseudo_rand_range(BIGNUM *rnd, BIGNUM *range);
218 \& BIGNUM *BN_generate_prime(BIGNUM *ret, int bits,int safe, BIGNUM *add,
219 \& BIGNUM *rem, void (*callback)(int, int, void *), void *cb_arg);
220 \& int BN_is_prime(const BIGNUM *p, int nchecks,
221 \& void (*callback)(int, int, void *), BN_CTX *ctx, void *cb_arg);
223 \& int BN_set_bit(BIGNUM *a, int n);
224 \& int BN_clear_bit(BIGNUM *a, int n);
225 \& int BN_is_bit_set(const BIGNUM *a, int n);
226 \& int BN_mask_bits(BIGNUM *a, int n);
227 \& int BN_lshift(BIGNUM *r, const BIGNUM *a, int n);
228 \& int BN_lshift1(BIGNUM *r, BIGNUM *a);
229 \& int BN_rshift(BIGNUM *r, BIGNUM *a, int n);
230 \& int BN_rshift1(BIGNUM *r, BIGNUM *a);
232 \& int BN_bn2bin(const BIGNUM *a, unsigned char *to);
233 \& BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret);
234 \& char *BN_bn2hex(const BIGNUM *a);
235 \& char *BN_bn2dec(const BIGNUM *a);
236 \& int BN_hex2bn(BIGNUM **a, const char *str);
237 \& int BN_dec2bn(BIGNUM **a, const char *str);
238 \& int BN_print(BIO *fp, const BIGNUM *a);
239 \& int BN_print_fp(FILE *fp, const BIGNUM *a);
240 \& int BN_bn2mpi(const BIGNUM *a, unsigned char *to);
241 \& BIGNUM *BN_mpi2bn(unsigned char *s, int len, BIGNUM *ret);
243 \& BIGNUM *BN_mod_inverse(BIGNUM *r, BIGNUM *a, const BIGNUM *n,
246 \& BN_RECP_CTX *BN_RECP_CTX_new(void);
247 \& void BN_RECP_CTX_init(BN_RECP_CTX *recp);
248 \& void BN_RECP_CTX_free(BN_RECP_CTX *recp);
249 \& int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *m, BN_CTX *ctx);
250 \& int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *a, BIGNUM *b,
251 \& BN_RECP_CTX *recp, BN_CTX *ctx);
253 \& BN_MONT_CTX *BN_MONT_CTX_new(void);
254 \& void BN_MONT_CTX_init(BN_MONT_CTX *ctx);
255 \& void BN_MONT_CTX_free(BN_MONT_CTX *mont);
256 \& int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *m, BN_CTX *ctx);
257 \& BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from);
258 \& int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b,
259 \& BN_MONT_CTX *mont, BN_CTX *ctx);
260 \& int BN_from_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont,
262 \& int BN_to_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont,
265 \& BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai,
267 \& void BN_BLINDING_free(BN_BLINDING *b);
268 \& int BN_BLINDING_update(BN_BLINDING *b,BN_CTX *ctx);
269 \& int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx);
270 \& int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx);
271 \& int BN_BLINDING_convert_ex(BIGNUM *n, BIGNUM *r, BN_BLINDING *b,
273 \& int BN_BLINDING_invert_ex(BIGNUM *n,const BIGNUM *r,BN_BLINDING *b,
275 \& unsigned long BN_BLINDING_get_thread_id(const BN_BLINDING *);
276 \& void BN_BLINDING_set_thread_id(BN_BLINDING *, unsigned long);
277 \& unsigned long BN_BLINDING_get_flags(const BN_BLINDING *);
278 \& void BN_BLINDING_set_flags(BN_BLINDING *, unsigned long);
279 \& BN_BLINDING *BN_BLINDING_create_param(BN_BLINDING *b,
280 \& const BIGNUM *e, BIGNUM *m, BN_CTX *ctx,
281 \& int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
282 \& const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx),
283 \& BN_MONT_CTX *m_ctx);
286 .IX Header "DESCRIPTION"
287 This library performs arithmetic operations on integers of arbitrary
288 size. It was written for use in public key cryptography, such as \s-1RSA\s0
291 It uses dynamic memory allocation for storing its data structures.
292 That means that there is no limit on the size of the numbers
293 manipulated by these functions, but return values must always be
294 checked in case a memory allocation error has occurred.
296 The basic object in this library is a \fB\s-1BIGNUM\s0\fR. It is used to hold a
297 single large integer. This type should be considered opaque and fields
298 should not be modified or accessed directly.
300 The creation of \fB\s-1BIGNUM\s0\fR objects is described in \fIBN_new\fR\|(3);
301 \&\fIBN_add\fR\|(3) describes most of the arithmetic operations.
302 Comparison is described in \fIBN_cmp\fR\|(3); \fIBN_zero\fR\|(3)
303 describes certain assignments, \fIBN_rand\fR\|(3) the generation of
304 random numbers, \fIBN_generate_prime\fR\|(3) deals with prime
305 numbers and \fIBN_set_bit\fR\|(3) with bit operations. The conversion
306 of \fB\s-1BIGNUM\s0\fRs to external formats is described in \fIBN_bn2bin\fR\|(3).
308 .IX Header "SEE ALSO"
309 \&\fIopenssl_bn_internal\fR\|(3),
310 \&\fIopenssl_dh\fR\|(3), \fIopenssl_err\fR\|(3), \fIopenssl_rand\fR\|(3), \fIopenssl_rsa\fR\|(3),
311 \&\fIBN_new\fR\|(3), \fIBN_CTX_new\fR\|(3),
312 \&\fIBN_copy\fR\|(3), \fIBN_swap\fR\|(3), \fIBN_num_bytes\fR\|(3),
313 \&\fIBN_add\fR\|(3), \fIBN_add_word\fR\|(3),
314 \&\fIBN_cmp\fR\|(3), \fIBN_zero\fR\|(3), \fIBN_rand\fR\|(3),
315 \&\fIBN_generate_prime\fR\|(3), \fIBN_set_bit\fR\|(3),
316 \&\fIBN_bn2bin\fR\|(3), \fIBN_mod_inverse\fR\|(3),
317 \&\fIBN_mod_mul_reciprocal\fR\|(3),
318 \&\fIBN_mod_mul_montgomery\fR\|(3),
319 \&\fIBN_BLINDING_new\fR\|(3)