summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin H. Johnson <robbat2@gentoo.org>2011-10-01 07:40:54 +0000
committerZac Medico <zmedico@gentoo.org>2011-10-01 22:55:02 -0700
commitfaf87ba9877e3b5a7866c6649f956f15950e789a (patch)
tree1454a00fb71d2921b6ec74a464eb47297bcabc41
parent47c5f5c9a9891cc296e989d8f29ffb74ef7738a3 (diff)
downloadportage-faf87ba9877e3b5a7866c6649f956f15950e789a.tar.gz
portage-faf87ba9877e3b5a7866c6649f956f15950e789a.tar.bz2
portage-faf87ba9877e3b5a7866c6649f956f15950e789a.zip
Manifest2 hash backend provider: mhash
Offer mhash as a provider for Manifest2 hash generation and validation. This is important as either of pycrypto or fchksum offer an accelerated Whirlpool implementation, and hashlib might not offer it. Additionally, the mhash implementation is accelerated and ships with a rigorious testsuite. Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
-rw-r--r--pym/portage/checksum.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py
index 6bace4d6a..a4a744ba9 100644
--- a/pym/portage/checksum.py
+++ b/pym/portage/checksum.py
@@ -80,6 +80,25 @@ sha1hash = _generate_hash_function("SHA1", _new_sha1, origin="internal")
from portage.util.whirlpool import new as _new_whirlpool
whirlpoolhash = _generate_hash_function("WHIRLPOOL", _new_whirlpool, origin="bundled")
+# Try to use mhash if available
+# mhash causes GIL presently, so it gets less priority than hashlib and
+# pycrypto. However, it might be the only accelerated implementation of
+# WHIRLPOOL available.
+try:
+ import mhash, functools
+ md5hash = _generate_hash_function("MD5", functools.partial(mhash.MHASH, mhash.MHASH_MD5), origin="mhash")
+ sha1hash = _generate_hash_function("SHA1", functools.partial(mhash.MHASH, mhash.MHASH_SHA1), origin="mhash")
+ sha256hash = _generate_hash_function("SHA256", functools.partial(mhash.MHASH, mhash.MHASH_SHA256), origin="mhash")
+ sha512hash = _generate_hash_function("SHA512", functools.partial(mhash.MHASH, mhash.MHASH_SHA512), origin="mhash")
+ for local_name, hash_name in (("rmd160", "ripemd160"), ("whirlpool", "whirlpool")):
+ if hasattr(mhash, 'MHASH_%s' % local_name.upper()):
+ globals()['%shash' % local_name] = \
+ _generate_hash_function(local_name.upper(), \
+ functools.partial(mhash.MHASH, getattr(mhash, 'MHASH_%s' % hash_name.upper())), \
+ origin='mhash')
+except ImportError:
+ pass
+
# Use pycrypto when available, prefer it over the internal fallbacks
try:
from Crypto.Hash import SHA256, RIPEMD