mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-24 07:18:09 +00:00
tests(crypto): update wycheproof testcase source and parsing
The JSON schema of the test cases has slightly changed. The "curve" field has moved to the "testGroups" level and the X25519 algorithm has been renamed, which requires adjustments in the parsing code. A duplicate definition of "ecdh_vectors" has also been removed.
This commit is contained in:
parent
176b12762f
commit
525bbab165
@ -387,22 +387,24 @@ def generate_curve25519_dh(filename):
|
|||||||
if not keys_in_dict(data, {"algorithm", "testGroups"}):
|
if not keys_in_dict(data, {"algorithm", "testGroups"}):
|
||||||
raise DataError()
|
raise DataError()
|
||||||
|
|
||||||
if data["algorithm"] != "X25519":
|
if data["algorithm"] != "XDH":
|
||||||
raise DataError()
|
raise DataError()
|
||||||
|
|
||||||
for test_group in data["testGroups"]:
|
for test_group in data["testGroups"]:
|
||||||
if not keys_in_dict(test_group, {"tests"}):
|
if not keys_in_dict(test_group, {"tests", "curve"}):
|
||||||
|
raise DataError()
|
||||||
|
|
||||||
|
try:
|
||||||
|
curve_name = parse_curve_name(test_group["curve"])
|
||||||
|
except Exception:
|
||||||
raise DataError()
|
raise DataError()
|
||||||
|
|
||||||
for test in test_group["tests"]:
|
for test in test_group["tests"]:
|
||||||
if not keys_in_dict(
|
if not keys_in_dict(test, {"public", "private", "shared", "result"}):
|
||||||
test, {"public", "private", "shared", "result", "curve"}
|
|
||||||
):
|
|
||||||
raise DataError()
|
raise DataError()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
public_key = unhexlify(test["public"])
|
public_key = unhexlify(test["public"])
|
||||||
curve_name = parse_curve_name(test["curve"])
|
|
||||||
private_key = unhexlify(test["private"])
|
private_key = unhexlify(test["private"])
|
||||||
shared = unhexlify(test["shared"])
|
shared = unhexlify(test["shared"])
|
||||||
result = parse_result(test["result"])
|
result = parse_result(test["result"])
|
||||||
@ -433,18 +435,20 @@ def generate_ecdh(filename):
|
|||||||
raise DataError()
|
raise DataError()
|
||||||
|
|
||||||
for test_group in data["testGroups"]:
|
for test_group in data["testGroups"]:
|
||||||
if not keys_in_dict(test_group, {"tests"}):
|
if not keys_in_dict(test_group, {"tests", "curve"}):
|
||||||
|
raise DataError()
|
||||||
|
|
||||||
|
try:
|
||||||
|
curve_name = parse_curve_name(test_group["curve"])
|
||||||
|
except Exception:
|
||||||
raise DataError()
|
raise DataError()
|
||||||
|
|
||||||
for test in test_group["tests"]:
|
for test in test_group["tests"]:
|
||||||
if not keys_in_dict(
|
if not keys_in_dict(test, {"public", "private", "shared", "result"}):
|
||||||
test, {"public", "private", "shared", "result", "curve"}
|
|
||||||
):
|
|
||||||
raise DataError()
|
raise DataError()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
public_key = unhexlify(test["public"])
|
public_key = unhexlify(test["public"])
|
||||||
curve_name = parse_curve_name(test["curve"])
|
|
||||||
private_key = parse_signed_hex(test["private"])
|
private_key = parse_signed_hex(test["private"])
|
||||||
shared = unhexlify(test["shared"])
|
shared = unhexlify(test["shared"])
|
||||||
result = parse_result(test["result"])
|
result = parse_result(test["result"])
|
||||||
@ -604,7 +608,6 @@ if not lib.zkp_context_is_initialized():
|
|||||||
testvectors_directory = os.path.join(dir, "wycheproof/testvectors")
|
testvectors_directory = os.path.join(dir, "wycheproof/testvectors")
|
||||||
context_structure_length = 1024
|
context_structure_length = 1024
|
||||||
|
|
||||||
ecdh_vectors = generate_ecdh("ecdh_test.json")
|
|
||||||
curve25519_dh_vectors = generate_curve25519_dh("x25519_test.json")
|
curve25519_dh_vectors = generate_curve25519_dh("x25519_test.json")
|
||||||
eddsa_vectors = generate_eddsa("eddsa_test.json")
|
eddsa_vectors = generate_eddsa("eddsa_test.json")
|
||||||
ecdsa_vectors = (
|
ecdsa_vectors = (
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 2904be69e9d666bf3064fdc15093747e695cfae6
|
Subproject commit 2196000605e45d91097147c9c71f26b72af58003
|
Loading…
Reference in New Issue
Block a user