Check each group of 512 bits for having enough entropy
This commit is contained in:
@@ -279,6 +279,12 @@ void inmClearEntropyLevel(void) {
|
||||
inmEntropyLevel = 0;
|
||||
}
|
||||
|
||||
// Check that the entropy of the last group of bits was high enough for use.
|
||||
bool inmEntropyOnTarget(uint32_t entropy, uint32_t numBits) {
|
||||
uint32_t expectedEntropy = numBits*inmExpectedEntropyPerBit;
|
||||
return expectedEntropy < entropy*INM_ACCURACY;
|
||||
}
|
||||
|
||||
#ifdef TEST_HEALTHCHECK
|
||||
|
||||
// Print the tables of statistics.
|
||||
|
||||
@@ -11,16 +11,17 @@
|
||||
// The FT240X has a 512 byte buffer. Must be multiple of 64
|
||||
//#define BUFLEN 512
|
||||
#define BUFLEN (64*8)
|
||||
#define DESIGN_K 1.736
|
||||
#define PREDICTION_BITS 14
|
||||
#define LINUX_POOL_SIZE (4096/8)
|
||||
|
||||
#ifdef VERSION1
|
||||
#define DESIGN_K 1.82
|
||||
#define COMP1 2
|
||||
#define COMP2 0
|
||||
#define SWEN1 4
|
||||
#define SWEN2 1
|
||||
#else
|
||||
#define DESIGN_K 1.736
|
||||
#define COMP1 1
|
||||
#define COMP2 4
|
||||
#define SWEN1 2
|
||||
@@ -175,7 +176,6 @@ static bool initializeUSB(struct ftdi_context *ftdic, char **message) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct ftdi_context ftdic;
|
||||
@@ -245,7 +245,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
uint8_t bytes[BUFLEN/8];
|
||||
uint32_t entropy = extractBytes(bytes, inBuf, raw);
|
||||
if(!noOutput && inmHealthCheckOkToUseData()) {
|
||||
if(!noOutput && inmHealthCheckOkToUseData() && inmEntropyOnTarget(entropy, BUFLEN)) {
|
||||
processBytes(keccakState, bytes, entropy, raw, writeDevRandom);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ 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);
|
||||
|
||||
Reference in New Issue
Block a user