summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Benjamin Barenblat <bbaren@mit.edu>2016-07-20 17:47:49 -0400
committerGravatar Benjamin Barenblat <bbaren@mit.edu>2016-07-20 17:47:49 -0400
commitb14760f0724926327a35dcb5e8592266632101cf (patch)
treeb91f3f083655ea7dc77e9b89f40c82d049e108ca
parente753293303a8dcd002ad16ec3d2a42fcc6402485 (diff)
Support OpenSSL 1.1
-rw-r--r--src/c/openssl.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/c/openssl.c b/src/c/openssl.c
index 15c4de5e..5982b831 100644
--- a/src/c/openssl.c
+++ b/src/c/openssl.c
@@ -1,6 +1,5 @@
#include "config.h"
-#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
@@ -8,17 +7,13 @@
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
-#include <pthread.h>
-#include <openssl/crypto.h>
+#include <openssl/opensslv.h>
#include <openssl/sha.h>
#include <openssl/rand.h>
#define PASSSIZE 4
-// OpenSSL locks array. See threads(3SSL).
-static pthread_mutex_t *openssl_locks;
-
int uw_hash_blocksize = 32;
static int password[PASSSIZE];
@@ -33,6 +28,17 @@ static void random_password() {
}
}
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
+// We're using OpenSSL <1.1, so we need to specify threading callbacks. See
+// threads(3SSL).
+
+#include <assert.h>
+#include <pthread.h>
+
+#include <openssl/crypto.h>
+
+static pthread_mutex_t *openssl_locks;
+
// OpenSSL callbacks
#ifdef PTHREAD_T_IS_POINTER
static void thread_id(CRYPTO_THREADID *const result) {
@@ -60,7 +66,7 @@ static void lock_or_unlock(const int mode, const int type, const char *file,
}
}
-void uw_init_crypto() {
+static void init_openssl() {
int i;
// Set up OpenSSL.
assert(openssl_locks == NULL);
@@ -74,6 +80,18 @@ void uw_init_crypto() {
}
CRYPTO_THREADID_set_callback(thread_id);
CRYPTO_set_locking_callback(lock_or_unlock);
+}
+
+#else
+// We're using OpenSSL >=1.1, which is thread-safe by default. We don't need to
+// do anything here.
+
+static void init_openssl() {}
+
+#endif // OPENSSL_VERSION_NUMBER < 0x10100000L
+
+void uw_init_crypto() {
+ init_openssl();
// Prepare signatures.
if (uw_sig_file) {
int fd;