@@ -14,6 +14,7 @@
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
#include <ftdi.h> // requires <sys/types.h>
|
||||
@@ -21,6 +22,15 @@
|
||||
#include "infnoise.h"
|
||||
#include "libinfnoise.h"
|
||||
|
||||
|
||||
volatile sig_atomic_t running = 1;
|
||||
|
||||
void term(int signum)
|
||||
{
|
||||
(void) signum;
|
||||
running = 0;
|
||||
}
|
||||
|
||||
static void initOpts(struct opt_struct *opts) {
|
||||
opts->outputMultiplier = 0u;
|
||||
opts->daemon = false;
|
||||
@@ -271,9 +281,16 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
//fprintf(stderr, "resultsize: %lu\n", resultSize);
|
||||
|
||||
// get proper shutdown
|
||||
struct sigaction action;
|
||||
memset(&action, 0, sizeof(action));
|
||||
action.sa_handler = term;
|
||||
sigaction(SIGTERM, &action, NULL);
|
||||
sigaction(SIGINT, &action, NULL);
|
||||
|
||||
// endless loop
|
||||
uint64_t totalBytesWritten = 0u;
|
||||
while (true) {
|
||||
while (running) {
|
||||
uint8_t result[resultSize];
|
||||
uint64_t bytesWritten = readData(&context, result, opts.raw, opts.outputMultiplier);
|
||||
totalBytesWritten += bytesWritten;
|
||||
@@ -295,5 +312,7 @@ int main(int argc, char **argv) {
|
||||
fprintf(stderr, "Output %lu bytes\n", (unsigned long) totalBytesWritten);
|
||||
}
|
||||
}
|
||||
deinitInfnoise(&context);
|
||||
inmWriteEntropyEnd();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ struct opt_struct {
|
||||
|
||||
|
||||
void inmWriteEntropyStart(uint32_t bufLen, bool debug);
|
||||
void inmWriteEntropyEnd();
|
||||
void inmWriteEntropyToPool(uint8_t *bytes, uint32_t length, uint32_t entropy);
|
||||
void inmWaitForPoolToHaveRoom(void);
|
||||
|
||||
|
||||
@@ -70,6 +70,12 @@ bool initInfnoise(struct infnoise_context *context, char *serial, bool keccak, b
|
||||
return true;
|
||||
}
|
||||
|
||||
void deinitInfnoise(struct infnoise_context *context)
|
||||
{
|
||||
inmHealthCheckStop();
|
||||
ftdi_deinit(&context->ftdic);
|
||||
}
|
||||
|
||||
uint8_t outBuf[BUFLEN];
|
||||
|
||||
void prepareOutputBuffer() {
|
||||
|
||||
@@ -57,6 +57,15 @@ devlist_node listUSBDevices(char **message);
|
||||
*/
|
||||
bool initInfnoise(struct infnoise_context *context, char *serial, bool keccak, bool debug);
|
||||
|
||||
|
||||
/*
|
||||
* deinitialize the Infinite Noise TRNG
|
||||
*
|
||||
* parameters:
|
||||
* - context: pointer to infnoise_context struct
|
||||
*/
|
||||
void deinitInfnoise(struct infnoise_context *context);
|
||||
|
||||
/*
|
||||
* Reads some bytes from the TRNG and stores them in the "result" byte array.
|
||||
* The array has to be of sufficient size. Please refer to the example programs.
|
||||
|
||||
@@ -61,6 +61,10 @@ void inmWriteEntropyStart(uint32_t bufLen, bool debug) {
|
||||
}
|
||||
}
|
||||
|
||||
void inmWriteEntropyEnd() {
|
||||
free( inmPoolInfo );
|
||||
}
|
||||
|
||||
// Block until either the entropy pool has room, or 1 minute has passed.
|
||||
void inmWaitForPoolToHaveRoom() {
|
||||
int ent_count;
|
||||
|
||||
Reference in New Issue
Block a user