commit: 5804bfcc13b6b35e2bab5d6d93f899f8648bbd89 Author: Sam James <sam <AT> gentoo <DOT> org> AuthorDate: Mon Mar 20 03:42:21 2023 +0000 Commit: Sam James <sam <AT> gentoo <DOT> org> CommitDate: Tue Mar 21 02:30:24 2023 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=5804bfcc
checksum: drop mhash usage for WHIRLPOOL; consolidate RIPEMD logic - Drop mhash fallback logic for WHIRLPOOL as we already have: hashlib > pycrypto > bundled C > bundled pure Python - Consolidate the RIPEMD logic accordingly as we don't need to share the mhash fallback logic between WHIRLPOOL and RIPEMD anymore. Signed-off-by: Sam James <sam <AT> gentoo.org> lib/portage/checksum.py | 49 +++++++++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/lib/portage/checksum.py b/lib/portage/checksum.py index 3b9796b32..b10643476 100644 --- a/lib/portage/checksum.py +++ b/lib/portage/checksum.py @@ -26,7 +26,7 @@ from portage.localization import _ # SHA256: hashlib # SHA512: hashlib # RMD160: hashlib, pycrypto, mhash -# WHIRLPOOL: hashlib, mhash, bundled (C), bundled (Python) +# WHIRLPOOL: hashlib, bundled (C), bundled (Python) # BLAKE2B (512): hashlib # BLAKE2S (512): hashlib # SHA3_256: hashlib @@ -141,33 +141,26 @@ if "RMD160" not in hashfunc_map: if rmd160hash_ is not None: _generate_hash_function("RMD160", rmd160hash_, origin="pycrypto") except ImportError: - pass - - pass - - -# 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. -if "RMD160" not in hashfunc_map or "WHIRLPOOL" not in hashfunc_map: - try: - import mhash - - for local_name, hash_name in ( - ("RMD160", "RIPEMD160"), - ("WHIRLPOOL", "WHIRLPOOL"), - ): - if local_name not in hashfunc_map and hasattr(mhash, f"MHASH_{hash_name}"): - _generate_hash_function( - local_name, - functools.partial( - mhash.MHASH, getattr(mhash, f"MHASH_{hash_name}") - ), - origin="mhash", - ) - except ImportError: - pass + # 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 + + for local_name, hash_name in (("RMD160", "RIPEMD160"),): + if local_name not in hashfunc_map and hasattr( + mhash, f"MHASH_{hash_name}" + ): + _generate_hash_function( + local_name, + functools.partial( + mhash.MHASH, getattr(mhash, f"MHASH_{hash_name}") + ), + origin="mhash", + ) + except ImportError: + pass _whirlpool_unaccelerated = False