Added a longest sequence finder
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
all: infnoise healthcheck
|
||||
all: infnoise healthcheck findlongest
|
||||
|
||||
infnoise: infnoise.c healthcheck.c Keccak/KeccakF-1600-reference.c Keccak/brg_endian.h
|
||||
gcc -Wall -std=c11 -O3 -m64 -march=native -I Keccak -o infnoise infnoise.c healthcheck.c Keccak/KeccakF-1600-reference.c -lftdi -lm
|
||||
@@ -6,5 +6,8 @@ infnoise: infnoise.c healthcheck.c Keccak/KeccakF-1600-reference.c Keccak/brg_en
|
||||
healthcheck: healthcheck.c
|
||||
gcc -Wall -std=c11 -O3 -m64 -march=native -D TEST_HEALTHCHECK -o healthcheck healthcheck.c -lm
|
||||
|
||||
findlongest: findlongest.c
|
||||
gcc -Wall -std=c11 -O3 -m64 -march=native -o findlongest findlongest.c
|
||||
|
||||
clean:
|
||||
rm -f healthcheck infnoise
|
||||
rm -f healthcheck infnoise findlongest
|
||||
|
||||
@@ -108,7 +108,7 @@ bool inmHealthCheckStart(uint8_t N, double K) {
|
||||
// zeros and ones. Check for this, and scale the stats if needed.
|
||||
static void scaleStats(void) {
|
||||
uint32_t i;
|
||||
printf("Scaling stats...\n");
|
||||
//printf("Scaling stats...\n");
|
||||
for(i = 0; i < (1 << inmN); i++) {
|
||||
inmZerosEven[i] >>= 1;
|
||||
inmOnesEven[i] >>= 1;
|
||||
@@ -129,11 +129,13 @@ static void scaleEntropy(void) {
|
||||
bool inmHealthCheckAddBit(bool bit, bool even) {
|
||||
inmTotalBits++;
|
||||
if((inmTotalBits & 0xfffff) == 0) {
|
||||
printf("Generated %lu bots. Estimated entropy per bit: %f, estimated K: %f\n",
|
||||
inmTotalBits, inmHealthCheckEstimateEntropyPerBit(), inmHealthCheckEstimateK());
|
||||
//printf("Generated %lu bits. Estimated entropy per bit: %f, estimated K: %f\n",
|
||||
//inmTotalBits, inmHealthCheckEstimateEntropyPerBit(), inmHealthCheckEstimateK());
|
||||
/*
|
||||
if(inmTotalBits > 3000000) {
|
||||
exit(0);
|
||||
}
|
||||
*/
|
||||
}
|
||||
inmPrevBits = (inmPrevBits << 1) & ((1 << inmN)-1);
|
||||
if(inmPrevBit) {
|
||||
@@ -145,15 +147,15 @@ bool inmHealthCheckAddBit(bool bit, bool even) {
|
||||
inmNumSequentialOnes++;
|
||||
inmNumSequentialZeros = 0;
|
||||
if(inmNumSequentialOnes > INM_MAX_SEQUENCE) {
|
||||
printf("Maximum sequence of %d 1's exceeded\n", INM_MAX_SEQUENCE);
|
||||
//exit(1);
|
||||
fprintf(stderr, "Maximum sequence of %d 1's exceeded\n", INM_MAX_SEQUENCE);
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
inmNumSequentialZeros++;
|
||||
inmNumSequentialOnes = 0;
|
||||
if(inmNumSequentialZeros > INM_MAX_SEQUENCE) {
|
||||
printf("Maximum sequence of %d 0's exceeded\n", INM_MAX_SEQUENCE);
|
||||
//exit(1);
|
||||
fprintf(stderr, "Maximum sequence of %d 0's exceeded\n", INM_MAX_SEQUENCE);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -230,7 +232,7 @@ double inmHealthCheckEstimateEntropyPerBit(void) {
|
||||
|
||||
// Return true if the health checker has enough data to verify proper operation of the INM.
|
||||
bool inmHealthCheckOkToUseData(void) {
|
||||
return inmNumBitsSampled >= INM_MIN_DATA;
|
||||
return inmTotalBits >= INM_MIN_DATA;
|
||||
}
|
||||
|
||||
// Just return the entropy level added so far in bytes;
|
||||
|
||||
@@ -57,12 +57,10 @@ static void processBytes(uint8_t *keccakState, uint8_t *bytes, bool raw) {
|
||||
if(raw) {
|
||||
// In raw mode, we disable the health check and whitening, and just output raw
|
||||
// data from the INM.
|
||||
/*
|
||||
if(fwrite(bytes, 1, BUFLEN/8, stdout) != BUFLEN/8) {
|
||||
fprintf(stderr, "Unable to write output from Infinite Noise Multiplier\n");
|
||||
exit(1);
|
||||
}
|
||||
*/
|
||||
return;
|
||||
}
|
||||
uint32_t i;
|
||||
@@ -72,14 +70,16 @@ static void processBytes(uint8_t *keccakState, uint8_t *bytes, bool raw) {
|
||||
if(inmHealthCheckOkToUseData() && inmHealthCheckGetEntropyLevel() >= 16) {
|
||||
// Only output byes if we have enough entropy and health check passes
|
||||
// Also, we output data at 1/2 the rate of entropy added to the sponge
|
||||
//uint32_t j;
|
||||
//for(j = 0; j < 1 << 24; j++) {
|
||||
uint8_t dataOut[8];
|
||||
KeccakPermutation(keccakState);
|
||||
KeccakExtract(keccakState, dataOut, 1);
|
||||
/*
|
||||
if(fwrite(dataOut, 1, 8, stdout) != 8) {
|
||||
fprintf(stderr, "Unable to write output from Infinite Noise Multiplier\n");
|
||||
exit(1);
|
||||
}
|
||||
*/
|
||||
//}
|
||||
inmHealthCheckReduceEntropyLevel(16);
|
||||
}
|
||||
}
|
||||
@@ -171,7 +171,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
uint8_t bytes[BUFLEN/8];
|
||||
extractBytes(bytes, inBuf, raw);
|
||||
//processBytes(keccakState, bytes, raw);
|
||||
processBytes(keccakState, bytes, raw);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user