[3.6] bpo-30102: Call OPENSSL_add_all_algorithms_noconf (GH-3112) (#3… · python/cpython@2ddea0f (original) (raw)

3 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1 +The ssl and hashlib modules now call OPENSSL_add_all_algorithms_noconf() on
2 +OpenSSL < 1.1.0. The function detects CPU features and enables optimizations
3 +on some CPU architectures such as POWER8. Patch is based on research from
4 +Gustavo Serra Scalet.
Original file line number Diff line number Diff line change
@@ -1022,8 +1022,11 @@ PyInit__hashlib(void)
1022 1022 {
1023 1023 PyObject *m, *openssl_md_meth_names;
1024 1024
1025 -OpenSSL_add_all_digests();
1025 +#ifndef OPENSSL_VERSION_1_1
1026 +/* Load all digest algorithms and initialize cpuid */
1027 +OPENSSL_add_all_algorithms_noconf();
1026 1028 ERR_load_crypto_strings();
1029 +#endif
1027 1030
1028 1031 /* TODO build EVP_functions openssl_* entries dynamically based
1029 1032 * on what hashes are supported rather than listing many
Original file line number Diff line number Diff line change
@@ -5171,9 +5171,14 @@ PyInit__ssl(void)
5171 5171 return NULL;
5172 5172 PySocketModule = *socket_api;
5173 5173
5174 +#ifndef OPENSSL_VERSION_1_1
5175 +/* Load all algorithms and initialize cpuid */
5176 +OPENSSL_add_all_algorithms_noconf();
5174 5177 /* Init OpenSSL */
5175 5178 SSL_load_error_strings();
5176 5179 SSL_library_init();
5180 +#endif
5181 +
5177 5182 #ifdef WITH_THREAD
5178 5183 #ifdef HAVE_OPENSSL_CRYPTO_LOCK
5179 5184 /* note that this will start threading if not already started */
@@ -5185,7 +5190,6 @@ PyInit__ssl(void)
5185 5190 _ssl_locks_count++;
5186 5191 #endif
5187 5192 #endif /* WITH_THREAD */
5188 -OpenSSL_add_all_algorithms();
5189 5193
5190 5194 /* Add symbols to module dict */
5191 5195 sslerror_type_slots[0].pfunc = PyExc_OSError;