Skip to content

Conversation

@tiran
Copy link
Member

@tiran tiran commented May 16, 2020

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.

https://bugs.python.org/issue40645

@tiran tiran force-pushed the openssl-hmac branch 4 times, most recently from 6bbb177 to 3e2345b Compare May 17, 2020 09:48
@tiran tiran requested review from encukou, gpshead and vstinner May 17, 2020 09:49
@tiran tiran marked this pull request as ready for review May 17, 2020 09:49
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>
@tiran
Copy link
Member Author

tiran commented May 17, 2020

@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.

@tiran tiran changed the title bpo-40645: Implement HMAC in C bpo-40645: Implement HMAC in C (GH-20129) May 17, 2020
@tiran tiran merged commit 54f2898 into python:master May 17, 2020
@tiran tiran deleted the openssl-hmac branch May 17, 2020 11:49
arturoescaip pushed a commit to arturoescaip/cpython that referenced this pull request May 24, 2020
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);
Copy link
Contributor

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_THREADS
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

5 participants