Mercurial > dropbear
comparison 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 |
comparison
equal
deleted
inserted
replaced
345:959c66ccf1b5 | 346:ed24dfc44904 |
---|---|
480 #ifdef DEBUG_TRACE | 480 #ifdef DEBUG_TRACE |
481 void printhex(const char * label, const unsigned char * buf, int len) { | 481 void printhex(const char * label, const unsigned char * buf, int len) { |
482 | 482 |
483 int i; | 483 int i; |
484 | 484 |
485 if (!debug_trace) { | |
486 return; | |
487 } | |
488 | |
485 fprintf(stderr, "%s\n", label); | 489 fprintf(stderr, "%s\n", label); |
486 for (i = 0; i < len; i++) { | 490 for (i = 0; i < len; i++) { |
487 fprintf(stderr, "%02x", buf[i]); | 491 fprintf(stderr, "%02x", buf[i]); |
488 if (i % 16 == 15) { | 492 if (i % 16 == 15) { |
489 fprintf(stderr, "\n"); | 493 fprintf(stderr, "\n"); |
492 fprintf(stderr, " "); | 496 fprintf(stderr, " "); |
493 } | 497 } |
494 } | 498 } |
495 fprintf(stderr, "\n"); | 499 fprintf(stderr, "\n"); |
496 } | 500 } |
501 | |
502 void print_mp_int(const char * label, mp_int *mp) { | |
503 int ret; | |
504 int size; | |
505 char * buf = NULL; | |
506 | |
507 if (!debug_trace) { | |
508 return; | |
509 } | |
510 | |
511 fprintf(stderr, "mp_int %s: ", label); | |
512 ret = mp_radix_size(mp, 10, &size); | |
513 dropbear_assert(ret == MP_OKAY); | |
514 | |
515 buf = m_malloc(size); | |
516 ret = mp_toradix(mp, buf, 10); | |
517 dropbear_assert(ret == MP_OKAY); | |
518 fprintf(stderr, "%s\n", buf); | |
519 m_free(buf); | |
520 } | |
521 | |
522 | |
497 #endif | 523 #endif |
498 | 524 |
499 /* Strip all control characters from text (a null-terminated string), except | 525 /* Strip all control characters from text (a null-terminated string), except |
500 * for '\n', '\r' and '\t'. | 526 * for '\n', '\r' and '\t'. |
501 * The result returned is a newly allocated string, this must be free()d after | 527 * The result returned is a newly allocated string, this must be free()d after |