summaryrefslogtreecommitdiffstats
path: root/Lib/hashlib.py
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2012-10-06 00:23:36 (GMT)
committerChristian Heimes <christian@cheimes.de>2012-10-06 00:23:36 (GMT)
commit4a0270d82bfd782c89a8ae2b869102dafb81ffea (patch)
tree5bd4262a7a42e94493aa4a0fdf7cdd32185f3a44 /Lib/hashlib.py
parent8c6db45d3e8a20cabe50f93b2bbc33b0040af5a3 (diff)
downloadcpython-4a0270d82bfd782c89a8ae2b869102dafb81ffea.zip
cpython-4a0270d82bfd782c89a8ae2b869102dafb81ffea.tar.gz
cpython-4a0270d82bfd782c89a8ae2b869102dafb81ffea.tar.bz2
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.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/Lib/hashlib.py b/Lib/hashlib.py
index 21454c7..a1bd8b2 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.