Don't use assertions to check application-provided arguments;
[oweals/openssl.git] / crypto / bn / bn.h
index 2688684b63512f17b7a1f346bdda1b4e415f8fea..6d754d5547767dbcdbda979312d876e0436eec1e 100644 (file)
@@ -245,8 +245,18 @@ extern "C" {
 
 #define BN_FLG_MALLOCED                0x01
 #define BN_FLG_STATIC_DATA     0x02
-#define BN_FLG_EXP_CONSTTIME   0x04 /* avoid leaking exponent information through timings
-                                     * (BN_mod_exp_mont() will call BN_mod_exp_mont_consttime) */
+#define BN_FLG_CONSTTIME       0x04 /* avoid leaking exponent information through timing,
+                                      * BN_mod_exp_mont() will call BN_mod_exp_mont_consttime,
+                                      * BN_div() will call BN_div_no_branch,
+                                      * BN_mod_inverse() will call BN_mod_inverse_no_branch.
+                                      */
+
+#ifndef OPENSSL_NO_DEPRECATED
+#define BN_FLG_EXP_CONSTTIME BN_FLG_CONSTTIME /* deprecated name for the flag */
+                                      /* avoid leaking exponent information through timings
+                                      * (BN_mod_exp_mont() will call BN_mod_exp_mont_consttime) */
+#endif
+
 #ifndef OPENSSL_NO_DEPRECATED
 #define BN_FLG_FREE            0x8000  /* used for debuging */
 #endif
@@ -293,7 +303,12 @@ struct bn_mont_ctx_st
        BIGNUM N;      /* The modulus */
        BIGNUM Ni;     /* R*(1/R mod N) - N*Ni = 1
                        * (Ni is only stored for bignum algorithm) */
+#if 0
+       /* OpenSSL 0.9.9 preview: */
+       BN_ULONG n0[2];/* least significant word(s) of Ni */
+#else
        BN_ULONG n0;   /* least significant word of Ni */
+#endif
        int flags;
        };
 
@@ -412,9 +427,15 @@ 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);
-/* BN_set_negative(): sets sign of a bignum */
+/** BN_set_negative sets sign of a BIGNUM
+ * \param  b  pointer to the BIGNUM object
+ * \param  n  0 if the BIGNUM b should be positive and a value != 0 otherwise 
+ */
 void   BN_set_negative(BIGNUM *b, int n);
-/* BN_get_negative():  returns 1 if the bignum is < 0 and 0 otherwise */
+/** BN_is_negative returns 1 if the BIGNUM is negative
+ * \param  a  pointer to the BIGNUM object
+ * \return 1 if a < 0 and 0 otherwise
+ */
 #define BN_is_negative(a) ((a)->neg != 0)
 
 int    BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d,
@@ -528,7 +549,7 @@ BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, int lock,
 #define        BN_BLINDING_NO_UPDATE   0x00000001
 #define        BN_BLINDING_NO_RECREATE 0x00000002
 
-BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, BIGNUM *mod);
+BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, /* const */ BIGNUM *mod);
 void BN_BLINDING_free(BN_BLINDING *b);
 int BN_BLINDING_update(BN_BLINDING *b,BN_CTX *ctx);
 int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx);
@@ -540,7 +561,7 @@ void BN_BLINDING_set_thread_id(BN_BLINDING *, unsigned long);
 unsigned long BN_BLINDING_get_flags(const BN_BLINDING *);
 void BN_BLINDING_set_flags(BN_BLINDING *, unsigned long);
 BN_BLINDING *BN_BLINDING_create_param(BN_BLINDING *b,
-       const BIGNUM *e, BIGNUM *m, BN_CTX *ctx,
+       const BIGNUM *e, /* const */ BIGNUM *m, BN_CTX *ctx,
        int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
                          const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx),
        BN_MONT_CTX *m_ctx);
@@ -735,16 +756,16 @@ BN_ULONG bn_add_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,int n
 BN_ULONG bn_sub_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,int num);
 
 /* Primes from RFC 2409 */
-int get_rfc2409_prime_768(BIGNUM **bn);
-int get_rfc2409_prime_1024(BIGNUM **bn);
+BIGNUM *get_rfc2409_prime_768(BIGNUM *bn);
+BIGNUM *get_rfc2409_prime_1024(BIGNUM *bn);
 
 /* Primes from RFC 3526 */
-int get_rfc3526_prime_1536(BIGNUM **bn);
-int get_rfc3526_prime_2048(BIGNUM **bn);
-int get_rfc3526_prime_3072(BIGNUM **bn);
-int get_rfc3526_prime_4096(BIGNUM **bn);
-int get_rfc3526_prime_6144(BIGNUM **bn);
-int get_rfc3526_prime_8192(BIGNUM **bn);
+BIGNUM *get_rfc3526_prime_1536(BIGNUM *bn);
+BIGNUM *get_rfc3526_prime_2048(BIGNUM *bn);
+BIGNUM *get_rfc3526_prime_3072(BIGNUM *bn);
+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, int bits, int top,int bottom);
 
@@ -769,6 +790,7 @@ void ERR_load_BN_strings(void);
 #define BN_F_BN_CTX_NEW                                         106
 #define BN_F_BN_CTX_START                               129
 #define BN_F_BN_DIV                                     107
+#define BN_F_BN_DIV_NO_BRANCH                           138
 #define BN_F_BN_DIV_RECP                                130
 #define BN_F_BN_EXP                                     123
 #define BN_F_BN_EXPAND2                                         108
@@ -787,6 +809,7 @@ void ERR_load_BN_strings(void);
 #define BN_F_BN_MOD_EXP_RECP                            125
 #define BN_F_BN_MOD_EXP_SIMPLE                          126
 #define BN_F_BN_MOD_INVERSE                             110
+#define BN_F_BN_MOD_INVERSE_NO_BRANCH                   139
 #define BN_F_BN_MOD_LSHIFT_QUICK                        119
 #define BN_F_BN_MOD_MUL_RECIPROCAL                      111
 #define BN_F_BN_MOD_SQRT                                121