-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
Closed
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtype-refactorCode refactoring (with no changes in behavior)Code refactoring (with no changes in behavior)
Description
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.:
/*[clinic input]
module _sha2
class SHA256Type "SHA256object *" "&PyType_Type"
class SHA512Type "SHA512object *" "&PyType_Type"
[clinic start generated code]*/
should be
/*[clinic input]
module _sha2
class SHA256Type "SHA256object *" "clinic_state()->sha256_type"
class SHA512Type "SHA512object *" "clinic_state()->sha512_type"
[clinic start generated code]*/
Linked PRs
- gh-135532: use
_Py_strhex
in_md5.md5.hexdigest
#135742 - gh-135532: optimize calls to
PyMem_Malloc
in SHAKE digest computation #135744 - gh-135532: cleanup clinic
module
directives for cryptographic modules #135822 - gh-135532: use
defining_class
for copying BLAKE-2 and SHA-3 objects #135838 - gh-135532: fortify DEBUG checks when fetching HACL*-based module state #135844
Bug fixes (3.14+)
- gh-135532: update
python_hacl_namespaces.h
#135741 - [3.14] gh-135532: update
Modules/_hacl/python_hacl_namespaces.h
(GH-135741) #135745
Backported PRs (HMAC-only)
- gh-135532: simplify handling of HACL* errors in
_hmac
#135740 - [3.14] gh-135532: simplify handling of HACL* errors in
_hmac
(GH-135740) #135743
Abandoned
Metadata
Metadata
Assignees
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtype-refactorCode refactoring (with no changes in behavior)Code refactoring (with no changes in behavior)
Projects
Milestone
Relationships
Development
Select code repository
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 char
where we could useuint8_t
: HACL* code expects anuint8_t
so we can consistently use it._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 atp_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._hmac
#135740python_hacl_namespaces.h
#135741_Py_strhex
in_md5.md5.hexdigest
#135742gh-135532: simplify handling of HACL* errors in `_hmac` (#135740)
pythongh-135532: simplify handling of HACL* errors in `_hmac` (python…
_hmac
(GH-135740) #135743[3.14] gh-135532: simplify handling of HACL* errors in `_hmac` (GH-13…
PyMem_Malloc
in SHAKE digest computation #135744gh-135532: update `Modules/_hacl/python_hacl_namespaces.h` (#135741)
21 remaining items