4
* test driver for the stat_test functions
11
#include <stdio.h> /* for printf() */
23
random_source_alloc(void);
26
err_check(err_status_t s) {
28
printf("error (code %d)\n", s);
34
main (int argc, char *argv[]) {
36
unsigned int buf_len = 2500;
38
extern cipher_type_t aes_icm;
41
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
42
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
43
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
44
0x00, 0x01, 0x02, 0x03, 0x04, 0x05
50
printf("statistical tests driver\n");
52
for (i=0; i < 2500; i++)
56
printf("running stat_tests on all-null buffer, expecting failure\n");
57
printf("monobit %d\n", stat_test_monobit(buffer));
58
printf("poker %d\n", stat_test_poker(buffer));
59
printf("runs %d\n", stat_test_runs(buffer));
61
for (i=0; i < 2500; i++)
63
printf("running stat_tests on rand(), expecting success\n");
64
printf("monobit %d\n", stat_test_monobit(buffer));
65
printf("poker %d\n", stat_test_poker(buffer));
66
printf("runs %d\n", stat_test_runs(buffer));
68
printf("running stat_tests on AES-128-ICM, expecting success\n");
69
/* set buffer to cipher output */
70
for (i=0; i < 2500; i++)
72
err_check(cipher_type_alloc(&aes_icm, &c, 30));
73
err_check(cipher_init(c, key, direction_encrypt));
74
err_check(cipher_set_iv(c, &nonce));
75
err_check(cipher_encrypt(c, buffer, &buf_len));
76
/* run tests on cipher outout */
77
printf("monobit %d\n", stat_test_monobit(buffer));
78
printf("poker %d\n", stat_test_poker(buffer));
79
printf("runs %d\n", stat_test_runs(buffer));
81
printf("runs test (please be patient): ");
84
v128_set_to_zero(&nonce);
85
for(j=0; j < num_trials; j++) {
86
for (i=0; i < 2500; i++)
89
err_check(cipher_set_iv(c, &nonce));
90
err_check(cipher_encrypt(c, buffer, &buf_len));
91
if (stat_test_runs(buffer)) {
96
printf("%d failures in %d tests\n", num_fail, num_trials);
97
printf("(nota bene: a small fraction of stat_test failures does not \n"
98
"indicate that the random source is invalid)\n");