projects
/
oweals
/
openssl.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Refine logic in bn_mont.c and eliminate redundant BN_CTX pulls.
[oweals/openssl.git]
/
crypto
/
bn
/
bn_word.c
diff --git
a/crypto/bn/bn_word.c
b/crypto/bn/bn_word.c
index 1bcb37e29222f76dce1baefd9d1bf949389e725e..ee7b87c45ccd38839db6261ed81c2d87b9e881b5 100644
(file)
--- a/
crypto/bn/bn_word.c
+++ b/
crypto/bn/bn_word.c
@@
-69,6
+69,9
@@
BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w)
#endif
int i;
#endif
int i;
+ if (w == 0)
+ return (BN_ULONG)-1;
+
bn_check_top(a);
w&=BN_MASK2;
for (i=a->top-1; i>=0; i--)
bn_check_top(a);
w&=BN_MASK2;
for (i=a->top-1; i>=0; i--)
@@
-94,7
+97,7
@@
BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w)
if (!w)
/* actually this an error (division by zero) */
if (!w)
/* actually this an error (division by zero) */
- return
0
;
+ return
(BN_ULONG)-1
;
if (a->top == 0)
return 0;
if (a->top == 0)
return 0;
@@
-102,7
+105,7
@@
BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w)
j = BN_BITS2 - BN_num_bits_word(w);
w <<= j;
if (!BN_lshift(a, a, j))
j = BN_BITS2 - BN_num_bits_word(w);
w <<= j;
if (!BN_lshift(a, a, j))
- return
0
;
+ return
(BN_ULONG)-1
;
for (i=a->top-1; i>=0; i--)
{
for (i=a->top-1; i>=0; i--)
{
@@
-175,7
+178,13
@@
int BN_sub_word(BIGNUM *a, BN_ULONG w)
/* degenerate case: w is zero */
if (!w) return 1;
/* degenerate case: a is zero */
/* degenerate case: w is zero */
if (!w) return 1;
/* degenerate case: a is zero */
- if(BN_is_zero(a)) return BN_set_word(a,w);
+ if(BN_is_zero(a))
+ {
+ i = BN_set_word(a,w);
+ if (i != 0)
+ BN_set_negative(a, 1);
+ return i;
+ }
/* handle 'a' when negative */
if (a->neg)
{
/* handle 'a' when negative */
if (a->neg)
{