-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathtvgen.py
More file actions
34 lines (28 loc) · 1.03 KB
/
tvgen.py
File metadata and controls
34 lines (28 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Copyright 2018 Google LLC
#
# Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.
import hexjson
import inputgen
def generate_testvectors(cipher):
for lengths in cipher.test_input_lengths():
print(lengths)
for tv, d in inputgen.generate_testinputs(lengths):
yield cipher.make_testvector(tv, d)
def write_tests(cipher, path):
d = path / cipher.name()
for v in cipher.variants():
cipher.variant = v
p = d / "{}.json".format(cipher.variant_name())
print(f"Writing: {p}")
hexjson.write_using_hex(p, generate_testvectors(cipher))
def check_testvector(cipher, tv, verbose):
cipher.check_testvector(tv)
if verbose:
print(f"OK: {tv['description']}")
def check_tests(cipher, path, verbose):
for fn in (path / cipher.name()).iterdir():
print(f"======== {fn.name} ========")
for tv in hexjson.iter_unhex(fn):
check_testvector(cipher, tv, verbose)