1 |
On Sat, Oct 01, 2011 at 07:40:52AM +0000, Robin H. Johnson wrote: |
2 |
> From: "Robin H. Johnson" <robbat2@g.o> |
3 |
> |
4 |
> Provide public-domain implementation of the Whirlpool hash algorithm to |
5 |
> be used as new Manifest2 hash. |
6 |
> |
7 |
> Signed-off-by: Robin H. Johnson <robbat2@g.o> |
8 |
> --- |
9 |
> pym/portage/checksum.py | 8 ++++++-- |
10 |
> 1 files changed, 6 insertions(+), 2 deletions(-) |
11 |
> |
12 |
> diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py |
13 |
> index e5455fa..3593686 100644 |
14 |
> --- a/pym/portage/checksum.py |
15 |
> +++ b/pym/portage/checksum.py |
16 |
> @@ -71,6 +71,10 @@ except ImportError: |
17 |
> |
18 |
> sha1hash = _generate_hash_function("SHA1", _new_sha1, origin="internal") |
19 |
> |
20 |
> +# Bundled WHIRLPOOL implementation |
21 |
> +from portage.util.whirlpool import new as _new_whirlpool |
22 |
> +whirlpoolhash = _generate_hash_function("WHIRLPOOL", _new_whirlpool, origin="bundled") |
23 |
> + |
24 |
|
25 |
Likely should shift this to a trailing check if no whirlpool |
26 |
implementation was found; via this, we can avoid the import unless |
27 |
it's needed. |
28 |
~brian |
29 |
|
30 |
> # Use pycrypto when available, prefer it over the internal fallbacks |
31 |
> try: |
32 |
> from Crypto.Hash import SHA256, RIPEMD |
33 |
> @@ -80,14 +84,14 @@ except ImportError as e: |
34 |
> pass |
35 |
> |
36 |
> # Use hashlib from python-2.5 if available and prefer it over pycrypto and internal fallbacks. |
37 |
> -# Need special handling for RMD160 as it may not always be provided by hashlib. |
38 |
> +# Need special handling for RMD160/WHIRLPOOL as they may not always be provided by hashlib. |
39 |
> try: |
40 |
> import hashlib, functools |
41 |
> |
42 |
> md5hash = _generate_hash_function("MD5", hashlib.md5, origin="hashlib") |
43 |
> sha1hash = _generate_hash_function("SHA1", hashlib.sha1, origin="hashlib") |
44 |
> sha256hash = _generate_hash_function("SHA256", hashlib.sha256, origin="hashlib") |
45 |
> - for local_name, hash_name in (("rmd160", "ripemd160"), ): |
46 |
> + for local_name, hash_name in (("rmd160", "ripemd160"), ("whirlpool", "whirlpool")): |
47 |
> try: |
48 |
> hashlib.new(hash_name) |
49 |
> except ValueError: |
50 |
> -- |
51 |
> 1.7.7 |
52 |
> |