summaryrefslogtreecommitdiff
path: root/src/common/crypto.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-06-20 18:56:35 +0000
committerNick Mathewson <nickm@torproject.org>2005-06-20 18:56:35 +0000
commit2aff87caae0055a4767e60356f44612db20ad5c1 (patch)
tree99dab8d7e82e8650c07e5c5fc40336e5ecbcb7cc /src/common/crypto.c
parent5eef9177c57ccac03b6676e039c56bf7a6705198 (diff)
downloadtor-2aff87caae0055a4767e60356f44612db20ad5c1.tar.gz
tor-2aff87caae0055a4767e60356f44612db20ad5c1.zip
Load hardware acceleration options when/where available. Can anybody test this?
svn:r4467
Diffstat (limited to 'src/common/crypto.c')
-rw-r--r--src/common/crypto.c42
1 files changed, 38 insertions, 4 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c
index 549735b38d..c84c675397 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -22,6 +22,7 @@ const char crypto_c_id[] = "$Id$";
#include <string.h>
+#include <openssl/engine.h>
#include <openssl/err.h>
#include <openssl/rsa.h>
#include <openssl/pem.h>
@@ -159,14 +160,46 @@ crypto_log_errors(int severity, const char *doing)
}
}
+static void
+log_engine(const char *fn, ENGINE *e)
+{
+ if (e) {
+ const char *name, *id;
+ name = ENGINE_get_name(e);
+ id = ENGINE_get_id(e);
+ log(LOG_NOTICE, "Using OpenSSL engine %s [%s] for %s",
+ name?name:"?", id?id:"?", fn);
+ } else {
+ log(LOG_INFO, "Using default implementation for %s", fn);
+ }
+}
+
/** Initialize the crypto library. Return 0 on success, -1 on failure.
*/
-int crypto_global_init()
+int
+crypto_global_init(int useAccel)
{
if (!_crypto_global_initialized) {
- ERR_load_crypto_strings();
- _crypto_global_initialized = 1;
- setup_openssl_threading();
+ ERR_load_crypto_strings();
+ OpenSSL_add_all_algorithms();
+ _crypto_global_initialized = 1;
+ setup_openssl_threading();
+ if (useAccel) {
+ if (useAccel < 0)
+ log_fn(LOG_WARN, "Initializing OpenSSL via tor_tls_init().");
+ log_fn(LOG_INFO, "Initializing OpenSSL engine support.");
+ ENGINE_load_builtin_engines();
+ if (!ENGINE_register_all_complete())
+ return -1;
+
+ /* XXXX make sure this isn't leaking. */
+ log_engine("RSA", ENGINE_get_default_RSA());
+ log_engine("DH", ENGINE_get_default_DH());
+ log_engine("RAND", ENGINE_get_default_RAND());
+ log_engine("SHA1", ENGINE_get_digest_engine(NID_sha1));
+ log_engine("3DES", ENGINE_get_cipher_engine(NID_des_ede3_ecb));
+ log_engine("AES", ENGINE_get_cipher_engine(NID_aes_128_ecb));
+ }
}
return 0;
}
@@ -176,6 +209,7 @@ int crypto_global_init()
int crypto_global_cleanup()
{
ERR_free_strings();
+ ENGINE_cleanup();
#ifdef TOR_IS_MULTITHREADED
if (_n_openssl_mutexes) {
int n = _n_openssl_mutexes;