make style
This commit is contained in:
1 parent
d490485920
commit
ab249d0d76
10 files changed
+141
-128
No files matched your search
@@ -427,7 +427,7 @@ int ASKDemod_ext(int clk, int invert, int maxErr, size_t maxlen, bool amplify, b
|
||||
if (start_idx >= clk / 2) {
|
||||
start_idx -= clk / 2;
|
||||
}
|
||||
if ( askType == 0 ) { // if not Manchester, clock width is halved
|
||||
if (askType == 0) { // if not Manchester, clock width is halved
|
||||
clk /= 2;
|
||||
}
|
||||
if (errCnt < 0 || bitlen < 16) { //if fatal error (or -1)
|
||||
|
||||
+15
-15
@@ -3069,7 +3069,7 @@ static int CmdHF14ADesSelectApp(const char *Cmd) {
|
||||
CLIParserFree(ctx);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
uint8_t dfname[32] = {0};
|
||||
int dfnamelen = 16;
|
||||
CLIGetStrWithReturn(ctx, 12, dfname, &dfnamelen);
|
||||
@@ -3092,22 +3092,22 @@ static int CmdHF14ADesSelectApp(const char *Cmd) {
|
||||
|
||||
if (resplen > 0)
|
||||
PrintAndLogEx(FAILED, "Application " _CYAN_("FCI template") " [%zu]%s", resplen, sprint_hex(resp, resplen));
|
||||
|
||||
|
||||
if (dfnamelen > 0)
|
||||
PrintAndLogEx(SUCCESS, "Application `%s` selected " _GREEN_("succesfully"), (char *)dfname);
|
||||
else
|
||||
PrintAndLogEx(SUCCESS, "PICC MF selected " _GREEN_("succesfully"));
|
||||
} else {
|
||||
} else {
|
||||
res = DesfireSelectAndAuthenticateEx(&dctx, securechann, appid, true, verbose);
|
||||
if (res != PM3_SUCCESS) {
|
||||
DropField();
|
||||
PrintAndLogEx(FAILED, "Select application 0x%06x " _RED_("failed") " ", appid);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
PrintAndLogEx(SUCCESS, "Application 0x%06x selected " _GREEN_("succesfully") " ", appid);
|
||||
}
|
||||
|
||||
|
||||
DropField();
|
||||
return res;
|
||||
}
|
||||
@@ -3146,9 +3146,9 @@ static int CmdHF14ADesBruteApps(const char *Cmd) {
|
||||
CLIGetHexWithReturn(ctx, 2, endAid, &endLen);
|
||||
uint32_t idIncrement = arg_get_int_def(ctx, 3, 1);
|
||||
bool mad = arg_get_lit(ctx, 4);
|
||||
|
||||
|
||||
CLIParserFree(ctx);
|
||||
|
||||
|
||||
// tru select PICC
|
||||
res = DesfireSelectAIDHex(&dctx, 0x000000, false, 0);
|
||||
if (res != PM3_SUCCESS) {
|
||||
@@ -3156,7 +3156,7 @@ static int CmdHF14ADesBruteApps(const char *Cmd) {
|
||||
PrintAndLogEx(FAILED, "Desfire PICC level select " _RED_("failed") ". Maybe wrong card or no card in the field.");
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
// TODO: We need to check the tag version, EV1 should stop after 26 apps are found
|
||||
if (mad) {
|
||||
idIncrement = 0x10;
|
||||
@@ -3174,18 +3174,18 @@ static int CmdHF14ADesBruteApps(const char *Cmd) {
|
||||
PrintAndLogEx(INFO, "Enumerating through all AIDs manually, this will take a while!");
|
||||
for (uint32_t id = idStart; id <= idEnd && id >= idStart; id += idIncrement) {
|
||||
if (kbd_enter_pressed()) break;
|
||||
|
||||
|
||||
int progress = ((id - idStart) * 100) / ((idEnd - idStart));
|
||||
PrintAndLogEx(INPLACE, "Progress: %d %%, current AID: %06X", progress, id);
|
||||
|
||||
|
||||
res = DesfireSelectAIDHexNoFieldOn(&dctx, id);
|
||||
|
||||
|
||||
if (res == PM3_SUCCESS) {
|
||||
printf("\33[2K\r"); // clear current line before printing
|
||||
PrintAndLogEx(SUCCESS, "Got new APPID %06X", id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(SUCCESS, _GREEN_("Done"));
|
||||
DropField();
|
||||
@@ -3250,7 +3250,7 @@ static int CmdHF14ADesAuth(const char *Cmd) {
|
||||
PrintAndLogEx(FAILED, "Select or authentication 0x%06x " _RED_("failed") ". Result [%d] %s", appid, res, DesfireAuthErrorToStr(res));
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
if (appid == 0x000000)
|
||||
PrintAndLogEx(SUCCESS, "PICC selected and authenticated " _GREEN_("succesfully"));
|
||||
else
|
||||
@@ -3258,7 +3258,7 @@ static int CmdHF14ADesAuth(const char *Cmd) {
|
||||
|
||||
PrintAndLogEx(SUCCESS, _CYAN_("Context: "));
|
||||
DesfirePrintContext(&dctx);
|
||||
|
||||
|
||||
if (save) {
|
||||
defaultKeyNum = dctx.keyNum;
|
||||
defaultAlgoId = dctx.keyType;
|
||||
@@ -3269,7 +3269,7 @@ static int CmdHF14ADesAuth(const char *Cmd) {
|
||||
defaultSecureChannel = securechann;
|
||||
defaultCommSet = dctx.cmdSet;
|
||||
defaultCommMode = dctx.commMode;
|
||||
|
||||
|
||||
PrintAndLogEx(SUCCESS, "Context saved to defaults " _GREEN_("succesfully") ". You can check them by command " _YELLOW_("hf mfdes default"));
|
||||
}
|
||||
|
||||
|
||||
@@ -673,10 +673,10 @@ static int DesfireExchangeISONative(bool activate_field, DesfireContext *ctx, ui
|
||||
static int DesfireExchangeISO(bool activate_field, DesfireContext *ctx, sAPDU apdu, uint16_t le, uint8_t *resp, size_t *resplen, uint16_t *sw) {
|
||||
uint32_t rlen = 0;
|
||||
int res = DESFIRESendApduEx(activate_field, apdu, le, resp, 255, &rlen, sw);
|
||||
|
||||
|
||||
if (res == PM3_SUCCESS)
|
||||
*resplen = rlen;
|
||||
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -775,10 +775,10 @@ int DesfireSelectAID(DesfireContext *ctx, uint8_t *aid1, uint8_t *aid2) {
|
||||
|
||||
DesfireClearSession(ctx);
|
||||
ctx->appSelected = (aid1[0] != 0x00 || aid1[1] != 0x00 || aid1[2] != 0x00);
|
||||
|
||||
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -817,7 +817,7 @@ int DesfireSelectAIDHexNoFieldOn(DesfireContext *ctx, uint32_t aid) {
|
||||
int DesfireSelectAndAuthenticateEx(DesfireContext *dctx, DesfireSecureChannel secureChannel, uint32_t aid, bool noauth, bool verbose) {
|
||||
if (verbose)
|
||||
DesfirePrintContext(dctx);
|
||||
|
||||
|
||||
bool isosw = false;
|
||||
if (dctx->cmdSet == DCCISO) {
|
||||
dctx->cmdSet = DCCNativeISO;
|
||||
@@ -833,7 +833,7 @@ int DesfireSelectAndAuthenticateEx(DesfireContext *dctx, DesfireSecureChannel se
|
||||
}
|
||||
if (verbose)
|
||||
PrintAndLogEx(INFO, "App %06x " _GREEN_("selected"), aid);
|
||||
|
||||
|
||||
if (isosw)
|
||||
dctx->cmdSet = DCCISO;
|
||||
|
||||
@@ -1154,7 +1154,7 @@ static int DesfireAuthenticateEV2(DesfireContext *dctx, DesfireSecureChannel sec
|
||||
uint8_t RndB[CRYPTO_AES_BLOCK_SIZE] = {0};
|
||||
uint8_t encRndB[CRYPTO_AES_BLOCK_SIZE] = {0};
|
||||
uint8_t rotRndB[CRYPTO_AES_BLOCK_SIZE] = {0}; //RndB'
|
||||
uint8_t both[CRYPTO_AES_BLOCK_SIZE * 2 + 1] = {0}; // ek/dk_keyNo(RndA+RndB')
|
||||
uint8_t both[CRYPTO_AES_BLOCK_SIZE * 2 + 1] = {0}; // ek/dk_keyNo(RndA+RndB')
|
||||
|
||||
uint8_t subcommand = firstauth ? MFDES_AUTHENTICATE_EV2F : MFDES_AUTHENTICATE_EV2NF;
|
||||
uint8_t *key = dctx->key;
|
||||
@@ -1162,7 +1162,7 @@ static int DesfireAuthenticateEV2(DesfireContext *dctx, DesfireSecureChannel sec
|
||||
size_t recv_len = 0;
|
||||
uint8_t respcode = 0;
|
||||
uint8_t recv_data[256] = {0};
|
||||
|
||||
|
||||
if (verbose)
|
||||
PrintAndLogEx(INFO, _CYAN_("Auth %s:") " cmd: 0x%02x keynum: 0x%02x key: %s", (firstauth) ? "first" : "non-first", subcommand, dctx->keyNum, sprint_hex(key, 16));
|
||||
|
||||
@@ -1191,7 +1191,7 @@ static int DesfireAuthenticateEV2(DesfireContext *dctx, DesfireSecureChannel sec
|
||||
// Part 3
|
||||
if (aes_decode(IV, key, encRndB, RndB, CRYPTO_AES_BLOCK_SIZE))
|
||||
return 5;
|
||||
|
||||
|
||||
if (g_debugMode > 1) {
|
||||
PrintAndLogEx(DEBUG, "encRndB: %s", sprint_hex(encRndB, CRYPTO_AES_BLOCK_SIZE));
|
||||
PrintAndLogEx(DEBUG, "RndB: %s", sprint_hex(RndB, CRYPTO_AES_BLOCK_SIZE));
|
||||
@@ -1211,7 +1211,7 @@ static int DesfireAuthenticateEV2(DesfireContext *dctx, DesfireSecureChannel sec
|
||||
PrintAndLogEx(DEBUG, "rotRndB: %s", sprint_hex(rotRndB, CRYPTO_AES_BLOCK_SIZE));
|
||||
PrintAndLogEx(DEBUG, "Both: %s", sprint_hex(tmp, CRYPTO_AES_BLOCK_SIZE * 2));
|
||||
}
|
||||
|
||||
|
||||
if (aes_encode(IV, key, tmp, both, CRYPTO_AES_BLOCK_SIZE * 2))
|
||||
return 6;
|
||||
if (g_debugMode > 1) {
|
||||
@@ -1232,7 +1232,7 @@ static int DesfireAuthenticateEV2(DesfireContext *dctx, DesfireSecureChannel sec
|
||||
}
|
||||
|
||||
// Part 4
|
||||
memcpy(encRndA, recv_data, CRYPTO_AES_BLOCK_SIZE);
|
||||
memcpy(encRndA, recv_data, CRYPTO_AES_BLOCK_SIZE);
|
||||
|
||||
uint8_t data[32] = {0};
|
||||
|
||||
@@ -1249,7 +1249,7 @@ static int DesfireAuthenticateEV2(DesfireContext *dctx, DesfireSecureChannel sec
|
||||
}
|
||||
return 11;
|
||||
}
|
||||
|
||||
|
||||
if (firstauth) {
|
||||
dctx->cmdCntr = 0;
|
||||
memcpy(dctx->TI, data, 4);
|
||||
@@ -1270,38 +1270,38 @@ static int DesfireAuthenticateEV2(DesfireContext *dctx, DesfireSecureChannel sec
|
||||
PrintAndLogEx(INFO, "session key ENC: %s", sprint_hex(dctx->sessionKeyEnc, 16));
|
||||
PrintAndLogEx(INFO, "session key MAC: %s", sprint_hex(dctx->sessionKeyMAC, 16));
|
||||
}
|
||||
|
||||
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
static int DesfireAuthenticateISO(DesfireContext *dctx, DesfireSecureChannel secureChannel, bool verbose) {
|
||||
uint8_t rndlen = DesfireGetRndLenForKey(dctx->keyType);
|
||||
|
||||
|
||||
uint8_t hostrnd[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16};
|
||||
uint8_t hostrnd2[] = {0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x09, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01};
|
||||
|
||||
|
||||
uint8_t piccrnd[64];
|
||||
size_t xlen = 0;
|
||||
int res = DesfireISOGetChallenge(dctx, dctx->keyType, piccrnd, &xlen);
|
||||
if (res != PM3_SUCCESS)
|
||||
return 301;
|
||||
|
||||
|
||||
if (xlen != rndlen)
|
||||
return 302;
|
||||
|
||||
|
||||
uint8_t both[32] = {0};
|
||||
memcpy(both, hostrnd, rndlen);
|
||||
memcpy(&both[rndlen], piccrnd, rndlen);
|
||||
|
||||
|
||||
// encode
|
||||
DesfireClearIV(dctx);
|
||||
DesfireCryptoEncDec(dctx, false, both, rndlen * 2, both, true); // error 303
|
||||
|
||||
|
||||
// external authenticate
|
||||
res = DesfireISOExternalAuth(dctx, dctx->appSelected, dctx->keyNum, dctx->keyType, both);
|
||||
if (res != PM3_SUCCESS)
|
||||
return 304;
|
||||
|
||||
|
||||
// internal authenticate
|
||||
uint8_t rnddata[64] = {0};
|
||||
xlen = 0;
|
||||
@@ -1311,36 +1311,36 @@ static int DesfireAuthenticateISO(DesfireContext *dctx, DesfireSecureChannel sec
|
||||
|
||||
if (xlen != rndlen * 2)
|
||||
return 306;
|
||||
|
||||
|
||||
// decode rnddata
|
||||
uint8_t piccrnd2[64] = {0};
|
||||
DesfireCryptoEncDec(dctx, false, rnddata, rndlen * 2, piccrnd2, false); // error 307
|
||||
|
||||
|
||||
// check
|
||||
if (memcmp(hostrnd2, &piccrnd2[rndlen], rndlen) != 0)
|
||||
return 308;
|
||||
|
||||
|
||||
DesfireGenSessionKeyEV1(hostrnd, piccrnd2, dctx->keyType, dctx->sessionKeyEnc);
|
||||
DesfireClearIV(dctx);
|
||||
memcpy(dctx->sessionKeyMAC, dctx->sessionKeyEnc, desfire_get_key_length(dctx->keyType));
|
||||
dctx->secureChannel = secureChannel;
|
||||
|
||||
|
||||
if (verbose)
|
||||
PrintAndLogEx(INFO, "session key: %s", sprint_hex(dctx->sessionKeyEnc, desfire_get_key_length(dctx->keyType)));
|
||||
|
||||
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
int DesfireAuthenticate(DesfireContext *dctx, DesfireSecureChannel secureChannel, bool verbose) {
|
||||
if (dctx->cmdSet == DCCISO && secureChannel != DACEV2)
|
||||
return DesfireAuthenticateISO(dctx, secureChannel, verbose);
|
||||
|
||||
|
||||
if (secureChannel == DACd40 || secureChannel == DACEV1)
|
||||
return DesfireAuthenticateEV1(dctx, secureChannel, verbose);
|
||||
|
||||
if (secureChannel == DACEV2)
|
||||
return DesfireAuthenticateEV2(dctx, secureChannel, (DesfireIsAuthenticated(dctx) == false), verbose); // non first auth if there is a working secure channel
|
||||
|
||||
|
||||
return 100;
|
||||
}
|
||||
|
||||
@@ -2227,15 +2227,15 @@ int DesfireISOSelect(DesfireContext *dctx, DesfireISOSelectControl cntr, uint8_t
|
||||
int res = DesfireExchangeISO(true, dctx, (sAPDU) {0x00, ISO7816_SELECT_FILE, cntr, ((resp == NULL) ? 0x0C : 0x00), datalen, data}, APDU_INCLUDE_LE_00, xresp, &xresplen, &sw);
|
||||
if (res == PM3_SUCCESS && sw != 0x9000)
|
||||
return PM3_ESOFT;
|
||||
|
||||
|
||||
if (resp != NULL && resplen != NULL) {
|
||||
*resplen = xresplen;
|
||||
memcpy(resp, xresp, xresplen);
|
||||
}
|
||||
|
||||
|
||||
DesfireClearSession(dctx);
|
||||
dctx->appSelected = !( (cntr == ISSMFDFEF && datalen == 0) || (cntr == ISSEFByFileID && datalen == 2 && data[0] == 0 && data[1] == 0) );
|
||||
|
||||
dctx->appSelected = !((cntr == ISSMFDFEF && datalen == 0) || (cntr == ISSEFByFileID && datalen == 2 && data[0] == 0 && data[1] == 0));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -2248,22 +2248,22 @@ int DesfireISOGetChallenge(DesfireContext *dctx, DesfireCryptoAlgorythm keytype,
|
||||
int res = DesfireExchangeISO(false, dctx, (sAPDU) {0x00, ISO7816_GET_CHALLENGE, 0x00, 0x00, 0x00, NULL}, DesfireGetRndLenForKey(keytype), resp, resplen, &sw);
|
||||
if (res == PM3_SUCCESS && sw != 0x9000)
|
||||
return PM3_ESOFT;
|
||||
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int DesfireISOExternalAuth(DesfireContext *dctx, bool app_level, uint8_t keynum, DesfireCryptoAlgorythm keytype, uint8_t *data) {
|
||||
uint8_t p1 = DesfireKeyToISOKey(keytype);
|
||||
uint8_t p2 = ((app_level) ? 0x80 : 0x00) | keynum;
|
||||
|
||||
|
||||
uint8_t resp[250] = {0};
|
||||
size_t resplen = 0;
|
||||
|
||||
|
||||
uint16_t sw = 0;
|
||||
int res = DesfireExchangeISO(false, dctx, (sAPDU) {0x00, ISO7816_EXTERNAL_AUTHENTICATION, p1, p2, DesfireGetRndLenForKey(keytype) * 2, data}, 0, resp, &resplen, &sw);
|
||||
if (res == PM3_SUCCESS && sw != 0x9000)
|
||||
return PM3_ESOFT;
|
||||
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -2276,7 +2276,7 @@ int DesfireISOInternalAuth(DesfireContext *dctx, bool app_level, uint8_t keynum,
|
||||
int res = DesfireExchangeISO(false, dctx, (sAPDU) {0x00, ISO7816_INTERNAL_AUTHENTICATION, p1, p2, keylen, data}, keylen * 2, resp, resplen, &sw);
|
||||
if (res == PM3_SUCCESS && sw != 0x9000)
|
||||
return PM3_ESOFT;
|
||||
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -23,9 +23,9 @@
|
||||
|
||||
enum DesfireISOSelectControlEnum {
|
||||
ISSMFDFEF = 0x00,
|
||||
ISSChildDF = 0x01,
|
||||
ISSChildDF = 0x01,
|
||||
ISSEFByFileID = 0x02,
|
||||
ISSParentDF = 0x03,
|
||||
ISSParentDF = 0x03,
|
||||
ISSDFName = 0x04
|
||||
};
|
||||
typedef enum DesfireISOSelectControlEnum DesfireISOSelectControl;
|
||||
|
||||
@@ -41,7 +41,7 @@ void DesfireClearContext(DesfireContext *ctx) {
|
||||
ctx->secureChannel = DACNone;
|
||||
ctx->cmdSet = DCCNative;
|
||||
ctx->commMode = DCMNone;
|
||||
|
||||
|
||||
ctx->appSelected = false;
|
||||
|
||||
ctx->kdfAlgo = 0;
|
||||
@@ -224,7 +224,7 @@ void DesfireCryptoEncDecEx(DesfireContext *ctx, bool use_session_key, uint8_t *s
|
||||
if (ctx->secureChannel == DACd40) {
|
||||
memset(ctx->IV, 0, DESFIRE_MAX_CRYPTO_BLOCK_SIZE);
|
||||
}
|
||||
|
||||
|
||||
size_t block_size = desfire_get_key_block_length(ctx->keyType);
|
||||
|
||||
if (iv == NULL)
|
||||
@@ -425,7 +425,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) {
|
||||
uint8_t data[64] = {0};
|
||||
memset(sessionkey, 0, CRYPTO_AES_BLOCK_SIZE);
|
||||
|
||||
|
||||
if (enckey) {
|
||||
data[0] = 0xa5;
|
||||
data[1] = 0x5a;
|
||||
@@ -435,7 +435,7 @@ void DesfireGenSessionKeyEV2(uint8_t *key, uint8_t *rndA, uint8_t *rndB, bool en
|
||||
}
|
||||
data[3] = 0x01;
|
||||
data[5] = 0x80;
|
||||
|
||||
|
||||
// data+6 - start of rnd part
|
||||
memcpy(data + 6, rndA, 8);
|
||||
bin_xor(data + 8, rndB, 6); // xor rndb 6b
|
||||
@@ -453,7 +453,7 @@ void DesfireGenSessionKeyEV2(uint8_t *key, uint8_t *rndA, uint8_t *rndB, bool en
|
||||
|
||||
void DesfireEV2FillIV(DesfireContext *ctx, bool ivforcommand, uint8_t *iv) {
|
||||
uint8_t xiv[CRYPTO_AES_BLOCK_SIZE] = {0};
|
||||
|
||||
|
||||
if (ivforcommand) {
|
||||
xiv[0] = 0xa5;
|
||||
xiv[1] = 0x5a;
|
||||
@@ -464,10 +464,10 @@ void DesfireEV2FillIV(DesfireContext *ctx, bool ivforcommand, uint8_t *iv) {
|
||||
|
||||
memcpy(xiv + 2, ctx->TI, 4);
|
||||
Uint2byteToMemLe(xiv + 2 + 4, ctx->cmdCntr);
|
||||
|
||||
|
||||
if (aes_encode(NULL, ctx->sessionKeyEnc, xiv, xiv, CRYPTO_AES_BLOCK_SIZE))
|
||||
return;
|
||||
|
||||
|
||||
if (iv == NULL)
|
||||
memcpy(ctx->IV, xiv, CRYPTO_AES_BLOCK_SIZE);
|
||||
else
|
||||
|
||||
@@ -75,7 +75,7 @@ typedef struct DesfireContextS {
|
||||
DesfireSecureChannel secureChannel; // none/d40/ev1/ev2
|
||||
DesfireCommandSet cmdSet; // native/nativeiso/iso
|
||||
DesfireCommunicationMode commMode; // plain/mac/enc
|
||||
|
||||
|
||||
bool appSelected; // for iso auth
|
||||
|
||||
uint8_t IV[DESFIRE_MAX_KEY_SIZE];
|
||||
|
||||
@@ -117,7 +117,7 @@ static const AllowedChannelModesS AllowedChannelModes[] = {
|
||||
|
||||
{MFDES_CHANGE_KEY, DACEV1, DCCNative, DCMEncryptedPlain},
|
||||
{MFDES_CHANGE_KEY_EV2, DACEV1, DCCNative, DCMEncryptedPlain},
|
||||
|
||||
|
||||
{MFDES_AUTHENTICATE_EV2F, DACEV2, DCCNative, DCMPlain},
|
||||
{MFDES_AUTHENTICATE_EV2NF, DACEV2, DCCNative, DCMPlain},
|
||||
};
|
||||
@@ -246,7 +246,7 @@ static void DesfireSecureChannelEncodeEV1(DesfireContext *ctx, uint8_t cmd, uint
|
||||
static void DesfireSecureChannelEncodeEV2(DesfireContext *ctx, uint8_t cmd, uint8_t *srcdata, size_t srcdatalen, uint8_t *dstdata, size_t *dstdatalen) {
|
||||
memcpy(dstdata, srcdata, srcdatalen);
|
||||
*dstdatalen = srcdatalen;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void DesfireSecureChannelEncode(DesfireContext *ctx, uint8_t cmd, uint8_t *srcdata, size_t srcdatalen, uint8_t *dstdata, size_t *dstdatalen) {
|
||||
|
||||
@@ -216,7 +216,7 @@ static bool TestEV2SessionKeys(void) {
|
||||
uint8_t rndb[] = {0xFA, 0x65, 0x9A, 0xD0, 0xDC, 0xA7, 0x38, 0xDD, 0x65, 0xDC, 0x7D, 0xC3, 0x86, 0x12, 0xAD, 0x81};
|
||||
uint8_t sessionkeyauth[] = {0x63, 0xDC, 0x07, 0x28, 0x62, 0x89, 0xA7, 0xA6, 0xC0, 0x33, 0x4C, 0xA3, 0x1C, 0x31, 0x4A, 0x04};
|
||||
uint8_t sessionkeymac[] = {0x77, 0x4F, 0x26, 0x74, 0x3E, 0xCE, 0x6A, 0xF5, 0x03, 0x3B, 0x6A, 0xE8, 0x52, 0x29, 0x46, 0xF6};
|
||||
|
||||
|
||||
uint8_t sessionkey[16] = {0};
|
||||
DesfireGenSessionKeyEV2(key, rnda, rndb, true, sessionkey);
|
||||
res = res && (memcmp(sessionkey, sessionkeyauth, sizeof(sessionkeyauth)) == 0);
|
||||
@@ -224,7 +224,7 @@ static bool TestEV2SessionKeys(void) {
|
||||
memset(sessionkey, 0, sizeof(sessionkey));
|
||||
DesfireGenSessionKeyEV2(key, rnda, rndb, false, sessionkey);
|
||||
res = res && (memcmp(sessionkey, sessionkeymac, sizeof(sessionkeymac)) == 0);
|
||||
|
||||
|
||||
if (res)
|
||||
PrintAndLogEx(INFO, "EV2 session keys.. " _GREEN_("passed"));
|
||||
else
|
||||
@@ -239,17 +239,17 @@ static bool TestEV2IVEncode(void) {
|
||||
uint8_t key[] = {0x66, 0xA8, 0xCB, 0x93, 0x26, 0x9D, 0xC9, 0xBC, 0x28, 0x85, 0xB7, 0xA9, 0x1B, 0x9C, 0x69, 0x7B};
|
||||
uint8_t ti[] = {0xED, 0x56, 0xF6, 0xE6};
|
||||
uint8_t ivres[] = {0xDA, 0x0F, 0x64, 0x4A, 0x49, 0x86, 0x27, 0x59, 0x57, 0xCF, 0x1E, 0xC3, 0xAF, 0x4C, 0xCE, 0x53};
|
||||
|
||||
|
||||
DesfireContext ctx = {0};
|
||||
ctx.keyType = T_AES;
|
||||
memcpy(ctx.sessionKeyEnc, key, 16);
|
||||
memcpy(ctx.TI, ti, 4);
|
||||
ctx.cmdCntr = 0;
|
||||
|
||||
|
||||
uint8_t iv[16] = {0};
|
||||
DesfireEV2FillIV(&ctx, true, iv);
|
||||
res = res && (memcmp(iv, ivres, sizeof(ivres)) == 0);
|
||||
|
||||
|
||||
uint8_t key2[] = {0x44, 0x5A, 0x86, 0x26, 0xB3, 0x33, 0x84, 0x59, 0x32, 0x12, 0x32, 0xfA, 0xDf, 0x6a, 0xDe, 0x2B};
|
||||
uint8_t ti2[] = {0x11, 0x22, 0x33, 0x44};
|
||||
uint8_t ivres2[] = {0x17, 0x74, 0x94, 0xFC, 0xC4, 0xF1, 0xDA, 0xB2, 0xAF, 0xBE, 0x8F, 0xAE, 0x20, 0x57, 0xA9, 0xD2};
|
||||
|
||||
Reference in new issue
Block a user