From 9b999b7d2c155244cf58856780c0ec5c71a9559e Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Sat, 7 Aug 2021 11:53:34 +0300 Subject: [PATCH] remove old session key gen --- client/src/mifare/desfirecore.c | 11 ++++------- client/src/mifare/desfirecore.h | 1 - 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/client/src/mifare/desfirecore.c b/client/src/mifare/desfirecore.c index b1cf61b9c..af29df827 100644 --- a/client/src/mifare/desfirecore.c +++ b/client/src/mifare/desfirecore.c @@ -30,7 +30,6 @@ #include "iso7816/apduinfo.h" // APDU manipulation / errorcodes #include "iso7816/iso7816core.h" // APDU logging #include "util_posix.h" // msleep -#include "mifare/desfire_crypto.h" #include "desfiresecurechan.h" #include "mifare/mad.h" #include "mifare/aiddesfire.h" @@ -1174,11 +1173,6 @@ static int DesfireAuthenticateEV1(DesfireContext *dctx, DesfireSecureChannel sec // Part 4 memcpy(encRndA, recv_data, rndlen); - struct desfire_key sesskey = {0}; - - Desfire_session_key_new(RndA, RndB, key, &sesskey); - memcpy(dctx->sessionKeyEnc, sesskey.data, desfire_get_key_length(dctx->keyType)); - //PrintAndLogEx(INFO, "encRndA : %s", sprint_hex(encRndA, rndlen)); //PrintAndLogEx(INFO, "IV : %s", sprint_hex(IV, rndlen)); if (dctx->keyType == T_DES) { @@ -1200,6 +1194,9 @@ static int DesfireAuthenticateEV1(DesfireContext *dctx, DesfireSecureChannel sec mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_DECRYPT, rndlen, IV, encRndA, encRndA); } + // generate session key from rnda and rndb. before rol(RndA)! + DesfireGenSessionKeyEV1(RndA, RndB, dctx->keyType, dctx->sessionKeyEnc); + rol(RndA, rndlen); //PrintAndLogEx(INFO, "Expected_RndA : %s", sprint_hex(RndA, rndlen)); //PrintAndLogEx(INFO, "Generated_RndA : %s", sprint_hex(encRndA, rndlen)); @@ -1212,7 +1209,7 @@ static int DesfireAuthenticateEV1(DesfireContext *dctx, DesfireSecureChannel sec return 11; } } - + // If the 3Des key first 8 bytes = 2nd 8 Bytes then we are really using Singe Des // As such we need to set the session key such that the 2nd 8 bytes = 1st 8 Bytes if (dctx->keyType == T_3DES) { diff --git a/client/src/mifare/desfirecore.h b/client/src/mifare/desfirecore.h index a03e489eb..833c1f8b3 100644 --- a/client/src/mifare/desfirecore.h +++ b/client/src/mifare/desfirecore.h @@ -16,7 +16,6 @@ #include "common.h" #include "cliparser.h" #include "mifare/desfirecrypto.h" -#include "mifare/desfire_crypto.h" #include "mifare/mifare4.h" #define DESFIRE_TX_FRAME_MAX_LEN 54