From 1f3e5303f712b432a39913d0bcdbdde141ab55c2 Mon Sep 17 00:00:00 2001 From: Jirka Hladky Date: Thu, 6 Jan 2022 00:15:04 +0100 Subject: Added new verbose mode --- man/haveged.8 | 2 ++ src/havege.h | 2 ++ src/haveged.c | 16 ++++++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/man/haveged.8 b/man/haveged.8 index b1dc7cc..f47f052 100644 --- a/man/haveged.8 +++ b/man/haveged.8 @@ -142,6 +142,8 @@ Set diagnostic bitmap as sum of following options: 32=Show all online test completion detail +64=Show info on RNDADDENTROPY operation + Default is 0. Use -1 for all diagnostics. .TP -w nnn, --write=nnn diff --git a/src/havege.h b/src/havege.h index 59f3172..0d9828c 100644 --- a/src/havege.h +++ b/src/havege.h @@ -65,10 +65,12 @@ typedef int (*pRawIn)(volatile H_UINT *pData, H_UINT szData); #define H_DEBUG_LOOP 0x008 /* Show loop parameters */ #define H_DEBUG_COMPILE 0x010 /* Show assembly info */ #define H_DEBUG_OLT 0x020 /* Show all test info */ +#define H_RNDADDENTROPY_INFO 0x040 /* RNDADDENTROPY info */ #define H_DEBUG_RAW_OUT 0x100 /* diagnostic output */ #define H_DEBUG_RAW_IN 0x200 /* diagnostic input */ #define H_DEBUG_TEST_IN 0x400 /* input test data */ + /** * Initialization parameters. Use non-zero values to override default values. * Notes: diff --git a/src/haveged.c b/src/haveged.c index 293f5e6..efa8be6 100644 --- a/src/haveged.c +++ b/src/haveged.c @@ -161,7 +161,7 @@ int main(int argc, char **argv) #if NUMBER_CORES>1 "t", "threads", "1", "Number of threads", #endif - "v", "verbose", "1", "Verbose mask 0=none,1=summary,2=retries,4=timing,8=loop,16=code,32=test", + "v", "verbose", "1", "Verbose mask 0=none,1=summary,2=retries,4=timing,8=loop,16=code,32=test,64=RNDADDENTROPY", "w", "write", "1", "Set write_wakeup_threshold [bits]", "V", "version", "0", "Print version information and exit", "h", "help", "0", "This help" @@ -636,6 +636,8 @@ static void run_daemon( /* RETURN: nothing */ t[0] = 0; for(;;) { int current,nbytes,r,max=0; + H_UINT fills; + char buf[120]; fd_set write_fd; #ifndef NO_COMMAND_MODE fd_set read_fd; @@ -649,6 +651,7 @@ static void run_daemon( /* RETURN: nothing */ /* add entropy on daemon start and then every 60 seconds unconditionally */ nbytes = poolSize / 2; r = (nbytes+sizeof(H_UINT)-1)/sizeof(H_UINT); + fills = h->n_fills; if (havege_rng(h, (H_UINT *)output->buf, r)<1) error_exit("RNG failed! %d", h->error); output->buf_size = nbytes; @@ -661,6 +664,10 @@ static void run_daemon( /* RETURN: nothing */ params->exit_code = 0; error_exit("Entropy refilled once (%d bytes), exiting.", nbytes); } + if (0 != (params->verbose & H_RNDADDENTROPY_INFO) && h->n_fills > fills) { + if (havege_status_dump(h, H_SD_TOPIC_SUM, buf, sizeof(buf))>0) + print_msg("%s\n", buf); + } t[0] = t[1]; continue; } @@ -738,6 +745,7 @@ static void run_daemon( /* RETURN: nothing */ if(nbytes<1) continue; /* get that many random bytes */ r = (nbytes+sizeof(H_UINT)-1)/sizeof(H_UINT); + fills = h->n_fills; if (havege_rng(h, (H_UINT *)output->buf, r)<1) error_exit("RNG failed! %d", h->error); output->buf_size = nbytes; @@ -747,6 +755,10 @@ static void run_daemon( /* RETURN: nothing */ if (ioctl(random_fd, RNDADDENTROPY, output) == -1) error_exit("RNDADDENTROPY failed!"); h->n_entropy_bytes += nbytes; + if (0 != (params->verbose & H_RNDADDENTROPY_INFO) && h->n_fills > fills) { + if (havege_status_dump(h, H_SD_TOPIC_SUM, buf, sizeof(buf))>0) + print_msg("%s\n", buf); + } } } /** @@ -909,7 +921,7 @@ void print_msg( /* RETURN: nothing */ ...) /* IN: args */ { char buffer[128]; - + va_list ap; va_start(ap, format); snprintf(buffer, sizeof(buffer), "%s: %s", params->daemon, format); -- cgit v1.2.3