diff options
Diffstat (limited to 'src/lib/libcrypto/bn/bn_lcl.h')
-rw-r--r-- | src/lib/libcrypto/bn/bn_lcl.h | 114 |
1 files changed, 58 insertions, 56 deletions
diff --git a/src/lib/libcrypto/bn/bn_lcl.h b/src/lib/libcrypto/bn/bn_lcl.h index 27ac4397a1..a84998f2bd 100644 --- a/src/lib/libcrypto/bn/bn_lcl.h +++ b/src/lib/libcrypto/bn/bn_lcl.h | |||
@@ -119,6 +119,20 @@ extern "C" { | |||
119 | #endif | 119 | #endif |
120 | 120 | ||
121 | 121 | ||
122 | /* Used for temp variables */ | ||
123 | #define BN_CTX_NUM 32 | ||
124 | #define BN_CTX_NUM_POS 12 | ||
125 | struct bignum_ctx | ||
126 | { | ||
127 | int tos; | ||
128 | BIGNUM bn[BN_CTX_NUM]; | ||
129 | int flags; | ||
130 | int depth; | ||
131 | int pos[BN_CTX_NUM_POS]; | ||
132 | int too_many; | ||
133 | } /* BN_CTX */; | ||
134 | |||
135 | |||
122 | /* | 136 | /* |
123 | * BN_window_bits_for_exponent_size -- macro for sliding window mod_exp functions | 137 | * BN_window_bits_for_exponent_size -- macro for sliding window mod_exp functions |
124 | * | 138 | * |
@@ -270,15 +284,6 @@ extern "C" { | |||
270 | : "a"(a),"g"(b) \ | 284 | : "a"(a),"g"(b) \ |
271 | : "cc"); | 285 | : "cc"); |
272 | # endif | 286 | # endif |
273 | # elif (defined(_M_AMD64) || defined(_M_X64)) && defined(SIXTY_FOUR_BIT) | ||
274 | # if defined(_MSC_VER) && _MSC_VER>=1400 | ||
275 | unsigned __int64 __umulh (unsigned __int64 a,unsigned __int64 b); | ||
276 | unsigned __int64 _umul128 (unsigned __int64 a,unsigned __int64 b, | ||
277 | unsigned __int64 *h); | ||
278 | # pragma intrinsic(__umulh,_umul128) | ||
279 | # define BN_UMULT_HIGH(a,b) __umulh((a),(b)) | ||
280 | # define BN_UMULT_LOHI(low,high,a,b) ((low)=_umul128((a),(b),&(high))) | ||
281 | # endif | ||
282 | # endif /* cpu */ | 287 | # endif /* cpu */ |
283 | #endif /* OPENSSL_NO_ASM */ | 288 | #endif /* OPENSSL_NO_ASM */ |
284 | 289 | ||
@@ -288,18 +293,45 @@ extern "C" { | |||
288 | #define Lw(t) (((BN_ULONG)(t))&BN_MASK2) | 293 | #define Lw(t) (((BN_ULONG)(t))&BN_MASK2) |
289 | #define Hw(t) (((BN_ULONG)((t)>>BN_BITS2))&BN_MASK2) | 294 | #define Hw(t) (((BN_ULONG)((t)>>BN_BITS2))&BN_MASK2) |
290 | 295 | ||
291 | #ifdef BN_DEBUG_RAND | 296 | /* This is used for internal error checking and is not normally used */ |
292 | #define bn_clear_top2max(a) \ | 297 | #ifdef BN_DEBUG |
293 | { \ | 298 | # include <assert.h> |
294 | int ind = (a)->dmax - (a)->top; \ | 299 | # define bn_check_top(a) assert ((a)->top >= 0 && (a)->top <= (a)->dmax); |
295 | BN_ULONG *ftl = &(a)->d[(a)->top-1]; \ | 300 | #else |
296 | for (; ind != 0; ind--) \ | 301 | # define bn_check_top(a) |
297 | *(++ftl) = 0x0; \ | 302 | #endif |
298 | } | 303 | |
304 | /* This macro is to add extra stuff for development checking */ | ||
305 | #ifdef BN_DEBUG | ||
306 | #define bn_set_max(r) ((r)->max=(r)->top,BN_set_flags((r),BN_FLG_STATIC_DATA)) | ||
299 | #else | 307 | #else |
300 | #define bn_clear_top2max(a) | 308 | #define bn_set_max(r) |
301 | #endif | 309 | #endif |
302 | 310 | ||
311 | /* These macros are used to 'take' a section of a bignum for read only use */ | ||
312 | #define bn_set_low(r,a,n) \ | ||
313 | { \ | ||
314 | (r)->top=((a)->top > (n))?(n):(a)->top; \ | ||
315 | (r)->d=(a)->d; \ | ||
316 | (r)->neg=(a)->neg; \ | ||
317 | (r)->flags|=BN_FLG_STATIC_DATA; \ | ||
318 | bn_set_max(r); \ | ||
319 | } | ||
320 | |||
321 | #define bn_set_high(r,a,n) \ | ||
322 | { \ | ||
323 | if ((a)->top > (n)) \ | ||
324 | { \ | ||
325 | (r)->top=(a)->top-n; \ | ||
326 | (r)->d= &((a)->d[n]); \ | ||
327 | } \ | ||
328 | else \ | ||
329 | (r)->top=0; \ | ||
330 | (r)->neg=(a)->neg; \ | ||
331 | (r)->flags|=BN_FLG_STATIC_DATA; \ | ||
332 | bn_set_max(r); \ | ||
333 | } | ||
334 | |||
303 | #ifdef BN_LLONG | 335 | #ifdef BN_LLONG |
304 | #define mul_add(r,a,w,c) { \ | 336 | #define mul_add(r,a,w,c) { \ |
305 | BN_ULLONG t; \ | 337 | BN_ULLONG t; \ |
@@ -322,33 +354,6 @@ extern "C" { | |||
322 | (r1)=Hw(t); \ | 354 | (r1)=Hw(t); \ |
323 | } | 355 | } |
324 | 356 | ||
325 | #elif defined(BN_UMULT_LOHI) | ||
326 | #define mul_add(r,a,w,c) { \ | ||
327 | BN_ULONG high,low,ret,tmp=(a); \ | ||
328 | ret = (r); \ | ||
329 | BN_UMULT_LOHI(low,high,w,tmp); \ | ||
330 | ret += (c); \ | ||
331 | (c) = (ret<(c))?1:0; \ | ||
332 | (c) += high; \ | ||
333 | ret += low; \ | ||
334 | (c) += (ret<low)?1:0; \ | ||
335 | (r) = ret; \ | ||
336 | } | ||
337 | |||
338 | #define mul(r,a,w,c) { \ | ||
339 | BN_ULONG high,low,ret,ta=(a); \ | ||
340 | BN_UMULT_LOHI(low,high,w,ta); \ | ||
341 | ret = low + (c); \ | ||
342 | (c) = high; \ | ||
343 | (c) += (ret<low)?1:0; \ | ||
344 | (r) = ret; \ | ||
345 | } | ||
346 | |||
347 | #define sqr(r0,r1,a) { \ | ||
348 | BN_ULONG tmp=(a); \ | ||
349 | BN_UMULT_LOHI(r0,r1,tmp,tmp); \ | ||
350 | } | ||
351 | |||
352 | #elif defined(BN_UMULT_HIGH) | 357 | #elif defined(BN_UMULT_HIGH) |
353 | #define mul_add(r,a,w,c) { \ | 358 | #define mul_add(r,a,w,c) { \ |
354 | BN_ULONG high,low,ret,tmp=(a); \ | 359 | BN_ULONG high,low,ret,tmp=(a); \ |
@@ -467,21 +472,18 @@ void bn_sqr_comba4(BN_ULONG *r,const BN_ULONG *a); | |||
467 | int bn_cmp_words(const BN_ULONG *a,const BN_ULONG *b,int n); | 472 | int bn_cmp_words(const BN_ULONG *a,const BN_ULONG *b,int n); |
468 | int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b, | 473 | int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b, |
469 | int cl, int dl); | 474 | int cl, int dl); |
470 | void bn_mul_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,int n2, | 475 | #ifdef BN_RECURSION |
471 | int dna,int dnb,BN_ULONG *t); | 476 | void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2, |
472 | void bn_mul_part_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b, | 477 | BN_ULONG *t); |
473 | int n,int tna,int tnb,BN_ULONG *t); | 478 | void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int tn, |
474 | void bn_sqr_recursive(BN_ULONG *r,const BN_ULONG *a, int n2, BN_ULONG *t); | 479 | int n, BN_ULONG *t); |
475 | void bn_mul_low_normal(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b, int n); | ||
476 | void bn_mul_low_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,int n2, | 480 | void bn_mul_low_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,int n2, |
477 | BN_ULONG *t); | 481 | BN_ULONG *t); |
478 | void bn_mul_high(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,BN_ULONG *l,int n2, | 482 | void bn_mul_high(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,BN_ULONG *l,int n2, |
479 | BN_ULONG *t); | 483 | BN_ULONG *t); |
480 | BN_ULONG bn_add_part_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, | 484 | void bn_sqr_recursive(BN_ULONG *r,const BN_ULONG *a, int n2, BN_ULONG *t); |
481 | int cl, int dl); | 485 | #endif |
482 | BN_ULONG bn_sub_part_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, | 486 | void bn_mul_low_normal(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b, int n); |
483 | int cl, int dl); | ||
484 | int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np,const BN_ULONG *n0, int num); | ||
485 | 487 | ||
486 | #ifdef __cplusplus | 488 | #ifdef __cplusplus |
487 | } | 489 | } |