diff options
author | Nick Mathewson <nickm@torproject.org> | 2017-03-25 12:04:11 +0100 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-03-31 10:04:44 -0400 |
commit | 1a14e5be91cfd32f8eee30896eb432a7ff060c05 (patch) | |
tree | 235b2f7fef2653270f7c707df41b7712809e05d0 /src/test/test_crypto_openssl.c | |
parent | 38fb651f0d740bef575ad7f95475cc504ea4cb8f (diff) | |
download | tor-1a14e5be91cfd32f8eee30896eb432a7ff060c05.tar.gz tor-1a14e5be91cfd32f8eee30896eb432a7ff060c05.zip |
Remove crypto/rand include from test_crypto.c
Create a new test_crypto_openssl to test openssl-only crypto.c
functionality.
Diffstat (limited to 'src/test/test_crypto_openssl.c')
-rw-r--r-- | src/test/test_crypto_openssl.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/test/test_crypto_openssl.c b/src/test/test_crypto_openssl.c new file mode 100644 index 0000000000..64e33f5fa6 --- /dev/null +++ b/src/test/test_crypto_openssl.c @@ -0,0 +1,52 @@ +/* Copyright (c) 2001-2004, Roger Dingledine. + * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. + * Copyright (c) 2007-2017, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +#include "orconfig.h" + +#define CRYPTO_PRIVATE + +#include "crypto.h" +#include "test.h" + +#include <openssl/evp.h> +#include <openssl/rand.h> +#include "compat_openssl.h" + +/* Test for rectifying openssl RAND engine. */ +static void +test_crypto_rng_engine(void *arg) +{ + (void)arg; + RAND_METHOD dummy_method; + memset(&dummy_method, 0, sizeof(dummy_method)); + + /* We should be a no-op if we're already on RAND_OpenSSL */ + tt_int_op(0, ==, crypto_force_rand_ssleay()); + tt_assert(RAND_get_rand_method() == RAND_OpenSSL()); + + /* We should correct the method if it's a dummy. */ + RAND_set_rand_method(&dummy_method); +#ifdef LIBRESSL_VERSION_NUMBER + /* On libressl, you can't override the RNG. */ + tt_assert(RAND_get_rand_method() == RAND_OpenSSL()); + tt_int_op(0, ==, crypto_force_rand_ssleay()); +#else + tt_assert(RAND_get_rand_method() == &dummy_method); + tt_int_op(1, ==, crypto_force_rand_ssleay()); +#endif + tt_assert(RAND_get_rand_method() == RAND_OpenSSL()); + + /* Make sure we aren't calling dummy_method */ + crypto_rand((void *) &dummy_method, sizeof(dummy_method)); + crypto_rand((void *) &dummy_method, sizeof(dummy_method)); + + done: + ; +} + +struct testcase_t crypto_openssl_tests[] = { + { "rng_engine", test_crypto_rng_engine, TT_FORK, NULL, NULL }, + END_OF_TESTCASES +}; |