Skip to content

Commit 2ddea0f

Browse files
authored
[3.6] bpo-30102: Call OPENSSL_add_all_algorithms_noconf (GH-3112) (#3342)
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 <[email protected]> (cherry picked from commit c941e62)
1 parent 02854da commit 2ddea0f

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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.

Modules/_hashopenssl.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,8 +1022,11 @@ PyInit__hashlib(void)
10221022
{
10231023
PyObject *m, *openssl_md_meth_names;
10241024

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();
10261028
ERR_load_crypto_strings();
1029+
#endif
10271030

10281031
/* TODO build EVP_functions openssl_* entries dynamically based
10291032
* on what hashes are supported rather than listing many

Modules/_ssl.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5171,9 +5171,14 @@ PyInit__ssl(void)
51715171
return NULL;
51725172
PySocketModule = *socket_api;
51735173

5174+
#ifndef OPENSSL_VERSION_1_1
5175+
/* Load all algorithms and initialize cpuid */
5176+
OPENSSL_add_all_algorithms_noconf();
51745177
/* Init OpenSSL */
51755178
SSL_load_error_strings();
51765179
SSL_library_init();
5180+
#endif
5181+
51775182
#ifdef WITH_THREAD
51785183
#ifdef HAVE_OPENSSL_CRYPTO_LOCK
51795184
/* note that this will start threading if not already started */
@@ -5185,7 +5190,6 @@ PyInit__ssl(void)
51855190
_ssl_locks_count++;
51865191
#endif
51875192
#endif /* WITH_THREAD */
5188-
OpenSSL_add_all_algorithms();
51895193

51905194
/* Add symbols to module dict */
51915195
sslerror_type_slots[0].pfunc = PyExc_OSError;

0 commit comments

Comments
 (0)