Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split key-hash for signature generation into mandatory and optional groups #71

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 47 additions & 23 deletions tests/nxpcrypto/test_nxpcrypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,32 +401,13 @@ def get_key_path(data_dir: str, key_type: str):
return private, public


@pytest.mark.parametrize(
"key_type",
["secp256r1", "secp384r1", "secp521r1", "rsa2048", "rsa4096"],
)
@pytest.mark.parametrize(
"algorithm",
[
None,
EnumHashAlgorithm.SHA1,
EnumHashAlgorithm.SHA256,
EnumHashAlgorithm.SHA384,
EnumHashAlgorithm.SHA512,
EnumHashAlgorithm.MD5,
],
)
def test_nxpcrypto_create_signature_algorithm(
cli_runner: CliRunner,
data_dir: str,
tmpdir,
key_type: str,
algorithm: Optional[EnumHashAlgorithm],
):
def run_signature(
cli_runner: CliRunner, data_dir: str, tmpdir: str, key_type: str, algorithm: EnumHashAlgorithm
) -> None:
priv_key, pub_key = get_key_path(data_dir, key_type)

input_file = os.path.join(data_dir, "data_to_sign.bin")
output_file = os.path.join(tmpdir, "signature.bin")
output_file = os.path.join(tmpdir, f"signature_{key_type}_{algorithm}.bin")

cmd = f"signature create -k {priv_key} -i {input_file} -o {output_file}"
if algorithm:
Expand All @@ -443,6 +424,49 @@ def test_nxpcrypto_create_signature_algorithm(
assert pub.verify_signature(signature, load_binary(input_file), **extra_params)


@pytest.mark.parametrize(
"key_type, algorithms",
[
("secp256r1", [None, EnumHashAlgorithm.SHA256]),
("secp384r1", [None, EnumHashAlgorithm.SHA384]),
("secp521r1", [None, EnumHashAlgorithm.SHA512]),
("rsa2048", [None, EnumHashAlgorithm.SHA256]),
("rsa4096", [None, EnumHashAlgorithm.SHA256]),
],
)
def test_nxpcrypto_create_signature_algorithm_mandatory(
cli_runner: CliRunner,
data_dir: str,
tmpdir,
key_type: str,
algorithms: List[Optional[EnumHashAlgorithm]],
):
for algorithm in algorithms:
run_signature(cli_runner, data_dir, tmpdir, key_type, algorithm)


@pytest.mark.xfail(reason="Some Linux distributions allows only certain combinations of key-hash")
@pytest.mark.parametrize(
"key_type, algorithms",
[
("secp256r1", [EnumHashAlgorithm.SHA384, EnumHashAlgorithm.SHA512]),
("secp384r1", [EnumHashAlgorithm.SHA256, EnumHashAlgorithm.SHA512]),
("secp521r1", [EnumHashAlgorithm.SHA256, EnumHashAlgorithm.SHA384]),
("rsa2048", [EnumHashAlgorithm.SHA384, EnumHashAlgorithm.SHA512]),
("rsa4096", [EnumHashAlgorithm.SHA384, EnumHashAlgorithm.SHA512]),
],
)
def test_nxpcrypto_create_signature_algorithm_optional(
cli_runner: CliRunner,
data_dir: str,
tmpdir,
key_type: str,
algorithms: List[Optional[EnumHashAlgorithm]],
):
for algorithm in algorithms:
run_signature(cli_runner, data_dir, tmpdir, key_type, algorithm)


@pytest.mark.skipif(not IS_OSCCA_SUPPORTED, reason="OSCCA support is not installed")
def test_nxpcrypto_create_signature_algorithm_oscca(cli_runner: CliRunner, data_dir: str, tmpdir):
input_file = os.path.join(data_dir, "data_to_sign.bin")
Expand Down