-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Use OpenSSL's HMAC API #84825
Comments
Python's hmac module provides a pure Python based implementation on top of the hashlib module. OpenSSL offers a dedicated HMAC implementation that has a couple of benefits over pure Python implementation:
For 3.9 I plan to deprecate hmac.HMAC.digest_con, hmac.HMAC.inner, and hmac.HMAC.outer attributes. They are implementation specific details any way. I'm also going to provide a _hashlib.hmac_new() function so we can test the new code. For 3.10 I'll be switching over to _haslib.hmac_new() when the digestmod is a string or a callable that returns _hashlib.HASH code. |
def new(key, msg=None, digestmod=''):
# use fast HMAC if OpenSSL bindings are available and digestmod is
# either a string or a callable that returns an OpenSSL HASH object.
if _hashopenssl is not None:
if isinstance(digestmod, str):
return _hashopenssl.hmac_new(key, msg, digestmod)
if callable(digestmod):
digest = digestmod(b'')
if isinstance(digest, _hashopenssl.HASH):
return _hashopenssl.hmac_new(key, msg, digest.name)
return HMAC(key, msg, digestmod) |
Compiler warning on 64-bit Windows: c:\vstinner\python\3.9\modules\_hashopenssl.c(1427): warning C4244: 'function': conversion from 'Py_ssize_t' to 'int', possible loss of data |
Thanks, Victor! |
memo to me: switch to new C implementation of HMAC. |
Seems that commit 933dfd7 introduced some reference leaks: commit 933dfd7
𓋹 ./python.exe -m test test_hashlib -R 3:3 == Tests result: FAILURE == 1 test failed: Total duration: 8.7 sec
Lib/hashlib.py | 1 + |
See for instance: https://buildbot.python.org/all/#/builders/75/builds/224 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: