New Option SSL_OP_CIPHER_SERVER_PREFERENCE allows TLS/SSLv3 server to override
[openssl.git] / crypto / bn / bn_word.c
index 7e7ca58842bb92dbd732924a05d247d7aa8f6682..cd59baa2c4902910f34a0268627512a24e839f0e 100644 (file)
@@ -140,7 +140,7 @@ int BN_sub_word(BIGNUM *a, BN_ULONG w)
        {
        int i;
 
-       if (a->neg)
+       if (BN_is_zero(a) || a->neg)
                {
                a->neg=0;
                i=BN_add_word(a,w);
@@ -182,11 +182,16 @@ int BN_mul_word(BIGNUM *a, BN_ULONG w)
        w&=BN_MASK2;
        if (a->top)
                {
-               ll=bn_mul_words(a->d,a->d,a->top,w);
-               if (ll)
+               if (w == 0)
+                       BN_zero(a);
+               else
                        {
-                       if (bn_wexpand(a,a->top+1) == NULL) return(0);
-                       a->d[a->top++]=ll;
+                       ll=bn_mul_words(a->d,a->d,a->top,w);
+                       if (ll)
+                               {
+                               if (bn_wexpand(a,a->top+1) == NULL) return(0);
+                               a->d[a->top++]=ll;
+                               }
                        }
                }
        return(1);