summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/bn_word.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/bn/bn_word.c')
-rw-r--r--src/lib/libcrypto/bn/bn_word.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/lib/libcrypto/bn/bn_word.c b/src/lib/libcrypto/bn/bn_word.c
index 73157a7d43..cd59baa2c4 100644
--- a/src/lib/libcrypto/bn/bn_word.c
+++ b/src/lib/libcrypto/bn/bn_word.c
@@ -115,7 +115,7 @@ int BN_add_word(BIGNUM *a, BN_ULONG w)
115 a->neg=0; 115 a->neg=0;
116 i=BN_sub_word(a,w); 116 i=BN_sub_word(a,w);
117 if (!BN_is_zero(a)) 117 if (!BN_is_zero(a))
118 a->neg=1; 118 a->neg=!(a->neg);
119 return(i); 119 return(i);
120 } 120 }
121 w&=BN_MASK2; 121 w&=BN_MASK2;
@@ -140,7 +140,7 @@ int BN_sub_word(BIGNUM *a, BN_ULONG w)
140 { 140 {
141 int i; 141 int i;
142 142
143 if (a->neg) 143 if (BN_is_zero(a) || a->neg)
144 { 144 {
145 a->neg=0; 145 a->neg=0;
146 i=BN_add_word(a,w); 146 i=BN_add_word(a,w);
@@ -182,11 +182,16 @@ int BN_mul_word(BIGNUM *a, BN_ULONG w)
182 w&=BN_MASK2; 182 w&=BN_MASK2;
183 if (a->top) 183 if (a->top)
184 { 184 {
185 ll=bn_mul_words(a->d,a->d,a->top,w); 185 if (w == 0)
186 if (ll) 186 BN_zero(a);
187 else
187 { 188 {
188 if (bn_wexpand(a,a->top+1) == NULL) return(0); 189 ll=bn_mul_words(a->d,a->d,a->top,w);
189 a->d[a->top++]=ll; 190 if (ll)
191 {
192 if (bn_wexpand(a,a->top+1) == NULL) return(0);
193 a->d[a->top++]=ll;
194 }
190 } 195 }
191 } 196 }
192 return(1); 197 return(1);