diff options
Diffstat (limited to 'src/lib/libcrypto/bn/bn.h')
-rw-r--r-- | src/lib/libcrypto/bn/bn.h | 290 |
1 files changed, 185 insertions, 105 deletions
diff --git a/src/lib/libcrypto/bn/bn.h b/src/lib/libcrypto/bn/bn.h index f935e1ca79..1eaf879553 100644 --- a/src/lib/libcrypto/bn/bn.h +++ b/src/lib/libcrypto/bn/bn.h | |||
@@ -59,38 +59,39 @@ | |||
59 | #ifndef HEADER_BN_H | 59 | #ifndef HEADER_BN_H |
60 | #define HEADER_BN_H | 60 | #define HEADER_BN_H |
61 | 61 | ||
62 | #ifndef WIN16 | 62 | #include <openssl/e_os2.h> |
63 | #ifndef OPENSSL_NO_FP_API | ||
63 | #include <stdio.h> /* FILE */ | 64 | #include <stdio.h> /* FILE */ |
64 | #endif | 65 | #endif |
65 | #include <openssl/opensslconf.h> | ||
66 | 66 | ||
67 | #ifdef __cplusplus | 67 | #ifdef __cplusplus |
68 | extern "C" { | 68 | extern "C" { |
69 | #endif | 69 | #endif |
70 | 70 | ||
71 | #ifdef VMS | 71 | #ifdef OPENSSL_SYS_VMS |
72 | #undef BN_LLONG /* experimental, so far... */ | 72 | #undef BN_LLONG /* experimental, so far... */ |
73 | #endif | 73 | #endif |
74 | 74 | ||
75 | #define BN_MUL_COMBA | 75 | #define BN_MUL_COMBA |
76 | #define BN_SQR_COMBA | 76 | #define BN_SQR_COMBA |
77 | #define BN_RECURSION | 77 | #define BN_RECURSION |
78 | #define RECP_MUL_MOD | ||
79 | #define MONT_MUL_MOD | ||
80 | 78 | ||
81 | /* This next option uses the C libraries (2 word)/(1 word) function. | 79 | /* This next option uses the C libraries (2 word)/(1 word) function. |
82 | * If it is not defined, I use my C version (which is slower). | 80 | * If it is not defined, I use my C version (which is slower). |
83 | * The reason for this flag is that when the particular C compiler | 81 | * The reason for this flag is that when the particular C compiler |
84 | * library routine is used, and the library is linked with a different | 82 | * library routine is used, and the library is linked with a different |
85 | * compiler, the library is missing. This mostly happens when the | 83 | * compiler, the library is missing. This mostly happens when the |
86 | * library is built with gcc and then linked using nornal cc. This would | 84 | * library is built with gcc and then linked using normal cc. This would |
87 | * be a common occurance because gcc normally produces code that is | 85 | * be a common occurrence because gcc normally produces code that is |
88 | * 2 times faster than system compilers for the big number stuff. | 86 | * 2 times faster than system compilers for the big number stuff. |
89 | * For machines with only one compiler (or shared libraries), this should | 87 | * For machines with only one compiler (or shared libraries), this should |
90 | * be on. Again this in only really a problem on machines | 88 | * be on. Again this in only really a problem on machines |
91 | * using "long long's", are 32bit, and are not using my assember code. */ | 89 | * using "long long's", are 32bit, and are not using my assembler code. */ |
92 | #if defined(MSDOS) || defined(WINDOWS) || defined(linux) | 90 | #if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WINDOWS) || \ |
93 | #define BN_DIV2W | 91 | defined(OPENSSL_SYS_WIN32) || defined(linux) |
92 | # ifndef BN_DIV2W | ||
93 | # define BN_DIV2W | ||
94 | # endif | ||
94 | #endif | 95 | #endif |
95 | 96 | ||
96 | /* assuming long is 64bit - this is the DEC Alpha | 97 | /* assuming long is 64bit - this is the DEC Alpha |
@@ -118,8 +119,8 @@ extern "C" { | |||
118 | 119 | ||
119 | /* This is where the long long data type is 64 bits, but long is 32. | 120 | /* This is where the long long data type is 64 bits, but long is 32. |
120 | * For machines where there are 64bit registers, this is the mode to use. | 121 | * For machines where there are 64bit registers, this is the mode to use. |
121 | * IRIX, on R4000 and above should use this mode, along with the relevent | 122 | * IRIX, on R4000 and above should use this mode, along with the relevant |
122 | * assember code :-). Do NOT define BN_LLONG. | 123 | * assembler code :-). Do NOT define BN_LLONG. |
123 | */ | 124 | */ |
124 | #ifdef SIXTY_FOUR_BIT | 125 | #ifdef SIXTY_FOUR_BIT |
125 | #undef BN_LLONG | 126 | #undef BN_LLONG |
@@ -135,14 +136,14 @@ extern "C" { | |||
135 | #define BN_MASK2h (0xffffffff00000000LL) | 136 | #define BN_MASK2h (0xffffffff00000000LL) |
136 | #define BN_MASK2h1 (0xffffffff80000000LL) | 137 | #define BN_MASK2h1 (0xffffffff80000000LL) |
137 | #define BN_TBIT (0x8000000000000000LL) | 138 | #define BN_TBIT (0x8000000000000000LL) |
138 | #define BN_DEC_CONV (10000000000000000000LL) | 139 | #define BN_DEC_CONV (10000000000000000000ULL) |
139 | #define BN_DEC_FMT1 "%llu" | 140 | #define BN_DEC_FMT1 "%llu" |
140 | #define BN_DEC_FMT2 "%019llu" | 141 | #define BN_DEC_FMT2 "%019llu" |
141 | #define BN_DEC_NUM 19 | 142 | #define BN_DEC_NUM 19 |
142 | #endif | 143 | #endif |
143 | 144 | ||
144 | #ifdef THIRTY_TWO_BIT | 145 | #ifdef THIRTY_TWO_BIT |
145 | #if defined(WIN32) && !defined(__GNUC__) | 146 | #if defined(OPENSSL_SYS_WIN32) && !defined(__GNUC__) |
146 | #define BN_ULLONG unsigned _int64 | 147 | #define BN_ULLONG unsigned _int64 |
147 | #else | 148 | #else |
148 | #define BN_ULLONG unsigned long long | 149 | #define BN_ULLONG unsigned long long |
@@ -153,7 +154,7 @@ extern "C" { | |||
153 | #define BN_BYTES 4 | 154 | #define BN_BYTES 4 |
154 | #define BN_BITS2 32 | 155 | #define BN_BITS2 32 |
155 | #define BN_BITS4 16 | 156 | #define BN_BITS4 16 |
156 | #ifdef WIN32 | 157 | #ifdef OPENSSL_SYS_WIN32 |
157 | /* VC++ doesn't like the LL suffix */ | 158 | /* VC++ doesn't like the LL suffix */ |
158 | #define BN_MASK (0xffffffffffffffffL) | 159 | #define BN_MASK (0xffffffffffffffffL) |
159 | #else | 160 | #else |
@@ -233,19 +234,13 @@ typedef struct bignum_st | |||
233 | BN_ULONG *d; /* Pointer to an array of 'BN_BITS2' bit chunks. */ | 234 | BN_ULONG *d; /* Pointer to an array of 'BN_BITS2' bit chunks. */ |
234 | int top; /* Index of last used d +1. */ | 235 | int top; /* Index of last used d +1. */ |
235 | /* The next are internal book keeping for bn_expand. */ | 236 | /* The next are internal book keeping for bn_expand. */ |
236 | int max; /* Size of the d array. */ | 237 | int dmax; /* Size of the d array. */ |
237 | int neg; /* one if the number is negative */ | 238 | int neg; /* one if the number is negative */ |
238 | int flags; | 239 | int flags; |
239 | } BIGNUM; | 240 | } BIGNUM; |
240 | 241 | ||
241 | /* Used for temp variables */ | 242 | /* Used for temp variables (declaration hidden in bn_lcl.h) */ |
242 | #define BN_CTX_NUM 12 | 243 | typedef struct bignum_ctx BN_CTX; |
243 | typedef struct bignum_ctx | ||
244 | { | ||
245 | int tos; | ||
246 | BIGNUM bn[BN_CTX_NUM+1]; | ||
247 | int flags; | ||
248 | } BN_CTX; | ||
249 | 244 | ||
250 | typedef struct bn_blinding_st | 245 | typedef struct bn_blinding_st |
251 | { | 246 | { |
@@ -257,16 +252,15 @@ typedef struct bn_blinding_st | |||
257 | 252 | ||
258 | /* Used for montgomery multiplication */ | 253 | /* Used for montgomery multiplication */ |
259 | typedef struct bn_mont_ctx_st | 254 | typedef struct bn_mont_ctx_st |
260 | { | 255 | { |
261 | int use_word; /* 0 for word form, 1 for long form */ | 256 | int ri; /* number of bits in R */ |
262 | int ri; /* number of bits in R */ | 257 | BIGNUM RR; /* used to convert to montgomery form */ |
263 | BIGNUM RR; /* used to convert to montgomery form */ | 258 | BIGNUM N; /* The modulus */ |
264 | BIGNUM N; /* The modulus */ | 259 | BIGNUM Ni; /* R*(1/R mod N) - N*Ni = 1 |
265 | BIGNUM Ni; /* The inverse of N */ | 260 | * (Ni is only stored for bignum algorithm) */ |
266 | BN_ULONG n0; /* word form of inverse, normally only one of | 261 | BN_ULONG n0; /* least significant word of Ni */ |
267 | * Ni or n0 is defined */ | ||
268 | int flags; | 262 | int flags; |
269 | } BN_MONT_CTX; | 263 | } BN_MONT_CTX; |
270 | 264 | ||
271 | /* Used for reciprocal division/mod functions | 265 | /* Used for reciprocal division/mod functions |
272 | * It cannot be shared between threads | 266 | * It cannot be shared between threads |
@@ -280,97 +274,129 @@ typedef struct bn_recp_ctx_st | |||
280 | int flags; | 274 | int flags; |
281 | } BN_RECP_CTX; | 275 | } BN_RECP_CTX; |
282 | 276 | ||
283 | #define BN_to_montgomery(r,a,mont,ctx) BN_mod_mul_montgomery(\ | 277 | #define BN_prime_checks 0 /* default: select number of iterations |
284 | r,a,&((mont)->RR),(mont),ctx) | 278 | based on the size of the number */ |
285 | 279 | ||
286 | #define BN_prime_checks (5) | 280 | /* number of Miller-Rabin iterations for an error rate of less than 2^-80 |
281 | * for random 'b'-bit input, b >= 100 (taken from table 4.4 in the Handbook | ||
282 | * of Applied Cryptography [Menezes, van Oorschot, Vanstone; CRC Press 1996]; | ||
283 | * original paper: Damgaard, Landrock, Pomerance: Average case error estimates | ||
284 | * for the strong probable prime test. -- Math. Comp. 61 (1993) 177-194) */ | ||
285 | #define BN_prime_checks_for_size(b) ((b) >= 1300 ? 2 : \ | ||
286 | (b) >= 850 ? 3 : \ | ||
287 | (b) >= 650 ? 4 : \ | ||
288 | (b) >= 550 ? 5 : \ | ||
289 | (b) >= 450 ? 6 : \ | ||
290 | (b) >= 400 ? 7 : \ | ||
291 | (b) >= 350 ? 8 : \ | ||
292 | (b) >= 300 ? 9 : \ | ||
293 | (b) >= 250 ? 12 : \ | ||
294 | (b) >= 200 ? 15 : \ | ||
295 | (b) >= 150 ? 18 : \ | ||
296 | /* b >= 100 */ 27) | ||
287 | 297 | ||
288 | #define BN_num_bytes(a) ((BN_num_bits(a)+7)/8) | 298 | #define BN_num_bytes(a) ((BN_num_bits(a)+7)/8) |
289 | #define BN_is_word(a,w) (((a)->top == 1) && ((a)->d[0] == (BN_ULONG)(w))) | 299 | |
290 | #define BN_is_zero(a) (((a)->top == 0) || BN_is_word(a,0)) | 300 | /* Note that BN_abs_is_word does not work reliably for w == 0 */ |
291 | #define BN_is_one(a) (BN_is_word((a),1)) | 301 | #define BN_abs_is_word(a,w) (((a)->top == 1) && ((a)->d[0] == (BN_ULONG)(w))) |
292 | #define BN_is_odd(a) (((a)->top > 0) && ((a)->d[0] & 1)) | 302 | #define BN_is_zero(a) (((a)->top == 0) || BN_abs_is_word(a,0)) |
303 | #define BN_is_one(a) (BN_abs_is_word((a),1) && !(a)->neg) | ||
304 | #define BN_is_word(a,w) ((w) ? BN_abs_is_word((a),(w)) && !(a)->neg : \ | ||
305 | BN_is_zero((a))) | ||
306 | #define BN_is_odd(a) (((a)->top > 0) && ((a)->d[0] & 1)) | ||
307 | |||
293 | #define BN_one(a) (BN_set_word((a),1)) | 308 | #define BN_one(a) (BN_set_word((a),1)) |
294 | #define BN_zero(a) (BN_set_word((a),0)) | 309 | #define BN_zero(a) (BN_set_word((a),0)) |
295 | 310 | ||
296 | /*#define BN_ascii2bn(a) BN_hex2bn(a) */ | 311 | /*#define BN_ascii2bn(a) BN_hex2bn(a) */ |
297 | /*#define BN_bn2ascii(a) BN_bn2hex(a) */ | 312 | /*#define BN_bn2ascii(a) BN_bn2hex(a) */ |
298 | 313 | ||
299 | #define bn_expand(n,b) ((((((b+BN_BITS2-1))/BN_BITS2)) <= (n)->max)?\ | 314 | const BIGNUM *BN_value_one(void); |
300 | (n):bn_expand2((n),(b)/BN_BITS2+1)) | ||
301 | #define bn_wexpand(n,b) (((b) <= (n)->max)?(n):bn_expand2((n),(b))) | ||
302 | |||
303 | #define bn_fix_top(a) \ | ||
304 | { \ | ||
305 | BN_ULONG *ftl; \ | ||
306 | if ((a)->top > 0) \ | ||
307 | { \ | ||
308 | for (ftl= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) \ | ||
309 | if (*(ftl--)) break; \ | ||
310 | } \ | ||
311 | } | ||
312 | |||
313 | BIGNUM *BN_value_one(void); | ||
314 | char * BN_options(void); | 315 | char * BN_options(void); |
315 | BN_CTX *BN_CTX_new(void); | 316 | BN_CTX *BN_CTX_new(void); |
316 | void BN_CTX_init(BN_CTX *c); | 317 | void BN_CTX_init(BN_CTX *c); |
317 | void BN_CTX_free(BN_CTX *c); | 318 | void BN_CTX_free(BN_CTX *c); |
319 | void BN_CTX_start(BN_CTX *ctx); | ||
320 | BIGNUM *BN_CTX_get(BN_CTX *ctx); | ||
321 | void BN_CTX_end(BN_CTX *ctx); | ||
318 | int BN_rand(BIGNUM *rnd, int bits, int top,int bottom); | 322 | int BN_rand(BIGNUM *rnd, int bits, int top,int bottom); |
323 | int BN_pseudo_rand(BIGNUM *rnd, int bits, int top,int bottom); | ||
324 | int BN_rand_range(BIGNUM *rnd, BIGNUM *range); | ||
325 | int BN_pseudo_rand_range(BIGNUM *rnd, BIGNUM *range); | ||
319 | int BN_num_bits(const BIGNUM *a); | 326 | int BN_num_bits(const BIGNUM *a); |
320 | int BN_num_bits_word(BN_ULONG); | 327 | int BN_num_bits_word(BN_ULONG); |
321 | BIGNUM *BN_new(void); | 328 | BIGNUM *BN_new(void); |
322 | void BN_init(BIGNUM *); | 329 | void BN_init(BIGNUM *); |
323 | void BN_clear_free(BIGNUM *a); | 330 | void BN_clear_free(BIGNUM *a); |
324 | BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b); | 331 | BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b); |
332 | void BN_swap(BIGNUM *a, BIGNUM *b); | ||
325 | BIGNUM *BN_bin2bn(const unsigned char *s,int len,BIGNUM *ret); | 333 | BIGNUM *BN_bin2bn(const unsigned char *s,int len,BIGNUM *ret); |
326 | int BN_bn2bin(const BIGNUM *a, unsigned char *to); | 334 | int BN_bn2bin(const BIGNUM *a, unsigned char *to); |
327 | BIGNUM *BN_mpi2bn(unsigned char *s,int len,BIGNUM *ret); | 335 | BIGNUM *BN_mpi2bn(const unsigned char *s,int len,BIGNUM *ret); |
328 | int BN_bn2mpi(const BIGNUM *a, unsigned char *to); | 336 | int BN_bn2mpi(const BIGNUM *a, unsigned char *to); |
329 | int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); | 337 | int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); |
330 | int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); | 338 | int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); |
331 | int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); | 339 | int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); |
332 | int BN_add(BIGNUM *r, BIGNUM *a, BIGNUM *b); | 340 | int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); |
333 | int BN_mod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx); | 341 | int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx); |
342 | int BN_sqr(BIGNUM *r, const BIGNUM *a,BN_CTX *ctx); | ||
343 | |||
334 | int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, | 344 | int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, |
335 | BN_CTX *ctx); | 345 | BN_CTX *ctx); |
336 | int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b,BN_CTX *ctx); | 346 | #define BN_mod(rem,m,d,ctx) BN_div(NULL,(rem),(m),(d),(ctx)) |
337 | int BN_sqr(BIGNUM *r, BIGNUM *a,BN_CTX *ctx); | 347 | int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx); |
338 | BN_ULONG BN_mod_word(BIGNUM *a, BN_ULONG w); | 348 | int BN_mod_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx); |
349 | int BN_mod_add_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m); | ||
350 | int BN_mod_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx); | ||
351 | int BN_mod_sub_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m); | ||
352 | int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, | ||
353 | const BIGNUM *m, BN_CTX *ctx); | ||
354 | int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx); | ||
355 | int BN_mod_lshift1(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx); | ||
356 | int BN_mod_lshift1_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *m); | ||
357 | int BN_mod_lshift(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m, BN_CTX *ctx); | ||
358 | int BN_mod_lshift_quick(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m); | ||
359 | |||
360 | BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w); | ||
339 | BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w); | 361 | BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w); |
340 | int BN_mul_word(BIGNUM *a, BN_ULONG w); | 362 | int BN_mul_word(BIGNUM *a, BN_ULONG w); |
341 | int BN_add_word(BIGNUM *a, BN_ULONG w); | 363 | int BN_add_word(BIGNUM *a, BN_ULONG w); |
342 | int BN_sub_word(BIGNUM *a, BN_ULONG w); | 364 | int BN_sub_word(BIGNUM *a, BN_ULONG w); |
343 | int BN_set_word(BIGNUM *a, BN_ULONG w); | 365 | int BN_set_word(BIGNUM *a, BN_ULONG w); |
344 | BN_ULONG BN_get_word(BIGNUM *a); | 366 | BN_ULONG BN_get_word(const BIGNUM *a); |
367 | |||
345 | int BN_cmp(const BIGNUM *a, const BIGNUM *b); | 368 | int BN_cmp(const BIGNUM *a, const BIGNUM *b); |
346 | void BN_free(BIGNUM *a); | 369 | void BN_free(BIGNUM *a); |
347 | int BN_is_bit_set(const BIGNUM *a, int n); | 370 | int BN_is_bit_set(const BIGNUM *a, int n); |
348 | int BN_lshift(BIGNUM *r, const BIGNUM *a, int n); | 371 | int BN_lshift(BIGNUM *r, const BIGNUM *a, int n); |
349 | int BN_lshift1(BIGNUM *r, BIGNUM *a); | 372 | int BN_lshift1(BIGNUM *r, const BIGNUM *a); |
350 | int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p,BN_CTX *ctx); | 373 | int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,BN_CTX *ctx); |
351 | int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p, | 374 | |
352 | const BIGNUM *m,BN_CTX *ctx); | 375 | int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, |
353 | int BN_mod_exp_mont(BIGNUM *r, BIGNUM *a, const BIGNUM *p, | 376 | const BIGNUM *m,BN_CTX *ctx); |
354 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | 377 | int BN_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, |
355 | int BN_mod_exp2_mont(BIGNUM *r, BIGNUM *a1, BIGNUM *p1,BIGNUM *a2, | 378 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); |
356 | BIGNUM *p2,BIGNUM *m,BN_CTX *ctx,BN_MONT_CTX *m_ctx); | 379 | int BN_mod_exp_mont_word(BIGNUM *r, BN_ULONG a, const BIGNUM *p, |
357 | int BN_mod_exp_simple(BIGNUM *r, BIGNUM *a, BIGNUM *p, | 380 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); |
358 | BIGNUM *m,BN_CTX *ctx); | 381 | int BN_mod_exp2_mont(BIGNUM *r, const BIGNUM *a1, const BIGNUM *p1, |
382 | const BIGNUM *a2, const BIGNUM *p2,const BIGNUM *m, | ||
383 | BN_CTX *ctx,BN_MONT_CTX *m_ctx); | ||
384 | int BN_mod_exp_simple(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
385 | const BIGNUM *m,BN_CTX *ctx); | ||
386 | |||
359 | int BN_mask_bits(BIGNUM *a,int n); | 387 | int BN_mask_bits(BIGNUM *a,int n); |
360 | int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m, BN_CTX *ctx); | 388 | #ifndef OPENSSL_NO_FP_API |
361 | #ifndef WIN16 | 389 | int BN_print_fp(FILE *fp, const BIGNUM *a); |
362 | int BN_print_fp(FILE *fp, BIGNUM *a); | ||
363 | #endif | 390 | #endif |
364 | #ifdef HEADER_BIO_H | 391 | #ifdef HEADER_BIO_H |
365 | int BN_print(BIO *fp, const BIGNUM *a); | 392 | int BN_print(BIO *fp, const BIGNUM *a); |
366 | #else | 393 | #else |
367 | int BN_print(char *fp, const BIGNUM *a); | 394 | int BN_print(void *fp, const BIGNUM *a); |
368 | #endif | 395 | #endif |
369 | int BN_reciprocal(BIGNUM *r, BIGNUM *m, int len, BN_CTX *ctx); | 396 | int BN_reciprocal(BIGNUM *r, const BIGNUM *m, int len, BN_CTX *ctx); |
370 | int BN_rshift(BIGNUM *r, BIGNUM *a, int n); | 397 | int BN_rshift(BIGNUM *r, const BIGNUM *a, int n); |
371 | int BN_rshift1(BIGNUM *r, BIGNUM *a); | 398 | int BN_rshift1(BIGNUM *r, const BIGNUM *a); |
372 | void BN_clear(BIGNUM *a); | 399 | void BN_clear(BIGNUM *a); |
373 | BIGNUM *bn_expand2(BIGNUM *b, int bits); | ||
374 | BIGNUM *BN_dup(const BIGNUM *a); | 400 | BIGNUM *BN_dup(const BIGNUM *a); |
375 | int BN_ucmp(const BIGNUM *a, const BIGNUM *b); | 401 | int BN_ucmp(const BIGNUM *a, const BIGNUM *b); |
376 | int BN_set_bit(BIGNUM *a, int n); | 402 | int BN_set_bit(BIGNUM *a, int n); |
@@ -379,26 +405,30 @@ char * BN_bn2hex(const BIGNUM *a); | |||
379 | char * BN_bn2dec(const BIGNUM *a); | 405 | char * BN_bn2dec(const BIGNUM *a); |
380 | int BN_hex2bn(BIGNUM **a, const char *str); | 406 | int BN_hex2bn(BIGNUM **a, const char *str); |
381 | int BN_dec2bn(BIGNUM **a, const char *str); | 407 | int BN_dec2bn(BIGNUM **a, const char *str); |
382 | int BN_gcd(BIGNUM *r,BIGNUM *in_a,BIGNUM *in_b,BN_CTX *ctx); | 408 | int BN_gcd(BIGNUM *r,const BIGNUM *a,const BIGNUM *b,BN_CTX *ctx); |
383 | BIGNUM *BN_mod_inverse(BIGNUM *ret,BIGNUM *a, const BIGNUM *n,BN_CTX *ctx); | 409 | int BN_kronecker(const BIGNUM *a,const BIGNUM *b,BN_CTX *ctx); /* returns -2 for error */ |
384 | BIGNUM *BN_generate_prime(BIGNUM *ret,int bits,int strong,BIGNUM *add, | 410 | BIGNUM *BN_mod_inverse(BIGNUM *ret, |
385 | BIGNUM *rem,void (*callback)(int,int,void *),void *cb_arg); | 411 | const BIGNUM *a, const BIGNUM *n,BN_CTX *ctx); |
386 | int BN_is_prime(BIGNUM *p,int nchecks,void (*callback)(int,int,void *), | 412 | BIGNUM *BN_mod_sqrt(BIGNUM *ret, |
387 | BN_CTX *ctx,void *cb_arg); | 413 | const BIGNUM *a, const BIGNUM *n,BN_CTX *ctx); |
388 | void ERR_load_BN_strings(void ); | 414 | BIGNUM *BN_generate_prime(BIGNUM *ret,int bits,int safe, |
389 | 415 | const BIGNUM *add, const BIGNUM *rem, | |
390 | BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w); | 416 | void (*callback)(int,int,void *),void *cb_arg); |
391 | BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w); | 417 | int BN_is_prime(const BIGNUM *p,int nchecks, |
392 | void bn_sqr_words(BN_ULONG *rp, BN_ULONG *ap, int num); | 418 | void (*callback)(int,int,void *), |
393 | BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d); | 419 | BN_CTX *ctx,void *cb_arg); |
394 | BN_ULONG bn_add_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int num); | 420 | int BN_is_prime_fasttest(const BIGNUM *p,int nchecks, |
395 | BN_ULONG bn_sub_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int num); | 421 | void (*callback)(int,int,void *),BN_CTX *ctx,void *cb_arg, |
422 | int do_trial_division); | ||
396 | 423 | ||
397 | BN_MONT_CTX *BN_MONT_CTX_new(void ); | 424 | BN_MONT_CTX *BN_MONT_CTX_new(void ); |
398 | void BN_MONT_CTX_init(BN_MONT_CTX *ctx); | 425 | void BN_MONT_CTX_init(BN_MONT_CTX *ctx); |
399 | int BN_mod_mul_montgomery(BIGNUM *r,BIGNUM *a,BIGNUM *b,BN_MONT_CTX *mont, | 426 | int BN_mod_mul_montgomery(BIGNUM *r,const BIGNUM *a,const BIGNUM *b, |
400 | BN_CTX *ctx); | 427 | BN_MONT_CTX *mont, BN_CTX *ctx); |
401 | int BN_from_montgomery(BIGNUM *r,BIGNUM *a,BN_MONT_CTX *mont,BN_CTX *ctx); | 428 | #define BN_to_montgomery(r,a,mont,ctx) BN_mod_mul_montgomery(\ |
429 | (r),(a),&((mont)->RR),(mont),(ctx)) | ||
430 | int BN_from_montgomery(BIGNUM *r,const BIGNUM *a, | ||
431 | BN_MONT_CTX *mont, BN_CTX *ctx); | ||
402 | void BN_MONT_CTX_free(BN_MONT_CTX *mont); | 432 | void BN_MONT_CTX_free(BN_MONT_CTX *mont); |
403 | int BN_MONT_CTX_set(BN_MONT_CTX *mont,const BIGNUM *modulus,BN_CTX *ctx); | 433 | int BN_MONT_CTX_set(BN_MONT_CTX *mont,const BIGNUM *modulus,BN_CTX *ctx); |
404 | BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to,BN_MONT_CTX *from); | 434 | BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to,BN_MONT_CTX *from); |
@@ -416,18 +446,55 @@ void BN_RECP_CTX_init(BN_RECP_CTX *recp); | |||
416 | BN_RECP_CTX *BN_RECP_CTX_new(void); | 446 | BN_RECP_CTX *BN_RECP_CTX_new(void); |
417 | void BN_RECP_CTX_free(BN_RECP_CTX *recp); | 447 | void BN_RECP_CTX_free(BN_RECP_CTX *recp); |
418 | int BN_RECP_CTX_set(BN_RECP_CTX *recp,const BIGNUM *rdiv,BN_CTX *ctx); | 448 | int BN_RECP_CTX_set(BN_RECP_CTX *recp,const BIGNUM *rdiv,BN_CTX *ctx); |
419 | int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *x, BIGNUM *y, | 449 | int BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y, |
420 | BN_RECP_CTX *recp,BN_CTX *ctx); | 450 | BN_RECP_CTX *recp,BN_CTX *ctx); |
421 | int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | 451 | int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, |
422 | const BIGNUM *m, BN_CTX *ctx); | 452 | const BIGNUM *m, BN_CTX *ctx); |
423 | int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, | 453 | int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, |
424 | BN_RECP_CTX *recp, BN_CTX *ctx); | 454 | BN_RECP_CTX *recp, BN_CTX *ctx); |
455 | |||
456 | /* library internal functions */ | ||
457 | |||
458 | #define bn_expand(a,bits) ((((((bits+BN_BITS2-1))/BN_BITS2)) <= (a)->dmax)?\ | ||
459 | (a):bn_expand2((a),(bits)/BN_BITS2+1)) | ||
460 | #define bn_wexpand(a,words) (((words) <= (a)->dmax)?(a):bn_expand2((a),(words))) | ||
461 | BIGNUM *bn_expand2(BIGNUM *a, int words); | ||
462 | BIGNUM *bn_dup_expand(const BIGNUM *a, int words); | ||
463 | |||
464 | #define bn_fix_top(a) \ | ||
465 | { \ | ||
466 | BN_ULONG *ftl; \ | ||
467 | if ((a)->top > 0) \ | ||
468 | { \ | ||
469 | for (ftl= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) \ | ||
470 | if (*(ftl--)) break; \ | ||
471 | } \ | ||
472 | } | ||
425 | 473 | ||
474 | BN_ULONG bn_mul_add_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w); | ||
475 | BN_ULONG bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w); | ||
476 | void bn_sqr_words(BN_ULONG *rp, const BN_ULONG *ap, int num); | ||
477 | BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d); | ||
478 | BN_ULONG bn_add_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,int num); | ||
479 | BN_ULONG bn_sub_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,int num); | ||
480 | |||
481 | #ifdef BN_DEBUG | ||
482 | void bn_dump1(FILE *o, const char *a, const BN_ULONG *b,int n); | ||
483 | # define bn_print(a) {fprintf(stderr, #a "="); BN_print_fp(stderr,a); \ | ||
484 | fprintf(stderr,"\n");} | ||
485 | # define bn_dump(a,n) bn_dump1(stderr,#a,a,n); | ||
486 | #else | ||
487 | # define bn_print(a) | ||
488 | # define bn_dump(a,b) | ||
489 | #endif | ||
490 | |||
491 | int BN_bntest_rand(BIGNUM *rnd, int bits, int top,int bottom); | ||
426 | 492 | ||
427 | /* BEGIN ERROR CODES */ | 493 | /* BEGIN ERROR CODES */ |
428 | /* The following lines are auto generated by the script mkerr.pl. Any changes | 494 | /* The following lines are auto generated by the script mkerr.pl. Any changes |
429 | * made after this point may be overwritten when the script is next run. | 495 | * made after this point may be overwritten when the script is next run. |
430 | */ | 496 | */ |
497 | void ERR_load_BN_strings(void); | ||
431 | 498 | ||
432 | /* Error codes for the BN functions. */ | 499 | /* Error codes for the BN functions. */ |
433 | 500 | ||
@@ -438,30 +505,43 @@ int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, | |||
438 | #define BN_F_BN_BLINDING_UPDATE 103 | 505 | #define BN_F_BN_BLINDING_UPDATE 103 |
439 | #define BN_F_BN_BN2DEC 104 | 506 | #define BN_F_BN_BN2DEC 104 |
440 | #define BN_F_BN_BN2HEX 105 | 507 | #define BN_F_BN_BN2HEX 105 |
508 | #define BN_F_BN_CTX_GET 116 | ||
441 | #define BN_F_BN_CTX_NEW 106 | 509 | #define BN_F_BN_CTX_NEW 106 |
442 | #define BN_F_BN_DIV 107 | 510 | #define BN_F_BN_DIV 107 |
443 | #define BN_F_BN_EXPAND2 108 | 511 | #define BN_F_BN_EXPAND2 108 |
512 | #define BN_F_BN_EXPAND_INTERNAL 120 | ||
513 | #define BN_F_BN_MOD_EXP2_MONT 118 | ||
444 | #define BN_F_BN_MOD_EXP_MONT 109 | 514 | #define BN_F_BN_MOD_EXP_MONT 109 |
515 | #define BN_F_BN_MOD_EXP_MONT_WORD 117 | ||
445 | #define BN_F_BN_MOD_INVERSE 110 | 516 | #define BN_F_BN_MOD_INVERSE 110 |
517 | #define BN_F_BN_MOD_LSHIFT_QUICK 119 | ||
446 | #define BN_F_BN_MOD_MUL_RECIPROCAL 111 | 518 | #define BN_F_BN_MOD_MUL_RECIPROCAL 111 |
519 | #define BN_F_BN_MOD_SQRT 121 | ||
447 | #define BN_F_BN_MPI2BN 112 | 520 | #define BN_F_BN_MPI2BN 112 |
448 | #define BN_F_BN_NEW 113 | 521 | #define BN_F_BN_NEW 113 |
449 | #define BN_F_BN_RAND 114 | 522 | #define BN_F_BN_RAND 114 |
523 | #define BN_F_BN_RAND_RANGE 122 | ||
450 | #define BN_F_BN_USUB 115 | 524 | #define BN_F_BN_USUB 115 |
451 | 525 | ||
452 | /* Reason codes. */ | 526 | /* Reason codes. */ |
453 | #define BN_R_ARG2_LT_ARG3 100 | 527 | #define BN_R_ARG2_LT_ARG3 100 |
454 | #define BN_R_BAD_RECIPROCAL 101 | 528 | #define BN_R_BAD_RECIPROCAL 101 |
529 | #define BN_R_BIGNUM_TOO_LONG 114 | ||
455 | #define BN_R_CALLED_WITH_EVEN_MODULUS 102 | 530 | #define BN_R_CALLED_WITH_EVEN_MODULUS 102 |
456 | #define BN_R_DIV_BY_ZERO 103 | 531 | #define BN_R_DIV_BY_ZERO 103 |
457 | #define BN_R_ENCODING_ERROR 104 | 532 | #define BN_R_ENCODING_ERROR 104 |
458 | #define BN_R_EXPAND_ON_STATIC_BIGNUM_DATA 105 | 533 | #define BN_R_EXPAND_ON_STATIC_BIGNUM_DATA 105 |
534 | #define BN_R_INPUT_NOT_REDUCED 110 | ||
459 | #define BN_R_INVALID_LENGTH 106 | 535 | #define BN_R_INVALID_LENGTH 106 |
536 | #define BN_R_INVALID_RANGE 115 | ||
537 | #define BN_R_NOT_A_SQUARE 111 | ||
460 | #define BN_R_NOT_INITIALIZED 107 | 538 | #define BN_R_NOT_INITIALIZED 107 |
461 | #define BN_R_NO_INVERSE 108 | 539 | #define BN_R_NO_INVERSE 108 |
540 | #define BN_R_P_IS_NOT_PRIME 112 | ||
541 | #define BN_R_TOO_MANY_ITERATIONS 113 | ||
542 | #define BN_R_TOO_MANY_TEMPORARY_VARIABLES 109 | ||
462 | 543 | ||
463 | #ifdef __cplusplus | 544 | #ifdef __cplusplus |
464 | } | 545 | } |
465 | #endif | 546 | #endif |
466 | #endif | 547 | #endif |
467 | |||