diff options
author | Christian Heimes <christian@cheimes.de> | 2012-10-06 02:23:36 +0200 |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2012-10-06 02:23:36 +0200 |
commit | 4a0270d82bfd782c89a8ae2b869102dafb81ffea (patch) | |
tree | 5bd4262a7a42e94493aa4a0fdf7cdd32185f3a44 /Lib/hashlib.py | |
parent | In debug mode, unicode_write_cstr() now checks that non-ASCII characters are (diff) | |
download | cpython-4a0270d82bfd782c89a8ae2b869102dafb81ffea.tar.gz cpython-4a0270d82bfd782c89a8ae2b869102dafb81ffea.tar.bz2 cpython-4a0270d82bfd782c89a8ae2b869102dafb81ffea.zip |
Issue #16113: integrade SHA-3 (Keccak) patch from http://hg.python.org/sandbox/cheimes
Diffstat (limited to 'Lib/hashlib.py')
-rw-r--r-- | Lib/hashlib.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/Lib/hashlib.py b/Lib/hashlib.py index 21454c7d306..a1bd8b2de8c 100644 --- a/Lib/hashlib.py +++ b/Lib/hashlib.py @@ -54,7 +54,8 @@ More condensed: # This tuple and __get_builtin_constructor() must be modified if a new # always available algorithm is added. -__always_supported = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512') +__always_supported = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512', + 'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512') algorithms_guaranteed = set(__always_supported) algorithms_available = set(__always_supported) @@ -85,6 +86,18 @@ def __get_builtin_constructor(name): return _sha512.sha512 elif bs == '384': return _sha512.sha384 + elif name in {'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512', + 'SHA3_224', 'SHA3_256', 'SHA3_384', 'SHA3_512'}: + import _sha3 + bs = name[5:] + if bs == '224': + return _sha3.sha3_224 + elif bs == '256': + return _sha3.sha3_256 + elif bs == '384': + return _sha3.sha3_384 + elif bs == '512': + return _sha3.sha3_512 except ImportError: pass # no extension module, this hash is unsupported. |