[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] Load hardware acceleration options when/where available. C...
Update of /home/or/cvsroot/tor/src/common
In directory moria:/tmp/cvs-serv22033/src/common
Modified Files:
crypto.c crypto.h tortls.c
Log Message:
Load hardware acceleration options when/where available. Can anybody test this?
Index: crypto.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/crypto.c,v
retrieving revision 1.141
retrieving revision 1.142
diff -u -d -r1.141 -r1.142
--- crypto.c 15 Jun 2005 18:34:46 -0000 1.141
+++ crypto.c 20 Jun 2005 18:56:34 -0000 1.142
@@ -22,6 +22,7 @@
#include <string.h>
+#include <openssl/engine.h>
#include <openssl/err.h>
#include <openssl/rsa.h>
#include <openssl/pem.h>
@@ -159,14 +160,46 @@
}
}
+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_cleanup()
{
ERR_free_strings();
+ ENGINE_cleanup();
#ifdef TOR_IS_MULTITHREADED
if (_n_openssl_mutexes) {
int n = _n_openssl_mutexes;
Index: crypto.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/crypto.h,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -d -r1.64 -r1.65
--- crypto.h 11 Jun 2005 05:31:15 -0000 1.64
+++ crypto.h 20 Jun 2005 18:56:34 -0000 1.65
@@ -48,7 +48,7 @@
typedef struct crypto_dh_env_t crypto_dh_env_t;
/* global state */
-int crypto_global_init(void);
+int crypto_global_init(int hardwareAccel);
int crypto_global_cleanup(void);
/* environment setup */
Index: tortls.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/tortls.c,v
retrieving revision 1.97
retrieving revision 1.98
diff -u -d -r1.97 -r1.98
--- tortls.c 11 Jun 2005 05:31:15 -0000 1.97
+++ tortls.c 20 Jun 2005 18:56:34 -0000 1.98
@@ -148,12 +148,11 @@
/** Initialize OpenSSL, unless it has already been initialized.
*/
static void
-tor_tls_init(void) {
+tor_tls_init() {
if (!tls_library_is_initialized) {
SSL_library_init();
SSL_load_error_strings();
- crypto_global_init();
- OpenSSL_add_all_algorithms();
+ crypto_global_init(-1);
tls_library_is_initialized = 1;
}
}