Provide public-domain implementation of the Whirlpool hash algorithm to
be used as new Manifest2 hash.
Signed-off-by: Robin H. Johnson
---
pym/portage/checksum.py |4 +
pym/portage/util/whirlpool.py | 788 +
2 files changed, 792 insertions(+), 0 deletions(-)
create mode 100644 pym/portage/util/whirlpool.py
diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py
index 9e7e455..3d674c8 100644
--- a/pym/portage/checksum.py
+++ b/pym/portage/checksum.py
@@ -71,6 +71,10 @@ except ImportError:
sha1hash = _generate_hash_function("SHA1", _new_sha1, origin="internal")
+# Bundled WHIRLPOOL implementation
+from portage.util.whirlpool import new as _new_whirlpool
+whirlpoolhash = _generate_hash_function("WHIRLPOOL", _new_whirlpool,
origin="bundled")
+
# Use pycrypto when available, prefer it over the internal fallbacks
try:
from Crypto.Hash import SHA256, RIPEMD
diff --git a/pym/portage/util/whirlpool.py b/pym/portage/util/whirlpool.py
new file mode 100644
index 000..0193c39
--- /dev/null
+++ b/pym/portage/util/whirlpool.py
@@ -0,0 +1,788 @@
+## whirlpool.py - pure Python implementation of the Whirlpool algorithm.
+## Bjorn Edstrom 16 december 2007.
+##
+## Copyrights
+## ==
+##
+## This code is based on the reference implementation by
+## Paulo S.L.M. Barreto and Vincent Rijmen. The reference implementation
+## is placed in the public domain but has the following headers:
+##
+## * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
+## * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+## * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+## * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
+## * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+## * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+## * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+## * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+## * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+## * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+## * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+## *
+## */
+## /* The code contained in this file (Whirlpool.c) is in the public domain. */
+##
+## This Python implementation is therefore also placed in the public domain.
+
+#block_size = 64
+digest_size = 64
+digestsize = 64
+
+class Whirlpool:
+"""Return a new Whirlpool object. An optional string argument
+may be provided; if present, this string will be automatically
+hashed."""
+def __init__(self, arg=None):
+self.ctx = WhirlpoolStruct()
+if arg:
+self.update(arg)
+self.digest_status = 0
+
+def update(self, arg):
+"""update(arg)"""
+WhirlpoolAdd(arg, len(arg)*8, self.ctx)
+self.digest_status = 0
+
+def digest(self):
+"""digest()"""
+if self.digest_status == 0:
+self.dig = WhirlpoolFinalize(self.ctx)
+self.digest_status = 1
+return self.dig
+
+def hexdigest(self):
+"""hexdigest()"""
+dig = self.digest()
+tempstr = ''
+for d in dig:
+xxx = '%02x' % (ord(d))
+tempstr = tempstr + xxx
+return tempstr
+
+def copy(self):
+"""copy()"""
+import copy
+return copy.deepcopy(self)
+
+
+def new(init=None):
+"""Return a new Whirlpool object. An optional string argument
+may be provided; if present, this string will be automatically
+hashed."""
+return Whirlpool(init)
+
+#
+# Private.
+#
+
+R = 10
+
+C0 = [
+0x18186018c07830d8, 0x23238c2305af4626, 0xc6c63fc67ef991b8,
0xe8e887e8136fcdfb,
+0x878726874ca113cb, 0xb8b8dab8a9626d11, 0x0101040108050209,
0x4f4f214f426e9e0d,
+0x3636d836adee6c9b, 0xa6a6a2a6590451ff, 0xd2d26fd2debdb90c,
0xf5f5f3f5fb06f70e,
+0x7979f979ef80f296, 0x6f6fa16f5fcede30, 0x91917e91fcef3f6d,
0x52525552aa07a4f8,
+0x60609d6027fdc047, 0xbcbccabc89766535, 0x9b9b569baccd2b37,
0x8e8e028e048c018a,
+0xa3a3b6a371155bd2, 0x0c0c300c603c186c, 0x7b7bf17bff8af684,
0x3535d435b5e16a80,
+0x1d1d741de8693af5, 0xe0e0a7e05347ddb3, 0xd7d77bd7f6acb321,
0xc2c22fc25eed999c,
+0x2e2eb82e6d965c43, 0x4b4b314b627a9629, 0xfefedffea321e15d,
0x575741578216aed5,
+0x15155415a8412abd, 0xc1779fb6eee8, 0x3737dc37a5eb6e92,
0xe5e5b3e57b56d79e,
+0x9f9f469f8cd92313, 0xf0f0e7f0d317fd23, 0x4a4a354a6a7f9420,
0xdada4fda9e95a944,
+0x58587d58fa25b0a2, 0xc9c903c906ca8fcf, 0x2929a429558d527c,
0x0a0a280a5022145a,
+0xb1b1feb1e14f7f50, 0xa0a0baa0691a5dc9, 0x6b6bb16b7fdad614,
0x85852e855cab17d9,
+0xbdbdcebd8173673c, 0x5d5d695dd234ba8f, 0x1010401080502090,
0xf4f4f7f4f303f507,
+0xcbcb0bcb16c08bdd, 0x3e3ef83eedc67cd3, 0x0505140528110a2d,
0x676781671fe6ce78,
+0xe4e4b7e47353d597, 0x27279c2725bb4e02, 0x4141194132588273,
0x8b8b168b2c9d0ba7