mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
bpo-37630: Use SHA3 and SHAKE XOF from OpenSSL (GH-16049)
OpenSSL 1.1.1 comes with SHA3 and SHAKE builtin. Signed-off-by: Christian Heimes <christian@python.org> Automerge-Triggered-By: @tiran
This commit is contained in:
parent
b17e49e0de
commit
d5b3f6b7f9
6 changed files with 845 additions and 21 deletions
|
@ -27,9 +27,10 @@ c_hashlib = import_fresh_module('hashlib', fresh=['_hashlib'])
|
|||
py_hashlib = import_fresh_module('hashlib', blocked=['_hashlib'])
|
||||
|
||||
try:
|
||||
from _hashlib import HASH
|
||||
from _hashlib import HASH, HASHXOF
|
||||
except ImportError:
|
||||
HASH = None
|
||||
HASHXOF = None
|
||||
|
||||
try:
|
||||
import _blake2
|
||||
|
@ -254,6 +255,9 @@ class HashLibTestCase(unittest.TestCase):
|
|||
h = cons()
|
||||
if h.name not in self.shakes:
|
||||
continue
|
||||
if HASH is not None and isinstance(h, HASH):
|
||||
# _hashopenssl's take a size_t
|
||||
continue
|
||||
for digest in h.digest, h.hexdigest:
|
||||
self.assertRaises(ValueError, digest, -10)
|
||||
for length in large_sizes:
|
||||
|
@ -860,6 +864,18 @@ class HashLibTestCase(unittest.TestCase):
|
|||
def test_get_fips_mode(self):
|
||||
self.assertIsInstance(c_hashlib.get_fips_mode(), int)
|
||||
|
||||
@unittest.skipUnless(HASH is not None, 'need _hashlib')
|
||||
def test_internal_types(self):
|
||||
# internal types like _hashlib.HASH are not constructable
|
||||
with self.assertRaisesRegex(
|
||||
TypeError, "cannot create 'HASH' instance"
|
||||
):
|
||||
HASH()
|
||||
with self.assertRaisesRegex(
|
||||
TypeError, "cannot create 'HASHXOF' instance"
|
||||
):
|
||||
HASHXOF()
|
||||
|
||||
|
||||
class KDFTests(unittest.TestCase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue