diff options
author | Fabian Jahr <fjahr@protonmail.com> | 2020-12-17 23:25:30 +0100 |
---|---|---|
committer | Fabian Jahr <fjahr@protonmail.com> | 2020-12-22 01:48:34 +0100 |
commit | 9815332d5158d69a94abeaf465a2c07bd8e43359 (patch) | |
tree | 129d161a4e5081f7a1a2e90da6912c5d1135b184 /test | |
parent | 01297fb3ca57e4b8cbc5a89fc7c6367de33b0bc6 (diff) | |
download | bitcoin-9815332d5158d69a94abeaf465a2c07bd8e43359.tar.xz |
test: Change MuHash Python implementation to match cpp version again
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/test_framework/muhash.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/test/functional/test_framework/muhash.py b/test/functional/test_framework/muhash.py index 97d02359cb..183548f71f 100644 --- a/test/functional/test_framework/muhash.py +++ b/test/functional/test_framework/muhash.py @@ -78,11 +78,13 @@ class MuHash3072: def insert(self, data): """Insert a byte array data in the set.""" - self.numerator = (self.numerator * data_to_num3072(data)) % self.MODULUS + data_hash = hashlib.sha256(data).digest() + self.numerator = (self.numerator * data_to_num3072(data_hash)) % self.MODULUS def remove(self, data): """Remove a byte array from the set.""" - self.denominator = (self.denominator * data_to_num3072(data)) % self.MODULUS + data_hash = hashlib.sha256(data).digest() + self.denominator = (self.denominator * data_to_num3072(data_hash)) % self.MODULUS def digest(self): """Extract the final hash. Does not modify this object.""" @@ -93,12 +95,12 @@ class MuHash3072: class TestFrameworkMuhash(unittest.TestCase): def test_muhash(self): muhash = MuHash3072() - muhash.insert([0]*32) - muhash.insert([1] + [0]*31) - muhash.remove([2] + [0]*31) + muhash.insert(b'\x00' * 32) + muhash.insert((b'\x01' + b'\x00' * 31)) + muhash.remove((b'\x02' + b'\x00' * 31)) finalized = muhash.digest() # This mirrors the result in the C++ MuHash3072 unit test - self.assertEqual(finalized[::-1].hex(), "a44e16d5e34d259b349af21c06e65d653915d2e208e4e03f389af750dc0bfdc3") + self.assertEqual(finalized[::-1].hex(), "10d312b100cbd32ada024a6646e40d3482fcff103668d2625f10002a607d5863") def test_chacha20(self): def chacha_check(key, result): |