[proxy] web.archive.org← back | site home | direct (HTTPS) ↗ | proxy home | ◑ dark◐ light

/ cpython Public

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

bpo-40645: Implement HMAC in C (GH-20129) #20129

Merged
merged 1 commit into from May 17, 2020
Merged

Conversation

Copy link
Member

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 force-pushed the openssl-hmac branch 4 times, most recently from 6bbb177 to 3e2345b May 17, 2020
tiran requested review from vstinner, encukou and gpshead May 17, 2020
tiran marked this pull request as ready for review May 17, 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.
news.gmane.io
Co-Authored-By: Petr Viktorin <encukou@gmail.com>
Signed-off-by: Christian Heimes <christian@python.org>
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 changed the title bpo-40645: Implement HMAC in C bpo-40645: Implement HMAC in C (GH-20129) May 17, 2020
tiran merged commit 54f2898 into python:master May 17, 2020
10 checks passed
tiran deleted the openssl-hmac branch May 17, 2020
arturoescaip added a commit to arturoescaip/cpython that referenced this issue 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>
vegerot added a commit to vegerot/cpython that referenced this issue Jun 10, 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>
vegerot added a commit to vegerot/cpython that referenced this issue Jun 10, 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>
gmelikov added a commit to gmelikov/cpython that referenced this issue Aug 22, 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>
chrisburr added a commit to chrisburr/cpython that referenced this issue Dec 9, 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);

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

gpshead May 16, 2021

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
Projects
None yet
5 participants