diff bn_mp_mul.c @ 142:d29b64170cf0 libtommath-orig

import of libtommath 0.32
author Matt Johnston <matt@ucc.asn.au>
date Sun, 19 Dec 2004 11:33:56 +0000
parents 86e0b50a9b58
children a96ff234ff19
line wrap: on
line diff
--- a/bn_mp_mul.c	Tue Jun 15 14:42:57 2004 +0000
+++ b/bn_mp_mul.c	Sun Dec 19 11:33:56 2004 +0000
@@ -1,3 +1,5 @@
+#include <tommath.h>
+#ifdef BN_MP_MUL_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
  * LibTomMath is a library that provides multiple-precision
@@ -12,7 +14,6 @@
  *
  * Tom St Denis, [email protected], http://math.libtomcrypt.org
  */
-#include <tommath.h>
 
 /* high level multiplication (handles sign) */
 int mp_mul (mp_int * a, mp_int * b, mp_int * c)
@@ -21,12 +22,18 @@
   neg = (a->sign == b->sign) ? MP_ZPOS : MP_NEG;
 
   /* use Toom-Cook? */
+#ifdef BN_MP_TOOM_MUL_C
   if (MIN (a->used, b->used) >= TOOM_MUL_CUTOFF) {
     res = mp_toom_mul(a, b, c);
+  } else 
+#endif
+#ifdef BN_MP_KARATSUBA_MUL_C
   /* use Karatsuba? */
-  } else if (MIN (a->used, b->used) >= KARATSUBA_MUL_CUTOFF) {
+  if (MIN (a->used, b->used) >= KARATSUBA_MUL_CUTOFF) {
     res = mp_karatsuba_mul (a, b, c);
-  } else {
+  } else 
+#endif
+  {
     /* can we use the fast multiplier?
      *
      * The fast multiplier can be used if the output will 
@@ -35,14 +42,21 @@
      */
     int     digs = a->used + b->used + 1;
 
+#ifdef BN_FAST_S_MP_MUL_DIGS_C
     if ((digs < MP_WARRAY) &&
         MIN(a->used, b->used) <= 
         (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
       res = fast_s_mp_mul_digs (a, b, c, digs);
-    } else {
-      res = s_mp_mul (a, b, c);
-    }
+    } else 
+#endif
+#ifdef BN_S_MP_MUL_DIGS_C
+      res = s_mp_mul (a, b, c); /* uses s_mp_mul_digs */
+#else
+      res = MP_VAL;
+#endif
+
   }
-  c->sign = neg;
+  c->sign = (c->used > 0) ? neg : MP_ZPOS;
   return res;
 }
+#endif