This commit is contained in:
iceman1001 2020-01-12 17:28:12 +01:00
commit ed67936892
11 changed files with 177 additions and 177 deletions

View file

@ -930,7 +930,7 @@ static void PacketReceived(PacketCommandNG *packet) {
#ifdef WITH_HITAG #ifdef WITH_HITAG
case CMD_LF_HITAG_SNIFF: { // Eavesdrop Hitag tag, args = type case CMD_LF_HITAG_SNIFF: { // Eavesdrop Hitag tag, args = type
SniffHitag(); SniffHitag();
// SniffHitag(packet->oldarg[0]); // SniffHitag(packet->oldarg[0]);
break; break;
} }

View file

@ -141,16 +141,16 @@ void FpgaSetupSsc(void) {
// Now set up the SSC proper, starting from a known state. // Now set up the SSC proper, starting from a known state.
AT91C_BASE_SSC->SSC_CR = AT91C_SSC_SWRST; AT91C_BASE_SSC->SSC_CR = AT91C_SSC_SWRST;
// RX clock comes from TX clock, RX starts on Transmit Start, // RX clock comes from TX clock, RX starts on Transmit Start,
// data and frame signal is sampled on falling edge of RK // data and frame signal is sampled on falling edge of RK
AT91C_BASE_SSC->SSC_RCMR = SSC_CLOCK_MODE_SELECT(1) | SSC_CLOCK_MODE_START(1); AT91C_BASE_SSC->SSC_RCMR = SSC_CLOCK_MODE_SELECT(1) | SSC_CLOCK_MODE_START(1);
// 8 bits per transfer, no loopback, MSB first, 1 transfer per sync // 8 bits per transfer, no loopback, MSB first, 1 transfer per sync
// pulse, no output sync // pulse, no output sync
AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(8) | AT91C_SSC_MSBF | SSC_FRAME_MODE_WORDS_PER_TRANSFER(0); AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(8) | AT91C_SSC_MSBF | SSC_FRAME_MODE_WORDS_PER_TRANSFER(0);
// TX clock comes from TK pin, no clock output, outputs change on falling // TX clock comes from TK pin, no clock output, outputs change on falling
// edge of TK, frame sync is sampled on rising edge of TK, start TX on rising edge of TF // edge of TK, frame sync is sampled on rising edge of TK, start TX on rising edge of TF
AT91C_BASE_SSC->SSC_TCMR = SSC_CLOCK_MODE_SELECT(2) | SSC_CLOCK_MODE_START(5); AT91C_BASE_SSC->SSC_TCMR = SSC_CLOCK_MODE_SELECT(2) | SSC_CLOCK_MODE_START(5);
// tx framing is the same as the rx framing // tx framing is the same as the rx framing
@ -461,11 +461,11 @@ void FpgaWriteConfWord(uint16_t v) {
// enable/disable FPGA internal tracing // enable/disable FPGA internal tracing
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void FpgaEnableTracing(void) { void FpgaEnableTracing(void) {
FpgaSendCommand(FPGA_CMD_TRACE_ENABLE, 1); FpgaSendCommand(FPGA_CMD_TRACE_ENABLE, 1);
} }
void FpgaDisableTracing(void) { void FpgaDisableTracing(void) {
FpgaSendCommand(FPGA_CMD_TRACE_ENABLE, 0); FpgaSendCommand(FPGA_CMD_TRACE_ENABLE, 0);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -91,40 +91,40 @@ void HfSniff(int samplesToSkip, int triggersToSkip) {
} }
void HfPlotDownload(void) { void HfPlotDownload(void) {
uint8_t *buf = ToSend; uint8_t *buf = ToSend;
uint8_t *this_buf = buf; uint8_t *this_buf = buf;
FpgaDownloadAndGo(FPGA_BITSTREAM_HF); FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
FpgaSetupSsc(); FpgaSetupSsc();
AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS; // Disable DMA Transfer AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS; // Disable DMA Transfer
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) this_buf; // start transfer to this memory address AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) this_buf; // start transfer to this memory address
AT91C_BASE_PDC_SSC->PDC_RCR = PM3_CMD_DATA_SIZE; // transfer this many samples AT91C_BASE_PDC_SSC->PDC_RCR = PM3_CMD_DATA_SIZE; // transfer this many samples
buf[0] = (uint8_t)AT91C_BASE_SSC->SSC_RHR; // clear receive register buf[0] = (uint8_t)AT91C_BASE_SSC->SSC_RHR; // clear receive register
AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTEN; // Start DMA transfer AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTEN; // Start DMA transfer
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_GET_TRACE); // let FPGA transfer its internal Block-RAM FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_GET_TRACE); // let FPGA transfer its internal Block-RAM
LED_B_ON(); LED_B_ON();
for(size_t i = 0; i < FPGA_TRACE_SIZE; i += PM3_CMD_DATA_SIZE) { for (size_t i = 0; i < FPGA_TRACE_SIZE; i += PM3_CMD_DATA_SIZE) {
// prepare next DMA transfer: // prepare next DMA transfer:
uint8_t *next_buf = buf + ((i + PM3_CMD_DATA_SIZE) % (2 * PM3_CMD_DATA_SIZE)); uint8_t *next_buf = buf + ((i + PM3_CMD_DATA_SIZE) % (2 * PM3_CMD_DATA_SIZE));
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t)next_buf; AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t)next_buf;
AT91C_BASE_PDC_SSC->PDC_RNCR = PM3_CMD_DATA_SIZE; AT91C_BASE_PDC_SSC->PDC_RNCR = PM3_CMD_DATA_SIZE;
size_t len = MIN(FPGA_TRACE_SIZE - i, PM3_CMD_DATA_SIZE); size_t len = MIN(FPGA_TRACE_SIZE - i, PM3_CMD_DATA_SIZE);
while (!(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_ENDRX))) {}; // wait for DMA transfer to complete while (!(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_ENDRX))) {}; // wait for DMA transfer to complete
reply_old(CMD_FPGAMEM_DOWNLOADED, i, len, FPGA_TRACE_SIZE, this_buf, len); reply_old(CMD_FPGAMEM_DOWNLOADED, i, len, FPGA_TRACE_SIZE, this_buf, len);
this_buf = next_buf; this_buf = next_buf;
} }
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
// Trigger a finish downloading signal with an ACK frame // Trigger a finish downloading signal with an ACK frame
reply_mix(CMD_ACK, 1, 0, FPGA_TRACE_SIZE, 0, 0); reply_mix(CMD_ACK, 1, 0, FPGA_TRACE_SIZE, 0, 0);
LED_B_OFF(); LED_B_OFF();
} }

View file

@ -3421,7 +3421,7 @@ TRexBool trex_searchrange(TRex *exp, const TRexChar *text_begin, const TRexChar
if (!cur) if (!cur)
break; break;
node = exp->_nodes[node].next; node = exp->_nodes[node].next;
} }
text_begin++; text_begin++;
} while (cur == NULL && text_begin != text_end); } while (cur == NULL && text_begin != text_end);
@ -3675,7 +3675,7 @@ void arg_register_error(struct arg_end *end,
* Return index of first table entry with a matching short option * Return index of first table entry with a matching short option
* or -1 if no match was found. * or -1 if no match was found.
*/ */
static int find_shortoption(struct arg_hdr** table, char shortopt) { static int find_shortoption(struct arg_hdr **table, char shortopt) {
int tabindex; int tabindex;
for (tabindex = 0; !(table[tabindex]->flag & ARG_TERMINATOR); tabindex++) { for (tabindex = 0; !(table[tabindex]->flag & ARG_TERMINATOR); tabindex++) {
if (table[tabindex]->shortopts && if (table[tabindex]->shortopts &&
@ -3708,7 +3708,7 @@ void dump_longoptions(struct longoptions *longoptions) {
} }
#endif #endif
static struct longoptions* alloc_longoptions(struct arg_hdr** table) { static struct longoptions *alloc_longoptions(struct arg_hdr **table) {
struct longoptions *result; struct longoptions *result;
size_t nbytes; size_t nbytes;
int noptions = 1; int noptions = 1;
@ -3790,7 +3790,7 @@ static struct longoptions* alloc_longoptions(struct arg_hdr** table) {
return result; return result;
} }
static char* alloc_shortoptions(struct arg_hdr** table) { static char *alloc_shortoptions(struct arg_hdr **table) {
char *result; char *result;
size_t len = 2; size_t len = 2;
int tabindex; int tabindex;
@ -3830,7 +3830,7 @@ static char* alloc_shortoptions(struct arg_hdr** table) {
/* return index of the table terminator entry */ /* return index of the table terminator entry */
static int arg_endindex(struct arg_hdr** table) { static int arg_endindex(struct arg_hdr **table) {
int tabindex = 0; int tabindex = 0;
while (!(table[tabindex]->flag & ARG_TERMINATOR)) while (!(table[tabindex]->flag & ARG_TERMINATOR))
tabindex++; tabindex++;
@ -3839,9 +3839,9 @@ static int arg_endindex(struct arg_hdr** table) {
static void arg_parse_tagged(int argc, static void arg_parse_tagged(int argc,
char **argv, char **argv,
struct arg_hdr **table, struct arg_hdr **table,
struct arg_end *endtable) { struct arg_end *endtable) {
struct longoptions *longoptions; struct longoptions *longoptions;
char *shortoptions; char *shortoptions;
int copt; int copt;
@ -3952,9 +3952,9 @@ static void arg_parse_tagged(int argc,
static void arg_parse_untagged(int argc, static void arg_parse_untagged(int argc,
char **argv, char **argv,
struct arg_hdr **table, struct arg_hdr **table,
struct arg_end *endtable) { struct arg_end *endtable) {
int tabindex = 0; int tabindex = 0;
int errorlast = 0; int errorlast = 0;
const char *optarglast = NULL; const char *optarglast = NULL;
@ -4154,11 +4154,11 @@ static void arg_cat(char **pdest, const char *src, size_t *pndest) {
static void arg_cat_option(char *dest, static void arg_cat_option(char *dest,
size_t ndest, size_t ndest,
const char *shortopts, const char *shortopts,
const char *longopts, const char *longopts,
const char *datatype, const char *datatype,
int optvalue) { int optvalue) {
if (shortopts) { if (shortopts) {
char option[3]; char option[3];
@ -4212,12 +4212,12 @@ static void arg_cat_option(char *dest,
} }
static void arg_cat_optionv(char *dest, static void arg_cat_optionv(char *dest,
size_t ndest, size_t ndest,
const char *shortopts, const char *shortopts,
const char *longopts, const char *longopts,
const char *datatype, const char *datatype,
int optvalue, int optvalue,
const char *separator) { const char *separator) {
separator = separator ? separator : ""; separator = separator ? separator : "";
if (shortopts) { if (shortopts) {

View file

@ -230,17 +230,17 @@ int CmdHFSniff(const char *Cmd) {
} }
int CmdHFPlot(const char *Cmd) { int CmdHFPlot(const char *Cmd) {
CLIParserInit("hf plot", CLIParserInit("hf plot",
"Plots HF signal after RF signal path and A/D conversion.", "Plots HF signal after RF signal path and A/D conversion.",
"This can be used after any hf command and will show the last few milliseconds of the HF signal.\n" "This can be used after any hf command and will show the last few milliseconds of the HF signal.\n"
"Note: If the last hf command terminated because of a timeout you will most probably see nothing.\n"); "Note: If the last hf command terminated because of a timeout you will most probably see nothing.\n");
void* argtable[] = { void *argtable[] = {
arg_param_begin, arg_param_begin,
arg_param_end arg_param_end
}; };
CLIExecWithReturn(Cmd, argtable, true); CLIExecWithReturn(Cmd, argtable, true);
uint8_t buf[FPGA_TRACE_SIZE]; uint8_t buf[FPGA_TRACE_SIZE];
PacketResponseNG response; PacketResponseNG response;
if (!GetFromDevice(FPGA_MEM, buf, FPGA_TRACE_SIZE, 0, NULL, 0, &response, 4000, true)) { if (!GetFromDevice(FPGA_MEM, buf, FPGA_TRACE_SIZE, 0, NULL, 0, &response, 4000, true)) {
@ -262,7 +262,7 @@ int CmdHFPlot(const char *Cmd) {
setClockGrid(0, 0); setClockGrid(0, 0);
DemodBufferLen = 0; DemodBufferLen = 0;
RepaintGraphWindow(); RepaintGraphWindow();
return PM3_SUCCESS; return PM3_SUCCESS;
} }
static command_t CommandTable[] = { static command_t CommandTable[] = {

View file

@ -2469,12 +2469,12 @@ static int CmdHF14AMfUGenDiverseKeys(const char *Cmd) {
PrintAndLogEx(WARNING, "iso14443a card select failed"); PrintAndLogEx(WARNING, "iso14443a card select failed");
return PM3_ESOFT; return PM3_ESOFT;
} }
/* /*
if (card.uidlen != 4) { if (card.uidlen != 4) {
PrintAndLogEx(WARNING, "Wrong sized UID, expected 4bytes got %d", card.uidlen); PrintAndLogEx(WARNING, "Wrong sized UID, expected 4bytes got %d", card.uidlen);
return PM3_ESOFT; return PM3_ESOFT;
} }
*/ */
memcpy(uid, card.uid, card.uidlen); memcpy(uid, card.uid, card.uidlen);
} else { } else {
if (param_gethex(Cmd, 0, uid, 8)) return usage_hf_mfu_gendiverse(); if (param_gethex(Cmd, 0, uid, 8)) return usage_hf_mfu_gendiverse();

View file

@ -474,13 +474,13 @@ int CmdLFConfig(const char *Cmd) {
} }
sample_config config = { sample_config config = {
.decimation = -1, .decimation = -1,
.bits_per_sample = -1, .bits_per_sample = -1,
.averaging = -1, .averaging = -1,
.divisor = -1, .divisor = -1,
.trigger_threshold = -1, .trigger_threshold = -1,
.samples_to_skip = -1, .samples_to_skip = -1,
.verbose = true .verbose = true
}; };
bool errors = false; bool errors = false;

View file

@ -73,14 +73,14 @@ static int usage_lf_indala_sim(void) {
static void encodeHeden2L(uint8_t *dest, uint32_t cardnumber) { static void encodeHeden2L(uint8_t *dest, uint32_t cardnumber) {
uint8_t template[] = { uint8_t template[] = {
1,0,1,0,0,0,0,0, 1, 0, 1, 0, 0, 0, 0, 0,
0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,
0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,
0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,
1,0,0,0,1,0,0,0, 1, 0, 0, 0, 1, 0, 0, 0,
1,0,0,0,0,0,0,0, 1, 0, 0, 0, 0, 0, 0, 0,
0,0,0,0,1,0,0,1, 0, 0, 0, 0, 1, 0, 0, 1,
0,0,0,0,0,0,1,0 0, 0, 0, 0, 0, 0, 1, 0
}; };
uint8_t cardbits[32]; uint8_t cardbits[32];
@ -105,14 +105,14 @@ static void encodeHeden2L(uint8_t *dest, uint32_t cardnumber) {
// Parity // Parity
uint8_t counter = 0; uint8_t counter = 0;
for (int i=0; i< sizeof(template) - HEDEN2L_OFFSET; i++) { for (int i = 0; i < sizeof(template) - HEDEN2L_OFFSET; i++) {
if (template[i]) if (template[i])
counter++; counter++;
} }
template[63] = (counter & 0x1); template[63] = (counter & 0x1);
for (int i = 0; i< sizeof(template); i += 8) { for (int i = 0; i < sizeof(template); i += 8) {
dest[i/8] = bytebits_to_byte(template + i, 8); dest[i / 8] = bytebits_to_byte(template + i, 8);
} }
PrintAndLogEx(INFO, "Heden-2L card number %u", cardnumber); PrintAndLogEx(INFO, "Heden-2L card number %u", cardnumber);
@ -123,22 +123,22 @@ static void decodeHeden2L(uint8_t *bits) {
uint32_t cardnumber = 0; uint32_t cardnumber = 0;
uint8_t offset = HEDEN2L_OFFSET; uint8_t offset = HEDEN2L_OFFSET;
if ( bits[offset + 8] ) cardnumber += 1; if (bits[offset + 8]) cardnumber += 1;
if ( bits[offset + 10] ) cardnumber += 2; if (bits[offset + 10]) cardnumber += 2;
if ( bits[offset + 14] ) cardnumber += 4; if (bits[offset + 14]) cardnumber += 4;
if ( bits[offset + 15] ) cardnumber += 8; if (bits[offset + 15]) cardnumber += 8;
if ( bits[offset + 12] ) cardnumber += 16; if (bits[offset + 12]) cardnumber += 16;
if ( bits[offset + 28] ) cardnumber += 32; if (bits[offset + 28]) cardnumber += 32;
if ( bits[offset + 3] ) cardnumber += 64; if (bits[offset + 3]) cardnumber += 64;
if ( bits[offset + 11] ) cardnumber += 128; if (bits[offset + 11]) cardnumber += 128;
if ( bits[offset + 19] ) cardnumber += 256; if (bits[offset + 19]) cardnumber += 256;
if ( bits[offset + 26] ) cardnumber += 512; if (bits[offset + 26]) cardnumber += 512;
if ( bits[offset + 17] ) cardnumber += 1024; if (bits[offset + 17]) cardnumber += 1024;
if ( bits[offset + 18] ) cardnumber += 2048; if (bits[offset + 18]) cardnumber += 2048;
if ( bits[offset + 20] ) cardnumber += 4096; if (bits[offset + 20]) cardnumber += 4096;
if ( bits[offset + 13] ) cardnumber += 8192; if (bits[offset + 13]) cardnumber += 8192;
if ( bits[offset + 7] ) cardnumber += 16384; if (bits[offset + 7]) cardnumber += 16384;
if ( bits[offset + 23] ) cardnumber += 32768; if (bits[offset + 23]) cardnumber += 32768;
PrintAndLogEx(SUCCESS, "\tHeden-2L | %u", cardnumber); PrintAndLogEx(SUCCESS, "\tHeden-2L | %u", cardnumber);
} }

View file

@ -128,8 +128,8 @@ static int CmdKeriClone(const char *Cmd) {
T55x7_MODULATION_PSK1 | T55x7_MODULATION_PSK1 |
T55x7_PSKCF_RF_2 | T55x7_PSKCF_RF_2 |
2 << T55x7_MAXBLOCK_SHIFT, 2 << T55x7_MAXBLOCK_SHIFT,
0, 0,
0 0
}; };
// dynamic bitrate used // dynamic bitrate used

View file

@ -36,13 +36,13 @@
//------------------------------------ //------------------------------------
static void transform_D(uint8_t *ru) { static void transform_D(uint8_t *ru) {
const uint32_t c_D[] = { const uint32_t c_D[] = {
0x6D835AFC, 0x7D15CD97, 0x0942B409, 0x32F9C923, 0xA811FB02, 0x64F121E8, 0x6D835AFC, 0x7D15CD97, 0x0942B409, 0x32F9C923, 0xA811FB02, 0x64F121E8,
0xD1CC8B4E, 0xE8873E6F, 0x61399BBB, 0xF1B91926, 0xAC661520, 0xA21A31C9, 0xD1CC8B4E, 0xE8873E6F, 0x61399BBB, 0xF1B91926, 0xAC661520, 0xA21A31C9,
0xD424808D, 0xFE118E07, 0xD18E728D, 0xABAC9E17, 0x18066433, 0x00E18E79, 0xD424808D, 0xFE118E07, 0xD18E728D, 0xABAC9E17, 0x18066433, 0x00E18E79,
0x65A77305, 0x5AE9E297, 0x11FC628C, 0x7BB3431F, 0x942A8308, 0xB2F8FD20, 0x65A77305, 0x5AE9E297, 0x11FC628C, 0x7BB3431F, 0x942A8308, 0xB2F8FD20,
0x5728B869, 0x30726D5A 0x5728B869, 0x30726D5A
}; };
//Transform //Transform
uint8_t i; uint8_t i;
@ -197,9 +197,9 @@ int mfc_algo_ving_one(uint8_t *uid, uint8_t sector, uint8_t keytype, uint64_t *k
int mfc_algo_ving_all(uint8_t *uid, uint8_t *keys) { int mfc_algo_ving_all(uint8_t *uid, uint8_t *keys) {
if (keys == NULL) return PM3_EINVARG; if (keys == NULL) return PM3_EINVARG;
for (int keytype = 0; keytype < 2; keytype++) { for (int keytype = 0; keytype < 2; keytype++) {
for (int sector = 0; sector < 16; sector++){ for (int sector = 0; sector < 16; sector++) {
uint64_t key = 0; uint64_t key = 0;
mfc_algo_ving_one(uid, sector, keytype, &key ); mfc_algo_ving_one(uid, sector, keytype, &key);
num_to_bytes(key, 6, keys + (keytype * 16 * 6) + (sector * 6)); num_to_bytes(key, 6, keys + (keytype * 16 * 6) + (sector * 6));
} }
} }
@ -216,9 +216,9 @@ int mfc_algo_yale_one(uint8_t *uid, uint8_t sector, uint8_t keytype, uint64_t *k
int mfc_algo_yale_all(uint8_t *uid, uint8_t *keys) { int mfc_algo_yale_all(uint8_t *uid, uint8_t *keys) {
if (keys == NULL) return PM3_EINVARG; if (keys == NULL) return PM3_EINVARG;
for (int keytype = 0; keytype < 2; keytype++) { for (int keytype = 0; keytype < 2; keytype++) {
for (int sector = 0; sector < 16; sector++){ for (int sector = 0; sector < 16; sector++) {
uint64_t key = 0; uint64_t key = 0;
mfc_algo_yale_one(uid, sector, keytype, &key ); mfc_algo_yale_one(uid, sector, keytype, &key);
num_to_bytes(key, 6, keys + (keytype * 16 * 6) + (sector * 6)); num_to_bytes(key, 6, keys + (keytype * 16 * 6) + (sector * 6));
} }
} }
@ -236,9 +236,9 @@ int mfc_algo_saflok_all(uint8_t *uid, uint8_t *keys) {
if (keys == NULL) return PM3_EINVARG; if (keys == NULL) return PM3_EINVARG;
for (int keytype = 0; keytype < 2; keytype++) { for (int keytype = 0; keytype < 2; keytype++) {
for (int sector = 0; sector < 16; sector++){ for (int sector = 0; sector < 16; sector++) {
uint64_t key = 0; uint64_t key = 0;
mfc_algo_saflok_one(uid, sector, keytype, &key ); mfc_algo_saflok_one(uid, sector, keytype, &key);
num_to_bytes(key, 6, keys + (keytype * 16 * 6) + (sector * 6)); num_to_bytes(key, 6, keys + (keytype * 16 * 6) + (sector * 6));
} }
} }
@ -253,15 +253,15 @@ int mfc_algo_mizip_one(uint8_t *uid, uint8_t sector, uint8_t keytype, uint64_t *
if (sector == 0) { if (sector == 0) {
// A // A
if (keytype == 0) if (keytype == 0)
*key = 0xA0A1A2A3A4A5U; *key = 0xA0A1A2A3A4A5U;
else // B else // B
*key = 0xB4C132439eef; *key = 0xB4C132439eef;
} else { } else {
uint8_t xor[6]; uint8_t xor[6];
if ( keytype == 0 ) { if (keytype == 0) {
uint64_t xor_tbl_a[] = { uint64_t xor_tbl_a[] = {
0x09125a2589e5, 0x09125a2589e5,
@ -273,7 +273,7 @@ int mfc_algo_mizip_one(uint8_t *uid, uint8_t sector, uint8_t keytype, uint64_t *
num_to_bytes(xor_tbl_a[sector - 1], 6, xor); num_to_bytes(xor_tbl_a[sector - 1], 6, xor);
*key = *key =
(uint64_t)(uid[0] ^ xor[0] ) << 40 | (uint64_t)(uid[0] ^ xor[0]) << 40 |
(uint64_t)(uid[1] ^ xor[1]) << 32 | (uint64_t)(uid[1] ^ xor[1]) << 32 |
(uint64_t)(uid[2] ^ xor[2]) << 24 | (uint64_t)(uid[2] ^ xor[2]) << 24 |
(uint64_t)(uid[3] ^ xor[3]) << 16 | (uint64_t)(uid[3] ^ xor[3]) << 16 |
@ -311,11 +311,11 @@ int mfc_algo_mizip_all(uint8_t *uid, uint8_t *keys) {
if (keys == NULL) return PM3_EINVARG; if (keys == NULL) return PM3_EINVARG;
for (int keytype = 0; keytype < 2; keytype++) { for (int keytype = 0; keytype < 2; keytype++) {
for (int sector = 0; sector < 5; sector++){ for (int sector = 0; sector < 5; sector++) {
uint64_t key = 0; uint64_t key = 0;
mfc_algo_mizip_one(uid, sector, keytype, &key); mfc_algo_mizip_one(uid, sector, keytype, &key);
num_to_bytes(key, 6, keys + (keytype * 5 * 6) + (sector * 6)); num_to_bytes(key, 6, keys + (keytype * 5 * 6) + (sector * 6));
} }
} }
return PM3_SUCCESS; return PM3_SUCCESS;
} }
@ -337,20 +337,20 @@ int mfc_algo_di_one(uint8_t *uid, uint8_t sector, uint8_t keytype, uint64_t *key
mbedtls_sha1(input, sizeof(input), hash); mbedtls_sha1(input, sizeof(input), hash);
*key = ( *key = (
(uint64_t)hash[3] << 40 | (uint64_t)hash[3] << 40 |
(uint64_t)hash[2] << 32 | (uint64_t)hash[2] << 32 |
(uint64_t)hash[1] << 24 | (uint64_t)hash[1] << 24 |
(uint64_t)hash[0] << 16 | (uint64_t)hash[0] << 16 |
(uint64_t)hash[7] << 8 | (uint64_t)hash[7] << 8 |
hash[6] hash[6]
); );
return PM3_SUCCESS; return PM3_SUCCESS;
} }
int mfc_algo_di_all(uint8_t *uid, uint8_t *keys) { int mfc_algo_di_all(uint8_t *uid, uint8_t *keys) {
if (keys == NULL) return PM3_EINVARG; if (keys == NULL) return PM3_EINVARG;
for (int keytype = 0; keytype < 2; keytype++) { for (int keytype = 0; keytype < 2; keytype++) {
for (int sector = 0; sector < 5; sector++){ for (int sector = 0; sector < 5; sector++) {
uint64_t key = 0; uint64_t key = 0;
mfc_algo_di_one(uid, sector, keytype, &key); mfc_algo_di_one(uid, sector, keytype, &key);
num_to_bytes(key, 6, keys + (keytype * 5 * 6) + (sector * 6)); num_to_bytes(key, 6, keys + (keytype * 5 * 6) + (sector * 6));
@ -361,10 +361,10 @@ int mfc_algo_di_all(uint8_t *uid, uint8_t *keys) {
// Skylanders // Skylanders
static uint64_t sky_crc64_like(uint64_t result, uint8_t sector) { static uint64_t sky_crc64_like(uint64_t result, uint8_t sector) {
#define SKY_POLY UINT64_C(0x42f0e1eba9ea3693) #define SKY_POLY UINT64_C(0x42f0e1eba9ea3693)
#define SKY_TOP UINT64_C(0x800000000000) #define SKY_TOP UINT64_C(0x800000000000)
result ^= (uint64_t)sector << 40; result ^= (uint64_t)sector << 40;
for(int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
result = (result & SKY_TOP) ? (result << 1) ^ SKY_POLY : result << 1; result = (result & SKY_TOP) ? (result << 1) ^ SKY_POLY : result << 1;
} }
return result; return result;
@ -387,7 +387,7 @@ int mfc_algo_sky_one(uint8_t *uid, uint8_t sector, uint8_t keytype, uint64_t *ke
// hash UID // hash UID
uint64_t hash = 0x9AE903260CC4; uint64_t hash = 0x9AE903260CC4;
for(int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
hash = sky_crc64_like(hash, uid[i]); hash = sky_crc64_like(hash, uid[i]);
} }
@ -398,7 +398,7 @@ int mfc_algo_sky_one(uint8_t *uid, uint8_t sector, uint8_t keytype, uint64_t *ke
int mfc_algo_sky_all(uint8_t *uid, uint8_t *keys) { int mfc_algo_sky_all(uint8_t *uid, uint8_t *keys) {
if (keys == NULL) return PM3_EINVARG; if (keys == NULL) return PM3_EINVARG;
for (int keytype = 0; keytype < 2; keytype++) { for (int keytype = 0; keytype < 2; keytype++) {
for (int sector = 0; sector < 16; sector++){ for (int sector = 0; sector < 16; sector++) {
uint64_t key = 0; uint64_t key = 0;
mfc_algo_sky_one(uid, sector, keytype, &key); mfc_algo_sky_one(uid, sector, keytype, &key);
num_to_bytes(key, 6, keys + (keytype * 16 * 6) + (sector * 6)); num_to_bytes(key, 6, keys + (keytype * 16 * 6) + (sector * 6));

View file

@ -106,14 +106,14 @@
static const int Iso15693FrameSOF[] = { static const int Iso15693FrameSOF[] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1 1, 1, 1, 1
}; };
static const int Iso15693Logic0[] = { static const int Iso15693Logic0[] = {
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
@ -122,10 +122,10 @@ static const int Iso15693Logic0[] = {
}; };
static const int Iso15693Logic1[] = { static const int Iso15693Logic1[] = {
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1 1, 1, 1, 1
}; };
// EOF defined as // EOF defined as
// 1) logic '0' (8 pulses of 423.75kHz followed by unmodulated for 18.88us) // 1) logic '0' (8 pulses of 423.75kHz followed by unmodulated for 18.88us)