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