@@ -78,11 +78,13 @@ def __init__(self):
7878
7979 def insert (self , data ):
8080 """Insert a byte array data in the set."""
81- self .numerator = (self .numerator * data_to_num3072 (data )) % self .MODULUS
81+ data_hash = hashlib .sha256 (data ).digest ()
82+ self .numerator = (self .numerator * data_to_num3072 (data_hash )) % self .MODULUS
8283
8384 def remove (self , data ):
8485 """Remove a byte array from the set."""
85- self .denominator = (self .denominator * data_to_num3072 (data )) % self .MODULUS
86+ data_hash = hashlib .sha256 (data ).digest ()
87+ self .denominator = (self .denominator * data_to_num3072 (data_hash )) % self .MODULUS
8688
8789 def digest (self ):
8890 """Extract the final hash. Does not modify this object."""
@@ -93,12 +95,12 @@ def digest(self):
9395class TestFrameworkMuhash (unittest .TestCase ):
9496 def test_muhash (self ):
9597 muhash = MuHash3072 ()
96- muhash .insert ([ 0 ] * 32 )
97- muhash .insert ([ 1 ] + [ 0 ] * 31 )
98- muhash .remove ([ 2 ] + [ 0 ] * 31 )
98+ muhash .insert (b' \x00 ' * 32 )
99+ muhash .insert (( b' \x01 ' + b' \x00 ' * 31 ) )
100+ muhash .remove (( b' \x02 ' + b' \x00 ' * 31 ) )
99101 finalized = muhash .digest ()
100102 # This mirrors the result in the C++ MuHash3072 unit test
101- self .assertEqual (finalized [::- 1 ].hex (), "a44e16d5e34d259b349af21c06e65d653915d2e208e4e03f389af750dc0bfdc3 " )
103+ self .assertEqual (finalized [::- 1 ].hex (), "10d312b100cbd32ada024a6646e40d3482fcff103668d2625f10002a607d5863 " )
102104
103105 def test_chacha20 (self ):
104106 def chacha_check (key , result ):
0 commit comments