From 227a553a9942d0168ab7611e5ce896eb1c837815 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Sat, 26 Aug 2017 07:25:33 +0200 Subject: [PATCH] update ripemd module for python3 --- lib/bitcoin.py | 5 ++--- lib/ripemd.py | 22 ++++++++-------------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/lib/bitcoin.py b/lib/bitcoin.py index 7f110a3f..701bd237 100644 --- a/lib/bitcoin.py +++ b/lib/bitcoin.py @@ -279,9 +279,8 @@ def hash_160(public_key): md = hashlib.new('ripemd160') md.update(sha256(public_key)) return md.digest() - except Exception: - # not available in Android SL4a - import ripemd + except BaseException: + from . import ripemd md = ripemd.new(sha256(public_key)) return md.digest() diff --git a/lib/ripemd.py b/lib/ripemd.py index cc7a38f9..92305d74 100644 --- a/lib/ripemd.py +++ b/lib/ripemd.py @@ -37,12 +37,6 @@ ## * ftp://ftp.rsasecurity.com/pub/cryptobytes/crypto3n2.pdf ## */ -try: - import psyco - psyco.full() -except ImportError: - pass - #block_size = 1 digest_size = 20 digestsize = 20 @@ -77,7 +71,7 @@ class RIPEMD160: dig = self.digest() hex_digest = '' for d in dig: - hex_digest += '%02x' % ord(d) + hex_digest += '%02x' % d return hex_digest def copy(self): @@ -155,7 +149,7 @@ import struct def RMD160Transform(state, block): #uint32 state[5], uchar block[64] x = [0]*16 if sys.byteorder == 'little': - x = struct.unpack('<16L', ''.join([chr(x) for x in block[0:64]])) + x = struct.unpack('<16L', bytes([x for x in block[0:64]])) else: raise "Error!!" a = state[0] @@ -362,13 +356,13 @@ def RMD160Update(ctx, inp, inplen): if type(inp) == str: inp = [ord(i)&0xff for i in inp] - have = (ctx.count / 8) % 64 + have = (ctx.count // 8) % 64 need = 64 - have ctx.count += 8 * inplen off = 0 if inplen >= need: if have: - for i in xrange(need): + for i in range(need): ctx.buffer[have+i] = inp[i] RMD160Transform(ctx.state, ctx.buffer) off = need @@ -378,12 +372,12 @@ def RMD160Update(ctx, inp, inplen): off += 64 if off < inplen: # memcpy(ctx->buffer + have, input+off, len-off); - for i in xrange(inplen - off): + for i in range(inplen - off): ctx.buffer[have+i] = inp[off+i] def RMD160Final(ctx): size = struct.pack("