Skip to content

Commit 7daa45d

Browse files
authored
[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 <[email protected]> (cherry picked from commit c941e62)
1 parent ffa7011 commit 7daa45d

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
@@ -899,8 +899,11 @@ init_hashlib(void)
899899
{
900900
PyObject *m, *openssl_md_meth_names;
901901

902-
OpenSSL_add_all_digests();
902+
#ifndef OPENSSL_VERSION_1_1
903+
/* Load all digest algorithms and initialize cpuid */
904+
OPENSSL_add_all_algorithms_noconf();
903905
ERR_load_crypto_strings();
906+
#endif
904907

905908
/* TODO build EVP_functions openssl_* entries dynamically based
906909
* 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
@@ -4084,9 +4084,14 @@ init_ssl(void)
40844084
if (PySocketModule_ImportModuleAndAPI())
40854085
return;
40864086

4087+
#ifndef OPENSSL_VERSION_1_1
4088+
/* Load all algorithms and initialize cpuid */
4089+
OPENSSL_add_all_algorithms_noconf();
40874090
/* Init OpenSSL */
40884091
SSL_load_error_strings();
40894092
SSL_library_init();
4093+
#endif
4094+
40904095
#ifdef WITH_THREAD
40914096
#ifdef HAVE_OPENSSL_CRYPTO_LOCK
40924097
/* note that this will start threading if not already started */
@@ -4098,7 +4103,6 @@ init_ssl(void)
40984103
_ssl_locks_count++;
40994104
#endif
41004105
#endif /* WITH_THREAD */
4101-
OpenSSL_add_all_algorithms();
41024106

41034107
/* Add symbols to module dict */
41044108
PySSLErrorObject = PyErr_NewExceptionWithDoc(

0 commit comments

Comments
 (0)