Go to the documentation of this file.
75 #if defined( INC_ALL )
104 #if defined( WIN32 ) && !defined( NDEBUG ) && 0
105 #define USE_BN_DEBUG_MALLOC
107 #ifdef USE_BN_DEBUG_MALLOC
108 #define clBnAlloc( string, size ) \
109 clBnAllocFn( __FILE__, string, __LINE__, size )
110 void *clBnAllocFn(
const char *
fileName,
const char *fnName,
111 const int lineNo,
size_t size );
113 #define clBnAlloc( string, size ) malloc( size )
115 #define OPENSSL_free free
116 #define OPENSSL_cleanse( a, b ) memset( a, 0, b )
124 #ifndef OPENSSL_NO_FP_API
159 #if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WINDOWS) || \
160 defined(OPENSSL_SYS_WIN32) || defined(linux)
169 #ifdef SIXTY_FOUR_BIT_LONG
170 #define BN_ULLONG unsigned long long
171 #define BN_ULONG unsigned long
177 #define BN_MASK (0xffffffffffffffffffffffffffffffffLL)
178 #define BN_MASK2 (0xffffffffffffffffL)
179 #define BN_MASK2l (0xffffffffL)
180 #define BN_MASK2h (0xffffffff00000000L)
181 #define BN_MASK2h1 (0xffffffff80000000L)
182 #define BN_TBIT (0x8000000000000000L)
183 #define BN_DEC_CONV (10000000000000000000UL)
184 #define BN_DEC_FMT1 "%lu"
185 #define BN_DEC_FMT2 "%019lu"
186 #define BN_DEC_NUM 19
194 #ifdef SIXTY_FOUR_BIT
197 #define BN_ULONG unsigned long long
198 #define BN_LONG long long
203 #define BN_MASK2 (0xffffffffffffffffLL)
204 #define BN_MASK2l (0xffffffffL)
205 #define BN_MASK2h (0xffffffff00000000LL)
206 #define BN_MASK2h1 (0xffffffff80000000LL)
207 #define BN_TBIT (0x8000000000000000LL)
208 #define BN_DEC_CONV (10000000000000000000ULL)
209 #define BN_DEC_FMT1 "%llu"
210 #define BN_DEC_FMT2 "%019llu"
211 #define BN_DEC_NUM 19
214 #ifdef THIRTY_TWO_BIT
216 # if defined(OPENSSL_SYS_WIN32) && !defined(__GNUC__)
217 # define BN_ULLONG unsigned __int64
219 # define BN_ULLONG unsigned long long
222 #define BN_ULONG unsigned long
228 #ifdef OPENSSL_SYS_WIN32
230 #define BN_MASK (0xffffffffffffffffL)
232 #define BN_MASK (0xffffffffffffffffLL)
234 #define BN_MASK2 (0xffffffffL)
235 #define BN_MASK2l (0xffff)
236 #define BN_MASK2h1 (0xffff8000L)
237 #define BN_MASK2h (0xffff0000L)
238 #define BN_TBIT (0x80000000L)
239 #define BN_DEC_CONV (1000000000L)
240 #define BN_DEC_FMT1 "%lu"
241 #define BN_DEC_FMT2 "%09lu"
249 #define BN_ULLONG unsigned long
250 #define BN_ULONG unsigned short
251 #define BN_LONG short
256 #define BN_MASK (0xffffffff)
257 #define BN_MASK2 (0xffff)
258 #define BN_MASK2l (0xff)
259 #define BN_MASK2h1 (0xff80)
260 #define BN_MASK2h (0xff00)
261 #define BN_TBIT (0x8000)
262 #define BN_DEC_CONV (100000)
263 #define BN_DEC_FMT1 "%u"
264 #define BN_DEC_FMT2 "%05u"
272 #define BN_ULLONG unsigned short
273 #define BN_ULONG unsigned char
279 #define BN_MASK (0xffff)
280 #define BN_MASK2 (0xff)
281 #define BN_MASK2l (0xf)
282 #define BN_MASK2h1 (0xf8)
283 #define BN_MASK2h (0xf0)
284 #define BN_TBIT (0x80)
285 #define BN_DEC_CONV (100)
286 #define BN_DEC_FMT1 "%u"
287 #define BN_DEC_FMT2 "%02u"
291 #define BN_DEFAULT_BITS 1280
293 #define BN_FLG_MALLOCED 0x01
294 #define BN_FLG_STATIC_DATA 0x02
295 #define BN_FLG_EXP_CONSTTIME 0x04
297 #ifndef OPENSSL_NO_DEPRECATED
298 #define BN_FLG_FREE 0x8000
300 #define BN_set_flags(b,n) ((b)->flags|=(n))
301 #define BN_get_flags(b,n) ((b)->flags&(n))
305 #define BN_with_flags(dest,b,n) ((dest)->d=(b)->d, \
306 (dest)->top=(b)->top, \
307 (dest)->dmax=(b)->dmax, \
308 (dest)->neg=(b)->neg, \
309 (dest)->flags=(((dest)->flags & BN_FLG_MALLOCED) \
310 | ((b)->flags & ~BN_FLG_MALLOCED) \
311 | BN_FLG_STATIC_DATA \
367 void (*
cb_1)(int, int,
void *);
375 #define BN_GENCB_set_old(gencb, callback, cb_arg) { \
376 BN_GENCB *tmp_gencb = (gencb); \
377 tmp_gencb->ver = 1; \
378 tmp_gencb->arg = (cb_arg); \
379 tmp_gencb->cb.cb_1 = (callback); }
381 #define BN_GENCB_set(gencb, callback, cb_arg) { \
382 BN_GENCB *tmp_gencb = (gencb); \
383 tmp_gencb->ver = 2; \
384 tmp_gencb->arg = (cb_arg); \
385 tmp_gencb->cb.cb_2 = (callback); }
387 #define BN_prime_checks 0
395 #define BN_prime_checks_for_size(b) ((b) >= 1300 ? 2 : \
408 #define BN_num_bytes(a) ((BN_num_bits(a)+7)/8)
411 #define BN_abs_is_word(a,w) ((((a)->top == 1) && ((a)->d[0] == (BN_ULONG)(w))) || \
412 (((w) == 0) && ((a)->top == 0)))
413 #define BN_is_zero(a) ((a)->top == 0)
414 #define BN_is_one(a) (BN_abs_is_word((a),1) && !(a)->neg)
415 #define BN_is_word(a,w) (BN_abs_is_word((a),(w)) && (!(w) || !(a)->neg))
416 #define BN_is_odd(a) (((a)->top > 0) && ((a)->d[0] & 1))
418 #define BN_one(a) (BN_set_word((a),1))
419 #define BN_zero_ex(a) \
421 BIGNUM *_tmp_bn = (a); \
425 #ifdef OPENSSL_NO_DEPRECATED
426 #define BN_zero(a) BN_zero_ex(a)
428 #define BN_zero(a) (BN_set_word((a),0))
434 #ifndef OPENSSL_NO_DEPRECATED
465 #define BN_is_negative(a) ((a)->neg != 0)
469 #define BN_mod(rem,m,d,ctx) BN_div(NULL,(rem),(m),(d),(ctx))
513 #ifndef OPENSSL_NO_FP_API
541 #ifndef OPENSSL_NO_DEPRECATED
544 void (*callback)(
int,
int,
void *),
void *cb_arg);
546 void (*callback)(
int,
int,
void *),
547 BN_CTX *ctx,
void *cb_arg);
549 void (*callback)(
int,
int,
void *),
BN_CTX *ctx,
void *cb_arg,
550 int do_trial_division);
558 int do_trial_division,
BN_GENCB *cb);
564 #define BN_to_montgomery(r,a,mont,ctx) BN_mod_mul_montgomery(\
565 (r),(a),&((mont)->RR),(mont),(ctx))
575 #define BN_BLINDING_NO_UPDATE 0x00000001
576 #define BN_BLINDING_NO_RECREATE 0x00000002
595 #ifndef OPENSSL_NO_DEPRECATED
625 #define BN_GF2m_sub(r, a, b) BN_GF2m_add(r, a, b)
641 #define BN_GF2m_cmp(a, b) BN_ucmp((a), (b))
650 const unsigned int p[],
BN_CTX *ctx);
656 const unsigned int p[],
BN_CTX *ctx);
658 const unsigned int p[],
BN_CTX *ctx);
660 const unsigned int p[],
BN_CTX *ctx);
662 const unsigned int p[],
BN_CTX *ctx);
682 #define bn_expand(a,bits) ((((((bits+BN_BITS2-1))/BN_BITS2)) <= (a)->dmax)?\
683 (a):bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2))
684 #define bn_wexpand(a,words) (((words) <= (a)->dmax)?(a):bn_expand2((a),(words)))
686 #ifndef OPENSSL_NO_DEPRECATED
725 #ifndef RAND_pseudo_bytes
726 int RAND_pseudo_bytes(
unsigned char *buf,
int num);
727 #define BN_DEBUG_TRIX
729 #define bn_pollute(a) \
731 const BIGNUM *_bnum1 = (a); \
732 if(_bnum1->top < _bnum1->dmax) { \
733 unsigned char _tmp_char; \
737 BN_ULONG *_not_const; \
738 memcpy(&_not_const, &_bnum1->d, sizeof(BN_ULONG*)); \
739 RAND_pseudo_bytes(&_tmp_char, 1); \
740 memset((unsigned char *)(_not_const + _bnum1->top), _tmp_char, \
741 (_bnum1->dmax - _bnum1->top) * sizeof(BN_ULONG)); \
745 #undef RAND_pseudo_bytes
748 #define bn_pollute(a)
750 #define bn_check_top(a) \
752 const BIGNUM *_bnum2 = (a); \
753 assert((_bnum2->top == 0) || \
754 (_bnum2->d[_bnum2->top - 1] != 0)); \
755 bn_pollute(_bnum2); \
758 #define bn_fix_top(a) bn_check_top(a)
762 #define bn_pollute(a)
763 #define bn_check_top(a)
764 #define bn_fix_top(a) bn_correct_top(a)
768 #define bn_correct_top(a) \
773 for (ftl= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) \
774 if (*(ftl--)) break; \
797 #define BN_F_BNRAND 127
798 #define BN_F_BN_BLINDING_CONVERT_EX 100
799 #define BN_F_BN_BLINDING_CREATE_PARAM 128
800 #define BN_F_BN_BLINDING_INVERT_EX 101
801 #define BN_F_BN_BLINDING_NEW 102
802 #define BN_F_BN_BLINDING_UPDATE 103
803 #define BN_F_BN_BN2DEC 104
804 #define BN_F_BN_BN2HEX 105
805 #define BN_F_BN_CTX_GET 116
806 #define BN_F_BN_CTX_NEW 106
807 #define BN_F_BN_CTX_START 129
808 #define BN_F_BN_DIV 107
809 #define BN_F_BN_DIV_RECP 130
810 #define BN_F_BN_EXP 123
811 #define BN_F_BN_EXPAND2 108
812 #define BN_F_BN_EXPAND_INTERNAL 120
813 #define BN_F_BN_GF2M_MOD 131
814 #define BN_F_BN_GF2M_MOD_EXP 132
815 #define BN_F_BN_GF2M_MOD_MUL 133
816 #define BN_F_BN_GF2M_MOD_SOLVE_QUAD 134
817 #define BN_F_BN_GF2M_MOD_SOLVE_QUAD_ARR 135
818 #define BN_F_BN_GF2M_MOD_SQR 136
819 #define BN_F_BN_GF2M_MOD_SQRT 137
820 #define BN_F_BN_MOD_EXP2_MONT 118
821 #define BN_F_BN_MOD_EXP_MONT 109
822 #define BN_F_BN_MOD_EXP_MONT_CONSTTIME 124
823 #define BN_F_BN_MOD_EXP_MONT_WORD 117
824 #define BN_F_BN_MOD_EXP_RECP 125
825 #define BN_F_BN_MOD_EXP_SIMPLE 126
826 #define BN_F_BN_MOD_INVERSE 110
827 #define BN_F_BN_MOD_LSHIFT_QUICK 119
828 #define BN_F_BN_MOD_MUL_RECIPROCAL 111
829 #define BN_F_BN_MOD_SQRT 121
830 #define BN_F_BN_MPI2BN 112
831 #define BN_F_BN_NEW 113
832 #define BN_F_BN_RAND 114
833 #define BN_F_BN_RAND_RANGE 122
834 #define BN_F_BN_USUB 115
837 #define BN_R_ARG2_LT_ARG3 100
838 #define BN_R_BAD_RECIPROCAL 101
839 #define BN_R_BIGNUM_TOO_LONG 114
840 #define BN_R_CALLED_WITH_EVEN_MODULUS 102
841 #define BN_R_DIV_BY_ZERO 103
842 #define BN_R_ENCODING_ERROR 104
843 #define BN_R_EXPAND_ON_STATIC_BIGNUM_DATA 105
844 #define BN_R_INPUT_NOT_REDUCED 110
845 #define BN_R_INVALID_LENGTH 106
846 #define BN_R_INVALID_RANGE 115
847 #define BN_R_NOT_A_SQUARE 111
848 #define BN_R_NOT_INITIALIZED 107
849 #define BN_R_NO_INVERSE 108
850 #define BN_R_NO_SOLUTION 116
851 #define BN_R_P_IS_NOT_PRIME 112
852 #define BN_R_TOO_MANY_ITERATIONS 113
853 #define BN_R_TOO_MANY_TEMPORARY_VARIABLES 109