fix some kdf parts

This commit is contained in:
merlokk 2021-08-08 23:48:07 +03:00
parent ccf31fef90
commit c4d35700a1
2 changed files with 15 additions and 9 deletions

View file

@ -1312,10 +1312,10 @@ int DesfireAuthenticate(DesfireContext *dctx, DesfireSecureChannel secureChannel
if (mfdes_kdf_input_gallagher(dctx->uid, dctx->uidlen, dctx->keyNum, dctx->selectedAID, dctx->kdfInput, &dctx->kdfInputLen) != PM3_SUCCESS) {
PrintAndLogEx(FAILED, "Could not generate Gallagher KDF input");
}
PrintAndLogEx(INFO, " KDF Input: " _YELLOW_("%s"), sprint_hex(dctx->kdfInput, dctx->kdfInputLen));
PrintAndLogEx(DEBUG, " KDF Input: " _YELLOW_("%s"), sprint_hex(dctx->kdfInput, dctx->kdfInputLen));
MifareKdfAn10922(dctx, DCOMasterKey, dctx->kdfInput, dctx->kdfInputLen);
PrintAndLogEx(INFO, " Derrived key: " _GREEN_("%s"), sprint_hex(dctx->key, desfire_get_key_block_length(dctx->keyType)));
PrintAndLogEx(DEBUG, " Derrived key: " _GREEN_("%s"), sprint_hex(dctx->key, desfire_get_key_block_length(dctx->keyType)));
}
if (dctx->cmdSet == DCCISO && secureChannel != DACEV2)
@ -2652,9 +2652,15 @@ int DesfireISOAppendRecord(DesfireContext *dctx, uint8_t fileid, uint8_t *data,
int DesfireGetCardUID(DesfireContext *ctx) {
iso14a_card_select_t card = {0};
int res = Hf14443_4aGetCardData(&card);
DropField();
if (res != PM3_SUCCESS) {
SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT, 0, 0, NULL, 0);
PacketResponseNG resp;
WaitForResponse(CMD_ACK, &resp);
memcpy(&card, (iso14a_card_select_t *)resp.data.asBytes, sizeof(iso14a_card_select_t));
uint64_t select_status = resp.oldarg[0];
if (select_status == 0 || select_status == 2 || select_status == 3) {
return PM3_ESOFT;
}

View file

@ -315,7 +315,7 @@ void DesfireCryptoCMACEx(DesfireContext *ctx, DesfireCryptoOpKeyType key_type, u
if (kbs == 0)
return;
uint8_t buffer[padded_data_length(len, kbs)];
uint8_t buffer[padded_data_length(MAX(minlen, len) + 1, kbs)];
memset(buffer, 0, sizeof(buffer));
uint8_t sk1[DESFIRE_MAX_CRYPTO_BLOCK_SIZE] = {0};
@ -360,9 +360,9 @@ void MifareKdfAn10922(DesfireContext *ctx, DesfireCryptoOpKeyType key_type, cons
kbs = CRYPTO_AES_BLOCK_SIZE;
buffer[0] = 0x01;
memcpy(&buffer[1], data, len++);
memcpy(&buffer[1], data, len);
DesfireCryptoCMACEx(ctx, key_type, buffer, len, kbs * 2, cmac);
DesfireCryptoCMACEx(ctx, key_type, buffer, len + 1, kbs * 2, cmac);
memcpy(ctx->key, cmac, kbs);
} else if (ctx->keyType == T_3DES) {
buffer[0] = 0x21;