clear record file works, lrp transaction check code
This commit is contained in:
1 parent
09b4c3eed1
commit
db2c8776c0
4 files changed
+67
-14
No files matched your search
@@ -667,6 +667,41 @@ void DesfireGenTransSessionKeyEV2(uint8_t *key, uint32_t trCntr, uint8_t *uid, b
|
||||
DesfireCryptoCMACEx(&ctx, DCOMainKey, xiv, 16, 0, sessionkey);
|
||||
}
|
||||
|
||||
// https://www.nxp.com/docs/en/data-sheet/MF2DLHX0.pdf
|
||||
// page 43
|
||||
void DesfireGenTransSessionKeyLRP(uint8_t *key, uint32_t trCntr, uint8_t *uid, bool forMAC, uint8_t *sessionkey) {
|
||||
uint8_t data[CRYPTO_AES_BLOCK_SIZE] = {0};
|
||||
|
||||
data[1] = 0x01;
|
||||
data[3] = 0x80;
|
||||
Uint4byteToMemLe(&data[4], trCntr + 0x00010001);
|
||||
memcpy(&data[8], uid, 7);
|
||||
if (forMAC) {
|
||||
data[15] = 0x5a;
|
||||
} else {
|
||||
data[15] = 0xa5;
|
||||
}
|
||||
|
||||
LRPContext lctx = {0};
|
||||
LRPSetKey(&lctx, key, 0, true);
|
||||
LRPCMAC(&lctx, data, sizeof(data), sessionkey);
|
||||
}
|
||||
|
||||
void DesfireDecodePrevReaderID(DesfireContext *ctx, uint8_t *key, uint32_t trCntr, uint8_t *encPrevReaderID, uint8_t *prevReaderID) {
|
||||
uint8_t sessionkey[16] = {0};
|
||||
uint8_t uid[7] = {0};
|
||||
memcpy(uid, ctx->uid, MAX(ctx->uidlen, 7));
|
||||
|
||||
if (ctx->secureChannel == DACEV2) {
|
||||
DesfireGenTransSessionKeyEV2(key, trCntr, uid, false, sessionkey);
|
||||
|
||||
aes_decode(NULL, sessionkey, encPrevReaderID, prevReaderID, CRYPTO_AES_BLOCK_SIZE);
|
||||
} else if (ctx->secureChannel == DACLRP) {
|
||||
DesfireGenTransSessionKeyLRP(key, trCntr, uid, false, sessionkey);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
int DesfireLRPCalcCMAC(DesfireContext *ctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *mac) {
|
||||
uint8_t mdata[1050] = {0};
|
||||
size_t mdatalen = 0;
|
||||
|
||||
@@ -141,7 +141,10 @@ 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);
|
||||
void DesfireEV2FillIV(DesfireContext *ctx, bool ivforcommand, uint8_t *iv);
|
||||
int DesfireEV2CalcCMAC(DesfireContext *ctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *mac);
|
||||
|
||||
void DesfireGenTransSessionKeyEV2(uint8_t *key, uint32_t trCntr, uint8_t *uid, bool forMAC, uint8_t *sessionkey);
|
||||
void DesfireGenTransSessionKeyLRP(uint8_t *key, uint32_t trCntr, uint8_t *uid, bool forMAC, uint8_t *sessionkey);
|
||||
void DesfireDecodePrevReaderID(DesfireContext *ctx, uint8_t *key, uint32_t trCntr, uint8_t *encPrevReaderID, uint8_t *prevReaderID);
|
||||
|
||||
int DesfireLRPCalcCMAC(DesfireContext *ctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *mac);
|
||||
|
||||
|
||||
@@ -153,6 +153,7 @@ static const AllowedChannelModesS AllowedChannelModes[] = {
|
||||
{MFDES_GET_ISOFILE_IDS, DACLRP, DCCNative, DCMMACed},
|
||||
{MFDES_GET_FILE_SETTINGS, DACLRP, DCCNative, DCMMACed},
|
||||
{MFDES_GET_KEY_VERSION, DACLRP, DCCNative, DCMMACed},
|
||||
{MFDES_CLEAR_RECORD_FILE, DACLRP, DCCNative, DCMMACed},
|
||||
|
||||
{MFDES_GET_UID, DACLRP, DCCNative, DCMEncrypted},
|
||||
{MFDES_CHANGE_FILE_SETTINGS, DACLRP, DCCNative, DCMEncrypted},
|
||||
|
||||
Reference in new issue
Block a user