MCPcopy Create free account
hub / github.com/ElementsProject/elements / ripemd160

Function ripemd160

test/functional/test_framework/ripemd160.py:95–109  ·  view source on GitHub ↗

Compute the RIPEMD-160 hash of data.

(data)

Source from the content-addressed store, hash-verified

93
94
95def ripemd160(data):
96 """Compute the RIPEMD-160 hash of data."""
97 # Initialize state.
98 state = (0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0)
99 # Process full 64-byte blocks in the input.
100 for b in range(len(data) >> 6):
101 state = compress(*state, data[64*b:64*(b+1)])
102 # Construct final blocks (with padding and size).
103 pad = b"\x80" + b"\x00" * ((119 - len(data)) & 63)
104 fin = data[len(data) & ~63:] + pad + (8 * len(data)).to_bytes(8, 'little')
105 # Process final blocks.
106 for b in range(len(fin) >> 6):
107 state = compress(*state, fin[64*b:64*(b+1)])
108 # Produce output.
109 return b"".join((h & 0xffffffff).to_bytes(4, 'little') for h in state)
110
111
112class TestFrameworkKey(unittest.TestCase):

Callers 2

hash160Function · 0.90
test_ripemd160Method · 0.85

Calls 2

compressFunction · 0.85
joinMethod · 0.45

Tested by 1

test_ripemd160Method · 0.68