Expand expspeed.c to make BN_kronecker timings.
[openssl.git] / crypto / bn / bn.h
index 0a665c25384ccc1708bcb7851bde8fef337989be..c81f3de8be90ecbe5a64bbdb1770c5bf5f394752 100644 (file)
@@ -304,10 +304,15 @@ typedef struct bn_recp_ctx_st
                                 /* b >= 100 */ 27)
 
 #define BN_num_bytes(a)        ((BN_num_bits(a)+7)/8)
-#define BN_is_word(a,w)        (((a)->top == 1) && ((a)->d[0] == (BN_ULONG)(w)))
-#define BN_is_zero(a)  (((a)->top == 0) || BN_is_word(a,0))
-#define BN_is_one(a)   (BN_is_word((a),1))
-#define BN_is_odd(a)   (((a)->top > 0) && ((a)->d[0] & 1))
+
+/* Note that BN_abs_is_word does not work reliably for w == 0 */
+#define BN_abs_is_word(a,w) (((a)->top == 1) && ((a)->d[0] == (BN_ULONG)(w)))
+#define BN_is_zero(a)       (((a)->top == 0) || BN_abs_is_word(a,0))
+#define BN_is_one(a)        (BN_abs_is_word((a),1) && !(a)->neg)
+#define BN_is_word(a,w)     ((w) ? BN_abs_is_word((a),(w)) && !(a)->neg : \
+                                   BN_is_zero((a)))
+#define BN_is_odd(a)       (((a)->top > 0) && ((a)->d[0] & 1))
+
 #define BN_one(a)      (BN_set_word((a),1))
 #define BN_zero(a)     (BN_set_word((a),0))
 
@@ -341,12 +346,22 @@ int       BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
 int    BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
 int    BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
 int    BN_sqr(BIGNUM *r, const BIGNUM *a,BN_CTX *ctx);
+
 int    BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d,
        BN_CTX *ctx);
 #define BN_mod(rem,m,d,ctx) BN_div(NULL,(rem),(m),(d),(ctx))
-int    BN_nnmod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx);
-int    BN_mod_mul(BIGNUM *ret, const BIGNUM *a, const BIGNUM *b,
+int    BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx);
+int    BN_mod_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx);
+int    BN_mod_add_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m);
+int    BN_mod_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx);
+int    BN_mod_sub_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m);
+int    BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
        const BIGNUM *m, BN_CTX *ctx);
+int    BN_mod_lshift1(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
+int    BN_mod_lshift1_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *m);
+int    BN_mod_lshift(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m, BN_CTX *ctx);
+int    BN_mod_lshift_quick(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m);
+
 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);
@@ -354,12 +369,14 @@ int       BN_add_word(BIGNUM *a, BN_ULONG 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);
+
 int    BN_cmp(const BIGNUM *a, const BIGNUM *b);
 void   BN_free(BIGNUM *a);
 int    BN_is_bit_set(const BIGNUM *a, int n);
 int    BN_lshift(BIGNUM *r, const BIGNUM *a, int n);
 int    BN_lshift1(BIGNUM *r, const BIGNUM *a);
 int    BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,BN_CTX *ctx);
+
 int    BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
        const BIGNUM *m,BN_CTX *ctx);
 int    BN_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
@@ -371,6 +388,7 @@ int BN_mod_exp2_mont(BIGNUM *r, const BIGNUM *a1, const BIGNUM *p1,
        BN_CTX *ctx,BN_MONT_CTX *m_ctx);
 int    BN_mod_exp_simple(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
        const BIGNUM *m,BN_CTX *ctx);
+
 int    BN_mask_bits(BIGNUM *a,int n);
 #ifndef NO_FP_API
 int    BN_print_fp(FILE *fp, const BIGNUM *a);
@@ -392,7 +410,8 @@ char *      BN_bn2hex(const BIGNUM *a);
 char * BN_bn2dec(const BIGNUM *a);
 int    BN_hex2bn(BIGNUM **a, const char *str);
 int    BN_dec2bn(BIGNUM **a, const char *str);
-int    BN_gcd(BIGNUM *r,const BIGNUM *in_a,const BIGNUM *in_b,BN_CTX *ctx);
+int    BN_gcd(BIGNUM *r,const BIGNUM *a,const BIGNUM *b,BN_CTX *ctx);
+int    BN_kronecker(const BIGNUM *a,const BIGNUM *b,BN_CTX *ctx); /* returns -2 for error */
 BIGNUM *BN_mod_inverse(BIGNUM *ret,
        const BIGNUM *a, const BIGNUM *n,BN_CTX *ctx);
 BIGNUM *BN_generate_prime(BIGNUM *ret,int bits,int safe,
@@ -491,10 +510,12 @@ void bn_dump1(FILE *o, const char *a, const BN_ULONG *b,int n);
 #define BN_F_BN_CTX_NEW                                         106
 #define BN_F_BN_DIV                                     107
 #define BN_F_BN_EXPAND2                                         108
+#define BN_F_BN_EXPAND_INTERNAL                                 120
 #define BN_F_BN_MOD_EXP2_MONT                           118
 #define BN_F_BN_MOD_EXP_MONT                            109
 #define BN_F_BN_MOD_EXP_MONT_WORD                       117
 #define BN_F_BN_MOD_INVERSE                             110
+#define BN_F_BN_MOD_LSHIFT_QUICK                        119
 #define BN_F_BN_MOD_MUL_RECIPROCAL                      111
 #define BN_F_BN_MPI2BN                                  112
 #define BN_F_BN_NEW                                     113
@@ -508,6 +529,7 @@ void bn_dump1(FILE *o, const char *a, const BN_ULONG *b,int n);
 #define BN_R_DIV_BY_ZERO                                103
 #define BN_R_ENCODING_ERROR                             104
 #define BN_R_EXPAND_ON_STATIC_BIGNUM_DATA               105
+#define BN_R_INPUT_NOT_REDUCED                          110
 #define BN_R_INVALID_LENGTH                             106
 #define BN_R_NOT_INITIALIZED                            107
 #define BN_R_NO_INVERSE                                         108
@@ -517,3 +539,4 @@ void bn_dump1(FILE *o, const char *a, const BN_ULONG *b,int n);
 }
 #endif
 #endif
+