f4jumble: Use BLAKE2b hashes for the long test vectors.

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
Daira Hopwood 2021-08-31 20:59:19 +01:00
parent fa1bd3773a
commit bdf4c9ff9b
1 changed files with 32 additions and 9 deletions

View File

@ -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<u8>'),
('jumbled', 'Vec<u8>'),
),
test_vectors,
plain_test_vectors,
)
print()
render_tv(
args,
'f4jumble',
(
('length', 'usize'),
('jumbled_hash', 'Vec<u8>'),
),
hashed_test_vectors,
)