mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-25 07:35:40 -07:00
encode with padding sketch
This commit is contained in:
parent
d847aed5a6
commit
e78c563e45
5 changed files with 19 additions and 9 deletions
|
@ -2628,14 +2628,12 @@ static int CmdHF14ADesSetConfiguration(const char *Cmd) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
DesfireSetCommMode(&dctx, DCMEncryptedPlain);
|
|
||||||
res = DesfireSetConfiguration(&dctx, paramid, param, paramlen);
|
res = DesfireSetConfiguration(&dctx, paramid, param, paramlen);
|
||||||
if (res == PM3_SUCCESS) {
|
if (res == PM3_SUCCESS) {
|
||||||
PrintAndLogEx(SUCCESS, "Set configuration 0x%02x " _GREEN_("ok") " ", paramid);
|
PrintAndLogEx(SUCCESS, "Set configuration 0x%02x " _GREEN_("ok") " ", paramid);
|
||||||
} else {
|
} else {
|
||||||
PrintAndLogEx(FAILED, "Set configuration 0x%02x " _RED_("failed") " ", paramid);
|
PrintAndLogEx(FAILED, "Set configuration 0x%02x " _RED_("failed") " ", paramid);
|
||||||
}
|
}
|
||||||
DesfireSetCommMode(&dctx, DCMEncrypted);
|
|
||||||
|
|
||||||
DropField();
|
DropField();
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -2545,7 +2545,7 @@ int DesfireSetConfiguration(DesfireContext *dctx, uint8_t paramid, uint8_t *para
|
||||||
size_t datalen = 1 + paramlen;
|
size_t datalen = 1 + paramlen;
|
||||||
|
|
||||||
|
|
||||||
// add crc
|
/*// add crc
|
||||||
if (dctx->secureChannel == DACd40) {
|
if (dctx->secureChannel == DACd40) {
|
||||||
iso14443a_crc_append(&data[1], datalen - 1);
|
iso14443a_crc_append(&data[1], datalen - 1);
|
||||||
datalen += 2;
|
datalen += 2;
|
||||||
|
@ -2553,11 +2553,12 @@ int DesfireSetConfiguration(DesfireContext *dctx, uint8_t paramid, uint8_t *para
|
||||||
desfire_crc32_append(cdata, datalen + 1);
|
desfire_crc32_append(cdata, datalen + 1);
|
||||||
datalen += 4;
|
datalen += 4;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
// dynamic length
|
// dynamic length
|
||||||
if (paramid == 0x02) {
|
if (paramid == 0x02 && dctx->commMode == DCMEncrypted) {
|
||||||
data[datalen] = 0x80;
|
dctx->commMode = DCMEncryptedWithPadding;
|
||||||
datalen++;
|
//data[datalen] = 0x80;
|
||||||
|
//datalen++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// send command
|
// send command
|
||||||
|
|
|
@ -429,6 +429,7 @@ uint8_t DesfireCommModeToFileCommMode(DesfireCommunicationMode comm_mode) {
|
||||||
fmode = 0x01;
|
fmode = 0x01;
|
||||||
break;
|
break;
|
||||||
case DCMEncrypted:
|
case DCMEncrypted:
|
||||||
|
case DCMEncryptedWithPadding:
|
||||||
case DCMEncryptedPlain:
|
case DCMEncryptedPlain:
|
||||||
fmode = 0x11;
|
fmode = 0x11;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -58,6 +58,7 @@ typedef enum {
|
||||||
DCMPlain,
|
DCMPlain,
|
||||||
DCMMACed,
|
DCMMACed,
|
||||||
DCMEncrypted,
|
DCMEncrypted,
|
||||||
|
DCMEncryptedWithPadding,
|
||||||
DCMEncryptedPlain
|
DCMEncryptedPlain
|
||||||
} DesfireCommunicationMode;
|
} DesfireCommunicationMode;
|
||||||
|
|
||||||
|
|
|
@ -260,16 +260,24 @@ static void DesfireSecureChannelEncodeEV1(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 || ctx->commMode == DCMEncryptedWithPadding) {
|
||||||
rlen = padded_data_length(srcdatalen + 4 - hdrlen, desfire_get_key_block_length(ctx->keyType));
|
uint8_t paddinglen = (ctx->commMode == DCMEncryptedWithPadding) ? 1 : 0;
|
||||||
|
rlen = padded_data_length(srcdatalen + 4 + paddinglen - hdrlen, desfire_get_key_block_length(ctx->keyType));
|
||||||
data[0] = cmd;
|
data[0] = cmd;
|
||||||
|
|
||||||
|
// crc
|
||||||
memcpy(&data[1], srcdata, srcdatalen);
|
memcpy(&data[1], srcdata, srcdatalen);
|
||||||
desfire_crc32_append(data, srcdatalen + 1);
|
desfire_crc32_append(data, srcdatalen + 1);
|
||||||
|
|
||||||
|
// add padding
|
||||||
|
if (paddinglen > 0)
|
||||||
|
data[srcdatalen + 1 + 4] = 0x80;
|
||||||
|
|
||||||
memcpy(dstdata, srcdata, hdrlen);
|
memcpy(dstdata, srcdata, hdrlen);
|
||||||
DesfireCryptoEncDec(ctx, DCOSessionKeyEnc, &data[1 + hdrlen], rlen, &dstdata[hdrlen], true);
|
DesfireCryptoEncDec(ctx, DCOSessionKeyEnc, &data[1 + hdrlen], rlen, &dstdata[hdrlen], true);
|
||||||
|
|
||||||
*dstdatalen = hdrlen + rlen;
|
*dstdatalen = hdrlen + rlen;
|
||||||
|
ctx->commMode = DCMEncrypted;
|
||||||
} else if (ctx->commMode == DCMEncryptedPlain) {
|
} else if (ctx->commMode == DCMEncryptedPlain) {
|
||||||
if (srcdatalen <= hdrlen)
|
if (srcdatalen <= hdrlen)
|
||||||
return;
|
return;
|
||||||
|
@ -374,6 +382,7 @@ static void DesfireSecureChannelDecodeD40(DesfireContext *ctx, uint8_t *srcdata,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DCMEncrypted:
|
case DCMEncrypted:
|
||||||
|
case DCMEncryptedWithPadding:
|
||||||
if (srcdatalen < desfire_get_key_block_length(ctx->keyType)) {
|
if (srcdatalen < desfire_get_key_block_length(ctx->keyType)) {
|
||||||
memcpy(dstdata, srcdata, srcdatalen);
|
memcpy(dstdata, srcdata, srcdatalen);
|
||||||
*dstdatalen = srcdatalen;
|
*dstdatalen = srcdatalen;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue