Loading src/common/crypto.c +1 −1 Original line number Diff line number Diff line Loading @@ -252,7 +252,7 @@ crypto_openssl_get_header_version_str(void) /** Make sure that openssl is using its default PRNG. Return 1 if we had to * adjust it; 0 otherwise. */ static int STATIC int crypto_force_rand_ssleay(void) { RAND_METHOD *default_method; Loading src/common/crypto.h +4 −0 Original line number Diff line number Diff line Loading @@ -314,5 +314,9 @@ struct dh_st *crypto_dh_get_dh_(crypto_dh_t *dh); void crypto_add_spaces_to_fp(char *out, size_t outlen, const char *in); #ifdef CRYPTO_PRIVATE STATIC int crypto_force_rand_ssleay(void); #endif #endif src/test/test_crypto.c +29 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ #include "orconfig.h" #define CRYPTO_CURVE25519_PRIVATE #define CRYPTO_PRIVATE #include "or.h" #include "test.h" #include "aes.h" Loading @@ -15,6 +16,7 @@ #include "ed25519_vectors.inc" #include <openssl/evp.h> #include <openssl/rand.h> extern const char AUTHORITY_SIGNKEY_3[]; extern const char AUTHORITY_SIGNKEY_A_DIGEST[]; Loading Loading @@ -131,6 +133,32 @@ test_crypto_rng_range(void *arg) ; } /* 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); tt_assert(RAND_get_rand_method() == &dummy_method); tt_int_op(1, ==, crypto_force_rand_ssleay()); 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 AES functionality */ static void test_crypto_aes(void *arg) Loading Loading @@ -2358,6 +2386,7 @@ 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 }, { "aes_AES", test_crypto_aes, TT_FORK, &passthrough_setup, (void*)"aes" }, { "aes_EVP", test_crypto_aes, TT_FORK, &passthrough_setup, (void*)"evp" }, CRYPTO_LEGACY(sha), Loading Loading
src/common/crypto.c +1 −1 Original line number Diff line number Diff line Loading @@ -252,7 +252,7 @@ crypto_openssl_get_header_version_str(void) /** Make sure that openssl is using its default PRNG. Return 1 if we had to * adjust it; 0 otherwise. */ static int STATIC int crypto_force_rand_ssleay(void) { RAND_METHOD *default_method; Loading
src/common/crypto.h +4 −0 Original line number Diff line number Diff line Loading @@ -314,5 +314,9 @@ struct dh_st *crypto_dh_get_dh_(crypto_dh_t *dh); void crypto_add_spaces_to_fp(char *out, size_t outlen, const char *in); #ifdef CRYPTO_PRIVATE STATIC int crypto_force_rand_ssleay(void); #endif #endif
src/test/test_crypto.c +29 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ #include "orconfig.h" #define CRYPTO_CURVE25519_PRIVATE #define CRYPTO_PRIVATE #include "or.h" #include "test.h" #include "aes.h" Loading @@ -15,6 +16,7 @@ #include "ed25519_vectors.inc" #include <openssl/evp.h> #include <openssl/rand.h> extern const char AUTHORITY_SIGNKEY_3[]; extern const char AUTHORITY_SIGNKEY_A_DIGEST[]; Loading Loading @@ -131,6 +133,32 @@ test_crypto_rng_range(void *arg) ; } /* 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); tt_assert(RAND_get_rand_method() == &dummy_method); tt_int_op(1, ==, crypto_force_rand_ssleay()); 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 AES functionality */ static void test_crypto_aes(void *arg) Loading Loading @@ -2358,6 +2386,7 @@ 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 }, { "aes_AES", test_crypto_aes, TT_FORK, &passthrough_setup, (void*)"aes" }, { "aes_EVP", test_crypto_aes, TT_FORK, &passthrough_setup, (void*)"evp" }, CRYPTO_LEGACY(sha), Loading