This commit is contained in:
merlokk 2021-08-21 00:05:04 +03:00
commit 09b4c3eed1
4 changed files with 5 additions and 5 deletions

View file

@ -5043,7 +5043,7 @@ static int CmdHF14ADesWriteData(const char *Cmd) {
uint8_t sessionkey[16] = {0};
uint8_t uid[7] = {0};
memcpy(uid, dctx.uid, MAX(dctx.uidlen, 7));
DesfireGenTransSessionKey(trkey, transactionCounter, uid, false, sessionkey);
DesfireGenTransSessionKeyEV2(trkey, transactionCounter, uid, false, sessionkey);
aes_decode(NULL, sessionkey, resp, resp, CRYPTO_AES_BLOCK_SIZE);
PrintAndLogEx(INFO, "Prev reader id [%zu]: %s", resplen, sprint_hex(resp, resplen));

View file

@ -649,7 +649,7 @@ int DesfireEV2CalcCMAC(DesfireContext *ctx, uint8_t cmd, uint8_t *data, size_t d
// https://www.nxp.com/docs/en/data-sheet/MF2DLHX0.pdf
// page 42
void DesfireGenTransSessionKey(uint8_t *key, uint32_t trCntr, uint8_t *uid, bool forMAC, uint8_t *sessionkey) {
void DesfireGenTransSessionKeyEV2(uint8_t *key, uint32_t trCntr, uint8_t *uid, bool forMAC, uint8_t *sessionkey) {
uint8_t xiv[CRYPTO_AES_BLOCK_SIZE] = {0};
if (forMAC) {

View file

@ -141,7 +141,7 @@ void DesfireGenSessionKeyEV1(const uint8_t rnda[], const uint8_t rndb[], Desfire
void DesfireGenSessionKeyEV2(uint8_t *key, uint8_t *rndA, uint8_t *rndB, bool enckey, uint8_t *sessionkey);
void DesfireEV2FillIV(DesfireContext *ctx, bool ivforcommand, uint8_t *iv);
int DesfireEV2CalcCMAC(DesfireContext *ctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *mac);
void DesfireGenTransSessionKey(uint8_t *key, uint32_t trCntr, uint8_t *uid, bool forMAC, uint8_t *sessionkey);
void DesfireGenTransSessionKeyEV2(uint8_t *key, uint32_t trCntr, uint8_t *uid, bool forMAC, uint8_t *sessionkey);
int DesfireLRPCalcCMAC(DesfireContext *ctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *mac);

View file

@ -462,11 +462,11 @@ static bool TestTransSessionKeys(void) {
uint32_t trCntr = 8;
uint8_t sessionkey[16] = {0};
DesfireGenTransSessionKey(key, trCntr, uid, true, sessionkey);
DesfireGenTransSessionKeyEV2(key, trCntr, uid, true, sessionkey);
uint8_t keymac[] = {0x7C, 0x1A, 0xD2, 0xD9, 0xC5, 0xC0, 0x81, 0x54, 0xA0, 0xA4, 0x91, 0x4B, 0x40, 0x1A, 0x65, 0x98};
res = res && (memcmp(sessionkey, keymac, sizeof(keymac)) == 0);
DesfireGenTransSessionKey(key, trCntr, uid, false, sessionkey);
DesfireGenTransSessionKeyEV2(key, trCntr, uid, false, sessionkey);
uint8_t keyenc[] = {0x11, 0x9B, 0x90, 0x2A, 0x07, 0xB1, 0x8A, 0x86, 0x5B, 0x8E, 0x1B, 0x00, 0x60, 0x59, 0x47, 0x84};
res = res && (memcmp(sessionkey, keyenc, sizeof(keyenc)) == 0);