Fallback to normal multiply if n2 == 8 and dna or dnb is not zero
[openssl.git] / crypto / bn / bn_mul.c
index e0c8ade99652daeb178b85ad82f4bfeaa7c35254..7bffc9c16a515d87eb1fa79d84205753972e3b5e 100644 (file)
@@ -66,7 +66,7 @@
 #include "cryptlib.h"
 #include "bn_lcl.h"
 
-#if defined(OPENSSL_NO_ASM) || !defined(__i386) /* Assembler implementation exists only for x86 */
+#if defined(OPENSSL_NO_ASM) || !(defined(__i386) || defined(__i386__))/* Assembler implementation exists only for x86 */
 /* Here follows specialised variants of bn_add_words() and
    bn_sub_words().  They have the property performing operations on
    arrays of different sizes.  The sizes of those arrays is expressed through
@@ -408,16 +408,22 @@ void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
                return;
                }
 #  endif
-       if (n2 == 8)
+       /* Only call bn_mul_comba 8 if n2 == 8 and the
+        * two arrays are complete [steve]
+        */
+       if (n2 == 8 && dna == 0 && dnb == 0)
                {
                bn_mul_comba8(r,a,b);
                return; 
                }
 # endif /* BN_MUL_COMBA */
+       /* Else do normal multiply */
        if (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL)
                {
-               /* This should not happen */
-               bn_mul_normal(r,a,n2,b,n2);
+               bn_mul_normal(r,a,n2+dna,b,n2+dnb);
+               if ((dna + dnb) < 0)
+                       memset(&r[2*n2 + dna + dnb], 0,
+                               sizeof(BN_ULONG) * -(dna + dnb));
                return;
                }
        /* r=(a[0]-a[1])*(b[1]-b[0]) */