Only force new entropy once a minute when backgrounded

Make the poll-timeout one minute if the option --daemon is used.
This saves a lot og CPU-time.
This commit is contained in:
Rune Magnussen
2017-12-01 16:18:29 +01:00
parent 54101c0de4
commit 2eebda163d
4 changed files with 8 additions and 4 deletions

View File

@@ -73,7 +73,9 @@ Options are:
--raw - do not whiten the output
--multiplier <value> - write 256 bits * value for each 512 bits written to the Keccak sponge
--no-output - do not write random output data
--daemon - run in the background. Output should be redirected to a file or the options should be used with --dev-random
--daemon - run in the background. Output should be redirected to a file or
the options should be used with --dev-random. To reduce CPU-usage addition
af entropy is only forced after a minute rather than a second.
--pidfile <filename> - write the process ID to a file. If --daemon is used, it is the ID of the background process.
--serial <serial> - use Infinite Noise TRNG/FT240 with the given serial number (see --list-devices)
--list-devices - list available devices

View File

@@ -56,7 +56,7 @@ static void outputBytes(uint8_t *bytes, uint32_t length, uint32_t entropy, struc
exit(1);
}
} else {
inmWaitForPoolToHaveRoom();
inmWaitForPoolToHaveRoom(opts);
inmWriteEntropyToPool(bytes, length, entropy);
}
}

View File

@@ -54,7 +54,7 @@ void inmClearEntropyLevel(void);
bool inmEntropyOnTarget(uint32_t entropy, uint32_t bits);
void inmWriteEntropyStart(uint32_t bufLen, struct opt_struct *opts);
void inmWriteEntropyToPool(uint8_t *bytes, uint32_t length, uint32_t entropy);
void inmWaitForPoolToHaveRoom(void);
void inmWaitForPoolToHaveRoom(struct opt_struct *opts);
void inmDumpStats(void);
void startDaemon(struct opt_struct *opts);
bool isSuperUser(void);

View File

@@ -61,7 +61,7 @@ void inmWriteEntropyStart(uint32_t bufLen, struct opt_struct* opts) {
}
// Block until either the entropy pool has room, or 1 second has passed.
void inmWaitForPoolToHaveRoom(void) {
void inmWaitForPoolToHaveRoom(struct opt_struct *opts) {
int ent_count;
struct pollfd pfd = {
.fd = inmDevRandomFD,
@@ -72,6 +72,8 @@ void inmWaitForPoolToHaveRoom(void) {
return;
}
timeout_msec = 1000u; // One second
if (opts->daemon)
timeout_msec *= 60u; // Do not poll aggressively when in the background
poll(&pfd, 1, timeout_msec);
}