Skip to content

Commit 2f21eb3

Browse files
committed
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
when the OpenSSL library is either not present or not found by setup.py. These are derived from the public domain libtomcrypt (libtom.org) just like the existing sha256 and sha512 modules.
1 parent b3b4dbe commit 2f21eb3

File tree

6 files changed

+1118
-16
lines changed

6 files changed

+1118
-16
lines changed

Lib/hashlib.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
given hash function; initializing the hash
1111
using the given binary data.
1212
13-
Named constructor functions are also available, these are much faster
14-
than using new():
13+
Named constructor functions are also available, these are faster
14+
than using new(name):
1515
1616
md5(), sha1(), sha224(), sha256(), sha384(), and sha512()
1717
@@ -22,14 +22,13 @@
2222
sha384 and sha512 will be slow on 32 bit platforms.
2323
2424
Hash objects have these methods:
25-
- update(arg): Update the hash object with the string arg. Repeated calls
25+
- update(arg): Update the hash object with the bytes in arg. Repeated calls
2626
are equivalent to a single call with the concatenation of all
2727
the arguments.
28-
- digest(): Return the digest of the strings passed to the update() method
29-
so far. This may contain non-ASCII characters, including
30-
NUL bytes.
31-
- hexdigest(): Like digest() except the digest is returned as a string of
32-
double length, containing only hexadecimal digits.
28+
- digest(): Return the digest of the bytes passed to the update() method
29+
so far.
30+
- hexdigest(): Like digest() except the digest is returned as a unicode
31+
object of double length, containing only hexadecimal digits.
3332
- copy(): Return a copy (clone) of the hash object. This can be used to
3433
efficiently compute the digests of strings that share a common
3534
initial substring.
@@ -54,11 +53,11 @@
5453

5554
def __get_builtin_constructor(name):
5655
if name in ('SHA1', 'sha1'):
57-
import _sha
58-
return _sha.new
56+
import _sha1
57+
return _sha1.sha1
5958
elif name in ('MD5', 'md5'):
6059
import _md5
61-
return _md5.new
60+
return _md5.md5
6261
elif name in ('SHA256', 'sha256', 'SHA224', 'sha224'):
6362
import _sha256
6463
bs = name[3:]
@@ -78,7 +77,7 @@ def __get_builtin_constructor(name):
7877

7978

8079
def __py_new(name, data=b''):
81-
"""new(name, data='') - Return a new hashing object using the named algorithm;
80+
"""new(name, data=b'') - Return a new hashing object using the named algorithm;
8281
optionally initialized with data (which must be bytes).
8382
"""
8483
return __get_builtin_constructor(name)(data)

0 commit comments

Comments
 (0)