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