summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2017-02-28 23:22:43 +0100
committerMichał Górny <mgorny@gentoo.org>2017-03-01 16:42:39 +0100
commit929f27a8ee7025c3ed29715437dc6bbdbba01f21 (patch)
tree6a1ad05303ad64dd06c542d3c6c53b966cef5a28
parentchecksum: Fix overriding fallbacks on broken pycrypto (diff)
downloadportage-929f27a8ee7025c3ed29715437dc6bbdbba01f21.tar.gz
portage-929f27a8ee7025c3ed29715437dc6bbdbba01f21.tar.bz2
portage-929f27a8ee7025c3ed29715437dc6bbdbba01f21.zip
checksum: Add pycryptodome fallbacks for SHA3 and BLAKE2
Approved-by: Zac Medico <zmedico@gentoo.org>
-rw-r--r--pym/portage/checksum.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py
index fc38417a7..042a0a745 100644
--- a/pym/portage/checksum.py
+++ b/pym/portage/checksum.py
@@ -116,6 +116,28 @@ try:
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:
+ blake2bhash = _generate_hash_function("BLAKE2B",
+ blake2bhash_, origin="pycrypto")
+ blake2shash_ = getattr(BLAKE2s, 'new', None)
+ if blake2shash_ is not None:
+ blake2shash = _generate_hash_function("BLAKE2S",
+ blake2shash_, origin="pycrypto")
+ sha3_256hash_ = getattr(SHA3_256, 'new', None)
+ if sha3_256hash_ is not None:
+ sha3_256hash = _generate_hash_function("SHA3_256",
+ sha3_256hash_, origin="pycrypto")
+ sha3_512hash_ = getattr(SHA3_512, 'new', None)
+ if sha3_512hash_ is not None:
+ sha3_512hash = _generate_hash_function("SHA3_512",
+ sha3_512hash_, origin="pycrypto")
+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.
try: