*** empty log message ***
[openssl.git] / crypto / bn / bn.h
index 8ac8acd1165b7ae7f73db7d557e1ac2bb23db2ed..d8822610dfaab6092733f80ae1e05ea84a7acd86 100644 (file)
@@ -240,13 +240,15 @@ typedef struct bignum_st
 
 /* Used for temp variables */
 #define BN_CTX_NUM     12
+#define BN_CTX_NUM_POS 12
 typedef struct bignum_ctx
        {
        int tos;
-       BIGNUM bn[BN_CTX_NUM+1];
+       BIGNUM bn[BN_CTX_NUM];
        int flags;
        int depth;
-       int pos[BN_CTX_NUM+1];
+       int pos[BN_CTX_NUM_POS];
+       int too_many;
        } BN_CTX;
 
 typedef struct bn_blinding_st
@@ -260,7 +262,6 @@ typedef struct bn_blinding_st
 /* Used for montgomery multiplication */
 typedef struct bn_mont_ctx_st
        {
-       int use_word;  /* 0 for word form, 1 for bignum form */
        int ri;        /* number of bits in R */
        BIGNUM RR;     /* used to convert to montgomery form */
        BIGNUM N;      /* The modulus */
@@ -288,7 +289,6 @@ typedef struct bn_recp_ctx_st
 #define BN_prime_checks 0 /* default: select number of iterations
                             based on the size of the number */
 
-
 /* number of Miller-Rabin iterations for an error rate  of less than 2^-80
  * for random 'b'-bit input, b >= 100 (taken from table 4.4 in the Handbook
  * of Applied Cryptography [Menezes, van Oorschot, Vanstone; CRC Press 1996];
@@ -318,20 +318,6 @@ typedef struct bn_recp_ctx_st
 /*#define BN_ascii2bn(a)       BN_hex2bn(a) */
 /*#define BN_bn2ascii(a)       BN_bn2hex(a) */
 
-#define bn_expand(n,b) ((((((b+BN_BITS2-1))/BN_BITS2)) <= (n)->max)?\
-       (n):bn_expand2((n),(b)/BN_BITS2+1))
-#define bn_wexpand(n,b) (((b) <= (n)->max)?(n):bn_expand2((n),(b)))
-
-#define bn_fix_top(a) \
-        { \
-        BN_ULONG *ftl; \
-       if ((a)->top > 0) \
-               { \
-               for (ftl= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) \
-               if (*(ftl--)) break; \
-               } \
-       }
-
 BIGNUM *BN_value_one(void);
 char * BN_options(void);
 BN_CTX *BN_CTX_new(void);
@@ -384,19 +370,18 @@ int       BN_mod_exp_simple(BIGNUM *r, BIGNUM *a, BIGNUM *p,
        BIGNUM *m,BN_CTX *ctx);
 int    BN_mask_bits(BIGNUM *a,int n);
 int    BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m, BN_CTX *ctx);
-#ifndef WIN16
+#ifndef NO_FP_API
 int    BN_print_fp(FILE *fp, const BIGNUM *a);
 #endif
 #ifdef HEADER_BIO_H
 int    BN_print(BIO *fp, const BIGNUM *a);
 #else
-int    BN_print(char *fp, const BIGNUM *a);
+int    BN_print(void *fp, const BIGNUM *a);
 #endif
 int    BN_reciprocal(BIGNUM *r, BIGNUM *m, int len, BN_CTX *ctx);
 int    BN_rshift(BIGNUM *r, BIGNUM *a, int n);
 int    BN_rshift1(BIGNUM *r, BIGNUM *a);
 void   BN_clear(BIGNUM *a);
-BIGNUM *bn_expand2(BIGNUM *b, int bits);
 BIGNUM *BN_dup(const BIGNUM *a);
 int    BN_ucmp(const BIGNUM *a, const BIGNUM *b);
 int    BN_set_bit(BIGNUM *a, int n);
@@ -417,13 +402,6 @@ int        BN_is_prime_fasttest(const BIGNUM *p,int nchecks,
                int do_trial_division);
 void   ERR_load_BN_strings(void );
 
-BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w);
-BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w);
-void     bn_sqr_words(BN_ULONG *rp, BN_ULONG *ap, int num);
-BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d);
-BN_ULONG bn_add_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int num);
-BN_ULONG bn_sub_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int num);
-
 BN_MONT_CTX *BN_MONT_CTX_new(void );
 void BN_MONT_CTX_init(BN_MONT_CTX *ctx);
 int BN_mod_mul_montgomery(BIGNUM *r,BIGNUM *a,BIGNUM *b,BN_MONT_CTX *mont,
@@ -453,6 +431,39 @@ int        BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
 int    BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m,
                BN_RECP_CTX *recp, BN_CTX *ctx);
 
+/* library internal functions */
+
+#define bn_expand(a,bits) ((((((bits+BN_BITS2-1))/BN_BITS2)) <= (a)->max)?\
+       (a):bn_expand2((a),(bits)/BN_BITS2+1))
+#define bn_wexpand(a,words) (((words) <= (a)->max)?(a):bn_expand2((a),(words)))
+BIGNUM *bn_expand2(BIGNUM *a, int words);
+
+#define bn_fix_top(a) \
+        { \
+        BN_ULONG *ftl; \
+       if ((a)->top > 0) \
+               { \
+               for (ftl= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) \
+               if (*(ftl--)) break; \
+               } \
+       }
+
+BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w);
+BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w);
+void     bn_sqr_words(BN_ULONG *rp, BN_ULONG *ap, int num);
+BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d);
+BN_ULONG bn_add_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int num);
+BN_ULONG bn_sub_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int num);
+
+#ifdef BN_DEBUG
+  void bn_dump1(FILE *o, const char *a, BN_ULONG *b,int n);
+# define bn_print(a) {fprintf(stderr, #a "="); BN_print_fp(stderr,a); \
+   fprintf(stderr,"\n");}
+# define bn_dump(a,n) bn_dump1(stderr,#a,a,n);
+#else
+# define bn_print(a)
+# define bn_dump(a,b)
+#endif
 
 /* BEGIN ERROR CODES */
 /* The following lines are auto generated by the script mkerr.pl. Any changes