diff dbutil.c @ 346:ed24dfc44904 debug-unrandom

add some debugging of mpints
author Matt Johnston <matt@ucc.asn.au>
date Fri, 04 Aug 2006 17:15:35 +0000
parents e17f0333c21e
children cd14c94fe89c
line wrap: on
line diff
--- a/dbutil.c	Fri Aug 04 17:15:05 2006 +0000
+++ b/dbutil.c	Fri Aug 04 17:15:35 2006 +0000
@@ -482,6 +482,10 @@
 
 	int i;
 
+	if (!debug_trace) {
+		return;
+	}
+
 	fprintf(stderr, "%s\n", label);
 	for (i = 0; i < len; i++) {
 		fprintf(stderr, "%02x", buf[i]);
@@ -494,6 +498,28 @@
 	}
 	fprintf(stderr, "\n");
 }
+
+void print_mp_int(const char * label, mp_int *mp) {
+	int ret;
+	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);
+
+	buf = m_malloc(size);
+	ret = mp_toradix(mp, buf, 10);
+	dropbear_assert(ret == MP_OKAY);
+	fprintf(stderr, "%s\n", buf);
+	m_free(buf);
+}
+
+
 #endif
 
 /* Strip all control characters from text (a null-terminated string), except