17 """This script translates JSON test vectors to BoringSSL's "FileTest" format.
19 Usage: translate_test_vectors.py TEST_VECTORS_JSON_FILE
21 The TEST_VECTORS_JSON_FILE is expected to come from the JSON copy of
22 draft-irtf-cfrg-hpke-12's test vectors, linked from its [TestVectors] citation.
23 The output is written to "hpke_test_vectors.txt".
32 HPKE_DHKEM_X25519_SHA256 = 0x0020
33 HPKE_HKDF_SHA256 = 0x0001
34 HPKE_AEAD_EXPORT_ONLY = 0xffff
38 """Translates JSON test vectors into BoringSSL's FileTest language.
41 json_file_in_path: Path to the JSON test vectors file.
42 test_file_out_path: Path to output file.
46 with open(json_file_in_path)
as file_in:
47 test_vecs = json.load(file_in)
50 for test
in test_vecs:
52 if (test[
"mode"] != HPKE_MODE_BASE
or
53 test[
"kem_id"] != HPKE_DHKEM_X25519_SHA256
or
54 test[
"aead_id"] == HPKE_AEAD_EXPORT_ONLY
or
55 test[
"kdf_id"] != HPKE_HKDF_SHA256):
58 keys = [
"mode",
"kdf_id",
"aead_id",
"info",
"skRm",
"skEm",
"pkRm",
"pkEm"]
60 if test[
"mode"] == HPKE_MODE_PSK:
65 lines.append(
"{} = {}".
format(key,
str(test[key])))
67 for i, enc
in enumerate(test[
"encryptions"]):
68 lines.append(
"# encryptions[{}]".
format(i))
69 for key
in (
"aad",
"ct",
"pt"):
70 lines.append(
"{} = {}".
format(key,
str(enc[key])))
72 for i, exp
in enumerate(test[
"exports"]):
73 lines.append(
"# exports[{}]".
format(i))
74 for key
in (
"exporter_context",
"L",
"exported_value"):
75 lines.append(
"{} = {}".
format(key,
str(exp[key])))
79 with open(test_file_out_path,
"w")
as file_out:
80 file_out.write(
"\n".join(lines))
91 if __name__ ==
"__main__":