Require exact EC scalar lengths on import

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos
2026-08-14 22:18:23 +02:00
parent b48ae519cf
commit ef19c3e208
2 changed files with 12 additions and 1 deletions
+2 -1
View File
@@ -1502,7 +1502,8 @@ static int cmd_import_asym(void) {
else if (algo == PIV_ALGO_ECCP256 || algo == PIV_ALGO_ECCP384) {
tlv_ctx_t a6 = {0};
tlv_find_tag(&ctxi, 0x06, &a6);
if (tlv_len(&a6) <= 0) {
size_t scalar_size = algo == PIV_ALGO_ECCP256 ? 32 : 48;
if (tlv_len(&a6) != scalar_size) {
return SW_WRONG_DATA();
}
mbedtls_ecp_group_id gid = algo == PIV_ALGO_ECCP256 ? MBEDTLS_ECP_DP_SECP256R1 : MBEDTLS_ECP_DP_SECP384R1;
+10
View File
@@ -112,3 +112,13 @@ def test_piv_rsa_general_authenticate_accepts_another_rsa_algorithm_id(managed_p
assert response
finally:
delete_key(managed_piv, slot)
def test_piv_ec_import_requires_the_field_length(managed_piv):
slot = SLOT.RETIRED1
try:
for key_type in (KEY_TYPE.ECCP256, KEY_TYPE.ECCP384):
body = Tlv(0x06, b"\x01")
assert_apdu_error(lambda: managed_piv.protocol.send_apdu(0, 0xFE, key_type, slot, body), SW.WRONG_DATA)
finally:
delete_key(managed_piv, slot)