[go: up one dir, main page]

Skip to content

Commit

Permalink
idprime: implement get_challenge and flag RNG support
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrd2 committed May 18, 2021
1 parent da6795b commit b5dfd15
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/libopensc/card-idprime.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,8 @@ static int idprime_init(sc_card_t *card)

card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;

card->caps |= SC_CARD_CAP_RNG;

LOG_FUNC_RETURN(card->ctx, 0);
}

Expand Down Expand Up @@ -1007,6 +1009,38 @@ idprime_decipher(struct sc_card *card,
LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
}

static int
idprime_get_challenge(struct sc_card *card, u8 *rnd, size_t len)
{
u8 rbuf[16];
size_t out_len;
struct sc_apdu apdu;
int r;

LOG_FUNC_CALLED(card->ctx);

if (len <= 8) {
/* official closed driver always calls this regardless the length */
sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0x84, 0x00, 0x01);
apdu.le = apdu.resplen = 8;
} else {
/* this was discovered accidentally - all 16 bytes seem random */
sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0x84, 0x00, 0x00);
apdu.le = apdu.resplen = 16;
}
apdu.resp = rbuf;

r = sc_transmit_apdu(card, &apdu);
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");

r = sc_check_sw(card, apdu.sw1, apdu.sw2);
LOG_TEST_RET(card->ctx, r, "GET CHALLENGE failed");

out_len = len < apdu.resplen ? len : apdu.resplen;
memcpy(rnd, rbuf, out_len);

LOG_FUNC_RETURN(card->ctx, (int) out_len);
}

static struct sc_card_driver * sc_get_driver(void)
{
Expand All @@ -1026,6 +1060,8 @@ static struct sc_card_driver * sc_get_driver(void)
idprime_ops.compute_signature = idprime_compute_signature;
idprime_ops.decipher = idprime_decipher;

idprime_ops.get_challenge = idprime_get_challenge;

return &idprime_drv;
}

Expand Down

0 comments on commit b5dfd15

Please sign in to comment.