| 1 | .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32 |
| 2 | .\" |
| 3 | .\" Standard preamble: |
| 4 | .\" ======================================================================== |
| 5 | .de Sh \" Subsection heading |
| 6 | .br |
| 7 | .if t .Sp |
| 8 | .ne 5 |
| 9 | .PP |
| 10 | \fB\\$1\fR |
| 11 | .PP |
| 12 | .. |
| 13 | .de Sp \" Vertical space (when we can't use .PP) |
| 14 | .if t .sp .5v |
| 15 | .if n .sp |
| 16 | .. |
| 17 | .de Vb \" Begin verbatim text |
| 18 | .ft CW |
| 19 | .nf |
| 20 | .ne \\$1 |
| 21 | .. |
| 22 | .de Ve \" End verbatim text |
| 23 | .ft R |
| 24 | .fi |
| 25 | .. |
| 26 | .\" Set up some character translations and predefined strings. \*(-- will |
| 27 | .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left |
| 28 | .\" double quote, and \*(R" will give a right double quote. | will give a |
| 29 | .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to |
| 30 | .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' |
| 31 | .\" expand to `' in nroff, nothing in troff, for use with C<>. |
| 32 | .tr \(*W-|\(bv\*(Tr |
| 33 | .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' |
| 34 | .ie n \{\ |
| 35 | . ds -- \(*W- |
| 36 | . ds PI pi |
| 37 | . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch |
| 38 | . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch |
| 39 | . ds L" "" |
| 40 | . ds R" "" |
| 41 | . ds C` "" |
| 42 | . ds C' "" |
| 43 | 'br\} |
| 44 | .el\{\ |
| 45 | . ds -- \|\(em\| |
| 46 | . ds PI \(*p |
| 47 | . ds L" `` |
| 48 | . ds R" '' |
| 49 | 'br\} |
| 50 | .\" |
| 51 | .\" If the F register is turned on, we'll generate index entries on stderr for |
| 52 | .\" titles (.TH), headers (.SH), subsections (.Sh), 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. |
| 55 | .if \nF \{\ |
| 56 | . de IX |
| 57 | . tm Index:\\$1\t\\n%\t"\\$2" |
| 58 | .. |
| 59 | . nr % 0 |
| 60 | . rr F |
| 61 | .\} |
| 62 | .\" |
| 63 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 64 | .\" way too many mistakes in technical documents. |
| 65 | .hy 0 |
| 66 | .if n .na |
| 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 3" |
| 132 | .TH bn 3 "2008-09-06" "0.9.8h" "OpenSSL" |
| 133 | .SH "NAME" |
| 134 | bn \- multiprecision integer arithmetics |
| 135 | .SH "SYNOPSIS" |
| 136 | .IX Header "SYNOPSIS" |
| 137 | .Vb 1 |
| 138 | \& #include <openssl/bn.h> |
| 139 | .Ve |
| 140 | .PP |
| 141 | .Vb 5 |
| 142 | \& BIGNUM *BN_new(void); |
| 143 | \& void BN_free(BIGNUM *a); |
| 144 | \& void BN_init(BIGNUM *); |
| 145 | \& void BN_clear(BIGNUM *a); |
| 146 | \& void BN_clear_free(BIGNUM *a); |
| 147 | .Ve |
| 148 | .PP |
| 149 | .Vb 3 |
| 150 | \& BN_CTX *BN_CTX_new(void); |
| 151 | \& void BN_CTX_init(BN_CTX *c); |
| 152 | \& void BN_CTX_free(BN_CTX *c); |
| 153 | .Ve |
| 154 | .PP |
| 155 | .Vb 2 |
| 156 | \& BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b); |
| 157 | \& BIGNUM *BN_dup(const BIGNUM *a); |
| 158 | .Ve |
| 159 | .PP |
| 160 | .Vb 1 |
| 161 | \& BIGNUM *BN_swap(BIGNUM *a, BIGNUM *b); |
| 162 | .Ve |
| 163 | .PP |
| 164 | .Vb 3 |
| 165 | \& int BN_num_bytes(const BIGNUM *a); |
| 166 | \& int BN_num_bits(const BIGNUM *a); |
| 167 | \& int BN_num_bits_word(BN_ULONG w); |
| 168 | .Ve |
| 169 | .PP |
| 170 | .Vb 2 |
| 171 | \& void BN_set_negative(BIGNUM *a, int n); |
| 172 | \& int BN_is_negative(const BIGNUM *a); |
| 173 | .Ve |
| 174 | .PP |
| 175 | .Vb 19 |
| 176 | \& int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); |
| 177 | \& int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); |
| 178 | \& int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx); |
| 179 | \& int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx); |
| 180 | \& int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *a, const BIGNUM *d, |
| 181 | \& BN_CTX *ctx); |
| 182 | \& int BN_mod(BIGNUM *rem, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx); |
| 183 | \& int BN_nnmod(BIGNUM *rem, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx); |
| 184 | \& int BN_mod_add(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m, |
| 185 | \& BN_CTX *ctx); |
| 186 | \& int BN_mod_sub(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m, |
| 187 | \& BN_CTX *ctx); |
| 188 | \& int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m, |
| 189 | \& BN_CTX *ctx); |
| 190 | \& int BN_mod_sqr(BIGNUM *ret, BIGNUM *a, const BIGNUM *m, BN_CTX *ctx); |
| 191 | \& int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BN_CTX *ctx); |
| 192 | \& int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p, |
| 193 | \& const BIGNUM *m, BN_CTX *ctx); |
| 194 | \& int BN_gcd(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx); |
| 195 | .Ve |
| 196 | .PP |
| 197 | .Vb 5 |
| 198 | \& int BN_add_word(BIGNUM *a, BN_ULONG w); |
| 199 | \& int BN_sub_word(BIGNUM *a, BN_ULONG w); |
| 200 | \& int BN_mul_word(BIGNUM *a, BN_ULONG w); |
| 201 | \& BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w); |
| 202 | \& BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w); |
| 203 | .Ve |
| 204 | .PP |
| 205 | .Vb 6 |
| 206 | \& int BN_cmp(BIGNUM *a, BIGNUM *b); |
| 207 | \& int BN_ucmp(BIGNUM *a, BIGNUM *b); |
| 208 | \& int BN_is_zero(BIGNUM *a); |
| 209 | \& int BN_is_one(BIGNUM *a); |
| 210 | \& int BN_is_word(BIGNUM *a, BN_ULONG w); |
| 211 | \& int BN_is_odd(BIGNUM *a); |
| 212 | .Ve |
| 213 | .PP |
| 214 | .Vb 5 |
| 215 | \& int BN_zero(BIGNUM *a); |
| 216 | \& int BN_one(BIGNUM *a); |
| 217 | \& const BIGNUM *BN_value_one(void); |
| 218 | \& int BN_set_word(BIGNUM *a, unsigned long w); |
| 219 | \& unsigned long BN_get_word(BIGNUM *a); |
| 220 | .Ve |
| 221 | .PP |
| 222 | .Vb 4 |
| 223 | \& int BN_rand(BIGNUM *rnd, int bits, int top, int bottom); |
| 224 | \& int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom); |
| 225 | \& int BN_rand_range(BIGNUM *rnd, BIGNUM *range); |
| 226 | \& int BN_pseudo_rand_range(BIGNUM *rnd, BIGNUM *range); |
| 227 | .Ve |
| 228 | .PP |
| 229 | .Vb 4 |
| 230 | \& BIGNUM *BN_generate_prime(BIGNUM *ret, int bits,int safe, BIGNUM *add, |
| 231 | \& BIGNUM *rem, void (*callback)(int, int, void *), void *cb_arg); |
| 232 | \& int BN_is_prime(const BIGNUM *p, int nchecks, |
| 233 | \& void (*callback)(int, int, void *), BN_CTX *ctx, void *cb_arg); |
| 234 | .Ve |
| 235 | .PP |
| 236 | .Vb 8 |
| 237 | \& int BN_set_bit(BIGNUM *a, int n); |
| 238 | \& int BN_clear_bit(BIGNUM *a, int n); |
| 239 | \& int BN_is_bit_set(const BIGNUM *a, int n); |
| 240 | \& int BN_mask_bits(BIGNUM *a, int n); |
| 241 | \& int BN_lshift(BIGNUM *r, const BIGNUM *a, int n); |
| 242 | \& int BN_lshift1(BIGNUM *r, BIGNUM *a); |
| 243 | \& int BN_rshift(BIGNUM *r, BIGNUM *a, int n); |
| 244 | \& int BN_rshift1(BIGNUM *r, BIGNUM *a); |
| 245 | .Ve |
| 246 | .PP |
| 247 | .Vb 10 |
| 248 | \& int BN_bn2bin(const BIGNUM *a, unsigned char *to); |
| 249 | \& BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret); |
| 250 | \& char *BN_bn2hex(const BIGNUM *a); |
| 251 | \& char *BN_bn2dec(const BIGNUM *a); |
| 252 | \& int BN_hex2bn(BIGNUM **a, const char *str); |
| 253 | \& int BN_dec2bn(BIGNUM **a, const char *str); |
| 254 | \& int BN_print(BIO *fp, const BIGNUM *a); |
| 255 | \& int BN_print_fp(FILE *fp, const BIGNUM *a); |
| 256 | \& int BN_bn2mpi(const BIGNUM *a, unsigned char *to); |
| 257 | \& BIGNUM *BN_mpi2bn(unsigned char *s, int len, BIGNUM *ret); |
| 258 | .Ve |
| 259 | .PP |
| 260 | .Vb 2 |
| 261 | \& BIGNUM *BN_mod_inverse(BIGNUM *r, BIGNUM *a, const BIGNUM *n, |
| 262 | \& BN_CTX *ctx); |
| 263 | .Ve |
| 264 | .PP |
| 265 | .Vb 6 |
| 266 | \& BN_RECP_CTX *BN_RECP_CTX_new(void); |
| 267 | \& void BN_RECP_CTX_init(BN_RECP_CTX *recp); |
| 268 | \& void BN_RECP_CTX_free(BN_RECP_CTX *recp); |
| 269 | \& int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *m, BN_CTX *ctx); |
| 270 | \& int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *a, BIGNUM *b, |
| 271 | \& BN_RECP_CTX *recp, BN_CTX *ctx); |
| 272 | .Ve |
| 273 | .PP |
| 274 | .Vb 11 |
| 275 | \& BN_MONT_CTX *BN_MONT_CTX_new(void); |
| 276 | \& void BN_MONT_CTX_init(BN_MONT_CTX *ctx); |
| 277 | \& void BN_MONT_CTX_free(BN_MONT_CTX *mont); |
| 278 | \& int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *m, BN_CTX *ctx); |
| 279 | \& BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from); |
| 280 | \& int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b, |
| 281 | \& BN_MONT_CTX *mont, BN_CTX *ctx); |
| 282 | \& int BN_from_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont, |
| 283 | \& BN_CTX *ctx); |
| 284 | \& int BN_to_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont, |
| 285 | \& BN_CTX *ctx); |
| 286 | .Ve |
| 287 | .PP |
| 288 | .Vb 19 |
| 289 | \& BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, |
| 290 | \& BIGNUM *mod); |
| 291 | \& void BN_BLINDING_free(BN_BLINDING *b); |
| 292 | \& int BN_BLINDING_update(BN_BLINDING *b,BN_CTX *ctx); |
| 293 | \& int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx); |
| 294 | \& int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx); |
| 295 | \& int BN_BLINDING_convert_ex(BIGNUM *n, BIGNUM *r, BN_BLINDING *b, |
| 296 | \& BN_CTX *ctx); |
| 297 | \& int BN_BLINDING_invert_ex(BIGNUM *n,const BIGNUM *r,BN_BLINDING *b, |
| 298 | \& BN_CTX *ctx); |
| 299 | \& unsigned long BN_BLINDING_get_thread_id(const BN_BLINDING *); |
| 300 | \& void BN_BLINDING_set_thread_id(BN_BLINDING *, unsigned long); |
| 301 | \& unsigned long BN_BLINDING_get_flags(const BN_BLINDING *); |
| 302 | \& void BN_BLINDING_set_flags(BN_BLINDING *, unsigned long); |
| 303 | \& BN_BLINDING *BN_BLINDING_create_param(BN_BLINDING *b, |
| 304 | \& const BIGNUM *e, BIGNUM *m, BN_CTX *ctx, |
| 305 | \& int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, |
| 306 | \& const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx), |
| 307 | \& BN_MONT_CTX *m_ctx); |
| 308 | .Ve |
| 309 | .SH "DESCRIPTION" |
| 310 | .IX Header "DESCRIPTION" |
| 311 | This library performs arithmetic operations on integers of arbitrary |
| 312 | size. It was written for use in public key cryptography, such as \s-1RSA\s0 |
| 313 | and Diffie\-Hellman. |
| 314 | .PP |
| 315 | It uses dynamic memory allocation for storing its data structures. |
| 316 | That means that there is no limit on the size of the numbers |
| 317 | manipulated by these functions, but return values must always be |
| 318 | checked in case a memory allocation error has occurred. |
| 319 | .PP |
| 320 | The basic object in this library is a \fB\s-1BIGNUM\s0\fR. It is used to hold a |
| 321 | single large integer. This type should be considered opaque and fields |
| 322 | should not be modified or accessed directly. |
| 323 | .PP |
| 324 | The creation of \fB\s-1BIGNUM\s0\fR objects is described in \fIBN_new\fR\|(3); |
| 325 | \&\fIBN_add\fR\|(3) describes most of the arithmetic operations. |
| 326 | Comparison is described in \fIBN_cmp\fR\|(3); \fIBN_zero\fR\|(3) |
| 327 | describes certain assignments, \fIBN_rand\fR\|(3) the generation of |
| 328 | random numbers, \fIBN_generate_prime\fR\|(3) deals with prime |
| 329 | numbers and \fIBN_set_bit\fR\|(3) with bit operations. The conversion |
| 330 | of \fB\s-1BIGNUM\s0\fRs to external formats is described in \fIBN_bn2bin\fR\|(3). |
| 331 | .SH "SEE ALSO" |
| 332 | .IX Header "SEE ALSO" |
| 333 | \&\fIbn_internal\fR\|(3), |
| 334 | \&\fIdh\fR\|(3), \fIerr\fR\|(3), \fIrand\fR\|(3), \fIrsa\fR\|(3), |
| 335 | \&\fIBN_new\fR\|(3), \fIBN_CTX_new\fR\|(3), |
| 336 | \&\fIBN_copy\fR\|(3), \fIBN_swap\fR\|(3), \fIBN_num_bytes\fR\|(3), |
| 337 | \&\fIBN_add\fR\|(3), \fIBN_add_word\fR\|(3), |
| 338 | \&\fIBN_cmp\fR\|(3), \fIBN_zero\fR\|(3), \fIBN_rand\fR\|(3), |
| 339 | \&\fIBN_generate_prime\fR\|(3), \fIBN_set_bit\fR\|(3), |
| 340 | \&\fIBN_bn2bin\fR\|(3), \fIBN_mod_inverse\fR\|(3), |
| 341 | \&\fIBN_mod_mul_reciprocal\fR\|(3), |
| 342 | \&\fIBN_mod_mul_montgomery\fR\|(3), |
| 343 | \&\fIBN_BLINDING_new\fR\|(3) |