mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2026-05-12 11:18:11 -07:00
rename typedef structs
This commit is contained in:
@@ -1710,13 +1710,13 @@ int CmdHpf(const char *Cmd) {
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
static bool _headBit(BitstreamOut *stream) {
|
||||
static bool _headBit(BitstreamOut_t *stream) {
|
||||
int bytepos = stream->position >> 3; // divide by 8
|
||||
int bitpos = (stream->position++) & 7; // mask out 00000111
|
||||
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;
|
||||
for (int i = 0 ; i < bits_per_sample; 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...");
|
||||
|
||||
BitstreamOut bout = { got, bits_per_sample * n, 0};
|
||||
BitstreamOut_t bout = { got, bits_per_sample * n, 0};
|
||||
uint32_t j = 0;
|
||||
for (j = 0; j * bits_per_sample < n * 8 && j < n; j++) {
|
||||
uint8_t sample = getByte(bits_per_sample, &bout);
|
||||
@@ -2425,7 +2425,7 @@ static int Cmdbin2hex(const char *Cmd) {
|
||||
size_t bytelen = (blen + 7) / 8;
|
||||
uint8_t *arr = (uint8_t *) calloc(bytelen, sizeof(uint8_t));
|
||||
memset(arr, 0, bytelen);
|
||||
BitstreamOut bout = { arr, 0, 0 };
|
||||
BitstreamOut_t bout = { arr, 0, 0 };
|
||||
|
||||
for (int i = 0; i < blen; i++) {
|
||||
uint8_t c = binarr[i];
|
||||
|
||||
@@ -3698,7 +3698,7 @@ static int CmdHFiClassEncode(const char *Cmd) {
|
||||
|
||||
uint8_t data[8];
|
||||
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++) {
|
||||
pushBit(&bout, 0);
|
||||
|
||||
+53
-53
@@ -380,7 +380,7 @@ static DesfireCommandSet defaultCommSet = DCCNativeISO;
|
||||
static DesfireCommunicationMode defaultCommMode = DCMPlain;
|
||||
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 kdfid, uint8_t kdfiid,
|
||||
uint8_t cmodeid, uint8_t ccsetid, uint8_t schannid,
|
||||
@@ -510,7 +510,7 @@ static int CmdHF14ADesDefault(const char *Cmd) {
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
int res = CmdDesGetSessionParameters(ctx, &dctx, 1, 2, 3, 4, 5, 6, 7, 8, 0, 0, &securechann, DCMNone, NULL, NULL);
|
||||
if (res) {
|
||||
@@ -621,7 +621,7 @@ static int CmdHF14ADesInfo(const char *Cmd) {
|
||||
if (major == 0 && minor == 2)
|
||||
PrintAndLogEx(INFO, "\t0.2 - DESFire Light, Originality check, ");
|
||||
|
||||
DesfireContext dctx = {0};
|
||||
DesfireContext_t dctx = {0};
|
||||
dctx.commMode = DCMPlain;
|
||||
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};
|
||||
size_t aidbuflen = 0;
|
||||
@@ -771,7 +771,7 @@ static void DesFill2bPattern(
|
||||
(*startPattern)++;
|
||||
}
|
||||
|
||||
static int AuthCheckDesfire(DesfireContext *dctx,
|
||||
static int AuthCheckDesfire(DesfireContext_t *dctx,
|
||||
DesfireSecureChannel secureChannel,
|
||||
uint8_t *aid,
|
||||
uint8_t deskeyList[MAX_KEYS_LIST_LEN][8], uint32_t deskeyListLen,
|
||||
@@ -825,7 +825,7 @@ static int AuthCheckDesfire(DesfireContext *dctx,
|
||||
usedkeys[0] = 1;
|
||||
|
||||
if (curaid != 0) {
|
||||
FileListS fileList = {0};
|
||||
FileList_t fileList = {0};
|
||||
size_t filescount = 0;
|
||||
bool isopresent = 0;
|
||||
res = DesfireFillFileList(dctx, fileList, &filescount, &isopresent);
|
||||
@@ -1180,7 +1180,7 @@ static int CmdHF14aDesChk(const char *Cmd) {
|
||||
|
||||
clearCommandBuffer();
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
DesfireSetKdf(&dctx, cmdKDFAlgo, kdfInput, kdfInputLen);
|
||||
DesfireSetCommandSet(&dctx, DCCNativeISO);
|
||||
DesfireSetCommMode(&dctx, DCMPlain);
|
||||
@@ -1294,7 +1294,7 @@ static int CmdHF14ADesList(const char *Cmd) {
|
||||
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);
|
||||
|
||||
int res = DesfireAuthenticate(dctx, secureChannel, false);
|
||||
@@ -1344,7 +1344,7 @@ static int CmdHF14aDesDetect(const char *Cmd) {
|
||||
bool APDULogging = arg_get_lit(ctx, 1);
|
||||
bool verbose = arg_get_lit(ctx, 2);
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
uint32_t appid = 0x000000;
|
||||
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 {
|
||||
// if fail - check auth commands
|
||||
AuthCommandsChk authCmdCheck = {0};
|
||||
AuthCommandsChk_t authCmdCheck = {0};
|
||||
DesfireCheckAuthCommands(appid, NULL, 0, &authCmdCheck);
|
||||
if (authCmdCheck.checked) {
|
||||
if (authCmdCheck.auth) {
|
||||
@@ -1600,7 +1600,7 @@ static int CmdHF14aDesMAD(const char *Cmd) {
|
||||
bool APDULogging = arg_get_lit(ctx, 1);
|
||||
bool verbose = arg_get_lit(ctx, 2);
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
uint32_t appid = 0x000000;
|
||||
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;
|
||||
}
|
||||
|
||||
PICCInfoS PICCInfo = {0};
|
||||
PICCInfo_t PICCInfo = {0};
|
||||
AppListS AppList = {0};
|
||||
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 verbose = arg_get_lit(ctx, 2);
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
uint32_t appid = 0x000000;
|
||||
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);
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
int res = CmdDesGetSessionParameters(ctx, &dctx, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &securechann, DCMNone, NULL, NULL);
|
||||
if (res) {
|
||||
@@ -1969,7 +1969,7 @@ static int CmdHF14ADesAuth(const char *Cmd) {
|
||||
bool APDULogging = arg_get_lit(ctx, 1);
|
||||
bool verbose = arg_get_lit(ctx, 2);
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
uint32_t id = 0x000000;
|
||||
DesfireISOSelectWay selectway = ISW6bAID;
|
||||
@@ -2062,7 +2062,7 @@ static int CmdHF14ADesSetConfiguration(const char *Cmd) {
|
||||
bool APDULogging = arg_get_lit(ctx, 1);
|
||||
bool verbose = arg_get_lit(ctx, 2);
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
uint32_t id = 0x000000;
|
||||
DesfireISOSelectWay selectway = ISW6bAID;
|
||||
@@ -2160,7 +2160,7 @@ static int CmdHF14ADesChangeKey(const char *Cmd) {
|
||||
bool APDULogging = arg_get_lit(ctx, 1);
|
||||
bool verbose = arg_get_lit(ctx, 2);
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
uint32_t id = 0x000000;
|
||||
DesfireISOSelectWay selectway = ISW6bAID;
|
||||
@@ -2322,7 +2322,7 @@ static int CmdHF14ADesCreateApp(const char *Cmd) {
|
||||
bool APDULogging = arg_get_lit(ctx, 1);
|
||||
bool verbose = arg_get_lit(ctx, 2);
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
uint32_t appid = 0x000000;
|
||||
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 verbose = arg_get_lit(ctx, 2);
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
uint32_t appid = 0x000000;
|
||||
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 verbose = arg_get_lit(ctx, 2);
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
uint32_t id = 0x000000;
|
||||
DesfireISOSelectWay selectway = ISW6bAID;
|
||||
@@ -2622,7 +2622,7 @@ static int CmdHF14ADesFormatPICC(const char *Cmd) {
|
||||
bool APDULogging = arg_get_lit(ctx, 1);
|
||||
bool verbose = arg_get_lit(ctx, 2);
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
uint32_t appid = 0x000000;
|
||||
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);
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 0, 0, &securechann, (noauth) ? DCMPlain : DCMMACed, NULL, NULL);
|
||||
if (res) {
|
||||
@@ -2741,7 +2741,7 @@ static int CmdHF14ADesChKeySettings(const char *Cmd) {
|
||||
bool APDULogging = arg_get_lit(ctx, 1);
|
||||
bool verbose = arg_get_lit(ctx, 2);
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
uint32_t appid = 0x000000;
|
||||
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 noauth = arg_get_lit(ctx, 15);
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
uint32_t id = 0x000000;
|
||||
DesfireISOSelectWay selectway = ISW6bAID;
|
||||
@@ -2915,7 +2915,7 @@ static int CmdHF14ADesGetKeySettings(const char *Cmd) {
|
||||
bool APDULogging = arg_get_lit(ctx, 1);
|
||||
bool verbose = arg_get_lit(ctx, 2);
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
uint32_t appid = 0x000000;
|
||||
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 noauth = arg_get_lit(ctx, 11);
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 0, 0, &securechann, DCMMACed, NULL, NULL);
|
||||
if (res) {
|
||||
@@ -3060,7 +3060,7 @@ static int CmdHF14ADesGetAppNames(const char *Cmd) {
|
||||
bool verbose = arg_get_lit(ctx, 2);
|
||||
bool noauth = arg_get_lit(ctx, 11);
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 0, 0, &securechann, DCMMACed, NULL, NULL);
|
||||
if (res) {
|
||||
@@ -3134,7 +3134,7 @@ static int CmdHF14ADesGetFileIDs(const char *Cmd) {
|
||||
bool verbose = arg_get_lit(ctx, 2);
|
||||
bool noauth = arg_get_lit(ctx, 13);
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
uint32_t id = 0x000000;
|
||||
DesfireISOSelectWay selectway = ISW6bAID;
|
||||
@@ -3208,7 +3208,7 @@ static int CmdHF14ADesGetFileISOIDs(const char *Cmd) {
|
||||
bool verbose = arg_get_lit(ctx, 2);
|
||||
bool noauth = arg_get_lit(ctx, 13);
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
uint32_t id = 0x000000;
|
||||
DesfireISOSelectWay selectway = ISW6bAID;
|
||||
@@ -3282,7 +3282,7 @@ static int CmdHF14ADesGetFileSettings(const char *Cmd) {
|
||||
bool verbose = arg_get_lit(ctx, 2);
|
||||
bool noauth = arg_get_lit(ctx, 14);
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
uint32_t id = 0x000000;
|
||||
DesfireISOSelectWay selectway = ISW6bAID;
|
||||
@@ -3462,7 +3462,7 @@ static int CmdHF14ADesChFileSettings(const char *Cmd) {
|
||||
bool verbose = arg_get_lit(ctx, 2);
|
||||
bool noauth = arg_get_lit(ctx, 21);
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
uint32_t id = 0x000000;
|
||||
DesfireISOSelectWay selectway = ISW6bAID;
|
||||
@@ -3610,7 +3610,7 @@ static int CmdHF14ADesCreateFile(const char *Cmd) {
|
||||
bool backup = arg_get_lit(ctx, 24);
|
||||
uint8_t filetype = (backup) ? 0x01 : 0x00; // backup / standard data file
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
uint32_t appid = 0x000000;
|
||||
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
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
uint32_t appid = 0x000000;
|
||||
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);
|
||||
uint8_t filetype = (cyclic) ? 0x04 : 0x03; // linear(03) / cyclic(04) record file
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
uint32_t appid = 0x000000;
|
||||
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
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
uint32_t id = 0x000000;
|
||||
DesfireISOSelectWay selectway = ISW6bAID;
|
||||
@@ -4098,7 +4098,7 @@ static int CmdHF14ADesDeleteFile(const char *Cmd) {
|
||||
bool verbose = arg_get_lit(ctx, 2);
|
||||
bool noauth = arg_get_lit(ctx, 14);
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
uint32_t id = 0x000000;
|
||||
DesfireISOSelectWay selectway = ISW6bAID;
|
||||
@@ -4178,7 +4178,7 @@ static int CmdHF14ADesValueOperations(const char *Cmd) {
|
||||
bool verbose = arg_get_lit(ctx, 2);
|
||||
bool noauth = arg_get_lit(ctx, 16);
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
uint32_t id = 0x000000;
|
||||
DesfireISOSelectWay selectway = ISW6bAID;
|
||||
@@ -4348,7 +4348,7 @@ static int CmdHF14ADesClearRecordFile(const char *Cmd) {
|
||||
bool verbose = arg_get_lit(ctx, 2);
|
||||
bool noauth = arg_get_lit(ctx, 14);
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
uint32_t id = 0x000000;
|
||||
DesfireISOSelectWay selectway = ISW6bAID;
|
||||
@@ -4406,7 +4406,7 @@ static int CmdHF14ADesClearRecordFile(const char *Cmd) {
|
||||
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) {
|
||||
PrintAndLogEx(ERR, "ISO mode needs to specify file type");
|
||||
@@ -4500,7 +4500,7 @@ static int DesfileReadISOFileAndPrint(DesfireContext *dctx, bool select_current_
|
||||
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;
|
||||
// length of record for record file
|
||||
size_t reclen = 0;
|
||||
@@ -4510,11 +4510,11 @@ static int DesfileReadFileAndPrint(DesfireContext *dctx, uint8_t fnum, int filet
|
||||
|
||||
// get file settings
|
||||
if (filetype == RFTAuto) {
|
||||
FileSettingsS fsettings;
|
||||
FileSettings_t fsettings;
|
||||
|
||||
DesfireCommunicationMode commMode = dctx->commMode;
|
||||
DesfireSetCommMode(dctx, DCMMACed);
|
||||
res = DesfireGetFileSettingsStruct(dctx, fnum, &fsettings);
|
||||
res = DesfireFileSettingsStruct(dctx, fnum, &fsettings);
|
||||
DesfireSetCommMode(dctx, commMode);
|
||||
|
||||
if (res == PM3_SUCCESS) {
|
||||
@@ -4734,7 +4734,7 @@ static int CmdHF14ADesReadData(const char *Cmd) {
|
||||
bool verbose = arg_get_lit(ctx, 2);
|
||||
bool noauth = arg_get_lit(ctx, 13);
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
uint32_t id = 0x000000;
|
||||
DesfireISOSelectWay selectway = ISW6bAID;
|
||||
@@ -4801,7 +4801,7 @@ static int CmdHF14ADesReadData(const char *Cmd) {
|
||||
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) {
|
||||
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 noauth = arg_get_lit(ctx, 13);
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
uint32_t id = 0x000000;
|
||||
DesfireISOSelectWay selectway = ISW6bAID;
|
||||
@@ -5006,11 +5006,11 @@ static int CmdHF14ADesWriteData(const char *Cmd) {
|
||||
|
||||
// get file settings
|
||||
if (op == RFTAuto) {
|
||||
FileSettingsS fsettings;
|
||||
FileSettings_t fsettings;
|
||||
|
||||
DesfireCommunicationMode commMode = dctx.commMode;
|
||||
DesfireSetCommMode(&dctx, DCMMACed);
|
||||
res = DesfireGetFileSettingsStruct(&dctx, fnum, &fsettings);
|
||||
res = DesfireFileSettingsStruct(&dctx, fnum, &fsettings);
|
||||
DesfireSetCommMode(&dctx, commMode);
|
||||
|
||||
if (res == PM3_SUCCESS) {
|
||||
@@ -5233,7 +5233,7 @@ static int CmdHF14ADesLsFiles(const char *Cmd) {
|
||||
bool verbose = arg_get_lit(ctx, 2);
|
||||
bool noauth = arg_get_lit(ctx, 13);
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
uint32_t id = 0x000000;
|
||||
DesfireISOSelectWay selectway = ISW6bAID;
|
||||
@@ -5253,7 +5253,7 @@ static int CmdHF14ADesLsFiles(const char *Cmd) {
|
||||
return res;
|
||||
}
|
||||
|
||||
FileListS FileList = {0};
|
||||
FileList_t FileList = {0};
|
||||
size_t filescount = 0;
|
||||
bool isopresent = false;
|
||||
res = DesfireFillFileList(&dctx, FileList, &filescount, &isopresent);
|
||||
@@ -5308,7 +5308,7 @@ static int CmdHF14ADesLsApp(const char *Cmd) {
|
||||
bool nodeep = arg_get_lit(ctx, 12);
|
||||
bool scanfiles = arg_get_lit(ctx, 13);
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 0, 0, &securechann, (noauth) ? DCMPlain : DCMMACed, NULL, NULL);
|
||||
if (res) {
|
||||
@@ -5327,7 +5327,7 @@ static int CmdHF14ADesLsApp(const char *Cmd) {
|
||||
return res;
|
||||
}
|
||||
|
||||
PICCInfoS PICCInfo = {0};
|
||||
PICCInfo_t PICCInfo = {0};
|
||||
AppListS AppList = {0};
|
||||
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 noauth = arg_get_lit(ctx, 14);
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
int securechann = defaultSecureChannel;
|
||||
uint32_t id = 0x000000;
|
||||
DesfireISOSelectWay selectway = ISW6bAID;
|
||||
@@ -5399,7 +5399,7 @@ static int CmdHF14ADesDump(const char *Cmd) {
|
||||
return res;
|
||||
}
|
||||
|
||||
FileListS FileList = {0};
|
||||
FileList_t FileList = {0};
|
||||
size_t filescount = 0;
|
||||
bool isopresent = false;
|
||||
res = DesfireFillFileList(&dctx, FileList, &filescount, &isopresent);
|
||||
|
||||
@@ -38,7 +38,7 @@ typedef struct {
|
||||
uint32_t colorreq;
|
||||
uint32_t Color_1; //Color palette
|
||||
uint32_t Color_2;
|
||||
} PACKED BMP_HEADER;
|
||||
} PACKED bmp_header_t;
|
||||
|
||||
#define EPD_1IN54B 0
|
||||
#define EPD_1IN54C 1
|
||||
@@ -92,11 +92,11 @@ static model_t models[] = {
|
||||
static int CmdHelp(const char *Cmd);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
BMP_HEADER *pbmpheader = (BMP_HEADER *)bmp;
|
||||
bmp_header_t *pbmpheader = (bmp_header_t *)bmp;
|
||||
PrintAndLogEx(DEBUG, "colorsused = %d", pbmpheader->colorsused);
|
||||
PrintAndLogEx(DEBUG, "pbmpheader->bpp = %d", pbmpheader->bpp);
|
||||
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) {
|
||||
BMP_HEADER *pbmpheader = (BMP_HEADER *)bmp;
|
||||
bmp_header_t *pbmpheader = (bmp_header_t *)bmp;
|
||||
// check file is bitmap
|
||||
if (pbmpheader->bpp != 1) {
|
||||
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) {
|
||||
BMP_HEADER *pbmpheader = (BMP_HEADER *)bmp;
|
||||
bmp_header_t *pbmpheader = (bmp_header_t *)bmp;
|
||||
// check file is full color
|
||||
if ((pbmpheader->bpp != 24) && (pbmpheader->bpp != 32)) {
|
||||
return PM3_ESOFT;
|
||||
|
||||
@@ -41,9 +41,9 @@ const char *TransactionTypeStr[] = {
|
||||
typedef struct {
|
||||
enum CardPSVendor vendor;
|
||||
const char *aid;
|
||||
} TAIDList;
|
||||
} AIDList_t;
|
||||
|
||||
static const TAIDList AIDlist [] = {
|
||||
static const AIDList_t AIDlist [] = {
|
||||
// Visa International
|
||||
{ CV_VISA, "A00000000305076010" }, // VISA ELO Credit
|
||||
{ CV_VISA, "A0000000031010" }, // VISA Debit/Credit (Classic)
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include "fileutils.h"
|
||||
#include "pm3_cmd.h"
|
||||
|
||||
static const ApplicationDataElm ApplicationData[] = {
|
||||
static const ApplicationDataElm_t ApplicationData[] = {
|
||||
{0x82, "AIP"},
|
||||
{0x94, "AFL"},
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
typedef struct {
|
||||
tlv_tag_t Tag;
|
||||
const char *Name;
|
||||
} ApplicationDataElm;
|
||||
} ApplicationDataElm_t;
|
||||
|
||||
const char *GetApplicationDataName(tlv_tag_t tag);
|
||||
|
||||
|
||||
+17
-17
@@ -60,14 +60,14 @@ typedef struct {
|
||||
uint8_t r;
|
||||
uint8_t b;
|
||||
uint16_t t;
|
||||
} State;
|
||||
} State_t;
|
||||
|
||||
/**
|
||||
* Definition 2. The feedback function for the top register T : F 16/2 → F 2
|
||||
* 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 .
|
||||
**/
|
||||
static bool T(State state) {
|
||||
static bool T(State_t state) {
|
||||
/*
|
||||
bool x0 = state.t & 0x8000;
|
||||
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
|
||||
* 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 x2 = state.b & 0x20;
|
||||
bool x3 = state.b & 0x10;
|
||||
@@ -169,12 +169,12 @@ static uint8_t _select(bool x, bool y, uint8_t r) {
|
||||
* @param s - state
|
||||
* @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 r4 = s.r >> 3 & 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 |= ((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
|
||||
* @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) {
|
||||
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 )
|
||||
* 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) {
|
||||
return;
|
||||
}
|
||||
pushBit(out, (s.r >> 2) & 1);
|
||||
//Remove first bit
|
||||
uint8_t x0 = headBit(in);
|
||||
State ss = successor(k, s, x0);
|
||||
State_t ss = successor(k, s, x0);
|
||||
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 >
|
||||
**/
|
||||
|
||||
static State init(uint8_t *k) {
|
||||
State s = {
|
||||
static State_t init(uint8_t *k) {
|
||||
State_t s = {
|
||||
((k[0] ^ 0x4c) + 0xEC) & 0xFF,// l
|
||||
((k[0] ^ 0x4c) + 0x21) & 0xFF,// r
|
||||
0x4c, // b
|
||||
@@ -237,10 +237,10 @@ static State init(uint8_t *k) {
|
||||
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};
|
||||
BitstreamIn input_32_zeroes = {zeroes_32, sizeof(zeroes_32) * 8, 0};
|
||||
State initState = suc(k, init(k), &input);
|
||||
BitstreamIn_t input_32_zeroes = {zeroes_32, sizeof(zeroes_32) * 8, 0};
|
||||
State_t initState = suc(k, init(k), &input);
|
||||
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);
|
||||
|
||||
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};
|
||||
BitstreamOut out = { dest, sizeof(dest) * 8, 0 };
|
||||
BitstreamOut_t out = { dest, sizeof(dest) * 8, 0 };
|
||||
MAC(div_key, bitstream, out);
|
||||
//The output MAC must also be reversed
|
||||
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);
|
||||
|
||||
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};
|
||||
BitstreamOut out = { dest, sizeof(dest) * 8, 0 };
|
||||
BitstreamOut_t out = { dest, sizeof(dest) * 8, 0 };
|
||||
MAC(div_key, bitstream, out);
|
||||
//The output MAC must also be reversed
|
||||
reverse_arraybytes(dest, sizeof(dest));
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
* @param stream
|
||||
* @return
|
||||
*/
|
||||
bool headBit(BitstreamIn *stream) {
|
||||
bool headBit(BitstreamIn_t *stream) {
|
||||
int bytepos = stream->position >> 3; // divide by 8
|
||||
int bitpos = (stream->position++) & 7; // mask out 00000111
|
||||
return (*(stream->buffer + bytepos) >> (7 - bitpos)) & 1;
|
||||
@@ -59,7 +59,7 @@ bool headBit(BitstreamIn *stream) {
|
||||
* @param stream
|
||||
* @return
|
||||
*/
|
||||
bool tailBit(BitstreamIn *stream) {
|
||||
bool tailBit(BitstreamIn_t *stream) {
|
||||
int bitpos = stream->numbits - 1 - (stream->position++);
|
||||
|
||||
int bytepos = bitpos >> 3;
|
||||
@@ -71,7 +71,7 @@ bool tailBit(BitstreamIn *stream) {
|
||||
* @param stream
|
||||
* @param bit
|
||||
*/
|
||||
void pushBit(BitstreamOut *stream, bool bit) {
|
||||
void pushBit(BitstreamOut_t *stream, bool bit) {
|
||||
int bytepos = stream->position >> 3; // divide by 8
|
||||
int bitpos = stream->position & 7;
|
||||
*(stream->buffer + bytepos) |= (bit) << (7 - bitpos);
|
||||
@@ -85,7 +85,7 @@ void pushBit(BitstreamOut *stream, bool bit) {
|
||||
* @param stream
|
||||
* @param bits
|
||||
*/
|
||||
void push6bits(BitstreamOut *stream, uint8_t bits) {
|
||||
void push6bits(BitstreamOut_t *stream, uint8_t bits) {
|
||||
pushBit(stream, bits & 0x20);
|
||||
pushBit(stream, bits & 0x10);
|
||||
pushBit(stream, bits & 0x08);
|
||||
@@ -99,7 +99,7 @@ void push6bits(BitstreamOut *stream, uint8_t bits) {
|
||||
* @param stream
|
||||
* @return number of bits left in stream
|
||||
*/
|
||||
int bitsLeft(BitstreamIn *stream) {
|
||||
int bitsLeft(BitstreamIn_t *stream) {
|
||||
return stream->numbits - stream->position;
|
||||
}
|
||||
/**
|
||||
@@ -108,7 +108,7 @@ int bitsLeft(BitstreamIn *stream) {
|
||||
* @return Number of bits stored in stream
|
||||
*/
|
||||
/*
|
||||
static int numBits(BitstreamOut *stream) {
|
||||
static int numBits(BitstreamOut_t *stream) {
|
||||
return stream->numbits;
|
||||
}
|
||||
*/
|
||||
@@ -187,8 +187,8 @@ void printarr_human_readable(const char *title, uint8_t *arr, int len) {
|
||||
static int testBitStream(void) {
|
||||
uint8_t input [] = {0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF};
|
||||
uint8_t output [] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
BitstreamIn in = { input, sizeof(input) * 8, 0};
|
||||
BitstreamOut out = { output, 0, 0}
|
||||
BitstreamIn_t in = { input, sizeof(input) * 8, 0};
|
||||
BitstreamOut_t out = { output, 0, 0}
|
||||
;
|
||||
while (bitsLeft(&in) > 0) {
|
||||
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 reverse [] = {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};
|
||||
BitstreamOut out = { output, 0, 0};
|
||||
BitstreamIn reversed_in = { reverse, sizeof(input) * 8, 0};
|
||||
BitstreamOut reversed_out = { reverse, 0, 0};
|
||||
BitstreamIn_t in = { input, sizeof(input) * 8, 0};
|
||||
BitstreamOut_t out = { output, 0, 0};
|
||||
BitstreamIn_t reversed_in = { reverse, sizeof(input) * 8, 0};
|
||||
BitstreamOut_t reversed_out = { reverse, 0, 0};
|
||||
|
||||
while (bitsLeft(&in) > 0) {
|
||||
pushBit(&reversed_out, tailBit(&in));
|
||||
|
||||
@@ -47,22 +47,22 @@ typedef struct {
|
||||
uint8_t *buffer;
|
||||
uint8_t numbits;
|
||||
uint8_t position;
|
||||
} BitstreamIn;
|
||||
} BitstreamIn_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t *buffer;
|
||||
uint8_t numbits;
|
||||
uint8_t position;
|
||||
} BitstreamOut;
|
||||
} BitstreamOut_t;
|
||||
|
||||
bool headBit(BitstreamIn *stream);
|
||||
bool tailBit(BitstreamIn *stream);
|
||||
void pushBit(BitstreamOut *stream, bool bit);
|
||||
int bitsLeft(BitstreamIn *stream);
|
||||
bool headBit(BitstreamIn_t *stream);
|
||||
bool tailBit(BitstreamIn_t *stream);
|
||||
void pushBit(BitstreamOut_t *stream, bool bit);
|
||||
int bitsLeft(BitstreamIn_t *stream);
|
||||
#ifndef ON_DEVICE
|
||||
int testCipherUtils(void);
|
||||
#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 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);
|
||||
|
||||
@@ -205,7 +205,7 @@ static uint64_t check(uint64_t z) {
|
||||
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)
|
||||
return;
|
||||
|
||||
@@ -290,9 +290,9 @@ void hash0(uint64_t c, uint8_t k[8]) {
|
||||
|
||||
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};
|
||||
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
|
||||
|
||||
//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);
|
||||
|
||||
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};
|
||||
BitstreamOut out = {outbuffer, 0, 0};
|
||||
BitstreamOut_t out = {outbuffer, 0, 0};
|
||||
|
||||
permute(&p_in, x, 0, 4, &out);
|
||||
|
||||
@@ -708,7 +708,7 @@ void checkParity2(uint8_t* key) {
|
||||
uint8_t stored_parity = key[7];
|
||||
PrintAndLogEx(NORMAL, "Parity byte: 0x%02x", stored_parity);
|
||||
int i, byte, fails = 0;
|
||||
BitstreamIn bits = {key, 56, 0};
|
||||
BitstreamIn_t bits = {key, 56, 0};
|
||||
bool parity = 0;
|
||||
|
||||
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;
|
||||
bool parity =0;
|
||||
BitstreamOut out = { output, 0, 0};
|
||||
BitstreamOut_t out = { output, 0, 0};
|
||||
unsigned int bbyte, bbit;
|
||||
for (bbyte = 0; bbyte <8; bbyte++ ) {
|
||||
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) {
|
||||
bool parity =0;
|
||||
BitstreamOut out = {output, 0, 0};
|
||||
BitstreamIn in = {key, 0, 0};
|
||||
BitstreamOut_t out = {output, 0, 0};
|
||||
BitstreamIn_t in = {key, 0, 0};
|
||||
unsigned int bbyte, bbit;
|
||||
for (bbit = 0; bbit < 56; bbit++) {
|
||||
if (bbit > 0 && bbit % 7 == 0) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -43,7 +43,7 @@ typedef struct {
|
||||
const uint8_t len;
|
||||
const uint8_t createlen;
|
||||
const bool mayHaveISOfid;
|
||||
} DesfireCreateFileCommandsS;
|
||||
} DesfireCreateFileCommands_t;
|
||||
|
||||
typedef struct {
|
||||
// all
|
||||
@@ -81,15 +81,15 @@ typedef struct {
|
||||
uint8_t additionalAccessRightsLength;
|
||||
uint16_t additionalAccessRights[16];
|
||||
|
||||
} FileSettingsS;
|
||||
} FileSettings_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t fileNum;
|
||||
uint16_t fileISONum;
|
||||
FileSettingsS fileSettings;
|
||||
} FileListElmS;
|
||||
FileSettings_t fileSettings;
|
||||
} FileListElm_t;
|
||||
|
||||
typedef FileListElmS FileListS[32];
|
||||
typedef FileListElm_t FileList_t[32];
|
||||
|
||||
typedef struct {
|
||||
bool checked;
|
||||
@@ -98,13 +98,13 @@ typedef struct {
|
||||
bool authAES;
|
||||
bool authEV2;
|
||||
bool authISONative;
|
||||
} AuthCommandsChk;
|
||||
} AuthCommandsChk_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t appNum;
|
||||
uint16_t appISONum;
|
||||
char appDFName[16];
|
||||
AuthCommandsChk authCmdCheck;
|
||||
AuthCommandsChk_t authCmdCheck;
|
||||
|
||||
uint8_t keySettings;
|
||||
uint8_t numKeysRaw;
|
||||
@@ -117,21 +117,21 @@ typedef struct {
|
||||
bool filesReaded;
|
||||
size_t filesCount;
|
||||
bool isoPresent;
|
||||
FileListS fileList;
|
||||
} AppListElmS;
|
||||
typedef AppListElmS AppListS[64];
|
||||
FileList_t fileList;
|
||||
} AppListElm_t;
|
||||
typedef AppListElm_t AppListS[64];
|
||||
|
||||
typedef struct {
|
||||
size_t appCount;
|
||||
uint32_t freemem;
|
||||
AuthCommandsChk authCmdCheck;
|
||||
AuthCommandsChk_t authCmdCheck;
|
||||
|
||||
uint8_t keySettings;
|
||||
uint8_t numKeysRaw;
|
||||
uint8_t numberOfKeys; // from numKeysRaw
|
||||
|
||||
uint8_t keyVersion0;
|
||||
} PICCInfoS;
|
||||
} PICCInfo_t;
|
||||
|
||||
typedef enum {
|
||||
RFTAuto,
|
||||
@@ -154,75 +154,75 @@ const char *DesfireGetErrorString(int res, uint16_t *sw);
|
||||
uint32_t DesfireAIDByteToUint(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 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 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_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 DesfireSelectAID(DesfireContext *ctx, uint8_t *aid1, uint8_t *aid2);
|
||||
int DesfireSelectAIDHex(DesfireContext *ctx, uint32_t aid1, bool select_two, uint32_t aid2);
|
||||
int DesfireSelectAIDHexNoFieldOn(DesfireContext *ctx, uint32_t aid);
|
||||
int DesfireSelectAID(DesfireContext_t *ctx, uint8_t *aid1, uint8_t *aid2);
|
||||
int DesfireSelectAIDHex(DesfireContext_t *ctx, uint32_t aid1, bool select_two, uint32_t aid2);
|
||||
int DesfireSelectAIDHexNoFieldOn(DesfireContext_t *ctx, uint32_t aid);
|
||||
void DesfirePrintAIDFunctions(uint32_t appid);
|
||||
void DesfirePrintMADAID(uint32_t appid, bool verbose);
|
||||
|
||||
int DesfireGetCardUID(DesfireContext *ctx);
|
||||
int DesfireGetCardUID(DesfireContext_t *ctx);
|
||||
|
||||
const char *DesfireSelectWayToStr(DesfireISOSelectWay way);
|
||||
char *DesfireWayIDStr(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 DesfireSelect(DesfireContext *ctx, DesfireISOSelectWay way, uint32_t id, char *dfname);
|
||||
int DesfireSelectEx(DesfireContext_t *ctx, bool fieldon, DesfireISOSelectWay way, uint32_t id, char *dfname);
|
||||
int DesfireSelect(DesfireContext_t *ctx, DesfireISOSelectWay way, uint32_t id, char *dfname);
|
||||
|
||||
const char *DesfireAuthErrorToStr(int error);
|
||||
int DesfireSelectAndAuthenticate(DesfireContext *dctx, DesfireSecureChannel secureChannel, uint32_t aid, bool verbose);
|
||||
int DesfireSelectAndAuthenticateEx(DesfireContext *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 DesfireSelectAndAuthenticateAppW(DesfireContext *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 DesfireAuthenticate(DesfireContext *dctx, DesfireSecureChannel secureChannel, bool verbose);
|
||||
void DesfireCheckAuthCommands(uint32_t appAID, char *dfname, uint8_t keyNum, AuthCommandsChk *authCmdCheck);
|
||||
void DesfireCheckAuthCommandsPrint(AuthCommandsChk *authCmdCheck);
|
||||
int DesfireSelectAndAuthenticate(DesfireContext_t *dctx, DesfireSecureChannel secureChannel, uint32_t aid, bool verbose);
|
||||
int DesfireSelectAndAuthenticateEx(DesfireContext_t *dctx, DesfireSecureChannel secureChannel, uint32_t aid, 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_t *dctx, DesfireSecureChannel secureChannel, DesfireISOSelectWay way, uint32_t id, 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_t *dctx, DesfireSecureChannel secureChannel, bool verbose);
|
||||
void DesfireCheckAuthCommands(uint32_t appAID, char *dfname, uint8_t keyNum, AuthCommandsChk_t *authCmdCheck);
|
||||
void DesfireCheckAuthCommandsPrint(AuthCommandsChk_t *authCmdCheck);
|
||||
|
||||
int DesfireFormatPICC(DesfireContext *dctx);
|
||||
int DesfireGetFreeMem(DesfireContext *dctx, uint32_t *freemem);
|
||||
int DesfireGetUID(DesfireContext *dctx, uint8_t *resp, size_t *resplen);
|
||||
int DesfireGetAIDList(DesfireContext *dctx, uint8_t *resp, size_t *resplen);
|
||||
int DesfireGetDFList(DesfireContext *dctx, uint8_t *resp, size_t *resplen);
|
||||
int DesfireFillPICCInfo(DesfireContext *dctx, PICCInfoS *PICCInfo, bool deepmode);
|
||||
int DesfireFillAppList(DesfireContext *dctx, PICCInfoS *PICCInfo, AppListS appList, bool deepmode, bool readFiles, bool fillAppSettings);
|
||||
void DesfirePrintPICCInfo(DesfireContext *dctx, PICCInfoS *PICCInfo);
|
||||
void DesfirePrintAppList(DesfireContext *dctx, PICCInfoS *PICCInfo, AppListS appList);
|
||||
int DesfireFormatPICC(DesfireContext_t *dctx);
|
||||
int DesfireGetFreeMem(DesfireContext_t *dctx, uint32_t *freemem);
|
||||
int DesfireGetUID(DesfireContext_t *dctx, uint8_t *resp, size_t *resplen);
|
||||
int DesfireGetAIDList(DesfireContext_t *dctx, uint8_t *resp, size_t *resplen);
|
||||
int DesfireGetDFList(DesfireContext_t *dctx, uint8_t *resp, size_t *resplen);
|
||||
int DesfireFillPICCInfo(DesfireContext_t *dctx, PICCInfo_t *PICCInfo, bool deepmode);
|
||||
int DesfireFillAppList(DesfireContext_t *dctx, PICCInfo_t *PICCInfo, AppListS appList, bool deepmode, bool readFiles, bool fillAppSettings);
|
||||
void DesfirePrintPICCInfo(DesfireContext_t *dctx, PICCInfo_t *PICCInfo);
|
||||
void DesfirePrintAppList(DesfireContext_t *dctx, PICCInfo_t *PICCInfo, AppListS appList);
|
||||
|
||||
int DesfireCreateApplication(DesfireContext *dctx, uint8_t *appdata, size_t appdatalen);
|
||||
int DesfireDeleteApplication(DesfireContext *dctx, uint32_t aid);
|
||||
int DesfireCreateApplication(DesfireContext_t *dctx, uint8_t *appdata, size_t appdatalen);
|
||||
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 DesfireGetKeySettings(DesfireContext *dctx, uint8_t *resp, size_t *resplen);
|
||||
int DesfireChangeKeySettings(DesfireContext *dctx, uint8_t *data, size_t len);
|
||||
int DesfireGetKeyVersion(DesfireContext_t *dctx, uint8_t *data, size_t len, uint8_t *resp, size_t *resplen);
|
||||
int DesfireGetKeySettings(DesfireContext_t *dctx, uint8_t *resp, size_t *resplen);
|
||||
int DesfireChangeKeySettings(DesfireContext_t *dctx, uint8_t *data, size_t len);
|
||||
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 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 DesfireChangeKeyCmd(DesfireContext_t *dctx, uint8_t *data, size_t datalen, uint8_t *resp, size_t *resplen);
|
||||
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 DesfireSetConfiguration(DesfireContext *dctx, uint8_t paramid, uint8_t *param, size_t paramlen);
|
||||
int DesfireSetConfigurationCmd(DesfireContext_t *dctx, uint8_t *data, size_t len, uint8_t *resp, size_t *resplen);
|
||||
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 DesfireGetFileIDList(DesfireContext *dctx, uint8_t *resp, size_t *resplen);
|
||||
int DesfireGetFileISOIDList(DesfireContext *dctx, uint8_t *resp, size_t *resplen);
|
||||
int DesfireFillFileList(DesfireContext_t *dctx, FileList_t FileList, size_t *filescount, bool *isopresent);
|
||||
int DesfireGetFileIDList(DesfireContext_t *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 DesfirePrintFileSettingsOneLine(FileSettingsS *fsettings);
|
||||
void DesfirePrintFileSettingsTable(bool printheader, uint8_t id, bool isoidavail, uint16_t isoid, FileSettingsS *fsettings);
|
||||
void DesfirePrintFileSettingsExtended(FileSettingsS *fsettings);
|
||||
int DesfireGetFileSettings(DesfireContext *dctx, uint8_t fileid, uint8_t *resp, size_t *resplen);
|
||||
int DesfireGetFileSettingsStruct(DesfireContext *dctx, uint8_t fileid, FileSettingsS *fsettings);
|
||||
int DesfireChangeFileSettings(DesfireContext *dctx, uint8_t *data, size_t datalen);
|
||||
void DesfireFillFileSettings(uint8_t *data, size_t datalen, FileSettings_t *fsettings);
|
||||
void DesfirePrintFileSettingsOneLine(FileSettings_t *fsettings);
|
||||
void DesfirePrintFileSettingsTable(bool printheader, uint8_t id, bool isoidavail, uint16_t isoid, FileSettings_t *fsettings);
|
||||
void DesfirePrintFileSettingsExtended(FileSettings_t *fsettings);
|
||||
int DesfireGetFileSettings(DesfireContext_t *dctx, uint8_t fileid, uint8_t *resp, size_t *resplen);
|
||||
int DesfireFileSettingsStruct(DesfireContext_t *dctx, uint8_t fileid, FileSettings_t *fsettings);
|
||||
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 *GetDesfireAccessRightShortStr(uint8_t right);
|
||||
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);
|
||||
|
||||
const char *GetDesfireFileType(uint8_t type);
|
||||
int DesfireCreateFile(DesfireContext *dctx, uint8_t ftype, uint8_t *fdata, size_t fdatalen, bool checklen);
|
||||
int DesfireDeleteFile(DesfireContext *dctx, uint8_t fnum);
|
||||
int DesfireCommitReaderID(DesfireContext *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 DesfireCommitTransaction(DesfireContext *dctx, bool enable_options, uint8_t options);
|
||||
int DesfireAbortTransaction(DesfireContext *dctx);
|
||||
int DesfireCreateFile(DesfireContext_t *dctx, uint8_t ftype, uint8_t *fdata, size_t fdatalen, bool checklen);
|
||||
int DesfireDeleteFile(DesfireContext_t *dctx, uint8_t fnum);
|
||||
int DesfireCommitReaderID(DesfireContext_t *dctx, uint8_t *readerid, size_t readeridlen, 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_t *dctx, bool enable_options, uint8_t options);
|
||||
int DesfireAbortTransaction(DesfireContext_t *dctx);
|
||||
|
||||
int DesfireValueFileOperations(DesfireContext *dctx, uint8_t fid, uint8_t operation, uint32_t *value);
|
||||
int DesfireClearRecordFile(DesfireContext *dctx, uint8_t fnum);
|
||||
int DesfireValueFileOperations(DesfireContext_t *dctx, uint8_t fid, uint8_t operation, uint32_t *value);
|
||||
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 DesfireWriteFile(DesfireContext *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 DesfireWriteRecord(DesfireContext *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 DesfireReadFile(DesfireContext_t *dctx, uint8_t fnum, uint32_t offset, uint32_t len, uint8_t *resp, size_t *resplen);
|
||||
int DesfireWriteFile(DesfireContext_t *dctx, uint8_t fnum, uint32_t offset, uint32_t len, uint8_t *data);
|
||||
int DesfireReadRecords(DesfireContext_t *dctx, uint8_t fnum, uint32_t recnum, uint32_t reccount, uint8_t *resp, size_t *resplen);
|
||||
int DesfireWriteRecord(DesfireContext_t *dctx, uint8_t fnum, 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 DesfireISOSelect(DesfireContext *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 DesfireISOSelectEx(DesfireContext *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 DesfireISOExternalAuth(DesfireContext *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 DesfireISOSelectDF(DesfireContext_t *dctx, char *dfname, 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_t *dctx, char *appdfname, uint16_t appid, uint16_t fileid);
|
||||
int DesfireISOSelectEx(DesfireContext_t *dctx, bool fieldon, DesfireISOSelectControl cntr, uint8_t *data, uint8_t datalen, uint8_t *resp, size_t *resplen);
|
||||
int DesfireISOGetChallenge(DesfireContext_t *dctx, DesfireCryptoAlgorythm keytype, uint8_t *resp, size_t *resplen);
|
||||
int DesfireISOExternalAuth(DesfireContext_t *dctx, bool app_level, uint8_t keynum, DesfireCryptoAlgorythm keytype, uint8_t *data);
|
||||
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 DesfireISOUpdateBinary(DesfireContext *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 DesfireISOAppendRecord(DesfireContext *dctx, uint8_t fileid, uint8_t *data, size_t datalen);
|
||||
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_t *dctx, bool use_file_id, uint8_t fileid, uint16_t offset, uint8_t *data, size_t datalen);
|
||||
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_t *dctx, uint8_t fileid, uint8_t *data, size_t datalen);
|
||||
|
||||
#endif // __DESFIRECORE_H
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include "crc32.h"
|
||||
#include "commonutil.h"
|
||||
|
||||
void DesfireClearContext(DesfireContext *ctx) {
|
||||
void DesfireClearContext(DesfireContext_t *ctx) {
|
||||
ctx->keyNum = 0;
|
||||
ctx->keyType = T_DES;
|
||||
memset(ctx->key, 0, sizeof(ctx->key));
|
||||
@@ -55,7 +55,7 @@ void DesfireClearContext(DesfireContext *ctx) {
|
||||
DesfireClearSession(ctx);
|
||||
}
|
||||
|
||||
void DesfireClearSession(DesfireContext *ctx) {
|
||||
void DesfireClearSession(DesfireContext_t *ctx) {
|
||||
ctx->secureChannel = DACNone; // here none - not authenticared
|
||||
|
||||
memset(ctx->IV, 0, sizeof(ctx->IV));
|
||||
@@ -68,42 +68,42 @@ void DesfireClearSession(DesfireContext *ctx) {
|
||||
memset(ctx->TI, 0, sizeof(ctx->TI));
|
||||
}
|
||||
|
||||
void DesfireClearIV(DesfireContext *ctx) {
|
||||
void DesfireClearIV(DesfireContext_t *ctx) {
|
||||
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);
|
||||
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->keyType = keyType;
|
||||
memcpy(ctx->key, 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;
|
||||
}
|
||||
|
||||
void DesfireSetCommMode(DesfireContext *ctx, DesfireCommunicationMode commMode) {
|
||||
void DesfireSetCommMode(DesfireContext_t *ctx, DesfireCommunicationMode 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->kdfInputLen = kdfInputLen;
|
||||
if (kdfInputLen)
|
||||
memcpy(ctx->kdfInput, kdfInput, kdfInputLen);
|
||||
}
|
||||
|
||||
bool DesfireIsAuthenticated(DesfireContext *dctx) {
|
||||
bool DesfireIsAuthenticated(DesfireContext_t *dctx) {
|
||||
return dctx->secureChannel != DACNone;
|
||||
}
|
||||
|
||||
size_t DesfireGetMACLength(DesfireContext *ctx) {
|
||||
size_t DesfireGetMACLength(DesfireContext_t *ctx) {
|
||||
size_t mac_length = DESFIRE_MAC_LENGTH;
|
||||
switch (ctx->secureChannel) {
|
||||
case DACNone:
|
||||
@@ -162,7 +162,7 @@ size_t DesfireSearchCRCPos(uint8_t *data, size_t datalen, uint8_t respcode, uint
|
||||
return crcposfound;
|
||||
}
|
||||
|
||||
uint8_t *DesfireGetKey(DesfireContext *ctx, DesfireCryptoOpKeyType key_type) {
|
||||
uint8_t *DesfireGetKey(DesfireContext_t *ctx, DesfireCryptoOpKeyType key_type) {
|
||||
if (key_type == DCOSessionKeyMac) {
|
||||
return ctx->sessionKeyMAC;
|
||||
} else if (key_type == DCOSessionKeyEnc) {
|
||||
@@ -241,7 +241,7 @@ static void DesfireCryptoEncDecSingleBlock(uint8_t *key, DesfireCryptoAlgorythm
|
||||
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 xiv[DESFIRE_MAX_CRYPTO_BLOCK_SIZE] = {0};
|
||||
|
||||
@@ -281,7 +281,7 @@ void DesfireCryptoEncDecEx(DesfireContext *ctx, DesfireCryptoOpKeyType key_type,
|
||||
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 xencode = encode;
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
if (kbs == 0)
|
||||
return;
|
||||
@@ -351,12 +351,12 @@ void DesfireCryptoCMACEx(DesfireContext *ctx, DesfireCryptoOpKeyType key_type, u
|
||||
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);
|
||||
}
|
||||
|
||||
// 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)
|
||||
return;
|
||||
|
||||
@@ -582,7 +582,7 @@ void DesfireGenSessionKeyEV2(uint8_t *key, uint8_t *rndA, uint8_t *rndB, bool en
|
||||
memcpy(data + 24, rndA + 8, 8);
|
||||
|
||||
uint8_t cmac[CRYPTO_AES_BLOCK_SIZE] = {0};
|
||||
DesfireContext ctx = {0};
|
||||
DesfireContext_t ctx = {0};
|
||||
ctx.keyType = T_AES;
|
||||
memcpy(ctx.key, key, 16); // aes-128
|
||||
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[31] = 0x69;
|
||||
|
||||
LRPContext ctx = {0};
|
||||
LRPContext_t ctx = {0};
|
||||
LRPSetKey(&ctx, key, 0, true);
|
||||
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};
|
||||
|
||||
if (ivforcommand) {
|
||||
@@ -633,7 +633,7 @@ void DesfireEV2FillIV(DesfireContext *ctx, bool ivforcommand, uint8_t *iv) {
|
||||
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};
|
||||
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);
|
||||
memcpy(&xiv[9], uid, 7);
|
||||
|
||||
DesfireContext ctx = {0};
|
||||
DesfireContext_t ctx = {0};
|
||||
DesfireSetKey(&ctx, 0, T_AES, key);
|
||||
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;
|
||||
}
|
||||
|
||||
LRPContext lctx = {0};
|
||||
LRPContext_t lctx = {0};
|
||||
LRPSetKey(&lctx, key, 0, false);
|
||||
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 uid[12] = {0};
|
||||
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);
|
||||
}
|
||||
|
||||
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};
|
||||
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);
|
||||
mdatalen = 1 + 2 + 4 + datalen;
|
||||
|
||||
LRPContext lctx = {0};
|
||||
LRPContext_t lctx = {0};
|
||||
LRPSetKey(&lctx, ctx->sessionKeyMAC, 0, true);
|
||||
LRPCMAC8(&lctx, mdata, mdatalen, mac);
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ typedef enum {
|
||||
DCOSessionKeyEnc
|
||||
} DesfireCryptoOpKeyType;
|
||||
|
||||
typedef struct DesfireContextS {
|
||||
typedef struct {
|
||||
uint8_t keyNum;
|
||||
DesfireCryptoAlgorythm keyType; // des/2tdea/3tdea/aes
|
||||
uint8_t key[DESFIRE_MAX_KEY_SIZE];
|
||||
@@ -102,28 +102,28 @@ typedef struct DesfireContextS {
|
||||
bool lastRequestZeroLen;
|
||||
uint16_t cmdCntr; // for AES
|
||||
uint8_t TI[4]; // for AES
|
||||
} DesfireContext;
|
||||
} DesfireContext_t;
|
||||
|
||||
void DesfireClearContext(DesfireContext *ctx);
|
||||
void DesfireClearSession(DesfireContext *ctx);
|
||||
void DesfireClearIV(DesfireContext *ctx);
|
||||
void DesfireSetKey(DesfireContext *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 DesfireSetCommandSet(DesfireContext *ctx, DesfireCommandSet cmdSet);
|
||||
void DesfireSetCommMode(DesfireContext *ctx, DesfireCommunicationMode commMode);
|
||||
void DesfireSetKdf(DesfireContext *ctx, uint8_t kdfAlgo, uint8_t *kdfInput, uint8_t kdfInputLen);
|
||||
bool DesfireIsAuthenticated(DesfireContext *dctx);
|
||||
size_t DesfireGetMACLength(DesfireContext *ctx);
|
||||
void DesfireClearContext(DesfireContext_t *ctx);
|
||||
void DesfireClearSession(DesfireContext_t *ctx);
|
||||
void DesfireClearIV(DesfireContext_t *ctx);
|
||||
void DesfireSetKey(DesfireContext_t *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_t *ctx, DesfireCommandSet cmdSet);
|
||||
void DesfireSetCommMode(DesfireContext_t *ctx, DesfireCommunicationMode commMode);
|
||||
void DesfireSetKdf(DesfireContext_t *ctx, uint8_t kdfAlgo, uint8_t *kdfInput, uint8_t kdfInputLen);
|
||||
bool DesfireIsAuthenticated(DesfireContext_t *dctx);
|
||||
size_t DesfireGetMACLength(DesfireContext_t *ctx);
|
||||
|
||||
size_t DesfireSearchCRCPos(uint8_t *data, size_t datalen, uint8_t respcode, uint8_t crclen);
|
||||
|
||||
uint8_t *DesfireGetKey(DesfireContext *ctx, DesfireCryptoOpKeyType key_type);
|
||||
void DesfireCryptoEncDec(DesfireContext *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 DesfireCMACGenerateSubkeys(DesfireContext *ctx, DesfireCryptoOpKeyType key_type, uint8_t *sk1, uint8_t *sk2);
|
||||
void DesfireCryptoCMAC(DesfireContext *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 MifareKdfAn10922(DesfireContext *ctx, DesfireCryptoOpKeyType key_type, const uint8_t *data, size_t len);
|
||||
uint8_t *DesfireGetKey(DesfireContext_t *ctx, DesfireCryptoOpKeyType key_type);
|
||||
void DesfireCryptoEncDec(DesfireContext_t *ctx, DesfireCryptoOpKeyType key_type, uint8_t *srcdata, size_t srcdatalen, uint8_t *dstdata, bool encode);
|
||||
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_t *ctx, DesfireCryptoOpKeyType key_type, uint8_t *sk1, uint8_t *sk2);
|
||||
void DesfireCryptoCMAC(DesfireContext_t *ctx, uint8_t *srcdata, size_t srcdatalen, 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_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);
|
||||
|
||||
@@ -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 DesfireGenSessionKeyEV2(uint8_t *key, uint8_t *rndA, uint8_t *rndB, bool enckey, uint8_t *sessionkey);
|
||||
void DesfireEV2FillIV(DesfireContext *ctx, bool ivforcommand, uint8_t *iv);
|
||||
int DesfireEV2CalcCMAC(DesfireContext *ctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *mac);
|
||||
void DesfireEV2FillIV(DesfireContext_t *ctx, bool ivforcommand, uint8_t *iv);
|
||||
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 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);
|
||||
size_t desfire_get_key_block_length(DesfireCryptoAlgorythm key_type);
|
||||
|
||||
@@ -47,7 +47,7 @@ static bool CommandCanUseAnyChannel(uint8_t cmd) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static const AllowedChannelModesS AllowedChannelModes[] = {
|
||||
static const AllowedChannelModes_t AllowedChannelModes[] = {
|
||||
// D40 channel
|
||||
{MFDES_SELECT_APPLICATION, DACd40, DCCNative, DCMPlain},
|
||||
|
||||
@@ -171,7 +171,7 @@ static const AllowedChannelModesS AllowedChannelModes[] = {
|
||||
};
|
||||
|
||||
#define CMD_HEADER_LEN_ALL 0xffff
|
||||
static const CmdHeaderLengthsS CmdHeaderLengths[] = {
|
||||
static const CmdHeaderLengths_t CmdHeaderLengths[] = {
|
||||
{MFDES_CREATE_APPLICATION, CMD_HEADER_LEN_ALL},
|
||||
{MFDES_DELETE_APPLICATION, CMD_HEADER_LEN_ALL},
|
||||
{MFDES_CHANGE_KEY, 1},
|
||||
@@ -217,7 +217,7 @@ static const uint8_t EV1D40TransmitMAC[] = {
|
||||
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)
|
||||
return true;
|
||||
|
||||
@@ -236,7 +236,7 @@ static const uint8_t D40ReceiveMAC[] = {
|
||||
MFDES_GET_VALUE,
|
||||
};
|
||||
|
||||
static bool DesfireEV1D40ReceiveMAC(DesfireContext *ctx, uint8_t cmd) {
|
||||
static bool DesfireEV1D40ReceiveMAC(DesfireContext_t *ctx, uint8_t cmd) {
|
||||
if (ctx->secureChannel != DACd40)
|
||||
return true;
|
||||
|
||||
@@ -266,7 +266,7 @@ static bool DesfireISOChannelValidCmd(uint8_t cmd) {
|
||||
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};
|
||||
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};
|
||||
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};
|
||||
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};
|
||||
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->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};
|
||||
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};
|
||||
|
||||
// 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++;
|
||||
|
||||
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++;
|
||||
|
||||
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);
|
||||
*dstdatalen = srcdatalen;
|
||||
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) {
|
||||
DesfireISODecode(ctx, srcdata, srcdatalen, dstdata, dstdatalen);
|
||||
return;
|
||||
|
||||
@@ -23,15 +23,15 @@ typedef struct {
|
||||
DesfireSecureChannel secureChannel;
|
||||
DesfireCommandSet cmdSet;
|
||||
DesfireCommunicationMode commMode;
|
||||
} AllowedChannelModesS;
|
||||
} AllowedChannelModes_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t cmd;
|
||||
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 DesfireSecureChannelDecode(DesfireContext *ctx, uint8_t *srcdata, size_t srcdatalen, uint8_t respcode, 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_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);
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ static bool TestCMACSubkeys(void) {
|
||||
|
||||
uint8_t sk1[DESFIRE_MAX_CRYPTO_BLOCK_SIZE] = {0};
|
||||
uint8_t sk2[DESFIRE_MAX_CRYPTO_BLOCK_SIZE] = {0};
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
// AES
|
||||
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};
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
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};
|
||||
@@ -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};
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
DesfireSetKey(&dctx, 0, T_3DES, key);
|
||||
|
||||
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};
|
||||
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
DesfireSetKey(&dctx, 0, T_3K3DES, key);
|
||||
|
||||
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,
|
||||
0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23
|
||||
};
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
DesfireSetKey(&dctx, 0, T_3K3DES, key);
|
||||
memcpy(dctx.sessionKeyMAC, key, DESFIRE_MAX_KEY_SIZE);
|
||||
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,
|
||||
0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01
|
||||
};
|
||||
DesfireContext dctx;
|
||||
DesfireContext_t dctx;
|
||||
DesfireSetKey(&dctx, 0, T_3DES, key);
|
||||
memcpy(dctx.sessionKeyMAC, key, DESFIRE_MAX_KEY_SIZE);
|
||||
uint8_t cmac[DESFIRE_MAX_KEY_SIZE] = {0};
|
||||
@@ -295,7 +295,7 @@ static bool TestCMACDES(void) {
|
||||
bool res = true;
|
||||
|
||||
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);
|
||||
memcpy(dctx.sessionKeyMAC, key, DESFIRE_MAX_KEY_SIZE);
|
||||
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 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;
|
||||
memcpy(ctx.sessionKeyEnc, key, 16);
|
||||
memcpy(ctx.TI, ti, 4);
|
||||
@@ -408,7 +408,7 @@ static bool TestEV2MAC(void) {
|
||||
uint8_t macres[] = {0x68, 0xF2, 0xC2, 0x8C, 0x57, 0x5A, 0x16, 0x28};
|
||||
|
||||
// init
|
||||
DesfireContext ctx = {0};
|
||||
DesfireContext_t ctx = {0};
|
||||
ctx.keyType = T_AES;
|
||||
memcpy(ctx.sessionKeyMAC, key, 16);
|
||||
memcpy(ctx.TI, ti, 4);
|
||||
@@ -484,7 +484,7 @@ static bool TestLRPPlaintexts(void) {
|
||||
bool res = true;
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
|
||||
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) {
|
||||
bool res = true;
|
||||
|
||||
LRPContext ctx = {0};
|
||||
LRPContext_t ctx = {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};
|
||||
@@ -626,7 +626,7 @@ static bool TestLRPEncode(void) {
|
||||
uint8_t resp[100] = {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 iv1[] = {0xC3, 0x31, 0x5D, 0xBF};
|
||||
@@ -694,7 +694,7 @@ static bool TestLRPDecode(void) {
|
||||
uint8_t resp[100] = {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 iv1[] = {0xC3, 0x31, 0x5D, 0xBF};
|
||||
@@ -800,7 +800,7 @@ static bool TestLRPSubkeys(void) {
|
||||
static bool TestLRPCMAC(void) {
|
||||
bool res = true;
|
||||
|
||||
LRPContext ctx = {0};
|
||||
LRPContext_t ctx = {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};
|
||||
|
||||
@@ -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 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);
|
||||
|
||||
ctx->useBitPadding = false;
|
||||
@@ -44,7 +44,7 @@ void LRPClearContext(LRPContext *ctx) {
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
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
|
||||
// Algorithm 1
|
||||
void LRPGeneratePlaintexts(LRPContext *ctx, size_t plaintextsCount) {
|
||||
void LRPGeneratePlaintexts(LRPContext_t *ctx, size_t plaintextsCount) {
|
||||
if (plaintextsCount > LRP_MAX_PLAINTEXTS_SIZE)
|
||||
return;
|
||||
|
||||
@@ -89,7 +89,7 @@ void LRPGeneratePlaintexts(LRPContext *ctx, size_t plaintextsCount) {
|
||||
|
||||
// https://www.nxp.com/docs/en/application-note/AN12304.pdf
|
||||
// Algorithm 2
|
||||
void LRPGenerateUpdatedKeys(LRPContext *ctx, size_t updatedKeysCount) {
|
||||
void LRPGenerateUpdatedKeys(LRPContext_t *ctx, size_t updatedKeysCount) {
|
||||
if (updatedKeysCount > LRP_MAX_UPDATED_KEYS_SIZE)
|
||||
return;
|
||||
|
||||
@@ -106,7 +106,7 @@ void LRPGenerateUpdatedKeys(LRPContext *ctx, size_t updatedKeysCount) {
|
||||
|
||||
// https://www.nxp.com/docs/en/application-note/AN12304.pdf
|
||||
// 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};
|
||||
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
|
||||
// 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;
|
||||
|
||||
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
|
||||
// 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;
|
||||
if (datalen % CRYPTO_AES128_KEY_SIZE)
|
||||
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) {
|
||||
LRPContext ctx = {0};
|
||||
LRPContext_t ctx = {0};
|
||||
|
||||
LRPSetKeyEx(&ctx, key, iv, 4 * 2, 1, true);
|
||||
if (encode)
|
||||
@@ -225,7 +225,7 @@ static void mulPolyX(uint8_t *data) {
|
||||
}
|
||||
|
||||
void LRPGenSubkeys(uint8_t *key, uint8_t *sk1, uint8_t *sk2) {
|
||||
LRPContext ctx = {0};
|
||||
LRPContext_t ctx = {0};
|
||||
LRPSetKey(&ctx, key, 0, true);
|
||||
|
||||
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
|
||||
// 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 sk2[CRYPTO_AES128_KEY_SIZE] = {0};
|
||||
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);
|
||||
}
|
||||
|
||||
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};
|
||||
memset(cmac, 0x00, 8);
|
||||
|
||||
|
||||
@@ -42,21 +42,21 @@ typedef struct {
|
||||
|
||||
uint8_t counter[LRP_MAX_COUNTER_SIZE];
|
||||
size_t counterLenNibbles; // len in bytes * 2 (or * 2 - 1)
|
||||
} LRPContext;
|
||||
} LRPContext_t;
|
||||
|
||||
void LRPClearContext(LRPContext *ctx);
|
||||
void LRPSetKey(LRPContext *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 LRPSetCounter(LRPContext *ctx, uint8_t *counter, size_t counterLenNibbles);
|
||||
void LRPGeneratePlaintexts(LRPContext *ctx, size_t plaintextsCount);
|
||||
void LRPGenerateUpdatedKeys(LRPContext *ctx, size_t updatedKeysCount);
|
||||
void LRPEvalLRP(LRPContext *ctx, uint8_t *iv, size_t ivlen, bool final, uint8_t *y);
|
||||
void LRPClearContext(LRPContext_t *ctx);
|
||||
void LRPSetKey(LRPContext_t *ctx, uint8_t *key, 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_t *ctx, uint8_t *counter, size_t counterLenNibbles);
|
||||
void LRPGeneratePlaintexts(LRPContext_t *ctx, size_t plaintextsCount);
|
||||
void LRPGenerateUpdatedKeys(LRPContext_t *ctx, size_t updatedKeysCount);
|
||||
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 LRPEncode(LRPContext *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 LRPEncode(LRPContext_t *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 LRPGenSubkeys(uint8_t *key, uint8_t *sk1, uint8_t *sk2);
|
||||
void LRPCMAC(LRPContext *ctx, uint8_t *data, size_t datalen, uint8_t *cmac);
|
||||
void LRPCMAC8(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_t *ctx, uint8_t *data, size_t datalen, uint8_t *cmac);
|
||||
|
||||
#endif // __LRPCRYPTO_H
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user