Added some tests for HD ciphering.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos 2023-07-24 11:45:11 +02:00
parent f631e4a5f3
commit 57188ff877
No known key found for this signature in database
GPG Key ID: C0095B7870A4CCD3

View File

@ -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)
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)