Abdelilah Essiari <aes@george.lbl.gov> reports that for very small
[openssl.git] / crypto / bn / bn_mul.c
index eb007e19e9a9063700ca358ab9a61e6cd3bd850e..3e8d8b9567a89af94383b8e6120a78cb060a55a5 100644 (file)
@@ -61,6 +61,9 @@
 #include "bn_lcl.h"
 
 #ifdef BN_RECURSION
+/* Karatsuba recursive multiplication algorithm
+ * (cf. Knuth, The Art of Computer Programming, Vol. 2) */
+
 /* r is 2*n2 words in size,
  * a and b are both n2 words in size.
  * n2 must be a power of 2.
@@ -628,7 +631,6 @@ int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
 
        al=a->top;
        bl=b->top;
-       r->neg=a->neg^b->neg;
 
        if ((al == 0) || (bl == 0))
                {
@@ -644,6 +646,7 @@ int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
                }
        else
                rr = r;
+       rr->neg=a->neg^b->neg;
 
 #if defined(BN_MUL_COMBA) || defined(BN_RECURSION)
        i = al-bl;