From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <gentoo-commits+bounces-938210-garchives=archives.gentoo.org@lists.gentoo.org> Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id F2BF2139694 for <garchives@archives.gentoo.org>; Mon, 13 Mar 2017 21:47:05 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id D266521C08C; Mon, 13 Mar 2017 21:46:54 +0000 (UTC) Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id B2C6221C08C for <gentoo-commits@lists.gentoo.org>; Mon, 13 Mar 2017 21:46:54 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 9B72B340A23 for <gentoo-commits@lists.gentoo.org>; Mon, 13 Mar 2017 21:46:48 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 1B78C673F for <gentoo-commits@lists.gentoo.org>; Mon, 13 Mar 2017 21:46:46 +0000 (UTC) From: "Michał Górny" <mgorny@gentoo.org> To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Michał Górny" <mgorny@gentoo.org> Message-ID: <1489441590.35d17f9331ac367a47e0e5277e63d766da097df3.mgorny@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/ X-VCS-Repository: proj/portage X-VCS-Files: pym/portage/checksum.py X-VCS-Directories: pym/portage/ X-VCS-Committer: mgorny X-VCS-Committer-Name: Michał Górny X-VCS-Revision: 35d17f9331ac367a47e0e5277e63d766da097df3 X-VCS-Branch: master Date: Mon, 13 Mar 2017 21:46:46 +0000 (UTC) Precedence: bulk List-Post: <mailto:gentoo-commits@lists.gentoo.org> List-Help: <mailto:gentoo-commits+help@lists.gentoo.org> List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org> List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org> List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org> X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 1f756816-9a8d-47d0-aabd-aa618d4c99d8 X-Archives-Hash: 8fb08fb43ab2e845335ddd5ac4f9bc48 commit: 35d17f9331ac367a47e0e5277e63d766da097df3 Author: Michał Górny <mgorny <AT> gentoo <DOT> org> AuthorDate: Sun Mar 12 16:32:06 2017 +0000 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> CommitDate: Mon Mar 13 21:46:30 2017 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=35d17f93 portage.checksum: Support pygcrypt as optimized fallback pygcrypt uses libgcrypt which provides support for ripemd160, whirlpool, SHA3, plus some algorithms not provided by any other library. pym/portage/checksum.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py index 2c482f5e7..92b41b133 100644 --- a/pym/portage/checksum.py +++ b/pym/portage/checksum.py @@ -135,6 +135,44 @@ if "SHA3_256" not in hashfunc_map or "SHA3_512" not in hashfunc_map: pass +# Support pygcrypt as fallback using optimized routines from libgcrypt +# (GnuPG). +gcrypt_algos = frozenset(('RMD160', 'WHIRLPOOL', 'SHA3_256', 'SHA3_512')) +if gcrypt_algos.difference(hashfunc_map): + try: + import binascii + import pygcrypt.hashcontext + + class GCryptHashWrapper(object): + def __init__(self, algo): + self._obj = pygcrypt.hashcontext.HashContext(algo=algo) + + def update(self, data): + self._obj.write(data) + + def hexdigest(self): + return binascii.b2a_hex(self._obj.read()).decode() + + name_mapping = { + 'RMD160': 'ripemd160', + 'WHIRLPOOL': 'whirlpool', + 'SHA3_256': 'sha3-256', + 'SHA3_512': 'sha3-512', + } + + for local_name, gcry_name in name_mapping.items(): + try: + pygcrypt.hashcontext.HashContext(algo=gcry_name) + except Exception: # yes, it throws Exception... + pass + else: + _generate_hash_function(local_name, + functools.partial(GCryptHashWrapper, gcry_name), + origin="pygcrypt") + except ImportError: + pass + + # Use pycrypto when available, prefer it over the internal fallbacks # Check for 'new' attributes, since they can be missing if the module # is broken somehow.