diff options
author | Nick Mathewson <nickm@torproject.org> | 2019-02-06 09:36:12 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2019-02-14 09:26:40 -0500 |
commit | acbde10fce5d688d70b5a4bfb3a736da838bb4cc (patch) | |
tree | 7a91744da5dd96bef81a5db2b3ae181fa2e934cb | |
parent | 490e187056d87ddd87981e0ea1b624b61bcbb666 (diff) | |
download | tor-acbde10fce5d688d70b5a4bfb3a736da838bb4cc.tar.gz tor-acbde10fce5d688d70b5a4bfb3a736da838bb4cc.zip |
Add a test-rng program so we can pipe to dieharder.
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | src/test/include.am | 11 | ||||
-rw-r--r-- | src/test/test_rng.c | 59 |
3 files changed, 70 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore index 6a49285b8a..a40cda02dd 100644 --- a/.gitignore +++ b/.gitignore @@ -248,6 +248,7 @@ uptime-*.json /src/test/test-memwipe /src/test/test-ntor-cl /src/test/test-hs-ntor-cl +/src/test/test-rng /src/test/test-switch-id /src/test/test-timers /src/test/test_workqueue @@ -258,6 +259,7 @@ uptime-*.json /src/test/test-ntor-cl.exe /src/test/test-hs-ntor-cl.exe /src/test/test-memwipe.exe +/src/test/test-rng.exe /src/test/test-switch-id.exe /src/test/test-timers.exe /src/test/test_workqueue.exe diff --git a/src/test/include.am b/src/test/include.am index 1b8f7f5ad3..8622fcbaa1 100644 --- a/src/test/include.am +++ b/src/test/include.am @@ -68,7 +68,8 @@ noinst_PROGRAMS+= \ src/test/test-process \ src/test/test_workqueue \ src/test/test-switch-id \ - src/test/test-timers + src/test/test-timers \ + src/test/test-rng endif src_test_AM_CPPFLAGS = -DSHARE_DATADIR="\"$(datadir)\"" \ @@ -258,7 +259,13 @@ src_test_test_LDADD = \ src_test_test_slow_CPPFLAGS = $(src_test_test_CPPFLAGS) src_test_test_slow_CFLAGS = $(src_test_test_CFLAGS) src_test_test_slow_LDADD = $(src_test_test_LDADD) -src_test_test_slow_LDFLAGS = $(src_test_test_LDFLAGS) +src_test_test_slow_LDFLAGS =@TOR_LDFLAGS_openssl@ + +src_test_test_rng_CPPFLAGS = $(src_test_test_CPPFLAGS) +src_test_test_rng_CFLAGS = $(src_test_test_CFLAGS) +src_test_test_rng_SOURCES = src/test/test_rng.c +src_test_test_rng_LDFLAGS = $(src_test_test_LDFLAGS) +src_test_test_rng_LDADD = $(src_test_test_LDADD) src_test_test_memwipe_CPPFLAGS = $(src_test_test_CPPFLAGS) # Don't use bugtrap cflags here: memwipe tests require memory violations. diff --git a/src/test/test_rng.c b/src/test/test_rng.c new file mode 100644 index 0000000000..c749de112a --- /dev/null +++ b/src/test/test_rng.c @@ -0,0 +1,59 @@ +/* Copyright (c) 2016-2019, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/* + * Example usage: + * + * ./src/test/test-rng --emit | dieharder -g 200 -a + * + * Remember, dieharder can tell you that your RNG is completely broken, but if + * your RNG is not _completely_ broken, dieharder cannot tell you whether your + * RNG is actually secure. + */ + +#include "orconfig.h" + +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#endif +#include <stdio.h> +#include <string.h> +#include <errno.h> + +#include "lib/crypt_ops/crypto_rand.h" + +int +main(int argc, char **argv) +{ + uint8_t buf[0x123]; + + if (argc != 2 || strcmp(argv[1], "--emit")) { + fprintf(stderr, "If you want me to fill stdout with a bunch of random " + "bytes, you need to say --emit.\n"); + return 1; + } + + if (crypto_seed_rng() < 0) { + fprintf(stderr, "Can't seed RNG.\n"); + return 1; + } + +#if 0 + while (1) { + crypto_rand(buf, sizeof(buf)); + if (write(1 /*stdout*/, buf, sizeof(buf)) != sizeof(buf)) { + fprintf(stderr, "write() failed: %s\n", strerror(errno)); + return 1; + } + } +#endif + + crypto_fast_rng_t *rng = crypto_fast_rng_new(); + while (1) { + crypto_fast_rng_getbytes(rng, buf, sizeof(buf)); + if (write(1 /*stdout*/, buf, sizeof(buf)) != sizeof(buf)) { + fprintf(stderr, "write() failed: %s\n", strerror(errno)); + return 1; + } + } +} |