More tweaks for comments due indent issues
[openssl.git] / crypto / bn / bn.h
index 5897d2b314d08a0fe76bbe320e91536d46c6bc02..0a735d9f1edaf389e6fcdfa7ed59b9a5318deb2c 100644 (file)
@@ -257,16 +257,22 @@ extern "C" {
 
 #define BN_FLG_MALLOCED                0x01
 #define BN_FLG_STATIC_DATA     0x02
-#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) */
+/*
+ * 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.
+ */
+#define BN_FLG_CONSTTIME       0x04 
+
+#ifdef OPENSSL_NO_DEPRECATED
+/* deprecated name for the flag */
+#define BN_FLG_EXP_CONSTTIME BN_FLG_CONSTTIME 
+/*
+ * avoid leaking exponent information through timings
+ * (BN_mod_exp_mont() will call BN_mod_exp_mont_consttime)
+ */
 #endif
 
 #ifndef OPENSSL_NO_DEPRECATED
@@ -520,6 +526,8 @@ BIGNUM *BN_mod_inverse(BIGNUM *ret,
 BIGNUM *BN_mod_sqrt(BIGNUM *ret,
        const BIGNUM *a, const BIGNUM *n,BN_CTX *ctx);
 
+void   BN_consttime_swap(BN_ULONG swap, BIGNUM *a, BIGNUM *b, int nwords);
+
 /* Deprecated versions */
 #ifndef OPENSSL_NO_DEPRECATED
 BIGNUM *BN_generate_prime(BIGNUM *ret,int bits,int safe,
@@ -616,45 +624,62 @@ int       BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m,
  * be expanded to the appropriate size if needed.
  */
 
-int    BN_GF2m_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); /*r = a + b*/
+/*r = a + b*/
+int    BN_GF2m_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
 #define BN_GF2m_sub(r, a, b) BN_GF2m_add(r, a, b)
-int    BN_GF2m_mod(BIGNUM *r, const BIGNUM *a, const BIGNUM *p); /*r=a mod p*/
+/*r=a mod p*/
+int    BN_GF2m_mod(BIGNUM *r, const BIGNUM *a, const BIGNUM *p);
+/* r = (a * b) mod p */
 int    BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
-       const BIGNUM *p, BN_CTX *ctx); /* r = (a * b) mod p */
+       const BIGNUM *p, BN_CTX *ctx);
+/* r = (a * a) mod p */
 int    BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
-       BN_CTX *ctx); /* r = (a * a) mod p */
+       BN_CTX *ctx);
+/* r = (1 / b) mod p */
 int    BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *b, const BIGNUM *p,
-       BN_CTX *ctx); /* r = (1 / b) mod p */
+       BN_CTX *ctx);
+/* r = (a / b) mod p */
 int    BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
-       const BIGNUM *p, BN_CTX *ctx); /* r = (a / b) mod p */
+       const BIGNUM *p, BN_CTX *ctx);
+/* r = (a ^ b) mod p */
 int    BN_GF2m_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
-       const BIGNUM *p, BN_CTX *ctx); /* r = (a ^ b) mod p */
+       const BIGNUM *p, BN_CTX *ctx); 
+/* r = sqrt(a) mod p */
 int    BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
-       BN_CTX *ctx); /* r = sqrt(a) mod p */
+       BN_CTX *ctx);
+/* r^2 + r = a mod p */
 int    BN_GF2m_mod_solve_quad(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
-       BN_CTX *ctx); /* r^2 + r = a mod p */
+       BN_CTX *ctx);
 #define BN_GF2m_cmp(a, b) BN_ucmp((a), (b))
-/* Some functions allow for representation of the irreducible polynomials
+/*-
+ * Some functions allow for representation of the irreducible polynomials
  * as an unsigned int[], say p.  The irreducible f(t) is then of the form:
  *     t^p[0] + t^p[1] + ... + t^p[k]
  * where m = p[0] > p[1] > ... > p[k] = 0.
  */
+/* r = a mod p */
 int    BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const int p[]);
-       /* r = a mod p */
+/* r = (a * b) mod p */
 int    BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
-       const int p[], BN_CTX *ctx); /* r = (a * b) mod p */
+       const int p[], BN_CTX *ctx);
+/* r = (a * a) mod p */
 int    BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const int p[],
-       BN_CTX *ctx); /* r = (a * a) mod p */
+       BN_CTX *ctx);
+/* r = (1 / b) mod p */
 int    BN_GF2m_mod_inv_arr(BIGNUM *r, const BIGNUM *b, const int p[],
-       BN_CTX *ctx); /* r = (1 / b) mod p */
+       BN_CTX *ctx);
+/* r = (a / b) mod p */
 int    BN_GF2m_mod_div_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
-       const int p[], BN_CTX *ctx); /* r = (a / b) mod p */
+       const int p[], BN_CTX *ctx);
+/* r = (a ^ b) mod p */
 int    BN_GF2m_mod_exp_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
-       const int p[], BN_CTX *ctx); /* r = (a ^ b) mod p */
+       const int p[], BN_CTX *ctx);
+/* r = sqrt(a) mod p */
 int    BN_GF2m_mod_sqrt_arr(BIGNUM *r, const BIGNUM *a,
-       const int p[], BN_CTX *ctx); /* r = sqrt(a) mod p */
+       const int p[], BN_CTX *ctx);
+/* r^2 + r = a mod p */
 int    BN_GF2m_mod_solve_quad_arr(BIGNUM *r, const BIGNUM *a,
-       const int p[], BN_CTX *ctx); /* r^2 + r = a mod p */
+       const int p[], BN_CTX *ctx);
 int    BN_GF2m_poly2arr(const BIGNUM *a, int p[], int max);
 int    BN_GF2m_arr2poly(const int p[], BIGNUM *a);
 
@@ -684,7 +709,8 @@ BIGNUM *bn_expand2(BIGNUM *a, int words);
 BIGNUM *bn_dup_expand(const BIGNUM *a, int words); /* unused */
 #endif
 
-/* Bignum consistency macros
+/*-
+ * Bignum consistency macros
  * There is one "API" macro, bn_fix_top(), for stripping leading zeroes from
  * bignum data after direct manipulations on the data. There is also an
  * "internal" macro, bn_check_top(), for verifying that there are no leading
@@ -756,11 +782,22 @@ int RAND_pseudo_bytes(unsigned char *buf,int num);
 
 #define bn_fix_top(a)          bn_check_top(a)
 
+#define bn_check_size(bn, bits) bn_wcheck_size(bn, ((bits+BN_BITS2-1))/BN_BITS2)
+#define bn_wcheck_size(bn, words) \
+       do { \
+               const BIGNUM *_bnum2 = (bn); \
+               assert((words) <= (_bnum2)->dmax && (words) >= (_bnum2)->top); \
+               /* avoid unused variable warning with NDEBUG */ \
+               (void)(_bnum2); \
+       } while(0)
+
 #else /* !BN_DEBUG */
 
 #define bn_pollute(a)
 #define bn_check_top(a)
 #define bn_fix_top(a)          bn_correct_top(a)
+#define bn_check_size(bn, bits)
+#define bn_wcheck_size(bn, words)
 
 #endif