[issue38132] Simplify hashlib implementation

Christian Heimes report at bugs.python.org
Thu Sep 12 06:44:02 EDT 2019


New submission from Christian Heimes <lists at cheimes.de>:

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.

----------
assignee: christian.heimes
components: Extension Modules
messages: 352099
nosy: christian.heimes, gregory.p.smith
priority: normal
severity: normal
status: open
title: Simplify hashlib implementation
type: enhancement
versions: Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38132>
_______________________________________


More information about the Python-bugs-list mailing list