1 |
Offer mhash as a provider for Manifest2 hash generation and validation. |
2 |
This is important as none of pycrypto/hashlib/fchksum offer an |
3 |
accelerated Whirlpool implementaiton. Additionally, the mhash |
4 |
implementation is accelerated and ships with a rigorious testsuite. |
5 |
|
6 |
Signed-off-by: Robin H. Johnson <robbat2@g.o> |
7 |
--- |
8 |
pym/portage/checksum.py | 19 +++++++++++++++++-- |
9 |
1 files changed, 17 insertions(+), 2 deletions(-) |
10 |
|
11 |
diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py |
12 |
index b2c9333..c3df36b 100644 |
13 |
--- a/pym/portage/checksum.py |
14 |
+++ b/pym/portage/checksum.py |
15 |
@@ -16,7 +16,7 @@ import tempfile |
16 |
hashfunc_map = {} |
17 |
hashorigin_map = {} |
18 |
|
19 |
-def _generate_hash_function(hashtype, hashobject, origin="unknown"): |
20 |
+def _generate_hash_function(hashtype, hashobject, origin="unknown", hashobjectargs=None): |
21 |
def pyhash(filename): |
22 |
""" |
23 |
Run a checksum against a file. |
24 |
@@ -41,7 +41,11 @@ def _generate_hash_function(hashtype, hashobject, origin="unknown"): |
25 |
blocksize = HASHING_BLOCKSIZE |
26 |
data = f.read(blocksize) |
27 |
size = 0 |
28 |
- checksum = hashobject() |
29 |
+ if hashobjectargs is None: |
30 |
+ checksum = hashobject() |
31 |
+ else: |
32 |
+ checksum = hashobject(hashobjectargs) |
33 |
+ |
34 |
while data: |
35 |
checksum.update(data) |
36 |
size = size + len(data) |
37 |
@@ -103,6 +107,17 @@ try: |
38 |
except ImportError as e: |
39 |
pass |
40 |
|
41 |
+# Try to use mhash if available |
42 |
+try: |
43 |
+ import mhash |
44 |
+ md5hash = _generate_hash_function("MD5", mhash.MHASH, origin="mhash", hashobjectargs=mhash.MHASH_MD5) |
45 |
+ sha1hash = _generate_hash_function("SHA1", mhash.MHASH, origin="mhash", hashobjectargs=mhash.MHASH_SHA1) |
46 |
+ sha256hash = _generate_hash_function("SHA256", mhash.MHASH, origin="mhash", hashobjectargs=mhash.MHASH_SHA256) |
47 |
+ sha512hash = _generate_hash_function("SHA512", mhash.MHASH, origin="mhash", hashobjectargs=mhash.MHASH_SHA512) |
48 |
+ rmd160hash = _generate_hash_function("RMD160", mhash.MHASH, origin="mhash", hashobjectargs=mhash.MHASH_RIPEMD160) |
49 |
+ whirlpoolhash = _generate_hash_function("WHIRLPOOL", mhash.MHASH, origin="mhash", hashobjectargs=mhash.MHASH_WHIRLPOOL) |
50 |
+except ImportError as e: |
51 |
+ pass |
52 |
|
53 |
# Use python-fchksum if available, prefer it over all other MD5 implementations |
54 |
try: |
55 |
-- |
56 |
1.7.6 |