mirror of
https://github.com/polhenarejos/pico-openpgp.git
synced 2026-08-27 07:05:07 +01:00
Require exact EC scalar lengths on import
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
+2
-1
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user