-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
gh-136968: fortify macro usage in cryptographic modules #136973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
gh-136968: fortify macro usage in cryptographic modules #136973
Conversation
ad5b0d0
to
aa41a74
Compare
🤖 New build scheduled with the buildbot fleet by @picnixz for commit aa41a74 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F136973%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-refleak-buildbots label again. |
8884b4a
to
aa41a74
Compare
Modules/hmacmodule.c
Outdated
(const char *)out, \ | ||
Py_hmac_## HACL_HID ##_digest_size \ | ||
); \ | ||
#define Py_HMAC_HACL_ONESHOT(HACL_HID, KEY, MSG) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could have rewritten this macro as well, but I don't really want to trade safety for speed here. By using a function I would need:
- Over-allocate the digest buffer or still use a macro to pre-allocate the buffer with its exact size or pass it to that function. None of them is satisfying to me because of it would make the function non-reusable due to its signature or the fact that it expects the buffer to be pre-allocated.
- Use pointer to functions for the dedicated computation functions. This is not optimal. Alternatively, I could use a dispatch mechanism to recover both the function and the digest size dynamically but it's again an overkill when I can directly access them.
At least, the part that made me suffer has been turned into a regular function (namely hmac_get_buffer_views
) so I'm happy for now.
_hashlibstate *state = get_hashlib_state(MODULE); \ | ||
return _hashlib_HASH(state, NAME, data_obj, USEDFORSECURITY); \ | ||
} while (0) | ||
return _hashlib_HASH_new_impl(MODULE, NAME, DATA, USEDFORSECURITY, STRING) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Python 3.19, we will be able to remove the "STRING" argument. In once it's done, we will also be able to remove the macro as the call to _hashlib_HASH_new_impl()
will fit on 80 characters for all hash functions.
Also, when I introduced that macro I should have kept the same parameter order. At runtime, the parameters passed to openssl_*
functions are forwarded to _hashlib_HASH_new_impl
in the same order so the compiler doesn't need to re-optimize stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you might want to leave this as a comment in the code.
Uh oh!
There was an error while loading. Please reload this page.