Gentoo Archives: gentoo-portage-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-portage-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-portage-dev] [PATCH 2/2] checksum: Add pycryptodome fallbacks for SHA3 and BLAKE2
Date: Wed, 01 Mar 2017 07:35:37
Message-Id: 20170301073459.4130-2-mgorny@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH 1/2] checksum: Fix overriding fallbacks on broken pycrypto by "Michał Górny"
1 ---
2 pym/portage/checksum.py | 22 ++++++++++++++++++++++
3 1 file changed, 22 insertions(+)
4
5 diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py
6 index fc38417a7..042a0a745 100644
7 --- a/pym/portage/checksum.py
8 +++ b/pym/portage/checksum.py
9 @@ -116,6 +116,28 @@ try:
10 except ImportError:
11 pass
12
13 +try:
14 + # added in pycryptodome
15 + from Crypto.Hash import BLAKE2b, BLAKE2s, SHA3_256, SHA3_512
16 + blake2bhash_ = getattr(BLAKE2b, 'new', None)
17 + if blake2bhash_ is not None:
18 + blake2bhash = _generate_hash_function("BLAKE2B",
19 + blake2bhash_, origin="pycrypto")
20 + blake2shash_ = getattr(BLAKE2s, 'new', None)
21 + if blake2shash_ is not None:
22 + blake2shash = _generate_hash_function("BLAKE2S",
23 + blake2shash_, origin="pycrypto")
24 + sha3_256hash_ = getattr(SHA3_256, 'new', None)
25 + if sha3_256hash_ is not None:
26 + sha3_256hash = _generate_hash_function("SHA3_256",
27 + sha3_256hash_, origin="pycrypto")
28 + sha3_512hash_ = getattr(SHA3_512, 'new', None)
29 + if sha3_512hash_ is not None:
30 + sha3_512hash = _generate_hash_function("SHA3_512",
31 + sha3_512hash_, origin="pycrypto")
32 +except ImportError:
33 + pass
34 +
35 # Use hashlib from python-2.5 if available and prefer it over pycrypto and internal fallbacks.
36 # Need special handling for RMD160/WHIRLPOOL as they may not always be provided by hashlib.
37 try:
38 --
39 2.12.0

Replies