Skip to content

bpo-36559: random module: optimize sha512 import#12742

Merged
rhettinger merged 1 commit intopython:masterfrom
tiran:bpo36559_random_sha512
Apr 10, 2019
Merged

bpo-36559: random module: optimize sha512 import#12742
rhettinger merged 1 commit intopython:masterfrom
tiran:bpo36559_random_sha512

Conversation

@tiran
Copy link
Copy Markdown
Member

@tiran tiran commented Apr 9, 2019

The random module now prefers the lean internal _sha512 module over hashlib
for seed(version=2) to optimize import time.

Signed-off-by: Christian Heimes christian@python.org

https://bugs.python.org/issue36559

@serhiy-storchaka
Copy link
Copy Markdown
Member

Does it work without OpenSSL?

@vstinner
Copy link
Copy Markdown
Member

vstinner commented Apr 9, 2019

Travis CI failed:

$ ./python Tools/scripts/patchcheck.py --travis $TRAVIS_PULL_REQUEST
...
Fixing Python file whitespace ... 1 file:
  Lib/random.py

@vstinner
Copy link
Copy Markdown
Member

vstinner commented Apr 9, 2019

Does it work without OpenSSL?

Yes, the _sha512 module is unrelated to OpenSSL. Moreover, _sha512 is available if even _hashlib (_hashopenssl.c) is missing. The _sha512 module is available even if OpenSSL is available.

The random module now prefers the lean internal _sha512 module over hashlib
for seed(version=2) to optimize import time.

Signed-off-by: Christian Heimes <christian@python.org>
@tiran tiran force-pushed the bpo36559_random_sha512 branch from 161956d to 8f45246 Compare April 9, 2019 17:18
@tiran
Copy link
Copy Markdown
Member Author

tiran commented Apr 9, 2019

The _sha512 module contains a full implementation of sha512 and sha384 based on code from libtomcrypt. Python always builds these modules. Some vendors may not deliver the modules, because the code is not FIPS approved crypto. That's why I have included a fallback to hashlib.

@rhettinger rhettinger merged commit d914596 into python:master Apr 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants