Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/random/unit_test.c
Show All 25 Lines | |||||
* $FreeBSD$ | * $FreeBSD$ | ||||
*/ | */ | ||||
/* | /* | ||||
Build this by going: | Build this by going: | ||||
cc -g -O0 -pthread -DRANDOM_<alg> -I../.. -lstdthreads -Wall \ | cc -g -O0 -pthread -DRANDOM_<alg> -I../.. -lstdthreads -Wall \ | ||||
unit_test.c \ | unit_test.c \ | ||||
yarrow.c \ | |||||
fortuna.c \ | fortuna.c \ | ||||
hash.c \ | hash.c \ | ||||
../../crypto/rijndael/rijndael-api-fst.c \ | ../../crypto/rijndael/rijndael-api-fst.c \ | ||||
../../crypto/rijndael/rijndael-alg-fst.c \ | ../../crypto/rijndael/rijndael-alg-fst.c \ | ||||
../../crypto/sha2/sha256c.c \ | ../../crypto/sha2/sha256c.c \ | ||||
-lz \ | -lz \ | ||||
-o unit_test | -o unit_test | ||||
./unit_test | ./unit_test | ||||
Where <alg> is YARROW or FORTUNA. | Where <alg> is FORTUNA. The parameterisation is a leftover from | ||||
when Yarrow was an option, and remains to enable the testing of | |||||
possible future algorithms. | |||||
*/ | */ | ||||
#include <sys/types.h> | #include <sys/types.h> | ||||
#include <inttypes.h> | #include <inttypes.h> | ||||
#include <stdbool.h> | #include <stdbool.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <threads.h> | #include <threads.h> | ||||
▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Lines | for (i = 0; ; i++) { | ||||
if (stopseeding) | if (stopseeding) | ||||
break; | break; | ||||
if (i % 1000 == 0) | if (i % 1000 == 0) | ||||
printf("Harvest: %d\n", i); | printf("Harvest: %d\n", i); | ||||
r = random()%10; | r = random()%10; | ||||
e.he_somecounter = i; | e.he_somecounter = i; | ||||
*((uint64_t *)e.he_entropy) = random(); | *((uint64_t *)e.he_entropy) = random(); | ||||
e.he_size = 8; | e.he_size = 8; | ||||
e.he_bits = random()%4; | |||||
e.he_destination = i; | e.he_destination = i; | ||||
e.he_source = (i + 3)%7; | e.he_source = (i + 3)%7; | ||||
e.he_next = NULL; | e.he_next = NULL; | ||||
random_alg_context.ra_event_processor(&e); | random_alg_context.ra_event_processor(&e); | ||||
usleep(r); | usleep(r); | ||||
} | } | ||||
printf("Thread #0 ends\n"); | printf("Thread #0 ends\n"); | ||||
▲ Show 20 Lines • Show All 99 Lines • Show Last 20 Lines |