commit:     929f27a8ee7025c3ed29715437dc6bbdbba01f21
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Tue Feb 28 22:22:43 2017 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Wed Mar  1 15:42:39 2017 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=929f27a8

checksum: Add pycryptodome fallbacks for SHA3 and BLAKE2

Approved-by: Zac Medico <zmedico <AT> gentoo.org>

 pym/portage/checksum.py | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

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:

Reply via email to