[2.7] bpo-30102: Call OPENSSL_add_all_algorithms_noconf (GH-3112) (#3343)

The ssl and hashlib modules now call OPENSSL_add_all_algorithms_noconf() on
OpenSSL < 1.1.0. The function detects CPU features and enables optimizations
on some CPU architectures such as POWER8. Patch is based on research from
Gustavo Serra Scalet.

Signed-off-by: Christian Heimes <christian@python.org>
(cherry picked from commit c941e62)
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index 832b5f9..2bc981f 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -4084,9 +4084,14 @@
     if (PySocketModule_ImportModuleAndAPI())
         return;
 
+#ifndef OPENSSL_VERSION_1_1
+    /* Load all algorithms and initialize cpuid */
+    OPENSSL_add_all_algorithms_noconf();
     /* Init OpenSSL */
     SSL_load_error_strings();
     SSL_library_init();
+#endif
+
 #ifdef WITH_THREAD
 #ifdef HAVE_OPENSSL_CRYPTO_LOCK
     /* note that this will start threading if not already started */
@@ -4098,7 +4103,6 @@
     _ssl_locks_count++;
 #endif
 #endif  /* WITH_THREAD */
-    OpenSSL_add_all_algorithms();
 
     /* Add symbols to module dict */
     PySSLErrorObject = PyErr_NewExceptionWithDoc(