mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 21:33:47 -07:00
rename typedef structs
This commit is contained in:
parent
5fce6271ee
commit
f6d88dced2
22 changed files with 406 additions and 406 deletions
|
@ -1710,13 +1710,13 @@ int CmdHpf(const char *Cmd) {
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool _headBit(BitstreamOut *stream) {
|
static bool _headBit(BitstreamOut_t *stream) {
|
||||||
int bytepos = stream->position >> 3; // divide by 8
|
int bytepos = stream->position >> 3; // divide by 8
|
||||||
int bitpos = (stream->position++) & 7; // mask out 00000111
|
int bitpos = (stream->position++) & 7; // mask out 00000111
|
||||||
return (*(stream->buffer + bytepos) >> (7 - bitpos)) & 1;
|
return (*(stream->buffer + bytepos) >> (7 - bitpos)) & 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t getByte(uint8_t bits_per_sample, BitstreamOut *b) {
|
static uint8_t getByte(uint8_t bits_per_sample, BitstreamOut_t *b) {
|
||||||
uint8_t val = 0;
|
uint8_t val = 0;
|
||||||
for (int i = 0 ; i < bits_per_sample; i++)
|
for (int i = 0 ; i < bits_per_sample; i++)
|
||||||
val |= (_headBit(b) << (7 - i));
|
val |= (_headBit(b) << (7 - i));
|
||||||
|
@ -1771,7 +1771,7 @@ int getSamplesEx(uint32_t start, uint32_t end, bool verbose) {
|
||||||
|
|
||||||
if (verbose) PrintAndLogEx(INFO, "Unpacking...");
|
if (verbose) PrintAndLogEx(INFO, "Unpacking...");
|
||||||
|
|
||||||
BitstreamOut bout = { got, bits_per_sample * n, 0};
|
BitstreamOut_t bout = { got, bits_per_sample * n, 0};
|
||||||
uint32_t j = 0;
|
uint32_t j = 0;
|
||||||
for (j = 0; j * bits_per_sample < n * 8 && j < n; j++) {
|
for (j = 0; j * bits_per_sample < n * 8 && j < n; j++) {
|
||||||
uint8_t sample = getByte(bits_per_sample, &bout);
|
uint8_t sample = getByte(bits_per_sample, &bout);
|
||||||
|
@ -2425,7 +2425,7 @@ static int Cmdbin2hex(const char *Cmd) {
|
||||||
size_t bytelen = (blen + 7) / 8;
|
size_t bytelen = (blen + 7) / 8;
|
||||||
uint8_t *arr = (uint8_t *) calloc(bytelen, sizeof(uint8_t));
|
uint8_t *arr = (uint8_t *) calloc(bytelen, sizeof(uint8_t));
|
||||||
memset(arr, 0, bytelen);
|
memset(arr, 0, bytelen);
|
||||||
BitstreamOut bout = { arr, 0, 0 };
|
BitstreamOut_t bout = { arr, 0, 0 };
|
||||||
|
|
||||||
for (int i = 0; i < blen; i++) {
|
for (int i = 0; i < blen; i++) {
|
||||||
uint8_t c = binarr[i];
|
uint8_t c = binarr[i];
|
||||||
|
|
|
@ -3698,7 +3698,7 @@ static int CmdHFiClassEncode(const char *Cmd) {
|
||||||
|
|
||||||
uint8_t data[8];
|
uint8_t data[8];
|
||||||
memset(data, 0, sizeof(data));
|
memset(data, 0, sizeof(data));
|
||||||
BitstreamOut bout = {data, 0, 0 };
|
BitstreamOut_t bout = {data, 0, 0 };
|
||||||
|
|
||||||
for (int i = 0; i < 64 - bin_len - 1; i++) {
|
for (int i = 0; i < 64 - bin_len - 1; i++) {
|
||||||
pushBit(&bout, 0);
|
pushBit(&bout, 0);
|
||||||
|
|
|
@ -380,7 +380,7 @@ static DesfireCommandSet defaultCommSet = DCCNativeISO;
|
||||||
static DesfireCommunicationMode defaultCommMode = DCMPlain;
|
static DesfireCommunicationMode defaultCommMode = DCMPlain;
|
||||||
static uint32_t transactionCounter = 0;
|
static uint32_t transactionCounter = 0;
|
||||||
|
|
||||||
static int CmdDesGetSessionParameters(CLIParserContext *ctx, DesfireContext *dctx,
|
static int CmdDesGetSessionParameters(CLIParserContext *ctx, DesfireContext_t *dctx,
|
||||||
uint8_t keynoid, uint8_t algoid, uint8_t keyid,
|
uint8_t keynoid, uint8_t algoid, uint8_t keyid,
|
||||||
uint8_t kdfid, uint8_t kdfiid,
|
uint8_t kdfid, uint8_t kdfiid,
|
||||||
uint8_t cmodeid, uint8_t ccsetid, uint8_t schannid,
|
uint8_t cmodeid, uint8_t ccsetid, uint8_t schannid,
|
||||||
|
@ -510,7 +510,7 @@ static int CmdHF14ADesDefault(const char *Cmd) {
|
||||||
};
|
};
|
||||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
int res = CmdDesGetSessionParameters(ctx, &dctx, 1, 2, 3, 4, 5, 6, 7, 8, 0, 0, &securechann, DCMNone, NULL, NULL);
|
int res = CmdDesGetSessionParameters(ctx, &dctx, 1, 2, 3, 4, 5, 6, 7, 8, 0, 0, &securechann, DCMNone, NULL, NULL);
|
||||||
if (res) {
|
if (res) {
|
||||||
|
@ -621,7 +621,7 @@ static int CmdHF14ADesInfo(const char *Cmd) {
|
||||||
if (major == 0 && minor == 2)
|
if (major == 0 && minor == 2)
|
||||||
PrintAndLogEx(INFO, "\t0.2 - DESFire Light, Originality check, ");
|
PrintAndLogEx(INFO, "\t0.2 - DESFire Light, Originality check, ");
|
||||||
|
|
||||||
DesfireContext dctx = {0};
|
DesfireContext_t dctx = {0};
|
||||||
dctx.commMode = DCMPlain;
|
dctx.commMode = DCMPlain;
|
||||||
dctx.cmdSet = DCCNative;
|
dctx.cmdSet = DCCNative;
|
||||||
|
|
||||||
|
@ -652,7 +652,7 @@ static int CmdHF14ADesInfo(const char *Cmd) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PICCInfoS PICCInfo = {0};
|
PICCInfo_t PICCInfo = {0};
|
||||||
|
|
||||||
uint8_t aidbuf[250] = {0};
|
uint8_t aidbuf[250] = {0};
|
||||||
size_t aidbuflen = 0;
|
size_t aidbuflen = 0;
|
||||||
|
@ -771,7 +771,7 @@ static void DesFill2bPattern(
|
||||||
(*startPattern)++;
|
(*startPattern)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int AuthCheckDesfire(DesfireContext *dctx,
|
static int AuthCheckDesfire(DesfireContext_t *dctx,
|
||||||
DesfireSecureChannel secureChannel,
|
DesfireSecureChannel secureChannel,
|
||||||
uint8_t *aid,
|
uint8_t *aid,
|
||||||
uint8_t deskeyList[MAX_KEYS_LIST_LEN][8], uint32_t deskeyListLen,
|
uint8_t deskeyList[MAX_KEYS_LIST_LEN][8], uint32_t deskeyListLen,
|
||||||
|
@ -825,7 +825,7 @@ static int AuthCheckDesfire(DesfireContext *dctx,
|
||||||
usedkeys[0] = 1;
|
usedkeys[0] = 1;
|
||||||
|
|
||||||
if (curaid != 0) {
|
if (curaid != 0) {
|
||||||
FileListS fileList = {0};
|
FileList_t fileList = {0};
|
||||||
size_t filescount = 0;
|
size_t filescount = 0;
|
||||||
bool isopresent = 0;
|
bool isopresent = 0;
|
||||||
res = DesfireFillFileList(dctx, fileList, &filescount, &isopresent);
|
res = DesfireFillFileList(dctx, fileList, &filescount, &isopresent);
|
||||||
|
@ -1180,7 +1180,7 @@ static int CmdHF14aDesChk(const char *Cmd) {
|
||||||
|
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
DesfireSetKdf(&dctx, cmdKDFAlgo, kdfInput, kdfInputLen);
|
DesfireSetKdf(&dctx, cmdKDFAlgo, kdfInput, kdfInputLen);
|
||||||
DesfireSetCommandSet(&dctx, DCCNativeISO);
|
DesfireSetCommandSet(&dctx, DCCNativeISO);
|
||||||
DesfireSetCommMode(&dctx, DCMPlain);
|
DesfireSetCommMode(&dctx, DCMPlain);
|
||||||
|
@ -1294,7 +1294,7 @@ static int CmdHF14ADesList(const char *Cmd) {
|
||||||
return CmdTraceListAlias(Cmd, "hf mfdes", "des");
|
return CmdTraceListAlias(Cmd, "hf mfdes", "des");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int DesfireAuthCheck(DesfireContext *dctx, uint32_t appid, DesfireSecureChannel secureChannel, uint8_t *key) {
|
static int DesfireAuthCheck(DesfireContext_t *dctx, uint32_t appid, DesfireSecureChannel secureChannel, uint8_t *key) {
|
||||||
DesfireSetKeyNoClear(dctx, dctx->keyNum, dctx->keyType, key);
|
DesfireSetKeyNoClear(dctx, dctx->keyNum, dctx->keyType, key);
|
||||||
|
|
||||||
int res = DesfireAuthenticate(dctx, secureChannel, false);
|
int res = DesfireAuthenticate(dctx, secureChannel, false);
|
||||||
|
@ -1344,7 +1344,7 @@ static int CmdHF14aDesDetect(const char *Cmd) {
|
||||||
bool APDULogging = arg_get_lit(ctx, 1);
|
bool APDULogging = arg_get_lit(ctx, 1);
|
||||||
bool verbose = arg_get_lit(ctx, 2);
|
bool verbose = arg_get_lit(ctx, 2);
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
uint32_t appid = 0x000000;
|
uint32_t appid = 0x000000;
|
||||||
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, &securechann, DCMMACed, &appid, NULL);
|
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, &securechann, DCMMACed, &appid, NULL);
|
||||||
|
@ -1397,7 +1397,7 @@ static int CmdHF14aDesDetect(const char *Cmd) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// if fail - check auth commands
|
// if fail - check auth commands
|
||||||
AuthCommandsChk authCmdCheck = {0};
|
AuthCommandsChk_t authCmdCheck = {0};
|
||||||
DesfireCheckAuthCommands(appid, NULL, 0, &authCmdCheck);
|
DesfireCheckAuthCommands(appid, NULL, 0, &authCmdCheck);
|
||||||
if (authCmdCheck.checked) {
|
if (authCmdCheck.checked) {
|
||||||
if (authCmdCheck.auth) {
|
if (authCmdCheck.auth) {
|
||||||
|
@ -1600,7 +1600,7 @@ static int CmdHF14aDesMAD(const char *Cmd) {
|
||||||
bool APDULogging = arg_get_lit(ctx, 1);
|
bool APDULogging = arg_get_lit(ctx, 1);
|
||||||
bool verbose = arg_get_lit(ctx, 2);
|
bool verbose = arg_get_lit(ctx, 2);
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
uint32_t appid = 0x000000;
|
uint32_t appid = 0x000000;
|
||||||
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, &securechann, DCMPlain, &appid, NULL);
|
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, &securechann, DCMPlain, &appid, NULL);
|
||||||
|
@ -1620,7 +1620,7 @@ static int CmdHF14aDesMAD(const char *Cmd) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
PICCInfoS PICCInfo = {0};
|
PICCInfo_t PICCInfo = {0};
|
||||||
AppListS AppList = {0};
|
AppListS AppList = {0};
|
||||||
DesfireFillAppList(&dctx, &PICCInfo, AppList, false, false, false); // no deep scan, no scan files
|
DesfireFillAppList(&dctx, &PICCInfo, AppList, false, false, false); // no deep scan, no scan files
|
||||||
|
|
||||||
|
@ -1745,7 +1745,7 @@ static int CmdHF14ADesSelectApp(const char *Cmd) {
|
||||||
bool APDULogging = arg_get_lit(ctx, 1);
|
bool APDULogging = arg_get_lit(ctx, 1);
|
||||||
bool verbose = arg_get_lit(ctx, 2);
|
bool verbose = arg_get_lit(ctx, 2);
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
uint32_t appid = 0x000000;
|
uint32_t appid = 0x000000;
|
||||||
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, &securechann, DCMPlain, &appid, NULL);
|
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, &securechann, DCMPlain, &appid, NULL);
|
||||||
|
@ -1868,7 +1868,7 @@ static int CmdHF14ADesBruteApps(const char *Cmd) {
|
||||||
};
|
};
|
||||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
int res = CmdDesGetSessionParameters(ctx, &dctx, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &securechann, DCMNone, NULL, NULL);
|
int res = CmdDesGetSessionParameters(ctx, &dctx, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &securechann, DCMNone, NULL, NULL);
|
||||||
if (res) {
|
if (res) {
|
||||||
|
@ -1969,7 +1969,7 @@ static int CmdHF14ADesAuth(const char *Cmd) {
|
||||||
bool APDULogging = arg_get_lit(ctx, 1);
|
bool APDULogging = arg_get_lit(ctx, 1);
|
||||||
bool verbose = arg_get_lit(ctx, 2);
|
bool verbose = arg_get_lit(ctx, 2);
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
uint32_t id = 0x000000;
|
uint32_t id = 0x000000;
|
||||||
DesfireISOSelectWay selectway = ISW6bAID;
|
DesfireISOSelectWay selectway = ISW6bAID;
|
||||||
|
@ -2062,7 +2062,7 @@ static int CmdHF14ADesSetConfiguration(const char *Cmd) {
|
||||||
bool APDULogging = arg_get_lit(ctx, 1);
|
bool APDULogging = arg_get_lit(ctx, 1);
|
||||||
bool verbose = arg_get_lit(ctx, 2);
|
bool verbose = arg_get_lit(ctx, 2);
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
uint32_t id = 0x000000;
|
uint32_t id = 0x000000;
|
||||||
DesfireISOSelectWay selectway = ISW6bAID;
|
DesfireISOSelectWay selectway = ISW6bAID;
|
||||||
|
@ -2160,7 +2160,7 @@ static int CmdHF14ADesChangeKey(const char *Cmd) {
|
||||||
bool APDULogging = arg_get_lit(ctx, 1);
|
bool APDULogging = arg_get_lit(ctx, 1);
|
||||||
bool verbose = arg_get_lit(ctx, 2);
|
bool verbose = arg_get_lit(ctx, 2);
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
uint32_t id = 0x000000;
|
uint32_t id = 0x000000;
|
||||||
DesfireISOSelectWay selectway = ISW6bAID;
|
DesfireISOSelectWay selectway = ISW6bAID;
|
||||||
|
@ -2322,7 +2322,7 @@ static int CmdHF14ADesCreateApp(const char *Cmd) {
|
||||||
bool APDULogging = arg_get_lit(ctx, 1);
|
bool APDULogging = arg_get_lit(ctx, 1);
|
||||||
bool verbose = arg_get_lit(ctx, 2);
|
bool verbose = arg_get_lit(ctx, 2);
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
uint32_t appid = 0x000000;
|
uint32_t appid = 0x000000;
|
||||||
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 12, 0, &securechann, DCMMACed, &appid, NULL);
|
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 12, 0, &securechann, DCMMACed, &appid, NULL);
|
||||||
|
@ -2479,7 +2479,7 @@ static int CmdHF14ADesDeleteApp(const char *Cmd) {
|
||||||
bool APDULogging = arg_get_lit(ctx, 1);
|
bool APDULogging = arg_get_lit(ctx, 1);
|
||||||
bool verbose = arg_get_lit(ctx, 2);
|
bool verbose = arg_get_lit(ctx, 2);
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
uint32_t appid = 0x000000;
|
uint32_t appid = 0x000000;
|
||||||
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, &securechann, DCMMACed, &appid, NULL);
|
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, &securechann, DCMMACed, &appid, NULL);
|
||||||
|
@ -2543,7 +2543,7 @@ static int CmdHF14ADesGetUID(const char *Cmd) {
|
||||||
bool APDULogging = arg_get_lit(ctx, 1);
|
bool APDULogging = arg_get_lit(ctx, 1);
|
||||||
bool verbose = arg_get_lit(ctx, 2);
|
bool verbose = arg_get_lit(ctx, 2);
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
uint32_t id = 0x000000;
|
uint32_t id = 0x000000;
|
||||||
DesfireISOSelectWay selectway = ISW6bAID;
|
DesfireISOSelectWay selectway = ISW6bAID;
|
||||||
|
@ -2622,7 +2622,7 @@ static int CmdHF14ADesFormatPICC(const char *Cmd) {
|
||||||
bool APDULogging = arg_get_lit(ctx, 1);
|
bool APDULogging = arg_get_lit(ctx, 1);
|
||||||
bool verbose = arg_get_lit(ctx, 2);
|
bool verbose = arg_get_lit(ctx, 2);
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
uint32_t appid = 0x000000;
|
uint32_t appid = 0x000000;
|
||||||
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, &securechann, DCMMACed, &appid, NULL);
|
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, &securechann, DCMMACed, &appid, NULL);
|
||||||
|
@ -2681,7 +2681,7 @@ static int CmdHF14ADesGetFreeMem(const char *Cmd) {
|
||||||
|
|
||||||
bool noauth = arg_get_lit(ctx, 11);
|
bool noauth = arg_get_lit(ctx, 11);
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 0, 0, &securechann, (noauth) ? DCMPlain : DCMMACed, NULL, NULL);
|
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 0, 0, &securechann, (noauth) ? DCMPlain : DCMMACed, NULL, NULL);
|
||||||
if (res) {
|
if (res) {
|
||||||
|
@ -2741,7 +2741,7 @@ static int CmdHF14ADesChKeySettings(const char *Cmd) {
|
||||||
bool APDULogging = arg_get_lit(ctx, 1);
|
bool APDULogging = arg_get_lit(ctx, 1);
|
||||||
bool verbose = arg_get_lit(ctx, 2);
|
bool verbose = arg_get_lit(ctx, 2);
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
uint32_t appid = 0x000000;
|
uint32_t appid = 0x000000;
|
||||||
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, &securechann, DCMEncrypted, &appid, NULL);
|
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, &securechann, DCMEncrypted, &appid, NULL);
|
||||||
|
@ -2818,7 +2818,7 @@ static int CmdHF14ADesGetKeyVersions(const char *Cmd) {
|
||||||
bool verbose = arg_get_lit(ctx, 2);
|
bool verbose = arg_get_lit(ctx, 2);
|
||||||
bool noauth = arg_get_lit(ctx, 15);
|
bool noauth = arg_get_lit(ctx, 15);
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
uint32_t id = 0x000000;
|
uint32_t id = 0x000000;
|
||||||
DesfireISOSelectWay selectway = ISW6bAID;
|
DesfireISOSelectWay selectway = ISW6bAID;
|
||||||
|
@ -2915,7 +2915,7 @@ static int CmdHF14ADesGetKeySettings(const char *Cmd) {
|
||||||
bool APDULogging = arg_get_lit(ctx, 1);
|
bool APDULogging = arg_get_lit(ctx, 1);
|
||||||
bool verbose = arg_get_lit(ctx, 2);
|
bool verbose = arg_get_lit(ctx, 2);
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
uint32_t appid = 0x000000;
|
uint32_t appid = 0x000000;
|
||||||
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, &securechann, DCMMACed, &appid, NULL);
|
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, &securechann, DCMMACed, &appid, NULL);
|
||||||
|
@ -2994,7 +2994,7 @@ static int CmdHF14ADesGetAIDs(const char *Cmd) {
|
||||||
bool verbose = arg_get_lit(ctx, 2);
|
bool verbose = arg_get_lit(ctx, 2);
|
||||||
bool noauth = arg_get_lit(ctx, 11);
|
bool noauth = arg_get_lit(ctx, 11);
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 0, 0, &securechann, DCMMACed, NULL, NULL);
|
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 0, 0, &securechann, DCMMACed, NULL, NULL);
|
||||||
if (res) {
|
if (res) {
|
||||||
|
@ -3060,7 +3060,7 @@ static int CmdHF14ADesGetAppNames(const char *Cmd) {
|
||||||
bool verbose = arg_get_lit(ctx, 2);
|
bool verbose = arg_get_lit(ctx, 2);
|
||||||
bool noauth = arg_get_lit(ctx, 11);
|
bool noauth = arg_get_lit(ctx, 11);
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 0, 0, &securechann, DCMMACed, NULL, NULL);
|
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 0, 0, &securechann, DCMMACed, NULL, NULL);
|
||||||
if (res) {
|
if (res) {
|
||||||
|
@ -3134,7 +3134,7 @@ static int CmdHF14ADesGetFileIDs(const char *Cmd) {
|
||||||
bool verbose = arg_get_lit(ctx, 2);
|
bool verbose = arg_get_lit(ctx, 2);
|
||||||
bool noauth = arg_get_lit(ctx, 13);
|
bool noauth = arg_get_lit(ctx, 13);
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
uint32_t id = 0x000000;
|
uint32_t id = 0x000000;
|
||||||
DesfireISOSelectWay selectway = ISW6bAID;
|
DesfireISOSelectWay selectway = ISW6bAID;
|
||||||
|
@ -3208,7 +3208,7 @@ static int CmdHF14ADesGetFileISOIDs(const char *Cmd) {
|
||||||
bool verbose = arg_get_lit(ctx, 2);
|
bool verbose = arg_get_lit(ctx, 2);
|
||||||
bool noauth = arg_get_lit(ctx, 13);
|
bool noauth = arg_get_lit(ctx, 13);
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
uint32_t id = 0x000000;
|
uint32_t id = 0x000000;
|
||||||
DesfireISOSelectWay selectway = ISW6bAID;
|
DesfireISOSelectWay selectway = ISW6bAID;
|
||||||
|
@ -3282,7 +3282,7 @@ static int CmdHF14ADesGetFileSettings(const char *Cmd) {
|
||||||
bool verbose = arg_get_lit(ctx, 2);
|
bool verbose = arg_get_lit(ctx, 2);
|
||||||
bool noauth = arg_get_lit(ctx, 14);
|
bool noauth = arg_get_lit(ctx, 14);
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
uint32_t id = 0x000000;
|
uint32_t id = 0x000000;
|
||||||
DesfireISOSelectWay selectway = ISW6bAID;
|
DesfireISOSelectWay selectway = ISW6bAID;
|
||||||
|
@ -3462,7 +3462,7 @@ static int CmdHF14ADesChFileSettings(const char *Cmd) {
|
||||||
bool verbose = arg_get_lit(ctx, 2);
|
bool verbose = arg_get_lit(ctx, 2);
|
||||||
bool noauth = arg_get_lit(ctx, 21);
|
bool noauth = arg_get_lit(ctx, 21);
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
uint32_t id = 0x000000;
|
uint32_t id = 0x000000;
|
||||||
DesfireISOSelectWay selectway = ISW6bAID;
|
DesfireISOSelectWay selectway = ISW6bAID;
|
||||||
|
@ -3610,7 +3610,7 @@ static int CmdHF14ADesCreateFile(const char *Cmd) {
|
||||||
bool backup = arg_get_lit(ctx, 24);
|
bool backup = arg_get_lit(ctx, 24);
|
||||||
uint8_t filetype = (backup) ? 0x01 : 0x00; // backup / standard data file
|
uint8_t filetype = (backup) ? 0x01 : 0x00; // backup / standard data file
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
uint32_t appid = 0x000000;
|
uint32_t appid = 0x000000;
|
||||||
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, &securechann, DCMMACed, &appid, NULL);
|
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, &securechann, DCMMACed, &appid, NULL);
|
||||||
|
@ -3747,7 +3747,7 @@ static int CmdHF14ADesCreateValueFile(const char *Cmd) {
|
||||||
|
|
||||||
uint8_t filetype = 0x02; // value file
|
uint8_t filetype = 0x02; // value file
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
uint32_t appid = 0x000000;
|
uint32_t appid = 0x000000;
|
||||||
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, &securechann, DCMMACed, &appid, NULL);
|
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, &securechann, DCMMACed, &appid, NULL);
|
||||||
|
@ -3874,7 +3874,7 @@ static int CmdHF14ADesCreateRecordFile(const char *Cmd) {
|
||||||
bool cyclic = arg_get_lit(ctx, 23);
|
bool cyclic = arg_get_lit(ctx, 23);
|
||||||
uint8_t filetype = (cyclic) ? 0x04 : 0x03; // linear(03) / cyclic(04) record file
|
uint8_t filetype = (cyclic) ? 0x04 : 0x03; // linear(03) / cyclic(04) record file
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
uint32_t appid = 0x000000;
|
uint32_t appid = 0x000000;
|
||||||
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, &securechann, DCMMACed, &appid, NULL);
|
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, &securechann, DCMMACed, &appid, NULL);
|
||||||
|
@ -3991,7 +3991,7 @@ static int CmdHF14ADesCreateTrMACFile(const char *Cmd) {
|
||||||
|
|
||||||
uint8_t filetype = 0x05; // transaction mac file
|
uint8_t filetype = 0x05; // transaction mac file
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
uint32_t id = 0x000000;
|
uint32_t id = 0x000000;
|
||||||
DesfireISOSelectWay selectway = ISW6bAID;
|
DesfireISOSelectWay selectway = ISW6bAID;
|
||||||
|
@ -4098,7 +4098,7 @@ static int CmdHF14ADesDeleteFile(const char *Cmd) {
|
||||||
bool verbose = arg_get_lit(ctx, 2);
|
bool verbose = arg_get_lit(ctx, 2);
|
||||||
bool noauth = arg_get_lit(ctx, 14);
|
bool noauth = arg_get_lit(ctx, 14);
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
uint32_t id = 0x000000;
|
uint32_t id = 0x000000;
|
||||||
DesfireISOSelectWay selectway = ISW6bAID;
|
DesfireISOSelectWay selectway = ISW6bAID;
|
||||||
|
@ -4178,7 +4178,7 @@ static int CmdHF14ADesValueOperations(const char *Cmd) {
|
||||||
bool verbose = arg_get_lit(ctx, 2);
|
bool verbose = arg_get_lit(ctx, 2);
|
||||||
bool noauth = arg_get_lit(ctx, 16);
|
bool noauth = arg_get_lit(ctx, 16);
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
uint32_t id = 0x000000;
|
uint32_t id = 0x000000;
|
||||||
DesfireISOSelectWay selectway = ISW6bAID;
|
DesfireISOSelectWay selectway = ISW6bAID;
|
||||||
|
@ -4348,7 +4348,7 @@ static int CmdHF14ADesClearRecordFile(const char *Cmd) {
|
||||||
bool verbose = arg_get_lit(ctx, 2);
|
bool verbose = arg_get_lit(ctx, 2);
|
||||||
bool noauth = arg_get_lit(ctx, 14);
|
bool noauth = arg_get_lit(ctx, 14);
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
uint32_t id = 0x000000;
|
uint32_t id = 0x000000;
|
||||||
DesfireISOSelectWay selectway = ISW6bAID;
|
DesfireISOSelectWay selectway = ISW6bAID;
|
||||||
|
@ -4406,7 +4406,7 @@ static int CmdHF14ADesClearRecordFile(const char *Cmd) {
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int DesfileReadISOFileAndPrint(DesfireContext *dctx, bool select_current_file, uint8_t fnum, uint16_t fisoid, int filetype, uint32_t offset, uint32_t length, bool noauth, bool verbose) {
|
static int DesfileReadISOFileAndPrint(DesfireContext_t *dctx, bool select_current_file, uint8_t fnum, uint16_t fisoid, int filetype, uint32_t offset, uint32_t length, bool noauth, bool verbose) {
|
||||||
|
|
||||||
if (filetype == RFTAuto) {
|
if (filetype == RFTAuto) {
|
||||||
PrintAndLogEx(ERR, "ISO mode needs to specify file type");
|
PrintAndLogEx(ERR, "ISO mode needs to specify file type");
|
||||||
|
@ -4500,7 +4500,7 @@ static int DesfileReadISOFileAndPrint(DesfireContext *dctx, bool select_current_
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int DesfileReadFileAndPrint(DesfireContext *dctx, uint8_t fnum, int filetype, uint32_t offset, uint32_t length, uint32_t maxdatafilelength, bool noauth, bool verbose) {
|
static int DesfileReadFileAndPrint(DesfireContext_t *dctx, uint8_t fnum, int filetype, uint32_t offset, uint32_t length, uint32_t maxdatafilelength, bool noauth, bool verbose) {
|
||||||
int res = 0;
|
int res = 0;
|
||||||
// length of record for record file
|
// length of record for record file
|
||||||
size_t reclen = 0;
|
size_t reclen = 0;
|
||||||
|
@ -4510,11 +4510,11 @@ static int DesfileReadFileAndPrint(DesfireContext *dctx, uint8_t fnum, int filet
|
||||||
|
|
||||||
// get file settings
|
// get file settings
|
||||||
if (filetype == RFTAuto) {
|
if (filetype == RFTAuto) {
|
||||||
FileSettingsS fsettings;
|
FileSettings_t fsettings;
|
||||||
|
|
||||||
DesfireCommunicationMode commMode = dctx->commMode;
|
DesfireCommunicationMode commMode = dctx->commMode;
|
||||||
DesfireSetCommMode(dctx, DCMMACed);
|
DesfireSetCommMode(dctx, DCMMACed);
|
||||||
res = DesfireGetFileSettingsStruct(dctx, fnum, &fsettings);
|
res = DesfireFileSettingsStruct(dctx, fnum, &fsettings);
|
||||||
DesfireSetCommMode(dctx, commMode);
|
DesfireSetCommMode(dctx, commMode);
|
||||||
|
|
||||||
if (res == PM3_SUCCESS) {
|
if (res == PM3_SUCCESS) {
|
||||||
|
@ -4734,7 +4734,7 @@ static int CmdHF14ADesReadData(const char *Cmd) {
|
||||||
bool verbose = arg_get_lit(ctx, 2);
|
bool verbose = arg_get_lit(ctx, 2);
|
||||||
bool noauth = arg_get_lit(ctx, 13);
|
bool noauth = arg_get_lit(ctx, 13);
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
uint32_t id = 0x000000;
|
uint32_t id = 0x000000;
|
||||||
DesfireISOSelectWay selectway = ISW6bAID;
|
DesfireISOSelectWay selectway = ISW6bAID;
|
||||||
|
@ -4801,7 +4801,7 @@ static int CmdHF14ADesReadData(const char *Cmd) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int DesfileWriteISOFile(DesfireContext *dctx, bool select_current_file, uint8_t fnum, uint16_t fisoid, int filetype, uint32_t offset, uint8_t *data, uint32_t datalen, bool verbose) {
|
static int DesfileWriteISOFile(DesfireContext_t *dctx, bool select_current_file, uint8_t fnum, uint16_t fisoid, int filetype, uint32_t offset, uint8_t *data, uint32_t datalen, bool verbose) {
|
||||||
|
|
||||||
if (filetype == RFTAuto) {
|
if (filetype == RFTAuto) {
|
||||||
PrintAndLogEx(ERR, "ISO mode needs to specify file type");
|
PrintAndLogEx(ERR, "ISO mode needs to specify file type");
|
||||||
|
@ -4905,7 +4905,7 @@ static int CmdHF14ADesWriteData(const char *Cmd) {
|
||||||
bool verbose = arg_get_lit(ctx, 2);
|
bool verbose = arg_get_lit(ctx, 2);
|
||||||
bool noauth = arg_get_lit(ctx, 13);
|
bool noauth = arg_get_lit(ctx, 13);
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
uint32_t id = 0x000000;
|
uint32_t id = 0x000000;
|
||||||
DesfireISOSelectWay selectway = ISW6bAID;
|
DesfireISOSelectWay selectway = ISW6bAID;
|
||||||
|
@ -5006,11 +5006,11 @@ static int CmdHF14ADesWriteData(const char *Cmd) {
|
||||||
|
|
||||||
// get file settings
|
// get file settings
|
||||||
if (op == RFTAuto) {
|
if (op == RFTAuto) {
|
||||||
FileSettingsS fsettings;
|
FileSettings_t fsettings;
|
||||||
|
|
||||||
DesfireCommunicationMode commMode = dctx.commMode;
|
DesfireCommunicationMode commMode = dctx.commMode;
|
||||||
DesfireSetCommMode(&dctx, DCMMACed);
|
DesfireSetCommMode(&dctx, DCMMACed);
|
||||||
res = DesfireGetFileSettingsStruct(&dctx, fnum, &fsettings);
|
res = DesfireFileSettingsStruct(&dctx, fnum, &fsettings);
|
||||||
DesfireSetCommMode(&dctx, commMode);
|
DesfireSetCommMode(&dctx, commMode);
|
||||||
|
|
||||||
if (res == PM3_SUCCESS) {
|
if (res == PM3_SUCCESS) {
|
||||||
|
@ -5233,7 +5233,7 @@ static int CmdHF14ADesLsFiles(const char *Cmd) {
|
||||||
bool verbose = arg_get_lit(ctx, 2);
|
bool verbose = arg_get_lit(ctx, 2);
|
||||||
bool noauth = arg_get_lit(ctx, 13);
|
bool noauth = arg_get_lit(ctx, 13);
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
uint32_t id = 0x000000;
|
uint32_t id = 0x000000;
|
||||||
DesfireISOSelectWay selectway = ISW6bAID;
|
DesfireISOSelectWay selectway = ISW6bAID;
|
||||||
|
@ -5253,7 +5253,7 @@ static int CmdHF14ADesLsFiles(const char *Cmd) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileListS FileList = {0};
|
FileList_t FileList = {0};
|
||||||
size_t filescount = 0;
|
size_t filescount = 0;
|
||||||
bool isopresent = false;
|
bool isopresent = false;
|
||||||
res = DesfireFillFileList(&dctx, FileList, &filescount, &isopresent);
|
res = DesfireFillFileList(&dctx, FileList, &filescount, &isopresent);
|
||||||
|
@ -5308,7 +5308,7 @@ static int CmdHF14ADesLsApp(const char *Cmd) {
|
||||||
bool nodeep = arg_get_lit(ctx, 12);
|
bool nodeep = arg_get_lit(ctx, 12);
|
||||||
bool scanfiles = arg_get_lit(ctx, 13);
|
bool scanfiles = arg_get_lit(ctx, 13);
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 0, 0, &securechann, (noauth) ? DCMPlain : DCMMACed, NULL, NULL);
|
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 0, 0, &securechann, (noauth) ? DCMPlain : DCMMACed, NULL, NULL);
|
||||||
if (res) {
|
if (res) {
|
||||||
|
@ -5327,7 +5327,7 @@ static int CmdHF14ADesLsApp(const char *Cmd) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
PICCInfoS PICCInfo = {0};
|
PICCInfo_t PICCInfo = {0};
|
||||||
AppListS AppList = {0};
|
AppListS AppList = {0};
|
||||||
DesfireFillAppList(&dctx, &PICCInfo, AppList, !nodeep, scanfiles, true);
|
DesfireFillAppList(&dctx, &PICCInfo, AppList, !nodeep, scanfiles, true);
|
||||||
|
|
||||||
|
@ -5373,7 +5373,7 @@ static int CmdHF14ADesDump(const char *Cmd) {
|
||||||
bool verbose = arg_get_lit(ctx, 2);
|
bool verbose = arg_get_lit(ctx, 2);
|
||||||
bool noauth = arg_get_lit(ctx, 14);
|
bool noauth = arg_get_lit(ctx, 14);
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
int securechann = defaultSecureChannel;
|
int securechann = defaultSecureChannel;
|
||||||
uint32_t id = 0x000000;
|
uint32_t id = 0x000000;
|
||||||
DesfireISOSelectWay selectway = ISW6bAID;
|
DesfireISOSelectWay selectway = ISW6bAID;
|
||||||
|
@ -5399,7 +5399,7 @@ static int CmdHF14ADesDump(const char *Cmd) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileListS FileList = {0};
|
FileList_t FileList = {0};
|
||||||
size_t filescount = 0;
|
size_t filescount = 0;
|
||||||
bool isopresent = false;
|
bool isopresent = false;
|
||||||
res = DesfireFillFileList(&dctx, FileList, &filescount, &isopresent);
|
res = DesfireFillFileList(&dctx, FileList, &filescount, &isopresent);
|
||||||
|
|
|
@ -38,7 +38,7 @@ typedef struct {
|
||||||
uint32_t colorreq;
|
uint32_t colorreq;
|
||||||
uint32_t Color_1; //Color palette
|
uint32_t Color_1; //Color palette
|
||||||
uint32_t Color_2;
|
uint32_t Color_2;
|
||||||
} PACKED BMP_HEADER;
|
} PACKED bmp_header_t;
|
||||||
|
|
||||||
#define EPD_1IN54B 0
|
#define EPD_1IN54B 0
|
||||||
#define EPD_1IN54C 1
|
#define EPD_1IN54C 1
|
||||||
|
@ -92,11 +92,11 @@ static model_t models[] = {
|
||||||
static int CmdHelp(const char *Cmd);
|
static int CmdHelp(const char *Cmd);
|
||||||
|
|
||||||
static int picture_bit_depth(const uint8_t *bmp, const size_t bmpsize, const uint8_t model_nr) {
|
static int picture_bit_depth(const uint8_t *bmp, const size_t bmpsize, const uint8_t model_nr) {
|
||||||
if (bmpsize < sizeof(BMP_HEADER)) {
|
if (bmpsize < sizeof(bmp_header_t)) {
|
||||||
return PM3_ESOFT;
|
return PM3_ESOFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
BMP_HEADER *pbmpheader = (BMP_HEADER *)bmp;
|
bmp_header_t *pbmpheader = (bmp_header_t *)bmp;
|
||||||
PrintAndLogEx(DEBUG, "colorsused = %d", pbmpheader->colorsused);
|
PrintAndLogEx(DEBUG, "colorsused = %d", pbmpheader->colorsused);
|
||||||
PrintAndLogEx(DEBUG, "pbmpheader->bpp = %d", pbmpheader->bpp);
|
PrintAndLogEx(DEBUG, "pbmpheader->bpp = %d", pbmpheader->bpp);
|
||||||
if ((pbmpheader->BMP_Width != models[model_nr].width) || (pbmpheader->BMP_Height != models[model_nr].height)) {
|
if ((pbmpheader->BMP_Width != models[model_nr].width) || (pbmpheader->BMP_Height != models[model_nr].height)) {
|
||||||
|
@ -106,7 +106,7 @@ static int picture_bit_depth(const uint8_t *bmp, const size_t bmpsize, const uin
|
||||||
}
|
}
|
||||||
|
|
||||||
static int read_bmp_bitmap(const uint8_t *bmp, const size_t bmpsize, uint8_t model_nr, uint8_t **black, uint8_t **red) {
|
static int read_bmp_bitmap(const uint8_t *bmp, const size_t bmpsize, uint8_t model_nr, uint8_t **black, uint8_t **red) {
|
||||||
BMP_HEADER *pbmpheader = (BMP_HEADER *)bmp;
|
bmp_header_t *pbmpheader = (bmp_header_t *)bmp;
|
||||||
// check file is bitmap
|
// check file is bitmap
|
||||||
if (pbmpheader->bpp != 1) {
|
if (pbmpheader->bpp != 1) {
|
||||||
return PM3_ESOFT;
|
return PM3_ESOFT;
|
||||||
|
@ -345,7 +345,7 @@ static void map8to1(uint8_t *colormap, uint16_t width, uint16_t height, uint8_t
|
||||||
}
|
}
|
||||||
|
|
||||||
static int read_bmp_rgb(uint8_t *bmp, const size_t bmpsize, uint8_t model_nr, uint8_t **black, uint8_t **red, char *filename, bool save_conversions) {
|
static int read_bmp_rgb(uint8_t *bmp, const size_t bmpsize, uint8_t model_nr, uint8_t **black, uint8_t **red, char *filename, bool save_conversions) {
|
||||||
BMP_HEADER *pbmpheader = (BMP_HEADER *)bmp;
|
bmp_header_t *pbmpheader = (bmp_header_t *)bmp;
|
||||||
// check file is full color
|
// check file is full color
|
||||||
if ((pbmpheader->bpp != 24) && (pbmpheader->bpp != 32)) {
|
if ((pbmpheader->bpp != 24) && (pbmpheader->bpp != 32)) {
|
||||||
return PM3_ESOFT;
|
return PM3_ESOFT;
|
||||||
|
|
|
@ -41,9 +41,9 @@ const char *TransactionTypeStr[] = {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
enum CardPSVendor vendor;
|
enum CardPSVendor vendor;
|
||||||
const char *aid;
|
const char *aid;
|
||||||
} TAIDList;
|
} AIDList_t;
|
||||||
|
|
||||||
static const TAIDList AIDlist [] = {
|
static const AIDList_t AIDlist [] = {
|
||||||
// Visa International
|
// Visa International
|
||||||
{ CV_VISA, "A00000000305076010" }, // VISA ELO Credit
|
{ CV_VISA, "A00000000305076010" }, // VISA ELO Credit
|
||||||
{ CV_VISA, "A0000000031010" }, // VISA Debit/Credit (Classic)
|
{ CV_VISA, "A0000000031010" }, // VISA Debit/Credit (Classic)
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
#include "fileutils.h"
|
#include "fileutils.h"
|
||||||
#include "pm3_cmd.h"
|
#include "pm3_cmd.h"
|
||||||
|
|
||||||
static const ApplicationDataElm ApplicationData[] = {
|
static const ApplicationDataElm_t ApplicationData[] = {
|
||||||
{0x82, "AIP"},
|
{0x82, "AIP"},
|
||||||
{0x94, "AFL"},
|
{0x94, "AFL"},
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
typedef struct {
|
typedef struct {
|
||||||
tlv_tag_t Tag;
|
tlv_tag_t Tag;
|
||||||
const char *Name;
|
const char *Name;
|
||||||
} ApplicationDataElm;
|
} ApplicationDataElm_t;
|
||||||
|
|
||||||
const char *GetApplicationDataName(tlv_tag_t tag);
|
const char *GetApplicationDataName(tlv_tag_t tag);
|
||||||
|
|
||||||
|
|
|
@ -60,14 +60,14 @@ typedef struct {
|
||||||
uint8_t r;
|
uint8_t r;
|
||||||
uint8_t b;
|
uint8_t b;
|
||||||
uint16_t t;
|
uint16_t t;
|
||||||
} State;
|
} State_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Definition 2. The feedback function for the top register T : F 16/2 → F 2
|
* Definition 2. The feedback function for the top register T : F 16/2 → F 2
|
||||||
* is defined as
|
* is defined as
|
||||||
* T (x 0 x 1 . . . . . . x 15 ) = x 0 ⊕ x 1 ⊕ x 5 ⊕ x 7 ⊕ x 10 ⊕ x 11 ⊕ x 14 ⊕ x 15 .
|
* T (x 0 x 1 . . . . . . x 15 ) = x 0 ⊕ x 1 ⊕ x 5 ⊕ x 7 ⊕ x 10 ⊕ x 11 ⊕ x 14 ⊕ x 15 .
|
||||||
**/
|
**/
|
||||||
static bool T(State state) {
|
static bool T(State_t state) {
|
||||||
/*
|
/*
|
||||||
bool x0 = state.t & 0x8000;
|
bool x0 = state.t & 0x8000;
|
||||||
bool x1 = state.t & 0x4000;
|
bool x1 = state.t & 0x4000;
|
||||||
|
@ -93,7 +93,7 @@ static bool T(State state) {
|
||||||
* Similarly, the feedback function for the bottom register B : F 8/2 → F 2 is defined as
|
* Similarly, the feedback function for the bottom register B : F 8/2 → F 2 is defined as
|
||||||
* B(x 0 x 1 . . . x 7 ) = x 1 ⊕ x 2 ⊕ x 3 ⊕ x 7 .
|
* B(x 0 x 1 . . . x 7 ) = x 1 ⊕ x 2 ⊕ x 3 ⊕ x 7 .
|
||||||
**/
|
**/
|
||||||
/*static bool B(State state) {
|
/*static bool B(State_t state) {
|
||||||
bool x1 = state.b & 0x40;
|
bool x1 = state.b & 0x40;
|
||||||
bool x2 = state.b & 0x20;
|
bool x2 = state.b & 0x20;
|
||||||
bool x3 = state.b & 0x10;
|
bool x3 = state.b & 0x10;
|
||||||
|
@ -169,12 +169,12 @@ static uint8_t _select(bool x, bool y, uint8_t r) {
|
||||||
* @param s - state
|
* @param s - state
|
||||||
* @param k - array containing 8 bytes
|
* @param k - array containing 8 bytes
|
||||||
**/
|
**/
|
||||||
static State successor(uint8_t *k, State s, bool y) {
|
static State_t successor(uint8_t *k, State_t s, bool y) {
|
||||||
bool r0 = s.r >> 7 & 0x1;
|
bool r0 = s.r >> 7 & 0x1;
|
||||||
bool r4 = s.r >> 3 & 0x1;
|
bool r4 = s.r >> 3 & 0x1;
|
||||||
bool r7 = s.r & 0x1;
|
bool r7 = s.r & 0x1;
|
||||||
|
|
||||||
State successor = {0, 0, 0, 0};
|
State_t successor = {0, 0, 0, 0};
|
||||||
|
|
||||||
successor.t = s.t >> 1;
|
successor.t = s.t >> 1;
|
||||||
successor.t |= ((T(s)) ^ (r0) ^ (r4)) << 15;
|
successor.t |= ((T(s)) ^ (r0) ^ (r4)) << 15;
|
||||||
|
@ -195,7 +195,7 @@ static State successor(uint8_t *k, State s, bool y) {
|
||||||
* to multiple bit input x ∈ F n 2 which we define as
|
* to multiple bit input x ∈ F n 2 which we define as
|
||||||
* @param k - array containing 8 bytes
|
* @param k - array containing 8 bytes
|
||||||
**/
|
**/
|
||||||
static State suc(uint8_t *k, State s, BitstreamIn *bitstream) {
|
static State_t suc(uint8_t *k, State_t s, BitstreamIn_t *bitstream) {
|
||||||
if (bitsLeft(bitstream) == 0) {
|
if (bitsLeft(bitstream) == 0) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
@ -211,14 +211,14 @@ static State suc(uint8_t *k, State s, BitstreamIn *bitstream) {
|
||||||
* output(k, s, x 0 . . . x n ) = output(s) · output(k, s ′ , x 1 . . . x n )
|
* output(k, s, x 0 . . . x n ) = output(s) · output(k, s ′ , x 1 . . . x n )
|
||||||
* where s ′ = suc(k, s, x 0 ).
|
* where s ′ = suc(k, s, x 0 ).
|
||||||
**/
|
**/
|
||||||
static void output(uint8_t *k, State s, BitstreamIn *in, BitstreamOut *out) {
|
static void output(uint8_t *k, State_t s, BitstreamIn_t *in, BitstreamOut_t *out) {
|
||||||
if (bitsLeft(in) == 0) {
|
if (bitsLeft(in) == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pushBit(out, (s.r >> 2) & 1);
|
pushBit(out, (s.r >> 2) & 1);
|
||||||
//Remove first bit
|
//Remove first bit
|
||||||
uint8_t x0 = headBit(in);
|
uint8_t x0 = headBit(in);
|
||||||
State ss = successor(k, s, x0);
|
State_t ss = successor(k, s, x0);
|
||||||
output(k, ss, in, out);
|
output(k, ss, in, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,8 +227,8 @@ static void output(uint8_t *k, State s, BitstreamIn *in, BitstreamOut *out) {
|
||||||
* key k ∈ (F 82 ) 8 and outputs the initial cipher state s =< l, r, t, b >
|
* key k ∈ (F 82 ) 8 and outputs the initial cipher state s =< l, r, t, b >
|
||||||
**/
|
**/
|
||||||
|
|
||||||
static State init(uint8_t *k) {
|
static State_t init(uint8_t *k) {
|
||||||
State s = {
|
State_t s = {
|
||||||
((k[0] ^ 0x4c) + 0xEC) & 0xFF,// l
|
((k[0] ^ 0x4c) + 0xEC) & 0xFF,// l
|
||||||
((k[0] ^ 0x4c) + 0x21) & 0xFF,// r
|
((k[0] ^ 0x4c) + 0x21) & 0xFF,// r
|
||||||
0x4c, // b
|
0x4c, // b
|
||||||
|
@ -237,10 +237,10 @@ static State init(uint8_t *k) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void MAC(uint8_t *k, BitstreamIn input, BitstreamOut out) {
|
static void MAC(uint8_t *k, BitstreamIn_t input, BitstreamOut_t out) {
|
||||||
uint8_t zeroes_32[] = {0, 0, 0, 0};
|
uint8_t zeroes_32[] = {0, 0, 0, 0};
|
||||||
BitstreamIn input_32_zeroes = {zeroes_32, sizeof(zeroes_32) * 8, 0};
|
BitstreamIn_t input_32_zeroes = {zeroes_32, sizeof(zeroes_32) * 8, 0};
|
||||||
State initState = suc(k, init(k), &input);
|
State_t initState = suc(k, init(k), &input);
|
||||||
output(k, initState, &input_32_zeroes, &out);
|
output(k, initState, &input_32_zeroes, &out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,9 +252,9 @@ void doMAC(uint8_t *cc_nr_p, uint8_t *div_key_p, uint8_t mac[4]) {
|
||||||
memcpy(div_key, div_key_p, 8);
|
memcpy(div_key, div_key_p, 8);
|
||||||
|
|
||||||
reverse_arraybytes(cc_nr, 12);
|
reverse_arraybytes(cc_nr, 12);
|
||||||
BitstreamIn bitstream = {cc_nr, 12 * 8, 0};
|
BitstreamIn_t bitstream = {cc_nr, 12 * 8, 0};
|
||||||
uint8_t dest [] = {0, 0, 0, 0, 0, 0, 0, 0};
|
uint8_t dest [] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
BitstreamOut out = { dest, sizeof(dest) * 8, 0 };
|
BitstreamOut_t out = { dest, sizeof(dest) * 8, 0 };
|
||||||
MAC(div_key, bitstream, out);
|
MAC(div_key, bitstream, out);
|
||||||
//The output MAC must also be reversed
|
//The output MAC must also be reversed
|
||||||
reverse_arraybytes(dest, sizeof(dest));
|
reverse_arraybytes(dest, sizeof(dest));
|
||||||
|
@ -270,9 +270,9 @@ void doMAC_N(uint8_t *address_data_p, uint8_t address_data_size, uint8_t *div_ke
|
||||||
memcpy(div_key, div_key_p, 8);
|
memcpy(div_key, div_key_p, 8);
|
||||||
|
|
||||||
reverse_arraybytes(address_data, address_data_size);
|
reverse_arraybytes(address_data, address_data_size);
|
||||||
BitstreamIn bitstream = {address_data, address_data_size * 8, 0};
|
BitstreamIn_t bitstream = {address_data, address_data_size * 8, 0};
|
||||||
uint8_t dest [] = {0, 0, 0, 0, 0, 0, 0, 0};
|
uint8_t dest [] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
BitstreamOut out = { dest, sizeof(dest) * 8, 0 };
|
BitstreamOut_t out = { dest, sizeof(dest) * 8, 0 };
|
||||||
MAC(div_key, bitstream, out);
|
MAC(div_key, bitstream, out);
|
||||||
//The output MAC must also be reversed
|
//The output MAC must also be reversed
|
||||||
reverse_arraybytes(dest, sizeof(dest));
|
reverse_arraybytes(dest, sizeof(dest));
|
||||||
|
|
|
@ -49,7 +49,7 @@
|
||||||
* @param stream
|
* @param stream
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
bool headBit(BitstreamIn *stream) {
|
bool headBit(BitstreamIn_t *stream) {
|
||||||
int bytepos = stream->position >> 3; // divide by 8
|
int bytepos = stream->position >> 3; // divide by 8
|
||||||
int bitpos = (stream->position++) & 7; // mask out 00000111
|
int bitpos = (stream->position++) & 7; // mask out 00000111
|
||||||
return (*(stream->buffer + bytepos) >> (7 - bitpos)) & 1;
|
return (*(stream->buffer + bytepos) >> (7 - bitpos)) & 1;
|
||||||
|
@ -59,7 +59,7 @@ bool headBit(BitstreamIn *stream) {
|
||||||
* @param stream
|
* @param stream
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
bool tailBit(BitstreamIn *stream) {
|
bool tailBit(BitstreamIn_t *stream) {
|
||||||
int bitpos = stream->numbits - 1 - (stream->position++);
|
int bitpos = stream->numbits - 1 - (stream->position++);
|
||||||
|
|
||||||
int bytepos = bitpos >> 3;
|
int bytepos = bitpos >> 3;
|
||||||
|
@ -71,7 +71,7 @@ bool tailBit(BitstreamIn *stream) {
|
||||||
* @param stream
|
* @param stream
|
||||||
* @param bit
|
* @param bit
|
||||||
*/
|
*/
|
||||||
void pushBit(BitstreamOut *stream, bool bit) {
|
void pushBit(BitstreamOut_t *stream, bool bit) {
|
||||||
int bytepos = stream->position >> 3; // divide by 8
|
int bytepos = stream->position >> 3; // divide by 8
|
||||||
int bitpos = stream->position & 7;
|
int bitpos = stream->position & 7;
|
||||||
*(stream->buffer + bytepos) |= (bit) << (7 - bitpos);
|
*(stream->buffer + bytepos) |= (bit) << (7 - bitpos);
|
||||||
|
@ -85,7 +85,7 @@ void pushBit(BitstreamOut *stream, bool bit) {
|
||||||
* @param stream
|
* @param stream
|
||||||
* @param bits
|
* @param bits
|
||||||
*/
|
*/
|
||||||
void push6bits(BitstreamOut *stream, uint8_t bits) {
|
void push6bits(BitstreamOut_t *stream, uint8_t bits) {
|
||||||
pushBit(stream, bits & 0x20);
|
pushBit(stream, bits & 0x20);
|
||||||
pushBit(stream, bits & 0x10);
|
pushBit(stream, bits & 0x10);
|
||||||
pushBit(stream, bits & 0x08);
|
pushBit(stream, bits & 0x08);
|
||||||
|
@ -99,7 +99,7 @@ void push6bits(BitstreamOut *stream, uint8_t bits) {
|
||||||
* @param stream
|
* @param stream
|
||||||
* @return number of bits left in stream
|
* @return number of bits left in stream
|
||||||
*/
|
*/
|
||||||
int bitsLeft(BitstreamIn *stream) {
|
int bitsLeft(BitstreamIn_t *stream) {
|
||||||
return stream->numbits - stream->position;
|
return stream->numbits - stream->position;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -108,7 +108,7 @@ int bitsLeft(BitstreamIn *stream) {
|
||||||
* @return Number of bits stored in stream
|
* @return Number of bits stored in stream
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
static int numBits(BitstreamOut *stream) {
|
static int numBits(BitstreamOut_t *stream) {
|
||||||
return stream->numbits;
|
return stream->numbits;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
@ -187,8 +187,8 @@ void printarr_human_readable(const char *title, uint8_t *arr, int len) {
|
||||||
static int testBitStream(void) {
|
static int testBitStream(void) {
|
||||||
uint8_t input [] = {0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF};
|
uint8_t input [] = {0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF};
|
||||||
uint8_t output [] = {0, 0, 0, 0, 0, 0, 0, 0};
|
uint8_t output [] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
BitstreamIn in = { input, sizeof(input) * 8, 0};
|
BitstreamIn_t in = { input, sizeof(input) * 8, 0};
|
||||||
BitstreamOut out = { output, 0, 0}
|
BitstreamOut_t out = { output, 0, 0}
|
||||||
;
|
;
|
||||||
while (bitsLeft(&in) > 0) {
|
while (bitsLeft(&in) > 0) {
|
||||||
pushBit(&out, headBit(&in));
|
pushBit(&out, headBit(&in));
|
||||||
|
@ -213,10 +213,10 @@ static int testReversedBitstream(void) {
|
||||||
uint8_t input [] = {0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF};
|
uint8_t input [] = {0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF};
|
||||||
uint8_t reverse [] = {0, 0, 0, 0, 0, 0, 0, 0};
|
uint8_t reverse [] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
uint8_t output [] = {0, 0, 0, 0, 0, 0, 0, 0};
|
uint8_t output [] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
BitstreamIn in = { input, sizeof(input) * 8, 0};
|
BitstreamIn_t in = { input, sizeof(input) * 8, 0};
|
||||||
BitstreamOut out = { output, 0, 0};
|
BitstreamOut_t out = { output, 0, 0};
|
||||||
BitstreamIn reversed_in = { reverse, sizeof(input) * 8, 0};
|
BitstreamIn_t reversed_in = { reverse, sizeof(input) * 8, 0};
|
||||||
BitstreamOut reversed_out = { reverse, 0, 0};
|
BitstreamOut_t reversed_out = { reverse, 0, 0};
|
||||||
|
|
||||||
while (bitsLeft(&in) > 0) {
|
while (bitsLeft(&in) > 0) {
|
||||||
pushBit(&reversed_out, tailBit(&in));
|
pushBit(&reversed_out, tailBit(&in));
|
||||||
|
|
|
@ -47,22 +47,22 @@ typedef struct {
|
||||||
uint8_t *buffer;
|
uint8_t *buffer;
|
||||||
uint8_t numbits;
|
uint8_t numbits;
|
||||||
uint8_t position;
|
uint8_t position;
|
||||||
} BitstreamIn;
|
} BitstreamIn_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t *buffer;
|
uint8_t *buffer;
|
||||||
uint8_t numbits;
|
uint8_t numbits;
|
||||||
uint8_t position;
|
uint8_t position;
|
||||||
} BitstreamOut;
|
} BitstreamOut_t;
|
||||||
|
|
||||||
bool headBit(BitstreamIn *stream);
|
bool headBit(BitstreamIn_t *stream);
|
||||||
bool tailBit(BitstreamIn *stream);
|
bool tailBit(BitstreamIn_t *stream);
|
||||||
void pushBit(BitstreamOut *stream, bool bit);
|
void pushBit(BitstreamOut_t *stream, bool bit);
|
||||||
int bitsLeft(BitstreamIn *stream);
|
int bitsLeft(BitstreamIn_t *stream);
|
||||||
#ifndef ON_DEVICE
|
#ifndef ON_DEVICE
|
||||||
int testCipherUtils(void);
|
int testCipherUtils(void);
|
||||||
#endif
|
#endif
|
||||||
void push6bits(BitstreamOut *stream, uint8_t bits);
|
void push6bits(BitstreamOut_t *stream, uint8_t bits);
|
||||||
void EncryptDES(bool key[56], bool outBlk[64], bool inBlk[64], int verbose) ;
|
void EncryptDES(bool key[56], bool outBlk[64], bool inBlk[64], int verbose) ;
|
||||||
void x_num_to_bytes(uint64_t n, size_t len, uint8_t *dest);
|
void x_num_to_bytes(uint64_t n, size_t len, uint8_t *dest);
|
||||||
uint64_t x_bytes_to_num(uint8_t *src, size_t len);
|
uint64_t x_bytes_to_num(uint8_t *src, size_t len);
|
||||||
|
|
|
@ -205,7 +205,7 @@ static uint64_t check(uint64_t z) {
|
||||||
return ck1 | ck2 >> 24;
|
return ck1 | ck2 >> 24;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void permute(BitstreamIn *p_in, uint64_t z, int l, int r, BitstreamOut *out) {
|
static void permute(BitstreamIn_t *p_in, uint64_t z, int l, int r, BitstreamOut_t *out) {
|
||||||
if (bitsLeft(p_in) == 0)
|
if (bitsLeft(p_in) == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -290,9 +290,9 @@ void hash0(uint64_t c, uint8_t k[8]) {
|
||||||
|
|
||||||
if (g_debugMode > 0) PrintAndLogEx(DEBUG, " p : %02x", p);
|
if (g_debugMode > 0) PrintAndLogEx(DEBUG, " p : %02x", p);
|
||||||
|
|
||||||
BitstreamIn p_in = { &p, 8, 0 };
|
BitstreamIn_t p_in = { &p, 8, 0 };
|
||||||
uint8_t outbuffer[] = {0, 0, 0, 0, 0, 0, 0, 0};
|
uint8_t outbuffer[] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
BitstreamOut out = {outbuffer, 0, 0};
|
BitstreamOut_t out = {outbuffer, 0, 0};
|
||||||
permute(&p_in, zCaret, 0, 4, &out); //returns 48 bits? or 6 8-bytes
|
permute(&p_in, zCaret, 0, 4, &out); //returns 48 bits? or 6 8-bytes
|
||||||
|
|
||||||
//Out is now a buffer containing six-bit bytes, should be 48 bits
|
//Out is now a buffer containing six-bit bytes, should be 48 bits
|
||||||
|
@ -387,9 +387,9 @@ static void testPermute(void) {
|
||||||
printarr("input_perm", mres, 8);
|
printarr("input_perm", mres, 8);
|
||||||
|
|
||||||
uint8_t p = ~pi[0];
|
uint8_t p = ~pi[0];
|
||||||
BitstreamIn p_in = { &p, 8, 0 };
|
BitstreamIn_t p_in = { &p, 8, 0 };
|
||||||
uint8_t outbuffer[] = {0, 0, 0, 0, 0, 0, 0, 0};
|
uint8_t outbuffer[] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
BitstreamOut out = {outbuffer, 0, 0};
|
BitstreamOut_t out = {outbuffer, 0, 0};
|
||||||
|
|
||||||
permute(&p_in, x, 0, 4, &out);
|
permute(&p_in, x, 0, 4, &out);
|
||||||
|
|
||||||
|
@ -708,7 +708,7 @@ void checkParity2(uint8_t* key) {
|
||||||
uint8_t stored_parity = key[7];
|
uint8_t stored_parity = key[7];
|
||||||
PrintAndLogEx(NORMAL, "Parity byte: 0x%02x", stored_parity);
|
PrintAndLogEx(NORMAL, "Parity byte: 0x%02x", stored_parity);
|
||||||
int i, byte, fails = 0;
|
int i, byte, fails = 0;
|
||||||
BitstreamIn bits = {key, 56, 0};
|
BitstreamIn_t bits = {key, 56, 0};
|
||||||
bool parity = 0;
|
bool parity = 0;
|
||||||
|
|
||||||
for (i = 0; i < 56; i++) {
|
for (i = 0; i < 56; i++) {
|
||||||
|
@ -736,7 +736,7 @@ void modifyKey_put_parity_last(uint8_t * key, uint8_t* output) {
|
||||||
|
|
||||||
uint8_t paritybits = 0;
|
uint8_t paritybits = 0;
|
||||||
bool parity =0;
|
bool parity =0;
|
||||||
BitstreamOut out = { output, 0, 0};
|
BitstreamOut_t out = { output, 0, 0};
|
||||||
unsigned int bbyte, bbit;
|
unsigned int bbyte, bbit;
|
||||||
for (bbyte = 0; bbyte <8; bbyte++ ) {
|
for (bbyte = 0; bbyte <8; bbyte++ ) {
|
||||||
for(bbit = 0; bbit < 7; bbit++) {
|
for(bbit = 0; bbit < 7; bbit++) {
|
||||||
|
@ -760,8 +760,8 @@ void modifyKey_put_parity_last(uint8_t * key, uint8_t* output) {
|
||||||
|
|
||||||
void modifyKey_put_parity_allover(uint8_t * key, uint8_t* output) {
|
void modifyKey_put_parity_allover(uint8_t * key, uint8_t* output) {
|
||||||
bool parity =0;
|
bool parity =0;
|
||||||
BitstreamOut out = {output, 0, 0};
|
BitstreamOut_t out = {output, 0, 0};
|
||||||
BitstreamIn in = {key, 0, 0};
|
BitstreamIn_t in = {key, 0, 0};
|
||||||
unsigned int bbyte, bbit;
|
unsigned int bbyte, bbit;
|
||||||
for (bbit = 0; bbit < 56; bbit++) {
|
for (bbit = 0; bbit < 56; bbit++) {
|
||||||
if (bbit > 0 && bbit % 7 == 0) {
|
if (bbit > 0 && bbit % 7 == 0) {
|
||||||
|
|
|
@ -378,7 +378,7 @@ static uint8_t DesfireGetRndLenForKey(DesfireCryptoAlgorythm keytype) {
|
||||||
return 0x00;
|
return 0x00;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesfirePrintContext(DesfireContext *ctx) {
|
void DesfirePrintContext(DesfireContext_t *ctx) {
|
||||||
PrintAndLogEx(INFO, "Key num: %d Key algo: %s Key[%d]: %s",
|
PrintAndLogEx(INFO, "Key num: %d Key algo: %s Key[%d]: %s",
|
||||||
ctx->keyNum,
|
ctx->keyNum,
|
||||||
CLIGetOptionListStr(DesfireAlgoOpts, ctx->keyType),
|
CLIGetOptionListStr(DesfireAlgoOpts, ctx->keyType),
|
||||||
|
@ -524,7 +524,7 @@ static int DESFIRESendRaw(bool activate_field, uint8_t *data, size_t datalen, ui
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int DesfireExchangeNative(bool activate_field, DesfireContext *ctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *respcode, uint8_t *resp, size_t *resplen, bool enable_chaining, size_t splitbysize) {
|
static int DesfireExchangeNative(bool activate_field, DesfireContext_t *ctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *respcode, uint8_t *resp, size_t *resplen, bool enable_chaining, size_t splitbysize) {
|
||||||
if (resplen)
|
if (resplen)
|
||||||
*resplen = 0;
|
*resplen = 0;
|
||||||
if (respcode)
|
if (respcode)
|
||||||
|
@ -630,7 +630,7 @@ static int DesfireExchangeNative(bool activate_field, DesfireContext *ctx, uint8
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int DesfireExchangeISONative(bool activate_field, DesfireContext *ctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *respcode, uint8_t *resp, size_t *resplen, bool enable_chaining, size_t splitbysize) {
|
static int DesfireExchangeISONative(bool activate_field, DesfireContext_t *ctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *respcode, uint8_t *resp, size_t *resplen, bool enable_chaining, size_t splitbysize) {
|
||||||
if (resplen)
|
if (resplen)
|
||||||
*resplen = 0;
|
*resplen = 0;
|
||||||
if (respcode)
|
if (respcode)
|
||||||
|
@ -736,7 +736,7 @@ static int DesfireExchangeISONative(bool activate_field, DesfireContext *ctx, ui
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int DesfireExchangeISO(bool activate_field, DesfireContext *ctx, sAPDU_t apdu, uint16_t le, uint8_t *resp, size_t *resplen, uint16_t *sw) {
|
static int DesfireExchangeISO(bool activate_field, DesfireContext_t *ctx, sAPDU_t apdu, uint16_t le, uint8_t *resp, size_t *resplen, uint16_t *sw) {
|
||||||
uint8_t data[1050] = {0};
|
uint8_t data[1050] = {0};
|
||||||
uint32_t datalen = 0;
|
uint32_t datalen = 0;
|
||||||
int res = DESFIRESendApduEx(activate_field, apdu, le, data, sizeof(data), &datalen, sw);
|
int res = DESFIRESendApduEx(activate_field, apdu, le, data, sizeof(data), &datalen, sw);
|
||||||
|
@ -779,7 +779,7 @@ static void DesfireSplitBytesToBlock(uint8_t *blockdata, size_t *blockdatacount,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireExchangeEx(bool activate_field, DesfireContext *ctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *respcode, uint8_t *resp, size_t *resplen, bool enable_chaining, size_t splitbysize) {
|
int DesfireExchangeEx(bool activate_field, DesfireContext_t *ctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *respcode, uint8_t *resp, size_t *resplen, bool enable_chaining, size_t splitbysize) {
|
||||||
int res = PM3_SUCCESS;
|
int res = PM3_SUCCESS;
|
||||||
|
|
||||||
if (!PrintChannelModeWarning(cmd, ctx->secureChannel, ctx->cmdSet, ctx->commMode))
|
if (!PrintChannelModeWarning(cmd, ctx->secureChannel, ctx->cmdSet, ctx->commMode))
|
||||||
|
@ -821,11 +821,11 @@ int DesfireExchangeEx(bool activate_field, DesfireContext *ctx, uint8_t cmd, uin
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireExchange(DesfireContext *ctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *respcode, uint8_t *resp, size_t *resplen) {
|
int DesfireExchange(DesfireContext_t *ctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *respcode, uint8_t *resp, size_t *resplen) {
|
||||||
return DesfireExchangeEx(false, ctx, cmd, data, datalen, respcode, resp, resplen, true, 0);
|
return DesfireExchangeEx(false, ctx, cmd, data, datalen, respcode, resp, resplen, true, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireSelectAID(DesfireContext *ctx, uint8_t *aid1, uint8_t *aid2) {
|
int DesfireSelectAID(DesfireContext_t *ctx, uint8_t *aid1, uint8_t *aid2) {
|
||||||
if (aid1 == NULL)
|
if (aid1 == NULL)
|
||||||
return PM3_EINVARG;
|
return PM3_EINVARG;
|
||||||
|
|
||||||
|
@ -857,7 +857,7 @@ int DesfireSelectAID(DesfireContext *ctx, uint8_t *aid1, uint8_t *aid2) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireSelectAIDHex(DesfireContext *ctx, uint32_t aid1, bool select_two, uint32_t aid2) {
|
int DesfireSelectAIDHex(DesfireContext_t *ctx, uint32_t aid1, bool select_two, uint32_t aid2) {
|
||||||
uint8_t data[6] = {0};
|
uint8_t data[6] = {0};
|
||||||
|
|
||||||
DesfireAIDUintToByte(aid1, data);
|
DesfireAIDUintToByte(aid1, data);
|
||||||
|
@ -866,7 +866,7 @@ int DesfireSelectAIDHex(DesfireContext *ctx, uint32_t aid1, bool select_two, uin
|
||||||
return DesfireSelectAID(ctx, data, (select_two) ? &data[3] : NULL);
|
return DesfireSelectAID(ctx, data, (select_two) ? &data[3] : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireSelectAIDHexNoFieldOn(DesfireContext *ctx, uint32_t aid) {
|
int DesfireSelectAIDHexNoFieldOn(DesfireContext_t *ctx, uint32_t aid) {
|
||||||
uint8_t data[3] = {0};
|
uint8_t data[3] = {0};
|
||||||
|
|
||||||
DesfireAIDUintToByte(aid, data);
|
DesfireAIDUintToByte(aid, data);
|
||||||
|
@ -929,7 +929,7 @@ void DesfirePrintAIDFunctions(uint32_t appid) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireSelectAndAuthenticateEx(DesfireContext *dctx, DesfireSecureChannel secureChannel, uint32_t aid, bool noauth, bool verbose) {
|
int DesfireSelectAndAuthenticateEx(DesfireContext_t *dctx, DesfireSecureChannel secureChannel, uint32_t aid, bool noauth, bool verbose) {
|
||||||
if (verbose)
|
if (verbose)
|
||||||
DesfirePrintContext(dctx);
|
DesfirePrintContext(dctx);
|
||||||
|
|
||||||
|
@ -985,11 +985,11 @@ int DesfireSelectAndAuthenticateEx(DesfireContext *dctx, DesfireSecureChannel se
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireSelectAndAuthenticate(DesfireContext *dctx, DesfireSecureChannel secureChannel, uint32_t aid, bool verbose) {
|
int DesfireSelectAndAuthenticate(DesfireContext_t *dctx, DesfireSecureChannel secureChannel, uint32_t aid, bool verbose) {
|
||||||
return DesfireSelectAndAuthenticateEx(dctx, secureChannel, aid, false, verbose);
|
return DesfireSelectAndAuthenticateEx(dctx, secureChannel, aid, false, verbose);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireSelectAndAuthenticateW(DesfireContext *dctx, DesfireSecureChannel secureChannel, DesfireISOSelectWay way, uint32_t id, bool selectfile, uint16_t isofileid, bool noauth, bool verbose) {
|
int DesfireSelectAndAuthenticateW(DesfireContext_t *dctx, DesfireSecureChannel secureChannel, DesfireISOSelectWay way, uint32_t id, bool selectfile, uint16_t isofileid, bool noauth, bool verbose) {
|
||||||
if (verbose)
|
if (verbose)
|
||||||
DesfirePrintContext(dctx);
|
DesfirePrintContext(dctx);
|
||||||
|
|
||||||
|
@ -1047,15 +1047,15 @@ int DesfireSelectAndAuthenticateW(DesfireContext *dctx, DesfireSecureChannel sec
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireSelectAndAuthenticateAppW(DesfireContext *dctx, DesfireSecureChannel secureChannel, DesfireISOSelectWay way, uint32_t id, bool noauth, bool verbose) {
|
int DesfireSelectAndAuthenticateAppW(DesfireContext_t *dctx, DesfireSecureChannel secureChannel, DesfireISOSelectWay way, uint32_t id, bool noauth, bool verbose) {
|
||||||
return DesfireSelectAndAuthenticateW(dctx, secureChannel, way, id, false, 0, noauth, verbose);
|
return DesfireSelectAndAuthenticateW(dctx, secureChannel, way, id, false, 0, noauth, verbose);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireSelectAndAuthenticateISO(DesfireContext *dctx, DesfireSecureChannel secureChannel, bool useaid, uint32_t aid, uint16_t isoappid, bool selectfile, uint16_t isofileid, bool noauth, bool verbose) {
|
int DesfireSelectAndAuthenticateISO(DesfireContext_t *dctx, DesfireSecureChannel secureChannel, bool useaid, uint32_t aid, uint16_t isoappid, bool selectfile, uint16_t isofileid, bool noauth, bool verbose) {
|
||||||
return DesfireSelectAndAuthenticateW(dctx, secureChannel, useaid ? ISW6bAID : ISWIsoID, useaid ? aid : isoappid, selectfile, isofileid, noauth, verbose);
|
return DesfireSelectAndAuthenticateW(dctx, secureChannel, useaid ? ISW6bAID : ISWIsoID, useaid ? aid : isoappid, selectfile, isofileid, noauth, verbose);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int DesfireAuthenticateEV1(DesfireContext *dctx, DesfireSecureChannel secureChannel, bool verbose) {
|
static int DesfireAuthenticateEV1(DesfireContext_t *dctx, DesfireSecureChannel secureChannel, bool verbose) {
|
||||||
// 3 different way to authenticate AUTH (CRC16) , AUTH_ISO (CRC32) , AUTH_AES (CRC32)
|
// 3 different way to authenticate AUTH (CRC16) , AUTH_ISO (CRC32) , AUTH_AES (CRC32)
|
||||||
// 4 different crypto arg1 DES, 3DES, 3K3DES, AES
|
// 4 different crypto arg1 DES, 3DES, 3K3DES, AES
|
||||||
// 3 different communication modes, PLAIN,MAC,CRYPTO
|
// 3 different communication modes, PLAIN,MAC,CRYPTO
|
||||||
|
@ -1217,7 +1217,7 @@ static int DesfireAuthenticateEV1(DesfireContext *dctx, DesfireSecureChannel sec
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int DesfireAuthenticateEV2(DesfireContext *dctx, DesfireSecureChannel secureChannel, bool firstauth, bool verbose) {
|
static int DesfireAuthenticateEV2(DesfireContext_t *dctx, DesfireSecureChannel secureChannel, bool firstauth, bool verbose) {
|
||||||
// Crypt constants
|
// Crypt constants
|
||||||
uint8_t IV[16] = {0};
|
uint8_t IV[16] = {0};
|
||||||
uint8_t RndA[CRYPTO_AES_BLOCK_SIZE] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16};
|
uint8_t RndA[CRYPTO_AES_BLOCK_SIZE] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16};
|
||||||
|
@ -1351,7 +1351,7 @@ static int DesfireAuthenticateEV2(DesfireContext *dctx, DesfireSecureChannel sec
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int DesfireAuthenticateISO(DesfireContext *dctx, DesfireSecureChannel secureChannel, bool verbose) {
|
static int DesfireAuthenticateISO(DesfireContext_t *dctx, DesfireSecureChannel secureChannel, bool verbose) {
|
||||||
uint8_t rndlen = DesfireGetRndLenForKey(dctx->keyType);
|
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 hostrnd[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16};
|
||||||
|
@ -1408,7 +1408,7 @@ static int DesfireAuthenticateISO(DesfireContext *dctx, DesfireSecureChannel sec
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int DesfireAuthenticateLRP(DesfireContext *dctx, DesfireSecureChannel secureChannel, bool firstauth, bool verbose) {
|
static int DesfireAuthenticateLRP(DesfireContext_t *dctx, DesfireSecureChannel secureChannel, bool firstauth, bool verbose) {
|
||||||
// Crypt constants
|
// Crypt constants
|
||||||
uint8_t RndA[CRYPTO_AES_BLOCK_SIZE] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16};
|
uint8_t RndA[CRYPTO_AES_BLOCK_SIZE] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16};
|
||||||
uint8_t RndB[CRYPTO_AES_BLOCK_SIZE] = {0};
|
uint8_t RndB[CRYPTO_AES_BLOCK_SIZE] = {0};
|
||||||
|
@ -1462,7 +1462,7 @@ static int DesfireAuthenticateLRP(DesfireContext *dctx, DesfireSecureChannel sec
|
||||||
memcpy(tmp + CRYPTO_AES_BLOCK_SIZE, RndB, CRYPTO_AES_BLOCK_SIZE);
|
memcpy(tmp + CRYPTO_AES_BLOCK_SIZE, RndB, CRYPTO_AES_BLOCK_SIZE);
|
||||||
|
|
||||||
uint8_t cmac[CRYPTO_AES_BLOCK_SIZE] = {0};
|
uint8_t cmac[CRYPTO_AES_BLOCK_SIZE] = {0};
|
||||||
LRPContext ctx = {0};
|
LRPContext_t ctx = {0};
|
||||||
LRPSetKey(&ctx, sessionkey, 0, true);
|
LRPSetKey(&ctx, sessionkey, 0, true);
|
||||||
LRPCMAC(&ctx, tmp, 32, cmac);
|
LRPCMAC(&ctx, tmp, 32, cmac);
|
||||||
|
|
||||||
|
@ -1539,7 +1539,7 @@ static int DesfireAuthenticateLRP(DesfireContext *dctx, DesfireSecureChannel sec
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int DesfireAuthenticate(DesfireContext *dctx, DesfireSecureChannel secureChannel, bool verbose) {
|
int DesfireAuthenticate(DesfireContext_t *dctx, DesfireSecureChannel secureChannel, bool verbose) {
|
||||||
if (dctx->kdfAlgo == MFDES_KDF_ALGO_AN10922) {
|
if (dctx->kdfAlgo == MFDES_KDF_ALGO_AN10922) {
|
||||||
MifareKdfAn10922(dctx, DCOMasterKey, dctx->kdfInput, dctx->kdfInputLen);
|
MifareKdfAn10922(dctx, DCOMasterKey, dctx->kdfInput, dctx->kdfInputLen);
|
||||||
PrintAndLogEx(DEBUG, " Derrived key: " _GREEN_("%s"), sprint_hex(dctx->key, desfire_get_key_block_length(dctx->keyType)));
|
PrintAndLogEx(DEBUG, " Derrived key: " _GREEN_("%s"), sprint_hex(dctx->key, desfire_get_key_block_length(dctx->keyType)));
|
||||||
|
@ -1576,7 +1576,7 @@ static bool DesfireCheckAuthCmd(uint32_t appAID, uint8_t keyNum, uint8_t authcmd
|
||||||
uint8_t respcode = 0;
|
uint8_t respcode = 0;
|
||||||
uint8_t recv_data[256] = {0};
|
uint8_t recv_data[256] = {0};
|
||||||
|
|
||||||
DesfireContext dctx = {0};
|
DesfireContext_t dctx = {0};
|
||||||
dctx.keyNum = keyNum;
|
dctx.keyNum = keyNum;
|
||||||
dctx.commMode = DCMPlain;
|
dctx.commMode = DCMPlain;
|
||||||
dctx.cmdSet = DCCNative;
|
dctx.cmdSet = DCCNative;
|
||||||
|
@ -1594,7 +1594,7 @@ static bool DesfireCheckAuthCmd(uint32_t appAID, uint8_t keyNum, uint8_t authcmd
|
||||||
|
|
||||||
static bool DesfireCheckISOAuthCmd(uint32_t appAID, char *dfname, uint8_t keyNum, DesfireCryptoAlgorythm keytype) {
|
static bool DesfireCheckISOAuthCmd(uint32_t appAID, char *dfname, uint8_t keyNum, DesfireCryptoAlgorythm keytype) {
|
||||||
|
|
||||||
DesfireContext dctx = {0};
|
DesfireContext_t dctx = {0};
|
||||||
dctx.keyNum = keyNum;
|
dctx.keyNum = keyNum;
|
||||||
dctx.commMode = DCMPlain;
|
dctx.commMode = DCMPlain;
|
||||||
dctx.cmdSet = DCCISO;
|
dctx.cmdSet = DCCISO;
|
||||||
|
@ -1637,8 +1637,8 @@ static bool DesfireCheckISOAuthCmd(uint32_t appAID, char *dfname, uint8_t keyNum
|
||||||
return (sw == 0x9000 || sw == 0x6982);
|
return (sw == 0x9000 || sw == 0x6982);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesfireCheckAuthCommands(uint32_t appAID, char *dfname, uint8_t keyNum, AuthCommandsChk *authCmdCheck) {
|
void DesfireCheckAuthCommands(uint32_t appAID, char *dfname, uint8_t keyNum, AuthCommandsChk_t *authCmdCheck) {
|
||||||
memset(authCmdCheck, 0, sizeof(AuthCommandsChk));
|
memset(authCmdCheck, 0, sizeof(AuthCommandsChk_t));
|
||||||
|
|
||||||
authCmdCheck->auth = DesfireCheckAuthCmd(appAID, keyNum, MFDES_AUTHENTICATE);
|
authCmdCheck->auth = DesfireCheckAuthCmd(appAID, keyNum, MFDES_AUTHENTICATE);
|
||||||
authCmdCheck->authISO = DesfireCheckAuthCmd(appAID, keyNum, MFDES_AUTHENTICATE_ISO);
|
authCmdCheck->authISO = DesfireCheckAuthCmd(appAID, keyNum, MFDES_AUTHENTICATE_ISO);
|
||||||
|
@ -1648,7 +1648,7 @@ void DesfireCheckAuthCommands(uint32_t appAID, char *dfname, uint8_t keyNum, Aut
|
||||||
authCmdCheck->checked = true;
|
authCmdCheck->checked = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesfireCheckAuthCommandsPrint(AuthCommandsChk *authCmdCheck) {
|
void DesfireCheckAuthCommandsPrint(AuthCommandsChk_t *authCmdCheck) {
|
||||||
PrintAndLogEx(NORMAL, "auth: %s auth iso: %s auth aes: %s auth ev2: %s auth iso native: %s",
|
PrintAndLogEx(NORMAL, "auth: %s auth iso: %s auth aes: %s auth ev2: %s auth iso native: %s",
|
||||||
authCmdCheck->auth ? _GREEN_("YES") : _RED_("NO"),
|
authCmdCheck->auth ? _GREEN_("YES") : _RED_("NO"),
|
||||||
authCmdCheck->authISO ? _GREEN_("YES") : _RED_("NO"),
|
authCmdCheck->authISO ? _GREEN_("YES") : _RED_("NO"),
|
||||||
|
@ -1658,7 +1658,7 @@ void DesfireCheckAuthCommandsPrint(AuthCommandsChk *authCmdCheck) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireFillPICCInfo(DesfireContext *dctx, PICCInfoS *PICCInfo, bool deepmode) {
|
int DesfireFillPICCInfo(DesfireContext_t *dctx, PICCInfo_t *PICCInfo, bool deepmode) {
|
||||||
uint8_t buf[250] = {0};
|
uint8_t buf[250] = {0};
|
||||||
size_t buflen = 0;
|
size_t buflen = 0;
|
||||||
|
|
||||||
|
@ -1701,7 +1701,7 @@ static int AppListSearchAID(uint32_t appNum, AppListS AppList, size_t appcount)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireFillAppList(DesfireContext *dctx, PICCInfoS *PICCInfo, AppListS appList, bool deepmode, bool readFiles, bool fillAppSettings) {
|
int DesfireFillAppList(DesfireContext_t *dctx, PICCInfo_t *PICCInfo, AppListS appList, bool deepmode, bool readFiles, bool fillAppSettings) {
|
||||||
uint8_t buf[250] = {0};
|
uint8_t buf[250] = {0};
|
||||||
size_t buflen = 0;
|
size_t buflen = 0;
|
||||||
|
|
||||||
|
@ -1777,7 +1777,7 @@ int DesfireFillAppList(DesfireContext *dctx, PICCInfoS *PICCInfo, AppListS appLi
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesfirePrintPICCInfo(DesfireContext *dctx, PICCInfoS *PICCInfo) {
|
void DesfirePrintPICCInfo(DesfireContext_t *dctx, PICCInfo_t *PICCInfo) {
|
||||||
PrintAndLogEx(SUCCESS, "------------------------------------ " _CYAN_("PICC level") " -------------------------------------");
|
PrintAndLogEx(SUCCESS, "------------------------------------ " _CYAN_("PICC level") " -------------------------------------");
|
||||||
if (PICCInfo->freemem == 0xffffffff)
|
if (PICCInfo->freemem == 0xffffffff)
|
||||||
PrintAndLogEx(SUCCESS, "Applications count: " _GREEN_("%zu") " free memory " _YELLOW_("n/a"), PICCInfo->appCount);
|
PrintAndLogEx(SUCCESS, "Applications count: " _GREEN_("%zu") " free memory " _YELLOW_("n/a"), PICCInfo->appCount);
|
||||||
|
@ -1793,7 +1793,7 @@ void DesfirePrintPICCInfo(DesfireContext *dctx, PICCInfoS *PICCInfo) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesfirePrintAppList(DesfireContext *dctx, PICCInfoS *PICCInfo, AppListS appList) {
|
void DesfirePrintAppList(DesfireContext_t *dctx, PICCInfo_t *PICCInfo, AppListS appList) {
|
||||||
if (PICCInfo->appCount == 0)
|
if (PICCInfo->appCount == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -1845,7 +1845,7 @@ void DesfirePrintAppList(DesfireContext *dctx, PICCInfoS *PICCInfo, AppListS app
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int DesfireCommandEx(DesfireContext *dctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *resp, size_t *resplen, int checklength, size_t splitbysize) {
|
static int DesfireCommandEx(DesfireContext_t *dctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *resp, size_t *resplen, int checklength, size_t splitbysize) {
|
||||||
if (resplen)
|
if (resplen)
|
||||||
*resplen = 0;
|
*resplen = 0;
|
||||||
|
|
||||||
|
@ -1867,27 +1867,27 @@ static int DesfireCommandEx(DesfireContext *dctx, uint8_t cmd, uint8_t *data, si
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int DesfireCommand(DesfireContext *dctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *resp, size_t *resplen, int checklength) {
|
static int DesfireCommand(DesfireContext_t *dctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *resp, size_t *resplen, int checklength) {
|
||||||
return DesfireCommandEx(dctx, cmd, data, datalen, resp, resplen, checklength, 0);
|
return DesfireCommandEx(dctx, cmd, data, datalen, resp, resplen, checklength, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int DesfireCommandNoData(DesfireContext *dctx, uint8_t cmd) {
|
static int DesfireCommandNoData(DesfireContext_t *dctx, uint8_t cmd) {
|
||||||
return DesfireCommand(dctx, cmd, NULL, 0, NULL, NULL, 0);
|
return DesfireCommand(dctx, cmd, NULL, 0, NULL, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int DesfireCommandTxData(DesfireContext *dctx, uint8_t cmd, uint8_t *data, size_t datalen) {
|
static int DesfireCommandTxData(DesfireContext_t *dctx, uint8_t cmd, uint8_t *data, size_t datalen) {
|
||||||
return DesfireCommand(dctx, cmd, data, datalen, NULL, NULL, 0);
|
return DesfireCommand(dctx, cmd, data, datalen, NULL, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int DesfireCommandRxData(DesfireContext *dctx, uint8_t cmd, uint8_t *resp, size_t *resplen, int checklength) {
|
static int DesfireCommandRxData(DesfireContext_t *dctx, uint8_t cmd, uint8_t *resp, size_t *resplen, int checklength) {
|
||||||
return DesfireCommand(dctx, cmd, NULL, 0, resp, resplen, checklength);
|
return DesfireCommand(dctx, cmd, NULL, 0, resp, resplen, checklength);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireFormatPICC(DesfireContext *dctx) {
|
int DesfireFormatPICC(DesfireContext_t *dctx) {
|
||||||
return DesfireCommandNoData(dctx, MFDES_FORMAT_PICC);
|
return DesfireCommandNoData(dctx, MFDES_FORMAT_PICC);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireGetFreeMem(DesfireContext *dctx, uint32_t *freemem) {
|
int DesfireGetFreeMem(DesfireContext_t *dctx, uint32_t *freemem) {
|
||||||
*freemem = 0;
|
*freemem = 0;
|
||||||
|
|
||||||
uint8_t resp[257] = {0};
|
uint8_t resp[257] = {0};
|
||||||
|
@ -1898,7 +1898,7 @@ int DesfireGetFreeMem(DesfireContext *dctx, uint32_t *freemem) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireReadSignature(DesfireContext *dctx, uint8_t sid, uint8_t *resp, size_t *resplen) {
|
int DesfireReadSignature(DesfireContext_t *dctx, uint8_t sid, uint8_t *resp, size_t *resplen) {
|
||||||
*resplen = 0;
|
*resplen = 0;
|
||||||
|
|
||||||
uint8_t xresp[257] = {0};
|
uint8_t xresp[257] = {0};
|
||||||
|
@ -1918,65 +1918,65 @@ int DesfireReadSignature(DesfireContext *dctx, uint8_t sid, uint8_t *resp, size_
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireGetUID(DesfireContext *dctx, uint8_t *resp, size_t *resplen) {
|
int DesfireGetUID(DesfireContext_t *dctx, uint8_t *resp, size_t *resplen) {
|
||||||
return DesfireCommandRxData(dctx, MFDES_GET_UID, resp, resplen, -1);
|
return DesfireCommandRxData(dctx, MFDES_GET_UID, resp, resplen, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireGetAIDList(DesfireContext *dctx, uint8_t *resp, size_t *resplen) {
|
int DesfireGetAIDList(DesfireContext_t *dctx, uint8_t *resp, size_t *resplen) {
|
||||||
return DesfireCommandRxData(dctx, MFDES_GET_APPLICATION_IDS, resp, resplen, -1);
|
return DesfireCommandRxData(dctx, MFDES_GET_APPLICATION_IDS, resp, resplen, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireGetDFList(DesfireContext *dctx, uint8_t *resp, size_t *resplen) {
|
int DesfireGetDFList(DesfireContext_t *dctx, uint8_t *resp, size_t *resplen) {
|
||||||
return DesfireCommandEx(dctx, MFDES_GET_DF_NAMES, NULL, 0, resp, resplen, -1, 24);
|
return DesfireCommandEx(dctx, MFDES_GET_DF_NAMES, NULL, 0, resp, resplen, -1, 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireCreateApplication(DesfireContext *dctx, uint8_t *appdata, size_t appdatalen) {
|
int DesfireCreateApplication(DesfireContext_t *dctx, uint8_t *appdata, size_t appdatalen) {
|
||||||
return DesfireCommandTxData(dctx, MFDES_CREATE_APPLICATION, appdata, appdatalen);
|
return DesfireCommandTxData(dctx, MFDES_CREATE_APPLICATION, appdata, appdatalen);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireDeleteApplication(DesfireContext *dctx, uint32_t aid) {
|
int DesfireDeleteApplication(DesfireContext_t *dctx, uint32_t aid) {
|
||||||
uint8_t data[3] = {0};
|
uint8_t data[3] = {0};
|
||||||
DesfireAIDUintToByte(aid, data);
|
DesfireAIDUintToByte(aid, data);
|
||||||
return DesfireCommandTxData(dctx, MFDES_DELETE_APPLICATION, data, sizeof(data));
|
return DesfireCommandTxData(dctx, MFDES_DELETE_APPLICATION, data, sizeof(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireGetKeySettings(DesfireContext *dctx, uint8_t *resp, size_t *resplen) {
|
int DesfireGetKeySettings(DesfireContext_t *dctx, uint8_t *resp, size_t *resplen) {
|
||||||
return DesfireCommandRxData(dctx, MFDES_GET_KEY_SETTINGS, resp, resplen, -1);
|
return DesfireCommandRxData(dctx, MFDES_GET_KEY_SETTINGS, resp, resplen, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireGetKeyVersion(DesfireContext *dctx, uint8_t *data, size_t len, uint8_t *resp, size_t *resplen) {
|
int DesfireGetKeyVersion(DesfireContext_t *dctx, uint8_t *data, size_t len, uint8_t *resp, size_t *resplen) {
|
||||||
return DesfireCommand(dctx, MFDES_GET_KEY_VERSION, data, len, resp, resplen, -1);
|
return DesfireCommand(dctx, MFDES_GET_KEY_VERSION, data, len, resp, resplen, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireChangeKeySettings(DesfireContext *dctx, uint8_t *data, size_t len) {
|
int DesfireChangeKeySettings(DesfireContext_t *dctx, uint8_t *data, size_t len) {
|
||||||
return DesfireCommandTxData(dctx, MFDES_CHANGE_KEY_SETTINGS, data, len);
|
return DesfireCommandTxData(dctx, MFDES_CHANGE_KEY_SETTINGS, data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireChangeKeyCmd(DesfireContext *dctx, uint8_t *data, size_t len, uint8_t *resp, size_t *resplen) {
|
int DesfireChangeKeyCmd(DesfireContext_t *dctx, uint8_t *data, size_t len, uint8_t *resp, size_t *resplen) {
|
||||||
return DesfireCommand(dctx, MFDES_CHANGE_KEY, data, len, resp, resplen, -1);
|
return DesfireCommand(dctx, MFDES_CHANGE_KEY, data, len, resp, resplen, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireSetConfigurationCmd(DesfireContext *dctx, uint8_t *data, size_t len, uint8_t *resp, size_t *resplen) {
|
int DesfireSetConfigurationCmd(DesfireContext_t *dctx, uint8_t *data, size_t len, uint8_t *resp, size_t *resplen) {
|
||||||
return DesfireCommand(dctx, MFDES_CHANGE_CONFIGURATION, data, len, resp, resplen, -1);
|
return DesfireCommand(dctx, MFDES_CHANGE_CONFIGURATION, data, len, resp, resplen, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireChangeFileSettings(DesfireContext *dctx, uint8_t *data, size_t datalen) {
|
int DesfireChangeFileSettings(DesfireContext_t *dctx, uint8_t *data, size_t datalen) {
|
||||||
return DesfireCommandTxData(dctx, MFDES_CHANGE_FILE_SETTINGS, data, datalen);
|
return DesfireCommandTxData(dctx, MFDES_CHANGE_FILE_SETTINGS, data, datalen);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireGetFileIDList(DesfireContext *dctx, uint8_t *resp, size_t *resplen) {
|
int DesfireGetFileIDList(DesfireContext_t *dctx, uint8_t *resp, size_t *resplen) {
|
||||||
return DesfireCommandRxData(dctx, MFDES_GET_FILE_IDS, resp, resplen, -1);
|
return DesfireCommandRxData(dctx, MFDES_GET_FILE_IDS, resp, resplen, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireGetFileISOIDList(DesfireContext *dctx, uint8_t *resp, size_t *resplen) {
|
int DesfireGetFileISOIDList(DesfireContext_t *dctx, uint8_t *resp, size_t *resplen) {
|
||||||
return DesfireCommandRxData(dctx, MFDES_GET_ISOFILE_IDS, resp, resplen, -1);
|
return DesfireCommandRxData(dctx, MFDES_GET_ISOFILE_IDS, resp, resplen, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireGetFileSettings(DesfireContext *dctx, uint8_t fileid, uint8_t *resp, size_t *resplen) {
|
int DesfireGetFileSettings(DesfireContext_t *dctx, uint8_t fileid, uint8_t *resp, size_t *resplen) {
|
||||||
return DesfireCommand(dctx, MFDES_GET_FILE_SETTINGS, &fileid, 1, resp, resplen, -1);
|
return DesfireCommand(dctx, MFDES_GET_FILE_SETTINGS, &fileid, 1, resp, resplen, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireGetFileSettingsStruct(DesfireContext *dctx, uint8_t fileid, FileSettingsS *fsettings) {
|
int DesfireFileSettingsStruct(DesfireContext_t *dctx, uint8_t fileid, FileSettings_t *fsettings) {
|
||||||
uint8_t resp[250] = {0};
|
uint8_t resp[250] = {0};
|
||||||
size_t resplen = 0;
|
size_t resplen = 0;
|
||||||
int res = DesfireGetFileSettings(dctx, fileid, resp, &resplen);
|
int res = DesfireGetFileSettings(dctx, fileid, resp, &resplen);
|
||||||
|
@ -1986,13 +1986,13 @@ int DesfireGetFileSettingsStruct(DesfireContext *dctx, uint8_t fileid, FileSetti
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireFillFileList(DesfireContext *dctx, FileListS FileList, size_t *filescount, bool *isopresent) {
|
int DesfireFillFileList(DesfireContext_t *dctx, FileList_t FileList, size_t *filescount, bool *isopresent) {
|
||||||
uint8_t buf[APDU_RES_LEN] = {0};
|
uint8_t buf[APDU_RES_LEN] = {0};
|
||||||
size_t buflen = 0;
|
size_t buflen = 0;
|
||||||
|
|
||||||
*filescount = 0;
|
*filescount = 0;
|
||||||
*isopresent = false;
|
*isopresent = false;
|
||||||
memset(FileList, 0, sizeof(FileListS));
|
memset(FileList, 0, sizeof(FileList_t));
|
||||||
|
|
||||||
int res = DesfireGetFileIDList(dctx, buf, &buflen);
|
int res = DesfireGetFileIDList(dctx, buf, &buflen);
|
||||||
if (res != PM3_SUCCESS) {
|
if (res != PM3_SUCCESS) {
|
||||||
|
@ -2005,7 +2005,7 @@ int DesfireFillFileList(DesfireContext *dctx, FileListS FileList, size_t *filesc
|
||||||
|
|
||||||
for (int i = 0; i < buflen; i++) {
|
for (int i = 0; i < buflen; i++) {
|
||||||
FileList[i].fileNum = buf[i];
|
FileList[i].fileNum = buf[i];
|
||||||
DesfireGetFileSettingsStruct(dctx, FileList[i].fileNum, &FileList[i].fileSettings);
|
DesfireFileSettingsStruct(dctx, FileList[i].fileNum, &FileList[i].fileSettings);
|
||||||
}
|
}
|
||||||
*filescount = buflen;
|
*filescount = buflen;
|
||||||
|
|
||||||
|
@ -2035,8 +2035,8 @@ int DesfireFillFileList(DesfireContext *dctx, FileListS FileList, size_t *filesc
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireCreateFile(DesfireContext *dctx, uint8_t ftype, uint8_t *fdata, size_t fdatalen, bool checklen) {
|
int DesfireCreateFile(DesfireContext_t *dctx, uint8_t ftype, uint8_t *fdata, size_t fdatalen, bool checklen) {
|
||||||
const DesfireCreateFileCommandsS *rcmd = GetDesfireFileCmdRec(ftype);
|
const DesfireCreateFileCommands_t *rcmd = GetDesfireFileCmdRec(ftype);
|
||||||
if (rcmd == NULL)
|
if (rcmd == NULL)
|
||||||
return -100;
|
return -100;
|
||||||
if (checklen && fdatalen != (rcmd->createlen + 1) && fdatalen != (rcmd->createlen + 1 + (rcmd->mayHaveISOfid ? 2 : 0)))
|
if (checklen && fdatalen != (rcmd->createlen + 1) && fdatalen != (rcmd->createlen + 1 + (rcmd->mayHaveISOfid ? 2 : 0)))
|
||||||
|
@ -2045,39 +2045,39 @@ int DesfireCreateFile(DesfireContext *dctx, uint8_t ftype, uint8_t *fdata, size_
|
||||||
return DesfireCommandTxData(dctx, rcmd->cmd, fdata, fdatalen);
|
return DesfireCommandTxData(dctx, rcmd->cmd, fdata, fdatalen);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireDeleteFile(DesfireContext *dctx, uint8_t fnum) {
|
int DesfireDeleteFile(DesfireContext_t *dctx, uint8_t fnum) {
|
||||||
return DesfireCommandTxData(dctx, MFDES_DELETE_FILE, &fnum, 1);
|
return DesfireCommandTxData(dctx, MFDES_DELETE_FILE, &fnum, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireClearRecordFile(DesfireContext *dctx, uint8_t fnum) {
|
int DesfireClearRecordFile(DesfireContext_t *dctx, uint8_t fnum) {
|
||||||
return DesfireCommandTxData(dctx, MFDES_CLEAR_RECORD_FILE, &fnum, 1);
|
return DesfireCommandTxData(dctx, MFDES_CLEAR_RECORD_FILE, &fnum, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireCommitReaderID(DesfireContext *dctx, uint8_t *readerid, size_t readeridlen, uint8_t *resp, size_t *resplen) {
|
int DesfireCommitReaderID(DesfireContext_t *dctx, uint8_t *readerid, size_t readeridlen, uint8_t *resp, size_t *resplen) {
|
||||||
uint8_t rid[16] = {0};
|
uint8_t rid[16] = {0};
|
||||||
// command use 16b reader id only
|
// command use 16b reader id only
|
||||||
memcpy(rid, readerid, MIN(readeridlen, 16));
|
memcpy(rid, readerid, MIN(readeridlen, 16));
|
||||||
return DesfireCommand(dctx, MFDES_COMMIT_READER_ID, rid, 16, resp, resplen, -1);
|
return DesfireCommand(dctx, MFDES_COMMIT_READER_ID, rid, 16, resp, resplen, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireCommitTransactionEx(DesfireContext *dctx, bool enable_options, uint8_t options, uint8_t *resp, size_t *resplen) {
|
int DesfireCommitTransactionEx(DesfireContext_t *dctx, bool enable_options, uint8_t options, uint8_t *resp, size_t *resplen) {
|
||||||
if (enable_options)
|
if (enable_options)
|
||||||
return DesfireCommand(dctx, MFDES_COMMIT_TRANSACTION, &options, 1, resp, resplen, -1);
|
return DesfireCommand(dctx, MFDES_COMMIT_TRANSACTION, &options, 1, resp, resplen, -1);
|
||||||
else
|
else
|
||||||
return DesfireCommandNoData(dctx, MFDES_COMMIT_TRANSACTION);
|
return DesfireCommandNoData(dctx, MFDES_COMMIT_TRANSACTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireCommitTransaction(DesfireContext *dctx, bool enable_options, uint8_t options) {
|
int DesfireCommitTransaction(DesfireContext_t *dctx, bool enable_options, uint8_t options) {
|
||||||
uint8_t resp[250] = {0};
|
uint8_t resp[250] = {0};
|
||||||
size_t resplen = 0;
|
size_t resplen = 0;
|
||||||
return DesfireCommitTransactionEx(dctx, enable_options, options, resp, &resplen);
|
return DesfireCommitTransactionEx(dctx, enable_options, options, resp, &resplen);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireAbortTransaction(DesfireContext *dctx) {
|
int DesfireAbortTransaction(DesfireContext_t *dctx) {
|
||||||
return DesfireCommandNoData(dctx, MFDES_ABORT_TRANSACTION);
|
return DesfireCommandNoData(dctx, MFDES_ABORT_TRANSACTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireReadFile(DesfireContext *dctx, uint8_t fnum, uint32_t offset, uint32_t len, uint8_t *resp, size_t *resplen) {
|
int DesfireReadFile(DesfireContext_t *dctx, uint8_t fnum, uint32_t offset, uint32_t len, uint8_t *resp, size_t *resplen) {
|
||||||
uint8_t data[10] = {0};
|
uint8_t data[10] = {0};
|
||||||
data[0] = fnum;
|
data[0] = fnum;
|
||||||
Uint3byteToMemLe(&data[1], offset);
|
Uint3byteToMemLe(&data[1], offset);
|
||||||
|
@ -2086,7 +2086,7 @@ int DesfireReadFile(DesfireContext *dctx, uint8_t fnum, uint32_t offset, uint32_
|
||||||
return DesfireCommand(dctx, (dctx->isoChaining) ? MFDES_READ_DATA2 : MFDES_READ_DATA, data, 7, resp, resplen, -1);
|
return DesfireCommand(dctx, (dctx->isoChaining) ? MFDES_READ_DATA2 : MFDES_READ_DATA, data, 7, resp, resplen, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireWriteFile(DesfireContext *dctx, uint8_t fnum, uint32_t offset, uint32_t len, uint8_t *data) {
|
int DesfireWriteFile(DesfireContext_t *dctx, uint8_t fnum, uint32_t offset, uint32_t len, uint8_t *data) {
|
||||||
uint8_t xdata[1024] = {0};
|
uint8_t xdata[1024] = {0};
|
||||||
xdata[0] = fnum;
|
xdata[0] = fnum;
|
||||||
Uint3byteToMemLe(&xdata[1], offset);
|
Uint3byteToMemLe(&xdata[1], offset);
|
||||||
|
@ -2096,7 +2096,7 @@ int DesfireWriteFile(DesfireContext *dctx, uint8_t fnum, uint32_t offset, uint32
|
||||||
return DesfireCommandTxData(dctx, (dctx->isoChaining) ? MFDES_WRITE_DATA2 : MFDES_WRITE_DATA, xdata, 7 + len);
|
return DesfireCommandTxData(dctx, (dctx->isoChaining) ? MFDES_WRITE_DATA2 : MFDES_WRITE_DATA, xdata, 7 + len);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireValueFileOperations(DesfireContext *dctx, uint8_t fid, uint8_t operation, uint32_t *value) {
|
int DesfireValueFileOperations(DesfireContext_t *dctx, uint8_t fid, uint8_t operation, uint32_t *value) {
|
||||||
uint8_t data[10] = {0};
|
uint8_t data[10] = {0};
|
||||||
data[0] = fid;
|
data[0] = fid;
|
||||||
size_t datalen = (operation == MFDES_GET_VALUE) ? 1 : 5;
|
size_t datalen = (operation == MFDES_GET_VALUE) ? 1 : 5;
|
||||||
|
@ -2113,7 +2113,7 @@ int DesfireValueFileOperations(DesfireContext *dctx, uint8_t fid, uint8_t operat
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireReadRecords(DesfireContext *dctx, uint8_t fnum, uint32_t recnum, uint32_t reccount, uint8_t *resp, size_t *resplen) {
|
int DesfireReadRecords(DesfireContext_t *dctx, uint8_t fnum, uint32_t recnum, uint32_t reccount, uint8_t *resp, size_t *resplen) {
|
||||||
uint8_t data[10] = {0};
|
uint8_t data[10] = {0};
|
||||||
data[0] = fnum;
|
data[0] = fnum;
|
||||||
Uint3byteToMemLe(&data[1], recnum);
|
Uint3byteToMemLe(&data[1], recnum);
|
||||||
|
@ -2122,7 +2122,7 @@ int DesfireReadRecords(DesfireContext *dctx, uint8_t fnum, uint32_t recnum, uint
|
||||||
return DesfireCommand(dctx, (dctx->isoChaining) ? MFDES_READ_RECORDS2 : MFDES_READ_RECORDS, data, 7, resp, resplen, -1);
|
return DesfireCommand(dctx, (dctx->isoChaining) ? MFDES_READ_RECORDS2 : MFDES_READ_RECORDS, data, 7, resp, resplen, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireWriteRecord(DesfireContext *dctx, uint8_t fnum, uint32_t offset, uint32_t len, uint8_t *data) {
|
int DesfireWriteRecord(DesfireContext_t *dctx, uint8_t fnum, uint32_t offset, uint32_t len, uint8_t *data) {
|
||||||
uint8_t xdata[1024] = {0};
|
uint8_t xdata[1024] = {0};
|
||||||
xdata[0] = fnum;
|
xdata[0] = fnum;
|
||||||
Uint3byteToMemLe(&xdata[1], offset);
|
Uint3byteToMemLe(&xdata[1], offset);
|
||||||
|
@ -2132,7 +2132,7 @@ int DesfireWriteRecord(DesfireContext *dctx, uint8_t fnum, uint32_t offset, uint
|
||||||
return DesfireCommandTxData(dctx, (dctx->isoChaining) ? MFDES_WRITE_RECORD2 : MFDES_WRITE_RECORD, xdata, 7 + len);
|
return DesfireCommandTxData(dctx, (dctx->isoChaining) ? MFDES_WRITE_RECORD2 : MFDES_WRITE_RECORD, xdata, 7 + len);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireUpdateRecord(DesfireContext *dctx, uint8_t fnum, uint32_t recnum, uint32_t offset, uint32_t len, uint8_t *data) {
|
int DesfireUpdateRecord(DesfireContext_t *dctx, uint8_t fnum, uint32_t recnum, uint32_t offset, uint32_t len, uint8_t *data) {
|
||||||
uint8_t xdata[1024] = {0};
|
uint8_t xdata[1024] = {0};
|
||||||
xdata[0] = fnum;
|
xdata[0] = fnum;
|
||||||
Uint3byteToMemLe(&xdata[1], recnum);
|
Uint3byteToMemLe(&xdata[1], recnum);
|
||||||
|
@ -2207,7 +2207,7 @@ static const char *DesfireUnknownStr = "unknown";
|
||||||
static const char *DesfireDisabledStr = "disabled";
|
static const char *DesfireDisabledStr = "disabled";
|
||||||
static const char *DesfireFreeStr = "free";
|
static const char *DesfireFreeStr = "free";
|
||||||
static const char *DesfireNAStr = "n/a";
|
static const char *DesfireNAStr = "n/a";
|
||||||
static const DesfireCreateFileCommandsS DesfireFileCommands[] = {
|
static const DesfireCreateFileCommands_t DesfireFileCommands[] = {
|
||||||
{0x00, "Standard data", MFDES_CREATE_STD_DATA_FILE, 6, 6, true},
|
{0x00, "Standard data", MFDES_CREATE_STD_DATA_FILE, 6, 6, true},
|
||||||
{0x01, "Backup data", MFDES_CREATE_BACKUP_DATA_FILE, 6, 6, true},
|
{0x01, "Backup data", MFDES_CREATE_BACKUP_DATA_FILE, 6, 6, true},
|
||||||
{0x02, "Value", MFDES_CREATE_VALUE_FILE, 16, 16, false},
|
{0x02, "Value", MFDES_CREATE_VALUE_FILE, 16, 16, false},
|
||||||
|
@ -2216,7 +2216,7 @@ static const DesfireCreateFileCommandsS DesfireFileCommands[] = {
|
||||||
{0x05, "Transaction MAC", MFDES_CREATE_TRANS_MAC_FILE, 5, 21, false},
|
{0x05, "Transaction MAC", MFDES_CREATE_TRANS_MAC_FILE, 5, 21, false},
|
||||||
};
|
};
|
||||||
|
|
||||||
const DesfireCreateFileCommandsS *GetDesfireFileCmdRec(uint8_t type) {
|
const DesfireCreateFileCommands_t *GetDesfireFileCmdRec(uint8_t type) {
|
||||||
for (int i = 0; i < ARRAYLEN(DesfireFileCommands); i++)
|
for (int i = 0; i < ARRAYLEN(DesfireFileCommands); i++)
|
||||||
if (DesfireFileCommands[i].id == type)
|
if (DesfireFileCommands[i].id == type)
|
||||||
return &DesfireFileCommands[i];
|
return &DesfireFileCommands[i];
|
||||||
|
@ -2225,7 +2225,7 @@ const DesfireCreateFileCommandsS *GetDesfireFileCmdRec(uint8_t type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *GetDesfireFileType(uint8_t type) {
|
const char *GetDesfireFileType(uint8_t type) {
|
||||||
const DesfireCreateFileCommandsS *res = GetDesfireFileCmdRec(type);
|
const DesfireCreateFileCommands_t *res = GetDesfireFileCmdRec(type);
|
||||||
if (res != NULL)
|
if (res != NULL)
|
||||||
return res->text;
|
return res->text;
|
||||||
else
|
else
|
||||||
|
@ -2335,11 +2335,11 @@ void DesfirePrintAccessRight(uint8_t *data) {
|
||||||
PrintAndLogEx(SUCCESS, "change : %s", GetDesfireAccessRightStr(ch));
|
PrintAndLogEx(SUCCESS, "change : %s", GetDesfireAccessRightStr(ch));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesfireFillFileSettings(uint8_t *data, size_t datalen, FileSettingsS *fsettings) {
|
void DesfireFillFileSettings(uint8_t *data, size_t datalen, FileSettings_t *fsettings) {
|
||||||
if (fsettings == NULL)
|
if (fsettings == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
memset(fsettings, 0, sizeof(FileSettingsS));
|
memset(fsettings, 0, sizeof(FileSettings_t));
|
||||||
|
|
||||||
if (datalen < 4)
|
if (datalen < 4)
|
||||||
return;
|
return;
|
||||||
|
@ -2395,7 +2395,7 @@ void DesfireFillFileSettings(uint8_t *data, size_t datalen, FileSettingsS *fsett
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DesfirePrintShortFileTypeSettings(FileSettingsS *fsettings) {
|
static void DesfirePrintShortFileTypeSettings(FileSettings_t *fsettings) {
|
||||||
switch (fsettings->fileType) {
|
switch (fsettings->fileType) {
|
||||||
case 0x00:
|
case 0x00:
|
||||||
case 0x01: {
|
case 0x01: {
|
||||||
|
@ -2423,7 +2423,7 @@ static void DesfirePrintShortFileTypeSettings(FileSettingsS *fsettings) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesfirePrintFileSettingsOneLine(FileSettingsS *fsettings) {
|
void DesfirePrintFileSettingsOneLine(FileSettings_t *fsettings) {
|
||||||
PrintAndLogEx(NORMAL, "(%-5s) " NOLF, GetDesfireCommunicationMode(fsettings->fileCommMode));
|
PrintAndLogEx(NORMAL, "(%-5s) " NOLF, GetDesfireCommunicationMode(fsettings->fileCommMode));
|
||||||
PrintAndLogEx(NORMAL, "[0x%02x] " _CYAN_("%-13s ") NOLF, fsettings->fileType, GetDesfireFileType(fsettings->fileType));
|
PrintAndLogEx(NORMAL, "[0x%02x] " _CYAN_("%-13s ") NOLF, fsettings->fileType, GetDesfireFileType(fsettings->fileType));
|
||||||
|
|
||||||
|
@ -2436,7 +2436,7 @@ void DesfirePrintFileSettingsOneLine(FileSettingsS *fsettings) {
|
||||||
GetDesfireAccessRightShortStr(fsettings->chAccess));
|
GetDesfireAccessRightShortStr(fsettings->chAccess));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesfirePrintFileSettingsTable(bool printheader, uint8_t id, bool isoidavail, uint16_t isoid, FileSettingsS *fsettings) {
|
void DesfirePrintFileSettingsTable(bool printheader, uint8_t id, bool isoidavail, uint16_t isoid, FileSettings_t *fsettings) {
|
||||||
if (printheader) {
|
if (printheader) {
|
||||||
PrintAndLogEx(SUCCESS, " ID |ISO ID| File type | Mode | Rights: raw, r w rw ch | File settings ");
|
PrintAndLogEx(SUCCESS, " ID |ISO ID| File type | Mode | Rights: raw, r w rw ch | File settings ");
|
||||||
PrintAndLogEx(SUCCESS, "------------------------------------------------------------------------------------------------------------");
|
PrintAndLogEx(SUCCESS, "------------------------------------------------------------------------------------------------------------");
|
||||||
|
@ -2466,7 +2466,7 @@ void DesfirePrintFileSettingsTable(bool printheader, uint8_t id, bool isoidavail
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesfirePrintFileSettingsExtended(FileSettingsS *fsettings) {
|
void DesfirePrintFileSettingsExtended(FileSettings_t *fsettings) {
|
||||||
PrintAndLogEx(SUCCESS, "File type : " _CYAN_("%s") " [0x%02x]", GetDesfireFileType(fsettings->fileType), fsettings->fileType);
|
PrintAndLogEx(SUCCESS, "File type : " _CYAN_("%s") " [0x%02x]", GetDesfireFileType(fsettings->fileType), fsettings->fileType);
|
||||||
PrintAndLogEx(SUCCESS, "Comm mode : %s", GetDesfireCommunicationMode(fsettings->fileCommMode));
|
PrintAndLogEx(SUCCESS, "Comm mode : %s", GetDesfireCommunicationMode(fsettings->fileCommMode));
|
||||||
|
|
||||||
|
@ -2626,7 +2626,7 @@ void DesfirePrintSetFileSettings(uint8_t *data, size_t len) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesfirePrintCreateFileSettings(uint8_t filetype, uint8_t *data, size_t len) {
|
void DesfirePrintCreateFileSettings(uint8_t filetype, uint8_t *data, size_t len) {
|
||||||
const DesfireCreateFileCommandsS *ftyperec = GetDesfireFileCmdRec(filetype);
|
const DesfireCreateFileCommands_t *ftyperec = GetDesfireFileCmdRec(filetype);
|
||||||
if (ftyperec == NULL) {
|
if (ftyperec == NULL) {
|
||||||
PrintAndLogEx(WARNING, "Unknown file type 0x%02x", filetype);
|
PrintAndLogEx(WARNING, "Unknown file type 0x%02x", filetype);
|
||||||
return;
|
return;
|
||||||
|
@ -2683,7 +2683,7 @@ void DesfirePrintCreateFileSettings(uint8_t filetype, uint8_t *data, size_t len)
|
||||||
xlen += reclen;
|
xlen += reclen;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireChangeKey(DesfireContext *dctx, bool change_master_key, uint8_t newkeynum, DesfireCryptoAlgorythm newkeytype, uint32_t newkeyver, uint8_t *newkey, DesfireCryptoAlgorythm oldkeytype, uint8_t *oldkey, bool verbose) {
|
int DesfireChangeKey(DesfireContext_t *dctx, bool change_master_key, uint8_t newkeynum, DesfireCryptoAlgorythm newkeytype, uint32_t newkeyver, uint8_t *newkey, DesfireCryptoAlgorythm oldkeytype, uint8_t *oldkey, bool verbose) {
|
||||||
|
|
||||||
uint8_t okeybuf[DESFIRE_MAX_KEY_SIZE] = {0};
|
uint8_t okeybuf[DESFIRE_MAX_KEY_SIZE] = {0};
|
||||||
uint8_t nkeybuf[DESFIRE_MAX_KEY_SIZE] = {0};
|
uint8_t nkeybuf[DESFIRE_MAX_KEY_SIZE] = {0};
|
||||||
|
@ -2777,7 +2777,7 @@ int DesfireChangeKey(DesfireContext *dctx, bool change_master_key, uint8_t newke
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireSetConfiguration(DesfireContext *dctx, uint8_t paramid, uint8_t *param, size_t paramlen) {
|
int DesfireSetConfiguration(DesfireContext_t *dctx, uint8_t paramid, uint8_t *param, size_t paramlen) {
|
||||||
uint8_t cdata[200] = {0};
|
uint8_t cdata[200] = {0};
|
||||||
cdata[0] = MFDES_CHANGE_CONFIGURATION;
|
cdata[0] = MFDES_CHANGE_CONFIGURATION;
|
||||||
uint8_t *data = &cdata[1];
|
uint8_t *data = &cdata[1];
|
||||||
|
@ -2801,7 +2801,7 @@ int DesfireSetConfiguration(DesfireContext *dctx, uint8_t paramid, uint8_t *para
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireISOSelectEx(DesfireContext *dctx, bool fieldon, DesfireISOSelectControl cntr, uint8_t *data, uint8_t datalen, uint8_t *resp, size_t *resplen) {
|
int DesfireISOSelectEx(DesfireContext_t *dctx, bool fieldon, DesfireISOSelectControl cntr, uint8_t *data, uint8_t datalen, uint8_t *resp, size_t *resplen) {
|
||||||
uint8_t xresp[250] = {0};
|
uint8_t xresp[250] = {0};
|
||||||
size_t xresplen = 0;
|
size_t xresplen = 0;
|
||||||
uint16_t sw = 0;
|
uint16_t sw = 0;
|
||||||
|
@ -2821,15 +2821,15 @@ int DesfireISOSelectEx(DesfireContext *dctx, bool fieldon, DesfireISOSelectContr
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireISOSelect(DesfireContext *dctx, DesfireISOSelectControl cntr, uint8_t *data, uint8_t datalen, uint8_t *resp, size_t *resplen) {
|
int DesfireISOSelect(DesfireContext_t *dctx, DesfireISOSelectControl cntr, uint8_t *data, uint8_t datalen, uint8_t *resp, size_t *resplen) {
|
||||||
return DesfireISOSelectEx(dctx, true, cntr, data, datalen, resp, resplen);
|
return DesfireISOSelectEx(dctx, true, cntr, data, datalen, resp, resplen);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireISOSelectDF(DesfireContext *dctx, char *dfname, uint8_t *resp, size_t *resplen) {
|
int DesfireISOSelectDF(DesfireContext_t *dctx, char *dfname, uint8_t *resp, size_t *resplen) {
|
||||||
return DesfireISOSelect(dctx, ISSDFName, (uint8_t *)dfname, strnlen(dfname, 16), resp, resplen);
|
return DesfireISOSelect(dctx, ISSDFName, (uint8_t *)dfname, strnlen(dfname, 16), resp, resplen);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireISOGetChallenge(DesfireContext *dctx, DesfireCryptoAlgorythm keytype, uint8_t *resp, size_t *resplen) {
|
int DesfireISOGetChallenge(DesfireContext_t *dctx, DesfireCryptoAlgorythm keytype, uint8_t *resp, size_t *resplen) {
|
||||||
uint16_t sw = 0;
|
uint16_t sw = 0;
|
||||||
int res = DesfireExchangeISO(false, dctx, (sAPDU_t) {0x00, ISO7816_GET_CHALLENGE, 0x00, 0x00, 0x00, NULL}, DesfireGetRndLenForKey(keytype), resp, resplen, &sw);
|
int res = DesfireExchangeISO(false, dctx, (sAPDU_t) {0x00, ISO7816_GET_CHALLENGE, 0x00, 0x00, 0x00, NULL}, DesfireGetRndLenForKey(keytype), resp, resplen, &sw);
|
||||||
if (res == PM3_SUCCESS && sw != 0x9000)
|
if (res == PM3_SUCCESS && sw != 0x9000)
|
||||||
|
@ -2838,7 +2838,7 @@ int DesfireISOGetChallenge(DesfireContext *dctx, DesfireCryptoAlgorythm keytype,
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireISOExternalAuth(DesfireContext *dctx, bool app_level, uint8_t keynum, DesfireCryptoAlgorythm keytype, uint8_t *data) {
|
int DesfireISOExternalAuth(DesfireContext_t *dctx, bool app_level, uint8_t keynum, DesfireCryptoAlgorythm keytype, uint8_t *data) {
|
||||||
uint8_t p1 = DesfireKeyToISOKey(keytype);
|
uint8_t p1 = DesfireKeyToISOKey(keytype);
|
||||||
uint8_t p2 = ((app_level) ? 0x80 : 0x00) | keynum;
|
uint8_t p2 = ((app_level) ? 0x80 : 0x00) | keynum;
|
||||||
|
|
||||||
|
@ -2853,7 +2853,7 @@ int DesfireISOExternalAuth(DesfireContext *dctx, bool app_level, uint8_t keynum,
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireISOInternalAuth(DesfireContext *dctx, bool app_level, uint8_t keynum, DesfireCryptoAlgorythm keytype, uint8_t *data, uint8_t *resp, size_t *resplen) {
|
int DesfireISOInternalAuth(DesfireContext_t *dctx, bool app_level, uint8_t keynum, DesfireCryptoAlgorythm keytype, uint8_t *data, uint8_t *resp, size_t *resplen) {
|
||||||
uint8_t keylen = DesfireGetRndLenForKey(keytype);
|
uint8_t keylen = DesfireGetRndLenForKey(keytype);
|
||||||
uint8_t p1 = DesfireKeyToISOKey(keytype);
|
uint8_t p1 = DesfireKeyToISOKey(keytype);
|
||||||
uint8_t p2 = ((app_level) ? 0x80 : 0x00) | keynum;
|
uint8_t p2 = ((app_level) ? 0x80 : 0x00) | keynum;
|
||||||
|
@ -2866,7 +2866,7 @@ int DesfireISOInternalAuth(DesfireContext *dctx, bool app_level, uint8_t keynum,
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireISOReadBinary(DesfireContext *dctx, bool use_file_id, uint8_t fileid, uint16_t offset, uint8_t length, uint8_t *resp, size_t *resplen) {
|
int DesfireISOReadBinary(DesfireContext_t *dctx, bool use_file_id, uint8_t fileid, uint16_t offset, uint8_t length, uint8_t *resp, size_t *resplen) {
|
||||||
uint8_t p1 = 0;
|
uint8_t p1 = 0;
|
||||||
if (use_file_id)
|
if (use_file_id)
|
||||||
p1 = 0x80 | (fileid & 0x1f);
|
p1 = 0x80 | (fileid & 0x1f);
|
||||||
|
@ -2882,7 +2882,7 @@ int DesfireISOReadBinary(DesfireContext *dctx, bool use_file_id, uint8_t fileid,
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireISOUpdateBinary(DesfireContext *dctx, bool use_file_id, uint8_t fileid, uint16_t offset, uint8_t *data, size_t datalen) {
|
int DesfireISOUpdateBinary(DesfireContext_t *dctx, bool use_file_id, uint8_t fileid, uint16_t offset, uint8_t *data, size_t datalen) {
|
||||||
uint8_t p1 = 0;
|
uint8_t p1 = 0;
|
||||||
if (use_file_id)
|
if (use_file_id)
|
||||||
p1 = 0x80 | (fileid & 0x1f);
|
p1 = 0x80 | (fileid & 0x1f);
|
||||||
|
@ -2901,7 +2901,7 @@ int DesfireISOUpdateBinary(DesfireContext *dctx, bool use_file_id, uint8_t filei
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireISOReadRecords(DesfireContext *dctx, uint8_t recordnum, bool read_all_records, uint8_t fileid, uint8_t length, uint8_t *resp, size_t *resplen) {
|
int DesfireISOReadRecords(DesfireContext_t *dctx, uint8_t recordnum, bool read_all_records, uint8_t fileid, uint8_t length, uint8_t *resp, size_t *resplen) {
|
||||||
uint8_t p2 = ((fileid & 0x1f) << 3) | ((read_all_records) ? 0x05 : 0x04);
|
uint8_t p2 = ((fileid & 0x1f) << 3) | ((read_all_records) ? 0x05 : 0x04);
|
||||||
|
|
||||||
uint16_t sw = 0;
|
uint16_t sw = 0;
|
||||||
|
@ -2912,7 +2912,7 @@ int DesfireISOReadRecords(DesfireContext *dctx, uint8_t recordnum, bool read_all
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireISOAppendRecord(DesfireContext *dctx, uint8_t fileid, uint8_t *data, size_t datalen) {
|
int DesfireISOAppendRecord(DesfireContext_t *dctx, uint8_t fileid, uint8_t *data, size_t datalen) {
|
||||||
uint8_t p2 = ((fileid & 0x1f) << 3);
|
uint8_t p2 = ((fileid & 0x1f) << 3);
|
||||||
|
|
||||||
uint8_t resp[250] = {0};
|
uint8_t resp[250] = {0};
|
||||||
|
@ -2926,7 +2926,7 @@ int DesfireISOAppendRecord(DesfireContext *dctx, uint8_t fileid, uint8_t *data,
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireGetCardUID(DesfireContext *ctx) {
|
int DesfireGetCardUID(DesfireContext_t *ctx) {
|
||||||
iso14a_card_select_t card = {0};
|
iso14a_card_select_t card = {0};
|
||||||
|
|
||||||
SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT, 0, 0, NULL, 0);
|
SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT, 0, 0, NULL, 0);
|
||||||
|
@ -2950,7 +2950,7 @@ int DesfireAnticollision(bool verbose) {
|
||||||
return SelectCard14443A_4(false, verbose, NULL);
|
return SelectCard14443A_4(false, verbose, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireSelectEx(DesfireContext *ctx, bool fieldon, DesfireISOSelectWay way, uint32_t id, char *dfname) {
|
int DesfireSelectEx(DesfireContext_t *ctx, bool fieldon, DesfireISOSelectWay way, uint32_t id, char *dfname) {
|
||||||
uint8_t resp[250] = {0};
|
uint8_t resp[250] = {0};
|
||||||
size_t resplen = 0;
|
size_t resplen = 0;
|
||||||
|
|
||||||
|
@ -2971,6 +2971,6 @@ int DesfireSelectEx(DesfireContext *ctx, bool fieldon, DesfireISOSelectWay way,
|
||||||
return PM3_ESOFT;
|
return PM3_ESOFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireSelect(DesfireContext *ctx, DesfireISOSelectWay way, uint32_t id, char *dfname) {
|
int DesfireSelect(DesfireContext_t *ctx, DesfireISOSelectWay way, uint32_t id, char *dfname) {
|
||||||
return DesfireSelectEx(ctx, true, way, id, dfname);
|
return DesfireSelectEx(ctx, true, way, id, dfname);
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ typedef struct {
|
||||||
const uint8_t len;
|
const uint8_t len;
|
||||||
const uint8_t createlen;
|
const uint8_t createlen;
|
||||||
const bool mayHaveISOfid;
|
const bool mayHaveISOfid;
|
||||||
} DesfireCreateFileCommandsS;
|
} DesfireCreateFileCommands_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
// all
|
// all
|
||||||
|
@ -81,15 +81,15 @@ typedef struct {
|
||||||
uint8_t additionalAccessRightsLength;
|
uint8_t additionalAccessRightsLength;
|
||||||
uint16_t additionalAccessRights[16];
|
uint16_t additionalAccessRights[16];
|
||||||
|
|
||||||
} FileSettingsS;
|
} FileSettings_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t fileNum;
|
uint8_t fileNum;
|
||||||
uint16_t fileISONum;
|
uint16_t fileISONum;
|
||||||
FileSettingsS fileSettings;
|
FileSettings_t fileSettings;
|
||||||
} FileListElmS;
|
} FileListElm_t;
|
||||||
|
|
||||||
typedef FileListElmS FileListS[32];
|
typedef FileListElm_t FileList_t[32];
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
bool checked;
|
bool checked;
|
||||||
|
@ -98,13 +98,13 @@ typedef struct {
|
||||||
bool authAES;
|
bool authAES;
|
||||||
bool authEV2;
|
bool authEV2;
|
||||||
bool authISONative;
|
bool authISONative;
|
||||||
} AuthCommandsChk;
|
} AuthCommandsChk_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t appNum;
|
uint32_t appNum;
|
||||||
uint16_t appISONum;
|
uint16_t appISONum;
|
||||||
char appDFName[16];
|
char appDFName[16];
|
||||||
AuthCommandsChk authCmdCheck;
|
AuthCommandsChk_t authCmdCheck;
|
||||||
|
|
||||||
uint8_t keySettings;
|
uint8_t keySettings;
|
||||||
uint8_t numKeysRaw;
|
uint8_t numKeysRaw;
|
||||||
|
@ -117,21 +117,21 @@ typedef struct {
|
||||||
bool filesReaded;
|
bool filesReaded;
|
||||||
size_t filesCount;
|
size_t filesCount;
|
||||||
bool isoPresent;
|
bool isoPresent;
|
||||||
FileListS fileList;
|
FileList_t fileList;
|
||||||
} AppListElmS;
|
} AppListElm_t;
|
||||||
typedef AppListElmS AppListS[64];
|
typedef AppListElm_t AppListS[64];
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
size_t appCount;
|
size_t appCount;
|
||||||
uint32_t freemem;
|
uint32_t freemem;
|
||||||
AuthCommandsChk authCmdCheck;
|
AuthCommandsChk_t authCmdCheck;
|
||||||
|
|
||||||
uint8_t keySettings;
|
uint8_t keySettings;
|
||||||
uint8_t numKeysRaw;
|
uint8_t numKeysRaw;
|
||||||
uint8_t numberOfKeys; // from numKeysRaw
|
uint8_t numberOfKeys; // from numKeysRaw
|
||||||
|
|
||||||
uint8_t keyVersion0;
|
uint8_t keyVersion0;
|
||||||
} PICCInfoS;
|
} PICCInfo_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
RFTAuto,
|
RFTAuto,
|
||||||
|
@ -154,75 +154,75 @@ const char *DesfireGetErrorString(int res, uint16_t *sw);
|
||||||
uint32_t DesfireAIDByteToUint(uint8_t *data);
|
uint32_t DesfireAIDByteToUint(uint8_t *data);
|
||||||
void DesfireAIDUintToByte(uint32_t aid, uint8_t *data);
|
void DesfireAIDUintToByte(uint32_t aid, uint8_t *data);
|
||||||
|
|
||||||
void DesfirePrintContext(DesfireContext *ctx);
|
void DesfirePrintContext(DesfireContext_t *ctx);
|
||||||
|
|
||||||
int DesfireExchange(DesfireContext *ctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *respcode, uint8_t *resp, size_t *resplen);
|
int DesfireExchange(DesfireContext_t *ctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *respcode, uint8_t *resp, size_t *resplen);
|
||||||
int DesfireExchangeEx(bool activate_field, DesfireContext *ctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *respcode, uint8_t *resp, size_t *resplen, bool enable_chaining, size_t splitbysize);
|
int DesfireExchangeEx(bool activate_field, DesfireContext_t *ctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *respcode, uint8_t *resp, size_t *resplen, bool enable_chaining, size_t splitbysize);
|
||||||
|
|
||||||
int DesfireReadSignature(DesfireContext *dctx, uint8_t sid, uint8_t *resp, size_t *resplen);
|
int DesfireReadSignature(DesfireContext_t *dctx, uint8_t sid, uint8_t *resp, size_t *resplen);
|
||||||
|
|
||||||
int DesfireAnticollision(bool verbose);
|
int DesfireAnticollision(bool verbose);
|
||||||
int DesfireSelectAID(DesfireContext *ctx, uint8_t *aid1, uint8_t *aid2);
|
int DesfireSelectAID(DesfireContext_t *ctx, uint8_t *aid1, uint8_t *aid2);
|
||||||
int DesfireSelectAIDHex(DesfireContext *ctx, uint32_t aid1, bool select_two, uint32_t aid2);
|
int DesfireSelectAIDHex(DesfireContext_t *ctx, uint32_t aid1, bool select_two, uint32_t aid2);
|
||||||
int DesfireSelectAIDHexNoFieldOn(DesfireContext *ctx, uint32_t aid);
|
int DesfireSelectAIDHexNoFieldOn(DesfireContext_t *ctx, uint32_t aid);
|
||||||
void DesfirePrintAIDFunctions(uint32_t appid);
|
void DesfirePrintAIDFunctions(uint32_t appid);
|
||||||
void DesfirePrintMADAID(uint32_t appid, bool verbose);
|
void DesfirePrintMADAID(uint32_t appid, bool verbose);
|
||||||
|
|
||||||
int DesfireGetCardUID(DesfireContext *ctx);
|
int DesfireGetCardUID(DesfireContext_t *ctx);
|
||||||
|
|
||||||
const char *DesfireSelectWayToStr(DesfireISOSelectWay way);
|
const char *DesfireSelectWayToStr(DesfireISOSelectWay way);
|
||||||
char *DesfireWayIDStr(DesfireISOSelectWay way, uint32_t id);
|
char *DesfireWayIDStr(DesfireISOSelectWay way, uint32_t id);
|
||||||
bool DesfireMFSelected(DesfireISOSelectWay way, uint32_t id);
|
bool DesfireMFSelected(DesfireISOSelectWay way, uint32_t id);
|
||||||
int DesfireSelectEx(DesfireContext *ctx, bool fieldon, DesfireISOSelectWay way, uint32_t id, char *dfname);
|
int DesfireSelectEx(DesfireContext_t *ctx, bool fieldon, DesfireISOSelectWay way, uint32_t id, char *dfname);
|
||||||
int DesfireSelect(DesfireContext *ctx, DesfireISOSelectWay way, uint32_t id, char *dfname);
|
int DesfireSelect(DesfireContext_t *ctx, DesfireISOSelectWay way, uint32_t id, char *dfname);
|
||||||
|
|
||||||
const char *DesfireAuthErrorToStr(int error);
|
const char *DesfireAuthErrorToStr(int error);
|
||||||
int DesfireSelectAndAuthenticate(DesfireContext *dctx, DesfireSecureChannel secureChannel, uint32_t aid, bool verbose);
|
int DesfireSelectAndAuthenticate(DesfireContext_t *dctx, DesfireSecureChannel secureChannel, uint32_t aid, bool verbose);
|
||||||
int DesfireSelectAndAuthenticateEx(DesfireContext *dctx, DesfireSecureChannel secureChannel, uint32_t aid, bool noauth, bool verbose);
|
int DesfireSelectAndAuthenticateEx(DesfireContext_t *dctx, DesfireSecureChannel secureChannel, uint32_t aid, bool noauth, bool verbose);
|
||||||
int DesfireSelectAndAuthenticateW(DesfireContext *dctx, DesfireSecureChannel secureChannel, DesfireISOSelectWay way, uint32_t id, bool selectfile, uint16_t isofileid, bool noauth, bool verbose);
|
int DesfireSelectAndAuthenticateW(DesfireContext_t *dctx, DesfireSecureChannel secureChannel, DesfireISOSelectWay way, uint32_t id, bool selectfile, uint16_t isofileid, bool noauth, bool verbose);
|
||||||
int DesfireSelectAndAuthenticateAppW(DesfireContext *dctx, DesfireSecureChannel secureChannel, DesfireISOSelectWay way, uint32_t id, bool noauth, bool verbose);
|
int DesfireSelectAndAuthenticateAppW(DesfireContext_t *dctx, DesfireSecureChannel secureChannel, DesfireISOSelectWay way, uint32_t id, bool noauth, bool verbose);
|
||||||
int DesfireSelectAndAuthenticateISO(DesfireContext *dctx, DesfireSecureChannel secureChannel, bool useaid, uint32_t aid, uint16_t isoappid, bool selectfile, uint16_t isofileid, bool noauth, bool verbose);
|
int DesfireSelectAndAuthenticateISO(DesfireContext_t *dctx, DesfireSecureChannel secureChannel, bool useaid, uint32_t aid, uint16_t isoappid, bool selectfile, uint16_t isofileid, bool noauth, bool verbose);
|
||||||
int DesfireAuthenticate(DesfireContext *dctx, DesfireSecureChannel secureChannel, bool verbose);
|
int DesfireAuthenticate(DesfireContext_t *dctx, DesfireSecureChannel secureChannel, bool verbose);
|
||||||
void DesfireCheckAuthCommands(uint32_t appAID, char *dfname, uint8_t keyNum, AuthCommandsChk *authCmdCheck);
|
void DesfireCheckAuthCommands(uint32_t appAID, char *dfname, uint8_t keyNum, AuthCommandsChk_t *authCmdCheck);
|
||||||
void DesfireCheckAuthCommandsPrint(AuthCommandsChk *authCmdCheck);
|
void DesfireCheckAuthCommandsPrint(AuthCommandsChk_t *authCmdCheck);
|
||||||
|
|
||||||
int DesfireFormatPICC(DesfireContext *dctx);
|
int DesfireFormatPICC(DesfireContext_t *dctx);
|
||||||
int DesfireGetFreeMem(DesfireContext *dctx, uint32_t *freemem);
|
int DesfireGetFreeMem(DesfireContext_t *dctx, uint32_t *freemem);
|
||||||
int DesfireGetUID(DesfireContext *dctx, uint8_t *resp, size_t *resplen);
|
int DesfireGetUID(DesfireContext_t *dctx, uint8_t *resp, size_t *resplen);
|
||||||
int DesfireGetAIDList(DesfireContext *dctx, uint8_t *resp, size_t *resplen);
|
int DesfireGetAIDList(DesfireContext_t *dctx, uint8_t *resp, size_t *resplen);
|
||||||
int DesfireGetDFList(DesfireContext *dctx, uint8_t *resp, size_t *resplen);
|
int DesfireGetDFList(DesfireContext_t *dctx, uint8_t *resp, size_t *resplen);
|
||||||
int DesfireFillPICCInfo(DesfireContext *dctx, PICCInfoS *PICCInfo, bool deepmode);
|
int DesfireFillPICCInfo(DesfireContext_t *dctx, PICCInfo_t *PICCInfo, bool deepmode);
|
||||||
int DesfireFillAppList(DesfireContext *dctx, PICCInfoS *PICCInfo, AppListS appList, bool deepmode, bool readFiles, bool fillAppSettings);
|
int DesfireFillAppList(DesfireContext_t *dctx, PICCInfo_t *PICCInfo, AppListS appList, bool deepmode, bool readFiles, bool fillAppSettings);
|
||||||
void DesfirePrintPICCInfo(DesfireContext *dctx, PICCInfoS *PICCInfo);
|
void DesfirePrintPICCInfo(DesfireContext_t *dctx, PICCInfo_t *PICCInfo);
|
||||||
void DesfirePrintAppList(DesfireContext *dctx, PICCInfoS *PICCInfo, AppListS appList);
|
void DesfirePrintAppList(DesfireContext_t *dctx, PICCInfo_t *PICCInfo, AppListS appList);
|
||||||
|
|
||||||
int DesfireCreateApplication(DesfireContext *dctx, uint8_t *appdata, size_t appdatalen);
|
int DesfireCreateApplication(DesfireContext_t *dctx, uint8_t *appdata, size_t appdatalen);
|
||||||
int DesfireDeleteApplication(DesfireContext *dctx, uint32_t aid);
|
int DesfireDeleteApplication(DesfireContext_t *dctx, uint32_t aid);
|
||||||
|
|
||||||
int DesfireGetKeyVersion(DesfireContext *dctx, uint8_t *data, size_t len, uint8_t *resp, size_t *resplen);
|
int DesfireGetKeyVersion(DesfireContext_t *dctx, uint8_t *data, size_t len, uint8_t *resp, size_t *resplen);
|
||||||
int DesfireGetKeySettings(DesfireContext *dctx, uint8_t *resp, size_t *resplen);
|
int DesfireGetKeySettings(DesfireContext_t *dctx, uint8_t *resp, size_t *resplen);
|
||||||
int DesfireChangeKeySettings(DesfireContext *dctx, uint8_t *data, size_t len);
|
int DesfireChangeKeySettings(DesfireContext_t *dctx, uint8_t *data, size_t len);
|
||||||
void PrintKeySettings(uint8_t keysettings, uint8_t numkeys, bool applevel, bool print2ndbyte);
|
void PrintKeySettings(uint8_t keysettings, uint8_t numkeys, bool applevel, bool print2ndbyte);
|
||||||
|
|
||||||
int DesfireChangeKeyCmd(DesfireContext *dctx, uint8_t *data, size_t datalen, uint8_t *resp, size_t *resplen);
|
int DesfireChangeKeyCmd(DesfireContext_t *dctx, uint8_t *data, size_t datalen, uint8_t *resp, size_t *resplen);
|
||||||
int DesfireChangeKey(DesfireContext *dctx, bool change_master_key, uint8_t newkeynum, DesfireCryptoAlgorythm newkeytype, uint32_t newkeyver, uint8_t *newkey, DesfireCryptoAlgorythm oldkeytype, uint8_t *oldkey, bool verbose);
|
int DesfireChangeKey(DesfireContext_t *dctx, bool change_master_key, uint8_t newkeynum, DesfireCryptoAlgorythm newkeytype, uint32_t newkeyver, uint8_t *newkey, DesfireCryptoAlgorythm oldkeytype, uint8_t *oldkey, bool verbose);
|
||||||
|
|
||||||
int DesfireSetConfigurationCmd(DesfireContext *dctx, uint8_t *data, size_t len, uint8_t *resp, size_t *resplen);
|
int DesfireSetConfigurationCmd(DesfireContext_t *dctx, uint8_t *data, size_t len, uint8_t *resp, size_t *resplen);
|
||||||
int DesfireSetConfiguration(DesfireContext *dctx, uint8_t paramid, uint8_t *param, size_t paramlen);
|
int DesfireSetConfiguration(DesfireContext_t *dctx, uint8_t paramid, uint8_t *param, size_t paramlen);
|
||||||
|
|
||||||
int DesfireFillFileList(DesfireContext *dctx, FileListS FileList, size_t *filescount, bool *isopresent);
|
int DesfireFillFileList(DesfireContext_t *dctx, FileList_t FileList, size_t *filescount, bool *isopresent);
|
||||||
int DesfireGetFileIDList(DesfireContext *dctx, uint8_t *resp, size_t *resplen);
|
int DesfireGetFileIDList(DesfireContext_t *dctx, uint8_t *resp, size_t *resplen);
|
||||||
int DesfireGetFileISOIDList(DesfireContext *dctx, uint8_t *resp, size_t *resplen);
|
int DesfireGetFileISOIDList(DesfireContext_t *dctx, uint8_t *resp, size_t *resplen);
|
||||||
|
|
||||||
void DesfireFillFileSettings(uint8_t *data, size_t datalen, FileSettingsS *fsettings);
|
void DesfireFillFileSettings(uint8_t *data, size_t datalen, FileSettings_t *fsettings);
|
||||||
void DesfirePrintFileSettingsOneLine(FileSettingsS *fsettings);
|
void DesfirePrintFileSettingsOneLine(FileSettings_t *fsettings);
|
||||||
void DesfirePrintFileSettingsTable(bool printheader, uint8_t id, bool isoidavail, uint16_t isoid, FileSettingsS *fsettings);
|
void DesfirePrintFileSettingsTable(bool printheader, uint8_t id, bool isoidavail, uint16_t isoid, FileSettings_t *fsettings);
|
||||||
void DesfirePrintFileSettingsExtended(FileSettingsS *fsettings);
|
void DesfirePrintFileSettingsExtended(FileSettings_t *fsettings);
|
||||||
int DesfireGetFileSettings(DesfireContext *dctx, uint8_t fileid, uint8_t *resp, size_t *resplen);
|
int DesfireGetFileSettings(DesfireContext_t *dctx, uint8_t fileid, uint8_t *resp, size_t *resplen);
|
||||||
int DesfireGetFileSettingsStruct(DesfireContext *dctx, uint8_t fileid, FileSettingsS *fsettings);
|
int DesfireFileSettingsStruct(DesfireContext_t *dctx, uint8_t fileid, FileSettings_t *fsettings);
|
||||||
int DesfireChangeFileSettings(DesfireContext *dctx, uint8_t *data, size_t datalen);
|
int DesfireChangeFileSettings(DesfireContext_t *dctx, uint8_t *data, size_t datalen);
|
||||||
|
|
||||||
const DesfireCreateFileCommandsS *GetDesfireFileCmdRec(uint8_t type);
|
const DesfireCreateFileCommands_t *GetDesfireFileCmdRec(uint8_t type);
|
||||||
const char *GetDesfireAccessRightStr(uint8_t right);
|
const char *GetDesfireAccessRightStr(uint8_t right);
|
||||||
const char *GetDesfireAccessRightShortStr(uint8_t right);
|
const char *GetDesfireAccessRightShortStr(uint8_t right);
|
||||||
void DesfireEncodeFileAcessMode(uint8_t *mode, uint8_t r, uint8_t w, uint8_t rw, uint8_t ch);
|
void DesfireEncodeFileAcessMode(uint8_t *mode, uint8_t r, uint8_t w, uint8_t rw, uint8_t ch);
|
||||||
|
@ -233,33 +233,33 @@ void DesfirePrintSetFileSettings(uint8_t *data, size_t len);
|
||||||
void DesfirePrintCreateFileSettings(uint8_t filetype, uint8_t *data, size_t len);
|
void DesfirePrintCreateFileSettings(uint8_t filetype, uint8_t *data, size_t len);
|
||||||
|
|
||||||
const char *GetDesfireFileType(uint8_t type);
|
const char *GetDesfireFileType(uint8_t type);
|
||||||
int DesfireCreateFile(DesfireContext *dctx, uint8_t ftype, uint8_t *fdata, size_t fdatalen, bool checklen);
|
int DesfireCreateFile(DesfireContext_t *dctx, uint8_t ftype, uint8_t *fdata, size_t fdatalen, bool checklen);
|
||||||
int DesfireDeleteFile(DesfireContext *dctx, uint8_t fnum);
|
int DesfireDeleteFile(DesfireContext_t *dctx, uint8_t fnum);
|
||||||
int DesfireCommitReaderID(DesfireContext *dctx, uint8_t *readerid, size_t readeridlen, uint8_t *resp, size_t *resplen);
|
int DesfireCommitReaderID(DesfireContext_t *dctx, uint8_t *readerid, size_t readeridlen, uint8_t *resp, size_t *resplen);
|
||||||
int DesfireCommitTransactionEx(DesfireContext *dctx, bool enable_options, uint8_t options, uint8_t *resp, size_t *resplen);
|
int DesfireCommitTransactionEx(DesfireContext_t *dctx, bool enable_options, uint8_t options, uint8_t *resp, size_t *resplen);
|
||||||
int DesfireCommitTransaction(DesfireContext *dctx, bool enable_options, uint8_t options);
|
int DesfireCommitTransaction(DesfireContext_t *dctx, bool enable_options, uint8_t options);
|
||||||
int DesfireAbortTransaction(DesfireContext *dctx);
|
int DesfireAbortTransaction(DesfireContext_t *dctx);
|
||||||
|
|
||||||
int DesfireValueFileOperations(DesfireContext *dctx, uint8_t fid, uint8_t operation, uint32_t *value);
|
int DesfireValueFileOperations(DesfireContext_t *dctx, uint8_t fid, uint8_t operation, uint32_t *value);
|
||||||
int DesfireClearRecordFile(DesfireContext *dctx, uint8_t fnum);
|
int DesfireClearRecordFile(DesfireContext_t *dctx, uint8_t fnum);
|
||||||
|
|
||||||
int DesfireReadFile(DesfireContext *dctx, uint8_t fnum, uint32_t offset, uint32_t len, uint8_t *resp, size_t *resplen);
|
int DesfireReadFile(DesfireContext_t *dctx, uint8_t fnum, uint32_t offset, uint32_t len, uint8_t *resp, size_t *resplen);
|
||||||
int DesfireWriteFile(DesfireContext *dctx, uint8_t fnum, uint32_t offset, uint32_t len, uint8_t *data);
|
int DesfireWriteFile(DesfireContext_t *dctx, uint8_t fnum, uint32_t offset, uint32_t len, uint8_t *data);
|
||||||
int DesfireReadRecords(DesfireContext *dctx, uint8_t fnum, uint32_t recnum, uint32_t reccount, uint8_t *resp, size_t *resplen);
|
int DesfireReadRecords(DesfireContext_t *dctx, uint8_t fnum, uint32_t recnum, uint32_t reccount, uint8_t *resp, size_t *resplen);
|
||||||
int DesfireWriteRecord(DesfireContext *dctx, uint8_t fnum, uint32_t offset, uint32_t len, uint8_t *data);
|
int DesfireWriteRecord(DesfireContext_t *dctx, uint8_t fnum, uint32_t offset, uint32_t len, uint8_t *data);
|
||||||
int DesfireUpdateRecord(DesfireContext *dctx, uint8_t fnum, uint32_t recnum, uint32_t offset, uint32_t len, uint8_t *data);
|
int DesfireUpdateRecord(DesfireContext_t *dctx, uint8_t fnum, uint32_t recnum, uint32_t offset, uint32_t len, uint8_t *data);
|
||||||
|
|
||||||
int DesfireISOSelectDF(DesfireContext *dctx, char *dfname, uint8_t *resp, size_t *resplen);
|
int DesfireISOSelectDF(DesfireContext_t *dctx, char *dfname, uint8_t *resp, size_t *resplen);
|
||||||
int DesfireISOSelect(DesfireContext *dctx, DesfireISOSelectControl cntr, uint8_t *data, uint8_t datalen, uint8_t *resp, size_t *resplen);
|
int DesfireISOSelect(DesfireContext_t *dctx, DesfireISOSelectControl cntr, uint8_t *data, uint8_t datalen, uint8_t *resp, size_t *resplen);
|
||||||
int DesfireISOSelectFile(DesfireContext *dctx, char *appdfname, uint16_t appid, uint16_t fileid);
|
int DesfireISOSelectFile(DesfireContext_t *dctx, char *appdfname, uint16_t appid, uint16_t fileid);
|
||||||
int DesfireISOSelectEx(DesfireContext *dctx, bool fieldon, DesfireISOSelectControl cntr, uint8_t *data, uint8_t datalen, uint8_t *resp, size_t *resplen);
|
int DesfireISOSelectEx(DesfireContext_t *dctx, bool fieldon, DesfireISOSelectControl cntr, uint8_t *data, uint8_t datalen, uint8_t *resp, size_t *resplen);
|
||||||
int DesfireISOGetChallenge(DesfireContext *dctx, DesfireCryptoAlgorythm keytype, uint8_t *resp, size_t *resplen);
|
int DesfireISOGetChallenge(DesfireContext_t *dctx, DesfireCryptoAlgorythm keytype, uint8_t *resp, size_t *resplen);
|
||||||
int DesfireISOExternalAuth(DesfireContext *dctx, bool app_level, uint8_t keynum, DesfireCryptoAlgorythm keytype, uint8_t *data);
|
int DesfireISOExternalAuth(DesfireContext_t *dctx, bool app_level, uint8_t keynum, DesfireCryptoAlgorythm keytype, uint8_t *data);
|
||||||
int DesfireISOInternalAuth(DesfireContext *dctx, bool app_level, uint8_t keynum, DesfireCryptoAlgorythm keytype, uint8_t *data, uint8_t *resp, size_t *resplen);
|
int DesfireISOInternalAuth(DesfireContext_t *dctx, bool app_level, uint8_t keynum, DesfireCryptoAlgorythm keytype, uint8_t *data, uint8_t *resp, size_t *resplen);
|
||||||
|
|
||||||
int DesfireISOReadBinary(DesfireContext *dctx, bool use_file_id, uint8_t fileid, uint16_t offset, uint8_t length, uint8_t *resp, size_t *resplen);
|
int DesfireISOReadBinary(DesfireContext_t *dctx, bool use_file_id, uint8_t fileid, uint16_t offset, uint8_t length, uint8_t *resp, size_t *resplen);
|
||||||
int DesfireISOUpdateBinary(DesfireContext *dctx, bool use_file_id, uint8_t fileid, uint16_t offset, uint8_t *data, size_t datalen);
|
int DesfireISOUpdateBinary(DesfireContext_t *dctx, bool use_file_id, uint8_t fileid, uint16_t offset, uint8_t *data, size_t datalen);
|
||||||
int DesfireISOReadRecords(DesfireContext *dctx, uint8_t recordnum, bool read_all_records, uint8_t fileid, uint8_t length, uint8_t *resp, size_t *resplen);
|
int DesfireISOReadRecords(DesfireContext_t *dctx, uint8_t recordnum, bool read_all_records, uint8_t fileid, uint8_t length, uint8_t *resp, size_t *resplen);
|
||||||
int DesfireISOAppendRecord(DesfireContext *dctx, uint8_t fileid, uint8_t *data, size_t datalen);
|
int DesfireISOAppendRecord(DesfireContext_t *dctx, uint8_t fileid, uint8_t *data, size_t datalen);
|
||||||
|
|
||||||
#endif // __DESFIRECORE_H
|
#endif // __DESFIRECORE_H
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
#include "crc32.h"
|
#include "crc32.h"
|
||||||
#include "commonutil.h"
|
#include "commonutil.h"
|
||||||
|
|
||||||
void DesfireClearContext(DesfireContext *ctx) {
|
void DesfireClearContext(DesfireContext_t *ctx) {
|
||||||
ctx->keyNum = 0;
|
ctx->keyNum = 0;
|
||||||
ctx->keyType = T_DES;
|
ctx->keyType = T_DES;
|
||||||
memset(ctx->key, 0, sizeof(ctx->key));
|
memset(ctx->key, 0, sizeof(ctx->key));
|
||||||
|
@ -55,7 +55,7 @@ void DesfireClearContext(DesfireContext *ctx) {
|
||||||
DesfireClearSession(ctx);
|
DesfireClearSession(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesfireClearSession(DesfireContext *ctx) {
|
void DesfireClearSession(DesfireContext_t *ctx) {
|
||||||
ctx->secureChannel = DACNone; // here none - not authenticared
|
ctx->secureChannel = DACNone; // here none - not authenticared
|
||||||
|
|
||||||
memset(ctx->IV, 0, sizeof(ctx->IV));
|
memset(ctx->IV, 0, sizeof(ctx->IV));
|
||||||
|
@ -68,42 +68,42 @@ void DesfireClearSession(DesfireContext *ctx) {
|
||||||
memset(ctx->TI, 0, sizeof(ctx->TI));
|
memset(ctx->TI, 0, sizeof(ctx->TI));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesfireClearIV(DesfireContext *ctx) {
|
void DesfireClearIV(DesfireContext_t *ctx) {
|
||||||
memset(ctx->IV, 0, sizeof(ctx->IV));
|
memset(ctx->IV, 0, sizeof(ctx->IV));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesfireSetKey(DesfireContext *ctx, uint8_t keyNum, enum DESFIRE_CRYPTOALGO keyType, uint8_t *key) {
|
void DesfireSetKey(DesfireContext_t *ctx, uint8_t keyNum, enum DESFIRE_CRYPTOALGO keyType, uint8_t *key) {
|
||||||
DesfireClearContext(ctx);
|
DesfireClearContext(ctx);
|
||||||
DesfireSetKeyNoClear(ctx, keyNum, keyType, key);
|
DesfireSetKeyNoClear(ctx, keyNum, keyType, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesfireSetKeyNoClear(DesfireContext *ctx, uint8_t keyNum, enum DESFIRE_CRYPTOALGO keyType, uint8_t *key) {
|
void DesfireSetKeyNoClear(DesfireContext_t *ctx, uint8_t keyNum, enum DESFIRE_CRYPTOALGO keyType, uint8_t *key) {
|
||||||
ctx->keyNum = keyNum;
|
ctx->keyNum = keyNum;
|
||||||
ctx->keyType = keyType;
|
ctx->keyType = keyType;
|
||||||
memcpy(ctx->key, key, desfire_get_key_length(keyType));
|
memcpy(ctx->key, key, desfire_get_key_length(keyType));
|
||||||
memcpy(ctx->masterKey, key, desfire_get_key_length(keyType));
|
memcpy(ctx->masterKey, key, desfire_get_key_length(keyType));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesfireSetCommandSet(DesfireContext *ctx, DesfireCommandSet cmdSet) {
|
void DesfireSetCommandSet(DesfireContext_t *ctx, DesfireCommandSet cmdSet) {
|
||||||
ctx->cmdSet = cmdSet;
|
ctx->cmdSet = cmdSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesfireSetCommMode(DesfireContext *ctx, DesfireCommunicationMode commMode) {
|
void DesfireSetCommMode(DesfireContext_t *ctx, DesfireCommunicationMode commMode) {
|
||||||
ctx->commMode = commMode;
|
ctx->commMode = commMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesfireSetKdf(DesfireContext *ctx, uint8_t kdfAlgo, uint8_t *kdfInput, uint8_t kdfInputLen) {
|
void DesfireSetKdf(DesfireContext_t *ctx, uint8_t kdfAlgo, uint8_t *kdfInput, uint8_t kdfInputLen) {
|
||||||
ctx->kdfAlgo = kdfAlgo;
|
ctx->kdfAlgo = kdfAlgo;
|
||||||
ctx->kdfInputLen = kdfInputLen;
|
ctx->kdfInputLen = kdfInputLen;
|
||||||
if (kdfInputLen)
|
if (kdfInputLen)
|
||||||
memcpy(ctx->kdfInput, kdfInput, kdfInputLen);
|
memcpy(ctx->kdfInput, kdfInput, kdfInputLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DesfireIsAuthenticated(DesfireContext *dctx) {
|
bool DesfireIsAuthenticated(DesfireContext_t *dctx) {
|
||||||
return dctx->secureChannel != DACNone;
|
return dctx->secureChannel != DACNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t DesfireGetMACLength(DesfireContext *ctx) {
|
size_t DesfireGetMACLength(DesfireContext_t *ctx) {
|
||||||
size_t mac_length = DESFIRE_MAC_LENGTH;
|
size_t mac_length = DESFIRE_MAC_LENGTH;
|
||||||
switch (ctx->secureChannel) {
|
switch (ctx->secureChannel) {
|
||||||
case DACNone:
|
case DACNone:
|
||||||
|
@ -162,7 +162,7 @@ size_t DesfireSearchCRCPos(uint8_t *data, size_t datalen, uint8_t respcode, uint
|
||||||
return crcposfound;
|
return crcposfound;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *DesfireGetKey(DesfireContext *ctx, DesfireCryptoOpKeyType key_type) {
|
uint8_t *DesfireGetKey(DesfireContext_t *ctx, DesfireCryptoOpKeyType key_type) {
|
||||||
if (key_type == DCOSessionKeyMac) {
|
if (key_type == DCOSessionKeyMac) {
|
||||||
return ctx->sessionKeyMAC;
|
return ctx->sessionKeyMAC;
|
||||||
} else if (key_type == DCOSessionKeyEnc) {
|
} else if (key_type == DCOSessionKeyEnc) {
|
||||||
|
@ -241,7 +241,7 @@ static void DesfireCryptoEncDecSingleBlock(uint8_t *key, DesfireCryptoAlgorythm
|
||||||
memcpy(dstdata, edata, block_size);
|
memcpy(dstdata, edata, block_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesfireCryptoEncDecEx(DesfireContext *ctx, DesfireCryptoOpKeyType key_type, uint8_t *srcdata, size_t srcdatalen, uint8_t *dstdata, bool dir_to_send, bool encode, uint8_t *iv) {
|
void DesfireCryptoEncDecEx(DesfireContext_t *ctx, DesfireCryptoOpKeyType key_type, uint8_t *srcdata, size_t srcdatalen, uint8_t *dstdata, bool dir_to_send, bool encode, uint8_t *iv) {
|
||||||
uint8_t data[1024] = {0};
|
uint8_t data[1024] = {0};
|
||||||
uint8_t xiv[DESFIRE_MAX_CRYPTO_BLOCK_SIZE] = {0};
|
uint8_t xiv[DESFIRE_MAX_CRYPTO_BLOCK_SIZE] = {0};
|
||||||
|
|
||||||
|
@ -281,7 +281,7 @@ void DesfireCryptoEncDecEx(DesfireContext *ctx, DesfireCryptoOpKeyType key_type,
|
||||||
memcpy(dstdata, data, srcdatalen);
|
memcpy(dstdata, data, srcdatalen);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesfireCryptoEncDec(DesfireContext *ctx, DesfireCryptoOpKeyType key_type, uint8_t *srcdata, size_t srcdatalen, uint8_t *dstdata, bool encode) {
|
void DesfireCryptoEncDec(DesfireContext_t *ctx, DesfireCryptoOpKeyType key_type, uint8_t *srcdata, size_t srcdatalen, uint8_t *dstdata, bool encode) {
|
||||||
bool dir_to_send = encode;
|
bool dir_to_send = encode;
|
||||||
bool xencode = encode;
|
bool xencode = encode;
|
||||||
if (ctx->secureChannel == DACd40)
|
if (ctx->secureChannel == DACd40)
|
||||||
|
@ -290,7 +290,7 @@ void DesfireCryptoEncDec(DesfireContext *ctx, DesfireCryptoOpKeyType key_type, u
|
||||||
DesfireCryptoEncDecEx(ctx, key_type, srcdata, srcdatalen, dstdata, dir_to_send, xencode, NULL);
|
DesfireCryptoEncDecEx(ctx, key_type, srcdata, srcdatalen, dstdata, dir_to_send, xencode, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesfireCMACGenerateSubkeys(DesfireContext *ctx, DesfireCryptoOpKeyType key_type, uint8_t *sk1, uint8_t *sk2) {
|
void DesfireCMACGenerateSubkeys(DesfireContext_t *ctx, DesfireCryptoOpKeyType key_type, uint8_t *sk1, uint8_t *sk2) {
|
||||||
int kbs = desfire_get_key_block_length(ctx->keyType);
|
int kbs = desfire_get_key_block_length(ctx->keyType);
|
||||||
const uint8_t R = (kbs == 8) ? 0x1B : 0x87;
|
const uint8_t R = (kbs == 8) ? 0x1B : 0x87;
|
||||||
|
|
||||||
|
@ -321,7 +321,7 @@ void DesfireCMACGenerateSubkeys(DesfireContext *ctx, DesfireCryptoOpKeyType key_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesfireCryptoCMACEx(DesfireContext *ctx, DesfireCryptoOpKeyType key_type, uint8_t *data, size_t len, size_t minlen, uint8_t *cmac) {
|
void DesfireCryptoCMACEx(DesfireContext_t *ctx, DesfireCryptoOpKeyType key_type, uint8_t *data, size_t len, size_t minlen, uint8_t *cmac) {
|
||||||
int kbs = desfire_get_key_block_length(ctx->keyType);
|
int kbs = desfire_get_key_block_length(ctx->keyType);
|
||||||
if (kbs == 0)
|
if (kbs == 0)
|
||||||
return;
|
return;
|
||||||
|
@ -351,12 +351,12 @@ void DesfireCryptoCMACEx(DesfireContext *ctx, DesfireCryptoOpKeyType key_type, u
|
||||||
memcpy(cmac, ctx->IV, kbs);
|
memcpy(cmac, ctx->IV, kbs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesfireCryptoCMAC(DesfireContext *ctx, uint8_t *data, size_t len, uint8_t *cmac) {
|
void DesfireCryptoCMAC(DesfireContext_t *ctx, uint8_t *data, size_t len, uint8_t *cmac) {
|
||||||
DesfireCryptoCMACEx(ctx, DCOSessionKeyMac, data, len, 0, cmac);
|
DesfireCryptoCMACEx(ctx, DCOSessionKeyMac, data, len, 0, cmac);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function is almot like cmac(...). but with some key differences.
|
// This function is almot like cmac(...). but with some key differences.
|
||||||
void MifareKdfAn10922(DesfireContext *ctx, DesfireCryptoOpKeyType key_type, const uint8_t *data, size_t len) {
|
void MifareKdfAn10922(DesfireContext_t *ctx, DesfireCryptoOpKeyType key_type, const uint8_t *data, size_t len) {
|
||||||
if (ctx == NULL || data == NULL || len < 1 || len > 31)
|
if (ctx == NULL || data == NULL || len < 1 || len > 31)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -582,7 +582,7 @@ void DesfireGenSessionKeyEV2(uint8_t *key, uint8_t *rndA, uint8_t *rndB, bool en
|
||||||
memcpy(data + 24, rndA + 8, 8);
|
memcpy(data + 24, rndA + 8, 8);
|
||||||
|
|
||||||
uint8_t cmac[CRYPTO_AES_BLOCK_SIZE] = {0};
|
uint8_t cmac[CRYPTO_AES_BLOCK_SIZE] = {0};
|
||||||
DesfireContext ctx = {0};
|
DesfireContext_t ctx = {0};
|
||||||
ctx.keyType = T_AES;
|
ctx.keyType = T_AES;
|
||||||
memcpy(ctx.key, key, 16); // aes-128
|
memcpy(ctx.key, key, 16); // aes-128
|
||||||
DesfireCryptoCMAC(&ctx, data, 32, cmac);
|
DesfireCryptoCMAC(&ctx, data, 32, cmac);
|
||||||
|
@ -605,12 +605,12 @@ void DesfireGenSessionKeyLRP(uint8_t *key, uint8_t *rndA, uint8_t *rndB, bool en
|
||||||
data[30] = 0x96;
|
data[30] = 0x96;
|
||||||
data[31] = 0x69;
|
data[31] = 0x69;
|
||||||
|
|
||||||
LRPContext ctx = {0};
|
LRPContext_t ctx = {0};
|
||||||
LRPSetKey(&ctx, key, 0, true);
|
LRPSetKey(&ctx, key, 0, true);
|
||||||
LRPCMAC(&ctx, data, 32, sessionkey);
|
LRPCMAC(&ctx, data, 32, sessionkey);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesfireEV2FillIV(DesfireContext *ctx, bool ivforcommand, uint8_t *iv) {
|
void DesfireEV2FillIV(DesfireContext_t *ctx, bool ivforcommand, uint8_t *iv) {
|
||||||
uint8_t xiv[CRYPTO_AES_BLOCK_SIZE] = {0};
|
uint8_t xiv[CRYPTO_AES_BLOCK_SIZE] = {0};
|
||||||
|
|
||||||
if (ivforcommand) {
|
if (ivforcommand) {
|
||||||
|
@ -633,7 +633,7 @@ void DesfireEV2FillIV(DesfireContext *ctx, bool ivforcommand, uint8_t *iv) {
|
||||||
memcpy(iv, xiv, CRYPTO_AES_BLOCK_SIZE);
|
memcpy(iv, xiv, CRYPTO_AES_BLOCK_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireEV2CalcCMAC(DesfireContext *ctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *mac) {
|
int DesfireEV2CalcCMAC(DesfireContext_t *ctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *mac) {
|
||||||
uint8_t mdata[1050] = {0};
|
uint8_t mdata[1050] = {0};
|
||||||
size_t mdatalen = 0;
|
size_t mdatalen = 0;
|
||||||
|
|
||||||
|
@ -662,7 +662,7 @@ void DesfireGenTransSessionKeyEV2(uint8_t *key, uint32_t trCntr, uint8_t *uid, b
|
||||||
Uint4byteToMemLe(&xiv[5], trCntr + 1);
|
Uint4byteToMemLe(&xiv[5], trCntr + 1);
|
||||||
memcpy(&xiv[9], uid, 7);
|
memcpy(&xiv[9], uid, 7);
|
||||||
|
|
||||||
DesfireContext ctx = {0};
|
DesfireContext_t ctx = {0};
|
||||||
DesfireSetKey(&ctx, 0, T_AES, key);
|
DesfireSetKey(&ctx, 0, T_AES, key);
|
||||||
DesfireCryptoCMACEx(&ctx, DCOMainKey, xiv, 16, 0, sessionkey);
|
DesfireCryptoCMACEx(&ctx, DCOMainKey, xiv, 16, 0, sessionkey);
|
||||||
}
|
}
|
||||||
|
@ -688,12 +688,12 @@ void DesfireGenTransSessionKeyLRP(uint8_t *key, uint32_t trCntr, uint8_t *uid, b
|
||||||
data[15] = 0xa5;
|
data[15] = 0xa5;
|
||||||
}
|
}
|
||||||
|
|
||||||
LRPContext lctx = {0};
|
LRPContext_t lctx = {0};
|
||||||
LRPSetKey(&lctx, key, 0, false);
|
LRPSetKey(&lctx, key, 0, false);
|
||||||
LRPCMAC(&lctx, data, sizeof(data), sessionkey);
|
LRPCMAC(&lctx, data, sizeof(data), sessionkey);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesfireDecodePrevReaderID(DesfireContext *ctx, uint8_t *key, uint32_t trCntr, uint8_t *encPrevReaderID, uint8_t *prevReaderID) {
|
void DesfireDecodePrevReaderID(DesfireContext_t *ctx, uint8_t *key, uint32_t trCntr, uint8_t *encPrevReaderID, uint8_t *prevReaderID) {
|
||||||
uint8_t sessionkey[CRYPTO_AES128_KEY_SIZE] = {0};
|
uint8_t sessionkey[CRYPTO_AES128_KEY_SIZE] = {0};
|
||||||
uint8_t uid[12] = {0};
|
uint8_t uid[12] = {0};
|
||||||
memcpy(uid, ctx->uid, MAX(ctx->uidlen, 7));
|
memcpy(uid, ctx->uid, MAX(ctx->uidlen, 7));
|
||||||
|
@ -706,7 +706,7 @@ void DesfireDecodePrevReaderID(DesfireContext *ctx, uint8_t *key, uint32_t trCnt
|
||||||
aes_decode(NULL, sessionkey, encPrevReaderID, prevReaderID, CRYPTO_AES128_KEY_SIZE);
|
aes_decode(NULL, sessionkey, encPrevReaderID, prevReaderID, CRYPTO_AES128_KEY_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireLRPCalcCMAC(DesfireContext *ctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *mac) {
|
int DesfireLRPCalcCMAC(DesfireContext_t *ctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *mac) {
|
||||||
uint8_t mdata[1050] = {0};
|
uint8_t mdata[1050] = {0};
|
||||||
size_t mdatalen = 0;
|
size_t mdatalen = 0;
|
||||||
|
|
||||||
|
@ -717,7 +717,7 @@ int DesfireLRPCalcCMAC(DesfireContext *ctx, uint8_t cmd, uint8_t *data, size_t d
|
||||||
memcpy(&mdata[7], data, datalen);
|
memcpy(&mdata[7], data, datalen);
|
||||||
mdatalen = 1 + 2 + 4 + datalen;
|
mdatalen = 1 + 2 + 4 + datalen;
|
||||||
|
|
||||||
LRPContext lctx = {0};
|
LRPContext_t lctx = {0};
|
||||||
LRPSetKey(&lctx, ctx->sessionKeyMAC, 0, true);
|
LRPSetKey(&lctx, ctx->sessionKeyMAC, 0, true);
|
||||||
LRPCMAC8(&lctx, mdata, mdatalen, mac);
|
LRPCMAC8(&lctx, mdata, mdatalen, mac);
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ typedef enum {
|
||||||
DCOSessionKeyEnc
|
DCOSessionKeyEnc
|
||||||
} DesfireCryptoOpKeyType;
|
} DesfireCryptoOpKeyType;
|
||||||
|
|
||||||
typedef struct DesfireContextS {
|
typedef struct {
|
||||||
uint8_t keyNum;
|
uint8_t keyNum;
|
||||||
DesfireCryptoAlgorythm keyType; // des/2tdea/3tdea/aes
|
DesfireCryptoAlgorythm keyType; // des/2tdea/3tdea/aes
|
||||||
uint8_t key[DESFIRE_MAX_KEY_SIZE];
|
uint8_t key[DESFIRE_MAX_KEY_SIZE];
|
||||||
|
@ -102,28 +102,28 @@ typedef struct DesfireContextS {
|
||||||
bool lastRequestZeroLen;
|
bool lastRequestZeroLen;
|
||||||
uint16_t cmdCntr; // for AES
|
uint16_t cmdCntr; // for AES
|
||||||
uint8_t TI[4]; // for AES
|
uint8_t TI[4]; // for AES
|
||||||
} DesfireContext;
|
} DesfireContext_t;
|
||||||
|
|
||||||
void DesfireClearContext(DesfireContext *ctx);
|
void DesfireClearContext(DesfireContext_t *ctx);
|
||||||
void DesfireClearSession(DesfireContext *ctx);
|
void DesfireClearSession(DesfireContext_t *ctx);
|
||||||
void DesfireClearIV(DesfireContext *ctx);
|
void DesfireClearIV(DesfireContext_t *ctx);
|
||||||
void DesfireSetKey(DesfireContext *ctx, uint8_t keyNum, enum DESFIRE_CRYPTOALGO keyType, uint8_t *key);
|
void DesfireSetKey(DesfireContext_t *ctx, uint8_t keyNum, enum DESFIRE_CRYPTOALGO keyType, uint8_t *key);
|
||||||
void DesfireSetKeyNoClear(DesfireContext *ctx, uint8_t keyNum, enum DESFIRE_CRYPTOALGO keyType, uint8_t *key);
|
void DesfireSetKeyNoClear(DesfireContext_t *ctx, uint8_t keyNum, enum DESFIRE_CRYPTOALGO keyType, uint8_t *key);
|
||||||
void DesfireSetCommandSet(DesfireContext *ctx, DesfireCommandSet cmdSet);
|
void DesfireSetCommandSet(DesfireContext_t *ctx, DesfireCommandSet cmdSet);
|
||||||
void DesfireSetCommMode(DesfireContext *ctx, DesfireCommunicationMode commMode);
|
void DesfireSetCommMode(DesfireContext_t *ctx, DesfireCommunicationMode commMode);
|
||||||
void DesfireSetKdf(DesfireContext *ctx, uint8_t kdfAlgo, uint8_t *kdfInput, uint8_t kdfInputLen);
|
void DesfireSetKdf(DesfireContext_t *ctx, uint8_t kdfAlgo, uint8_t *kdfInput, uint8_t kdfInputLen);
|
||||||
bool DesfireIsAuthenticated(DesfireContext *dctx);
|
bool DesfireIsAuthenticated(DesfireContext_t *dctx);
|
||||||
size_t DesfireGetMACLength(DesfireContext *ctx);
|
size_t DesfireGetMACLength(DesfireContext_t *ctx);
|
||||||
|
|
||||||
size_t DesfireSearchCRCPos(uint8_t *data, size_t datalen, uint8_t respcode, uint8_t crclen);
|
size_t DesfireSearchCRCPos(uint8_t *data, size_t datalen, uint8_t respcode, uint8_t crclen);
|
||||||
|
|
||||||
uint8_t *DesfireGetKey(DesfireContext *ctx, DesfireCryptoOpKeyType key_type);
|
uint8_t *DesfireGetKey(DesfireContext_t *ctx, DesfireCryptoOpKeyType key_type);
|
||||||
void DesfireCryptoEncDec(DesfireContext *ctx, DesfireCryptoOpKeyType key_type, uint8_t *srcdata, size_t srcdatalen, uint8_t *dstdata, bool encode);
|
void DesfireCryptoEncDec(DesfireContext_t *ctx, DesfireCryptoOpKeyType key_type, uint8_t *srcdata, size_t srcdatalen, uint8_t *dstdata, bool encode);
|
||||||
void DesfireCryptoEncDecEx(DesfireContext *ctx, DesfireCryptoOpKeyType key_type, uint8_t *srcdata, size_t srcdatalen, uint8_t *dstdata, bool dir_to_send, bool encode, uint8_t *iv);
|
void DesfireCryptoEncDecEx(DesfireContext_t *ctx, DesfireCryptoOpKeyType key_type, uint8_t *srcdata, size_t srcdatalen, uint8_t *dstdata, bool dir_to_send, bool encode, uint8_t *iv);
|
||||||
void DesfireCMACGenerateSubkeys(DesfireContext *ctx, DesfireCryptoOpKeyType key_type, uint8_t *sk1, uint8_t *sk2);
|
void DesfireCMACGenerateSubkeys(DesfireContext_t *ctx, DesfireCryptoOpKeyType key_type, uint8_t *sk1, uint8_t *sk2);
|
||||||
void DesfireCryptoCMAC(DesfireContext *ctx, uint8_t *srcdata, size_t srcdatalen, uint8_t *cmac);
|
void DesfireCryptoCMAC(DesfireContext_t *ctx, uint8_t *srcdata, size_t srcdatalen, uint8_t *cmac);
|
||||||
void DesfireCryptoCMACEx(DesfireContext *ctx, DesfireCryptoOpKeyType key_type, uint8_t *data, size_t len, size_t minlen, uint8_t *cmac);
|
void DesfireCryptoCMACEx(DesfireContext_t *ctx, DesfireCryptoOpKeyType key_type, uint8_t *data, size_t len, size_t minlen, uint8_t *cmac);
|
||||||
void MifareKdfAn10922(DesfireContext *ctx, DesfireCryptoOpKeyType key_type, const uint8_t *data, size_t len);
|
void MifareKdfAn10922(DesfireContext_t *ctx, DesfireCryptoOpKeyType key_type, const uint8_t *data, size_t len);
|
||||||
|
|
||||||
void DesfireGenSessionKeyLRP(uint8_t *key, uint8_t *rndA, uint8_t *rndB, bool enckey, uint8_t *sessionkey);
|
void DesfireGenSessionKeyLRP(uint8_t *key, uint8_t *rndA, uint8_t *rndB, bool enckey, uint8_t *sessionkey);
|
||||||
|
|
||||||
|
@ -139,14 +139,14 @@ uint8_t DesfireCommModeToFileCommMode(DesfireCommunicationMode comm_mode);
|
||||||
|
|
||||||
void DesfireGenSessionKeyEV1(const uint8_t rnda[], const uint8_t rndb[], DesfireCryptoAlgorythm keytype, uint8_t *key);
|
void DesfireGenSessionKeyEV1(const uint8_t rnda[], const uint8_t rndb[], DesfireCryptoAlgorythm keytype, uint8_t *key);
|
||||||
void DesfireGenSessionKeyEV2(uint8_t *key, uint8_t *rndA, uint8_t *rndB, bool enckey, uint8_t *sessionkey);
|
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);
|
void DesfireEV2FillIV(DesfireContext_t *ctx, bool ivforcommand, uint8_t *iv);
|
||||||
int DesfireEV2CalcCMAC(DesfireContext *ctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *mac);
|
int DesfireEV2CalcCMAC(DesfireContext_t *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 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 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);
|
void DesfireDecodePrevReaderID(DesfireContext_t *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);
|
int DesfireLRPCalcCMAC(DesfireContext_t *ctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *mac);
|
||||||
|
|
||||||
int desfire_get_key_length(DesfireCryptoAlgorythm key_type);
|
int desfire_get_key_length(DesfireCryptoAlgorythm key_type);
|
||||||
size_t desfire_get_key_block_length(DesfireCryptoAlgorythm key_type);
|
size_t desfire_get_key_block_length(DesfireCryptoAlgorythm key_type);
|
||||||
|
|
|
@ -47,7 +47,7 @@ static bool CommandCanUseAnyChannel(uint8_t cmd) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const AllowedChannelModesS AllowedChannelModes[] = {
|
static const AllowedChannelModes_t AllowedChannelModes[] = {
|
||||||
// D40 channel
|
// D40 channel
|
||||||
{MFDES_SELECT_APPLICATION, DACd40, DCCNative, DCMPlain},
|
{MFDES_SELECT_APPLICATION, DACd40, DCCNative, DCMPlain},
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ static const AllowedChannelModesS AllowedChannelModes[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
#define CMD_HEADER_LEN_ALL 0xffff
|
#define CMD_HEADER_LEN_ALL 0xffff
|
||||||
static const CmdHeaderLengthsS CmdHeaderLengths[] = {
|
static const CmdHeaderLengths_t CmdHeaderLengths[] = {
|
||||||
{MFDES_CREATE_APPLICATION, CMD_HEADER_LEN_ALL},
|
{MFDES_CREATE_APPLICATION, CMD_HEADER_LEN_ALL},
|
||||||
{MFDES_DELETE_APPLICATION, CMD_HEADER_LEN_ALL},
|
{MFDES_DELETE_APPLICATION, CMD_HEADER_LEN_ALL},
|
||||||
{MFDES_CHANGE_KEY, 1},
|
{MFDES_CHANGE_KEY, 1},
|
||||||
|
@ -217,7 +217,7 @@ static const uint8_t EV1D40TransmitMAC[] = {
|
||||||
MFDES_FINALIZE_KEY_SETTINGS,
|
MFDES_FINALIZE_KEY_SETTINGS,
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool DesfireEV1D40TransmitMAC(DesfireContext *ctx, uint8_t cmd) {
|
static bool DesfireEV1D40TransmitMAC(DesfireContext_t *ctx, uint8_t cmd) {
|
||||||
if (ctx->secureChannel != DACd40 && ctx->secureChannel != DACEV1)
|
if (ctx->secureChannel != DACd40 && ctx->secureChannel != DACEV1)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -236,7 +236,7 @@ static const uint8_t D40ReceiveMAC[] = {
|
||||||
MFDES_GET_VALUE,
|
MFDES_GET_VALUE,
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool DesfireEV1D40ReceiveMAC(DesfireContext *ctx, uint8_t cmd) {
|
static bool DesfireEV1D40ReceiveMAC(DesfireContext_t *ctx, uint8_t cmd) {
|
||||||
if (ctx->secureChannel != DACd40)
|
if (ctx->secureChannel != DACd40)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -266,7 +266,7 @@ static bool DesfireISOChannelValidCmd(uint8_t cmd) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DesfireSecureChannelEncodeD40(DesfireContext *ctx, uint8_t cmd, uint8_t *srcdata, size_t srcdatalen, uint8_t *dstdata, size_t *dstdatalen) {
|
static void DesfireSecureChannelEncodeD40(DesfireContext_t *ctx, uint8_t cmd, uint8_t *srcdata, size_t srcdatalen, uint8_t *dstdata, size_t *dstdatalen) {
|
||||||
uint8_t data[1024] = {0};
|
uint8_t data[1024] = {0};
|
||||||
size_t rlen = 0;
|
size_t rlen = 0;
|
||||||
|
|
||||||
|
@ -324,7 +324,7 @@ static void DesfireSecureChannelEncodeD40(DesfireContext *ctx, uint8_t cmd, uint
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DesfireSecureChannelEncodeEV1(DesfireContext *ctx, uint8_t cmd, uint8_t *srcdata, size_t srcdatalen, uint8_t *dstdata, size_t *dstdatalen) {
|
static void DesfireSecureChannelEncodeEV1(DesfireContext_t *ctx, uint8_t cmd, uint8_t *srcdata, size_t srcdatalen, uint8_t *dstdata, size_t *dstdatalen) {
|
||||||
uint8_t data[1024] = {0};
|
uint8_t data[1024] = {0};
|
||||||
size_t rlen = 0;
|
size_t rlen = 0;
|
||||||
|
|
||||||
|
@ -380,7 +380,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) {
|
static void DesfireSecureChannelEncodeEV2(DesfireContext_t *ctx, uint8_t cmd, uint8_t *srcdata, size_t srcdatalen, uint8_t *dstdata, size_t *dstdatalen) {
|
||||||
uint8_t data[1050] = {0};
|
uint8_t data[1050] = {0};
|
||||||
size_t rlen = 0;
|
size_t rlen = 0;
|
||||||
|
|
||||||
|
@ -419,7 +419,7 @@ static void DesfireSecureChannelEncodeEV2(DesfireContext *ctx, uint8_t cmd, uint
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DesfireSecureChannelEncodeLRP(DesfireContext *ctx, uint8_t cmd, uint8_t *srcdata, size_t srcdatalen, uint8_t *dstdata, size_t *dstdatalen) {
|
static void DesfireSecureChannelEncodeLRP(DesfireContext_t *ctx, uint8_t cmd, uint8_t *srcdata, size_t srcdatalen, uint8_t *dstdata, size_t *dstdatalen) {
|
||||||
uint8_t data[1050] = {0};
|
uint8_t data[1050] = {0};
|
||||||
size_t rlen = 0;
|
size_t rlen = 0;
|
||||||
|
|
||||||
|
@ -457,7 +457,7 @@ static void DesfireSecureChannelEncodeLRP(DesfireContext *ctx, uint8_t cmd, uint
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesfireSecureChannelEncode(DesfireContext *ctx, uint8_t cmd, uint8_t *srcdata, size_t srcdatalen, uint8_t *dstdata, size_t *dstdatalen) {
|
void DesfireSecureChannelEncode(DesfireContext_t *ctx, uint8_t cmd, uint8_t *srcdata, size_t srcdatalen, uint8_t *dstdata, size_t *dstdatalen) {
|
||||||
ctx->lastCommand = cmd;
|
ctx->lastCommand = cmd;
|
||||||
ctx->lastRequestZeroLen = (srcdatalen <= DesfireGetCmdHeaderLen(cmd));
|
ctx->lastRequestZeroLen = (srcdatalen <= DesfireGetCmdHeaderLen(cmd));
|
||||||
|
|
||||||
|
@ -481,7 +481,7 @@ void DesfireSecureChannelEncode(DesfireContext *ctx, uint8_t cmd, uint8_t *srcda
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DesfireSecureChannelDecodeD40(DesfireContext *ctx, uint8_t *srcdata, size_t srcdatalen, uint8_t respcode, uint8_t *dstdata, size_t *dstdatalen) {
|
static void DesfireSecureChannelDecodeD40(DesfireContext_t *ctx, uint8_t *srcdata, size_t srcdatalen, uint8_t respcode, uint8_t *dstdata, size_t *dstdatalen) {
|
||||||
uint8_t data[1024] = {0};
|
uint8_t data[1024] = {0};
|
||||||
size_t rlen = 0;
|
size_t rlen = 0;
|
||||||
|
|
||||||
|
@ -537,7 +537,7 @@ static void DesfireSecureChannelDecodeD40(DesfireContext *ctx, uint8_t *srcdata,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DesfireSecureChannelDecodeEV1(DesfireContext *ctx, uint8_t *srcdata, size_t srcdatalen, uint8_t respcode, uint8_t *dstdata, size_t *dstdatalen) {
|
static void DesfireSecureChannelDecodeEV1(DesfireContext_t *ctx, uint8_t *srcdata, size_t srcdatalen, uint8_t respcode, uint8_t *dstdata, size_t *dstdatalen) {
|
||||||
uint8_t data[1024] = {0};
|
uint8_t data[1024] = {0};
|
||||||
|
|
||||||
// if comm mode = plain --> response with MAC
|
// if comm mode = plain --> response with MAC
|
||||||
|
@ -589,7 +589,7 @@ static void DesfireSecureChannelDecodeEV1(DesfireContext *ctx, uint8_t *srcdata,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DesfireSecureChannelDecodeEV2(DesfireContext *ctx, uint8_t *srcdata, size_t srcdatalen, uint8_t respcode, uint8_t *dstdata, size_t *dstdatalen) {
|
static void DesfireSecureChannelDecodeEV2(DesfireContext_t *ctx, uint8_t *srcdata, size_t srcdatalen, uint8_t respcode, uint8_t *dstdata, size_t *dstdatalen) {
|
||||||
ctx->cmdCntr++;
|
ctx->cmdCntr++;
|
||||||
|
|
||||||
memcpy(dstdata, srcdata, srcdatalen);
|
memcpy(dstdata, srcdata, srcdatalen);
|
||||||
|
@ -647,7 +647,7 @@ static void DesfireSecureChannelDecodeEV2(DesfireContext *ctx, uint8_t *srcdata,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DesfireSecureChannelDecodeLRP(DesfireContext *ctx, uint8_t *srcdata, size_t srcdatalen, uint8_t respcode, uint8_t *dstdata, size_t *dstdatalen) {
|
static void DesfireSecureChannelDecodeLRP(DesfireContext_t *ctx, uint8_t *srcdata, size_t srcdatalen, uint8_t respcode, uint8_t *dstdata, size_t *dstdatalen) {
|
||||||
ctx->cmdCntr++;
|
ctx->cmdCntr++;
|
||||||
|
|
||||||
memcpy(dstdata, srcdata, srcdatalen);
|
memcpy(dstdata, srcdata, srcdatalen);
|
||||||
|
@ -704,7 +704,7 @@ static void DesfireSecureChannelDecodeLRP(DesfireContext *ctx, uint8_t *srcdata,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DesfireISODecode(DesfireContext *ctx, uint8_t *srcdata, size_t srcdatalen, uint8_t *dstdata, size_t *dstdatalen) {
|
static void DesfireISODecode(DesfireContext_t *ctx, uint8_t *srcdata, size_t srcdatalen, uint8_t *dstdata, size_t *dstdatalen) {
|
||||||
memcpy(dstdata, srcdata, srcdatalen);
|
memcpy(dstdata, srcdata, srcdatalen);
|
||||||
*dstdatalen = srcdatalen;
|
*dstdatalen = srcdatalen;
|
||||||
uint8_t data[1050] = {0};
|
uint8_t data[1050] = {0};
|
||||||
|
@ -731,7 +731,7 @@ static void DesfireISODecode(DesfireContext *ctx, uint8_t *srcdata, size_t srcda
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesfireSecureChannelDecode(DesfireContext *ctx, uint8_t *srcdata, size_t srcdatalen, uint8_t respcode, uint8_t *dstdata, size_t *dstdatalen) {
|
void DesfireSecureChannelDecode(DesfireContext_t *ctx, uint8_t *srcdata, size_t srcdatalen, uint8_t respcode, uint8_t *dstdata, size_t *dstdatalen) {
|
||||||
if (ctx->cmdSet == DCCISO) {
|
if (ctx->cmdSet == DCCISO) {
|
||||||
DesfireISODecode(ctx, srcdata, srcdatalen, dstdata, dstdatalen);
|
DesfireISODecode(ctx, srcdata, srcdatalen, dstdata, dstdatalen);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -23,15 +23,15 @@ typedef struct {
|
||||||
DesfireSecureChannel secureChannel;
|
DesfireSecureChannel secureChannel;
|
||||||
DesfireCommandSet cmdSet;
|
DesfireCommandSet cmdSet;
|
||||||
DesfireCommunicationMode commMode;
|
DesfireCommunicationMode commMode;
|
||||||
} AllowedChannelModesS;
|
} AllowedChannelModes_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t cmd;
|
uint8_t cmd;
|
||||||
uint32_t len;
|
uint32_t len;
|
||||||
} CmdHeaderLengthsS;
|
} CmdHeaderLengths_t;
|
||||||
|
|
||||||
void DesfireSecureChannelEncode(DesfireContext *ctx, uint8_t cmd, uint8_t *srcdata, size_t srcdatalen, uint8_t *dstdata, size_t *dstdatalen);
|
void DesfireSecureChannelEncode(DesfireContext_t *ctx, uint8_t cmd, uint8_t *srcdata, size_t srcdatalen, 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);
|
void DesfireSecureChannelDecode(DesfireContext_t *ctx, uint8_t *srcdata, size_t srcdatalen, uint8_t respcode, uint8_t *dstdata, size_t *dstdatalen);
|
||||||
|
|
||||||
bool PrintChannelModeWarning(uint8_t cmd, DesfireSecureChannel secureChannel, DesfireCommandSet cmdSet, DesfireCommunicationMode commMode);
|
bool PrintChannelModeWarning(uint8_t cmd, DesfireSecureChannel secureChannel, DesfireCommandSet cmdSet, DesfireCommunicationMode commMode);
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ static bool TestCMACSubkeys(void) {
|
||||||
|
|
||||||
uint8_t sk1[DESFIRE_MAX_CRYPTO_BLOCK_SIZE] = {0};
|
uint8_t sk1[DESFIRE_MAX_CRYPTO_BLOCK_SIZE] = {0};
|
||||||
uint8_t sk2[DESFIRE_MAX_CRYPTO_BLOCK_SIZE] = {0};
|
uint8_t sk2[DESFIRE_MAX_CRYPTO_BLOCK_SIZE] = {0};
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
// AES
|
// AES
|
||||||
DesfireSetKey(&dctx, 0, T_AES, key);
|
DesfireSetKey(&dctx, 0, T_AES, key);
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ static bool TestAn10922KDFAES(void) {
|
||||||
|
|
||||||
uint8_t key[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
|
uint8_t key[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
DesfireSetKey(&dctx, 0, T_AES, key);
|
DesfireSetKey(&dctx, 0, T_AES, key);
|
||||||
|
|
||||||
uint8_t kdfInput[] = {0x04, 0x78, 0x2E, 0x21, 0x80, 0x1D, 0x80, 0x30, 0x42, 0xF5, 0x4E, 0x58, 0x50, 0x20, 0x41, 0x62, 0x75};
|
uint8_t kdfInput[] = {0x04, 0x78, 0x2E, 0x21, 0x80, 0x1D, 0x80, 0x30, 0x42, 0xF5, 0x4E, 0x58, 0x50, 0x20, 0x41, 0x62, 0x75};
|
||||||
|
@ -162,7 +162,7 @@ static bool TestAn10922KDF2TDEA(void) {
|
||||||
|
|
||||||
uint8_t key[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
|
uint8_t key[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
DesfireSetKey(&dctx, 0, T_3DES, key);
|
DesfireSetKey(&dctx, 0, T_3DES, key);
|
||||||
|
|
||||||
uint8_t kdfInput[] = {0x04, 0x78, 0x2E, 0x21, 0x80, 0x1D, 0x80, 0x30, 0x42, 0xF5, 0x4E, 0x58, 0x50, 0x20, 0x41};
|
uint8_t kdfInput[] = {0x04, 0x78, 0x2E, 0x21, 0x80, 0x1D, 0x80, 0x30, 0x42, 0xF5, 0x4E, 0x58, 0x50, 0x20, 0x41};
|
||||||
|
@ -184,7 +184,7 @@ static bool TestAn10922KDF3TDEA(void) {
|
||||||
|
|
||||||
uint8_t key[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
|
uint8_t key[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
|
||||||
|
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
DesfireSetKey(&dctx, 0, T_3K3DES, key);
|
DesfireSetKey(&dctx, 0, T_3K3DES, key);
|
||||||
|
|
||||||
uint8_t kdfInput[] = {0x04, 0x78, 0x2E, 0x21, 0x80, 0x1D, 0x80, 0x30, 0x42, 0xF5, 0x4E, 0x58, 0x50};
|
uint8_t kdfInput[] = {0x04, 0x78, 0x2E, 0x21, 0x80, 0x1D, 0x80, 0x30, 0x42, 0xF5, 0x4E, 0x58, 0x50};
|
||||||
|
@ -211,7 +211,7 @@ static bool TestCMAC3TDEA(void) {
|
||||||
0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01,
|
0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01,
|
||||||
0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23
|
0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23
|
||||||
};
|
};
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
DesfireSetKey(&dctx, 0, T_3K3DES, key);
|
DesfireSetKey(&dctx, 0, T_3K3DES, key);
|
||||||
memcpy(dctx.sessionKeyMAC, key, DESFIRE_MAX_KEY_SIZE);
|
memcpy(dctx.sessionKeyMAC, key, DESFIRE_MAX_KEY_SIZE);
|
||||||
uint8_t cmac[DESFIRE_MAX_KEY_SIZE] = {0};
|
uint8_t cmac[DESFIRE_MAX_KEY_SIZE] = {0};
|
||||||
|
@ -254,7 +254,7 @@ static bool TestCMAC2TDEA(void) {
|
||||||
uint8_t key[DESFIRE_MAX_KEY_SIZE] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
|
uint8_t key[DESFIRE_MAX_KEY_SIZE] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
|
||||||
0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01
|
0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01
|
||||||
};
|
};
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
DesfireSetKey(&dctx, 0, T_3DES, key);
|
DesfireSetKey(&dctx, 0, T_3DES, key);
|
||||||
memcpy(dctx.sessionKeyMAC, key, DESFIRE_MAX_KEY_SIZE);
|
memcpy(dctx.sessionKeyMAC, key, DESFIRE_MAX_KEY_SIZE);
|
||||||
uint8_t cmac[DESFIRE_MAX_KEY_SIZE] = {0};
|
uint8_t cmac[DESFIRE_MAX_KEY_SIZE] = {0};
|
||||||
|
@ -295,7 +295,7 @@ static bool TestCMACDES(void) {
|
||||||
bool res = true;
|
bool res = true;
|
||||||
|
|
||||||
uint8_t key[DESFIRE_MAX_KEY_SIZE] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF};
|
uint8_t key[DESFIRE_MAX_KEY_SIZE] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF};
|
||||||
DesfireContext dctx;
|
DesfireContext_t dctx;
|
||||||
DesfireSetKey(&dctx, 0, T_DES, key);
|
DesfireSetKey(&dctx, 0, T_DES, key);
|
||||||
memcpy(dctx.sessionKeyMAC, key, DESFIRE_MAX_KEY_SIZE);
|
memcpy(dctx.sessionKeyMAC, key, DESFIRE_MAX_KEY_SIZE);
|
||||||
uint8_t cmac[DESFIRE_MAX_KEY_SIZE] = {0};
|
uint8_t cmac[DESFIRE_MAX_KEY_SIZE] = {0};
|
||||||
|
@ -365,7 +365,7 @@ static bool TestEV2IVEncode(void) {
|
||||||
uint8_t ti[] = {0xED, 0x56, 0xF6, 0xE6};
|
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};
|
uint8_t ivres[] = {0xDA, 0x0F, 0x64, 0x4A, 0x49, 0x86, 0x27, 0x59, 0x57, 0xCF, 0x1E, 0xC3, 0xAF, 0x4C, 0xCE, 0x53};
|
||||||
|
|
||||||
DesfireContext ctx = {0};
|
DesfireContext_t ctx = {0};
|
||||||
ctx.keyType = T_AES;
|
ctx.keyType = T_AES;
|
||||||
memcpy(ctx.sessionKeyEnc, key, 16);
|
memcpy(ctx.sessionKeyEnc, key, 16);
|
||||||
memcpy(ctx.TI, ti, 4);
|
memcpy(ctx.TI, ti, 4);
|
||||||
|
@ -408,7 +408,7 @@ static bool TestEV2MAC(void) {
|
||||||
uint8_t macres[] = {0x68, 0xF2, 0xC2, 0x8C, 0x57, 0x5A, 0x16, 0x28};
|
uint8_t macres[] = {0x68, 0xF2, 0xC2, 0x8C, 0x57, 0x5A, 0x16, 0x28};
|
||||||
|
|
||||||
// init
|
// init
|
||||||
DesfireContext ctx = {0};
|
DesfireContext_t ctx = {0};
|
||||||
ctx.keyType = T_AES;
|
ctx.keyType = T_AES;
|
||||||
memcpy(ctx.sessionKeyMAC, key, 16);
|
memcpy(ctx.sessionKeyMAC, key, 16);
|
||||||
memcpy(ctx.TI, ti, 4);
|
memcpy(ctx.TI, ti, 4);
|
||||||
|
@ -484,7 +484,7 @@ static bool TestLRPPlaintexts(void) {
|
||||||
bool res = true;
|
bool res = true;
|
||||||
|
|
||||||
uint8_t key[] = {0x56, 0x78, 0x26, 0xB8, 0xDA, 0x8E, 0x76, 0x84, 0x32, 0xA9, 0x54, 0x8D, 0xBE, 0x4A, 0xA3, 0xA0};
|
uint8_t key[] = {0x56, 0x78, 0x26, 0xB8, 0xDA, 0x8E, 0x76, 0x84, 0x32, 0xA9, 0x54, 0x8D, 0xBE, 0x4A, 0xA3, 0xA0};
|
||||||
LRPContext ctx = {0};
|
LRPContext_t ctx = {0};
|
||||||
LRPSetKey(&ctx, key, 0, false);
|
LRPSetKey(&ctx, key, 0, false);
|
||||||
|
|
||||||
uint8_t pt0[] = {0xAC, 0x20, 0xD3, 0x9F, 0x53, 0x41, 0xFE, 0x98, 0xDF, 0xCA, 0x21, 0xDA, 0x86, 0xBA, 0x79, 0x14};
|
uint8_t pt0[] = {0xAC, 0x20, 0xD3, 0x9F, 0x53, 0x41, 0xFE, 0x98, 0xDF, 0xCA, 0x21, 0xDA, 0x86, 0xBA, 0x79, 0x14};
|
||||||
|
@ -513,7 +513,7 @@ static bool TestLRPUpdatedKeys(void) {
|
||||||
bool res = true;
|
bool res = true;
|
||||||
|
|
||||||
uint8_t key[] = {0x56, 0x78, 0x26, 0xB8, 0xDA, 0x8E, 0x76, 0x84, 0x32, 0xA9, 0x54, 0x8D, 0xBE, 0x4A, 0xA3, 0xA0};
|
uint8_t key[] = {0x56, 0x78, 0x26, 0xB8, 0xDA, 0x8E, 0x76, 0x84, 0x32, 0xA9, 0x54, 0x8D, 0xBE, 0x4A, 0xA3, 0xA0};
|
||||||
LRPContext ctx = {0};
|
LRPContext_t ctx = {0};
|
||||||
LRPSetKey(&ctx, key, 0, false);
|
LRPSetKey(&ctx, key, 0, false);
|
||||||
|
|
||||||
uint8_t key0[] = {0x16, 0x3D, 0x14, 0xED, 0x24, 0xED, 0x93, 0x53, 0x73, 0x56, 0x8E, 0xC5, 0x21, 0xE9, 0x6C, 0xF4};
|
uint8_t key0[] = {0x16, 0x3D, 0x14, 0xED, 0x24, 0xED, 0x93, 0x53, 0x73, 0x56, 0x8E, 0xC5, 0x21, 0xE9, 0x6C, 0xF4};
|
||||||
|
@ -538,7 +538,7 @@ static bool TestLRPUpdatedKeys(void) {
|
||||||
static bool TestLRPEval(void) {
|
static bool TestLRPEval(void) {
|
||||||
bool res = true;
|
bool res = true;
|
||||||
|
|
||||||
LRPContext ctx = {0};
|
LRPContext_t ctx = {0};
|
||||||
|
|
||||||
uint8_t y[CRYPTO_AES128_KEY_SIZE] = {0};
|
uint8_t y[CRYPTO_AES128_KEY_SIZE] = {0};
|
||||||
uint8_t key[] = {0x56, 0x78, 0x26, 0xB8, 0xDA, 0x8E, 0x76, 0x84, 0x32, 0xA9, 0x54, 0x8D, 0xBE, 0x4A, 0xA3, 0xA0};
|
uint8_t key[] = {0x56, 0x78, 0x26, 0xB8, 0xDA, 0x8E, 0x76, 0x84, 0x32, 0xA9, 0x54, 0x8D, 0xBE, 0x4A, 0xA3, 0xA0};
|
||||||
|
@ -626,7 +626,7 @@ static bool TestLRPEncode(void) {
|
||||||
uint8_t resp[100] = {0};
|
uint8_t resp[100] = {0};
|
||||||
size_t resplen = 0;
|
size_t resplen = 0;
|
||||||
|
|
||||||
LRPContext ctx = {0};
|
LRPContext_t ctx = {0};
|
||||||
|
|
||||||
uint8_t key1[] = {0xE0, 0xC4, 0x93, 0x5F, 0xF0, 0xC2, 0x54, 0xCD, 0x2C, 0xEF, 0x8F, 0xDD, 0xC3, 0x24, 0x60, 0xCF};
|
uint8_t key1[] = {0xE0, 0xC4, 0x93, 0x5F, 0xF0, 0xC2, 0x54, 0xCD, 0x2C, 0xEF, 0x8F, 0xDD, 0xC3, 0x24, 0x60, 0xCF};
|
||||||
uint8_t iv1[] = {0xC3, 0x31, 0x5D, 0xBF};
|
uint8_t iv1[] = {0xC3, 0x31, 0x5D, 0xBF};
|
||||||
|
@ -694,7 +694,7 @@ static bool TestLRPDecode(void) {
|
||||||
uint8_t resp[100] = {0};
|
uint8_t resp[100] = {0};
|
||||||
size_t resplen = 0;
|
size_t resplen = 0;
|
||||||
|
|
||||||
LRPContext ctx = {0};
|
LRPContext_t ctx = {0};
|
||||||
|
|
||||||
uint8_t key1[] = {0xE0, 0xC4, 0x93, 0x5F, 0xF0, 0xC2, 0x54, 0xCD, 0x2C, 0xEF, 0x8F, 0xDD, 0xC3, 0x24, 0x60, 0xCF};
|
uint8_t key1[] = {0xE0, 0xC4, 0x93, 0x5F, 0xF0, 0xC2, 0x54, 0xCD, 0x2C, 0xEF, 0x8F, 0xDD, 0xC3, 0x24, 0x60, 0xCF};
|
||||||
uint8_t iv1[] = {0xC3, 0x31, 0x5D, 0xBF};
|
uint8_t iv1[] = {0xC3, 0x31, 0x5D, 0xBF};
|
||||||
|
@ -800,7 +800,7 @@ static bool TestLRPSubkeys(void) {
|
||||||
static bool TestLRPCMAC(void) {
|
static bool TestLRPCMAC(void) {
|
||||||
bool res = true;
|
bool res = true;
|
||||||
|
|
||||||
LRPContext ctx = {0};
|
LRPContext_t ctx = {0};
|
||||||
uint8_t cmac[CRYPTO_AES128_KEY_SIZE] = {0};
|
uint8_t cmac[CRYPTO_AES128_KEY_SIZE] = {0};
|
||||||
|
|
||||||
uint8_t key1[] = {0x81, 0x95, 0x08, 0x8C, 0xE6, 0xC3, 0x93, 0x70, 0x8E, 0xBB, 0xE6, 0xC7, 0x91, 0x4E, 0xCB, 0x0B};
|
uint8_t key1[] = {0x81, 0x95, 0x08, 0x8C, 0xE6, 0xC3, 0x93, 0x70, 0x8E, 0xBB, 0xE6, 0xC7, 0x91, 0x4E, 0xCB, 0x0B};
|
||||||
|
|
|
@ -33,7 +33,7 @@ static uint8_t constAA[] = {0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa
|
||||||
static uint8_t const55[] = {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
|
static uint8_t const55[] = {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
|
||||||
static uint8_t const00[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
static uint8_t const00[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||||
|
|
||||||
void LRPClearContext(LRPContext *ctx) {
|
void LRPClearContext(LRPContext_t *ctx) {
|
||||||
memset(ctx->key, 0, CRYPTO_AES128_KEY_SIZE);
|
memset(ctx->key, 0, CRYPTO_AES128_KEY_SIZE);
|
||||||
|
|
||||||
ctx->useBitPadding = false;
|
ctx->useBitPadding = false;
|
||||||
|
@ -44,7 +44,7 @@ void LRPClearContext(LRPContext *ctx) {
|
||||||
ctx->useUpdatedKeyNum = 0;
|
ctx->useUpdatedKeyNum = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LRPSetKey(LRPContext *ctx, uint8_t *key, size_t updatedKeyNum, bool useBitPadding) {
|
void LRPSetKey(LRPContext_t *ctx, uint8_t *key, size_t updatedKeyNum, bool useBitPadding) {
|
||||||
LRPClearContext(ctx);
|
LRPClearContext(ctx);
|
||||||
|
|
||||||
memcpy(ctx->key, key, CRYPTO_AES128_KEY_SIZE);
|
memcpy(ctx->key, key, CRYPTO_AES128_KEY_SIZE);
|
||||||
|
@ -59,12 +59,12 @@ void LRPSetKey(LRPContext *ctx, uint8_t *key, size_t updatedKeyNum, bool useBitP
|
||||||
ctx->counterLenNibbles = CRYPTO_AES128_KEY_SIZE;
|
ctx->counterLenNibbles = CRYPTO_AES128_KEY_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LRPSetCounter(LRPContext *ctx, uint8_t *counter, size_t counterLenNibbles) {
|
void LRPSetCounter(LRPContext_t *ctx, uint8_t *counter, size_t counterLenNibbles) {
|
||||||
memcpy(ctx->counter, counter, counterLenNibbles / 2);
|
memcpy(ctx->counter, counter, counterLenNibbles / 2);
|
||||||
ctx->counterLenNibbles = counterLenNibbles;
|
ctx->counterLenNibbles = counterLenNibbles;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LRPSetKeyEx(LRPContext *ctx, uint8_t *key, uint8_t *counter, size_t counterLenNibbles, size_t updatedKeyNum, bool useBitPadding) {
|
void LRPSetKeyEx(LRPContext_t *ctx, uint8_t *key, uint8_t *counter, size_t counterLenNibbles, size_t updatedKeyNum, bool useBitPadding) {
|
||||||
LRPSetKey(ctx, key, updatedKeyNum, useBitPadding);
|
LRPSetKey(ctx, key, updatedKeyNum, useBitPadding);
|
||||||
LRPSetCounter(ctx, counter, counterLenNibbles);
|
LRPSetCounter(ctx, counter, counterLenNibbles);
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ void LRPSetKeyEx(LRPContext *ctx, uint8_t *key, uint8_t *counter, size_t counter
|
||||||
|
|
||||||
// https://www.nxp.com/docs/en/application-note/AN12304.pdf
|
// https://www.nxp.com/docs/en/application-note/AN12304.pdf
|
||||||
// Algorithm 1
|
// Algorithm 1
|
||||||
void LRPGeneratePlaintexts(LRPContext *ctx, size_t plaintextsCount) {
|
void LRPGeneratePlaintexts(LRPContext_t *ctx, size_t plaintextsCount) {
|
||||||
if (plaintextsCount > LRP_MAX_PLAINTEXTS_SIZE)
|
if (plaintextsCount > LRP_MAX_PLAINTEXTS_SIZE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ void LRPGeneratePlaintexts(LRPContext *ctx, size_t plaintextsCount) {
|
||||||
|
|
||||||
// https://www.nxp.com/docs/en/application-note/AN12304.pdf
|
// https://www.nxp.com/docs/en/application-note/AN12304.pdf
|
||||||
// Algorithm 2
|
// Algorithm 2
|
||||||
void LRPGenerateUpdatedKeys(LRPContext *ctx, size_t updatedKeysCount) {
|
void LRPGenerateUpdatedKeys(LRPContext_t *ctx, size_t updatedKeysCount) {
|
||||||
if (updatedKeysCount > LRP_MAX_UPDATED_KEYS_SIZE)
|
if (updatedKeysCount > LRP_MAX_UPDATED_KEYS_SIZE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ void LRPGenerateUpdatedKeys(LRPContext *ctx, size_t updatedKeysCount) {
|
||||||
|
|
||||||
// https://www.nxp.com/docs/en/application-note/AN12304.pdf
|
// https://www.nxp.com/docs/en/application-note/AN12304.pdf
|
||||||
// Algorithm 3
|
// Algorithm 3
|
||||||
void LRPEvalLRP(LRPContext *ctx, uint8_t *iv, size_t ivlen, bool final, uint8_t *y) {
|
void LRPEvalLRP(LRPContext_t *ctx, uint8_t *iv, size_t ivlen, bool final, uint8_t *y) {
|
||||||
uint8_t ry[CRYPTO_AES128_KEY_SIZE] = {0};
|
uint8_t ry[CRYPTO_AES128_KEY_SIZE] = {0};
|
||||||
memcpy(ry, ctx->updatedKeys[ctx->useUpdatedKeyNum], CRYPTO_AES128_KEY_SIZE);
|
memcpy(ry, ctx->updatedKeys[ctx->useUpdatedKeyNum], CRYPTO_AES128_KEY_SIZE);
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ void LRPIncCounter(uint8_t *ctr, size_t ctrlen) {
|
||||||
|
|
||||||
// https://www.nxp.com/docs/en/application-note/AN12304.pdf
|
// https://www.nxp.com/docs/en/application-note/AN12304.pdf
|
||||||
// Algorithm 4
|
// Algorithm 4
|
||||||
void LRPEncode(LRPContext *ctx, uint8_t *data, size_t datalen, uint8_t *resp, size_t *resplen) {
|
void LRPEncode(LRPContext_t *ctx, uint8_t *data, size_t datalen, uint8_t *resp, size_t *resplen) {
|
||||||
*resplen = 0;
|
*resplen = 0;
|
||||||
|
|
||||||
uint8_t xdata[1024] = {0};
|
uint8_t xdata[1024] = {0};
|
||||||
|
@ -168,7 +168,7 @@ void LRPEncode(LRPContext *ctx, uint8_t *data, size_t datalen, uint8_t *resp, si
|
||||||
|
|
||||||
// https://www.nxp.com/docs/en/application-note/AN12304.pdf
|
// https://www.nxp.com/docs/en/application-note/AN12304.pdf
|
||||||
// Algorithm 5
|
// Algorithm 5
|
||||||
void LRPDecode(LRPContext *ctx, uint8_t *data, size_t datalen, uint8_t *resp, size_t *resplen) {
|
void LRPDecode(LRPContext_t *ctx, uint8_t *data, size_t datalen, uint8_t *resp, size_t *resplen) {
|
||||||
*resplen = 0;
|
*resplen = 0;
|
||||||
if (datalen % CRYPTO_AES128_KEY_SIZE)
|
if (datalen % CRYPTO_AES128_KEY_SIZE)
|
||||||
return;
|
return;
|
||||||
|
@ -193,7 +193,7 @@ void LRPDecode(LRPContext *ctx, uint8_t *data, size_t datalen, uint8_t *resp, si
|
||||||
}
|
}
|
||||||
|
|
||||||
void LRPEncDec(uint8_t *key, uint8_t *iv, bool encode, uint8_t *data, size_t datalen, uint8_t *resp, size_t *resplen) {
|
void LRPEncDec(uint8_t *key, uint8_t *iv, bool encode, uint8_t *data, size_t datalen, uint8_t *resp, size_t *resplen) {
|
||||||
LRPContext ctx = {0};
|
LRPContext_t ctx = {0};
|
||||||
|
|
||||||
LRPSetKeyEx(&ctx, key, iv, 4 * 2, 1, true);
|
LRPSetKeyEx(&ctx, key, iv, 4 * 2, 1, true);
|
||||||
if (encode)
|
if (encode)
|
||||||
|
@ -225,7 +225,7 @@ static void mulPolyX(uint8_t *data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void LRPGenSubkeys(uint8_t *key, uint8_t *sk1, uint8_t *sk2) {
|
void LRPGenSubkeys(uint8_t *key, uint8_t *sk1, uint8_t *sk2) {
|
||||||
LRPContext ctx = {0};
|
LRPContext_t ctx = {0};
|
||||||
LRPSetKey(&ctx, key, 0, true);
|
LRPSetKey(&ctx, key, 0, true);
|
||||||
|
|
||||||
uint8_t y[CRYPTO_AES128_KEY_SIZE] = {0};
|
uint8_t y[CRYPTO_AES128_KEY_SIZE] = {0};
|
||||||
|
@ -240,7 +240,7 @@ void LRPGenSubkeys(uint8_t *key, uint8_t *sk1, uint8_t *sk2) {
|
||||||
|
|
||||||
// https://www.nxp.com/docs/en/application-note/AN12304.pdf
|
// https://www.nxp.com/docs/en/application-note/AN12304.pdf
|
||||||
// Algorithm 6
|
// Algorithm 6
|
||||||
void LRPCMAC(LRPContext *ctx, uint8_t *data, size_t datalen, uint8_t *cmac) {
|
void LRPCMAC(LRPContext_t *ctx, uint8_t *data, size_t datalen, uint8_t *cmac) {
|
||||||
uint8_t sk1[CRYPTO_AES128_KEY_SIZE] = {0};
|
uint8_t sk1[CRYPTO_AES128_KEY_SIZE] = {0};
|
||||||
uint8_t sk2[CRYPTO_AES128_KEY_SIZE] = {0};
|
uint8_t sk2[CRYPTO_AES128_KEY_SIZE] = {0};
|
||||||
LRPGenSubkeys(ctx->key, sk1, sk2);
|
LRPGenSubkeys(ctx->key, sk1, sk2);
|
||||||
|
@ -277,7 +277,7 @@ void LRPCMAC(LRPContext *ctx, uint8_t *data, size_t datalen, uint8_t *cmac) {
|
||||||
LRPEvalLRP(ctx, y, CRYPTO_AES128_KEY_SIZE * 2, true, cmac);
|
LRPEvalLRP(ctx, y, CRYPTO_AES128_KEY_SIZE * 2, true, cmac);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LRPCMAC8(LRPContext *ctx, uint8_t *data, size_t datalen, uint8_t *cmac) {
|
void LRPCMAC8(LRPContext_t *ctx, uint8_t *data, size_t datalen, uint8_t *cmac) {
|
||||||
uint8_t cmac_tmp[16] = {0};
|
uint8_t cmac_tmp[16] = {0};
|
||||||
memset(cmac, 0x00, 8);
|
memset(cmac, 0x00, 8);
|
||||||
|
|
||||||
|
|
|
@ -42,21 +42,21 @@ typedef struct {
|
||||||
|
|
||||||
uint8_t counter[LRP_MAX_COUNTER_SIZE];
|
uint8_t counter[LRP_MAX_COUNTER_SIZE];
|
||||||
size_t counterLenNibbles; // len in bytes * 2 (or * 2 - 1)
|
size_t counterLenNibbles; // len in bytes * 2 (or * 2 - 1)
|
||||||
} LRPContext;
|
} LRPContext_t;
|
||||||
|
|
||||||
void LRPClearContext(LRPContext *ctx);
|
void LRPClearContext(LRPContext_t *ctx);
|
||||||
void LRPSetKey(LRPContext *ctx, uint8_t *key, size_t updatedKeyNum, bool useBitPadding);
|
void LRPSetKey(LRPContext_t *ctx, uint8_t *key, size_t updatedKeyNum, bool useBitPadding);
|
||||||
void LRPSetKeyEx(LRPContext *ctx, uint8_t *key, uint8_t *counter, size_t counterLenNibbles, size_t updatedKeyNum, bool useBitPadding);
|
void LRPSetKeyEx(LRPContext_t *ctx, uint8_t *key, uint8_t *counter, size_t counterLenNibbles, size_t updatedKeyNum, bool useBitPadding);
|
||||||
void LRPSetCounter(LRPContext *ctx, uint8_t *counter, size_t counterLenNibbles);
|
void LRPSetCounter(LRPContext_t *ctx, uint8_t *counter, size_t counterLenNibbles);
|
||||||
void LRPGeneratePlaintexts(LRPContext *ctx, size_t plaintextsCount);
|
void LRPGeneratePlaintexts(LRPContext_t *ctx, size_t plaintextsCount);
|
||||||
void LRPGenerateUpdatedKeys(LRPContext *ctx, size_t updatedKeysCount);
|
void LRPGenerateUpdatedKeys(LRPContext_t *ctx, size_t updatedKeysCount);
|
||||||
void LRPEvalLRP(LRPContext *ctx, uint8_t *iv, size_t ivlen, bool final, uint8_t *y);
|
void LRPEvalLRP(LRPContext_t *ctx, uint8_t *iv, size_t ivlen, bool final, uint8_t *y);
|
||||||
void LRPIncCounter(uint8_t *ctr, size_t ctrlen);
|
void LRPIncCounter(uint8_t *ctr, size_t ctrlen);
|
||||||
void LRPEncode(LRPContext *ctx, uint8_t *data, size_t datalen, uint8_t *resp, size_t *resplen);
|
void LRPEncode(LRPContext_t *ctx, uint8_t *data, size_t datalen, uint8_t *resp, size_t *resplen);
|
||||||
void LRPDecode(LRPContext *ctx, uint8_t *data, size_t datalen, uint8_t *resp, size_t *resplen);
|
void LRPDecode(LRPContext_t *ctx, uint8_t *data, size_t datalen, uint8_t *resp, size_t *resplen);
|
||||||
void LRPEncDec(uint8_t *key, uint8_t *iv, bool encode, uint8_t *data, size_t datalen, uint8_t *resp, size_t *resplen);
|
void LRPEncDec(uint8_t *key, uint8_t *iv, bool encode, uint8_t *data, size_t datalen, uint8_t *resp, size_t *resplen);
|
||||||
void LRPGenSubkeys(uint8_t *key, uint8_t *sk1, uint8_t *sk2);
|
void LRPGenSubkeys(uint8_t *key, uint8_t *sk1, uint8_t *sk2);
|
||||||
void LRPCMAC(LRPContext *ctx, uint8_t *data, size_t datalen, uint8_t *cmac);
|
void LRPCMAC(LRPContext_t *ctx, uint8_t *data, size_t datalen, uint8_t *cmac);
|
||||||
void LRPCMAC8(LRPContext *ctx, uint8_t *data, size_t datalen, uint8_t *cmac);
|
void LRPCMAC8(LRPContext_t *ctx, uint8_t *data, size_t datalen, uint8_t *cmac);
|
||||||
|
|
||||||
#endif // __LRPCRYPTO_H
|
#endif // __LRPCRYPTO_H
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#include "prng.h"
|
#include "prng.h"
|
||||||
|
|
||||||
#define rot(x,k) (((x)<<(k))|((x)>>(32-(k))))
|
#define rot(x,k) (((x)<<(k))|((x)>>(32-(k))))
|
||||||
uint32_t burtle_get_mod(prng_ctx *x) {
|
uint32_t burtle_get_mod(prng_ctx_t *x) {
|
||||||
uint32_t e = x->a - rot(x->b, 21);
|
uint32_t e = x->a - rot(x->b, 21);
|
||||||
x->a = x->b ^ rot(x->c, 19);
|
x->a = x->b ^ rot(x->c, 19);
|
||||||
x->b = x->c + rot(x->d, 6);
|
x->b = x->c + rot(x->d, 6);
|
||||||
|
@ -15,7 +15,7 @@ uint32_t burtle_get_mod(prng_ctx *x) {
|
||||||
return x->d;
|
return x->d;
|
||||||
}
|
}
|
||||||
|
|
||||||
void burtle_init_mod(prng_ctx *x, uint32_t seed) {
|
void burtle_init_mod(prng_ctx_t *x, uint32_t seed) {
|
||||||
x->a = 0xf1ea5eed;
|
x->a = 0xf1ea5eed;
|
||||||
x->b = x->c = x->d = seed;
|
x->b = x->c = x->d = seed;
|
||||||
for (uint8_t i = 0; i < 42; ++i) {
|
for (uint8_t i = 0; i < 42; ++i) {
|
||||||
|
@ -23,7 +23,7 @@ void burtle_init_mod(prng_ctx *x, uint32_t seed) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void burtle_init(prng_ctx *x, uint32_t seed) {
|
void burtle_init(prng_ctx_t *x, uint32_t seed) {
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
x->a = 0xf1ea5eed, x->b = x->c = x->d = seed;
|
x->a = 0xf1ea5eed, x->b = x->c = x->d = seed;
|
||||||
for (i = 0; i < 20; ++i) {
|
for (i = 0; i < 20; ++i) {
|
||||||
|
|
|
@ -9,17 +9,17 @@
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
typedef struct prng_ctx {
|
typedef struct {
|
||||||
uint32_t a;
|
uint32_t a;
|
||||||
uint32_t b;
|
uint32_t b;
|
||||||
uint32_t c;
|
uint32_t c;
|
||||||
uint32_t d;
|
uint32_t d;
|
||||||
} prng_ctx;
|
} prng_ctx_t;
|
||||||
|
|
||||||
//uint32_t burtle_get( prng_ctx *x );
|
//uint32_t burtle_get( prng_ctx_t *x );
|
||||||
uint32_t burtle_get_mod(prng_ctx *x);
|
uint32_t burtle_get_mod(prng_ctx_t *x);
|
||||||
void burtle_init_mod(prng_ctx *x, uint32_t seed);
|
void burtle_init_mod(prng_ctx_t *x, uint32_t seed);
|
||||||
void burtle_init(prng_ctx *x, uint32_t seed);
|
void burtle_init(prng_ctx_t *x, uint32_t seed);
|
||||||
|
|
||||||
uint32_t GetSimplePrng(uint32_t seed);
|
uint32_t GetSimplePrng(uint32_t seed);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue