diff --git a/f4jumble.py b/f4jumble.py index 8cf3983..342cabd 100644 --- a/f4jumble.py +++ b/f4jumble.py @@ -91,7 +91,9 @@ def main(): return bytes(ret) rand = Rand(randbytes) - test_vectors = [] + plain_test_vectors = [] + hashed_test_vectors = [] + # Generate test vectors with various lengths: for l_M in [ MIN_l_M, @@ -102,19 +104,30 @@ def main(): 3*l_H + 1, 257*l_H, 257*l_H + 1, - (rand.u32() % (MAX_l_M - MIN_l_M)) + MIN_l_M, - MAX_l_M, ]: M = rand.b(l_M) jumbled = f4jumble(M) assert len(jumbled) == len(M) assert f4jumble_inv(jumbled) == M - test_vectors.append(M) - test_vectors = [{ - 'normal': M, - 'jumbled': f4jumble(M), - } for M in test_vectors] + plain_test_vectors.append({ + 'normal': M, + 'jumbled': jumbled, + }) + + for l_M in [ + (rand.u32() % (MAX_l_M - MIN_l_M)) + MIN_l_M, + MAX_l_M, + ]: + M = bytes([i & 0xFF for i in range(l_M)]) + jumbled = f4jumble(M) + assert len(jumbled) == len(M) + assert f4jumble_inv(jumbled) == M + + hashed_test_vectors.append({ + 'length': l_M, + 'jumbled_hash': blake2b(jumbled).digest() + }) render_tv( args, @@ -123,7 +136,17 @@ def main(): ('normal', 'Vec'), ('jumbled', 'Vec'), ), - test_vectors, + plain_test_vectors, + ) + print() + render_tv( + args, + 'f4jumble', + ( + ('length', 'usize'), + ('jumbled_hash', 'Vec'), + ), + hashed_test_vectors, )