diff options
| author | djm <> | 2008-09-06 12:17:54 +0000 |
|---|---|---|
| committer | djm <> | 2008-09-06 12:17:54 +0000 |
| commit | 6b62d1fdd8a4fd35acfcc0c4bb1bf8b757fa8cda (patch) | |
| tree | 7ccc28afe1789ea3dbedf72365f955d5b8e105b5 /src/lib/libcrypto/bn/bn_lcl.h | |
| parent | 89181603212b41e95cde36b1be5a146ce8fb2935 (diff) | |
| download | openbsd-6b62d1fdd8a4fd35acfcc0c4bb1bf8b757fa8cda.tar.gz openbsd-6b62d1fdd8a4fd35acfcc0c4bb1bf8b757fa8cda.tar.bz2 openbsd-6b62d1fdd8a4fd35acfcc0c4bb1bf8b757fa8cda.zip | |
resolve conflicts
Diffstat (limited to 'src/lib/libcrypto/bn/bn_lcl.h')
| -rw-r--r-- | src/lib/libcrypto/bn/bn_lcl.h | 114 |
1 files changed, 56 insertions, 58 deletions
diff --git a/src/lib/libcrypto/bn/bn_lcl.h b/src/lib/libcrypto/bn/bn_lcl.h index a84998f2bd..27ac4397a1 100644 --- a/src/lib/libcrypto/bn/bn_lcl.h +++ b/src/lib/libcrypto/bn/bn_lcl.h | |||
| @@ -119,20 +119,6 @@ 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 | |||
| 136 | /* | 122 | /* |
| 137 | * BN_window_bits_for_exponent_size -- macro for sliding window mod_exp functions | 123 | * BN_window_bits_for_exponent_size -- macro for sliding window mod_exp functions |
| 138 | * | 124 | * |
| @@ -284,6 +270,15 @@ struct bignum_ctx | |||
| 284 | : "a"(a),"g"(b) \ | 270 | : "a"(a),"g"(b) \ |
| 285 | : "cc"); | 271 | : "cc"); |
| 286 | # endif | 272 | # 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 | ||
| 287 | # endif /* cpu */ | 282 | # endif /* cpu */ |
| 288 | #endif /* OPENSSL_NO_ASM */ | 283 | #endif /* OPENSSL_NO_ASM */ |
| 289 | 284 | ||
| @@ -293,44 +288,17 @@ struct bignum_ctx | |||
| 293 | #define Lw(t) (((BN_ULONG)(t))&BN_MASK2) | 288 | #define Lw(t) (((BN_ULONG)(t))&BN_MASK2) |
| 294 | #define Hw(t) (((BN_ULONG)((t)>>BN_BITS2))&BN_MASK2) | 289 | #define Hw(t) (((BN_ULONG)((t)>>BN_BITS2))&BN_MASK2) |
| 295 | 290 | ||
| 296 | /* This is used for internal error checking and is not normally used */ | 291 | #ifdef BN_DEBUG_RAND |
| 297 | #ifdef BN_DEBUG | 292 | #define bn_clear_top2max(a) \ |
| 298 | # include <assert.h> | ||
| 299 | # define bn_check_top(a) assert ((a)->top >= 0 && (a)->top <= (a)->dmax); | ||
| 300 | #else | ||
| 301 | # define bn_check_top(a) | ||
| 302 | #endif | ||
| 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)) | ||
| 307 | #else | ||
| 308 | #define bn_set_max(r) | ||
| 309 | #endif | ||
| 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 | { \ | 293 | { \ |
| 323 | if ((a)->top > (n)) \ | 294 | int ind = (a)->dmax - (a)->top; \ |
| 324 | { \ | 295 | BN_ULONG *ftl = &(a)->d[(a)->top-1]; \ |
| 325 | (r)->top=(a)->top-n; \ | 296 | for (; ind != 0; ind--) \ |
| 326 | (r)->d= &((a)->d[n]); \ | 297 | *(++ftl) = 0x0; \ |
| 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 | } | 298 | } |
| 299 | #else | ||
| 300 | #define bn_clear_top2max(a) | ||
| 301 | #endif | ||
| 334 | 302 | ||
| 335 | #ifdef BN_LLONG | 303 | #ifdef BN_LLONG |
| 336 | #define mul_add(r,a,w,c) { \ | 304 | #define mul_add(r,a,w,c) { \ |
| @@ -354,6 +322,33 @@ struct bignum_ctx | |||
| 354 | (r1)=Hw(t); \ | 322 | (r1)=Hw(t); \ |
| 355 | } | 323 | } |
| 356 | 324 | ||
| 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 | |||
| 357 | #elif defined(BN_UMULT_HIGH) | 352 | #elif defined(BN_UMULT_HIGH) |
| 358 | #define mul_add(r,a,w,c) { \ | 353 | #define mul_add(r,a,w,c) { \ |
| 359 | BN_ULONG high,low,ret,tmp=(a); \ | 354 | BN_ULONG high,low,ret,tmp=(a); \ |
| @@ -472,18 +467,21 @@ void bn_sqr_comba4(BN_ULONG *r,const BN_ULONG *a); | |||
| 472 | int bn_cmp_words(const BN_ULONG *a,const BN_ULONG *b,int n); | 467 | int bn_cmp_words(const BN_ULONG *a,const BN_ULONG *b,int n); |
| 473 | int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b, | 468 | int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b, |
| 474 | int cl, int dl); | 469 | int cl, int dl); |
| 475 | #ifdef BN_RECURSION | 470 | void bn_mul_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,int n2, |
| 476 | void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2, | 471 | int dna,int dnb,BN_ULONG *t); |
| 477 | BN_ULONG *t); | 472 | void bn_mul_part_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b, |
| 478 | void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int tn, | 473 | int n,int tna,int tnb,BN_ULONG *t); |
| 479 | int n, BN_ULONG *t); | 474 | void bn_sqr_recursive(BN_ULONG *r,const BN_ULONG *a, int n2, BN_ULONG *t); |
| 475 | void bn_mul_low_normal(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b, int n); | ||
| 480 | void bn_mul_low_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,int n2, | 476 | void bn_mul_low_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,int n2, |
| 481 | BN_ULONG *t); | 477 | BN_ULONG *t); |
| 482 | void bn_mul_high(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,BN_ULONG *l,int n2, | 478 | void bn_mul_high(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,BN_ULONG *l,int n2, |
| 483 | BN_ULONG *t); | 479 | BN_ULONG *t); |
| 484 | void bn_sqr_recursive(BN_ULONG *r,const BN_ULONG *a, int n2, BN_ULONG *t); | 480 | BN_ULONG bn_add_part_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, |
| 485 | #endif | 481 | int cl, int dl); |
| 486 | void bn_mul_low_normal(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b, int n); | 482 | BN_ULONG bn_sub_part_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, |
| 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); | ||
| 487 | 485 | ||
| 488 | #ifdef __cplusplus | 486 | #ifdef __cplusplus |
| 489 | } | 487 | } |
