Changeset 1137 for trunk/cscrypt
- Timestamp:
- 01/09/10 11:09:26 (14 years ago)
- Location:
- trunk/cscrypt
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cscrypt/bn.h
r813 r1137 328 328 /*#define BN_bn2ascii(a) BN_bn2hex(a) */ 329 329 330 BIGNUM *BN_value_one(void);330 const BIGNUM *BN_value_one(void); 331 331 char * BN_options(void); 332 332 BN_CTX *BN_CTX_new(void); … … 365 365 int BN_sub_word(BIGNUM *a, BN_ULONG w); 366 366 int BN_set_word(BIGNUM *a, BN_ULONG w); 367 BN_ULONG BN_get_word( BIGNUM *a);367 BN_ULONG BN_get_word(const BIGNUM *a); 368 368 int BN_cmp(const BIGNUM *a, const BIGNUM *b); 369 369 void BN_free(BIGNUM *a); -
trunk/cscrypt/bn_lib.c
r8 r1137 93 93 if (mult >= 0) 94 94 { 95 if (mult > ( sizeof(int)*8)-1)95 if (mult > (int)(sizeof(int)*8)-1) 96 96 mult=sizeof(int)*8-1; 97 97 bn_limit_bits=mult; … … 100 100 if (high >= 0) 101 101 { 102 if (high > ( sizeof(int)*8)-1)102 if (high > (int)(sizeof(int)*8)-1) 103 103 high=sizeof(int)*8-1; 104 104 bn_limit_bits_high=high; … … 107 107 if (low >= 0) 108 108 { 109 if (low > ( sizeof(int)*8)-1)109 if (low > (int)(sizeof(int)*8)-1) 110 110 low=sizeof(int)*8-1; 111 111 bn_limit_bits_low=low; … … 114 114 if (mont >= 0) 115 115 { 116 if (mont > ( sizeof(int)*8)-1)116 if (mont > (int)(sizeof(int)*8)-1) 117 117 mont=sizeof(int)*8-1; 118 118 bn_limit_bits_mont=mont; … … 130 130 } 131 131 132 BIGNUM *BN_value_one(void)133 { 134 static BN_ULONG data_one=1L;135 static BIGNUM const_one={&data_one,1,1,0};132 const BIGNUM *BN_value_one(void) 133 { 134 static const BN_ULONG data_one=1L; 135 static const BIGNUM const_one={(BN_ULONG *)&data_one,1,1,0,BN_FLG_STATIC_DATA}; 136 136 137 137 return(&const_one); … … 518 518 } 519 519 520 BN_ULONG BN_get_word(BIGNUM *a) 521 { 522 int i,n; 523 BN_ULONG ret=0; 524 525 n=BN_num_bytes(a); 526 if (n > sizeof(BN_ULONG)) 527 return(BN_MASK2); 528 for (i=a->top-1; i>=0; i--) 529 { 530 #ifndef SIXTY_FOUR_BIT /* the data item > unsigned long */ 531 ret<<=BN_BITS4; /* stops the compiler complaining */ 532 ret<<=BN_BITS4; 533 #else 534 ret=0; 535 #endif 536 ret|=a->d[i]; 537 } 538 return(ret); 520 BN_ULONG BN_get_word(const BIGNUM *a) 521 { 522 if (a->top > 1) 523 return BN_MASK2; 524 else if (a->top == 1) 525 return a->d[0]; 526 /* a->top == 0 */ 527 return 0; 539 528 } 540 529 541 530 int BN_set_word(BIGNUM *a, BN_ULONG w) 542 531 { 543 int i,n; 544 if (bn_expand(a,sizeof(BN_ULONG)*8) == NULL) return(0); 545 546 n=sizeof(BN_ULONG)/BN_BYTES; 547 a->neg=0; 548 a->top=0; 549 a->d[0]=(BN_ULONG)w&BN_MASK2; 550 if (a->d[0] != 0) a->top=1; 551 for (i=1; i<n; i++) 552 { 553 /* the following is done instead of 554 * w>>=BN_BITS2 so compilers don't complain 555 * on builds where sizeof(long) == BN_TYPES */ 556 #ifndef SIXTY_FOUR_BIT /* the data item > unsigned long */ 557 w>>=BN_BITS4; 558 w>>=BN_BITS4; 559 #else 560 w=0; 561 #endif 562 a->d[i]=(BN_ULONG)w&BN_MASK2; 563 if (a->d[i] != 0) a->top=i+1; 564 } 532 bn_check_top(a); 533 if (bn_expand(a,(int)sizeof(BN_ULONG)*8) == NULL) return(0); 534 a->neg = 0; 535 a->d[0] = w; 536 a->top = (w ? 1 : 0); 537 bn_check_top(a); 565 538 return(1); 566 539 } -
trunk/cscrypt/bn_mul.c
r943 r1137 378 378 /* The overflow will stop before we over write 379 379 * words we should not overwrite */ 380 if (ln < c1)380 if (ln < (BN_ULONG)c1) 381 381 { 382 382 do {
Note:
See TracChangeset
for help on using the changeset viewer.