Add secure DSA nonce flag.
[openssl.git] / crypto / bn / bn.h
index 65202ae9f2d6436f028c583b5245411c780b07cf..7c23c01c2f7f4e2e8809dcd2f57836ccc2bda74a 100644 (file)
 #ifndef OPENSSL_NO_FP_API
 #include <stdio.h> /* FILE */
 #endif
-#include <openssl/crypto.h>
 #include <openssl/ossl_typ.h>
+#include <openssl/crypto.h>
 
 #ifdef  __cplusplus
 extern "C" {
@@ -416,10 +416,10 @@ BIGNUM *BN_CTX_get(BN_CTX *ctx);
 void   BN_CTX_end(BN_CTX *ctx);
 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, BIGNUM *range);
-int    BN_pseudo_rand_range(BIGNUM *rnd, BIGNUM *range);
+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);
-int    BN_num_bits_word(BN_ULONG);
+int    BN_num_bits_word(BN_ULONG l);
 BIGNUM *BN_new(void);
 void   BN_init(BIGNUM *);
 void   BN_clear_free(BIGNUM *a);
@@ -540,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,
@@ -569,8 +580,7 @@ int BN_BLINDING_invert_ex(BIGNUM *n, const BIGNUM *r, BN_BLINDING *b, BN_CTX *);
 unsigned long BN_BLINDING_get_thread_id(const BN_BLINDING *);
 void BN_BLINDING_set_thread_id(BN_BLINDING *, unsigned long);
 #endif
-void BN_BLINDING_set_thread(BN_BLINDING *);
-int BN_BLINDING_cmp_thread(const BN_BLINDING *, const CRYPTO_THREADID *);
+CRYPTO_THREADID *BN_BLINDING_thread_id(BN_BLINDING *);
 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,
@@ -595,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
@@ -646,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);
@@ -660,6 +674,12 @@ 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);
+
+int BN_generate_dsa_nonce(BIGNUM *out, const BIGNUM *range, const BIGNUM *priv,
+                         const unsigned char *message, size_t message_len,
+                         BN_CTX *ctx);
+
 /* library internal functions */
 
 #define bn_expand(a,bits) ((((((bits+BN_BITS2-1))/BN_BITS2)) <= (a)->dmax)?\
@@ -753,10 +773,12 @@ int RAND_pseudo_bytes(unsigned char *buf,int num);
 #define bn_correct_top(a) \
         { \
         BN_ULONG *ftl; \
-       if ((a)->top > 0) \
+       int tmp_top = (a)->top; \
+       if (tmp_top > 0) \
                { \
-               for (ftl= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) \
-               if (*(ftl--)) break; \
+               for (ftl= &((a)->d[tmp_top-1]); tmp_top > 0; tmp_top--) \
+                       if (*(ftl--)) break; \
+               (a)->top = tmp_top; \
                } \
        bn_pollute(a); \
        }
@@ -808,6 +830,8 @@ void ERR_load_BN_strings(void);
 #define BN_F_BN_EXP                                     123
 #define BN_F_BN_EXPAND2                                         108
 #define BN_F_BN_EXPAND_INTERNAL                                 120
+#define BN_F_BN_GENERATE_DSA_NONCE                      140
+#define BN_F_BN_GENERATE_PRIME_EX                       141
 #define BN_F_BN_GF2M_MOD                                131
 #define BN_F_BN_GF2M_MOD_EXP                            132
 #define BN_F_BN_GF2M_MOD_MUL                            133
@@ -836,6 +860,7 @@ void ERR_load_BN_strings(void);
 #define BN_R_ARG2_LT_ARG3                               100
 #define BN_R_BAD_RECIPROCAL                             101
 #define BN_R_BIGNUM_TOO_LONG                            114
+#define BN_R_BITS_TOO_SMALL                             118
 #define BN_R_CALLED_WITH_EVEN_MODULUS                   102
 #define BN_R_DIV_BY_ZERO                                103
 #define BN_R_ENCODING_ERROR                             104
@@ -847,6 +872,7 @@ void ERR_load_BN_strings(void);
 #define BN_R_NOT_INITIALIZED                            107
 #define BN_R_NO_INVERSE                                         108
 #define BN_R_NO_SOLUTION                                116
+#define BN_R_PRIVATE_KEY_TOO_LARGE                      117
 #define BN_R_P_IS_NOT_PRIME                             112
 #define BN_R_TOO_MANY_ITERATIONS                        113
 #define BN_R_TOO_MANY_TEMPORARY_VARIABLES               109