Added key unwrap support.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos 2022-03-04 23:30:56 +01:00
parent a29b01cdd8
commit 6cd575ea51
No known key found for this signature in database
GPG key ID: C0095B7870A4CCD3

View file

@ -1331,6 +1331,20 @@ static int cmd_key_wrap() {
return SW_OK();
}
static int cmd_key_unwrap() {
int key_id = P1(apdu);
if (P2(apdu) != 0x93)
return SW_WRONG_P1P2();
if (!isUserAuthenticated)
return SW_SECURITY_STATUS_NOT_SATISFIED();
file_t *ef = search_dynamic_file((KEY_PREFIX << 8) | key_id);
if (!ef)
ef = file_new((KEY_PREFIX << 8) | key_id);
flash_write_data_to_file(ef, apdu.cmd_apdu_data, apdu.cmd_apdu_data_len);
low_flash_available();
return SW_OK();
}
typedef struct cmd
{
uint8_t ins;
@ -1347,6 +1361,7 @@ typedef struct cmd
#define INS_LIST_KEYS 0x58
#define INS_SIGNATURE 0x68
#define INS_WRAP 0x72
#define INS_UNWRAP 0x74
#define INS_CHALLENGE 0x84
#define INS_SELECT_FILE 0xA4
#define INS_READ_BINARY 0xB0
@ -1371,6 +1386,7 @@ static const cmd_t cmds[] = {
{ INS_KEY_GEN, cmd_key_gen },
{ INS_SIGNATURE, cmd_signature },
{ INS_WRAP, cmd_key_wrap },
{ INS_UNWRAP, cmd_key_unwrap },
{ 0x00, 0x0}
};