changeset 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 381834084475
children e66eec4dcba7
files dbutil.c libtommath/bn_mp_exptmod.c libtommath/bn_mp_exptmod_fast.c
diffstat 3 files changed, 10 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/dbutil.c	Fri Aug 04 17:37:45 2006 +0000
+++ b/dbutil.c	Sun Aug 06 15:29:41 2006 +0000
@@ -482,10 +482,6 @@
 
 	int i;
 
-	if (!debug_trace) {
-		return;
-	}
-
 	fprintf(stderr, "%s\n", label);
 	for (i = 0; i < len; i++) {
 		fprintf(stderr, "%02x", buf[i]);
@@ -504,10 +500,6 @@
 	int size;
 	char * buf = NULL;
 
-	if (!debug_trace) {
-		return;
-	}
-
 	fprintf(stderr, "mp_int %s: ", label);
 	ret = mp_radix_size(mp, 10, &size);
 	dropbear_assert(ret == MP_OKAY);
--- a/libtommath/bn_mp_exptmod.c	Fri Aug 04 17:37:45 2006 +0000
+++ b/libtommath/bn_mp_exptmod.c	Sun Aug 06 15:29:41 2006 +0000
@@ -1,3 +1,4 @@
+#include "../dbutil.h"
 #include <tommath.h>
 #ifdef BN_MP_EXPTMOD_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
--- 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 */