Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(32545)

Delta Between Two Patch Sets: Lib/hashlib.py

Issue 26798: add BLAKE2 to hashlib
Left Patch Set: Created 3 years, 5 months ago
Right Patch Set: Created 3 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Doc/library/hashlib.rst ('k') | Lib/test/test_hashlib.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #. Copyright (C) 2005-2010 Gregory P. Smith (greg@krypto.org) 1 #. Copyright (C) 2005-2010 Gregory P. Smith (greg@krypto.org)
2 # Licensed to PSF under a Contributor Agreement. 2 # Licensed to PSF under a Contributor Agreement.
3 # 3 #
4 4
5 __doc__ = """hashlib module - A common interface to many hash functions. 5 __doc__ = """hashlib module - A common interface to many hash functions.
6 6
7 new(name, data=b'', **kwargs) - returns a new hash object implementing the 7 new(name, data=b'', **kwargs) - returns a new hash object implementing the
8 given hash function; initializing the hash 8 given hash function; initializing the hash
9 using the given binary data. 9 using the given binary data.
10 10
11 Named constructor functions are also available, these are faster 11 Named constructor functions are also available, these are faster
12 than using new(name): 12 than using new(name):
13 13
14 md5(), sha1(), sha224(), sha256(), sha384(), and sha512() 14 md5(), sha1(), sha224(), sha256(), sha384(), sha512(), blake2b(), and blake2s()
15
16 On platforms with support for 64bit integer types (some 32bit platforms,
17 all 64bit platforms), blake2b and blake2s are supported.
18 15
19 More algorithms may be available on your platform but the above are guaranteed 16 More algorithms may be available on your platform but the above are guaranteed
20 to exist. See the algorithms_guaranteed and algorithms_available attributes 17 to exist. See the algorithms_guaranteed and algorithms_available attributes
21 to find out what algorithm names can be passed to new(). 18 to find out what algorithm names can be passed to new().
22 19
23 NOTE: If you want the adler32 or crc32 hash functions they are available in 20 NOTE: If you want the adler32 or crc32 hash functions they are available in
24 the zlib module. 21 the zlib module.
25 22
26 Choose your hash function wisely. Some have known collision weaknesses. 23 Choose your hash function wisely. Some have known collision weaknesses.
27 sha384 and sha512 will be slow on 32 bit platforms. 24 sha384 and sha512 will be slow on 32 bit platforms.
(...skipping 22 matching lines...) Expand all
50 47
51 More condensed: 48 More condensed:
52 49
53 >>> hashlib.sha224(b"Nobody inspects the spammish repetition").hexdigest() 50 >>> hashlib.sha224(b"Nobody inspects the spammish repetition").hexdigest()
54 'a4337bc45a8fc544c03f52dc550cd6e1e87021bc896588bd79e901e2' 51 'a4337bc45a8fc544c03f52dc550cd6e1e87021bc896588bd79e901e2'
55 52
56 """ 53 """
57 54
58 # This tuple and __get_builtin_constructor() must be modified if a new 55 # This tuple and __get_builtin_constructor() must be modified if a new
59 # always available algorithm is added. 56 # always available algorithm is added.
60 __always_supported = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512') 57 __always_supported = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512',
58 'blake2b', 'blake2s')
61 59
62 algorithms_guaranteed = set(__always_supported) 60 algorithms_guaranteed = set(__always_supported)
63 algorithms_available = set(__always_supported) 61 algorithms_available = set(__always_supported)
64 62
65 __all__ = __always_supported + ('new', 'algorithms_guaranteed', 63 __all__ = __always_supported + ('new', 'algorithms_guaranteed',
66 'algorithms_available', 'pbkdf2_hmac') 64 'algorithms_available', 'pbkdf2_hmac')
67
68 # Supported on most platforms
69 __often_supported = ('blake2b', 'blake2s')
70 65
71 66
72 __builtin_constructor_cache = {} 67 __builtin_constructor_cache = {}
73 68
74 def __get_builtin_constructor(name): 69 def __get_builtin_constructor(name):
75 cache = __builtin_constructor_cache 70 cache = __builtin_constructor_cache
76 constructor = cache.get(name) 71 constructor = cache.get(name)
77 if constructor is not None: 72 if constructor is not None:
78 return constructor 73 return constructor
79 try: 74 try:
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 216
222 for __func_name in __always_supported: 217 for __func_name in __always_supported:
223 # try them all, some may not work due to the OpenSSL 218 # try them all, some may not work due to the OpenSSL
224 # version not supporting that algorithm. 219 # version not supporting that algorithm.
225 try: 220 try:
226 globals()[__func_name] = __get_hash(__func_name) 221 globals()[__func_name] = __get_hash(__func_name)
227 except ValueError: 222 except ValueError:
228 import logging 223 import logging
229 logging.exception('code for hash %s was not found.', __func_name) 224 logging.exception('code for hash %s was not found.', __func_name)
230 225
231 for __func_name in __often_supported:
232 try:
233 globals()[__func_name] = __get_hash(__func_name)
234 except ValueError:
235 pass
236 else:
237 algorithms_available.add(__func_name)
238
239 226
240 # Cleanup locals() 227 # Cleanup locals()
241 del __always_supported, __often_supported, __func_name, __get_hash 228 del __always_supported, __func_name, __get_hash
242 del __py_new, __hash_new, __get_openssl_constructor 229 del __py_new, __hash_new, __get_openssl_constructor
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+