Replace all hashlib ripemd160 functions.

This commit is contained in:
tecnovert 2023-12-16 09:29:48 +02:00
parent 08f0156b75
commit 0a9db22828
No known key found for this signature in database
GPG key ID: 8ED6D8750C4E3F93
11 changed files with 31 additions and 23 deletions

View file

@ -1,3 +1,3 @@
name = "basicswap"
__version__ = "0.12.1"
__version__ = "0.12.2"

View file

@ -83,9 +83,6 @@ def set_regtest() -> None:
def sha256(s):
return hashlib.new('sha256', s).digest()
def ripemd160(s):
return hashlib.new('ripemd160', s).digest()
def hash256(s):
return sha256(sha256(s))

View file

@ -37,10 +37,6 @@ MAX_SCRIPT_OPCODES = 201
OPCODE_NAMES = {}
def hash160(s):
return hashlib.new('ripemd160', sha256(s)).digest()
_opcode_instances = []
class CScriptOp(int):
"""A single script opcode"""

View file

@ -68,9 +68,6 @@ mininode_lock = RLock()
def sha256(s):
return hashlib.new('sha256', s).digest()
def ripemd160(s):
return hashlib.new('ripemd160', s).digest()
def hash256(s):
return sha256(sha256(s))

View file

@ -37,10 +37,6 @@ MAX_SCRIPT_OPCODES = 201
OPCODE_NAMES = {}
def hash160(s):
return hashlib.new('ripemd160', sha256(s)).digest()
_opcode_instances = []
class CScriptOp(int):
"""A single script opcode"""

View file

@ -51,9 +51,6 @@ MSG_TYPE_MASK = 0xffffffff >> 2
def sha256(s):
return hashlib.new('sha256', s).digest()
def ripemd160(s):
return hashlib.new('ripemd160', s).digest()
def hash256(s):
return sha256(sha256(s))

View file

@ -13,6 +13,7 @@ from basicswap.util import (
i2b,
ensure,
)
from basicswap.util.crypto import hash160
from basicswap.util.address import decodeAddress
from basicswap.chainparams import Coins
from basicswap.interface.contrib.firo_test_framework.script import (
@ -22,7 +23,6 @@ from basicswap.interface.contrib.firo_test_framework.script import (
OP_HASH160,
OP_CHECKSIG,
OP_EQUALVERIFY,
hash160,
)
from basicswap.interface.contrib.firo_test_framework.mininode import (
CBlock,

View file

@ -25,6 +25,7 @@ from basicswap.interface.contrib.nav_test_framework.mininode import (
FromHex,
uint256_from_str,
)
from basicswap.util.crypto import hash160
from basicswap.util.address import (
decodeWif,
pubkeyToAddress,
@ -39,7 +40,6 @@ from basicswap.basicswap_util import (
)
from basicswap.interface.contrib.nav_test_framework.script import (
hash160,
CScript,
OP_0,
OP_EQUAL,

View file

@ -1,13 +1,23 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2022 tecnovert
# Copyright (c) 2022-2023 tecnovert
# Distributed under the MIT software license, see the accompanying
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
from Crypto.Hash import RIPEMD160 # pycryptodome
from Crypto.Hash import RIPEMD160, SHA256 # pycryptodome
def sha256(data):
h = SHA256.new()
h.update(data)
return h.digest()
def ripemd160(data):
h = RIPEMD160.new()
h.update(data)
return h.digest()
def hash160(s):
return ripemd160(sha256(s))

View file

@ -1,3 +1,11 @@
0.12.2
==============
- Updated coincurve and libsecp256k1 versions.
- Avoids needing secp256k1_generator_const_g as it's not accessible from a dll.
- Fix missing ripemd160 on some systems.
0.12.1
==============

View file

@ -22,7 +22,7 @@ from coincurve.keys import (
PrivateKey)
from basicswap.util import i2b, h2b
from basicswap.util.crypto import ripemd160
from basicswap.util.crypto import ripemd160, hash160
from basicswap.util.rfc2440 import rfc2440_hash_password
from basicswap.interface.btc import BTCInterface
from basicswap.interface.xmr import XMRInterface
@ -40,6 +40,7 @@ from basicswap.messages_pb2 import (
BidMessage,
BidMessage_v1Deprecated,
)
from basicswap.contrib.test_framework.script import hash160 as hash160_btc
class Test(unittest.TestCase):
@ -317,6 +318,12 @@ class Test(unittest.TestCase):
input_data = b'hash this'
assert (ripemd160(input_data).hex() == 'd5443a154f167e2c1332f6de72cfb4c6ab9c8c17')
def test_hash160(self):
# hash160 is RIPEMD(SHA256(data))
input_data = b'hash this'
assert (hash160(input_data).hex() == '072985b3583a4a71f548494a5e1d5f6b00d0fe13')
assert (hash160_btc(input_data).hex() == '072985b3583a4a71f548494a5e1d5f6b00d0fe13')
def test_protobuf(self):
# Ensure old protobuf templates can be read