1 |
commit: faf87ba9877e3b5a7866c6649f956f15950e789a |
2 |
Author: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Oct 1 07:40:54 2011 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Oct 2 05:55:02 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=faf87ba9 |
7 |
|
8 |
Manifest2 hash backend provider: mhash |
9 |
|
10 |
Offer mhash as a provider for Manifest2 hash generation and validation. |
11 |
This is important as either of pycrypto or fchksum offer an accelerated |
12 |
Whirlpool implementation, and hashlib might not offer it. Additionally, |
13 |
the mhash implementation is accelerated and ships with a rigorious |
14 |
testsuite. |
15 |
|
16 |
Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org> |
17 |
|
18 |
--- |
19 |
pym/portage/checksum.py | 19 +++++++++++++++++++ |
20 |
1 files changed, 19 insertions(+), 0 deletions(-) |
21 |
|
22 |
diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py |
23 |
index 6bace4d..a4a744b 100644 |
24 |
--- a/pym/portage/checksum.py |
25 |
+++ b/pym/portage/checksum.py |
26 |
@@ -80,6 +80,25 @@ sha1hash = _generate_hash_function("SHA1", _new_sha1, origin="internal") |
27 |
from portage.util.whirlpool import new as _new_whirlpool |
28 |
whirlpoolhash = _generate_hash_function("WHIRLPOOL", _new_whirlpool, origin="bundled") |
29 |
|
30 |
+# Try to use mhash if available |
31 |
+# mhash causes GIL presently, so it gets less priority than hashlib and |
32 |
+# pycrypto. However, it might be the only accelerated implementation of |
33 |
+# WHIRLPOOL available. |
34 |
+try: |
35 |
+ import mhash, functools |
36 |
+ md5hash = _generate_hash_function("MD5", functools.partial(mhash.MHASH, mhash.MHASH_MD5), origin="mhash") |
37 |
+ sha1hash = _generate_hash_function("SHA1", functools.partial(mhash.MHASH, mhash.MHASH_SHA1), origin="mhash") |
38 |
+ sha256hash = _generate_hash_function("SHA256", functools.partial(mhash.MHASH, mhash.MHASH_SHA256), origin="mhash") |
39 |
+ sha512hash = _generate_hash_function("SHA512", functools.partial(mhash.MHASH, mhash.MHASH_SHA512), origin="mhash") |
40 |
+ for local_name, hash_name in (("rmd160", "ripemd160"), ("whirlpool", "whirlpool")): |
41 |
+ if hasattr(mhash, 'MHASH_%s' % local_name.upper()): |
42 |
+ globals()['%shash' % local_name] = \ |
43 |
+ _generate_hash_function(local_name.upper(), \ |
44 |
+ functools.partial(mhash.MHASH, getattr(mhash, 'MHASH_%s' % hash_name.upper())), \ |
45 |
+ origin='mhash') |
46 |
+except ImportError: |
47 |
+ pass |
48 |
+ |
49 |
# Use pycrypto when available, prefer it over the internal fallbacks |
50 |
try: |
51 |
from Crypto.Hash import SHA256, RIPEMD |