summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/bn.h
diff options
context:
space:
mode:
authorjsing <>2014-05-08 13:20:49 +0000
committerjsing <>2014-05-08 13:20:49 +0000
commit2e8879604fe3abbc2431ca79a4a923f1e87da75e (patch)
tree18398455223278c0cb2bd44f57e4499a4370f665 /src/lib/libcrypto/bn/bn.h
parentf7d9a959949e5f3918c1cf2b27fb4cd7b62d07d5 (diff)
downloadopenbsd-2e8879604fe3abbc2431ca79a4a923f1e87da75e.tar.gz
openbsd-2e8879604fe3abbc2431ca79a4a923f1e87da75e.tar.bz2
openbsd-2e8879604fe3abbc2431ca79a4a923f1e87da75e.zip
Emergency knfectomie requested by tedu@.
Diffstat (limited to 'src/lib/libcrypto/bn/bn.h')
-rw-r--r--src/lib/libcrypto/bn/bn.h197
1 files changed, 99 insertions, 98 deletions
diff --git a/src/lib/libcrypto/bn/bn.h b/src/lib/libcrypto/bn/bn.h
index 74005ed254..2a73bbbecc 100644
--- a/src/lib/libcrypto/bn/bn.h
+++ b/src/lib/libcrypto/bn/bn.h
@@ -5,21 +5,21 @@
5 * This package is an SSL implementation written 5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com). 6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL. 7 * The implementation was written so as to conform with Netscapes SSL.
8 * 8 *
9 * This library is free for commercial and non-commercial use as long as 9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions 10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -63,7 +63,7 @@
63 * are met: 63 * are met:
64 * 64 *
65 * 1. Redistributions of source code must retain the above copyright 65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer. 66 * notice, this list of conditions and the following disclaimer.
67 * 67 *
68 * 2. Redistributions in binary form must reproduce the above copyright 68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in 69 * notice, this list of conditions and the following disclaimer in
@@ -111,13 +111,13 @@
111/* ==================================================================== 111/* ====================================================================
112 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 112 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
113 * 113 *
114 * Portions of the attached software ("Contribution") are developed by 114 * Portions of the attached software ("Contribution") are developed by
115 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project. 115 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
116 * 116 *
117 * The Contribution is licensed pursuant to the Eric Young open source 117 * The Contribution is licensed pursuant to the Eric Young open source
118 * license provided above. 118 * license provided above.
119 * 119 *
120 * The binary polynomial arithmetic software is originally written by 120 * The binary polynomial arithmetic software is originally written by
121 * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories. 121 * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.
122 * 122 *
123 */ 123 */
@@ -251,19 +251,17 @@ typedef struct bn_recp_ctx_st BN_RECP_CTX;
251typedef struct bn_gencb_st BN_GENCB; 251typedef struct bn_gencb_st BN_GENCB;
252#endif 252#endif
253 253
254struct bignum_st 254struct bignum_st {
255 {
256 BN_ULONG *d; /* Pointer to an array of 'BN_BITS2' bit chunks. */ 255 BN_ULONG *d; /* Pointer to an array of 'BN_BITS2' bit chunks. */
257 int top; /* Index of last used d +1. */ 256 int top; /* Index of last used d +1. */
258 /* The next are internal book keeping for bn_expand. */ 257 /* The next are internal book keeping for bn_expand. */
259 int dmax; /* Size of the d array. */ 258 int dmax; /* Size of the d array. */
260 int neg; /* one if the number is negative */ 259 int neg; /* one if the number is negative */
261 int flags; 260 int flags;
262 }; 261};
263 262
264/* Used for montgomery multiplication */ 263/* Used for montgomery multiplication */
265struct bn_mont_ctx_st 264struct bn_mont_ctx_st {
266 {
267 int ri; /* number of bits in R */ 265 int ri; /* number of bits in R */
268 BIGNUM RR; /* used to convert to montgomery form */ 266 BIGNUM RR; /* used to convert to montgomery form */
269 BIGNUM N; /* The modulus */ 267 BIGNUM N; /* The modulus */
@@ -272,33 +270,30 @@ struct bn_mont_ctx_st
272 BN_ULONG n0[2];/* least significant word(s) of Ni; 270 BN_ULONG n0[2];/* least significant word(s) of Ni;
273 (type changed with 0.9.9, was "BN_ULONG n0;" before) */ 271 (type changed with 0.9.9, was "BN_ULONG n0;" before) */
274 int flags; 272 int flags;
275 }; 273};
276 274
277/* Used for reciprocal division/mod functions 275/* Used for reciprocal division/mod functions
278 * It cannot be shared between threads 276 * It cannot be shared between threads
279 */ 277 */
280struct bn_recp_ctx_st 278struct bn_recp_ctx_st {
281 {
282 BIGNUM N; /* the divisor */ 279 BIGNUM N; /* the divisor */
283 BIGNUM Nr; /* the reciprocal */ 280 BIGNUM Nr; /* the reciprocal */
284 int num_bits; 281 int num_bits;
285 int shift; 282 int shift;
286 int flags; 283 int flags;
287 }; 284};
288 285
289/* Used for slow "generation" functions. */ 286/* Used for slow "generation" functions. */
290struct bn_gencb_st 287struct bn_gencb_st {
291 {
292 unsigned int ver; /* To handle binary (in)compatibility */ 288 unsigned int ver; /* To handle binary (in)compatibility */
293 void *arg; /* callback-specific data */ 289 void *arg; /* callback-specific data */
294 union 290 union {
295 {
296 /* if(ver==1) - handles old style callbacks */ 291 /* if(ver==1) - handles old style callbacks */
297 void (*cb_1)(int, int, void *); 292 void (*cb_1)(int, int, void *);
298 /* if(ver==2) - new callback style */ 293 /* if(ver==2) - new callback style */
299 int (*cb_2)(int, int, BN_GENCB *); 294 int (*cb_2)(int, int, BN_GENCB *);
300 } cb; 295 } cb;
301 }; 296};
302/* Wrapper function to make using BN_GENCB easier, */ 297/* Wrapper function to make using BN_GENCB easier, */
303int BN_GENCB_call(BN_GENCB *cb, int a, int b); 298int BN_GENCB_call(BN_GENCB *cb, int a, int b);
304/* Macro to populate a BN_GENCB structure with an "old"-style callback */ 299/* Macro to populate a BN_GENCB structure with an "old"-style callback */
@@ -368,8 +363,8 @@ void BN_CTX_free(BN_CTX *c);
368void BN_CTX_start(BN_CTX *ctx); 363void BN_CTX_start(BN_CTX *ctx);
369BIGNUM *BN_CTX_get(BN_CTX *ctx); 364BIGNUM *BN_CTX_get(BN_CTX *ctx);
370void BN_CTX_end(BN_CTX *ctx); 365void BN_CTX_end(BN_CTX *ctx);
371int BN_rand(BIGNUM *rnd, int bits, int top,int bottom); 366int BN_rand(BIGNUM *rnd, int bits, int top, int bottom);
372int BN_pseudo_rand(BIGNUM *rnd, int bits, int top,int bottom); 367int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom);
373int BN_rand_range(BIGNUM *rnd, const BIGNUM *range); 368int BN_rand_range(BIGNUM *rnd, const BIGNUM *range);
374int BN_pseudo_rand_range(BIGNUM *rnd, const BIGNUM *range); 369int BN_pseudo_rand_range(BIGNUM *rnd, const BIGNUM *range);
375int BN_num_bits(const BIGNUM *a); 370int BN_num_bits(const BIGNUM *a);
@@ -379,19 +374,19 @@ void BN_init(BIGNUM *);
379void BN_clear_free(BIGNUM *a); 374void BN_clear_free(BIGNUM *a);
380BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b); 375BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b);
381void BN_swap(BIGNUM *a, BIGNUM *b); 376void BN_swap(BIGNUM *a, BIGNUM *b);
382BIGNUM *BN_bin2bn(const unsigned char *s,int len,BIGNUM *ret); 377BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret);
383int BN_bn2bin(const BIGNUM *a, unsigned char *to); 378int BN_bn2bin(const BIGNUM *a, unsigned char *to);
384BIGNUM *BN_mpi2bn(const unsigned char *s,int len,BIGNUM *ret); 379BIGNUM *BN_mpi2bn(const unsigned char *s, int len, BIGNUM *ret);
385int BN_bn2mpi(const BIGNUM *a, unsigned char *to); 380int BN_bn2mpi(const BIGNUM *a, unsigned char *to);
386int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); 381int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
387int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); 382int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
388int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); 383int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
389int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); 384int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
390int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx); 385int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
391int BN_sqr(BIGNUM *r, const BIGNUM *a,BN_CTX *ctx); 386int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx);
392/** BN_set_negative sets sign of a BIGNUM 387/** BN_set_negative sets sign of a BIGNUM
393 * \param b pointer to the BIGNUM object 388 * \param b pointer to the BIGNUM object
394 * \param n 0 if the BIGNUM b should be positive and a value != 0 otherwise 389 * \param n 0 if the BIGNUM b should be positive and a value != 0 otherwise
395 */ 390 */
396void BN_set_negative(BIGNUM *b, int n); 391void BN_set_negative(BIGNUM *b, int n);
397/** BN_is_negative returns 1 if the BIGNUM is negative 392/** BN_is_negative returns 1 if the BIGNUM is negative
@@ -401,7 +396,7 @@ void BN_set_negative(BIGNUM *b, int n);
401#define BN_is_negative(a) ((a)->neg != 0) 396#define BN_is_negative(a) ((a)->neg != 0)
402 397
403int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, 398int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d,
404 BN_CTX *ctx); 399 BN_CTX *ctx);
405#define BN_mod(rem,m,d,ctx) BN_div(NULL,(rem),(m),(d),(ctx)) 400#define BN_mod(rem,m,d,ctx) BN_div(NULL,(rem),(m),(d),(ctx))
406int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx); 401int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx);
407int BN_mod_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx); 402int BN_mod_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx);
@@ -409,7 +404,7 @@ int BN_mod_add_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *
409int BN_mod_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx); 404int BN_mod_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx);
410int BN_mod_sub_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m); 405int BN_mod_sub_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m);
411int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, 406int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
412 const BIGNUM *m, BN_CTX *ctx); 407 const BIGNUM *m, BN_CTX *ctx);
413int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx); 408int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
414int BN_mod_lshift1(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx); 409int BN_mod_lshift1(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
415int BN_mod_lshift1_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *m); 410int BN_mod_lshift1_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *m);
@@ -429,23 +424,23 @@ void BN_free(BIGNUM *a);
429int BN_is_bit_set(const BIGNUM *a, int n); 424int BN_is_bit_set(const BIGNUM *a, int n);
430int BN_lshift(BIGNUM *r, const BIGNUM *a, int n); 425int BN_lshift(BIGNUM *r, const BIGNUM *a, int n);
431int BN_lshift1(BIGNUM *r, const BIGNUM *a); 426int BN_lshift1(BIGNUM *r, const BIGNUM *a);
432int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,BN_CTX *ctx); 427int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
433 428
434int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, 429int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
435 const BIGNUM *m,BN_CTX *ctx); 430 const BIGNUM *m, BN_CTX *ctx);
436int BN_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, 431int BN_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
437 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); 432 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
438int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p, 433int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
439 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont); 434 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont);
440int BN_mod_exp_mont_word(BIGNUM *r, BN_ULONG a, const BIGNUM *p, 435int BN_mod_exp_mont_word(BIGNUM *r, BN_ULONG a, const BIGNUM *p,
441 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); 436 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
442int BN_mod_exp2_mont(BIGNUM *r, const BIGNUM *a1, const BIGNUM *p1, 437int BN_mod_exp2_mont(BIGNUM *r, const BIGNUM *a1, const BIGNUM *p1,
443 const BIGNUM *a2, const BIGNUM *p2,const BIGNUM *m, 438 const BIGNUM *a2, const BIGNUM *p2, const BIGNUM *m,
444 BN_CTX *ctx,BN_MONT_CTX *m_ctx); 439 BN_CTX *ctx, BN_MONT_CTX *m_ctx);
445int BN_mod_exp_simple(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, 440int BN_mod_exp_simple(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
446 const BIGNUM *m,BN_CTX *ctx); 441 const BIGNUM *m, BN_CTX *ctx);
447 442
448int BN_mask_bits(BIGNUM *a,int n); 443int BN_mask_bits(BIGNUM *a, int n);
449#ifndef OPENSSL_NO_FP_API 444#ifndef OPENSSL_NO_FP_API
450int BN_print_fp(FILE *fp, const BIGNUM *a); 445int BN_print_fp(FILE *fp, const BIGNUM *a);
451#endif 446#endif
@@ -467,59 +462,59 @@ char * BN_bn2dec(const BIGNUM *a);
467int BN_hex2bn(BIGNUM **a, const char *str); 462int BN_hex2bn(BIGNUM **a, const char *str);
468int BN_dec2bn(BIGNUM **a, const char *str); 463int BN_dec2bn(BIGNUM **a, const char *str);
469int BN_asc2bn(BIGNUM **a, const char *str); 464int BN_asc2bn(BIGNUM **a, const char *str);
470int BN_gcd(BIGNUM *r,const BIGNUM *a,const BIGNUM *b,BN_CTX *ctx); 465int BN_gcd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
471int BN_kronecker(const BIGNUM *a,const BIGNUM *b,BN_CTX *ctx); /* returns -2 for error */ 466int BN_kronecker(const BIGNUM *a,const BIGNUM *b,BN_CTX *ctx); /* returns -2 for error */
472BIGNUM *BN_mod_inverse(BIGNUM *ret, 467BIGNUM *BN_mod_inverse(BIGNUM *ret,
473 const BIGNUM *a, const BIGNUM *n,BN_CTX *ctx); 468 const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx);
474BIGNUM *BN_mod_sqrt(BIGNUM *ret, 469BIGNUM *BN_mod_sqrt(BIGNUM *ret,
475 const BIGNUM *a, const BIGNUM *n,BN_CTX *ctx); 470 const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx);
476 471
477void BN_consttime_swap(BN_ULONG swap, BIGNUM *a, BIGNUM *b, int nwords); 472void BN_consttime_swap(BN_ULONG swap, BIGNUM *a, BIGNUM *b, int nwords);
478 473
479/* Deprecated versions */ 474/* Deprecated versions */
480#ifndef OPENSSL_NO_DEPRECATED 475#ifndef OPENSSL_NO_DEPRECATED
481BIGNUM *BN_generate_prime(BIGNUM *ret,int bits,int safe, 476BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int safe,
482 const BIGNUM *add, const BIGNUM *rem, 477 const BIGNUM *add, const BIGNUM *rem,
483 void (*callback)(int,int,void *),void *cb_arg); 478 void (*callback)(int, int, void *), void *cb_arg);
484int BN_is_prime(const BIGNUM *p,int nchecks, 479int BN_is_prime(const BIGNUM *p, int nchecks,
485 void (*callback)(int,int,void *), 480 void (*callback)(int, int, void *),
486 BN_CTX *ctx,void *cb_arg); 481 BN_CTX *ctx, void *cb_arg);
487int BN_is_prime_fasttest(const BIGNUM *p,int nchecks, 482int BN_is_prime_fasttest(const BIGNUM *p, int nchecks,
488 void (*callback)(int,int,void *),BN_CTX *ctx,void *cb_arg, 483 void (*callback)(int, int, void *), BN_CTX *ctx, void *cb_arg,
489 int do_trial_division); 484 int do_trial_division);
490#endif /* !defined(OPENSSL_NO_DEPRECATED) */ 485#endif /* !defined(OPENSSL_NO_DEPRECATED) */
491 486
492/* Newer versions */ 487/* Newer versions */
493int BN_generate_prime_ex(BIGNUM *ret,int bits,int safe, const BIGNUM *add, 488int BN_generate_prime_ex(BIGNUM *ret, int bits, int safe, const BIGNUM *add,
494 const BIGNUM *rem, BN_GENCB *cb); 489 const BIGNUM *rem, BN_GENCB *cb);
495int BN_is_prime_ex(const BIGNUM *p,int nchecks, BN_CTX *ctx, BN_GENCB *cb); 490int BN_is_prime_ex(const BIGNUM *p, int nchecks, BN_CTX *ctx, BN_GENCB *cb);
496int BN_is_prime_fasttest_ex(const BIGNUM *p,int nchecks, BN_CTX *ctx, 491int BN_is_prime_fasttest_ex(const BIGNUM *p, int nchecks, BN_CTX *ctx,
497 int do_trial_division, BN_GENCB *cb); 492 int do_trial_division, BN_GENCB *cb);
498 493
499int BN_X931_generate_Xpq(BIGNUM *Xp, BIGNUM *Xq, int nbits, BN_CTX *ctx); 494int BN_X931_generate_Xpq(BIGNUM *Xp, BIGNUM *Xq, int nbits, BN_CTX *ctx);
500 495
501int BN_X931_derive_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2, 496int BN_X931_derive_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2,
502 const BIGNUM *Xp, const BIGNUM *Xp1, const BIGNUM *Xp2, 497 const BIGNUM *Xp, const BIGNUM *Xp1, const BIGNUM *Xp2,
503 const BIGNUM *e, BN_CTX *ctx, BN_GENCB *cb); 498 const BIGNUM *e, BN_CTX *ctx, BN_GENCB *cb);
504int BN_X931_generate_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2, 499int BN_X931_generate_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2,
505 BIGNUM *Xp1, BIGNUM *Xp2, 500 BIGNUM *Xp1, BIGNUM *Xp2,
506 const BIGNUM *Xp, 501 const BIGNUM *Xp,
507 const BIGNUM *e, BN_CTX *ctx, 502 const BIGNUM *e, BN_CTX *ctx,
508 BN_GENCB *cb); 503 BN_GENCB *cb);
509 504
510BN_MONT_CTX *BN_MONT_CTX_new(void ); 505BN_MONT_CTX *BN_MONT_CTX_new(void );
511void BN_MONT_CTX_init(BN_MONT_CTX *ctx); 506void BN_MONT_CTX_init(BN_MONT_CTX *ctx);
512int BN_mod_mul_montgomery(BIGNUM *r,const BIGNUM *a,const BIGNUM *b, 507int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
513 BN_MONT_CTX *mont, BN_CTX *ctx); 508 BN_MONT_CTX *mont, BN_CTX *ctx);
514#define BN_to_montgomery(r,a,mont,ctx) BN_mod_mul_montgomery(\ 509#define BN_to_montgomery(r,a,mont,ctx) BN_mod_mul_montgomery(\
515 (r),(a),&((mont)->RR),(mont),(ctx)) 510 (r),(a),&((mont)->RR),(mont),(ctx))
516int BN_from_montgomery(BIGNUM *r,const BIGNUM *a, 511int BN_from_montgomery(BIGNUM *r, const BIGNUM *a,
517 BN_MONT_CTX *mont, BN_CTX *ctx); 512 BN_MONT_CTX *mont, BN_CTX *ctx);
518void BN_MONT_CTX_free(BN_MONT_CTX *mont); 513void BN_MONT_CTX_free(BN_MONT_CTX *mont);
519int BN_MONT_CTX_set(BN_MONT_CTX *mont,const BIGNUM *mod,BN_CTX *ctx); 514int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx);
520BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to,BN_MONT_CTX *from); 515BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from);
521BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, int lock, 516BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, int lock,
522 const BIGNUM *mod, BN_CTX *ctx); 517 const BIGNUM *mod, BN_CTX *ctx);
523 518
524/* BN_BLINDING flags */ 519/* BN_BLINDING flags */
525#define BN_BLINDING_NO_UPDATE 0x00000001 520#define BN_BLINDING_NO_UPDATE 0x00000001
@@ -527,7 +522,7 @@ BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, int lock,
527 522
528BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, BIGNUM *mod); 523BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, BIGNUM *mod);
529void BN_BLINDING_free(BN_BLINDING *b); 524void BN_BLINDING_free(BN_BLINDING *b);
530int BN_BLINDING_update(BN_BLINDING *b,BN_CTX *ctx); 525int BN_BLINDING_update(BN_BLINDING *b, BN_CTX *ctx);
531int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx); 526int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx);
532int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx); 527int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx);
533int BN_BLINDING_convert_ex(BIGNUM *n, BIGNUM *r, BN_BLINDING *b, BN_CTX *); 528int BN_BLINDING_convert_ex(BIGNUM *n, BIGNUM *r, BN_BLINDING *b, BN_CTX *);
@@ -540,30 +535,30 @@ CRYPTO_THREADID *BN_BLINDING_thread_id(BN_BLINDING *);
540unsigned long BN_BLINDING_get_flags(const BN_BLINDING *); 535unsigned long BN_BLINDING_get_flags(const BN_BLINDING *);
541void BN_BLINDING_set_flags(BN_BLINDING *, unsigned long); 536void BN_BLINDING_set_flags(BN_BLINDING *, unsigned long);
542BN_BLINDING *BN_BLINDING_create_param(BN_BLINDING *b, 537BN_BLINDING *BN_BLINDING_create_param(BN_BLINDING *b,
543 const BIGNUM *e, BIGNUM *m, BN_CTX *ctx, 538 const BIGNUM *e, BIGNUM *m, BN_CTX *ctx,
544 int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, 539 int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
545 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx), 540 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx),
546 BN_MONT_CTX *m_ctx); 541 BN_MONT_CTX *m_ctx);
547 542
548#ifndef OPENSSL_NO_DEPRECATED 543#ifndef OPENSSL_NO_DEPRECATED
549void BN_set_params(int mul,int high,int low,int mont); 544void BN_set_params(int mul, int high, int low, int mont);
550int BN_get_params(int which); /* 0, mul, 1 high, 2 low, 3 mont */ 545int BN_get_params(int which); /* 0, mul, 1 high, 2 low, 3 mont */
551#endif 546#endif
552 547
553void BN_RECP_CTX_init(BN_RECP_CTX *recp); 548void BN_RECP_CTX_init(BN_RECP_CTX *recp);
554BN_RECP_CTX *BN_RECP_CTX_new(void); 549BN_RECP_CTX *BN_RECP_CTX_new(void);
555void BN_RECP_CTX_free(BN_RECP_CTX *recp); 550void BN_RECP_CTX_free(BN_RECP_CTX *recp);
556int BN_RECP_CTX_set(BN_RECP_CTX *recp,const BIGNUM *rdiv,BN_CTX *ctx); 551int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *rdiv, BN_CTX *ctx);
557int BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y, 552int BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y,
558 BN_RECP_CTX *recp,BN_CTX *ctx); 553 BN_RECP_CTX *recp, BN_CTX *ctx);
559int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, 554int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
560 const BIGNUM *m, BN_CTX *ctx); 555 const BIGNUM *m, BN_CTX *ctx);
561int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, 556int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m,
562 BN_RECP_CTX *recp, BN_CTX *ctx); 557 BN_RECP_CTX *recp, BN_CTX *ctx);
563 558
564#ifndef OPENSSL_NO_EC2M 559#ifndef OPENSSL_NO_EC2M
565 560
566/* Functions for arithmetic over binary polynomials represented by BIGNUMs. 561/* Functions for arithmetic over binary polynomials represented by BIGNUMs.
567 * 562 *
568 * The BIGNUM::neg property of BIGNUMs representing binary polynomials is 563 * The BIGNUM::neg property of BIGNUMs representing binary polynomials is
569 * ignored. 564 * ignored.
@@ -575,17 +570,23 @@ int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m,
575int BN_GF2m_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); /*r = a + b*/ 570int BN_GF2m_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); /*r = a + b*/
576#define BN_GF2m_sub(r, a, b) BN_GF2m_add(r, a, b) 571#define BN_GF2m_sub(r, a, b) BN_GF2m_add(r, a, b)
577int BN_GF2m_mod(BIGNUM *r, const BIGNUM *a, const BIGNUM *p); /*r=a mod p*/ 572int BN_GF2m_mod(BIGNUM *r, const BIGNUM *a, const BIGNUM *p); /*r=a mod p*/
578int BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, 573int
574BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
579 const BIGNUM *p, BN_CTX *ctx); /* r = (a * b) mod p */ 575 const BIGNUM *p, BN_CTX *ctx); /* r = (a * b) mod p */
580int BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, 576int
577BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
581 BN_CTX *ctx); /* r = (a * a) mod p */ 578 BN_CTX *ctx); /* r = (a * a) mod p */
582int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *b, const BIGNUM *p, 579int
580BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *b, const BIGNUM *p,
583 BN_CTX *ctx); /* r = (1 / b) mod p */ 581 BN_CTX *ctx); /* r = (1 / b) mod p */
584int BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, 582int
583BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
585 const BIGNUM *p, BN_CTX *ctx); /* r = (a / b) mod p */ 584 const BIGNUM *p, BN_CTX *ctx); /* r = (a / b) mod p */
586int BN_GF2m_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, 585int
586BN_GF2m_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
587 const BIGNUM *p, BN_CTX *ctx); /* r = (a ^ b) mod p */ 587 const BIGNUM *p, BN_CTX *ctx); /* r = (a ^ b) mod p */
588int BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, 588int
589BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
589 BN_CTX *ctx); /* r = sqrt(a) mod p */ 590 BN_CTX *ctx); /* r = sqrt(a) mod p */
590int BN_GF2m_mod_solve_quad(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, 591int BN_GF2m_mod_solve_quad(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
591 BN_CTX *ctx); /* r^2 + r = a mod p */ 592 BN_CTX *ctx); /* r^2 + r = a mod p */
@@ -596,12 +597,12 @@ int BN_GF2m_mod_solve_quad(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
596 * where m = p[0] > p[1] > ... > p[k] = 0. 597 * where m = p[0] > p[1] > ... > p[k] = 0.
597 */ 598 */
598int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const int p[]); 599int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const int p[]);
599 /* r = a mod p */ 600/* r = a mod p */
600int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, 601int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
601 const int p[], BN_CTX *ctx); /* r = (a * b) mod p */ 602 const int p[], BN_CTX *ctx); /* r = (a * b) mod p */
602int BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const int p[], 603int BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const int p[],
603 BN_CTX *ctx); /* r = (a * a) mod p */ 604 BN_CTX *ctx); /* r = (a * a) mod p */
604int BN_GF2m_mod_inv_arr(BIGNUM *r, const BIGNUM *b, const int p[], 605int BN_GF2m_mod_inv_arr(BIGNUM *r, const BIGNUM *b, const int p[],
605 BN_CTX *ctx); /* r = (1 / b) mod p */ 606 BN_CTX *ctx); /* r = (1 / b) mod p */
606int BN_GF2m_mod_div_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, 607int BN_GF2m_mod_div_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
607 const int p[], BN_CTX *ctx); /* r = (a / b) mod p */ 608 const int p[], BN_CTX *ctx); /* r = (a / b) mod p */
@@ -616,7 +617,7 @@ int BN_GF2m_arr2poly(const int p[], BIGNUM *a);
616 617
617#endif 618#endif
618 619
619/* faster mod functions for the 'NIST primes' 620/* faster mod functions for the 'NIST primes'
620 * 0 <= a < p^2 */ 621 * 0 <= a < p^2 */
621int BN_nist_mod_192(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx); 622int BN_nist_mod_192(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
622int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx); 623int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
@@ -676,7 +677,7 @@ BIGNUM *bn_dup_expand(const BIGNUM *a, int words); /* unused */
676#ifdef BN_DEBUG_RAND 677#ifdef BN_DEBUG_RAND
677/* To avoid "make update" cvs wars due to BN_DEBUG, use some tricks */ 678/* To avoid "make update" cvs wars due to BN_DEBUG, use some tricks */
678#ifndef RAND_pseudo_bytes 679#ifndef RAND_pseudo_bytes
679int RAND_pseudo_bytes(unsigned char *buf,int num); 680int RAND_pseudo_bytes(unsigned char *buf, int num);
680#define BN_DEBUG_TRIX 681#define BN_DEBUG_TRIX
681#endif 682#endif
682#define bn_pollute(a) \ 683#define bn_pollute(a) \
@@ -742,12 +743,12 @@ int RAND_pseudo_bytes(unsigned char *buf,int num);
742 bn_pollute(a); \ 743 bn_pollute(a); \
743 } 744 }
744 745
745BN_ULONG bn_mul_add_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w); 746 BN_ULONG bn_mul_add_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w);
746BN_ULONG bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w); 747BN_ULONG bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w);
747void bn_sqr_words(BN_ULONG *rp, const BN_ULONG *ap, int num); 748void bn_sqr_words(BN_ULONG *rp, const BN_ULONG *ap, int num);
748BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d); 749BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d);
749BN_ULONG bn_add_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,int num); 750BN_ULONG bn_add_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, int num);
750BN_ULONG bn_sub_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,int num); 751BN_ULONG bn_sub_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, int num);
751 752
752/* Primes from RFC 2409 */ 753/* Primes from RFC 2409 */
753BIGNUM *get_rfc2409_prime_768(BIGNUM *bn); 754BIGNUM *get_rfc2409_prime_768(BIGNUM *bn);
@@ -761,7 +762,7 @@ BIGNUM *get_rfc3526_prime_4096(BIGNUM *bn);
761BIGNUM *get_rfc3526_prime_6144(BIGNUM *bn); 762BIGNUM *get_rfc3526_prime_6144(BIGNUM *bn);
762BIGNUM *get_rfc3526_prime_8192(BIGNUM *bn); 763BIGNUM *get_rfc3526_prime_8192(BIGNUM *bn);
763 764
764int BN_bntest_rand(BIGNUM *rnd, int bits, int top,int bottom); 765int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom);
765 766
766/* BEGIN ERROR CODES */ 767/* BEGIN ERROR CODES */
767/* The following lines are auto generated by the script mkerr.pl. Any changes 768/* The following lines are auto generated by the script mkerr.pl. Any changes