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
I recently rewrote the _blake2 module. I want to the same for other modules where I can align the naming of functions across the different modules. The reason why I'm doing this is because it's becoming harder to make "similar" changes everywhere. In general, if I need to change something in MD5, then I also need to change it in SHA1/SHA2/SHA3, and it's easier if the code looks similar elsewhere.
There are some places that need to be updated because they are dead code, e.g.:
I've rewritten SHA-2 and SHA-3 modules with generic macros but I'm torn between the now cleaner modules and the fact that I entirely rewrote them. SHA-2 is smaller but SHA-3 is larger.
Offline I found other stuff that need to be updated independently:
SHA-3 types in Argument Clinic code.
MD-5 digests computations don't use _Py_strhex.
Useless memory allocation for 0-length SHAKE hashes (we can switch conditions checks)
Usage of unsigned char where we could use uint8_t: HACL* code expects an uint8_t so we can consistently use it.
Inconsistentcies in naming classes: we have _sha2.SHA256Type vs _sha3.sha3_224. Note SHA-2 doesn't expose a __new__ method but SHA-3 does. MD-5/SHA-1/SHA-1 don't have a tp_new slot but SHA-3 and BLAKE-2 do. I don't know which one is the best, but I don't think we should have both.
I think I've done enough cleanup. The PR that is currently a draft for the module's state is stale and I won't merge it because it's not that important IMO. Other modules also suffer from similar constructions, so the best plan is to add some internal helpers for correctly fetching the module's def/state from a final heap type.
Activity
picnixz commentedon Jun 19, 2025
I've rewritten SHA-2 and SHA-3 modules with generic macros but I'm torn between the now cleaner modules and the fact that I entirely rewrote them. SHA-2 is smaller but SHA-3 is larger.
picnixz commentedon Jun 19, 2025
Offline I found other stuff that need to be updated independently:
_Py_strhex.unsigned charwhere we could useuint8_t: HACL* code expects anuint8_tso we can consistently use it._sha2.SHA256Typevs_sha3.sha3_224. Note SHA-2 doesn't expose a__new__method but SHA-3 does. MD-5/SHA-1/SHA-1 don't have atp_newslot but SHA-3 and BLAKE-2 do. I don't know which one is the best, but I don't think we should have both.gh-135532: simplify handling of HACL* errors in `_hmac` (#135740)
pythongh-135532: simplify handling of HACL* errors in `_hmac` (python…
[3.14] gh-135532: simplify handling of HACL* errors in `_hmac` (GH-13…
gh-135532: update `Modules/_hacl/python_hacl_namespaces.h` (#135741)
pythongh-135532: update `Modules/_hacl/python_hacl_namespaces.h` (pyt…
gh-135532: use `_Py_strhex` in HACL-MD5's `hexdigest` (#135742)
[3.14] gh-135532: update `Modules/_hacl/python_hacl_namespaces.h` (GH…
gh-135532: optimize calls to `PyMem_Malloc` in SHAKE digest computati…
gh-135532: cleanup clinic `module` directives for cryptographic modul…
gh-135532: use `defining_class` for copying BLAKE-2 and SHA-3 objects (…
7 remaining items
pythongh-135532: use `defining_class` for copying BLAKE-2 and SHA-3 o…
picnixz commentedon Jul 13, 2025
I think I've done enough cleanup. The PR that is currently a draft for the module's state is stale and I won't merge it because it's not that important IMO. Other modules also suffer from similar constructions, so the best plan is to add some internal helpers for correctly fetching the module's def/state from a final heap type.
pythongh-135532: simplify handling of HACL* errors in `_hmac` (python…
pythongh-135532: update `Modules/_hacl/python_hacl_namespaces.h` (pyt…
pythongh-135532: use `_Py_strhex` in HACL-MD5's `hexdigest` (python#1…
pythongh-135532: optimize calls to `PyMem_Malloc` in SHAKE digest com…
pythongh-135532: cleanup clinic `module` directives for cryptographic…
pythongh-135532: use `defining_class` for copying BLAKE-2 and SHA-3 o…
pythongh-135532: simplify handling of HACL* errors in `_hmac` (python…
pythongh-135532: update `Modules/_hacl/python_hacl_namespaces.h` (pyt…
pythongh-135532: use `_Py_strhex` in HACL-MD5's `hexdigest` (python#1…
pythongh-135532: optimize calls to `PyMem_Malloc` in SHAKE digest com…
pythongh-135532: cleanup clinic `module` directives for cryptographic…
pythongh-135532: use `defining_class` for copying BLAKE-2 and SHA-3 o…