From 393d3b3b0cb80223cde9be75a6a10169e37c5778 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Thu, 21 Aug 2008 18:34:24 +0000 Subject: Finished the X9.31 RNG implementations. --- src/ChangeLog | 4 ++++ src/fips.c | 5 +++++ src/g10lib.h | 3 ++- src/misc.c | 21 +++++++++++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ChangeLog b/src/ChangeLog index 85076b10..b811b6ed 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2008-08-21 Werner Koch + + * misc.c (_gcry_log_printhex): New. + 2008-08-20 Werner Koch * g10lib.h (gcry_assert): New. use this at almost all places diff --git a/src/fips.c b/src/fips.c index c02f064a..ed4b9fd5 100644 --- a/src/fips.c +++ b/src/fips.c @@ -422,6 +422,10 @@ run_pubkey_selftests (void) static int run_random_selftests (void) { + char buffer[8]; + + /* FIXME: For now we just try to get a few bytes. */ + gcry_randomize (buffer, sizeof buffer, GCRY_STRONG_RANDOM); return 0; } @@ -536,6 +540,7 @@ fips_new_state (enum module_states new_state) case STATE_ERROR: if (new_state == STATE_SHUTDOWN + || new_state == STATE_FATALERROR || new_state == STATE_INIT) ok = 1; break; diff --git a/src/g10lib.h b/src/g10lib.h index ed25a514..8670de4d 100644 --- a/src/g10lib.h +++ b/src/g10lib.h @@ -102,6 +102,7 @@ int _gcry_log_info_with_dummy_fp (FILE *fp, const char *fmt, ... ) JNLIB_GCC_A_PRINTF(2,3); void _gcry_log_debug( const char *fmt, ... ) JNLIB_GCC_A_PRINTF(1,2); void _gcry_log_printf ( const char *fmt, ... ) JNLIB_GCC_A_PRINTF(1,2); +void _gcry_log_printhex (const char *text, const void *buffer, size_t length); void _gcry_set_log_verbosity( int level ); int _gcry_log_verbosity( int level ); @@ -121,13 +122,13 @@ int _gcry_log_verbosity( int level ); #endif -#define log_hexdump _gcry_log_hexdump #define log_bug _gcry_log_bug #define log_fatal _gcry_log_fatal #define log_error _gcry_log_error #define log_info _gcry_log_info #define log_debug _gcry_log_debug #define log_printf _gcry_log_printf +#define log_printhex _gcry_log_printhex /*-- src/hwfeatures.c --*/ diff --git a/src/misc.c b/src/misc.c index cbb59e1d..545463bd 100644 --- a/src/misc.c +++ b/src/misc.c @@ -250,6 +250,7 @@ _gcry_log_debug( const char *fmt, ... ) va_end(arg_ptr); } + void _gcry_log_printf (const char *fmt, ...) { @@ -263,6 +264,26 @@ _gcry_log_printf (const char *fmt, ...) } } +/* Print a hexdump of BUFFER. With TEXT of NULL print just the raw + dump, with TEXT an empty string, print a trailing linefeed, + otherwise print an entire debug line. */ +void +_gcry_log_printhex (const char *text, const void *buffer, size_t length) +{ + if (text && *text) + log_debug ("%s ", text); + if (length) + { + const unsigned char *p = buffer; + log_printf ("%02X", *p); + for (length--, p++; length--; p++) + log_printf (" %02X", *p); + } + if (text) + log_printf ("\n"); +} + + void _gcry_burn_stack (int bytes) { -- cgit v1.2.1