Offer mhash as a provider for Manifest2 hash generation and validation.
This is important as none of pycrypto/hashlib/fchksum offer an
accelerated Whirlpool implementaiton. Additionally, the mhash
implementation is accelerated and ships with a rigorious testsuite.
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
---
pym/portage/checksum.py | 19 +++++++++++++++++--
1 files changed, 17 insertions(+), 2 deletions(-)
# Use python-fchksum if available, prefer it over all other MD5 implementations
try:
--
1.7.6
09-30-2011, 10:51 PM
"Robin H. Johnson"
Manifest2 hash backend provider: mhash
On Fri, Sep 30, 2011 at 01:27:41AM +0000, Robin H. Johnson wrote:
> Offer mhash as a provider for Manifest2 hash generation and validation.
> This is important as none of pycrypto/hashlib/fchksum offer an
> accelerated Whirlpool implementaiton. Additionally, the mhash
> implementation is accelerated and ships with a rigorious testsuite.
ferringb has pointed out that mhash holds the GIL lock, and that hashlib
does support whirlpool (despite the docs not mentioning it).
This portion might end up dropped then.
--
Robin Hugh Johnson
Gentoo Linux: Developer, Trustee & Infrastructure Lead
E-Mail : robbat2@gentoo.org
GnuPG FP : 11AC BA4F 4778 E3F6 E4ED F38E B27B 944E 3488 4E85
10-01-2011, 07:40 AM
"Robin H. Johnson"
Manifest2 hash backend provider: mhash
From: "Robin H. Johnson" <robbat2@gentoo.org>
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>
---
pym/portage/checksum.py | 19 +++++++++++++++++++
1 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py
index 40ae836..c0c7c04 100644
--- a/pym/portage/checksum.py
+++ b/pym/portage/checksum.py
@@ -75,6 +75,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' % s.upper())),
+ origin='mhash')
+except ImportError as e:
+ pass
+
# Use pycrypto when available, prefer it over the internal fallbacks
try:
from Crypto.Hash import SHA256, RIPEMD
--
1.7.7