On some operating systems, Python doesn’t provide the expected ripemd160 implementation anymore, so the reference implementation fails to start. E.g. in Ubuntu 22.04:
0$ ./reference.py send_and_receive_test_vectors.json
1Simple send: two inputs
2Traceback (most recent call last):
3 File "/usr/lib/python3.10/hashlib.py", line 160, in __hash_new
4 return _hashlib.new(name, data, **kwargs)
5ValueError: [digital envelope routines] unsupported
6
7During handling of the above exception, another exception occurred:
8
9Traceback (most recent call last):
10 File "/home/thestack/bips/bip-0352/./reference.py", line 228, in <module>
11 pubkey = get_pubkey_from_input(vin)
12 File "/home/thestack/bips/bip-0352/./reference.py", line 46, in get_pubkey_from_input
13 pubkey_hash = hash160(pubkey_bytes)
14 File "/home/thestack/bips/bip-0352/bitcoin_utils.py", line 130, in hash160
15 return hashlib.new("ripemd160", hashlib.sha256(s).digest()).digest()
16 File "/usr/lib/python3.10/hashlib.py", line 166, in __hash_new
17 return __get_builtin_constructor(name)(data)
18 File "/usr/lib/python3.10/hashlib.py", line 123, in __get_builtin_constructor
19 raise ValueError('unsupported hash type ' + name)
20ValueError: unsupported hash type ripemd160
Fix this by providing a manual implementation, taken from the functional test framework of Bitcoin Core. See corresponding issue https://github.com/bitcoin/bitcoin/issues/23710 and PR https://github.com/bitcoin/bitcoin/pull/23716.