@@ -78,11 +78,13 @@ def __init__(self):
78
78
79
79
def insert (self , data ):
80
80
"""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
82
83
83
84
def remove (self , data ):
84
85
"""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
86
88
87
89
def digest (self ):
88
90
"""Extract the final hash. Does not modify this object."""
@@ -93,12 +95,12 @@ def digest(self):
93
95
class TestFrameworkMuhash (unittest .TestCase ):
94
96
def test_muhash (self ):
95
97
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 ) )
99
101
finalized = muhash .digest ()
100
102
# This mirrors the result in the C++ MuHash3072 unit test
101
- self .assertEqual (finalized [::- 1 ].hex (), "a44e16d5e34d259b349af21c06e65d653915d2e208e4e03f389af750dc0bfdc3 " )
103
+ self .assertEqual (finalized [::- 1 ].hex (), "10d312b100cbd32ada024a6646e40d3482fcff103668d2625f10002a607d5863 " )
102
104
103
105
def test_chacha20 (self ):
104
106
def chacha_check (key , result ):
0 commit comments