commit:     cd23be212c0ae60034c833873502bb36ee27e94c
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Sun Mar 12 12:12:31 2017 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Mon Mar 13 21:46:28 2017 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=cd23be21

portage.checksum: Support pysha3 fallback for SHA3

pysha3 provides a stand-alone FIPS-compliant SHA3 implementation that
can be used as a fallback for Python < 3.6.

 pym/portage/checksum.py | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py
index ac11d3f4b..3e61acdec 100644
--- a/pym/portage/checksum.py
+++ b/pym/portage/checksum.py
@@ -10,6 +10,7 @@ from portage import _encodings
 from portage import _unicode_decode, _unicode_encode
 import errno
 import stat
+import sys
 import subprocess
 import tempfile
 
@@ -26,8 +27,8 @@ import tempfile
 # WHIRLPOOL: hashlib, mhash, bundled
 # BLAKE2B (512): hashlib (3.6+), pycrypto
 # BLAKE2S (512): hashlib (3.6+), pycrypto
-# SHA3_256: hashlib (3.6+), pycrypto
-# SHA3_512: hashlib (3.6+), pycrypto
+# SHA3_256: hashlib (3.6+), pysha3, pycrypto
+# SHA3_512: hashlib (3.6+), pysha3, pycrypto
 
 
 #dict of all available hash functions
@@ -138,6 +139,15 @@ try:
 except ImportError:
        pass
 
+# Support using pysha3 as fallback for python<3.6
+try:
+       import sha3
+
+       sha3_256hash = _generate_hash_function("SHA3_256", sha3.sha3_256, 
origin="pysha3")
+       sha3_512hash = _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.
 try:

Reply via email to