From 57188ff877f2e518acac909bf728d633ac06fb2d Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Mon, 24 Jul 2023 11:45:11 +0200 Subject: [PATCH] Added some tests for HD ciphering. Signed-off-by: Pol Henarejos --- tests/pico-hsm/test_095_bip_slip.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/pico-hsm/test_095_bip_slip.py b/tests/pico-hsm/test_095_bip_slip.py index fd360a1..e5ae119 100644 --- a/tests/pico-hsm/test_095_bip_slip.py +++ b/tests/pico-hsm/test_095_bip_slip.py @@ -27,7 +27,7 @@ from cvc.certificates import CVC from cvc import oid from cryptography.hazmat.primitives.asymmetric import ec from cryptography.hazmat.primitives import hashes -from picohsm import DOPrefixes, APDUResponse, SWCodes, PicoHSM +from picohsm import EncryptionMode, APDUResponse, SWCodes, PicoHSM import hashlib TEST_STRING = b'Pico Keys are awesome!' @@ -438,4 +438,16 @@ def test_signature_slip(device, path): pub = device.hd_derive_node(path) with pytest.raises(APDUResponse) as e: resp = device.hd_signature(path, TEST_STRING) - assert (e.value.sw == SWCodes.SW_CONDITIONS_NOT_SATISFIED) \ No newline at end of file + assert (e.value.sw == SWCodes.SW_CONDITIONS_NOT_SATISFIED) + +@pytest.mark.parametrize( + "ask_on_encrypt", [True, False] +) +@pytest.mark.parametrize( + "ask_on_decrypt", [True, False] +) +def test_cipher_slip(device, ask_on_encrypt, ask_on_decrypt): + MSG1 = b"testing message!" + enctext = device.hd_cipher([7, b"\x01", b"\x02"], b"test", MSG1, EncryptionMode.ENCRYPT, ask_on_encrypt, ask_on_decrypt) + resp = device.hd_cipher([7, b"\x01", b"\x02"], b"test", enctext, EncryptionMode.DECRYPT, ask_on_encrypt, ask_on_decrypt) + assert(resp == MSG1)