summaryrefslogtreecommitdiff
path: root/Lib/hmac.py
diff options
context:
space:
mode:
authorChristian Heimes <christian@python.org>2020-05-28 14:09:38 +0200
committerGitHub <noreply@github.com>2020-05-28 05:09:38 -0700
commit8183e11d87388e4e44e3242c42085b87a878f781 (patch)
tree0b0302ad36f4a4b67a64eb68dc5b280ce84f90f7 /Lib/hmac.py
parentd23ee5d652ba69a32504dac43131be782b6afdc7 (diff)
downloadcpython-git-8183e11d87388e4e44e3242c42085b87a878f781.tar.gz
[3.9] bpo-40791: Use CRYPTO_memcmp() for compare_digest (GH-20456) (GH-20461)
hashlib.compare_digest uses OpenSSL's CRYPTO_memcmp() function when OpenSSL is available. Note: The _operator module is a builtin module. I don't want to add libcrypto dependency to libpython. Therefore I duplicated the wrapper function and added a copy to _hashopenssl.c.. (cherry picked from commit db5aed931f8a617f7b63e773f62db468fe9c5ca1) Co-authored-by: Christian Heimes <christian@python.org>
Diffstat (limited to 'Lib/hmac.py')
-rw-r--r--Lib/hmac.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/Lib/hmac.py b/Lib/hmac.py
index 54a1ef9bdb..180bc378b5 100644
--- a/Lib/hmac.py
+++ b/Lib/hmac.py
@@ -4,14 +4,15 @@ Implements the HMAC algorithm as described by RFC 2104.
"""
import warnings as _warnings
-from _operator import _compare_digest as compare_digest
try:
import _hashlib as _hashopenssl
except ImportError:
_hashopenssl = None
_openssl_md_meths = None
+ from _operator import _compare_digest as compare_digest
else:
_openssl_md_meths = frozenset(_hashopenssl.openssl_md_meth_names)
+ compare_digest = _hashopenssl.compare_digest
import hashlib as _hashlib
trans_5C = bytes((x ^ 0x5C) for x in range(256))