Reduce some var scopes

This commit is contained in:
Philippe Teuwen 2019-06-07 18:41:39 +02:00
parent ac6b0ec1ce
commit 732bc766f9
52 changed files with 318 additions and 409 deletions

View file

@ -223,7 +223,6 @@ void RunMod() {
*/
bool printKeys = false; // Prints keys
bool transferToEml = true; // Transfer keys to emulator memory
bool ecfill = true; // Fill emulator memory with cards content.
bool simulation = true; // Simulates an exact copy of the target tag
bool fillFromEmulator = false; // Dump emulator memory.
@ -236,7 +235,6 @@ void RunMod() {
uint64_t key64; // Defines current key
uint8_t *keyBlock; // Where the keys will be held in memory.
uint8_t stKeyBlock = 20; // Set the quantity of keys in the block.
int filled; // Used to check if the memory was filled with success.
bool keyFound = false;
/*
@ -368,7 +366,7 @@ void RunMod() {
}
Dbprintf("\t✓ Found keys have been transferred to the emulator memory.");
if (ecfill) {
int filled;
Dbprintf("\tFilling in with key A.");
filled = MifareECardLoad(sectorsCnt, 0);
if (filled != PM3_SUCCESS) {

View file

@ -160,13 +160,14 @@ void RunMod() {
Bytes 5-7 are reserved SAK and ATQA for mifare classic
-Use mfCSetBlock(0, block0, oldUID, wantWipe, MAGIC_SINGLE) to write it
*/
uint8_t oldBlock0[16] = {0}, newBlock0[16] = {0}, testBlock0[16] = {0};
uint8_t oldBlock0[16] = {0}, newBlock0[16] = {0};
// arg0 = Flags, arg1=blockNo
MifareCGetBlock(params, 0, oldBlock0);
if (oldBlock0[0] == 0 && oldBlock0[0] == oldBlock0[1] && oldBlock0[1] == oldBlock0[2] && oldBlock0[2] == oldBlock0[3]) {
Dbprintf("No changeable tag detected. Returning to replay mode for bank[%d]", selected);
playing = 1;
} else {
uint8_t testBlock0[16] = {0};
Dbprintf("UID from target tag: %02X%02X%02X%02X", oldBlock0[0], oldBlock0[1], oldBlock0[2], oldBlock0[3]);
memcpy(newBlock0 + 5, oldBlock0 + 5, 11);

View file

@ -1465,7 +1465,6 @@ static void PacketReceived(PacketCommandNG *packet) {
case CMD_DOWNLOAD_EML_BIGBUF: {
LED_B_ON();
uint8_t *mem = BigBuf_get_EM_addr();
size_t len = 0;
uint32_t startidx = packet->oldarg[0];
uint32_t numofbytes = packet->oldarg[1];
@ -1474,7 +1473,7 @@ static void PacketReceived(PacketCommandNG *packet) {
// arg2 = RFU
for (size_t i = 0; i < numofbytes; i += PM3_CMD_DATA_SIZE) {
len = MIN((numofbytes - i), PM3_CMD_DATA_SIZE);
size_t len = MIN((numofbytes - i), PM3_CMD_DATA_SIZE);
int result = reply_old(CMD_DOWNLOADED_EML_BIGBUF, i, len, 0, mem + startidx + i, len);
if (result != PM3_SUCCESS)
Dbprintf("transfer to client failed :: | bytes between %d - %d (%d) | result: %d", i, i + len, len, result);

View file

@ -208,9 +208,9 @@ void permute(const uint8_t *ptable, const uint8_t *in, uint8_t *out) {
ob = ptable[1];
ptable = &(ptable[2]);
for (byte = 0; byte < ob; ++byte) {
uint8_t x, t = 0;
uint8_t t = 0;
for (bit = 0; bit < 8; ++bit) {
x = *ptable++ - 1;
uint8_t x = *ptable++ - 1;
t <<= 1;
if ((in[x / 8]) & (0x80 >> (x % 8))) {
t |= 0x01;

View file

@ -288,7 +288,6 @@ void *mifare_cryto_preprocess_data(desfiretag_t tag, void *data, size_t *nbytes,
void *mifare_cryto_postprocess_data(desfiretag_t tag, void *data, size_t *nbytes, int communication_settings) {
void *res = data;
size_t edl;
void *edata = NULL;
uint8_t first_cmac_byte = 0x00;
@ -322,7 +321,7 @@ void *mifare_cryto_postprocess_data(desfiretag_t tag, void *data, size_t *nbytes
break;
}
edl = enciphered_data_length(tag, *nbytes - 1, communication_settings);
size_t edl = enciphered_data_length(tag, *nbytes - 1, communication_settings);
edata = malloc(edl);
memcpy(edata, data, *nbytes - 1);

View file

@ -496,19 +496,17 @@ void EPA_PACE_Replay(PacketCommandNG *c) {
// Returns 0 on success or a non-zero error code on failure
//-----------------------------------------------------------------------------
int EPA_Setup() {
int return_code = 0;
uint8_t uid[10];
uint8_t pps_response[3];
uint8_t pps_response_par[1];
iso14a_card_select_t card_a_info;
iso14b_card_select_t card_b_info;
// first, look for type A cards
// power up the field
iso14443a_setup(FPGA_HF_ISO14443A_READER_MOD);
// select the card
return_code = iso14443a_select_card(uid, &card_a_info, NULL, true, 0, false);
int return_code = iso14443a_select_card(uid, &card_a_info, NULL, true, 0, false);
if (return_code == 1) {
uint8_t pps_response[3];
uint8_t pps_response_par[1];
// send the PPS request
ReaderTransmit((uint8_t *)pps, sizeof(pps), NULL);
return_code = ReaderReceive(pps_response, pps_response_par);
@ -523,6 +521,7 @@ int EPA_Setup() {
// if we're here, there is no type A card, so we look for type B
// power up the field
iso14443b_setup();
iso14b_card_select_t card_b_info;
// select the card
return_code = iso14443b_select_card(&card_b_info);
if (return_code == 0) {

View file

@ -1366,9 +1366,7 @@ void WriterHitag(hitag_function htf, hitag_data *htd, int page) {
uint8_t *tx = txbuf;
size_t txlen = 0;
int lastbit;
bool bSkip;
int reset_sof;
int tag_sof;
int t_wait = HITAG_T_WAIT_MAX;
bool bStop;
@ -1515,8 +1513,8 @@ void WriterHitag(hitag_function htf, hitag_data *htd, int page) {
memset(rx, 0x00, sizeof(rx));
rxlen = 0;
lastbit = 1;
bSkip = true;
tag_sof = reset_sof;
bool bSkip = true;
int tag_sof = reset_sof;
response = 0;
uint32_t errorCount = 0;

View file

@ -295,8 +295,6 @@ static int check_select(uint8_t *rx, uint32_t uid) {
static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen,
uint8_t *tx, size_t *txlen) {
uint8_t rx_air[HITAG_FRAME_LEN];
uint8_t page;
int i;
uint64_t state;
unsigned char crc;
@ -330,7 +328,7 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen,
}
//send uid as a response
*txlen = 32;
for (i = 0; i < 4; i++)
for (int i = 0; i < 4; i++)
tx[i] = (tag.uid >> (24 - (i * 8))) & 0xff;
}
break;
@ -357,13 +355,13 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen,
}
//send configuration
for (i = 0; i < 4; i++)
for (int i = 0; i < 4; i++)
tx[i] = (tag.pages[0][1] >> (i * 8)) & 0xff;
tx[3] = 0xff;
if (tag.mode != HT_STANDARD) {
*txlen = 40;
crc = CRC_PRESET;
for (i = 0; i < 4; i++)
for (int i = 0; i < 4; i++)
calc_crc(&crc, tx[i], 8);
tx[4] = crc;
}
@ -399,7 +397,7 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen,
break;
}
for (i = 0; i < 4; i++)
for (int i = 0; i < 4; i++)
_hitag2_byte(&state);
//send con2, pwdh0, pwdl0, pwdl1 encrypted as a response
@ -490,7 +488,7 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen,
//write page, write block, read page or read block command received
if ((rx[0] & 0xf0) == 0xc0) { //read page
//send page data
page = ((rx[0] & 0x0f) * 16) + ((rx[1] & 0xf0) / 16);
uint8_t page = ((rx[0] & 0x0f) * 16) + ((rx[1] & 0xf0) / 16);
*txlen = 32;
tx[0] = (tag.pages[page / 4][page % 4]) & 0xff;
tx[1] = (tag.pages[page / 4][page % 4] >> 8) & 0xff;
@ -520,7 +518,7 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen,
//add crc8
*txlen = 40;
crc = CRC_PRESET;
for (i = 0; i < 4; i++)
for (int i = 0; i < 4; i++)
calc_crc(&crc, tx[i], 8);
tx[4] = crc;
}
@ -531,10 +529,10 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen,
*txlen = 0;
}
} else if ((rx[0] & 0xf0) == 0xd0) { //read block
page = ((rx[0] & 0x0f) * 16) + ((rx[1] & 0xf0) / 16);
uint8_t page = ((rx[0] & 0x0f) * 16) + ((rx[1] & 0xf0) / 16);
*txlen = 32 * 4;
//send page,...,page+3 data
for (i = 0; i < 4; i++) {
for (int i = 0; i < 4; i++) {
tx[0 + i * 4] = (tag.pages[page / 4][page % 4]) & 0xff;
tx[1 + i * 4] = (tag.pages[page / 4][page % 4] >> 8) & 0xff;
tx[2 + i * 4] = (tag.pages[page / 4][page % 4] >> 16) & 0xff;
@ -563,7 +561,7 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen,
//add crc8
*txlen = 32 * 4 + 8;
crc = CRC_PRESET;
for (i = 0; i < 16; i++)
for (int i = 0; i < 16; i++)
calc_crc(&crc, tx[i], 8);
tx[16] = crc;
}
@ -573,7 +571,7 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen,
*txlen = 0;
}
} else if ((rx[0] & 0xf0) == 0x80) { //write page
page = ((rx[0] & 0x0f) * 16) + ((rx[1] & 0xf0) / 16);
uint8_t page = ((rx[0] & 0x0f) * 16) + ((rx[1] & 0xf0) / 16);
switch (tag.mode) {
case HT_STANDARD:
@ -604,7 +602,7 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen,
}
} else if ((rx[0] & 0xf0) == 0x90) { //write block
page = ((rx[0] & 0x0f) * 6) + ((rx[1] & 0xf0) / 16);
uint8_t page = ((rx[0] & 0x0f) * 6) + ((rx[1] & 0xf0) / 16);
switch (tag.mode) {
case HT_STANDARD:
sof_bits = 1;
@ -647,10 +645,8 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen,
static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrAr, uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen) {
uint8_t rx_air[HITAG_FRAME_LEN];
int response_bit[200];
int i, j, z;
unsigned char mask = 1;
unsigned char uid[32];
uint8_t uid1, uid2, uid3, uid4;
unsigned char crc;
uint64_t state;
uint8_t auth_ks[4];
@ -664,9 +660,9 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
Dbprintf("authentication failed!");
return -1;
}
z = 0;
for (i = 0; i < 10; i++) {
for (j = 0; j < 8; j++) {
int z = 0;
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 8; j++) {
response_bit[z] = 0;
if ((rx[i] & ((mask << 7) >> j)) != 0)
response_bit[z] = 1;
@ -674,13 +670,13 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
}
}
uint16_t k = 0;
for (i = 5; i < z; i += 2) {
for (int i = 5; i < z; i += 2) {
uid[k] = response_bit[i];
k++;
if (k > 31)
break;
}
uid1 = (uid[0] << 7)
uint8_t uid1 = (uid[0] << 7)
| (uid[1] << 6)
| (uid[2] << 5)
| (uid[3] << 4)
@ -689,7 +685,7 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
| (uid[6] << 1)
| uid[7];
uid2 = (uid[8] << 7)
uint8_t uid2 = (uid[8] << 7)
| (uid[9] << 6)
| (uid[10] << 5)
| (uid[11] << 4)
@ -698,7 +694,7 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
| (uid[14] << 1)
| uid[15];
uid3 = (uid[16] << 7)
uint8_t uid3 = (uid[16] << 7)
| (uid[17] << 6)
| (uid[18] << 5)
| (uid[19] << 4)
@ -707,7 +703,7 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
| (uid[22] << 1)
| uid[23];
uid4 = (uid[24] << 7)
uint8_t uid4 = (uid[24] << 7)
| (uid[25] << 6)
| (uid[26] << 5)
| (uid[27] << 4)
@ -730,19 +726,19 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
calc_crc(&crc, uid3, 8);
calc_crc(&crc, uid4, 8);
for (i = 0; i < 100; i++) {
for (int i = 0; i < 100; i++) {
response_bit[i] = 0;
}
for (i = 0; i < 5; i++) {
for (int i = 0; i < 5; i++) {
response_bit[i] = 0;
}
for (i = 5; i < 37; i++) {
int i = 5;
for (; i < 37; i++) {
response_bit[i] = uid[i - 5];
}
for (j = 0; j < 8; j++) {
for (int j = 0; j < 8; j++) {
response_bit[i] = 0;
if ((crc & ((mask << 7) >> j)) != 0)
response_bit[i] = 1;
@ -750,7 +746,7 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
}
k = 0;
for (i = 0; i < 6; i++) {
for (int i = 0; i < 6; i++) {
tx[i] = (response_bit[k] << 7)
| (response_bit[k + 1] << 6)
| (response_bit[k + 2] << 5)
@ -766,9 +762,9 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
tag.pstate = HT_INIT;
} else if (tag.pstate == HT_INIT && rxlen == 44) {
// received configuration after select command
z = 0;
for (i = 0; i < 6; i++) {
for (j = 0; j < 8; j++) {
int z = 0;
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 8; j++) {
response_bit[z] = 0;
if ((rx[i] & ((mask << 7) >> j)) != 0)
response_bit[z] = 1;
@ -819,7 +815,7 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
if (htf == 02 || htf == 04) { //RHTS_KEY //WHTS_KEY
state = _hitag2_init(REV64(key), REV32(tag.uid), REV32(rnd));
for (i = 0; i < 4; i++) {
for (int i = 0; i < 4; i++) {
auth_ks[i] = _hitag2_byte(&state) ^ 0xff;
}
*txlen = 64;
@ -836,7 +832,7 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
Dbprintf("%02X %02X %02X %02X %02X %02X %02X %02X", tx[0],
tx[1], tx[2], tx[3], tx[4], tx[5], tx[6], tx[7]);
} else if (htf == 01 || htf == 03) { //RHTS_CHALLENGE //WHTS_CHALLENGE
for (i = 0; i < 8; i++)
for (int i = 0; i < 8; i++)
tx[i] = ((NrAr >> (56 - (i * 8))) & 0xff);
}
end = true;
@ -869,7 +865,7 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
if (htf == 02 || htf == 04) { //RHTS_KEY //WHTS_KEY
{
state = _hitag2_init(REV64(key), REV32(tag.uid), REV32(rnd));
for (i = 0; i < 5; i++)
for (int i = 0; i < 5; i++)
_hitag2_byte(&state);
pwdh0 = ((rx[1] & 0x0f) * 16 + ((rx[2] & 0xf0) / 16)) ^ _hitag2_byte(&state);
@ -1133,9 +1129,7 @@ void ReadHitagS(hitag_function htf, hitag_data *htd) {
uint8_t *tx = txbuf;
size_t txlen = 0;
int lastbit = 1;
bool bSkip;
int reset_sof = 1;
int tag_sof;
int t_wait = HITAG_T_WAIT_MAX;
bool bStop = false;
int sendNum = 0;
@ -1369,8 +1363,8 @@ void ReadHitagS(hitag_function htf, hitag_data *htd) {
memset(rx, 0x00, sizeof(rx));
rxlen = 0;
lastbit = 1;
bSkip = true;
tag_sof = reset_sof;
bool bSkip = true;
int tag_sof = reset_sof;
response = 0;
// Receive frame, watch for at most T0*EOF periods
@ -1462,9 +1456,7 @@ void WritePageHitagS(hitag_function htf, hitag_data *htd, int page) {
uint8_t *tx = txbuf;
size_t txlen = 0;
int lastbit;
bool bSkip;
int reset_sof;
int tag_sof;
int t_wait = HITAG_T_WAIT_MAX;
bool bStop;
unsigned char crc;
@ -1659,8 +1651,8 @@ void WritePageHitagS(hitag_function htf, hitag_data *htd, int page) {
memset(rx, 0x00, sizeof(rx));
rxlen = 0;
lastbit = 1;
bSkip = true;
tag_sof = reset_sof;
bool bSkip = true;
int tag_sof = reset_sof;
response = 0;
uint32_t errorCount = 0;
@ -1754,12 +1746,11 @@ void check_challenges(bool file_given, uint8_t *data) {
uint8_t rx[HITAG_FRAME_LEN];
uint8_t unlocker[60][8];
int u1 = 0;
size_t rxlen = 0, txlen = 0;
size_t rxlen = 0;
uint8_t txbuf[HITAG_FRAME_LEN];
uint8_t *tx;
int t_wait = HITAG_T_WAIT_MAX;
int lastbit, reset_sof, tag_sof, STATE = 0;;
bool bSkip, bStop;
int lastbit, reset_sof, STATE = 0;;
bool bStop;
int response_bit[200];
unsigned char mask = 1;
unsigned char uid[32];
@ -1837,8 +1828,8 @@ void check_challenges(bool file_given, uint8_t *data) {
LogTrace(rx, nbytes(rxlen), response, 0, NULL, false);
}
tx = txbuf;
txlen = 0;
uint8_t *tx = txbuf;
size_t txlen = 0;
if (rxlen == 0) {
if (STATE == 2)
// challenge failed
@ -1968,8 +1959,8 @@ void check_challenges(bool file_given, uint8_t *data) {
memset(rx, 0x00, sizeof(rx));
rxlen = 0;
lastbit = 1;
bSkip = true;
tag_sof = reset_sof;
bool bSkip = true;
int tag_sof = reset_sof;
response = 0;
// Receive frame, watch for at most T0*EOF periods

View file

@ -1093,7 +1093,6 @@ void SimulateIso14443aTag(uint8_t tagType, uint8_t flags, uint8_t *data) {
#define ORDER_EV1_COMP_WRITE 40
#define ORDER_RATS 70
int order = ORDER_NONE;
int lastorder;
int retval = PM3_SUCCESS;
@ -1101,7 +1100,6 @@ void SimulateIso14443aTag(uint8_t tagType, uint8_t flags, uint8_t *data) {
int happened = 0;
int happened2 = 0;
int cmdsRecvd = 0;
tag_response_info_t *p_response;
// compatible write block number
uint8_t wrblock = 0;
@ -1118,10 +1116,10 @@ void SimulateIso14443aTag(uint8_t tagType, uint8_t flags, uint8_t *data) {
retval = PM3_EOPABORTED;
break;
}
p_response = NULL;
tag_response_info_t *p_response = NULL;
// Okay, look at the command now.
lastorder = order;
int lastorder = order;
//
// we need to check "ordered" states before, because received data may be same to any command - is wrong!!!
@ -1527,17 +1525,16 @@ void PrepareDelayedTransfer(uint16_t delay) {
delay &= 0x07;
if (!delay) return;
uint8_t bitmask = 0, bits_to_shift;
uint8_t bitmask = 0;
uint8_t bits_shifted = 0;
uint16_t i = 0;
for (i = 0; i < delay; i++)
for (uint16_t i = 0; i < delay; i++)
bitmask |= (0x01 << i);
ToSend[ToSendMax++] = 0x00;
for (i = 0; i < ToSendMax; i++) {
bits_to_shift = ToSend[i] & bitmask;
for (uint16_t i = 0; i < ToSendMax; i++) {
uint8_t bits_to_shift = ToSend[i] & bitmask;
ToSend[i] = ToSend[i] >> delay;
ToSend[i] = ToSend[i] | (bits_shifted << (8 - delay));
bits_shifted = bits_to_shift;
@ -1600,9 +1597,7 @@ static void TransmitFor14443a(const uint8_t *cmd, uint16_t len, uint32_t *timing
// Prepare reader command (in bits, support short frames) to send to FPGA
//-----------------------------------------------------------------------------
void CodeIso14443aBitsAsReaderPar(const uint8_t *cmd, uint16_t bits, const uint8_t *par) {
int i, j;
int last = 0;
uint8_t b;
ToSendReset();
@ -1612,11 +1607,11 @@ void CodeIso14443aBitsAsReaderPar(const uint8_t *cmd, uint16_t bits, const uint8
size_t bytecount = nbytes(bits);
// Generate send structure for the data bits
for (i = 0; i < bytecount; i++) {
for (int i = 0; i < bytecount; i++) {
// Get the current byte to send
b = cmd[i];
uint8_t b = cmd[i];
size_t bitsleft = MIN((bits - (i * 8)), 8);
int j;
for (j = 0; j < bitsleft; j++) {
if (b & 1) {
// Sequence X
@ -2078,25 +2073,22 @@ void iso14443a_antifuzz(uint32_t flags) {
static void iso14a_set_ATS_times(uint8_t *ats) {
uint8_t tb1;
uint8_t fwi, sfgi;
uint32_t fwt, sfgt;
if (ats[0] > 1) { // there is a format byte T0
if ((ats[1] & 0x20) == 0x20) { // there is an interface byte TB(1)
uint8_t tb1;
if ((ats[1] & 0x10) == 0x10) { // there is an interface byte TA(1) preceding TB(1)
tb1 = ats[3];
} else {
tb1 = ats[2];
}
fwi = (tb1 & 0xf0) >> 4; // frame waiting time integer (FWI)
uint8_t fwi = (tb1 & 0xf0) >> 4; // frame waiting time integer (FWI)
if (fwi != 15) {
fwt = 256 * 16 * (1 << fwi); // frame waiting time (FWT) in 1/fc
uint32_t fwt = 256 * 16 * (1 << fwi); // frame waiting time (FWT) in 1/fc
iso14a_set_timeout(fwt / (8 * 16));
}
sfgi = tb1 & 0x0f; // startup frame guard time integer (SFGI)
uint8_t sfgi = tb1 & 0x0f; // startup frame guard time integer (SFGI)
if (sfgi != 0 && sfgi != 15) {
sfgt = 256 * 16 * (1 << sfgi); // startup frame guard time (SFGT) in 1/fc
uint32_t sfgt = 256 * 16 * (1 << sfgi); // startup frame guard time (SFGT) in 1/fc
NextTransferTime = MAX(NextTransferTime, Demod.endTime + (sfgt - DELAY_AIR2ARM_AS_READER - DELAY_ARM2AIR_AS_READER) / 16);
}
}
@ -2144,7 +2136,6 @@ int iso14443a_select_card(uint8_t *uid_ptr, iso14a_card_select_t *p_card, uint32
uint8_t sak = 0x04; // cascade uid
int cascade_level = 0;
int len;
if (p_card) {
p_card->uidlen = 0;
@ -2271,7 +2262,7 @@ int iso14443a_select_card(uint8_t *uid_ptr, iso14a_card_select_t *p_card, uint32
AddCrc14A(rats, 2);
ReaderTransmit(rats, sizeof(rats), NULL);
len = ReaderReceive(resp, resp_par);
int len = ReaderReceive(resp, resp_par);
if (!len) return 0;
@ -2639,7 +2630,6 @@ void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype) {
uint16_t sync_tries = 0;
bool have_uid = false;
bool received_nack;
uint8_t cascade_levels = 0;
// static variables here, is re-used in the next call
@ -2667,7 +2657,7 @@ void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype) {
uint16_t i;
for (i = 0; true; ++i) {
received_nack = false;
bool received_nack = false;
WDT_HIT();
@ -2893,7 +2883,6 @@ void DetectNACKbug() {
uint16_t sync_tries = 0;
uint32_t sync_time = 0;
bool have_uid = false;
bool received_nack;
int32_t status = PM3_SUCCESS;
@ -2912,7 +2901,7 @@ void DetectNACKbug() {
uint16_t i;
for (i = 1; true; ++i) {
received_nack = false;
bool received_nack = false;
// Cards always leaks a NACK, no matter the parity
if ((i == 10) && (num_nacks == i - 1)) {

View file

@ -237,9 +237,6 @@ static void CodeIso14443bAsTag(const uint8_t *cmd, int len) {
*
*/
int i, j;
uint8_t b;
ToSendReset();
// Transmit a burst of ones, as the initial thing that lets the
@ -252,23 +249,23 @@ static void CodeIso14443bAsTag(const uint8_t *cmd, int len) {
// Send SOF.
// 10-11 ETU * 4times samples ZEROS
for (i = 0; i < 10; i++) { SEND4STUFFBIT(0); }
for (int i = 0; i < 10; i++) { SEND4STUFFBIT(0); }
//for(i = 0; i < 10; i++) { ToSendStuffBit(0); }
// 2-3 ETU * 4times samples ONES
for (i = 0; i < 3; i++) { SEND4STUFFBIT(1); }
for (int i = 0; i < 3; i++) { SEND4STUFFBIT(1); }
//for(i = 0; i < 3; i++) { ToSendStuffBit(1); }
// data
for (i = 0; i < len; ++i) {
for (int i = 0; i < len; ++i) {
// Start bit
SEND4STUFFBIT(0);
//ToSendStuffBit(0);
// Data bits
b = cmd[i];
for (j = 0; j < 8; ++j) {
uint8_t b = cmd[i];
for (int j = 0; j < 8; ++j) {
// if(b & 1) {
// SEND4STUFFBIT(1);
// //ToSendStuffBit(1);
@ -292,11 +289,11 @@ static void CodeIso14443bAsTag(const uint8_t *cmd, int len) {
// Send EOF.
// 10-11 ETU * 4 sample rate = ZEROS
for (i = 0; i < 10; i++) { SEND4STUFFBIT(0); }
for (int i = 0; i < 10; i++) { SEND4STUFFBIT(0); }
//for(i = 0; i < 10; i++) { ToSendStuffBit(0); }
// why this?
for (i = 0; i < 40; i++) { SEND4STUFFBIT(1); }
for (int i = 0; i < 40; i++) { SEND4STUFFBIT(1); }
//for(i = 0; i < 40; i++) { ToSendStuffBit(1); }
// Convert from last byte pos to length
@ -945,7 +942,7 @@ static RAMFUNC int Handle14443bTagSamplesDemod(int ci, int cq) {
* quiet: set to 'TRUE' to disable debug output
*/
static void GetTagSamplesFor14443bDemod() {
bool gotFrame, finished = false;
bool finished = false;
// int lastRxCounter = ISO14443B_DMA_BUFFER_SIZE;
uint32_t time_0 = 0, time_stop = 0;
@ -991,7 +988,7 @@ static void GetTagSamplesFor14443bDemod() {
}
// https://github.com/Proxmark/proxmark3/issues/103
gotFrame = Handle14443bTagSamplesDemod(ci, cq);
bool gotFrame = Handle14443bTagSamplesDemod(ci, cq);
time_stop = GetCountSspClk() - time_0;
finished = (time_stop > iso14b_timeout || gotFrame);
@ -1058,14 +1055,12 @@ static void CodeIso14443bAsReader(const uint8_t *cmd, int len) {
* QUESTION: how long is a 1 or 0 in pulses in the xcorr_848 mode?
* 1 "stuffbit" = 1ETU (9us)
*/
int i;
uint8_t b;
ToSendReset();
// Send SOF
// 10-11 ETUs of ZERO
for (i = 0; i < 10; ++i) ToSendStuffBit(0);
for (int i = 0; i < 10; ++i) ToSendStuffBit(0);
// 2-3 ETUs of ONE
ToSendStuffBit(1);
@ -1074,11 +1069,11 @@ static void CodeIso14443bAsReader(const uint8_t *cmd, int len) {
// Sending cmd, LSB
// from here we add BITS
for (i = 0; i < len; ++i) {
for (int i = 0; i < len; ++i) {
// Start bit
ToSendStuffBit(0);
// Data bits
b = cmd[i];
uint8_t b = cmd[i];
// if ( b & 1 ) ToSendStuffBit(1); else ToSendStuffBit(0);
// if ( (b>>1) & 1) ToSendStuffBit(1); else ToSendStuffBit(0);
// if ( (b>>2) & 1) ToSendStuffBit(1); else ToSendStuffBit(0);
@ -1108,13 +1103,13 @@ static void CodeIso14443bAsReader(const uint8_t *cmd, int len) {
// Send EOF
// 10-11 ETUs of ZERO
for (i = 0; i < 10; ++i) ToSendStuffBit(0);
for (int i = 0; i < 10; ++i) ToSendStuffBit(0);
// Transition time. TR0 - guard time
// 8ETUS minum?
// Per specification, Subcarrier must be stopped no later than 2 ETUs after EOF.
// I'm guessing this is for the FPGA to be able to send all bits before we switch to listening mode
for (i = 0; i < 24 ; ++i) ToSendStuffBit(1);
for (int i = 0; i < 24 ; ++i) ToSendStuffBit(1);
// TR1 - Synchronization time
// Convert from last character reference to length
@ -1462,7 +1457,6 @@ static void iso1444b_setup_sniff(void) {
void RAMFUNC SniffIso14443b(void) {
uint32_t time_0 = 0, time_start = 0, time_stop;
int ci, cq;
// We won't start recording the frames that we acquire until we trigger;
// a good trigger condition to get started is probably when we see a
@ -1490,8 +1484,8 @@ void RAMFUNC SniffIso14443b(void) {
while (!BUTTON_PRESS()) {
WDT_HIT();
ci = data[0];
cq = data[1];
int ci = data[0];
int cq = data[1];
data += 2;
if (data >= dmaBuf + ISO14443B_DMA_BUFFER_SIZE) {

View file

@ -736,9 +736,9 @@ int SendDataTag(uint8_t *send, int sendlen, bool init, int speed, uint8_t *outda
// Decodes a message from a tag and displays its metadata and content
#define DBD15STATLEN 48
void DbdecodeIso15693Answer(int len, uint8_t *d) {
char status[DBD15STATLEN + 1] = {0};
if (len > 3) {
char status[DBD15STATLEN + 1] = {0};
if (d[0] & (1 << 3))
strncat(status, "ProtExt ", DBD15STATLEN - strlen(status));
if (d[0] & 1) {
@ -802,9 +802,6 @@ void DbdecodeIso15693Answer(int len, uint8_t *d) {
void ReaderIso15693(uint32_t parameter) {
int answerLen1 = 0;
int tsamples = 0, wait = 0, elapsed = 0;
uint8_t uid[8] = {0, 0, 0, 0, 0, 0, 0, 0};
// set up device/fpga
Iso15693InitReader();
@ -829,6 +826,7 @@ void ReaderIso15693(uint32_t parameter) {
// we should do a better check than this
if (answerLen1 >= 12) {
uint8_t uid[8];
uid[0] = answer1[9]; // always E0
uid[1] = answer1[8]; // IC Manufacturer code
uid[2] = answer1[7];

View file

@ -1151,24 +1151,20 @@ void CmdAWIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol)
// w = wiegand parity
// (26 bit format shown)
uint32_t fac = 0;
uint32_t cardnum = 0;
uint32_t code1 = 0;
uint32_t code2 = 0;
uint8_t fmtLen = bytebits_to_byte(dest, 8);
if (fmtLen == 26) {
fac = bytebits_to_byte(dest + 9, 8);
cardnum = bytebits_to_byte(dest + 17, 16);
code1 = bytebits_to_byte(dest + 8, fmtLen);
uint32_t fac = bytebits_to_byte(dest + 9, 8);
uint32_t cardnum = bytebits_to_byte(dest + 17, 16);
uint32_t code1 = bytebits_to_byte(dest + 8, fmtLen);
Dbprintf("AWID Found - BitLength: %d, FC: %d, Card: %d - Wiegand: %x, Raw: %08x%08x%08x", fmtLen, fac, cardnum, code1, rawHi2, rawHi, rawLo);
} else {
cardnum = bytebits_to_byte(dest + 8 + (fmtLen - 17), 16);
uint32_t cardnum = bytebits_to_byte(dest + 8 + (fmtLen - 17), 16);
if (fmtLen > 32) {
code1 = bytebits_to_byte(dest + 8, fmtLen - 32);
code2 = bytebits_to_byte(dest + 8 + (fmtLen - 32), 32);
uint32_t code1 = bytebits_to_byte(dest + 8, fmtLen - 32);
uint32_t code2 = bytebits_to_byte(dest + 8 + (fmtLen - 32), 32);
Dbprintf("AWID Found - BitLength: %d -unknown BitLength- (%d) - Wiegand: %x%08x, Raw: %08x%08x%08x", fmtLen, cardnum, code1, code2, rawHi2, rawHi, rawLo);
} else {
code1 = bytebits_to_byte(dest + 8, fmtLen);
uint32_t code1 = bytebits_to_byte(dest + 8, fmtLen);
Dbprintf("AWID Found - BitLength: %d -unknown BitLength- (%d) - Wiegand: %x, Raw: %08x%08x%08x", fmtLen, cardnum, code1, rawHi2, rawHi, rawLo);
}
}
@ -1189,7 +1185,7 @@ void CmdEM410xdemod(int findone, uint32_t *high, uint64_t *low, int ledcontrol)
uint8_t *dest = BigBuf_get_addr();
size_t size, idx = 0;
int clk = 0, invert = 0, errCnt, maxErr = 20;
int clk = 0, invert = 0, maxErr = 20;
uint32_t hi = 0;
uint64_t lo = 0;
@ -1207,7 +1203,7 @@ void CmdEM410xdemod(int findone, uint32_t *high, uint64_t *low, int ledcontrol)
size = BigBuf_max_traceLen();
//askdemod and manchester decode
if (size > 16385) size = 16385; //big enough to catch 2 sequences of largest format
errCnt = askdemod(dest, &size, &clk, &invert, maxErr, 0, 1);
int errCnt = askdemod(dest, &size, &clk, &invert, maxErr, 0, 1);
WDT_HIT();
if (errCnt > 50) continue;

View file

@ -861,11 +861,10 @@ void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain)
ui64Key = bytes_to_num(datain, 6);
// variables
uint16_t rtr, i, j, len;
uint16_t davg = 0;
uint16_t i, j, len;
static uint16_t dmin, dmax;
uint8_t uid[10] = {0x00};
uint32_t cuid = 0, nt1, nt2, nttmp, nttest, ks1;
uint32_t cuid = 0, nt1, nt2, nttest, ks1;
uint8_t par[1] = {0x00};
uint32_t target_nt[2] = {0x00}, target_ks[2] = {0x00};
@ -893,15 +892,16 @@ void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain)
// statistics on nonce distance
int16_t isOK = 0;
#define NESTED_MAX_TRIES 12
uint16_t unsuccessfull_tries = 0;
if (arg2) { // calibrate: for first call only. Otherwise reuse previous calibration
LED_B_ON();
WDT_HIT();
davg = dmax = 0;
uint16_t unsuccessfull_tries = 0;
uint16_t davg = 0;
dmax = 0;
dmin = 2000;
delta_time = 0;
uint16_t rtr;
for (rtr = 0; rtr < 17; rtr++) {
// Test if the action was cancelled
@ -937,7 +937,7 @@ void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain)
continue;
};
nttmp = prng_successor(nt1, 100); //NXP Mifare is typical around 840,but for some unlicensed/compatible mifare card this can be 160
uint32_t nttmp = prng_successor(nt1, 100); //NXP Mifare is typical around 840,but for some unlicensed/compatible mifare card this can be 160
for (i = 101; i < 1200; i++) {
nttmp = prng_successor(nttmp, 1);
if (nttmp == nt2) break;
@ -1653,7 +1653,6 @@ void MifareEMemGet(uint8_t blockno, uint8_t blockcnt) {
//
//-----------------------------------------------------------------------------
int MifareECardLoad(uint32_t arg0, uint32_t arg1) {
uint64_t ui64Key;
uint32_t cuid = 0;
uint8_t numSectors = arg0;
uint8_t keyType = arg1;
@ -1682,7 +1681,7 @@ int MifareECardLoad(uint32_t arg0, uint32_t arg1) {
}
for (uint8_t sectorNo = 0; isOK && sectorNo < numSectors; sectorNo++) {
ui64Key = emlGetKey(sectorNo, keyType);
uint64_t ui64Key = emlGetKey(sectorNo, keyType);
if (sectorNo == 0) {
if (isOK && mifare_classic_auth(pcs, cuid, FirstBlockOfSector(sectorNo), keyType, ui64Key, AUTH_FIRST)) {
if (DBGLEVEL >= 1) Dbprintf("Sector[%2d]. Auth error", sectorNo);
@ -2016,7 +2015,6 @@ void MifareSetMod(uint8_t *datain) {
uint32_t cuid = 0;
struct Crypto1State mpcs = {0, 0};
struct Crypto1State *pcs = &mpcs;
int respLen;
uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE] = {0};
uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE] = {0};
@ -2040,6 +2038,7 @@ void MifareSetMod(uint8_t *datain) {
break;
}
int respLen;
if (((respLen = mifare_sendcmd_short(pcs, 1, 0x43, mod, receivedAnswer, receivedAnswerPar, NULL)) != 1) || (receivedAnswer[0] != 0x0a)) {
if (DBGLEVEL >= 1) Dbprintf("SetMod error; response[0]: %hhX, len: %d", receivedAnswer[0], respLen);
break;

View file

@ -174,22 +174,18 @@ void MifareDES_Auth1(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
int len = 0;
//uint8_t PICC_MASTER_KEY8[8] = { 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47};
uint8_t PICC_MASTER_KEY16[16] = { 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f };
uint8_t null_key_data8[8] = {0x00};
//uint8_t null_key_data16[16] = {0x00};
//uint8_t new_key_data8[8] = { 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77};
//uint8_t new_key_data16[16] = { 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xAA,0xBB,0xCC,0xDD,0xEE,0xFF};
uint8_t resp[256] = {0x00};
uint8_t IV[16] = {0x00};
size_t datalen = datain[0];
uint8_t cmd[40] = {0x00};
uint8_t encRndB[16] = {0x00};
uint8_t decRndB[16] = {0x00};
uint8_t nonce[16] = {0x00};
uint8_t both[32] = {0x00};
uint8_t encBoth[32] = {0x00};
InitDesfireCard();
@ -217,6 +213,7 @@ void MifareDES_Auth1(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
} else {
if (arg1 == 1) {
if (datain[1] == 0xff) {
uint8_t null_key_data8[8] = {0x00};
memcpy(keybytes, null_key_data8, 8);
} else {
memcpy(keybytes, datain + 1, datalen);
@ -437,6 +434,7 @@ void MifareDES_Auth1(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
Desfire_aes_key_new(keybytes, key);
AesCtx ctx;
uint8_t IV[16] = {0x00};
if (AesCtxIni(&ctx, IV, key->data, KEY128, CBC) < 0) {
if (DBGLEVEL >= 4) {
DbpString("AES context failed to init");
@ -461,8 +459,10 @@ void MifareDES_Auth1(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
// dekryptera tagnonce.
AesDecrypt(&ctx, encRndB, decRndB, 16);
rol(decRndB, 16);
uint8_t nonce[16] = {0x00};
memcpy(both, nonce, 16);
memcpy(both + 16, decRndB, 16);
uint8_t encBoth[32] = {0x00};
AesEncrypt(&ctx, both, encBoth, 32);
cmd[0] = ADDITIONAL_FRAME;

View file

@ -309,13 +309,13 @@ bool RAMFUNC MfSniffLogic(const uint8_t *data, uint16_t len, uint8_t *parity, ui
*/
void RAMFUNC MfSniffSend() {
uint16_t chunksize, tracelen = BigBuf_get_traceLen();
uint16_t tracelen = BigBuf_get_traceLen();
int packlen = tracelen; // total number of bytes to send
uint8_t *data = BigBuf_get_addr();
while (packlen > 0) {
LED_B_ON();
chunksize = MIN(PM3_CMD_DATA_SIZE, packlen); // chunk size 512
uint16_t chunksize = MIN(PM3_CMD_DATA_SIZE, packlen); // chunk size 512
reply_old(CMD_ACK, 1, tracelen, chunksize, data + tracelen - packlen, chunksize);
packlen -= chunksize;
LED_B_OFF();

View file

@ -111,9 +111,8 @@ void opt_successor(const uint8_t *k, State *s, bool y, State *successor) {
void opt_suc(const uint8_t *k, State *s, uint8_t *in, uint8_t length, bool add32Zeroes) {
State x2;
int i;
uint8_t head;
for (i = 0; i < length; i++) {
for (int i = 0; i < length; i++) {
uint8_t head;
head = 1 & (in[i] >> 7);
opt_successor(k, s, head, &x2);
@ -141,7 +140,7 @@ void opt_suc(const uint8_t *k, State *s, uint8_t *in, uint8_t length, bool add32
//For tag MAC, an additional 32 zeroes
if (add32Zeroes) {
for (i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
opt_successor(k, s, 0, &x2);
opt_successor(k, &x2, 0, s);
}
@ -149,10 +148,9 @@ void opt_suc(const uint8_t *k, State *s, uint8_t *in, uint8_t length, bool add32
}
void opt_output(const uint8_t *k, State *s, uint8_t *buffer) {
uint8_t bout, times = 0;
State temp = {0, 0, 0, 0};
for (; times < 4; times++) {
bout = 0;
for (uint8_t times = 0; times < 4; times++) {
uint8_t bout = 0;
bout |= (s->r & 0x4) << 5;
opt_successor(k, s, 0, &temp);
bout |= (temp.r & 0x4) << 4;

View file

@ -60,12 +60,10 @@ char const hex2ascii_data[] = "0123456789abcdefghijklmnopqrstuvwxyz";
*/
static char *
ksprintn(char *nbuf, uintmax_t num, int base, int *lenp, int upper) {
char *p, c;
p = nbuf;
char *p = nbuf;
*p = '\0';
do {
c = hex2ascii(num % base);
char c = hex2ascii(num % base);
*++p = upper ? toupper(c) : c;
} while (num /= base);
if (lenp)

View file

@ -80,10 +80,10 @@ char *strcat(char *dest, const char *src) {
/* reverse: reverse string s in place */
void strreverse(char s[]) {
int c, i, j;
int j = strlen(s) - 1;
for (i = 0, j = strlen(s) - 1; i < j; i++, j--) {
c = s[i];
for (int i = 0; i < j; i++, j--) {
int c = s[i];
s[i] = s[j];
s[j] = c;
}

View file

@ -114,7 +114,6 @@ static void Fatal(void) {
void UsbPacketReceived(uint8_t *packet, int len) {
int i, dont_ack = 0;
PacketCommandOLD *c = (PacketCommandOLD *)packet;
volatile uint32_t *p;
//if ( len != sizeof(PacketCommandOLD`)) Fatal();
@ -136,7 +135,7 @@ void UsbPacketReceived(uint8_t *packet, int len) {
/* The temporary write buffer of the embedded flash controller is mapped to the
* whole memory region, only the last 8 bits are decoded.
*/
p = (volatile uint32_t *)&_flash_start;
volatile uint32_t *p = (volatile uint32_t *)&_flash_start;
for (i = 0; i < 12; i++)
p[i + arg0] = c->d.asDwords[i];
}

View file

@ -13,8 +13,6 @@
static int split(char *str, char *arr[MAX_ARGS]) {
int beginIndex = 0;
int endIndex;
int maxWords = MAX_ARGS;
int wordCnt = 0;
while (1) {
@ -24,7 +22,7 @@ static int split(char *str, char *arr[MAX_ARGS]) {
if (str[beginIndex] == '\0') {
break;
}
endIndex = beginIndex;
int endIndex = beginIndex;
while (str[endIndex] && !isspace(str[endIndex])) {
++endIndex;
}
@ -33,7 +31,7 @@ static int split(char *str, char *arr[MAX_ARGS]) {
memcpy(tmp, &str[beginIndex], len);
arr[wordCnt++] = tmp;
beginIndex = endIndex;
if (wordCnt == maxWords)
if (wordCnt == MAX_ARGS)
break;
}
return wordCnt;
@ -45,10 +43,8 @@ int GetModels(char *Models[], int *count, uint8_t *width) {
/* default values */
static model_t model = MZERO;
int ibperhx = 8;//, obperhx = 8;
int rflags = 0, uflags = 0; /* search and UI flags */
poly_t apoly, crc, qpoly = PZERO, *apolys = NULL, *pptr = NULL, *qptr = NULL;
model_t pset = model, *candmods, *mptr;
model_t pset = model;
/* stdin must be binary */
#ifdef _WIN32
@ -81,6 +77,8 @@ int GetModels(char *Models[], int *count, uint8_t *width) {
mfree(&model);
} else { //reveng -s
int ibperhx = 8;//, obperhx = 8;
int rflags = 0, uflags = 0; /* search and UI flags */
if (~model.flags & P_MULXN) {
PrintAndLogEx(WARNING, "cannot search for non-Williams compliant models");
return 0;
@ -108,9 +106,9 @@ int GetModels(char *Models[], int *count, uint8_t *width) {
/* scan against preset models */
if (~uflags & C_NOPCK) {
pass = 0;
int Cnt = 0, psets;
int Cnt = 0;
do {
psets = mcount();
int psets = mcount();
while (psets) {
mbynum(&pset, --psets);
@ -192,7 +190,8 @@ int GetModels(char *Models[], int *count, uint8_t *width) {
pass = 0;
int args = 0;
do {
mptr = candmods = reveng(&model, qpoly, rflags, args, apolys);
model_t *candmods = reveng(&model, qpoly, rflags, args, apolys);
model_t *mptr = candmods;
if (mptr && plen(mptr->spoly)) {
uflags |= C_RESULT;
}
@ -396,7 +395,6 @@ static int CmdrevengSearch(const char *Cmd) {
uint8_t width[NMODELS] = {0};
int count = 0;
uint8_t crcChars;
char result[30];
char revResult[30];
int ans = GetModels(Models, &count, width);
@ -410,7 +408,7 @@ static int CmdrevengSearch(const char *Cmd) {
continue;
}*/
// round up to # of characters in this model's crc
crcChars = ((width[i] + 7) / 8) * 2;
uint8_t crcChars = ((width[i] + 7) / 8) * 2;
// can't test a model that has more crc digits than our data
if (crcChars >= dataLen)
continue;

View file

@ -384,7 +384,6 @@ void printDemodBuff(void) {
}
int CmdPrintDemodBuff(const char *Cmd) {
char hex[512] = {0x00};
bool hexMode = false;
bool errors = false;
uint32_t offset = 0;
@ -425,6 +424,7 @@ int CmdPrintDemodBuff(const char *Cmd) {
if (hexMode) {
char *buf = (char *)(DemodBuffer + offset);
char hex[512] = {0x00};
int numBits = binarraytohex(hex, sizeof(hex), buf, length);
if (numBits == 0) {
return PM3_ESOFT;
@ -745,15 +745,13 @@ int AutoCorrelate(const int *in, int *out, size_t len, size_t window, bool SaveG
//test
double autocv = 0.0; // Autocovariance value
double ac_value; // Computed autocorrelation value to be returned
double variance; // Computed variance
double mean;
size_t correlation = 0;
int lastmax = 0;
// in, len, 4000
mean = compute_mean(in, len);
variance = compute_variance(in, len);
double mean = compute_mean(in, len);
// Computed variance
double variance = compute_variance(in, len);
static int CorrelBuffer[MAX_GRAPH_TRACE_LEN];
@ -766,8 +764,9 @@ int AutoCorrelate(const int *in, int *out, size_t len, size_t window, bool SaveG
CorrelBuffer[i] = autocv;
// Computed autocorrelation value to be returned
// Autocorrelation is autocovariance divided by variance
ac_value = autocv / variance;
double ac_value = autocv / variance;
// keep track of which distance is repeating.
if (ac_value > 1) {

View file

@ -506,9 +506,9 @@ int CmdHF14ASim(const char *Cmd) {
}
int CmdHF14ASniff(const char *Cmd) {
uint8_t param = 0, ctmp;
uint8_t param = 0;
for (uint8_t i = 0; i < 2; i++) {
ctmp = tolower(param_getchar(Cmd, i));
uint8_t ctmp = tolower(param_getchar(Cmd, i));
if (ctmp == 'h') return usage_hf_14a_sniff();
if (ctmp == 'c') param |= 0x01;
if (ctmp == 'r') param |= 0x02;
@ -701,11 +701,10 @@ static int CmdExchangeAPDU(bool chainingin, uint8_t *datain, int datainlen, bool
else
SendCommandMIX(CMD_READER_ISO_14443a, ISO14A_APDU | ISO14A_NO_DISCONNECT | cmdc, 0, 0, NULL, 0);
uint8_t *recv;
PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
recv = resp.data.asBytes;
uint8_t *recv = resp.data.asBytes;
int iLen = resp.oldarg[0];
uint8_t res = resp.oldarg[1];

View file

@ -121,7 +121,6 @@ static int switch_off_field_14b(void) {
static bool waitCmd14b(bool verbose) {
uint8_t data[PM3_CMD_DATA_SIZE] = {0x00};
PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) {
@ -130,6 +129,7 @@ static bool waitCmd14b(bool verbose) {
uint16_t len = (resp.oldarg[1] & 0xFFFF);
uint8_t data[PM3_CMD_DATA_SIZE] = {0x00};
memcpy(data, resp.data.asBytes, len);
if (verbose) {

View file

@ -1160,9 +1160,8 @@ static int CmdHF15Restore(const char *Cmd) {
char newCmdPrefix[FILE_PATH_SIZE + 1] = {0x00}, tmpCmd[FILE_PATH_SIZE + 262] = {0x00};
char param[FILE_PATH_SIZE] = "";
char hex[255] = "";
uint8_t retries = 3, tried = 0, i = 0;
uint8_t retries = 3, i = 0;
int retval = 0;
size_t bytes_read;
while (param_getchar(Cmd, cmdp) != 0x00) {
switch (tolower(param_getchar(Cmd, cmdp))) {
@ -1226,11 +1225,11 @@ static int CmdHF15Restore(const char *Cmd) {
PrintAndLogEx(INFO, "Restoring data blocks.");
while (1) {
tried = 0;
uint8_t tried = 0;
hex[0] = 0x00;
tmpCmd[0] = 0x00;
bytes_read = fread(buff, 1, blocksize, f);
size_t bytes_read = fread(buff, 1, blocksize, f);
if (bytes_read == 0) {
PrintAndLogEx(SUCCESS, "File reading done `%s`", filename);
fclose(f);

View file

@ -308,8 +308,6 @@ static int CmdHFiClassSim(const char *Cmd) {
return usage_hf_iclass_sim();
}
uint8_t numberOfCSNs = 0;
/*
// pre-defined 8 CSN by Holiman
uint8_t csns[8*NUM_CSNS] = {
@ -478,9 +476,8 @@ static int CmdHFiClassSim(const char *Cmd) {
//KEYROLL 2
memset(dump, 0, datalen);
uint8_t resp_index = 0;
for (uint8_t i = 0; i < NUM_CSNS; i++) {
resp_index = (i + NUM_CSNS) * 16;
uint8_t resp_index = (i + NUM_CSNS) * 16;
// Copy CSN
memcpy(dump + i * MAC_ITEM_SIZE, csns + i * 8, 8);
// copy EPURSE
@ -496,6 +493,7 @@ static int CmdHFiClassSim(const char *Cmd) {
case 1:
case 3:
default: {
uint8_t numberOfCSNs = 0;
clearCommandBuffer();
SendCommandOLD(CMD_SIMULATE_TAG_ICLASS, simType, numberOfCSNs, 0, CSN, 8);
break;
@ -1303,7 +1301,6 @@ static int CmdHFiClassCloneTag(const char *Cmd) {
return 0;
}
uint8_t *ptr;
uint8_t data[(endblock - startblock) * 12];
// calculate all mac for every the block we will write
for (i = startblock; i <= endblock; i++) {
@ -1312,7 +1309,7 @@ static int CmdHFiClassCloneTag(const char *Cmd) {
// memcpy(pointer,tag_data[i - 6],8) 8 bytes
// memcpy(pointer + 8,mac,sizoof(mac) 4 bytes;
// next one
ptr = data + (i - startblock) * 12;
uint8_t *ptr = data + (i - startblock) * 12;
memcpy(ptr, &(tag_data[i - startblock].d[0]), 8);
memcpy(ptr + 8, MAC, 4);
}
@ -1335,11 +1332,10 @@ static int CmdHFiClassCloneTag(const char *Cmd) {
}
static int ReadBlock(uint8_t *KEY, uint8_t blockno, uint8_t keyType, bool elite, bool rawkey, bool verbose, bool auth) {
uint8_t MAC[4] = {0x00, 0x00, 0x00, 0x00};
uint8_t div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
// block 0,1 should always be able to read, and block 5 on some cards.
if (auth || blockno >= 2) {
uint8_t MAC[4] = {0x00, 0x00, 0x00, 0x00};
uint8_t div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
if (!select_and_auth(KEY, MAC, div_key, (keyType == 0x18), elite, rawkey, verbose))
return 0;
} else {
@ -1445,8 +1441,8 @@ static int CmdHFiClass_loclass(const char *Cmd) {
if (strlen(Cmd) < 1 || opt == 'h')
usage_hf_iclass_loclass();
char fileName[FILE_PATH_SIZE] = {0};
if (opt == 'f') {
char fileName[FILE_PATH_SIZE] = {0};
if (param_getstr(Cmd, 1, fileName, sizeof(fileName)) > 0) {
return bruteforceFileNoKeys(fileName);
} else {
@ -1551,9 +1547,9 @@ static int CmdHFiClassReadTagFile(const char *Cmd) {
}
void HFiClassCalcDivKey(uint8_t *CSN, uint8_t *KEY, uint8_t *div_key, bool elite) {
uint8_t keytable[128] = {0};
uint8_t key_index[8] = {0};
if (elite) {
uint8_t keytable[128] = {0};
uint8_t key_index[8] = {0};
uint8_t key_sel[8] = { 0 };
uint8_t key_sel_p[8] = { 0 };
hash2(KEY, keytable);
@ -1595,7 +1591,6 @@ static int CmdHFiClassCalcNewKey(const char *Cmd) {
uint8_t NEWKEY[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t xor_div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t CSN[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t CCNR[12] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t keyNbr = 0;
uint8_t dataLen = 0;
char tempStr[50] = {0};
@ -1665,9 +1660,11 @@ static int CmdHFiClassCalcNewKey(const char *Cmd) {
}
if (errors || cmdp < 4) return usage_hf_iclass_calc_newkey();
if (!givenCSN)
if (!givenCSN) {
uint8_t CCNR[12] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
if (!select_only(CSN, CCNR, false, true))
return 0;
}
HFiClassCalcNewKey(CSN, OLDKEY, NEWKEY, xor_div_key, elite, oldElite, true);
return PM3_SUCCESS;
@ -2318,11 +2315,10 @@ static void permute(uint8_t *data, uint8_t len, uint8_t *output) {
PrintAndLogEx(NORMAL, "[!] wrong key size\n");
return;
}
uint8_t i, j, p, mask;
for (i = 0; i < KEY_SIZE; ++i) {
p = 0;
mask = 0x80 >> i;
for (j = 0; j < KEY_SIZE; ++j) {
for (uint8_t i = 0; i < KEY_SIZE; ++i) {
uint8_t p = 0;
uint8_t mask = 0x80 >> i;
for (uint8_t j = 0; j < KEY_SIZE; ++j) {
p >>= 1;
if (data[j] & mask)
p |= 0x80;
@ -2377,8 +2373,6 @@ static void generate(uint8_t *data, uint8_t len) {
static int CmdHFiClassPermuteKey(const char *Cmd) {
uint8_t key[8] = {0};
uint8_t key_std_format[8] = {0};
uint8_t key_iclass_format[8] = {0};
uint8_t data[16] = {0};
bool isReverse = false;
int len = 0;
@ -2396,10 +2390,12 @@ static int CmdHFiClassPermuteKey(const char *Cmd) {
if (isReverse) {
generate_rev(data, len);
uint8_t key_std_format[8] = {0};
permutekey_rev(key, key_std_format);
PrintAndLogEx(SUCCESS, "holiman iclass key | %s \n", sprint_hex(key_std_format, 8));
} else {
generate(data, len);
uint8_t key_iclass_format[8] = {0};
permutekey(key, key_iclass_format);
PrintAndLogEx(SUCCESS, "holiman std key | %s \n", sprint_hex(key_iclass_format, 8));
}

View file

@ -591,10 +591,8 @@ static int CmdHF14AMfRdBl(const char *Cmd) {
}
static int CmdHF14AMfRdSc(const char *Cmd) {
int i;
uint8_t isOK, sectorNo = 0, keyType = 0;
uint8_t sectorNo = 0, keyType = 0;
uint8_t key[6] = {0, 0, 0, 0, 0, 0};
uint8_t *data = NULL;
char cmdp = 0x00;
if (strlen(Cmd) < 3) {
@ -631,12 +629,12 @@ static int CmdHF14AMfRdSc(const char *Cmd) {
PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
isOK = resp.oldarg[0] & 0xff;
data = resp.data.asBytes;
uint8_t isOK = resp.oldarg[0] & 0xff;
uint8_t *data = resp.data.asBytes;
PrintAndLogEx(NORMAL, "isOk:%02x", isOK);
if (isOK) {
for (i = 0; i < (sectorNo < 32 ? 3 : 15); i++) {
for (int i = 0; i < (sectorNo < 32 ? 3 : 15); i++) {
PrintAndLogEx(NORMAL, "data : %s", sprint_hex(data + i * 16, 16));
}
PrintAndLogEx(NORMAL, "trailer: %s", sprint_hex(data + (sectorNo < 32 ? 3 : 15) * 16, 16));
@ -644,7 +642,7 @@ static int CmdHF14AMfRdSc(const char *Cmd) {
PrintAndLogEx(NORMAL, "Trailer decoded:");
int bln = mfFirstBlockOfSector(sectorNo);
int blinc = (mfNumBlocksPerSector(sectorNo) > 4) ? 5 : 1;
for (i = 0; i < 4; i++) {
for (int i = 0; i < 4; i++) {
PrintAndLogEx(NORMAL, "Access block %d%s: %s", bln, ((blinc > 1) && (i < 3) ? "+" : ""), mfGetAccessConditionsDesc(i, &(data + (sectorNo < 32 ? 3 : 15) * 16)[6]));
bln += blinc;
}
@ -1065,9 +1063,7 @@ static int CmdHF14AMfRestore(const char *Cmd) {
}
static int CmdHF14AMfNested(const char *Cmd) {
int i, iterations;
sector_t *e_sector = NULL;
uint8_t blockNo = 0;
uint8_t keyType = 0;
uint8_t trgBlockNo = 0;
uint8_t trgKeyType = 0;
@ -1077,16 +1073,12 @@ static int CmdHF14AMfNested(const char *Cmd) {
uint64_t key64 = 0;
bool transferToEml = false;
bool createDumpFile = false;
FILE *fkeys;
uint8_t standart[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
uint8_t tempkey[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
char *fptr;
if (strlen(Cmd) < 3) return usage_hf14_nested();
char cmdp, ctmp;
cmdp = tolower(param_getchar(Cmd, 0));
blockNo = param_get8(Cmd, 1);
uint8_t blockNo = param_get8(Cmd, 1);
ctmp = tolower(param_getchar(Cmd, 2));
if (ctmp != 'a' && ctmp != 'b') {
@ -1195,10 +1187,10 @@ static int CmdHF14AMfNested(const char *Cmd) {
PrintAndLogEx(SUCCESS, "enter nested attack");
// nested sectors
iterations = 0;
// int iterations = 0;
bool calibrate = true;
for (i = 0; i < MIFARE_SECTOR_RETRY; i++) {
for (int i = 0; i < MIFARE_SECTOR_RETRY; i++) {
for (uint8_t sectorNo = 0; sectorNo < SectorsCnt; ++sectorNo) {
for (trgKeyType = 0; trgKeyType < 2; ++trgKeyType) {
@ -1217,11 +1209,11 @@ static int CmdHF14AMfNested(const char *Cmd) {
break;
case -4 : //key not found
calibrate = false;
iterations++;
// iterations++;
continue;
case -5 :
calibrate = false;
iterations++;
// iterations++;
e_sector[sectorNo].foundKey[trgKeyType] = 1;
e_sector[sectorNo].Key[trgKeyType] = bytes_to_num(keyBlock, 6);
@ -1243,7 +1235,7 @@ static int CmdHF14AMfNested(const char *Cmd) {
// 20160116 If Sector A is found, but not Sector B, try just reading it of the tag?
PrintAndLogEx(INFO, "trying to read key B...");
for (i = 0; i < SectorsCnt; i++) {
for (int i = 0; i < SectorsCnt; i++) {
// KEY A but not KEY B
if (e_sector[i].foundKey[0] && !e_sector[i].foundKey[1]) {
@ -1283,7 +1275,7 @@ static int CmdHF14AMfNested(const char *Cmd) {
if (transferToEml) {
// fast push mode
conn.block_after_ACK = true;
for (i = 0; i < SectorsCnt; i++) {
for (int i = 0; i < SectorsCnt; i++) {
mfEmlGetMem(keyBlock, FirstBlockOfSector(i) + NumBlocksPerSector(i) - 1, 1);
if (e_sector[i].foundKey[0])
@ -1303,12 +1295,12 @@ static int CmdHF14AMfNested(const char *Cmd) {
// Create dump file
if (createDumpFile) {
fptr = GenerateFilename("hf-mf-", "-key.bin");
char *fptr = GenerateFilename("hf-mf-", "-key.bin");
if (fptr == NULL) {
free(e_sector);
return PM3_ESOFT;
}
FILE *fkeys;
if ((fkeys = fopen(fptr, "wb")) == NULL) {
PrintAndLogEx(WARNING, "could not create file " _YELLOW_("%s"), fptr);
free(e_sector);
@ -1316,7 +1308,9 @@ static int CmdHF14AMfNested(const char *Cmd) {
}
PrintAndLogEx(SUCCESS, "saving keys to binary file " _YELLOW_("%s"), fptr);
for (i = 0; i < SectorsCnt; i++) {
uint8_t standart[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
uint8_t tempkey[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
for (int i = 0; i < SectorsCnt; i++) {
if (e_sector[i].foundKey[0]) {
num_to_bytes(e_sector[i].Key[0], 6, tempkey);
fwrite(tempkey, 1, 6, fkeys);
@ -1324,7 +1318,7 @@ static int CmdHF14AMfNested(const char *Cmd) {
fwrite(&standart, 1, 6, fkeys);
}
}
for (i = 0; i < SectorsCnt; i++) {
for (int i = 0; i < SectorsCnt; i++) {
if (e_sector[i].foundKey[1]) {
num_to_bytes(e_sector[i].Key[1], 6, tempkey);
fwrite(tempkey, 1, 6, fkeys);
@ -2756,7 +2750,6 @@ static int CmdHF14AMfEKeyPrn(const char *Cmd) {
int i;
uint8_t numSectors;
uint8_t data[16];
uint64_t keyA, keyB;
char c = tolower(param_getchar(Cmd, 0));
if (c == 'h')
@ -2777,8 +2770,8 @@ static int CmdHF14AMfEKeyPrn(const char *Cmd) {
PrintAndLogEx(WARNING, "error get block %d", FirstBlockOfSector(i) + NumBlocksPerSector(i) - 1);
break;
}
keyA = bytes_to_num(data, 6);
keyB = bytes_to_num(data + 10, 6);
uint64_t keyA = bytes_to_num(data, 6);
uint64_t keyB = bytes_to_num(data + 10, 6);
PrintAndLogEx(NORMAL, "|%03d| %012" PRIx64 " | %012" PRIx64 " |", i, keyA, keyB);
}
PrintAndLogEx(NORMAL, "|---|----------------|----------------|");
@ -2875,9 +2868,7 @@ static int CmdHF14AMfCSetBlk(const char *Cmd) {
static int CmdHF14AMfCLoad(const char *Cmd) {
uint8_t buf8[16] = {0x00};
uint8_t fillFromEmulator = 0;
int blockNum, flags = 0;
bool fillFromJson = false;
bool fillFromBin = false;
char fileName[50] = {0};
@ -2895,7 +2886,9 @@ static int CmdHF14AMfCLoad(const char *Cmd) {
if (fillFromEmulator) {
for (blockNum = 0; blockNum < 16 * 4; blockNum += 1) {
for (int blockNum = 0; blockNum < 16 * 4; blockNum += 1) {
int flags = 0;
uint8_t buf8[16] = {0x00};
if (mfEmlGetMem(buf8, blockNum, 1)) {
PrintAndLogEx(WARNING, "Cant get block: %d", blockNum);
return 2;
@ -2949,7 +2942,8 @@ static int CmdHF14AMfCLoad(const char *Cmd) {
PrintAndLogEx(INFO, "Copying to magic card");
blockNum = 0;
int blockNum = 0;
int flags = 0;
while (datalen) {
// switch on field and send magic sequence
@ -2992,17 +2986,15 @@ static int CmdHF14AMfCLoad(const char *Cmd) {
static int CmdHF14AMfCGetBlk(const char *Cmd) {
uint8_t data[16] = {0};
uint8_t blockNo = 0;
int res;
char ctmp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) < 1 || ctmp == 'h') return usage_hf14_cgetblk();
blockNo = param_get8(Cmd, 0);
uint8_t blockNo = param_get8(Cmd, 0);
PrintAndLogEx(NORMAL, "--block number:%2d ", blockNo);
res = mfCGetBlock(blockNo, data, MAGIC_SINGLE);
int res = mfCGetBlock(blockNo, data, MAGIC_SINGLE);
if (res) {
PrintAndLogEx(WARNING, "Can't read block. error=%d", res);
return PM3_ESOFT;
@ -3028,13 +3020,11 @@ static int CmdHF14AMfCGetBlk(const char *Cmd) {
static int CmdHF14AMfCGetSc(const char *Cmd) {
uint8_t data[16] = {0};
uint8_t sector = 0;
int i, res, flags;
char ctmp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) < 1 || ctmp == 'h') return usage_hf14_cgetsc();
sector = param_get8(Cmd, 0);
uint8_t sector = param_get8(Cmd, 0);
if (sector > 39) {
PrintAndLogEx(WARNING, "Sector number must be less then 40");
return PM3_ESOFT;
@ -3049,13 +3039,13 @@ static int CmdHF14AMfCGetSc(const char *Cmd) {
start = 128 + (sector - 32) * 16;
}
flags = MAGIC_INIT + MAGIC_WUPC;
int flags = MAGIC_INIT + MAGIC_WUPC;
for (i = 0; i < blocks; i++) {
for (int i = 0; i < blocks; i++) {
if (i == 1) flags = 0;
if (i == blocks - 1) flags = MAGIC_HALT + MAGIC_OFF;
res = mfCGetBlock(start + i, data, flags);
int res = mfCGetBlock(start + i, data, flags);
if (res) {
PrintAndLogEx(WARNING, "Can't read block. %d error=%d", start + i, res);
return PM3_ESOFT;
@ -3075,10 +3065,9 @@ static int CmdHF14AMfCSave(const char *Cmd) {
int i, len, flags;
uint8_t numblocks = 0, cmdp = 0;
uint16_t bytes = 0;
char ctmp;
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
ctmp = tolower(param_getchar(Cmd, cmdp));
char ctmp = tolower(param_getchar(Cmd, cmdp));
switch (ctmp) {
case 'e':
useuid = true;

View file

@ -1038,12 +1038,7 @@ static void estimate_sum_a8(void) {
static int read_nonce_file(char *filename) {
FILE *fnonces = NULL;
char progress_text[80] = "";
size_t bytes_read;
uint8_t trgBlockNo;
uint8_t trgKeyType;
uint8_t read_buf[9];
uint32_t nt_enc1, nt_enc2;
uint8_t par_enc;
num_acquired_nonces = 0;
if ((fnonces = fopen(filename, "rb")) == NULL) {
@ -1052,21 +1047,21 @@ static int read_nonce_file(char *filename) {
}
snprintf(progress_text, 80, "Reading nonces from file %s...", filename);
hardnested_print_progress(0, progress_text, (float)(1LL << 47), 0);
bytes_read = fread(read_buf, 1, 6, fnonces);
size_t bytes_read = fread(read_buf, 1, 6, fnonces);
if (bytes_read != 6) {
PrintAndLogEx(WARNING, "File reading error.");
fclose(fnonces);
return 1;
}
cuid = bytes_to_num(read_buf, 4);
trgBlockNo = bytes_to_num(read_buf + 4, 1);
trgKeyType = bytes_to_num(read_buf + 5, 1);
uint8_t trgBlockNo = bytes_to_num(read_buf + 4, 1);
uint8_t trgKeyType = bytes_to_num(read_buf + 5, 1);
bytes_read = fread(read_buf, 1, 9, fnonces);
while (bytes_read == 9) {
nt_enc1 = bytes_to_num(read_buf, 4);
nt_enc2 = bytes_to_num(read_buf + 4, 4);
par_enc = bytes_to_num(read_buf + 8, 1);
uint32_t nt_enc1 = bytes_to_num(read_buf, 4);
uint32_t nt_enc2 = bytes_to_num(read_buf + 4, 4);
uint8_t par_enc = bytes_to_num(read_buf + 8, 1);
add_nonce(nt_enc1, par_enc >> 4);
add_nonce(nt_enc2, par_enc & 0x0f);
num_acquired_nonces += 2;
@ -1416,14 +1411,12 @@ static int acquire_nonces(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_
}
if (!initialize) {
uint32_t nt_enc1, nt_enc2;
uint8_t par_enc;
uint16_t num_sampled_nonces = resp.oldarg[2];
uint8_t *bufp = resp.data.asBytes;
for (uint16_t i = 0; i < num_sampled_nonces; i += 2) {
nt_enc1 = bytes_to_num(bufp, 4);
nt_enc2 = bytes_to_num(bufp + 4, 4);
par_enc = bytes_to_num(bufp + 8, 1);
uint32_t nt_enc1 = bytes_to_num(bufp, 4);
uint32_t nt_enc2 = bytes_to_num(bufp + 4, 4);
uint8_t par_enc = bytes_to_num(bufp + 8, 1);
//PrintAndLogEx(NORMAL, "Encrypted nonce: %08x, encrypted_parity: %02x\n", nt_enc1, par_enc >> 4);
num_acquired_nonces += add_nonce(nt_enc1, par_enc >> 4);

View file

@ -1051,9 +1051,6 @@ uint32_t GetHF14AMfU_Type(void) {
TagTypeUL_t tagtype = UNKNOWN;
iso14a_card_select_t card;
uint8_t version[10] = {0x00};
int status = 0;
int len;
if (!ul_select(&card)) return UL_ERROR;
@ -1066,7 +1063,8 @@ uint32_t GetHF14AMfU_Type(void) {
if (card.uid[0] != 0x05) {
len = ulev1_getVersion(version, sizeof(version));
uint8_t version[10] = {0x00};
int len = ulev1_getVersion(version, sizeof(version));
DropField();
switch (len) {
@ -1112,7 +1110,7 @@ uint32_t GetHF14AMfU_Type(void) {
// do UL_C check first...
uint8_t nonce[11] = {0x00};
status = ulc_requestAuthentication(nonce, sizeof(nonce));
int status = ulc_requestAuthentication(nonce, sizeof(nonce));
DropField();
if (status > 1) {
tagtype = UL_C;
@ -1944,10 +1942,8 @@ static int CmdHF14AMfUDump(const char *Cmd) {
iso14a_card_select_t card;
mfu_dump_t dump_file_data;
uint8_t get_pack[] = {0, 0};
uint8_t get_version[] = {0, 0, 0, 0, 0, 0, 0, 0};
uint8_t get_counter_tearing[][4] = {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}};
uint8_t dummy_pack[] = {0, 0};
uint8_t get_signature[32];
memset(get_signature, 0, sizeof(get_signature));
@ -1955,6 +1951,7 @@ static int CmdHF14AMfUDump(const char *Cmd) {
// VERSION, SIGNATURE, COUNTERS, TEARING, PACK,
if (!(tagtype & UL_C || tagtype & UL)) {
//attempt to read pack
uint8_t get_pack[] = {0, 0};
if (!ul_auth_select(&card, tagtype, true, authKeyPtr, get_pack, sizeof(get_pack))) {
//reset pack
get_pack[0] = 0;
@ -1969,9 +1966,10 @@ static int CmdHF14AMfUDump(const char *Cmd) {
memcpy(data + (pages * 4) - 4, get_pack, sizeof(get_pack));
}
if (hasAuthKey)
if (hasAuthKey) {
uint8_t dummy_pack[] = {0, 0};
ul_auth_select(&card, tagtype, hasAuthKey, authKeyPtr, dummy_pack, sizeof(dummy_pack));
else
} else
ul_select(&card);
ulev1_getVersion(get_version, sizeof(get_version));
@ -1981,9 +1979,10 @@ static int CmdHF14AMfUDump(const char *Cmd) {
}
DropField();
if (hasAuthKey)
if (hasAuthKey) {
uint8_t dummy_pack[] = {0, 0};
ul_auth_select(&card, tagtype, hasAuthKey, authKeyPtr, dummy_pack, sizeof(dummy_pack));
else
} else
ul_select(&card);
ulev1_readSignature(get_signature, sizeof(get_signature));

View file

@ -898,7 +898,6 @@ int EM4x50Read(const char *Cmd, bool verbose) {
// get rid of leading crap
snprintf(tmp, sizeof(tmp), "%i", skip);
CmdLtrim(tmp);
bool pTest;
bool AllPTest = true;
// now work through remaining buffer printing out data blocks
block = 0;
@ -930,7 +929,7 @@ int EM4x50Read(const char *Cmd, bool verbose) {
//set DemodBufferLen to just one block
DemodBufferLen = skip / clk;
//test parities
pTest = EM_ByteParityTest(DemodBuffer, DemodBufferLen, 5, 9, 0);
bool pTest = EM_ByteParityTest(DemodBuffer, DemodBufferLen, 5, 9, 0);
pTest &= EM_EndParityTest(DemodBuffer, DemodBufferLen, 5, 9, 0);
AllPTest &= pTest;
//get output

View file

@ -89,9 +89,8 @@ static int CmdIndalaDemod(const char *Cmd) {
setClockGrid(g_DemodClock, g_DemodStartIdx + (idx * g_DemodClock));
//convert UID to HEX
uint32_t uid1, uid2, uid3, uid4, uid5, uid6, uid7;
uid1 = bytebits_to_byte(DemodBuffer, 32);
uid2 = bytebits_to_byte(DemodBuffer + 32, 32);
uint32_t uid1 = bytebits_to_byte(DemodBuffer, 32);
uint32_t uid2 = bytebits_to_byte(DemodBuffer + 32, 32);
uint64_t foo = (((uint64_t)uid1 << 32) & 0x1FFFFFFF) | (uid2 & 0x7FFFFFFF);
if (DemodBufferLen == 64) {
@ -137,11 +136,11 @@ static int CmdIndalaDemod(const char *Cmd) {
} else {
uid3 = bytebits_to_byte(DemodBuffer + 64, 32);
uid4 = bytebits_to_byte(DemodBuffer + 96, 32);
uid5 = bytebits_to_byte(DemodBuffer + 128, 32);
uid6 = bytebits_to_byte(DemodBuffer + 160, 32);
uid7 = bytebits_to_byte(DemodBuffer + 192, 32);
uint32_t uid3 = bytebits_to_byte(DemodBuffer + 64, 32);
uint32_t uid4 = bytebits_to_byte(DemodBuffer + 96, 32);
uint32_t uid5 = bytebits_to_byte(DemodBuffer + 128, 32);
uint32_t uid6 = bytebits_to_byte(DemodBuffer + 160, 32);
uint32_t uid7 = bytebits_to_byte(DemodBuffer + 192, 32);
PrintAndLogEx(
SUCCESS
, "Indala Found - bitlength %d, Raw 0x%x%08x%08x%08x%08x%08x%08x"
@ -288,9 +287,9 @@ static int CmdIndalaDemodAlt(const char *Cmd) {
}
//convert UID to HEX
uint32_t uid1, uid2, uid3, uid4, uid5, uid6, uid7;
int idx;
uid1 = uid2 = 0;
uint32_t uid1 = 0;
uint32_t uid2 = 0;
if (uidlen == 64) {
for (idx = 0; idx < 64; idx++) {
@ -304,7 +303,11 @@ static int CmdIndalaDemodAlt(const char *Cmd) {
}
PrintAndLogEx(SUCCESS, "UID | %s (%x%08x)", showbits, uid1, uid2);
} else {
uid3 = uid4 = uid5 = uid6 = uid7 = 0;
uint32_t uid3 = 0;
uint32_t uid4 = 0;
uint32_t uid5 = 0;
uint32_t uid6 = 0;
uint32_t uid7 = 0;
for (idx = 0; idx < 224; idx++) {
uid1 = (uid1 << 1) | (uid2 >> 31);

View file

@ -284,20 +284,19 @@ static int CmdLFNedapChk(const char *Cmd) {
//uint8_t last = GetParity(data, EVEN, 62);
//PrintAndLogEx(NORMAL, "TEST PARITY:: %d | %d ", DemodBuffer[62], last);
uint8_t cl = 0x1D, ch = 0x1D, carry = 0;
uint8_t al, bl, temp;
uint8_t cl = 0x1D, ch = 0x1D;
for (int i = len; i >= 0; --i) {
al = data[i];
uint8_t al = data[i];
for (int j = 8; j > 0; --j) {
bl = al ^ ch;
uint8_t bl = al ^ ch;
//PrintAndLogEx(NORMAL, "BL %02x | CH %02x \n", al, ch);
carry = (cl & 0x80) ? 1 : 0;
uint8_t carry = (cl & 0x80) ? 1 : 0;
cl <<= 1;
temp = (ch & 0x80) ? 1 : 0;
uint8_t temp = (ch & 0x80) ? 1 : 0;
ch = (ch << 1) | carry;
carry = temp;
@ -305,7 +304,7 @@ static int CmdLFNedapChk(const char *Cmd) {
al <<= 1;
carry = (bl & 0x80) ? 1 : 0;
bl <<= 1;
// bl <<= 1;
if (carry) {
cl ^= 0x21;

View file

@ -213,7 +213,6 @@ int detectPresco(uint8_t *dest, size_t *size) {
// convert base 12 ID to sitecode & usercode & 8 bit other unknown code
int getWiegandFromPresco(const char *Cmd, uint32_t *sitecode, uint32_t *usercode, uint32_t *fullcode, bool *Q5) {
uint8_t val = 0;
bool hex = false, errors = false;
uint8_t cmdp = 0;
char id[11];
@ -250,8 +249,8 @@ int getWiegandFromPresco(const char *Cmd, uint32_t *sitecode, uint32_t *usercode
if (errors || cmdp == 0) return PM3_EINVARG;
if (!hex) {
uint8_t val = 0;
for (int index = 0; index < strlen(id); ++index) {
// Get value from number string.
if (id[index] == '*')
val = 10;

View file

@ -154,28 +154,27 @@ static int CmdPyramidDemod(const char *Cmd) {
}
uint8_t fmtLen = size - j - 8;
uint32_t fc, cardnum, code1;
if (fmtLen == 26) {
fc = bytebits_to_byte(bits + 73, 8);
cardnum = bytebits_to_byte(bits + 81, 16);
code1 = bytebits_to_byte(bits + 72, fmtLen);
uint32_t fc = bytebits_to_byte(bits + 73, 8);
uint32_t cardnum = bytebits_to_byte(bits + 81, 16);
uint32_t code1 = bytebits_to_byte(bits + 72, fmtLen);
PrintAndLogEx(SUCCESS, "Pyramid ID Found - BitLength: %d, FC: %d, Card: %d - Wiegand: %x, Raw: %08x%08x%08x%08x", fmtLen, fc, cardnum, code1, rawHi3, rawHi2, rawHi, rawLo);
} else if (fmtLen == 45) {
fmtLen = 42; //end = 10 bits not 7 like 26 bit fmt
fc = bytebits_to_byte(bits + 53, 10);
cardnum = bytebits_to_byte(bits + 63, 32);
uint32_t fc = bytebits_to_byte(bits + 53, 10);
uint32_t cardnum = bytebits_to_byte(bits + 63, 32);
PrintAndLogEx(SUCCESS, "Pyramid ID Found - BitLength: %d, FC: %d, Card: %d - Raw: %08x%08x%08x%08x", fmtLen, fc, cardnum, rawHi3, rawHi2, rawHi, rawLo);
/*
} else if (fmtLen > 32) {
cardnum = bytebits_to_byte(bits + 81, 16);
//code1 = bytebits_to_byte(bits+(size-fmtLen),fmtLen-32);
uint32_t cardnum = bytebits_to_byte(bits + 81, 16);
//uint32_t code1 = bytebits_to_byte(bits+(size-fmtLen),fmtLen-32);
//code2 = bytebits_to_byte(bits+(size-32),32);
PrintAndLogEx(SUCCESS, "Pyramid ID Found - BitLength: %d -unknown BitLength- (%d), Raw: %08x%08x%08x%08x", fmtLen, cardnum, rawHi3, rawHi2, rawHi, rawLo);
*/
} else {
cardnum = bytebits_to_byte(bits + 81, 16);
//code1 = bytebits_to_byte(bits+(size-fmtLen),fmtLen);
uint32_t cardnum = bytebits_to_byte(bits + 81, 16);
//uint32_t code1 = bytebits_to_byte(bits+(size-fmtLen),fmtLen);
PrintAndLogEx(SUCCESS, "Pyramid ID Found - BitLength: %d -unknown BitLength- (%d), Raw: %08x%08x%08x%08x", fmtLen, cardnum, rawHi3, rawHi2, rawHi, rawLo);
}

View file

@ -918,9 +918,8 @@ static bool testBitRate(uint8_t readRate, uint8_t clk) {
bool test(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk, bool *Q5) {
if (DemodBufferLen < 64) return false;
uint8_t si;
for (uint8_t idx = 28; idx < 64; idx++) {
si = idx;
uint8_t si = idx;
if (PackBits(si, 28, DemodBuffer) == 0x00) continue;
uint8_t safer = PackBits(si, 4, DemodBuffer);

View file

@ -694,7 +694,6 @@ bool WaitForResponseTimeoutW(uint32_t cmd, PacketResponseNG *response, size_t ms
ms_timeout += communication_delay();
__atomic_store_n(&timeout_start_time, msclock(), __ATOMIC_SEQ_CST);
uint64_t tmp_clk;
// Wait until the command is received
while (true) {
@ -705,7 +704,7 @@ bool WaitForResponseTimeoutW(uint32_t cmd, PacketResponseNG *response, size_t ms
}
}
tmp_clk = __atomic_load_n(&timeout_start_time, __ATOMIC_SEQ_CST);
uint64_t tmp_clk = __atomic_load_n(&timeout_start_time, __ATOMIC_SEQ_CST);
if ((ms_timeout != (size_t) -1) && (msclock() - tmp_clk > ms_timeout))
break;
@ -778,7 +777,6 @@ static bool dl_it(uint8_t *dest, uint32_t bytes, uint32_t start_index, PacketRes
uint32_t bytes_completed = 0;
__atomic_store_n(&timeout_start_time, msclock(), __ATOMIC_SEQ_CST);
uint64_t tmp_clk;
// Add delay depending on the communication channel & speed
if (ms_timeout != (size_t) -1)
@ -815,7 +813,7 @@ static bool dl_it(uint8_t *dest, uint32_t bytes, uint32_t start_index, PacketRes
}
}
tmp_clk = __atomic_load_n(&timeout_start_time, __ATOMIC_SEQ_CST);
uint64_t tmp_clk = __atomic_load_n(&timeout_start_time, __ATOMIC_SEQ_CST);
if (msclock() - tmp_clk > ms_timeout) {
PrintAndLogEx(FAILED, "Timed out while trying to download data from device");
break;

View file

@ -279,14 +279,13 @@ static int CodeCmp(const char *code1, const char *code2) {
const APDUCode *GetAPDUCode(uint8_t sw1, uint8_t sw2) {
char buf[6] = {0};
int res;
int mineq = APDUCodeTableLen;
int mineqindx = 0;
sprintf(buf, "%02X%02X", sw1, sw2);
for (int i = 0; i < APDUCodeTableLen; i++) {
res = CodeCmp(APDUCodeTable[i].ID, buf);
int res = CodeCmp(APDUCodeTable[i].ID, buf);
// equal
if (res == 0) {

View file

@ -220,9 +220,9 @@ int COSEGetECDSAKey(uint8_t *data, size_t datalen, bool verbose, uint8_t *public
}
// d - private key
uint8_t private_key[128] = {0};
res = CborMapGetKeyById(&parser, &map, data, datalen, -4);
if (!res) {
uint8_t private_key[128] = {0};
res = CborGetBinStringValue(&map, private_key, sizeof(private_key), &len);
cbor_check(res);
if (verbose)

View file

@ -397,10 +397,6 @@ static int generate_fpga_version_info(FILE *infile[], char *infile_names[], int
}
int main(int argc, char **argv) {
FILE **infiles;
char **infile_names;
FILE *outfile;
if (argc == 1 || argc == 2) {
usage();
return (EXIT_FAILURE);
@ -408,7 +404,7 @@ int main(int argc, char **argv) {
if (!strcmp(argv[1], "-d")) { // Decompress
infiles = calloc(1, sizeof(FILE *));
FILE **infiles = calloc(1, sizeof(FILE *));
if (argc != 4) {
usage();
free(infiles);
@ -420,7 +416,7 @@ int main(int argc, char **argv) {
free(infiles);
return (EXIT_FAILURE);
}
outfile = fopen(argv[3], "wb");
FILE *outfile = fopen(argv[3], "wb");
if (outfile == NULL) {
fprintf(stderr, "Error. Cannot open output file %s\n\n", argv[3]);
free(infiles);
@ -450,8 +446,8 @@ int main(int argc, char **argv) {
num_input_files = argc - 2;
}
infiles = calloc(num_input_files, sizeof(FILE *));
infile_names = calloc(num_input_files, sizeof(char *));
FILE **infiles = calloc(num_input_files, sizeof(FILE *));
char **infile_names = calloc(num_input_files, sizeof(char *));
for (uint16_t i = 0; i < num_input_files; i++) {
infile_names[i] = argv[i + ((hardnested_mode || generate_version_file) ? 2 : 1)];
infiles[i] = fopen(infile_names[i], "rb");
@ -462,7 +458,7 @@ int main(int argc, char **argv) {
return (EXIT_FAILURE);
}
}
outfile = fopen(argv[argc - 1], "wb");
FILE *outfile = fopen(argv[argc - 1], "wb");
if (outfile == NULL) {
fprintf(stderr, "Error. Cannot open output file %s\n\n", argv[argc - 1]);
free(infile_names);

View file

@ -257,17 +257,15 @@ void hash0(uint64_t c, uint8_t k[8]) {
// z0-z7 6 bits each : 48 bits
uint8_t x = (c & 0xFF00000000000000) >> 56;
uint8_t y = (c & 0x00FF000000000000) >> 48;
int n;
uint8_t zn, zn4, _zn, _zn4;
uint64_t zP = 0;
for (n = 0; n < 4 ; n++) {
zn = getSixBitByte(c, n);
for (int n = 0; n < 4 ; n++) {
uint8_t zn = getSixBitByte(c, n);
zn4 = getSixBitByte(c, n + 4);
uint8_t zn4 = getSixBitByte(c, n + 4);
_zn = (zn % (63 - n)) + n;
_zn4 = (zn4 % (64 - n)) + n;
uint8_t _zn = (zn % (63 - n)) + n;
uint8_t _zn4 = (zn4 % (64 - n)) + n;
pushbackSixBitByte(&zP, _zn, n);
pushbackSixBitByte(&zP, _zn4, n + 4);
@ -300,9 +298,8 @@ void hash0(uint64_t c, uint8_t k[8]) {
printState("0|0|z~", zTilde);
int i;
int zerocounter = 0 ;
for (i = 0; i < 8; i++) {
// int zerocounter = 0 ;
for (int i = 0; i < 8; i++) {
// the key on index i is first a bit from y
// then six bits from z,
// then a bit from p
@ -340,9 +337,9 @@ void hash0(uint64_t c, uint8_t k[8]) {
k[i] |= zTilde_i & 0x7E;
k[i] |= (~p_i) & 1;
}
if ((k[i] & 1) == 0) {
zerocounter++;
}
// if ((k[i] & 1) == 0) {
// zerocounter++;
// }
}
}
/**

View file

@ -45,7 +45,7 @@ uint32_t intersection(uint64_t *listA, uint64_t *listB) {
uint32_t nonce2key(uint32_t uid, uint32_t nt, uint32_t nr, uint32_t ar, uint64_t par_info, uint64_t ks_info, uint64_t **keys) {
struct Crypto1State *states;
uint32_t i, pos;
uint8_t bt, ks3x[8], par[8][8];
uint8_t ks3x[8], par[8][8];
uint64_t key_recovered;
uint64_t *keylist;
@ -54,7 +54,7 @@ uint32_t nonce2key(uint32_t uid, uint32_t nt, uint32_t nr, uint32_t ar, uint64_t
for (pos = 0; pos < 8; pos++) {
ks3x[7 - pos] = (ks_info >> (pos * 8)) & 0x0F;
bt = (par_info >> (pos * 8)) & 0xFF;
uint8_t bt = (par_info >> (pos * 8)) & 0xFF;
par[7 - pos][0] = (bt >> 0) & 1;
par[7 - pos][1] = (bt >> 1) & 1;

View file

@ -339,16 +339,16 @@ int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBlockNo,
while (p1 <= statelists[0].tail.sltail && p2 <= statelists[1].tail.sltail) {
if (Compare16Bits(p1, p2) == 0) {
struct Crypto1State savestate, *savep = &savestate;
struct Crypto1State savestate;
savestate = *p1;
while (Compare16Bits(p1, savep) == 0 && p1 <= statelists[0].tail.sltail) {
while (Compare16Bits(p1, &savestate) == 0 && p1 <= statelists[0].tail.sltail) {
*p3 = *p1;
lfsr_rollback_word(p3, statelists[0].nt ^ statelists[0].uid, 0);
p3++;
p1++;
}
savestate = *p2;
while (Compare16Bits(p2, savep) == 0 && p2 <= statelists[1].tail.sltail) {
while (Compare16Bits(p2, &savestate) == 0 && p2 <= statelists[1].tail.sltail) {
*p4 = *p2;
lfsr_rollback_word(p4, statelists[1].nt ^ statelists[1].uid, 0);
p4++;
@ -710,10 +710,6 @@ void mf_crypto1_decrypt(struct Crypto1State *pcs, uint8_t *data, int len, bool i
}
int mfTraceDecode(uint8_t *data_src, int len, bool wantSaveToEmlFile) {
uint32_t nt = 0; // tag challenge
uint32_t nr_enc = 0; // encrypted reader challenge
uint32_t ar_enc = 0; // encrypted reader response
uint32_t at_enc = 0; // encrypted tag response
if (traceState == TRACE_ERROR)
return PM3_ESOFT;
@ -831,6 +827,10 @@ int mfTraceDecode(uint8_t *data_src, int len, bool wantSaveToEmlFile) {
break;
case TRACE_AUTH_OK:
if (len == 4) {
uint32_t nt = 0; // tag challenge
uint32_t nr_enc = 0; // encrypted reader challenge
uint32_t ar_enc = 0; // encrypted reader response
uint32_t at_enc = 0; // encrypted tag response
traceState = TRACE_IDLE;
// encrypted tag response
at_enc = bytes_to_num(data, 4);

View file

@ -167,12 +167,11 @@ static int l_unpack(lua_State *L) { /** unpack(f,s, [init]) */
case OP_HEX: {
luaL_Buffer buf;
char hdigit = '0';
int val = 0;
luaL_buffinit(L, &buf);
N++;
if (i + N > len) {done = 1; break;}
for (unsigned int ii = i; ii < i + N; ii++) {
val = s[ii] & 0xF0;
int val = s[ii] & 0xF0;
val = val >> 4;
hdigit = HEXDIGITS(val);
luaL_addlstring(&buf, &hdigit, 1);

View file

@ -338,6 +338,7 @@ static int l_WaitForResponseTimeout(lua_State *L) {
memcpy(foo + n, &resp.ng, sizeof(resp.ng));
n += sizeof(resp.ng);
(void) n;
//Push it as a string
lua_pushlstring(L, (const char *)&foo, sizeof(foo));
@ -995,7 +996,7 @@ static int l_T55xx_detect(lua_State *L) {
//
static int l_ndefparse(lua_State *L) {
size_t len = 0, size;
size_t size;
//Check number of arguments
int n = lua_gettop(L);
@ -1021,7 +1022,6 @@ static int l_ndefparse(lua_State *L) {
for (int i = 0; i < size; i += 2) {
sscanf(&p_data[i], "%02x", &tmp);
data[i >> 1] = tmp & 0xFF;
len++;
}
}

View file

@ -234,13 +234,13 @@ void memcpy_filter_ansi(void *dest, const void *src, size_t n, bool filter) {
uint8_t *rsrc = (uint8_t *)src;
uint16_t si = 0;
for (uint16_t i = 0; i < n; i++) {
if ((rsrc[i] == '\x1b')
&& (i < n - 1)
if ((i < n - 1)
&& (rsrc[i] == '\x1b')
&& (rsrc[i + 1] >= 0x40)
&& (rsrc[i + 1] <= 0x5F)) { // entering ANSI sequence
i++;
if ((rsrc[i] == '[') && (i < n - 1)) { // entering CSI sequence
if ((i < n - 1) && (rsrc[i] == '[')) { // entering CSI sequence
i++;
while ((i < n - 1) && (rsrc[i] >= 0x30) && (rsrc[i] <= 0x3F)) { // parameter bytes

View file

@ -29,10 +29,9 @@ extern void bucket_sort_intersect(uint32_t *const estart, uint32_t *const estop,
// write back intersecting buckets as sorted list.
// fill in bucket_info with head and tail of the bucket contents in the list and number of non-empty buckets.
uint32_t nonempty_bucket;
for (uint32_t i = 0; i < 2; i++) {
p1 = start[i];
nonempty_bucket = 0;
uint32_t nonempty_bucket = 0;
for (uint32_t j = 0x00; j <= 0xff; j++) {
if (bucket[0][j].bp != bucket[0][j].head && bucket[1][j].bp != bucket[1][j].head) { // non-empty intersecting buckets only
bucket_info->bucket_info[i][nonempty_bucket].head = p1;

View file

@ -369,12 +369,12 @@ uint32_t lfsr_rollback_word(struct Crypto1State *s, uint32_t in, int fb) {
*/
static uint16_t *dist = 0;
int nonce_distance(uint32_t from, uint32_t to) {
uint16_t x, i;
if (!dist) {
dist = calloc(2 << 16, sizeof(uint8_t));
if (!dist)
return -1;
for (x = i = 1; i; ++i) {
uint16_t x = 1;
for (uint16_t i = 1; i; ++i) {
dist[(x & 0xff) << 8 | x >> 8] = i;
x = x >> 1 | (x ^ x >> 2 ^ x >> 3 ^ x >> 5) << 15;
}
@ -412,12 +412,12 @@ uint32_t *lfsr_prefix_ks(uint8_t ks[8], int isodd) {
uint32_t *candidates = calloc(4 << 10, sizeof(uint8_t));
if (!candidates) return 0;
uint32_t c, entry;
int size = 0, i, good;
int size = 0;
for (i = 0; i < 1 << 21; ++i) {
for (c = 0, good = 1; good && c < 8; ++c) {
entry = i ^ fastfwd[isodd][c];
for (int i = 0; i < 1 << 21; ++i) {
int good = 1;
for (uint32_t c = 0; good && c < 8; ++c) {
uint32_t entry = i ^ fastfwd[isodd][c];
good &= (BIT(ks[c], isodd) == filter(entry >> 1));
good &= (BIT(ks[c], isodd + 2) == filter(entry));
}
@ -434,24 +434,24 @@ uint32_t *lfsr_prefix_ks(uint8_t ks[8], int isodd) {
* helper function which eliminates possible secret states using parity bits
*/
static struct Crypto1State *check_pfx_parity(uint32_t prefix, uint32_t rresp, uint8_t parities[8][8], uint32_t odd, uint32_t even, struct Crypto1State *sl, uint32_t no_par) {
uint32_t ks1, nr, ks2, rr, ks3, c, good = 1;
uint32_t good = 1;
for (c = 0; good && c < 8; ++c) {
for (uint32_t c = 0; good && c < 8; ++c) {
sl->odd = odd ^ fastfwd[1][c];
sl->even = even ^ fastfwd[0][c];
lfsr_rollback_bit(sl, 0, 0);
lfsr_rollback_bit(sl, 0, 0);
ks3 = lfsr_rollback_bit(sl, 0, 0);
ks2 = lfsr_rollback_word(sl, 0, 0);
ks1 = lfsr_rollback_word(sl, prefix | c << 5, 1);
uint32_t ks3 = lfsr_rollback_bit(sl, 0, 0);
uint32_t ks2 = lfsr_rollback_word(sl, 0, 0);
uint32_t ks1 = lfsr_rollback_word(sl, prefix | c << 5, 1);
if (no_par)
break;
nr = ks1 ^ (prefix | c << 5);
rr = ks2 ^ rresp;
uint32_t nr = ks1 ^ (prefix | c << 5);
uint32_t rr = ks2 ^ rresp;
good &= evenparity32(nr & 0x000000ff) ^ parities[c][3] ^ BIT(ks2, 24);
good &= evenparity32(rr & 0xff000000) ^ parities[c][4] ^ BIT(ks2, 16);

View file

@ -51,16 +51,14 @@ void init_table(CrcType_t crctype) {
void generate_table(uint16_t polynomial, bool refin) {
uint16_t i, j, crc, c;
for (i = 0; i < 256; i++) {
crc = 0;
for (uint16_t i = 0; i < 256; i++) {
uint16_t c, crc = 0;
if (refin)
c = reflect8(i) << 8;
else
c = i << 8;
for (j = 0; j < 8; j++) {
for (uint16_t j = 0; j < 8; j++) {
if ((crc ^ c) & 0x8000)
crc = (crc << 1) ^ polynomial;
@ -109,11 +107,10 @@ uint16_t crc16_fast(uint8_t const *d, size_t n, uint16_t initval, bool refin, bo
// bit looped solution TODO REMOVED
uint16_t update_crc16_ex(uint16_t crc, uint8_t c, uint16_t polynomial) {
uint16_t i, v, tmp = 0;
uint16_t tmp = 0;
uint16_t v = (crc ^ c) & 0xff;
v = (crc ^ c) & 0xff;
for (i = 0; i < 8; i++) {
for (uint16_t i = 0; i < 8; i++) {
if ((tmp ^ v) & 1)
tmp = (tmp >> 1) ^ polynomial;
@ -133,9 +130,8 @@ uint16_t Crc16(uint8_t const *d, size_t length, uint16_t remainder, uint16_t pol
if (length == 0)
return (~remainder);
uint8_t c;
for (uint32_t i = 0; i < length; ++i) {
c = d[i];
uint8_t c = d[i];
if (refin) c = reflect8(c);
// xor in at msb

View file

@ -333,7 +333,7 @@ void getNextHigh(uint8_t *samples, size_t size, int high, size_t *i) {
// load wave counters
bool loadWaveCounters(uint8_t *samples, size_t size, int lowToLowWaveLen[], int highToLowWaveLen[], int *waveCnt, int *skip, int *minClk, int *high, int *low) {
size_t i = 0, firstLow, firstHigh;
size_t i = 0;
//size_t testsize = (size < 512) ? size : 512;
// just noise - no super good detection. good enough
@ -352,10 +352,10 @@ bool loadWaveCounters(uint8_t *samples, size_t size, int lowToLowWaveLen[], int
// populate tmpbuff buffer with pulse lengths
while (i < size) {
// measure from low to low
firstLow = i;
size_t firstLow = i;
//find first high point for this wave
getNextHigh(samples, size, *high, &i);
firstHigh = i;
size_t firstHigh = i;
getNextLow(samples, size, *low, &i);

View file

@ -112,7 +112,7 @@ uint16_t usart_rxdata_available(void) {
uint32_t usart_read_ng(uint8_t *data, size_t len) {
if (len == 0) return 0;
uint32_t packetSize, nbBytesRcv = 0;
uint32_t nbBytesRcv = 0;
uint32_t try = 0;
// uint32_t highest_observed_try = 0;
// Empirical max try observed: 3000000 / USART_BAUD_RATE
@ -129,7 +129,7 @@ uint32_t usart_read_ng(uint8_t *data, size_t len) {
while (len) {
uint32_t available = usart_rxdata_available();
packetSize = MIN(available, len);
uint32_t packetSize = MIN(available, len);
if (available > 0) {
// Dbprintf_usb("Dbg USART ask %d bytes, available %d bytes, packetsize %d bytes", len, available, packetSize);
// highest_observed_try = MAX(highest_observed_try, try);

View file

@ -766,11 +766,10 @@ int usb_write(const uint8_t *data, const size_t len) {
//* \brief Send Data through the control endpoint
//*----------------------------------------------------------------------------
void AT91F_USB_SendData(AT91PS_UDP pUdp, const char *pData, uint32_t length) {
uint32_t cpt = 0;
AT91_REG csr;
do {
cpt = MIN(length, AT91C_EP_CONTROL_SIZE);
uint32_t cpt = MIN(length, AT91C_EP_CONTROL_SIZE);
length -= cpt;
while (cpt--)

View file

@ -428,12 +428,12 @@ uint32_t lfsr_rollback_word(struct Crypto1State *s, uint32_t in, int fb) {
*/
static uint16_t *dist = 0;
int nonce_distance(uint32_t from, uint32_t to) {
uint16_t x, i;
if (!dist) {
dist = calloc(2 << 16, sizeof(uint8_t));
if (!dist)
return -1;
for (x = i = 1; i; ++i) {
uint16_t x = 1;
for (uint16_t i = 1; i; ++i) {
dist[(x & 0xff) << 8 | x >> 8] = i;
x = x >> 1 | (x ^ x >> 2 ^ x >> 3 ^ x >> 5) << 15;
}

View file

@ -5,8 +5,8 @@
int main(const int argc, const char *argv[]) {
struct Crypto1State *state;
uint32_t pos, uid, nt, nr, rr, nr_diff;
uint8_t bt, i, ks3x[8], par[8][8];
uint32_t pos, uid, nt, nr, rr;
uint8_t ks3x[8], par[8][8];
uint64_t key_recovered;
uint64_t par_info;
uint64_t ks_info;
@ -28,9 +28,9 @@ int main(const int argc, const char *argv[]) {
for (pos = 0; pos < 8; pos++) {
ks3x[7 - pos] = (ks_info >> (pos * 8)) & 0x0f;
bt = (par_info >> (pos * 8)) & 0xff;
uint8_t bt = (par_info >> (pos * 8)) & 0xff;
for (i = 0; i < 8; i++) {
for (uint8_t i = 0; i < 8; i++) {
par[7 - pos][i] = (bt >> i) & 0x01;
}
}
@ -38,8 +38,8 @@ int main(const int argc, const char *argv[]) {
printf("|diff|{nr} |ks3|ks3^5|parity |\n");
printf("+----+--------+---+-----+---------------+\n");
for (i = 0; i < 8; i++) {
nr_diff = nr | i << 5;
for (uint8_t i = 0; i < 8; i++) {
uint32_t nr_diff = nr | i << 5;
printf("| %02x |%08x| %01x | %01x |", i << 5, nr_diff, ks3x[i], ks3x[i] ^ 5);
for (pos = 0; pos < 7; pos++)