Skip to content

bpo-30102: Improve libssl performance on POWER8 for, e.g sha256 #1181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Modules/_hashopenssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

/* EVP is the preferred interface to hashing in OpenSSL */
#include <openssl/evp.h>
#include <openssl/engine.h>
/* We use the object interface to discover what hashes OpenSSL supports. */
#include <openssl/objects.h>
#include "openssl/err.h"
Expand All @@ -43,6 +44,8 @@ module _hashlib
#define EVP_MD_CTX_free EVP_MD_CTX_destroy
#define HAS_FAST_PKCS5_PBKDF2_HMAC 0
#include <openssl/hmac.h>
/* For some reason, this function is not declared on OpenSSL's headers */
void OPENSSL_cpuid_setup(void);
#else
/* OpenSSL >= 1.1.0 */
#define HAS_FAST_PKCS5_PBKDF2_HMAC 1
Expand Down Expand Up @@ -1022,9 +1025,18 @@ PyInit__hashlib(void)
{
PyObject *m, *openssl_md_meth_names;

#ifndef OPENSSL_VERSION_1_1
/* "As of version 1.1.0 OpenSSL will automatically allocate all resources
* that it needs so no explicit initialisation is required. Similarly it
* will also automatically deinitialise as required."
* https://www.openssl.org/docs/man1.1.0/crypto/OPENSSL_init_crypto.html */
OpenSSL_add_all_digests();
ERR_load_crypto_strings();

/* Detect HW capabilities to improve performance */
OPENSSL_cpuid_setup();
#endif

/* TODO build EVP_functions openssl_* entries dynamically based
* on what hashes are supported rather than listing many
* but having some be unsupported. Only init appropriate
Expand Down
13 changes: 13 additions & 0 deletions Modules/_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ static PySocketModule_APIObject PySocketModule;
#include "openssl/err.h"
#include "openssl/rand.h"
#include "openssl/bio.h"
#include "openssl/engine.h"

/* SSL error object */
static PyObject *PySSLErrorObject;
Expand Down Expand Up @@ -175,6 +176,8 @@ static void _PySSLFixErrno(void) {
#define HAVE_OPENSSL_CRYPTO_LOCK
#endif

/* For some reason, this function is not declared on OpenSSL's headers */
void OPENSSL_cpuid_setup(void);
#define TLS_method SSLv23_method
#define TLS_client_method SSLv23_client_method
#define TLS_server_method SSLv23_server_method
Expand Down Expand Up @@ -5186,8 +5189,18 @@ PyInit__ssl(void)
_ssl_locks_count++;
#endif
#endif /* WITH_THREAD */

#ifndef OPENSSL_VERSION_1_1
/* "As of version 1.1.0 OpenSSL will automatically allocate all resources
* that it needs so no explicit initialisation is required. Similarly it
* will also automatically deinitialise as required."
* https://www.openssl.org/docs/man1.1.0/crypto/OPENSSL_init_crypto.html */
OpenSSL_add_all_algorithms();

/* Detect HW capabilities to improve performance */
OPENSSL_cpuid_setup();
#endif

/* Add symbols to module dict */
sslerror_type_slots[0].pfunc = PyExc_OSError;
PySSLErrorObject = PyType_FromSpec(&sslerror_type_spec);
Expand Down
2 changes: 1 addition & 1 deletion PCbuild/_hashlib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
</PropertyGroup>
<ItemDefinitionGroup>
<Link>
<AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>ws2_32.lib;crypt32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
Expand Down