mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-23 22:55:37 -07:00
ev2/encoded works with/wo data on the all directions
This commit is contained in:
parent
c3a5a45d37
commit
a6e39a5ff1
1 changed files with 15 additions and 15 deletions
|
@ -259,22 +259,21 @@ static void DesfireSecureChannelEncodeEV2(DesfireContext *ctx, uint8_t cmd, uint
|
||||||
memcpy(&dstdata[srcdatalen], cmac, DesfireGetMACLength(ctx));
|
memcpy(&dstdata[srcdatalen], cmac, DesfireGetMACLength(ctx));
|
||||||
*dstdatalen = srcdatalen + DesfireGetMACLength(ctx);
|
*dstdatalen = srcdatalen + DesfireGetMACLength(ctx);
|
||||||
} else if (ctx->commMode == DCMEncrypted) {
|
} else if (ctx->commMode == DCMEncrypted) {
|
||||||
dstdata[0] = cmd;
|
memcpy(dstdata, srcdata, hdrlen);
|
||||||
memcpy(&dstdata[1], srcdata, hdrlen);
|
|
||||||
|
|
||||||
if (srcdatalen > hdrlen) {
|
if (srcdatalen > hdrlen) {
|
||||||
rlen = padded_data_length(srcdatalen + 1 - hdrlen, desfire_get_key_block_length(ctx->keyType));
|
rlen = padded_data_length(srcdatalen + 1 - hdrlen, desfire_get_key_block_length(ctx->keyType));
|
||||||
memcpy(data, &srcdata[hdrlen], srcdatalen - hdrlen);
|
memcpy(data, &srcdata[hdrlen], srcdatalen - hdrlen);
|
||||||
data[hdrlen] = 0x80; // padding
|
data[srcdatalen - hdrlen] = 0x80; // padding
|
||||||
|
|
||||||
DesfireEV2FillIV(ctx, true, NULL); // fill IV to ctx
|
DesfireEV2FillIV(ctx, true, NULL); // fill IV to ctx
|
||||||
DesfireCryptoEncDec(ctx, DCOSessionKeyEnc, data, rlen, &dstdata[1 + hdrlen], true);
|
DesfireCryptoEncDec(ctx, DCOSessionKeyEnc, data, rlen, &dstdata[hdrlen], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t cmac[DESFIRE_MAX_CRYPTO_BLOCK_SIZE] = {0};
|
uint8_t cmac[DESFIRE_MAX_CRYPTO_BLOCK_SIZE] = {0};
|
||||||
DesfireEV2CalcCMAC(ctx, cmd, &dstdata[1], hdrlen + rlen, cmac);
|
DesfireEV2CalcCMAC(ctx, cmd, dstdata, hdrlen + rlen, cmac);
|
||||||
|
|
||||||
memcpy(&dstdata[ + hdrlen + rlen], cmac, DesfireGetMACLength(ctx));
|
memcpy(&dstdata[hdrlen + rlen], cmac, DesfireGetMACLength(ctx));
|
||||||
|
|
||||||
*dstdatalen = hdrlen + rlen + DesfireGetMACLength(ctx);
|
*dstdatalen = hdrlen + rlen + DesfireGetMACLength(ctx);
|
||||||
} else if (ctx->commMode == DCMEncryptedPlain) {
|
} else if (ctx->commMode == DCMEncryptedPlain) {
|
||||||
|
@ -442,7 +441,7 @@ static void DesfireSecureChannelDecodeEV2(DesfireContext *ctx, uint8_t *srcdata,
|
||||||
PrintAndLogEx(INFO, "Received MAC OK");
|
PrintAndLogEx(INFO, "Received MAC OK");
|
||||||
}
|
}
|
||||||
} else if (ctx->commMode == DCMEncrypted) {
|
} else if (ctx->commMode == DCMEncrypted) {
|
||||||
if (srcdatalen < desfire_get_key_block_length(ctx->keyType) + DesfireGetMACLength(ctx)) {
|
if (srcdatalen < DesfireGetMACLength(ctx)) {
|
||||||
memcpy(dstdata, srcdata, srcdatalen);
|
memcpy(dstdata, srcdata, srcdatalen);
|
||||||
*dstdatalen = srcdatalen;
|
*dstdatalen = srcdatalen;
|
||||||
return;
|
return;
|
||||||
|
@ -459,8 +458,8 @@ static void DesfireSecureChannelDecodeEV2(DesfireContext *ctx, uint8_t *srcdata,
|
||||||
PrintAndLogEx(INFO, "Received MAC OK");
|
PrintAndLogEx(INFO, "Received MAC OK");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (*dstdatalen >= desfire_get_key_block_length(ctx->keyType)) {
|
||||||
DesfireEV2FillIV(ctx, false, NULL); // fill response IV to ctx
|
DesfireEV2FillIV(ctx, false, NULL); // fill response IV to ctx
|
||||||
|
|
||||||
DesfireCryptoEncDec(ctx, DCOSessionKeyEnc, srcdata, *dstdatalen, dstdata, false);
|
DesfireCryptoEncDec(ctx, DCOSessionKeyEnc, srcdata, *dstdatalen, dstdata, false);
|
||||||
|
|
||||||
size_t puredatalen = FindISO9797M2PaddingDataLen(dstdata, *dstdatalen);
|
size_t puredatalen = FindISO9797M2PaddingDataLen(dstdata, *dstdatalen);
|
||||||
|
@ -471,6 +470,7 @@ static void DesfireSecureChannelDecodeEV2(DesfireContext *ctx, uint8_t *srcdata,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DesfireSecureChannelDecode(DesfireContext *ctx, uint8_t *srcdata, size_t srcdatalen, uint8_t respcode, uint8_t *dstdata, size_t *dstdatalen) {
|
void DesfireSecureChannelDecode(DesfireContext *ctx, uint8_t *srcdata, size_t srcdatalen, uint8_t respcode, uint8_t *dstdata, size_t *dstdatalen) {
|
||||||
switch (ctx->secureChannel) {
|
switch (ctx->secureChannel) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue