Skip to content
Snippets Groups Projects
Commit 1a14e5be authored by Nick Mathewson's avatar Nick Mathewson :game_die:
Browse files

Remove crypto/rand include from test_crypto.c

Create a new test_crypto_openssl to test openssl-only crypto.c
functionality.
parent 38fb651f
No related branches found
No related tags found
No related merge requests found
......@@ -91,6 +91,7 @@ src_test_test_SOURCES = \
src/test/test_controller.c \
src/test/test_controller_events.c \
src/test/test_crypto.c \
src/test/test_crypto_openssl.c \
src/test/test_data.c \
src/test/test_dir.c \
src/test/test_dir_common.c \
......
......@@ -1199,6 +1199,7 @@ struct testgroup_t testgroups[] = {
{ "control/", controller_tests },
{ "control/event/", controller_event_tests },
{ "crypto/", crypto_tests },
{ "crypto/openssl/", crypto_openssl_tests },
{ "dir/", dir_tests },
{ "dir_handle_get/", dir_handle_get_tests },
{ "dir/md/", microdesc_tests },
......
......@@ -194,6 +194,7 @@ extern struct testcase_t container_tests[];
extern struct testcase_t controller_tests[];
extern struct testcase_t controller_event_tests[];
extern struct testcase_t crypto_tests[];
extern struct testcase_t crypto_openssl_tests[];
extern struct testcase_t dir_tests[];
extern struct testcase_t dir_handle_get_tests[];
extern struct testcase_t entryconn_tests[];
......
......@@ -16,7 +16,6 @@
#include "ed25519_vectors.inc"
#include <openssl/evp.h>
#include <openssl/rand.h>
/** Run unit tests for Diffie-Hellman functionality. */
static void
......@@ -331,38 +330,6 @@ test_crypto_rng_strongest(void *arg)
#undef N
}
/* 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:
;
}
/** Run unit tests for our AES128 functionality */
static void
test_crypto_aes128(void *arg)
......@@ -2941,7 +2908,6 @@ struct testcase_t crypto_tests[] = {
CRYPTO_LEGACY(formats),
CRYPTO_LEGACY(rng),
{ "rng_range", test_crypto_rng_range, 0, NULL, NULL },
{ "rng_engine", test_crypto_rng_engine, TT_FORK, NULL, NULL },
{ "rng_strongest", test_crypto_rng_strongest, TT_FORK, NULL, NULL },
{ "rng_strongest_nosyscall", test_crypto_rng_strongest, TT_FORK,
&passthrough_setup, (void*)"nosyscall" },
......
/* 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
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment