1 /* Copyright (c) 2016-2020, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
7 * ./src/test/test-rng --emit | dieharder -g 200 -a
9 * Remember, dieharder can tell you that your RNG is completely broken, but if
10 * your RNG is not _completely_ broken, dieharder cannot tell you whether your
11 * RNG is actually secure.
23 #include "lib/crypt_ops/crypto_rand.h"
26 main(int argc
, char **argv
)
30 if (argc
!= 2 || strcmp(argv
[1], "--emit")) {
31 fprintf(stderr
, "If you want me to fill stdout with a bunch of random "
32 "bytes, you need to say --emit.\n");
36 if (crypto_seed_rng() < 0) {
37 fprintf(stderr
, "Can't seed RNG.\n");
43 crypto_rand(buf
, sizeof(buf
));
44 if (write(1 /*stdout*/, buf
, sizeof(buf
)) != sizeof(buf
)) {
45 fprintf(stderr
, "write() failed: %s\n", strerror(errno
));
51 crypto_fast_rng_t
*rng
= crypto_fast_rng_new();
53 crypto_fast_rng_getbytes(rng
, buf
, sizeof(buf
));
54 if (write(1 /*stdout*/, buf
, sizeof(buf
)) != sizeof(buf
)) {
55 fprintf(stderr
, "write() failed: %s\n", strerror(errno
));