public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/
Date: Mon, 13 Mar 2017 21:46:46 +0000 (UTC)	[thread overview]
Message-ID: <1489441590.9a36b0c028af8a13bc9c8b28da2cdbf336a625ae.mgorny@gentoo> (raw)

commit:     9a36b0c028af8a13bc9c8b28da2cdbf336a625ae
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Sun Mar 12 16:00:27 2017 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Mon Mar 13 21:46:30 2017 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=9a36b0c0

portage.checksum: Reorder to avoid loading redundant impls

Reorder the checksum implementations to start with the most preferred
implementation, and try fallbacks only if the most preferred
implementation is not available. Most importantly, this means that
Portage will no longer attempt to load all hash libraries in the system,
especially when it can satisfy its requirements with hashlib.

 pym/portage/checksum.py | 145 +++++++++++++++++++++++++++++-------------------
 1 file changed, 87 insertions(+), 58 deletions(-)

diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py
index 659012cdc..2c482f5e7 100644
--- a/pym/portage/checksum.py
+++ b/pym/portage/checksum.py
@@ -93,66 +93,11 @@ class _generate_hash_function(object):
 
 		return (checksum.hexdigest(), size)
 
-# Define hash functions, try to use the best module available. Later definitions
-# override earlier ones
 
-# 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"), ("WHIRLPOOL", "WHIRLPOOL")):
-		if hasattr(mhash, 'MHASH_%s' % hash_name):
-			_generate_hash_function(local_name,
-				functools.partial(mhash.MHASH, getattr(mhash, 'MHASH_%s' % hash_name)),
-				origin='mhash')
-except ImportError:
-	pass
-
-# Use pycrypto when available, prefer it over the internal fallbacks
-# Check for 'new' attributes, since they can be missing if the module
-# is broken somehow.
-try:
-	from Crypto.Hash import RIPEMD
-	rmd160hash_ = getattr(RIPEMD, 'new', None)
-	if rmd160hash_ is not None:
-		_generate_hash_function("RMD160",
-			rmd160hash_, origin="pycrypto")
-except ImportError:
-	pass
-
-try:
-	# added in pycryptodome
-	from Crypto.Hash import BLAKE2b, BLAKE2s, SHA3_256, SHA3_512
-
-	blake2bhash_ = getattr(BLAKE2b, 'new', None)
-	if blake2bhash_ is not None:
-		_generate_hash_function("BLAKE2B",
-			functools.partial(blake2bhash_, digest_bytes=64), origin="pycrypto")
-	blake2shash_ = getattr(BLAKE2s, 'new', None)
-	if blake2shash_ is not None:
-		_generate_hash_function("BLAKE2S",
-			functools.partial(blake2shash_, digest_bytes=32), origin="pycrypto")
-	sha3_256hash_ = getattr(SHA3_256, 'new', None)
-	if sha3_256hash_ is not None:
-		_generate_hash_function("SHA3_256",
-			sha3_256hash_, origin="pycrypto")
-	sha3_512hash_ = getattr(SHA3_512, 'new', None)
-	if sha3_512hash_ is not None:
-		_generate_hash_function("SHA3_512",
-			sha3_512hash_, origin="pycrypto")
-except ImportError:
-	pass
-
-# Support using pysha3 as fallback for python<3.6
-try:
-	import sha3
+# Define hash functions, try to use the best module available. Preferred
+# modules should go first, latter ones should check if the hashes aren't
+# already defined.
 
-	_generate_hash_function("SHA3_256", sha3.sha3_256, origin="pysha3")
-	_generate_hash_function("SHA3_512", sha3.sha3_512, origin="pysha3")
-except ImportError:
-	pass
 
 # Use hashlib from python-2.5 if available and prefer it over pycrypto and internal fallbacks.
 # Need special handling for RMD160/WHIRLPOOL as they may not always be provided by hashlib.
@@ -178,6 +123,89 @@ for local_name, hash_name in (
 			functools.partial(hashlib.new, hash_name),
 			origin='hashlib')
 
+
+# Support using pysha3 as fallback for python<3.6
+if "SHA3_256" not in hashfunc_map or "SHA3_512" not in hashfunc_map:
+	try:
+		import sha3
+
+		_generate_hash_function("SHA3_256", sha3.sha3_256, origin="pysha3")
+		_generate_hash_function("SHA3_512", sha3.sha3_512, origin="pysha3")
+	except ImportError:
+		pass
+
+
+# Use pycrypto when available, prefer it over the internal fallbacks
+# Check for 'new' attributes, since they can be missing if the module
+# is broken somehow.
+if 'RMD160' not in hashfunc_map:
+	try:
+		from Crypto.Hash import RIPEMD
+		rmd160hash_ = getattr(RIPEMD, 'new', None)
+		if rmd160hash_ is not None:
+			_generate_hash_function("RMD160",
+				rmd160hash_, origin="pycrypto")
+	except ImportError:
+		pass
+
+# The following hashes were added in pycryptodome (pycrypto fork)
+if 'BLAKE2B' not in hashfunc_map:
+	try:
+		from Crypto.Hash import BLAKE2b
+		blake2bhash_ = getattr(BLAKE2b, 'new', None)
+		if blake2bhash_ is not None:
+			_generate_hash_function("BLAKE2B",
+				functools.partial(blake2bhash_, digest_bytes=64), origin="pycrypto")
+	except ImportError:
+		pass
+
+if 'BLAKE2S' not in hashfunc_map:
+	try:
+		from Crypto.Hash import BLAKE2s
+		blake2shash_ = getattr(BLAKE2s, 'new', None)
+		if blake2shash_ is not None:
+			_generate_hash_function("BLAKE2S",
+				functools.partial(blake2shash_, digest_bytes=32), origin="pycrypto")
+	except ImportError:
+		pass
+
+if 'SHA3_256' not in hashfunc_map:
+	try:
+		from Crypto.Hash import SHA3_256
+		sha3_256hash_ = getattr(SHA3_256, 'new', None)
+		if sha3_256hash_ is not None:
+			_generate_hash_function("SHA3_256",
+				sha3_256hash_, origin="pycrypto")
+	except ImportError:
+		pass
+
+if 'SHA3_512' not in hashfunc_map:
+	try:
+		from Crypto.Hash import SHA3_512
+		sha3_512hash_ = getattr(SHA3_512, 'new', None)
+		if sha3_512hash_ is not None:
+			_generate_hash_function("SHA3_512",
+				sha3_512hash_, origin="pycrypto")
+	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.
+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, 'MHASH_%s' % hash_name):
+				_generate_hash_function(local_name,
+					functools.partial(mhash.MHASH, getattr(mhash, 'MHASH_%s' % hash_name)),
+					origin='mhash')
+	except ImportError:
+		pass
+
+
 _whirlpool_unaccelerated = False
 if "WHIRLPOOL" not in hashfunc_map:
 	# Bundled WHIRLPOOL implementation
@@ -196,6 +224,7 @@ hashfunc_map["size"] = SizeHash()
 
 # end actual hash functions
 
+
 prelink_capable = False
 if os.path.exists(PRELINK_BINARY):
 	cmd = [PRELINK_BINARY, "--version"]


             reply	other threads:[~2017-03-13 21:47 UTC|newest]

Thread overview: 248+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-13 21:46 Michał Górny [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-04-28 23:08 [gentoo-commits] proj/portage:master commit in: pym/portage/ Zac Medico
2018-04-17  2:22 Zac Medico
2018-03-30  5:20 [gentoo-commits] proj/portage:repoman " Zac Medico
2018-03-30  4:23 ` [gentoo-commits] proj/portage:master " Zac Medico
2018-03-11 11:44 Michał Górny
2018-03-04 21:05 Michał Górny
2018-02-25 20:58 Michał Górny
2018-02-22 19:13 Michał Górny
2018-02-22 17:32 Zac Medico
2018-01-14  9:59 Michał Górny
2017-12-06  8:39 Michał Górny
2017-12-05 17:37 Michał Górny
2017-12-04  8:40 Zac Medico
2017-11-20 18:44 Michał Górny
2017-11-06 14:33 Michał Górny
2017-11-06 14:33 Michał Górny
2017-10-22 22:33 Zac Medico
2017-07-19 20:54 Manuel Rüger
2017-06-15 17:15 Michał Górny
2017-06-15 17:05 Michał Górny
2017-03-13 21:46 Michał Górny
2017-03-13 21:46 Michał Górny
2017-03-13 21:46 Michał Górny
2017-03-13 21:46 Michał Górny
2017-03-13 21:46 Michał Górny
2017-03-13 21:46 Michał Górny
2017-03-13 21:46 Michał Górny
2017-03-13 21:46 Michał Górny
2017-03-13 21:46 Michał Górny
2017-03-13 21:46 Michał Górny
2017-03-13 21:46 Michał Górny
2017-03-13 21:46 Michał Górny
2017-03-01 15:43 Michał Górny
2017-03-01 15:43 Michał Górny
2017-02-28 22:07 Michał Górny
2017-02-28 22:07 Michał Górny
2017-02-28 22:07 Michał Górny
2017-01-27  0:04 Zac Medico
2017-01-20  7:28 Zac Medico
2017-01-17 17:43 Zac Medico
2016-12-06  3:54 Brian Dolbec
2016-12-06  3:54 Brian Dolbec
2016-12-05  5:14 Brian Dolbec
2016-10-02  4:46 Zac Medico
2016-09-15 21:42 Zac Medico
2016-09-15  2:03 Zac Medico
2016-09-15  2:03 Zac Medico
2016-07-23 23:09 Zac Medico
2016-06-29  3:04 Brian Dolbec
2016-05-31  1:05 Zac Medico
2016-05-20  9:01 Alexander Berntsen
2016-05-18 16:45 Zac Medico
2016-05-18 16:42 Zac Medico
2016-05-16  9:47 Brian Dolbec
2016-04-30  0:12 Brian Dolbec
2016-04-29 23:16 Brian Dolbec
2015-12-21 16:17 Zac Medico
2015-12-16 18:58 Zac Medico
2015-12-15 16:18 Zac Medico
2015-11-15 22:54 Michał Górny
2015-11-12 19:32 Michał Górny
2015-10-02  5:08 Zac Medico
2015-08-17  3:39 Zac Medico
2015-05-11  0:47 Zac Medico
2015-01-31 23:13 Zac Medico
2015-01-30 20:32 Brian Dolbec
2015-01-30 20:32 Brian Dolbec
2015-01-12  9:13 Zac Medico
2015-01-12  9:13 Zac Medico
2014-12-04 14:01 Michał Górny
2014-12-04 14:01 Michał Górny
2014-12-03 18:30 Zac Medico
2014-11-18  1:04 Zac Medico
2014-11-11 22:30 Zac Medico
2014-10-23 18:18 Zac Medico
2014-09-12 21:26 Zac Medico
2014-09-11 23:45 Brian Dolbec
2014-09-11 23:45 Brian Dolbec
2014-09-11 23:45 Brian Dolbec
2014-09-11 23:04 Brian Dolbec
2014-09-11 23:04 Brian Dolbec
2014-08-19  7:01 Michał Górny
2014-08-06 20:54 ` Michał Górny
2014-06-12 15:47 Brian Dolbec
2014-04-05 20:44 Sebastian Luther
2014-02-04  2:53 Mike Frysinger
2014-01-19  8:45 Arfrever Frehtes Taifersar Arahesis
2014-01-07 23:42 Arfrever Frehtes Taifersar Arahesis
2014-01-02 22:53 Arfrever Frehtes Taifersar Arahesis
2013-11-30 18:15 Mike Frysinger
2013-11-30  5:35 Mike Frysinger
2013-09-02  0:55 Zac Medico
2013-09-01 23:57 Zac Medico
2013-09-01 20:55 Zac Medico
2013-08-18  6:04 Zac Medico
2013-07-29 18:40 Zac Medico
2013-07-13  9:24 Arfrever Frehtes Taifersar Arahesis
2013-06-22 17:49 Zac Medico
2013-04-28 22:42 Zac Medico
2013-03-22 15:42 Zac Medico
2013-03-22 15:36 Zac Medico
2013-03-22  1:42 Zac Medico
2013-03-19 21:57 Zac Medico
2013-03-17  4:33 Arfrever Frehtes Taifersar Arahesis
2013-03-17  3:35 Arfrever Frehtes Taifersar Arahesis
2013-02-17 22:13 Zac Medico
2013-02-15 22:34 Zac Medico
2013-01-28  1:21 Zac Medico
2013-01-25 21:30 Zac Medico
2013-01-19  6:14 Zac Medico
2013-01-19  4:57 Zac Medico
2013-01-19  4:32 Zac Medico
2013-01-19  4:03 Zac Medico
2013-01-19  3:43 Zac Medico
2013-01-19  2:10 Zac Medico
2013-01-18 19:11 Zac Medico
2013-01-17 17:23 Zac Medico
2013-01-14 11:35 Zac Medico
2013-01-09 12:20 Zac Medico
2013-01-08  1:03 Zac Medico
2013-01-08  0:56 Zac Medico
2013-01-04  4:25 Zac Medico
2013-01-03 23:45 Zac Medico
2012-11-15 16:09 Zac Medico
2012-11-14 17:28 Zac Medico
2012-10-17 22:58 Zac Medico
2012-10-16 19:09 Zac Medico
2012-10-08 15:43 Zac Medico
2012-10-08 14:54 Zac Medico
2012-09-24 15:19 Zac Medico
2012-09-21 22:00 Zac Medico
2012-09-20  4:17 Zac Medico
2012-09-12  8:12 Zac Medico
2012-09-12  6:39 Zac Medico
2012-09-02  2:38 Zac Medico
2012-09-02  0:42 Zac Medico
2012-08-29 20:29 Zac Medico
2012-08-26 22:31 Zac Medico
2012-07-27 22:46 Zac Medico
2012-07-27 22:40 Zac Medico
2012-07-27 22:22 Zac Medico
2012-07-27 22:10 Zac Medico
2012-07-27  2:43 Zac Medico
2012-07-23  7:52 Zac Medico
2012-07-22 22:06 Zac Medico
2012-07-22 21:53 Zac Medico
2012-07-18 22:31 Zac Medico
2012-07-12 19:54 Zac Medico
2012-07-10  0:13 Zac Medico
2012-07-09 21:50 Zac Medico
2012-07-09 20:46 Zac Medico
2012-07-05  0:22 Zac Medico
2012-07-02 21:34 Zac Medico
2012-06-10 23:41 Zac Medico
2012-06-03  6:35 Arfrever Frehtes Taifersar Arahesis
2012-06-01 21:43 Zac Medico
2012-06-01 21:28 Zac Medico
2012-05-14  3:29 Zac Medico
2012-05-14  3:18 Zac Medico
2012-05-14  1:24 Zac Medico
2012-05-13 22:30 Zac Medico
2012-05-13 22:16 Zac Medico
2012-05-13 19:52 Zac Medico
2012-05-13  9:05 Zac Medico
2012-05-13  8:44 Zac Medico
2012-05-12 22:57 Zac Medico
2012-05-12 22:31 Arfrever Frehtes Taifersar Arahesis
2012-05-12 16:26 Arfrever Frehtes Taifersar Arahesis
2012-05-12  7:36 Zac Medico
2012-05-02 19:55 Zac Medico
2012-04-14  0:56 Zac Medico
2012-04-01 16:38 Zac Medico
2012-03-31 17:22 Zac Medico
2012-03-29  3:35 Mike Frysinger
2012-03-28  0:36 Zac Medico
2012-03-18 17:07 Zac Medico
2012-02-28  4:58 Zac Medico
2012-02-16 19:44 Arfrever Frehtes Taifersar Arahesis
2012-02-15  9:32 Zac Medico
2012-02-13 21:58 Zac Medico
2012-02-12  3:39 Zac Medico
2012-02-06 17:20 Zac Medico
2012-01-11  3:59 Arfrever Frehtes Taifersar Arahesis
2011-12-24  1:29 Arfrever Frehtes Taifersar Arahesis
2011-12-21 20:56 Zac Medico
2011-12-20 23:27 Zac Medico
2011-12-14 20:14 Arfrever Frehtes Taifersar Arahesis
2011-12-14 17:54 Zac Medico
2011-12-14  9:11 Zac Medico
2011-12-14  7:33 Zac Medico
2011-12-14  6:00 Zac Medico
2011-12-14  5:26 Zac Medico
2011-12-14  2:03 Zac Medico
2011-12-11  8:15 Zac Medico
2011-12-10 23:49 Zac Medico
2011-12-10 22:40 Zac Medico
2011-12-10 22:02 Zac Medico
2011-12-10 19:13 Zac Medico
2011-12-10  5:28 Arfrever Frehtes Taifersar Arahesis
2011-12-09 23:23 Zac Medico
2011-12-08 21:16 Zac Medico
2011-12-02  3:24 Zac Medico
2011-12-01 23:26 Zac Medico
2011-12-01 17:52 Zac Medico
2011-11-13 20:33 Zac Medico
2011-10-30  7:08 Zac Medico
2011-10-30  6:53 Zac Medico
2011-10-29  3:34 Zac Medico
2011-10-28  0:54 Zac Medico
2011-10-26 21:51 Zac Medico
2011-10-23 18:32 Zac Medico
2011-10-17 21:46 Zac Medico
2011-10-17  3:04 Zac Medico
2011-10-17  3:00 Zac Medico
2011-10-16 12:50 Arfrever Frehtes Taifersar Arahesis
2011-10-15  1:49 Zac Medico
2011-10-08  8:05 Zac Medico
2011-10-03 17:42 Zac Medico
2011-10-02 23:43 Zac Medico
2011-10-02 22:54 Zac Medico
2011-10-02  6:32 Zac Medico
2011-10-02  6:01 Zac Medico
2011-10-02  5:55 Zac Medico
2011-10-02  5:42 Zac Medico
2011-10-02  5:25 Zac Medico
2011-10-02  5:18 Zac Medico
2011-10-02  4:58 Zac Medico
2011-09-28  6:49 Zac Medico
2011-09-15  2:38 Zac Medico
2011-09-15  2:23 Zac Medico
2011-09-14  2:35 Zac Medico
2011-09-09 20:47 Zac Medico
2011-09-09  4:06 Zac Medico
2011-09-06 19:15 Zac Medico
2011-09-02  2:14 Zac Medico
2011-08-29  5:21 Zac Medico
2011-08-25 21:50 Arfrever Frehtes Taifersar Arahesis
2011-07-12 22:49 Zac Medico
2011-07-11  0:13 Zac Medico
2011-07-10 23:46 Zac Medico
2011-06-09 15:44 Zac Medico
2011-06-09 10:41 Zac Medico
2011-06-03 21:51 Zac Medico
2011-05-04  4:12 Zac Medico
2011-03-06  0:41 Zac Medico
2011-02-18  8:33 Zac Medico
2011-02-18  8:04 Zac Medico
2011-02-08  9:33 Zac Medico

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1489441590.9a36b0c028af8a13bc9c8b28da2cdbf336a625ae.mgorny@gentoo \
    --to=mgorny@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox