You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Activity
tiran commentedon Sep 12, 2019
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.
stratakis commentedon Sep 12, 2019
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.
matrixise commentedon Sep 12, 2019
New changeset 5a4f82f by Stéphane Wirtel (Christian Heimes) in branch 'master':
bpo-38132: Simplify _hashopenssl code (GH-16023)
5a4f82f
matrixise commentedon Sep 12, 2019
New changeset 67b90a0 by Stéphane Wirtel (Miss Islington (bot)) in branch '3.8':
bpo-38132: Simplify _hashopenssl code (GH-16023) (bpo-16040)
67b90a0
matrixise commentedon Sep 12, 2019
New changeset 8c74574 by Stéphane Wirtel (Christian Heimes) in branch 'master':
bpo-38132: Check EVP_DigestUpdate for error (GH-16041)
8c74574
miss-islington commentedon Sep 12, 2019
New changeset 0d7cb5b by Miss Islington (bot) in branch '3.8':
bpo-38132: Check EVP_DigestUpdate for error (GH-16041)
0d7cb5b
erlend-aasland commentedon Jan 4, 2024
AFAICS, all three suggested items was implemented by gh-16023:
EVPobjectname is now fetched from theEVP_MD_CTXon demandClosing as completed.