Add SRP support.
[openssl.git] / crypto / bn / bn.h
index 3a8d694bb6c2b701c01e824526de2e41a1c6a7ca..0a66a2ea0c691949bd9f3c6ba6c81e72cd57cee9 100644 (file)
@@ -300,9 +300,9 @@ typedef struct bn_gencb_st BN_GENCB;
 struct bignum_st
        {
        BN_ULONG *d;    /* Pointer to an array of 'BN_BITS2' bit chunks. */
-       size_t top;     /* Index of last used d +1. */
+       int top;        /* Index of last used d +1. */
        /* The next are internal book keeping for bn_expand. */
-       size_t dmax;    /* Size of the d array. */
+       int dmax;       /* Size of the d array. */
        int neg;        /* one if the number is negative */
        int flags;
        };
@@ -414,8 +414,8 @@ void        BN_CTX_free(BN_CTX *c);
 void   BN_CTX_start(BN_CTX *ctx);
 BIGNUM *BN_CTX_get(BN_CTX *ctx);
 void   BN_CTX_end(BN_CTX *ctx);
-int     BN_rand(BIGNUM *rnd, size_t bits, int top,int bottom);
-int     BN_pseudo_rand(BIGNUM *rnd, size_t bits, int top,int bottom);
+int     BN_rand(BIGNUM *rnd, int bits, int top,int bottom);
+int     BN_pseudo_rand(BIGNUM *rnd, int bits, int top,int bottom);
 int    BN_rand_range(BIGNUM *rnd, const BIGNUM *range);
 int    BN_pseudo_rand_range(BIGNUM *rnd, const BIGNUM *range);
 int    BN_num_bits(const BIGNUM *a);
@@ -425,9 +425,9 @@ void        BN_init(BIGNUM *);
 void   BN_clear_free(BIGNUM *a);
 BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b);
 void   BN_swap(BIGNUM *a, BIGNUM *b);
-BIGNUM *BN_bin2bn(const unsigned char *s, size_t len, BIGNUM *ret);
+BIGNUM *BN_bin2bn(const unsigned char *s,int len,BIGNUM *ret);
 int    BN_bn2bin(const BIGNUM *a, unsigned char *to);
-BIGNUM *BN_mpi2bn(const unsigned char *s, size_t len, BIGNUM *ret);
+BIGNUM *BN_mpi2bn(const unsigned char *s,int len,BIGNUM *ret);
 int    BN_bn2mpi(const BIGNUM *a, unsigned char *to);
 int    BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
 int    BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
@@ -466,8 +466,6 @@ BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w);
 BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w);
 int    BN_mul_word(BIGNUM *a, BN_ULONG w);
 int    BN_add_word(BIGNUM *a, BN_ULONG w);
-/* Note that this will give an error if w is negative */
-int    BN_add_signed_word(BIGNUM *a, BN_LONG w);
 int    BN_sub_word(BIGNUM *a, BN_ULONG w);
 int    BN_set_word(BIGNUM *a, BN_ULONG w);
 BN_ULONG BN_get_word(const BIGNUM *a);
@@ -502,7 +500,7 @@ int BN_print(BIO *fp, const BIGNUM *a);
 #else
 int    BN_print(void *fp, const BIGNUM *a);
 #endif
-int    BN_reciprocal(BIGNUM *r, const BIGNUM *m, size_t len, BN_CTX *ctx);
+int    BN_reciprocal(BIGNUM *r, const BIGNUM *m, int len, BN_CTX *ctx);
 int    BN_rshift(BIGNUM *r, const BIGNUM *a, int n);
 int    BN_rshift1(BIGNUM *r, const BIGNUM *a);
 void   BN_clear(BIGNUM *a);
@@ -542,6 +540,17 @@ int        BN_is_prime_ex(const BIGNUM *p,int nchecks, BN_CTX *ctx, BN_GENCB *cb);
 int    BN_is_prime_fasttest_ex(const BIGNUM *p,int nchecks, BN_CTX *ctx,
                int do_trial_division, BN_GENCB *cb);
 
+int BN_X931_generate_Xpq(BIGNUM *Xp, BIGNUM *Xq, int nbits, BN_CTX *ctx);
+
+int BN_X931_derive_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2,
+                       const BIGNUM *Xp, const BIGNUM *Xp1, const BIGNUM *Xp2,
+                       const BIGNUM *e, BN_CTX *ctx, BN_GENCB *cb);
+int BN_X931_generate_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2,
+                       BIGNUM *Xp1, BIGNUM *Xp2,
+                       const BIGNUM *Xp,
+                       const BIGNUM *e, BN_CTX *ctx,
+                       BN_GENCB *cb);
+
 BN_MONT_CTX *BN_MONT_CTX_new(void );
 void BN_MONT_CTX_init(BN_MONT_CTX *ctx);
 int BN_mod_mul_montgomery(BIGNUM *r,const BIGNUM *a,const BIGNUM *b,
@@ -596,6 +605,8 @@ int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
 int    BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m,
        BN_RECP_CTX *recp, BN_CTX *ctx);
 
+#ifndef OPENSSL_NO_EC2M
+
 /* Functions for arithmetic over binary polynomials represented by BIGNUMs. 
  *
  * The BIGNUM::neg property of BIGNUMs representing binary polynomials is
@@ -647,6 +658,8 @@ int BN_GF2m_mod_solve_quad_arr(BIGNUM *r, const BIGNUM *a,
 int    BN_GF2m_poly2arr(const BIGNUM *a, int p[], int max);
 int    BN_GF2m_arr2poly(const int p[], BIGNUM *a);
 
+#endif
+
 /* faster mod functions for the 'NIST primes' 
  * 0 <= a < p^2 */
 int BN_nist_mod_192(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
@@ -661,14 +674,16 @@ const BIGNUM *BN_get0_nist_prime_256(void);
 const BIGNUM *BN_get0_nist_prime_384(void);
 const BIGNUM *BN_get0_nist_prime_521(void);
 
+int (*BN_nist_mod_func(const BIGNUM *p))(BIGNUM *r, const BIGNUM *a, const BIGNUM *field, BN_CTX *ctx);
+
 /* library internal functions */
 
 #define bn_expand(a,bits) ((((((bits+BN_BITS2-1))/BN_BITS2)) <= (a)->dmax)?\
        (a):bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2))
 #define bn_wexpand(a,words) (((words) <= (a)->dmax)?(a):bn_expand2((a),(words)))
-BIGNUM *bn_expand2(BIGNUM *a, size_t words);
+BIGNUM *bn_expand2(BIGNUM *a, int words);
 #ifndef OPENSSL_NO_DEPRECATED
-BIGNUM *bn_dup_expand(const BIGNUM *a, size_t words); /* unused */
+BIGNUM *bn_dup_expand(const BIGNUM *a, int words); /* unused */
 #endif
 
 /* Bignum consistency macros
@@ -754,25 +769,22 @@ int RAND_pseudo_bytes(unsigned char *buf,int num);
 #define bn_correct_top(a) \
         { \
         BN_ULONG *ftl; \
-       int _t371q = (a)->top; \
-       if (_t371q > 0) \
+       int tmp_top = (a)->top; \
+       if (tmp_top > 0) \
                { \
-               for (ftl= &((a)->d[_t371q-1]); _t371q > 0; _t371q--) \
+               for (ftl= &((a)->d[tmp_top-1]); tmp_top > 0; tmp_top--) \
                        if (*(ftl--)) break; \
-               (a)->top = _t371q; \
+               (a)->top = tmp_top; \
                } \
        bn_pollute(a); \
        }
 
-BN_ULONG bn_mul_add_words(BN_ULONG *rp, const BN_ULONG *ap, size_t num,
-                         BN_ULONG w);
-BN_ULONG bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, size_t num, BN_ULONG w);
-void     bn_sqr_words(BN_ULONG *rp, const BN_ULONG *ap, size_t num);
+BN_ULONG bn_mul_add_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w);
+BN_ULONG bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w);
+void     bn_sqr_words(BN_ULONG *rp, const 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, const BN_ULONG *ap, const BN_ULONG *bp,
-                     size_t num);
-BN_ULONG bn_sub_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
-                     size_t num);
+BN_ULONG bn_add_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,int num);
+BN_ULONG bn_sub_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,int num);
 
 /* Primes from RFC 2409 */
 BIGNUM *get_rfc2409_prime_768(BIGNUM *bn);
@@ -786,7 +798,7 @@ BIGNUM *get_rfc3526_prime_4096(BIGNUM *bn);
 BIGNUM *get_rfc3526_prime_6144(BIGNUM *bn);
 BIGNUM *get_rfc3526_prime_8192(BIGNUM *bn);
 
-int BN_bntest_rand(BIGNUM *rnd, size_t bits, int top, int bottom);
+int BN_bntest_rand(BIGNUM *rnd, int bits, int top,int bottom);
 
 /* BEGIN ERROR CODES */
 /* The following lines are auto generated by the script mkerr.pl. Any changes