-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
bpo-40645: Implement HMAC in C (GH-20129) #20129
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
Conversation
6bbb177 to
3e2345b
Compare
The internal module ``_hashlib`` wraps and exposes OpenSSL's HMAC API. The new code will be used in Python 3.10 after the internal implementation details of the pure Python HMAC module are no longer part of the public API. The code is based on a patch by Petr Viktorin for RHEL and Python 3.6. news.gmane.io Co-Authored-By: Petr Viktorin <encukou@gmail.com> Signed-off-by: Christian Heimes <christian@python.org>
|
@gpshead I'm merging the PR without your ACK to get it into Python 3.9 before beta freeze. In case you don't like it I can remove it from 3.9 and postpone the new feature to 3.10. |
The internal module ``_hashlib`` wraps and exposes OpenSSL's HMAC API. The new code will be used in Python 3.10 after the internal implementation details of the pure Python HMAC module are no longer part of the public API. The code is based on a patch by Petr Viktorin for RHEL and Python 3.6. Co-Authored-By: Petr Viktorin <encukou@gmail.com>
| if (self->lock != NULL) { | ||
| ENTER_HASHLIB(self); | ||
| r = HMAC_Update(self->ctx, (const unsigned char*)view.buf, view.len); | ||
| LEAVE_HASHLIB(self); |
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.
Looking at the definition of ENTER_HASHLIB, I believe that the GIL is released only while acquiring the HMACobject lock, and not during the actual HMAC_Update.
It seems the intention was to release it for HMAC_Update as well, which is what EVP_update does. If that's the case, then I think this should use the same approach as EVP_update. Something like
Py_BEGIN_ALLOW_THREADS
PyThread_acquire_lock(self->lock, 1);
r = HMAC_Update(self->ctx, (const unsigned char*)view.buf, view.len);
PyThread_release_lock(self->lock);
Py_END_ALLOW_THREADSThere 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.
Good catch. True. https://bugs.python.org/issue44145 filed to track and fix.
The internal module
_hashlibwraps and exposes OpenSSL's HMAC API. Thenew code will be used in Python 3.10 after the internal implementation
details of the pure Python HMAC module are no longer part of the public API.
The code is based on a patch by Petr Viktorin for RHEL and Python 3.6.
https://bugs.python.org/issue40645