Skip to content

Commit 1ef9727

Browse files
committed
bpo-30102: Call OPENSSL_add_all_algorithms_noconf
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>
1 parent af64aff commit 1ef9727

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
@@ -5181,9 +5181,14 @@ PyInit__ssl(void)
51815181
return NULL;
51825182
PySocketModule = *socket_api;
51835183

5184+
#ifndef OPENSSL_VERSION_1_1
5185+
/* Load all algorithms and initialize cpuid */
5186+
OPENSSL_add_all_algorithms_noconf();
51845187
/* Init OpenSSL */
51855188
SSL_load_error_strings();
51865189
SSL_library_init();
5190+
#endif
5191+
51875192
#ifdef WITH_THREAD
51885193
#ifdef HAVE_OPENSSL_CRYPTO_LOCK
51895194
/* note that this will start threading if not already started */
@@ -5195,7 +5200,6 @@ PyInit__ssl(void)
51955200
_ssl_locks_count++;
51965201
#endif
51975202
#endif /* WITH_THREAD */
5198-
OpenSSL_add_all_algorithms();
51995203

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

0 commit comments

Comments
 (0)