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:
-- 
2.12.0


Reply via email to