This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Simplify hashlib implementation
Type: enhancement Stage: patch review
Components: Extension Modules Versions: Python 3.9, Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: christian.heimes Nosy List: christian.heimes, cstratak, gregory.p.smith, matrixise, miss-islington
Priority: normal Keywords: patch

Created on 2019-09-12 10:44 by christian.heimes, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 16023 merged christian.heimes, 2019-09-12 10:52
PR 16040 merged miss-islington, 2019-09-12 12:42
PR 16041 merged christian.heimes, 2019-09-12 12:45
PR 16048 merged miss-islington, 2019-09-12 13:31
Messages (6)
msg352099 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2019-09-12 10:44
The hashlib module uses complicated macros and some pointless optimization. The code can be simplified to make maintenance easier. Cleanup also makes it easier to get rid of static global state and to add "usedforsecurity" feature.

* The EVPobject contains a PyObject* with the name of the hashing algorithm as PyUnicode object. The name is rarely used and can be efficiently calculated from a const char* of the EVP_MD_CTX.

* The module caches pre-generated EVP_MD_CTX objects for commonly used hashes like sha256. Tests with timeit has shown that generating a EVP_MD_CTX from a EVP constructor is as fast as copying and reinitializing a EVP_MD_CTX.

* The pre-calculated constructs can be replaced with argument clinic to make the code more readable.
msg352100 - (view) Author: Charalampos Stratakis (cstratak) * Date: 2019-09-12 10:49
Yes that would be awesome!

Indeed hashlib has been a bit of a pain to work with especially with FIPS related modifications, simplifying it would help a ton.
msg352146 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2019-09-12 12:42
New changeset 5a4f82f457049b5b07b6fba4ca42bc1ecf597976 by Stéphane Wirtel (Christian Heimes) in branch 'master':
bpo-38132: Simplify _hashopenssl code (GH-16023)
https://github.com/python/cpython/commit/5a4f82f457049b5b07b6fba4ca42bc1ecf597976
msg352151 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2019-09-12 13:03
New changeset 67b90a079c39066aa9d51690fe5678c36ccbc258 by Stéphane Wirtel (Miss Islington (bot)) in branch '3.8':
bpo-38132: Simplify _hashopenssl code (GH-16023) (#16040)
https://github.com/python/cpython/commit/67b90a079c39066aa9d51690fe5678c36ccbc258
msg352160 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2019-09-12 13:30
New changeset 8c74574e0aaf1a00719fbc9acbdc27a3923520aa by Stéphane Wirtel (Christian Heimes) in branch 'master':
bpo-38132: Check EVP_DigestUpdate for error (GH-16041)
https://github.com/python/cpython/commit/8c74574e0aaf1a00719fbc9acbdc27a3923520aa
msg352164 - (view) Author: miss-islington (miss-islington) Date: 2019-09-12 13:50
New changeset 0d7cb5bb291d8645824581ae570a394e3d221e5e by Miss Islington (bot) in branch '3.8':
bpo-38132: Check EVP_DigestUpdate for error (GH-16041)
https://github.com/python/cpython/commit/0d7cb5bb291d8645824581ae570a394e3d221e5e
History
Date User Action Args
2022-04-11 14:59:20adminsetgithub: 82313
2019-09-12 13:50:49miss-islingtonsetnosy: + miss-islington
messages: + msg352164
2019-09-12 13:31:00miss-islingtonsetpull_requests: + pull_request15670
2019-09-12 13:30:51matrixisesetmessages: + msg352160
2019-09-12 13:03:53matrixisesetmessages: + msg352151
2019-09-12 12:45:24christian.heimessetpull_requests: + pull_request15663
2019-09-12 12:42:19miss-islingtonsetpull_requests: + pull_request15662
2019-09-12 12:42:10matrixisesetnosy: + matrixise
messages: + msg352146
2019-09-12 10:52:58christian.heimessetkeywords: + patch
stage: patch review
pull_requests: + pull_request15646
2019-09-12 10:49:45cstrataksetnosy: + cstratak
messages: + msg352100
2019-09-12 10:44:02christian.heimescreate