diff libtommath/bn_mp_exptmod_fast.c @ 348:cd14c94fe89c debug-unrandom

add some more copious debugging
author Matt Johnston <matt@ucc.asn.au>
date Sun, 06 Aug 2006 15:29:41 +0000
parents eed26cff980b
children e66eec4dcba7
line wrap: on
line diff
--- a/libtommath/bn_mp_exptmod_fast.c	Fri Aug 04 17:37:45 2006 +0000
+++ b/libtommath/bn_mp_exptmod_fast.c	Sun Aug 06 15:29:41 2006 +0000
@@ -1,3 +1,4 @@
+#include "../dbutil.h"
 #include <tommath.h>
 #ifdef BN_MP_EXPTMOD_FAST_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
@@ -65,6 +66,8 @@
   }
 #endif
 
+  dropbear_trace("mp_exptmod_fast x bits %d redmode %d", x, redmode);
+
   /* init M array */
   /* init first cell */
   if ((err = mp_init(&M[1])) != MP_OKAY) {
@@ -210,6 +213,8 @@
       bitcnt = (int)DIGIT_BIT;
     }
 
+    dropbear_trace("mp_exptmod_fast digidx %d buf %u", digidx+1, buf);
+
     /* grab the next msb from the exponent */
     y     = (mp_digit)(buf >> (DIGIT_BIT - 1)) & 1;
     buf <<= (mp_digit)1;
@@ -231,6 +236,7 @@
       if ((err = redux (&res, P, mp)) != MP_OKAY) {
         goto LBL_RES;
       }
+      print_mp_int("mp_exptmod_fast bit=0 mode=1 sq", &res);
       continue;
     }
 
@@ -263,6 +269,7 @@
       bitbuf = 0;
       mode   = 1;
     }
+    print_mp_int("mp_exptmod_fast other way", &res);
   }
 
   /* if bits remain then square/multiply */
@@ -289,6 +296,7 @@
       }
     }
   }
+  print_mp_int("mp_exptmod_fast remaining bits", &res);
 
   if (redmode == 0) {
      /* fixup result if Montgomery reduction is used
@@ -300,6 +308,7 @@
      if ((err = redux(&res, P, mp)) != MP_OKAY) {
        goto LBL_RES;
      }
+     print_mp_int("mp_exptmod_fast fixup", &res);
   }
 
   /* swap res with Y */