const and bad OR

This commit is contained in:
iceman1001 2024-09-06 09:52:30 +02:00
commit b0dd246d94
6 changed files with 24 additions and 15 deletions

View file

@ -947,7 +947,7 @@ static void Code4bitAnswerAsTag(uint8_t cmd) {
// stop when button is pressed or client usb connection resets // stop when button is pressed or client usb connection resets
// or return TRUE when command is captured // or return TRUE when command is captured
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool GetIso14443aCommandFromReader(uint8_t *received, uint16_t received_max_len, uint8_t *par, int *len) { bool GetIso14443aCommandFromReader(uint8_t *received, uint16_t received_maxlen, uint8_t *par, int *len) {
// Set FPGA mode to "simulated ISO 14443 tag", no modulation (listen // Set FPGA mode to "simulated ISO 14443 tag", no modulation (listen
// only, since we are receiving, not transmitting). // only, since we are receiving, not transmitting).
// Signal field is off with the appropriate LED // Signal field is off with the appropriate LED
@ -955,7 +955,7 @@ bool GetIso14443aCommandFromReader(uint8_t *received, uint16_t received_max_len,
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_ISO14443A | FPGA_HF_ISO14443A_TAGSIM_LISTEN); FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_ISO14443A | FPGA_HF_ISO14443A_TAGSIM_LISTEN);
// Now run a `software UART` on the stream of incoming samples. // Now run a `software UART` on the stream of incoming samples.
Uart14aInit(received, received_max_len, par); Uart14aInit(received, received_maxlen, par);
// clear RXRDY: // clear RXRDY:
uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR; uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR;

View file

@ -142,7 +142,7 @@ RAMFUNC int ManchesterDecoding(uint8_t bit, uint16_t offset, uint32_t non_real_t
void RAMFUNC SniffIso14443a(uint8_t param); void RAMFUNC SniffIso14443a(uint8_t param);
void SimulateIso14443aTag(uint8_t tagType, uint16_t flags, uint8_t *data, uint8_t exitAfterNReads); void SimulateIso14443aTag(uint8_t tagType, uint16_t flags, uint8_t *data, uint8_t exitAfterNReads);
bool SimulateIso14443aInit(uint8_t tagType, uint16_t flags, uint8_t *data, tag_response_info_t **responses, uint32_t *cuid, uint32_t counters[3], uint8_t tearings[3], uint8_t *pages); bool SimulateIso14443aInit(uint8_t tagType, uint16_t flags, uint8_t *data, tag_response_info_t **responses, uint32_t *cuid, uint32_t counters[3], uint8_t tearings[3], uint8_t *pages);
bool GetIso14443aCommandFromReader(uint8_t *received, uint16_t rec_maxlen, uint8_t *par, int *len); bool GetIso14443aCommandFromReader(uint8_t *received, uint16_t received_maxlen, uint8_t *par, int *len);
void iso14443a_antifuzz(uint32_t flags); void iso14443a_antifuzz(uint32_t flags);
void ReaderIso14443a(PacketCommandNG *c); void ReaderIso14443a(PacketCommandNG *c);
void ReaderTransmit(uint8_t *frame, uint16_t len, uint32_t *timing); void ReaderTransmit(uint8_t *frame, uint16_t len, uint32_t *timing);

View file

@ -304,7 +304,7 @@ static bool MifareSimInit(uint16_t flags, uint8_t *datain, uint16_t atqa, uint8_
} }
// Correct uid size bits in ATQA // Correct uid size bits in ATQA
rATQA[0] = (rATQA[0] & 0x3f) | 0x00; // single size uid rATQA[0] = (rATQA[0] & 0x3f); // single size uid
} else if ((flags & FLAG_7B_UID_IN_DATA) == FLAG_7B_UID_IN_DATA) { } else if ((flags & FLAG_7B_UID_IN_DATA) == FLAG_7B_UID_IN_DATA) {
memcpy(&rUIDBCC1[1], datain, 3); memcpy(&rUIDBCC1[1], datain, 3);

View file

@ -145,7 +145,8 @@ int mifare_classic_auth(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo,
int mifare_classic_authex(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t keyType, uint64_t ui64Key, uint8_t isNested, uint32_t *ntptr, uint32_t *timing) { int mifare_classic_authex(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t keyType, uint64_t ui64Key, uint8_t isNested, uint32_t *ntptr, uint32_t *timing) {
return mifare_classic_authex_cmd(pcs, uid, blockNo, MIFARE_AUTH_KEYA + (keyType & 0xF), ui64Key, isNested, ntptr, NULL, NULL, timing, false, false); return mifare_classic_authex_cmd(pcs, uid, blockNo, MIFARE_AUTH_KEYA + (keyType & 0xF), ui64Key, isNested, ntptr, NULL, NULL, timing, false, false);
} }
int mifare_classic_authex_cmd(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t cmd, uint64_t ui64Key, uint8_t isNested, uint32_t *ntptr, uint32_t *ntencptr, uint8_t *ntparptr, uint32_t *timing, bool corruptnrar, bool corruptnrarparity) { int mifare_classic_authex_cmd(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t cmd, uint64_t ui64Key, uint8_t isNested,
uint32_t *ntptr, uint32_t *ntencptr, uint8_t *ntencparptr, uint32_t *timing, bool corruptnrar, bool corruptnrarparity) {
// "random" reader nonce: // "random" reader nonce:
uint8_t nr[4]; uint8_t nr[4];
num_to_bytes(prng_successor(GetTickCount(), 32), 4, nr); num_to_bytes(prng_successor(GetTickCount(), 32), 4, nr);
@ -159,14 +160,18 @@ int mifare_classic_authex_cmd(struct Crypto1State *pcs, uint32_t uid, uint8_t bl
// Save the tag nonce (nt) // Save the tag nonce (nt)
uint32_t nt = bytes_to_num(receivedAnswer, 4); uint32_t nt = bytes_to_num(receivedAnswer, 4);
if (ntencptr) if (ntencptr) {
*ntencptr = nt; *ntencptr = nt;
if (ntparptr) }
*ntparptr = receivedAnswerPar[0];
if (ntencparptr) {
*ntencparptr = receivedAnswerPar[0];
}
// ----------------------------- crypto1 create // ----------------------------- crypto1 create
if (isNested) if (isNested) {
crypto1_deinit(pcs); crypto1_deinit(pcs);
}
// Init cipher with key // Init cipher with key
crypto1_init(pcs, ui64Key); crypto1_init(pcs, ui64Key);
@ -214,8 +219,9 @@ int mifare_classic_authex_cmd(struct Crypto1State *pcs, uint32_t uid, uint8_t bl
} }
} }
// save Nt // save Nt
if (ntptr) if (ntptr) {
*ntptr = nt; *ntptr = nt;
}
// Generate (encrypted) nr+parity by loading it into the cipher (Nr) // Generate (encrypted) nr+parity by loading it into the cipher (Nr)
uint32_t pos; uint32_t pos;
@ -233,11 +239,13 @@ int mifare_classic_authex_cmd(struct Crypto1State *pcs, uint32_t uid, uint8_t bl
Dbprintf("Corrupting nRaR..."); Dbprintf("Corrupting nRaR...");
nt ^= 1; nt ^= 1;
} }
for (pos = 4; pos < 8; pos++) { for (pos = 4; pos < 8; pos++) {
nt = prng_successor(nt, 8); nt = prng_successor(nt, 8);
mf_nr_ar[pos] = crypto1_byte(pcs, 0x00, 0) ^ (nt & 0xff); mf_nr_ar[pos] = crypto1_byte(pcs, 0x00, 0) ^ (nt & 0xff);
par[0] |= (((filter(pcs->odd) ^ oddparity8(nt & 0xff)) & 0x01) << (7 - pos)); par[0] |= (((filter(pcs->odd) ^ oddparity8(nt & 0xff)) & 0x01) << (7 - pos));
} }
if (corruptnrarparity) { if (corruptnrarparity) {
Dbprintf("Corrupting nRaR parity..."); Dbprintf("Corrupting nRaR parity...");
par[0] ^= 1; par[0] ^= 1;
@ -250,15 +258,16 @@ int mifare_classic_authex_cmd(struct Crypto1State *pcs, uint32_t uid, uint8_t bl
uint32_t save_timeout = iso14a_get_timeout(); uint32_t save_timeout = iso14a_get_timeout();
// set timeout for authentication response // set timeout for authentication response
if (save_timeout > 106) if (save_timeout > 106) {
iso14a_set_timeout(106); iso14a_set_timeout(106);
}
// Receive 4 byte tag answer // Receive 4 byte tag answer
len = ReaderReceive(receivedAnswer, sizeof(receivedAnswer), receivedAnswerPar); len = ReaderReceive(receivedAnswer, sizeof(receivedAnswer), receivedAnswerPar);
iso14a_set_timeout(save_timeout); iso14a_set_timeout(save_timeout);
if (!len) { if (len == 0) {
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("Authentication failed. Card timeout"); if (g_dbglevel >= DBG_EXTENDED) Dbprintf("Authentication failed. Card timeout");
return 2; return 2;
} }

View file

@ -82,7 +82,7 @@ https://github.com/ApertureLabsLtd/RFIDler/blob/master/firmware/Pic32/RFIDler.X/
*/ */
// convert hex to sequence of 0/1 bit values // convert hex to sequence of 0/1 bit values
// returns number of bits converted // returns number of bits converted
int hex2binarray(char *target, char *source) { int hex2binarray(char *target, const char *source) {
return hex2binarray_n(target, source, strlen(source)); return hex2binarray_n(target, source, strlen(source));
} }

View file

@ -84,11 +84,11 @@
size_t nbytes(size_t nbits); size_t nbytes(size_t nbits);
uint8_t hex2int(char x); uint8_t hex2int(char x);
int hex2binarray(char *target, char *source); int hex2binarray(char *target, const char *source);
int hex2binarray_n(char *target, const char *source, int sourcelen); int hex2binarray_n(char *target, const char *source, int sourcelen);
int binarray2hex(const uint8_t *bs, int bs_len, uint8_t *hex); int binarray2hex(const uint8_t *bs, int bs_len, uint8_t *hex);
void convertToHexArray(uint8_t num, uint8_t *partialKey); void convertToHexArray(uint8_t num, uint8_t *partialkey);
void LED(int led, int ms); void LED(int led, int ms);
void LEDsoff(void); void LEDsoff(void);