N_ENTROPY randomness metrics regression (headless).
N_ENTROPY randomness metrics regression (headless).
#include <math.h>
#include <string.h>
static void approx(
const char* label,
double got,
double want,
double tol) {
if (fabs(got - want) > tol) {
n_log(
LOG_ERR,
"%s: got %.4f, expected %.4f", label, got, want);
}
}
unsigned char uni[256];
unsigned char same[64];
unsigned char z[8];
unsigned char f[8];
unsigned char half[8];
unsigned char two[4] = {'A', 'B', 'A', 'B'};
int i;
for (i = 0; i < 256; i++)
uni[i] = (unsigned char)i;
memset(same, 'A', sizeof(same));
}
memset(z, 0x00, sizeof(z));
memset(f, 0xFF, sizeof(f));
memset(half, 0x0F, sizeof(half));
return 1;
}
return 0;
}
static void approx(const char *label, double got, double want, double tol)
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_ERR
error conditions
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL )
#define LOG_NOTICE
normal but significant condition
double n_entropy_shannon(const unsigned char *data, size_t len)
Shannon entropy of the byte sample, in bits per byte (0.0 .
double n_entropy_monobit(const unsigned char *data, size_t len)
Fraction of set bits in the sample (0.0 .
double n_entropy_chi_square(const unsigned char *data, size_t len)
Chi-square statistic of the byte histogram against a uniform distribution over 256 values.
Randomness/entropy metrics for byte samples (token-randomness analysis)