[v2,3/3] linux-generic: crypto: support OpenSSL 1.1.0

Message ID 20170207180617.5169-3-dmitry.ereminsolenikov@linaro.org
State New
Headers show
Series
  • [v2,1/3] linux-generic: crypto: add missing include
Related show

Commit Message

Dmitry Eremin-Solenikov Feb. 7, 2017, 6:06 p.m.
OpenSSL 1.1.0 uses new threading API. It is no longer necessary to set
locking callbacks to use OpenSSL in a multi-threaded environment. The
old threading API should no longer be used. So don't allocate/set
locking callbacks with new OpenSSL.

Signed-off-by: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>

---
 platform/linux-generic/odp_crypto.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

-- 
2.11.0

Patch

diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c
index d83b8e09..d1d32497 100644
--- a/platform/linux-generic/odp_crypto.c
+++ b/platform/linux-generic/odp_crypto.c
@@ -26,6 +26,7 @@ 
 #include <openssl/rand.h>
 #include <openssl/hmac.h>
 #include <openssl/evp.h>
+#include <openssl/opensslv.h>
 
 #define MAX_SESSIONS 32
 
@@ -948,16 +949,18 @@  odp_crypto_operation(odp_crypto_op_param_t *param,
 	return 0;
 }
 
-static unsigned long openssl_thread_id(void)
+static
+unsigned long ODP_UNUSED openssl_thread_id(void)
 {
 	return (unsigned long)odp_thread_id();
 }
 
 odp_ticketlock_t *openssl_locks;
 
-static void openssl_lock(int mode, int n,
-			 const char *file ODP_UNUSED,
-			 int line ODP_UNUSED)
+static
+void ODP_UNUSED openssl_lock(int mode, int n,
+			     const char *file ODP_UNUSED,
+			     int line ODP_UNUSED)
 {
 	if (mode & CRYPTO_LOCK)
 		odp_ticketlock_lock(&openssl_locks[n]);
@@ -972,6 +975,10 @@  static void openssl_init_locks(void)
 	odp_shm_t shm;
 	int idx;
 
+	/* OpenSSL does not need locks after 1.1.0 */
+	if (OPENSSL_VERSION_NUMBER >= 0x10100000L)
+		return;
+
 	nlocks = CRYPTO_num_locks();
 	if (nlocks <= 0)
 		return;
@@ -996,6 +1003,10 @@  static void openssl_init_locks(void)
 
 static int openssl_term_locks(void)
 {
+	/* OpenSSL does not need locks after 1.1.0 */
+	if (OPENSSL_VERSION_NUMBER >= 0x10100000L)
+		return 0;
+
 	CRYPTO_set_locking_callback(NULL);
 	CRYPTO_set_id_callback(NULL);