clean up libinfnoise.h
This commit is contained in:
@@ -18,20 +18,35 @@ endif
|
||||
|
||||
all: libinfnoise.a infnoise
|
||||
|
||||
infnoise: infnoise.c infnoise.h libinfnoise.a healthcheck.c writeentropy.c daemon.c
|
||||
$(CC) $(CFLAGS) -o infnoise infnoise.c writeentropy.c healthcheck.c daemon.c $(FTDI) -lm -lrt -L . -linfnoise
|
||||
infnoise: infnoise.c infnoise.h libinfnoise.a infnoise.o daemon.o
|
||||
$(CC) $(CFLAGS) -o infnoise infnoise.o daemon.o libinfnoise.a $(FTDI) -lm -lrt -L. -linfnoise
|
||||
|
||||
libinfnoise.a: libinfnoise.c libinfnoise.h healthcheck.c healthcheck.h Keccak/brg_endian.h Keccak/KeccakF-1600-reference.c
|
||||
$(CC) $(CFLAGS) -c libinfnoise.c libinfnoise.h healthcheck.c Keccak/KeccakF-1600-reference.c $(FTDI) -lm
|
||||
ar rcs libinfnoise.a libinfnoise.o healthcheck.o KeccakF-1600-reference.o
|
||||
infnoise.o: infnoise.c infnoise.h
|
||||
$(CC) $(CFLAGS) -c infnoise.c
|
||||
|
||||
daemon.o: daemon.c
|
||||
$(CC) $(CFLAGS) -c daemon.c
|
||||
|
||||
writeentropy.o: writeentropy.c
|
||||
$(CC) $(CFLAGS) -c writeentropy.c
|
||||
|
||||
libinfnoise.o: libinfnoise.c libinfnoise.h libinfnoise_private.h healthcheck.c healthcheck.h Keccak/brg_endian.h Keccak/KeccakF-1600-reference.c
|
||||
$(CC) $(CFLAGS) -c libinfnoise.c healthcheck.c Keccak/KeccakF-1600-reference.c
|
||||
|
||||
libinfnoise.a: libinfnoise.o healthcheck.o KeccakF-1600-reference.o writeentropy.o
|
||||
ar rcs libinfnoise.a libinfnoise.o healthcheck.o KeccakF-1600-reference.o writeentropy.o
|
||||
ranlib libinfnoise.a
|
||||
|
||||
KeccakF-1600-reference.o: Keccak/brg_endian.h Keccak/KeccakF-1600-reference.c
|
||||
$(CC) $(CFLAGS) -c Keccak/KeccakF-1600-reference.c -lm -lrt
|
||||
|
||||
libs: libinfnoise.a
|
||||
|
||||
libinfnoise-example: libinfnoise.c libinfnoise.h
|
||||
$(CC) $(CFLAGS) -D LIB_EXAMPLE_PROGRAM -o libinfnoise-example libinfnoise.c libinfnoise.h healthcheck.c writeentropy.c daemon.c Keccak/KeccakF-1600-reference.c $(FTDI) -lm -lrt
|
||||
|
||||
clean:
|
||||
$(RM) infnoise *.o *.a libinfnoise-example
|
||||
$(RM) infnoise *.o *.a *.gch libinfnoise-example
|
||||
|
||||
install:
|
||||
install -d $(PREFIX)/sbin
|
||||
|
||||
@@ -24,7 +24,7 @@ confirmed.
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
#include "libinfnoise.h"
|
||||
#include "libinfnoise_private.h"
|
||||
|
||||
#define INM_MIN_DATA 80000u
|
||||
#define INM_MIN_SAMPLE_SIZE 100u
|
||||
|
||||
@@ -10,16 +10,20 @@
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <ftdi.h>
|
||||
#include "infnoise.h"
|
||||
#include "libinfnoise.h"
|
||||
#include "libinfnoise_private.h"
|
||||
#include "KeccakF-1600-interface.h"
|
||||
|
||||
static void initOpts(struct opt_struct *opts) {
|
||||
opts->outputMultiplier = 0u;
|
||||
opts->daemon =
|
||||
opts->debug =
|
||||
opts->devRandom =
|
||||
opts->noOutput =
|
||||
opts->listDevices =
|
||||
opts->daemon = false;
|
||||
opts->debug = false;
|
||||
opts->devRandom = false;
|
||||
opts->noOutput = false;
|
||||
opts->listDevices = false;
|
||||
opts->raw = false;
|
||||
opts->version = false;
|
||||
opts->help = false;
|
||||
@@ -164,66 +168,40 @@ int main(int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (opts.devRandom) {
|
||||
inmWriteEntropyStart(BUFLEN/8u, opts.debug); // todo: create method in libinfnoise.h for this
|
||||
// also todo: check if superUser in this mode (it will fail silently if not :-/)
|
||||
}
|
||||
|
||||
// Optionally run in the background and optionally write a PID-file
|
||||
startDaemon(&opts);
|
||||
|
||||
if (opts.devRandom) {
|
||||
inmWriteEntropyStart(BUFLEN/8u, opts.debug);
|
||||
// initialize USB device and health check
|
||||
if (initInfnoise(&ftdic, opts.serial, opts.debug) != true) {
|
||||
return 1; // ERROR (message still goes to stderr)
|
||||
}
|
||||
|
||||
if (!inmHealthCheckStart(PREDICTION_BITS, DESIGN_K, opts.debug)) {
|
||||
fputs("Can't initialize health checker\n", stderr);
|
||||
return 1;
|
||||
}
|
||||
// initialize keccak
|
||||
KeccakInitialize();
|
||||
uint8_t keccakState[KeccakPermutationSizeInBytes];
|
||||
KeccakInitializeState(keccakState);
|
||||
|
||||
if(!initializeUSB(&ftdic, &message, opts.serial)) {
|
||||
// Sometimes have to do it twice - not sure why
|
||||
if(!initializeUSB(&ftdic, &message, opts.serial)) {
|
||||
fputs(message, stderr);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Endless loop: set SW1EN and SW2EN alternately
|
||||
uint32_t i;
|
||||
uint8_t outBuf[BUFLEN], inBuf[BUFLEN];
|
||||
for(i = 0u; i < BUFLEN; i++) {
|
||||
// Alternate Ph1 and Ph2
|
||||
outBuf[i] = i & 1? (1 << SWEN2) : (1 << SWEN1);
|
||||
}
|
||||
uint8_t result[1024]; // only used in noOutput mode (and libinfnoise)
|
||||
|
||||
uint64_t totalBytesWritten = 0u;
|
||||
while(true) {
|
||||
struct timespec start;
|
||||
clock_gettime(CLOCK_REALTIME, &start);
|
||||
|
||||
if(ftdi_write_data(&ftdic, outBuf, BUFLEN) != BUFLEN) {
|
||||
fputs("USB write failed\n", stderr);
|
||||
return 1;
|
||||
}
|
||||
if(ftdi_read_data(&ftdic, inBuf, BUFLEN) != BUFLEN) {
|
||||
fputs("USB read failed\n", stderr);
|
||||
return 1;
|
||||
}
|
||||
struct timespec end;
|
||||
clock_gettime(CLOCK_REALTIME, &end);
|
||||
uint32_t us = diffTime(&start, &end);
|
||||
if(us <= MAX_MICROSEC_FOR_SAMPLES) {
|
||||
uint8_t bytes[BUFLEN/8u];
|
||||
uint32_t entropy = extractBytes(bytes, inBuf);
|
||||
if(!opts.noOutput && inmHealthCheckOkToUseData() && inmEntropyOnTarget(entropy, BUFLEN)) {
|
||||
uint64_t prevTotalBytesWritten = totalBytesWritten;
|
||||
totalBytesWritten += processBytes(keccakState, bytes, NULL, entropy, opts.raw,
|
||||
opts.devRandom, opts.outputMultiplier, opts.noOutput);
|
||||
uint64_t bytesWritten = readData1(&ftdic, keccakState, result, opts.noOutput, opts.raw, opts.outputMultiplier, opts.devRandom);
|
||||
//printf("%d", (uint8_t)opts.noOutput);
|
||||
|
||||
if (totalBytesWritten == (unsigned long)-1) {
|
||||
return 1; // ERROR (message goes to stderr)
|
||||
}
|
||||
totalBytesWritten += bytesWritten;
|
||||
if(opts.debug && (1u << 20u)*(totalBytesWritten/(1u << 20u)) > (1u << 20u)*(prevTotalBytesWritten/(1u << 20u))) {
|
||||
fprintf(stderr, "Output %lu bytes\n", (unsigned long)totalBytesWritten);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <ftdi.h>
|
||||
|
||||
// Structure for parsed command line options
|
||||
struct opt_struct {
|
||||
@@ -18,23 +19,4 @@ struct opt_struct {
|
||||
char *serial; // Name of selected device
|
||||
};
|
||||
|
||||
//bool inmHealthCheckStart(uint8_t N, double K, struct opt_struct *opts);
|
||||
//void inmHealthCheckStop(void);
|
||||
/*bool inmHealthCheckAddBit(bool evenBit, bool oddBit, bool even);
|
||||
bool inmHealthCheckOkToUseData(void);
|
||||
double inmHealthCheckEstimateK(void);
|
||||
double inmHealthCheckEstimateEntropyPerBit(void);
|
||||
uint32_t inmGetEntropyLevel(void);
|
||||
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 inmDumpStats(void);
|
||||
*/
|
||||
void startDaemon(struct opt_struct *opts);
|
||||
bool isSuperUser(void);
|
||||
|
||||
|
||||
//extern double inmK, inmExpectedEntropyPerBit;
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <ftdi.h>
|
||||
#include "libinfnoise_private.h"
|
||||
#include "libinfnoise.h"
|
||||
#include "KeccakF-1600-interface.h"
|
||||
|
||||
@@ -101,7 +102,11 @@ uint32_t processBytes(uint8_t *keccakState, uint8_t *bytes, uint8_t *result, uin
|
||||
if(outputMultiplier == 0u) {
|
||||
// Output all the bytes of entropy we have
|
||||
KeccakExtract(keccakState, dataOut, (entropy + 63u)/64u);
|
||||
outputBytes(dataOut, entropy/8u, entropy & 0x7u, writeDevRandom);
|
||||
if (!noOutput) {
|
||||
outputBytes(dataOut, entropy/8u, entropy & 0x7u, writeDevRandom);
|
||||
} else {
|
||||
memcpy(result, dataOut, entropy/8u * sizeof(uint8_t));
|
||||
}
|
||||
return entropy/8u;
|
||||
} // todo: write to result array
|
||||
|
||||
@@ -150,6 +155,7 @@ uint32_t processBytes(uint8_t *keccakState, uint8_t *bytes, uint8_t *result, uin
|
||||
return bytesWritten;
|
||||
}
|
||||
|
||||
|
||||
void add_to_list(struct inm_devlist **list, struct infnoise_device **dev) {
|
||||
struct inm_devlist_node *tmp = malloc(sizeof(struct inm_devlist_node ) );
|
||||
tmp->device = (*dev);
|
||||
@@ -300,7 +306,16 @@ bool initializeUSB(struct ftdi_context *ftdic, char **message, char *serial) {
|
||||
return true;
|
||||
}
|
||||
|
||||
uint64_t readData(struct ftdi_context *ftdic, uint8_t *keccakState, uint8_t *result, bool raw, uint32_t outputMultiplier, bool debug) {
|
||||
|
||||
uint64_t readRawData(struct ftdi_context *ftdic, uint8_t *result) {
|
||||
return readData1(ftdic, NULL, result, false, true, 0, false);
|
||||
}
|
||||
|
||||
uint64_t readData(struct ftdi_context *ftdic, uint8_t *keccakState, uint8_t *result, uint32_t outputMultiplier) {
|
||||
return readData1(ftdic, keccakState, result, false, false, outputMultiplier, false);
|
||||
}
|
||||
|
||||
uint64_t readData1(struct ftdi_context *ftdic, uint8_t *keccakState, uint8_t *result, bool noOutput, bool raw, uint32_t outputMultiplier, bool devRandom) {
|
||||
// Endless loop: set SW1EN and SW2EN alternately
|
||||
uint32_t i;
|
||||
uint8_t outBuf[BUFLEN], inBuf[BUFLEN];
|
||||
@@ -331,73 +346,77 @@ uint64_t readData(struct ftdi_context *ftdic, uint8_t *keccakState, uint8_t *res
|
||||
uint8_t bytes[BUFLEN/8u];
|
||||
uint32_t entropy = extractBytes(bytes, inBuf);
|
||||
|
||||
if(inmHealthCheckOkToUseData() && inmEntropyOnTarget(entropy, BUFLEN)) {
|
||||
uint64_t prevTotalBytesWritten = totalBytesWritten;
|
||||
totalBytesWritten += processBytes(keccakState, bytes, result, entropy, raw, false, outputMultiplier, true);
|
||||
fprintf(stderr, "bw3: %lu\n", (unsigned long)totalBytesWritten);
|
||||
|
||||
if(debug && (1u << 20u)*(totalBytesWritten/(1u << 20u)) > (1u << 20u)*(prevTotalBytesWritten/(1u << 20u))) {
|
||||
fprintf(stderr, "Output %lu bytes\n", (unsigned long)totalBytesWritten);
|
||||
}
|
||||
// call health check and process bytes if OK
|
||||
if(!noOutput && inmHealthCheckOkToUseData() && inmEntropyOnTarget(entropy, BUFLEN)) {
|
||||
totalBytesWritten += processBytes(keccakState, bytes, result, entropy, raw, devRandom, outputMultiplier, noOutput);
|
||||
}
|
||||
}
|
||||
return totalBytesWritten;
|
||||
}
|
||||
|
||||
#ifdef LIB_EXAMPLE_PROGRAM
|
||||
// example use of libinfnoise
|
||||
int main() {
|
||||
bool initInfnoise(struct ftdi_context *ftdic,char *serial, bool debug) {
|
||||
|
||||
//inmWriteEntropyStart(BUFLEN/8u, debug); // todo: create method in libinfnoise.h for this
|
||||
|
||||
// initialize health check
|
||||
if (!inmHealthCheckStart(PREDICTION_BITS, DESIGN_K, false)) {
|
||||
if (!inmHealthCheckStart(PREDICTION_BITS, DESIGN_K, debug)) {
|
||||
fputs("Can't initialize health checker\n", stderr);
|
||||
return 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
// initialize USB
|
||||
char *message;
|
||||
if(!initializeUSB(ftdic, &message, serial)) {
|
||||
// Sometimes have to do it twice - not sure why
|
||||
if(!initializeUSB(ftdic, &message, serial)) {
|
||||
fputs(message, stderr);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef LIB_EXAMPLE_PROGRAM
|
||||
// example use of libinfnoise - with keccak
|
||||
int main() {
|
||||
char *serial=NULL; // use any device, can be set to a specific serial
|
||||
|
||||
// initialize USB
|
||||
struct ftdi_context ftdic;
|
||||
initInfnoise(&ftdic, serial);
|
||||
|
||||
// initialize keccak
|
||||
KeccakInitialize();
|
||||
uint8_t keccakState[KeccakPermutationSizeInBytes];
|
||||
KeccakInitializeState(keccakState);
|
||||
|
||||
// initialize USB
|
||||
struct ftdi_context ftdic;
|
||||
char *message;
|
||||
char *serial=NULL; // use any device, can be set to a specific serial
|
||||
if(!initializeUSB(&ftdic, &message, serial)) {
|
||||
// Sometimes have to do it twice - not sure why
|
||||
if(!initializeUSB(&ftdic, &message, serial)) {
|
||||
fputs(message, stderr);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t totalBytesWritten = 0u;
|
||||
|
||||
// parameters for readData(..):
|
||||
bool rawOutput = true;
|
||||
uint32_t multiplier = 10u;
|
||||
bool debug = false;
|
||||
|
||||
// calculate output size based on the parameters:
|
||||
// when using the multiplier, we need a result array of multiplier*32 bytes - otherwise the full buffer size (512 bytes)
|
||||
// when using the multiplier, we need a result array of max 1024 bytes - otherwise 64(BUFLEN/8) bytes
|
||||
uint32_t resultSize;
|
||||
if (multiplier == 0 || rawOutput == true) {
|
||||
resultSize = BUFLEN;
|
||||
resultSize = BUFLEN/8u;
|
||||
} else {
|
||||
resultSize = multiplier*32;
|
||||
resultSize = 1024; // optimize?
|
||||
}
|
||||
fprintf(stderr, "%d\n", resultSize);
|
||||
|
||||
// read and print
|
||||
uint64_t totalBytesWritten = 0u;
|
||||
|
||||
// read and print in a loop
|
||||
while (totalBytesWritten < 100000) {
|
||||
fprintf(stderr, "%lu\n", (unsigned long)totalBytesWritten);
|
||||
uint8_t result[resultSize];
|
||||
//uint8_t *result = malloc(resultSize * sizeof(uint8_t)); // array to hold the (whitened) result
|
||||
|
||||
uint64_t bytesWritten = 0u;
|
||||
bytesWritten = readData(&ftdic, keccakState, result, rawOutput, multiplier, debug);
|
||||
fprintf(stderr, "bw2: %lu\n", (unsigned long)bytesWritten);
|
||||
bytesWritten = readData(&ftdic, keccakState, result, multiplier);
|
||||
|
||||
totalBytesWritten += bytesWritten;
|
||||
// check for -1!
|
||||
totalBytesWritten += bytesWritten;
|
||||
|
||||
// make sure to only read as many bytes as readData returned. Only those have passed the health check in this round (usually all but..)
|
||||
fwrite(result, 1, bytesWritten, stdout);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,59 +4,10 @@
|
||||
#include <ftdi.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#define INFNOISE_VENDOR_ID 0x0403
|
||||
#define INFNOISE_PRODUCT_ID 0x6015
|
||||
|
||||
// Required accuracy of estimated vs measured entropy in health monitor
|
||||
#define INM_ACCURACY 1.03
|
||||
|
||||
// The FT240X has a 512 byte buffer. Must be multiple of 64
|
||||
// We also write this in one go to the Keccak sponge, which is at most 1600 bits
|
||||
#define BUFLEN 512u
|
||||
|
||||
// This is how many previous bits are used to predict the next bit from the INM
|
||||
#define PREDICTION_BITS 14u
|
||||
|
||||
// This is the maximum time we allow to pass to perform the I/O operations, since long
|
||||
// delays can reduce entropy from the INM.
|
||||
#define MAX_MICROSEC_FOR_SAMPLES 5000u
|
||||
|
||||
// This is the gain of each of the two op-amp stages in the INM
|
||||
#define DESIGN_K 1.84
|
||||
|
||||
#define BITMODE_SYNCBB 0x4
|
||||
|
||||
// This defines which pins on the FT240X are used
|
||||
#define COMP1 1u
|
||||
#define COMP2 4u
|
||||
#define SWEN1 2u
|
||||
#define SWEN2 0u
|
||||
|
||||
// All data bus bits of the FT240X are outputs, except COMP1 and COMP2
|
||||
#define MASK (0xffu & ~(1u << COMP1) & ~(1u << COMP2))
|
||||
|
||||
// Structure for parsed command line options
|
||||
struct opt_struct {
|
||||
uint32_t outputMultiplier; // We output all the entropy when outputMultiplier == 0
|
||||
bool daemon; // Run as daemon?
|
||||
bool debug; // Print debugging info?
|
||||
bool devRandom; // Feed /dev/random?
|
||||
bool noOutput; // Supress output?
|
||||
bool listDevices; // List possible USB-devices?
|
||||
bool help; // Show help
|
||||
bool none; // set to true when no valid arguments where detected
|
||||
bool raw; // No whitening?
|
||||
bool version; // Show version
|
||||
char *pidFileName; // Name of optional PID-file
|
||||
char *serial; // Name of selected device
|
||||
};
|
||||
|
||||
// struct for ftdi_device_descriptor
|
||||
struct infnoise_device {
|
||||
@@ -84,28 +35,14 @@ struct infnoise_device_list {
|
||||
struct infnoise_device_list * next;
|
||||
};
|
||||
|
||||
bool inmHealthCheckStart(uint8_t N, double K, bool debug);
|
||||
void inmHealthCheckStop(void);
|
||||
bool inmHealthCheckAddBit(bool evenBit, bool oddBit, bool even);
|
||||
bool inmHealthCheckOkToUseData(void);
|
||||
double inmHealthCheckEstimateK(void);
|
||||
double inmHealthCheckEstimateEntropyPerBit(void);
|
||||
uint32_t inmGetEntropyLevel(void);
|
||||
void inmClearEntropyLevel(void);
|
||||
bool inmEntropyOnTarget(uint32_t entropy, uint32_t bits);
|
||||
void inmWriteEntropyStart(uint32_t bufLen, bool debug);
|
||||
void inmWriteEntropyToPool(uint8_t *bytes, uint32_t length, uint32_t entropy);
|
||||
void inmWaitForPoolToHaveRoom(void);
|
||||
void inmDumpStats(void);
|
||||
void startDaemon(struct opt_struct *opts);
|
||||
bool isSuperUser(void);
|
||||
bool listUSBDevices(struct ftdi_context *ftdic, struct inm_devlist **result, char **message);
|
||||
|
||||
extern double inmK, inmExpectedEntropyPerBit;
|
||||
struct timespec;
|
||||
double diffTime(struct timespec *start, struct timespec *end);
|
||||
uint32_t extractBytes(uint8_t *bytes, uint8_t *inBuf);
|
||||
void outputBytes(uint8_t *bytes, uint32_t length, uint32_t entropy, bool writeDevRandom);
|
||||
bool listUSBDevices(struct ftdi_context *ftdic, struct inm_devlist **result, char** message);
|
||||
bool initializeUSB(struct ftdi_context* ftdic, char **message, char *serial);
|
||||
uint32_t processBytes(uint8_t *keccakState, uint8_t *bytes, uint8_t *result, uint32_t entropy, bool raw,
|
||||
bool writeDevRandom, uint32_t outputMultiplier, bool noOutput);
|
||||
bool initInfnoise(struct ftdi_context *ftdic, char *serial, bool debug);
|
||||
|
||||
bool initKeccak(struct ftdi_context *ftdic, char *serial);
|
||||
|
||||
uint64_t readRawData(struct ftdi_context *ftdic, uint8_t *result);
|
||||
|
||||
uint64_t readData(struct ftdi_context *ftdic, uint8_t *keccakState, uint8_t *result, uint32_t outputMultiplier);
|
||||
|
||||
uint64_t readData1(struct ftdi_context *ftdic, uint8_t *keccakState, uint8_t *result, bool noOutput, bool raw, uint32_t outputMultiplier, bool devRandom);
|
||||
|
||||
57
software/libinfnoise_private.h
Normal file
57
software/libinfnoise_private.h
Normal file
@@ -0,0 +1,57 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <ftdi.h>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
#define INFNOISE_VENDOR_ID 0x0403
|
||||
#define INFNOISE_PRODUCT_ID 0x6015
|
||||
|
||||
// Required accuracy of estimated vs measured entropy in health monitor
|
||||
#define INM_ACCURACY 1.03
|
||||
|
||||
// This is how many previous bits are used to predict the next bit from the INM
|
||||
#define PREDICTION_BITS 14u
|
||||
|
||||
// This is the maximum time we allow to pass to perform the I/O operations, since long
|
||||
// delays can reduce entropy from the INM.
|
||||
#define MAX_MICROSEC_FOR_SAMPLES 5000u
|
||||
|
||||
// This is the gain of each of the two op-amp stages in the INM
|
||||
#define DESIGN_K 1.84
|
||||
|
||||
#define BITMODE_SYNCBB 0x4
|
||||
|
||||
// This defines which pins on the FT240X are used
|
||||
#define COMP1 1u
|
||||
#define COMP2 4u
|
||||
#define SWEN1 2u
|
||||
#define SWEN2 0u
|
||||
|
||||
// All data bus bits of the FT240X are outputs, except COMP1 and COMP2
|
||||
#define MASK (0xffu & ~(1u << COMP1) & ~(1u << COMP2))
|
||||
|
||||
bool inmHealthCheckStart(uint8_t N, double K, bool debug);
|
||||
void inmHealthCheckStop(void);
|
||||
bool inmHealthCheckAddBit(bool evenBit, bool oddBit, bool even);
|
||||
bool inmHealthCheckOkToUseData(void);
|
||||
double inmHealthCheckEstimateK(void);
|
||||
double inmHealthCheckEstimateEntropyPerBit(void);
|
||||
uint32_t inmGetEntropyLevel(void);
|
||||
void inmClearEntropyLevel(void);
|
||||
bool inmEntropyOnTarget(uint32_t entropy, uint32_t bits);
|
||||
void inmWriteEntropyStart(uint32_t bufLen, bool debug);
|
||||
void inmWriteEntropyToPool(uint8_t *bytes, uint32_t length, uint32_t entropy);
|
||||
void inmWaitForPoolToHaveRoom(void);
|
||||
void inmDumpStats(void);
|
||||
bool isSuperUser(void);
|
||||
|
||||
extern double inmK, inmExpectedEntropyPerBit;
|
||||
struct timespec;
|
||||
double diffTime(struct timespec *start, struct timespec *end);
|
||||
uint32_t extractBytes(uint8_t *bytes, uint8_t *inBuf);
|
||||
void outputBytes(uint8_t *bytes, uint32_t length, uint32_t entropy, bool writeDevRandom);
|
||||
uint32_t processBytes(uint8_t *keccakState, uint8_t *bytes, uint8_t *result, uint32_t entropy, bool raw,
|
||||
bool writeDevRandom, uint32_t outputMultiplier, bool noOutput);
|
||||
|
||||
@@ -35,10 +35,10 @@ int main(int argc, char **argv) {
|
||||
uint32_t i;
|
||||
printf("password:");
|
||||
for (i = 0u; i < keys; i++) {
|
||||
uint32_t randVal = rollDie(26u, file);
|
||||
uint32_t randVal = rollDie(32u, file);
|
||||
putchar('a' + randVal);
|
||||
}
|
||||
printf("\nThis password has %.2f bits of entropy\n", log(pow(26.0, keys))/log(2));
|
||||
printf("\nThis password has %.2f bits of entropy\n", log(pow(32.0, keys))/log(2));
|
||||
fclose(file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/random.h>
|
||||
#include "infnoise.h"
|
||||
#include "libinfnoise.h"
|
||||
|
||||
#define SIZE_PROC_FILENAME "/proc/sys/kernel/random/poolsize"
|
||||
#define FILL_PROC_FILENAME "/proc/sys/kernel/random/write_wakeup_threshold"
|
||||
@@ -40,9 +40,9 @@ static uint32_t readNumberFromFile(char *fileName) {
|
||||
}
|
||||
|
||||
// Open /dev/random
|
||||
void inmWriteEntropyStart(uint32_t bufLen, struct opt_struct* opts) {
|
||||
void inmWriteEntropyStart(uint32_t bufLen, bool debug) {
|
||||
inmBufLen = bufLen;
|
||||
inmDebug = opts->debug;
|
||||
inmDebug = debug;
|
||||
//inmDevRandomFD = open("/dev/random", O_WRONLY);
|
||||
inmDevRandomFD = open("/dev/random", O_RDWR);
|
||||
if(inmDevRandomFD < 0) {
|
||||
|
||||
Reference in New Issue
Block a user