diff --git a/armsrc/BigBuf.h b/armsrc/BigBuf.h index 61e82b865..c3a7503f8 100644 --- a/armsrc/BigBuf.h +++ b/armsrc/BigBuf.h @@ -13,8 +13,8 @@ #define __BIGBUF_H #include "proxmark3.h" -#include "apps.h" #include "string.h" +#include "ticks.h" #define BIGBUF_SIZE 40000 #define MAX_FRAME_SIZE 256 // maximum allowed ISO14443 frame diff --git a/armsrc/Makefile b/armsrc/Makefile index 07227a2d5..bde50f0ec 100644 --- a/armsrc/Makefile +++ b/armsrc/Makefile @@ -19,11 +19,13 @@ APP_CFLAGS = -DWITH_ISO14443a_StandAlone -DWITH_LF \ #SRC_LCD = fonts.c LCD.c SRC_LF = lfops.c hitag2.c hitagS.c lfsampling.c pcf7931.c lfdemod.c protocols.c SRC_ISO15693 = iso15693.c iso15693tools.c -SRC_ISO14443a = epa.c iso14443a.c mifareutil.c mifarecmd.c mifaresniff.c +SRC_ISO14443a = iso14443a.c mifareutil.c mifarecmd.c mifaresniff.c epa.c SRC_ISO14443b = iso14443b.c SRC_CRAPTO1 = crapto1.c crypto1.c des.c aes.c desfire_key.c desfire_crypto.c mifaredesfire.c SRC_CRC = iso14443crc.c crc.c crc16.c crc32.c SRC_EMV = tlv.c emvdataels.c emvutil.c emvcmd.c +SRC_ICLASS = iclass.c optimized_cipher.c +SRC_LEGIC = legicrf.c legic_prng.c #the FPGA bitstream files. Note: order matters! FPGA_BITSTREAMS = fpga_lf.bit fpga_hf.bit @@ -45,28 +47,30 @@ THUMBSRC = start.c \ $(SRC_ISO15693) \ $(SRC_LF) \ $(SRC_ZLIB) \ + $(SRC_LEGIC) \ + $(SRC_ISO14443b) \ + $(SRC_ICLASS) \ appmain.c \ printf.c \ util.c \ string.c \ usb_cdc.c \ cmd.c \ - ticks.c + BigBuf.c \ + ticks.c \ + hfsnoop.c # These are to be compiled in ARM mode ARMSRC = fpgaloader.c \ - legicrf.c \ - $(SRC_ISO14443a) \ - $(SRC_ISO14443b) \ - $(SRC_CRAPTO1) \ $(SRC_CRC) \ - legic_prng.c \ - iclass.c \ - BigBuf.c \ - optimized_cipher.c \ - hfsnoop.c \ + $(SRC_CRAPTO1) \ + $(SRC_ISO14443a) \ parity.c -# $(SRC_EMV) +# $(SRC_ISO14443b) \ +# $(SRC_ICLASS) \ +# $(SRC_EMV) \ + #BigBuf.c \ + # Do not move this inclusion before the definition of {THUMB,ASM,ARM}SRC include ../common/Makefile.common diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 4eabb3191..d4b22465e 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -10,20 +10,15 @@ // executes. //----------------------------------------------------------------------------- #include "usb_cdc.h" -//#include "cmd.h" #include "proxmark3.h" #include "apps.h" #include "util.h" #include "printf.h" #include "string.h" -#include #include "legicrf.h" -#include "hitag2.h" -#include "hitagS.h" #include "lfsampling.h" #include "BigBuf.h" #include "mifareutil.h" -#include "pcf7931.h" #ifdef WITH_LCD #include "LCD.h" @@ -76,6 +71,28 @@ void PrintToSendBuffer(void){ Dbhexdump(ToSendMax, ToSend, 0); } +void print_result(char *name, uint8_t *buf, size_t len) { + uint8_t *p = buf; + + if ( len % 16 == 0 ) { + for(; p-buf < len; p += 16) + Dbprintf("[%s:%d/%d] %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", + name, + p-buf, + len, + p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15] + ); + } + else { + for(; p-buf < len; p += 8) + Dbprintf("[%s:%d/%d] %02x %02x %02x %02x %02x %02x %02x %02x", + name, + p-buf, + len, + p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); + } +} + //============================================================================= // Debug print functions, to go out over USB, to the usual PC-side client. //============================================================================= @@ -1025,19 +1042,15 @@ void UsbPacketReceived(uint8_t *packet, int len) case CMD_RECORD_RAW_ADC_SAMPLES_ISO_15693: RecordRawAdcSamplesIso15693(); break; - case CMD_ISO_15693_COMMAND: DirectTag15693Command(c->arg[0],c->arg[1],c->arg[2],c->d.asBytes); break; - case CMD_ISO_15693_FIND_AFI: BruteforceIso15693Afi(c->arg[0]); break; - case CMD_ISO_15693_DEBUG: SetDebugIso15693(c->arg[0]); break; - case CMD_READER_ISO_15693: ReaderIso15693(c->arg[0]); break; diff --git a/armsrc/apps.h b/armsrc/apps.h index d119d2396..6289223b0 100644 --- a/armsrc/apps.h +++ b/armsrc/apps.h @@ -11,26 +11,25 @@ #ifndef __APPS_H #define __APPS_H -#include -#include +#ifdef __cplusplus +extern "C" { +#endif + #include -//#include +#include #include "common.h" +#include "usb_cdc.h" #include "crc32.h" #include "lfdemod.h" #include "BigBuf.h" #include "fpgaloader.h" -#include "usb_cdc.h" #include "hitag2.h" #include "hitagS.h" #include "mifare.h" #include "pcf7931.h" -//#include "des.h" -//#include "aes.h" #include "desfire.h" #include "iso14443b.h" -extern const uint8_t OddByteParity[256]; extern int rsamples; // = 0; extern int tracing; // = TRUE; extern uint8_t trigger; @@ -55,6 +54,7 @@ void Dbhexdump(int len, uint8_t *d, bool bAsci); #define MAX_ADC_LF_VOLTAGE 140800 int AvgAdc(int ch); +void print_result(char *name, uint8_t *buf, size_t len); void PrintToSendBuffer(void); void ToSendStuffBit(int b); void ToSendReset(void); @@ -105,6 +105,9 @@ void AcquireRawAdcSamplesIso14443b(uint32_t parameter); void ReadSTMemoryIso14443b(uint8_t numofblocks); void RAMFUNC SnoopIso14443b(void); void SendRawCommand14443B(uint32_t, uint32_t, uint8_t, uint8_t[]); +void SendRawCommand14443B_Ex(UsbCommand *c); +void AppendCrc14443b(uint8_t* data, int len); +void ClearFpgaShiftingRegisters(void); // iso14443a.h void RAMFUNC SniffIso14443a(uint8_t param); @@ -163,7 +166,6 @@ size_t CreateAPDU( uint8_t *datain, size_t len, uint8_t *dataout); void OnSuccess(); void OnError(uint8_t reason); - // desfire_crypto.h void *mifare_cryto_preprocess_data (desfiretag_t tag, void *data, size_t *nbytes, size_t offset, int communication_settings); void *mifare_cryto_postprocess_data (desfiretag_t tag, void *data, size_t *nbytes, int communication_settings); @@ -223,4 +225,8 @@ void EMVgetUDOL(void); void EMVloadvalue(uint32_t tag, uint8_t* datain); void EMVdumpcard(void); +#ifdef __cplusplus +} +#endif + #endif diff --git a/armsrc/des.c b/armsrc/des.c index 6b3bea9b7..513f89bfe 100644 --- a/armsrc/des.c +++ b/armsrc/des.c @@ -25,8 +25,8 @@ * \license GPLv3 or later * */ -#include -#include + +#include "des.h" const uint8_t sbox[256] = { /* S-box 1 */ diff --git a/armsrc/des.h b/armsrc/des.h index 3379463a6..03b9f6469 100644 --- a/armsrc/des.h +++ b/armsrc/des.h @@ -24,8 +24,11 @@ * \license GPLv3 or later * */ -#ifndef DES_H_ -#define DES_H_ +#ifndef __DES_H_ +#define __DES_H_ + +#include +#include /* the FIPS 46-3 (1999-10-25) name for triple DES is triple data encryption algorithm so TDEA. * Also we only implement the three key mode */ @@ -67,7 +70,8 @@ void des_enc(void* out, const void* in, const void* key); * \param in pointer to the block (64 bit = 8 byte) where the ciphertext is read from * \param key pointer to the key (64 bit = 8 byte) */ -void des_dec(void* out, const void* in, const void* key); +//void des_dec(void* out, const void* in, const void* key); +void des_dec(void* out, const void* in, const uint8_t* key); /** \fn void tdes_enc(void* out, const void* in, const void* key) * \brief encrypt a block with Tripple-DES @@ -81,7 +85,8 @@ void des_dec(void* out, const void* in, const void* key); * \param in pointer to the block (64 bit = 8 byte) where the plaintext is read from * \param key pointer to the key (192 bit = 24 byte) */ -void tdes_enc(void* out, const void* in, const void* key); +//void tdes_enc(void* out, const void* in, const void* key); +void tdes_enc(void* out, void* in, const void* key); /** \fn void tdes_dec(void* out, const void* in, const void* key) * \brief decrypt a block with Tripple-DES @@ -95,19 +100,16 @@ void tdes_enc(void* out, const void* in, const void* key); * \param in pointer to the block (64 bit = 8 byte) where the ciphertext is read from * \param key pointer to the key (192 bit = 24 byte) */ - void tdes_dec(void* out, const void* in, const void* key); + //void tdes_dec(void* out, const void* in, const void* key); + void tdes_dec(void* out, void* in, const uint8_t* key); void tdes_2key_enc(void* out, const void* in, size_t length, const void* key, unsigned char iv[8]); void tdes_2key_dec(void* out, const void* in, size_t length, const void* key, unsigned char iv[8]); - void tdes_2key_enc(void* out, const void* in, size_t length, const void* key, unsigned char iv[8]); - void tdes_2key_dec(void* out, const void* in, size_t length, const void* key, unsigned char iv[8]); - -#endif /*DES_H_*/ - // Copied from des.h in desfire imp. typedef unsigned long DES_KS[16][2]; /* Single-key DES key schedule */ typedef unsigned long DES3_KS[48][2]; /* Triple-DES key schedule */ - extern int Asmversion; /* 1 if we're linked with an asm version, 0 if C */ + +#endif /*DES_H_*/ diff --git a/armsrc/desfire_crypto.c b/armsrc/desfire_crypto.c index e7eceb3cc..fdb067711 100644 --- a/armsrc/desfire_crypto.c +++ b/armsrc/desfire_crypto.c @@ -89,7 +89,6 @@ void cmac (const desfirekey_t key, uint8_t *ivect, const uint8_t *data, size_t l size_t key_block_size (const desfirekey_t key) { size_t block_size = 8; - switch (key->type) { case T_DES: case T_3DES: @@ -100,7 +99,6 @@ size_t key_block_size (const desfirekey_t key) { block_size = 16; break; } - return block_size; } @@ -109,7 +107,6 @@ size_t key_block_size (const desfirekey_t key) { */ static size_t key_macing_length (const desfirekey_t key) { size_t mac_length = MAC_LENGTH; - switch (key->type) { case T_DES: case T_3DES: @@ -120,7 +117,6 @@ static size_t key_macing_length (const desfirekey_t key) { mac_length = CMAC_LENGTH; break; } - return mac_length; } @@ -459,7 +455,7 @@ void* mifare_cryto_postprocess_data (desfiretag_t tag, void *data, size_t *nbyte break; case AS_NEW: end_crc_pos = crc_pos + 4; - crc32 (res, end_crc_pos, (uint8_t *)&crc); + crc32_ex (res, end_crc_pos, (uint8_t *)&crc); break; } if (!crc) { diff --git a/armsrc/desfire_crypto.h b/armsrc/desfire_crypto.h index df5a68877..7be85bfba 100644 --- a/armsrc/desfire_crypto.h +++ b/armsrc/desfire_crypto.h @@ -1,12 +1,19 @@ #ifndef __DESFIRE_CRYPTO_H #define __DESFIRE_CRYPTO_H +#ifdef __cplusplus +extern "C" { +#endif + #include -#include +//#include "apps.h" +#include "crc32.h" #include "printf.h" +#include "desfire.h" #include "iso14443a.h" -#include "../common/desfire.h" -#include "des.h" -//#include "aes.h" + +#ifdef __cplusplus +} +#endif #endif diff --git a/armsrc/desfire_key.h b/armsrc/desfire_key.h index df932643f..4e6fdaea9 100644 --- a/armsrc/desfire_key.h +++ b/armsrc/desfire_key.h @@ -3,8 +3,9 @@ #include #include +#include "iso14443a.h" #include "desfire.h" -#include "iso14443a.h" //test +//#include "mifare.h" // iso14a_card_select_t struct void Desfire_des_key_new (const uint8_t value[8], desfirekey_t key); void Desfire_3des_key_new (const uint8_t value[16], desfirekey_t key); void Desfire_des_key_new_with_version (const uint8_t value[8], desfirekey_t key); diff --git a/armsrc/emvcmd.c b/armsrc/emvcmd.c index 3549d0e3d..4a58e25af 100644 --- a/armsrc/emvcmd.c +++ b/armsrc/emvcmd.c @@ -8,13 +8,7 @@ //-------------------------------------------------------------------------------- //Routines to support EMV transactions //-------------------------------------------------------------------------------- - -#include "mifare.h" -#include "iso14443a.h" -#include "emvutil.h" #include "emvcmd.h" -#include "apps.h" -#include "emvdataels.h" static emvtags currentcard; //use to hold emv tags for the reader/card during communications static tUart Uart; diff --git a/armsrc/emvcmd.h b/armsrc/emvcmd.h index 070eb586c..811953421 100644 --- a/armsrc/emvcmd.h +++ b/armsrc/emvcmd.h @@ -11,15 +11,18 @@ #ifndef __EMVCMD_H #define __EMVCMD_H + #include "proxmark3.h" +#include "common.h" #include "apps.h" #include "util.h" #include "string.h" - #include "iso14443crc.h" #include "iso14443a.h" -#include "common.h" +#include "mifare.h" +#include "emvcmd.h" #include "emvutil.h" +#include "emvdataels.h" #include "emvcard.h" #define VISA_DCVV 0 diff --git a/armsrc/emvdataels.c b/armsrc/emvdataels.c index 3db9ee782..da64a6f47 100644 --- a/armsrc/emvdataels.c +++ b/armsrc/emvdataels.c @@ -1,16 +1,13 @@ // ICEMAN 2017, this file looks similar to emvdataels.h headerfile. - //Data elements for EMV transactions. -#ifndef __EMVDATAELS_H -#define __EMVDATAELS_H #include "emvdataels.h" -//Known AIDs -typedef struct{ -uint8_t tag[2]; -char description[255]; -} tagdescription; +//Known AIDs +struct tagdescription { + uint8_t tag[2]; + char description[255]; +}; const uint8_t AID_VISA[] = {0xa0,0x00,0x00,0x00,0x03}; const uint8_t AID_VISA_DB[] = {0xa0,0x00,0x00,0x00,0x03,0x10,0x10}; @@ -111,18 +108,3 @@ const tagdescription EMV_TAG_LIST[] = { {"\x9f\x66","card production life cycle"}, {"\xbf\x0c","file control information (fci) issuer discretionary data"} }; - -//AIP bitmasks details -#define AIP_CHIP_SUPPORTED 0x80 -#define AIP_MSR_SUPPORTED 0x40 - -#define AIP_SDA_SUPPORTED 0x40 -#define AIP_DDA_SUPPORTED 0x20 -#define AIP_CARDHOLDER_VERIFICATION 0x10 -#define AIP_TERMINAL_RISK 0x08 -#define AIP_ISSUER_AUTH 0x04 -#define AIP_CDA_SUPPORTED 0x01 - -//human readable error messages - -#endif //__EMVDATAELS_H diff --git a/armsrc/emvdataels.h b/armsrc/emvdataels.h index d88b8797e..ad46e9f4b 100644 --- a/armsrc/emvdataels.h +++ b/armsrc/emvdataels.h @@ -4,6 +4,8 @@ #include +typedef struct tagdescription tagdescription; + //Known AIDs extern const uint8_t AID_VISA[5]; extern const uint8_t AID_VISA_DB[7] ; @@ -25,12 +27,6 @@ extern const uint8_t AID_ALIAS[7]; //Master data file for PSE extern const uint8_t DF_PSE[]; - -typedef struct{ - uint8_t tag[2]; - char description[255]; -} tagdescription; - extern const tagdescription EMV_TAG_LIST[62]; //SW1 return values extern const uint8_t SW1_RESPONSE_BYTES[]; extern const uint8_t SW1_WRONG_LENGTH[] ; diff --git a/armsrc/emvutil.c b/armsrc/emvutil.c index e35cb1efe..c4c296133 100644 --- a/armsrc/emvutil.c +++ b/armsrc/emvutil.c @@ -8,19 +8,7 @@ //----------------------------------------------------------------------------- // various EMV related functions. //----------------------------------------------------------------------------- -#include -#include "proxmark3.h" -#include "apps.h" -#include "util.h" -#include "string.h" - -#include "BigBuf.h" - -#include "iso14443crc.h" -#include "iso14443a.h" #include "emvutil.h" -#include "emvdataels.h" //EMV data elements -#include "emvtags.h" //EMV card structure #define DUMP(varname) Dbprintf("%s=", #varname); diff --git a/armsrc/emvutil.h b/armsrc/emvutil.h index 6fe748ddf..bd5ec4fef 100644 --- a/armsrc/emvutil.h +++ b/armsrc/emvutil.h @@ -11,12 +11,21 @@ //----------------------------------------------------------------------------- #ifndef __EMVUTIL_H #define __EMVUTIL_H + #include #include -#include "iso14443a.h" +#include "proxmark3.h" +#include "apps.h" #include "tlv.h" -#include "emvtags.h" -#include "emvdataels.h" +#include "util.h" +#include "string.h" +#include "BigBuf.h" +#include "iso14443crc.h" +#include "iso14443a.h" +#include "emvutil.h" +#include "emvdataels.h" //EMV data elements +#include "emvtags.h" //EMV card structure + // mifare 4bit card answers // reader voltage field detector #define EMV_MINFIELDV 4000 diff --git a/armsrc/iclass.c b/armsrc/iclass.c index 01693dcad..f5e821cb3 100644 --- a/armsrc/iclass.c +++ b/armsrc/iclass.c @@ -36,11 +36,7 @@ // //----------------------------------------------------------------------------- -#include "proxmark3.h" #include "apps.h" -#include "util.h" -#include "string.h" -#include "common.h" #include "cmd.h" // Needed for CRC in emulation mode; // same construction as in ISO 14443; @@ -52,7 +48,6 @@ static int timeout = 4096; - static int SendIClassAnswer(uint8_t *resp, int respLen, int delay); //----------------------------------------------------------------------------- @@ -63,7 +58,7 @@ static struct { enum { STATE_UNSYNCD, STATE_START_OF_COMMUNICATION, - STATE_RECEIVING + STATE_RECEIVING } state; uint16_t shiftReg; int bitCnt; diff --git a/armsrc/iso14443a.h b/armsrc/iso14443a.h index 3dec61222..2128f6ec5 100644 --- a/armsrc/iso14443a.h +++ b/armsrc/iso14443a.h @@ -12,24 +12,20 @@ #ifndef __ISO14443A_H #define __ISO14443A_H -#include "common.h" -#include "proxmark3.h" -#include "apps.h" -#include "util.h" -#include "string.h" -#include "cmd.h" -#include "iso14443crc.h" -#include "mifaresniff.h" -#include "iso14443b.h" -#include "crapto1.h" -#include "mifareutil.h" -#include "BigBuf.h" -#include "parity.h" #ifdef __cplusplus extern "C" { #endif +#include "cmd.h" +#include "apps.h" +#include "util.h" +#include "string.h" +#include "iso14443crc.h" +#include "mifaresniff.h" +#include "crapto1.h" +#include "mifareutil.h" +#include "parity.h" typedef struct { enum { diff --git a/armsrc/iso14443b.h b/armsrc/iso14443b.h index f2cf74a56..885d8730c 100644 --- a/armsrc/iso14443b.h +++ b/armsrc/iso14443b.h @@ -13,8 +13,12 @@ #ifndef __ISO14443B_H #define __ISO14443B_H +#ifdef __cplusplus +extern "C" { +#endif + #include "proxmark3.h" -#include "common.h" +#include "common.h" // access to global variable: MF_DBGLEVEL #include "apps.h" #include "util.h" #include "string.h" @@ -22,11 +26,7 @@ #include "mifare.h" #include "protocols.h" -#include "mifareutil.h" // access to global variable: MF_DBGLEVEL - -#ifdef __cplusplus -extern "C" { -#endif +//#include "mifareutil.h" extern void AppendCrc14443b(uint8_t *data, int len); void SendRawCommand14443B_Ex(UsbCommand *c); diff --git a/armsrc/lfsampling.c b/armsrc/lfsampling.c index 94ddc7274..02c0cd4a7 100644 --- a/armsrc/lfsampling.c +++ b/armsrc/lfsampling.c @@ -48,11 +48,11 @@ sample_config* getSamplingConfig() { return &config; } -typedef struct { +struct BitstreamOut { uint8_t * buffer; uint32_t numbits; uint32_t position; -} BitstreamOut; +}; /** * @brief Pushes bit onto the stream @@ -259,7 +259,7 @@ void doT55x7Acquisition(size_t sample_size) { while(!BUTTON_PRESS() && !usb_poll_validate_length() && skipCnt < 1000 && (i < bufsize) ) { WDT_HIT(); if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY) { - AT91C_BASE_SSC->SSC_THR = 0x43; + AT91C_BASE_SSC->SSC_THR = 0x43; //43 LED_D_ON(); } if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) { @@ -275,7 +275,7 @@ void doT55x7Acquisition(size_t sample_size) { skipCnt++; continue; } - // skip until the first Low sample below threshold + // skip until the first low sample below threshold if (!startFound && curSample < T55xx_READ_LOWER_THRESHOLD) { //if (curSample > lastSample) lastSample = curSample; diff --git a/armsrc/lfsampling.h b/armsrc/lfsampling.h index cf1bb45da..b37b786eb 100644 --- a/armsrc/lfsampling.h +++ b/armsrc/lfsampling.h @@ -1,5 +1,5 @@ -#ifndef LFSAMPLING_H -#define LFSAMPLING_H +#ifndef __LFSAMPLING_H +#define __LFSAMPLING_H #include "proxmark3.h" #include "apps.h" @@ -8,6 +8,8 @@ #include "usb_cdc.h" // for usb_poll_validate_length #include "ticks.h" // for StartTicks +typedef struct BitstreamOut BitstreamOut; + /** * acquisition of T55x7 LF signal. Similart to other LF, but adjusted with @marshmellows thresholds * the data is collected in BigBuf. @@ -72,4 +74,4 @@ sample_config * getSamplingConfig(); void printConfig(); -#endif // LFSAMPLING_H +#endif // __LFSAMPLING_H diff --git a/armsrc/mifaredesfire.h b/armsrc/mifaredesfire.h index c17ad1b4b..40c623ef9 100644 --- a/armsrc/mifaredesfire.h +++ b/armsrc/mifaredesfire.h @@ -1,16 +1,14 @@ #ifndef __MIFAREDESFIRE_H #define __MIFAREDESFIRE_H +#include "common.h" #include "proxmark3.h" #include "apps.h" -#include "util.h" #include "string.h" #include "BigBuf.h" #include "iso14443crc.h" #include "iso14443a.h" #include "desfire_key.h" #include "mifareutil.h" -#include "common.h" #include "des.h" - #endif diff --git a/armsrc/mifareutil.c b/armsrc/mifareutil.c index 5dfeeab0a..4795a7ec4 100644 --- a/armsrc/mifareutil.c +++ b/armsrc/mifareutil.c @@ -8,7 +8,6 @@ //----------------------------------------------------------------------------- // Work with mifare cards. //----------------------------------------------------------------------------- - #include "mifareutil.h" int MF_DBGLEVEL = MF_DBG_ALL; @@ -277,7 +276,7 @@ int mifare_ultra_auth(uint8_t *keybytes){ memcpy(enc_random_b,resp+1,8); // decrypt nonce. - tdes_2key_dec(random_b, enc_random_b, sizeof(random_b), key, IV ); + tdes_2key_dec((void*)random_b, (void*)enc_random_b, sizeof(random_b), (const void*)key, IV ); rol(random_b,8); memcpy(rnd_ab ,random_a,8); memcpy(rnd_ab+8,random_b,8); diff --git a/armsrc/mifareutil.h b/armsrc/mifareutil.h index f59ab8068..041da2126 100644 --- a/armsrc/mifareutil.h +++ b/armsrc/mifareutil.h @@ -12,16 +12,15 @@ #ifndef __MIFAREUTIL_H #define __MIFAREUTIL_H - #include "proxmark3.h" #include "apps.h" +#include "parity.h" #include "util.h" #include "string.h" #include "iso14443crc.h" #include "iso14443a.h" #include "crapto1.h" -#include "parity.h" -//#include "des.h" +#include "des.h" // mifare authentication #define CRYPT_NONE 0 @@ -30,18 +29,6 @@ #define AUTH_FIRST 0 #define AUTH_NESTED 2 -// reader voltage field detector -#define MF_MINFIELDV 4000 - -// debug -// 0 - no debug messages 1 - error messages 2 - all messages 4 - extended debug mode -#define MF_DBG_NONE 0 -#define MF_DBG_ERROR 1 -#define MF_DBG_ALL 2 -#define MF_DBG_EXTENDED 4 - -extern int MF_DBGLEVEL; - //mifare emulator states #define MFEMUL_NOFIELD 0 #define MFEMUL_IDLE 1 diff --git a/armsrc/start.c b/armsrc/start.c index f1e58ab0e..d2e4ed4c4 100644 --- a/armsrc/start.c +++ b/armsrc/start.c @@ -9,6 +9,9 @@ // with the linker script. //----------------------------------------------------------------------------- +#ifndef __START_H +#define __START_H + #include "proxmark3.h" #include "apps.h" #include "zlib.h" @@ -18,7 +21,6 @@ static uint8_t *next_free_memory; extern struct common_area common_area; extern char __data_src_start__, __data_start__, __data_end__, __bss_start__, __bss_end__; - static voidpf inflate_malloc(voidpf opaque, uInt items, uInt size) { uint8_t *allocated_memory; @@ -28,11 +30,9 @@ static voidpf inflate_malloc(voidpf opaque, uInt items, uInt size) return allocated_memory; } - static void inflate_free(voidpf opaque, voidpf address) { // nothing to do - } static void uncompress_data_section(void) @@ -60,7 +60,6 @@ static void uncompress_data_section(void) common_area.arg1 = data_section.total_in; } - void __attribute__((section(".startos"))) Vector(void) { /* Stack should have been set up by the bootloader */ @@ -80,6 +79,6 @@ void __attribute__((section(".startos"))) Vector(void) // end = &__data_end__; // while(dst < end) *dst++ = *src++; - AppMain(); } +#endif \ No newline at end of file diff --git a/armsrc/util.c b/armsrc/util.c index 10c056559..cef643576 100644 --- a/armsrc/util.c +++ b/armsrc/util.c @@ -9,28 +9,6 @@ //----------------------------------------------------------------------------- #include "util.h" -void print_result(char *name, uint8_t *buf, size_t len) { - uint8_t *p = buf; - - if ( len % 16 == 0 ) { - for(; p-buf < len; p += 16) - Dbprintf("[%s:%d/%d] %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", - name, - p-buf, - len, - p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15] - ); - } - else { - for(; p-buf < len; p += 8) - Dbprintf("[%s:%d/%d] %02x %02x %02x %02x %02x %02x %02x %02x", - name, - p-buf, - len, - p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); - } -} - size_t nbytes(size_t nbits) { return (nbits >> 3)+((nbits % 8) > 0); } diff --git a/armsrc/util.h b/armsrc/util.h index d32352922..12840d6b0 100644 --- a/armsrc/util.h +++ b/armsrc/util.h @@ -11,13 +11,10 @@ #ifndef __UTIL_H #define __UTIL_H -#include -#include #include "common.h" -#include "string.h" -#include "apps.h" -#include "BigBuf.h" #include "proxmark3.h" +#include "string.h" +#include "BigBuf.h" #include "ticks.h" #define BYTEx(x, n) (((x) >> (n * 8)) & 0xff ) @@ -42,7 +39,6 @@ # define ARRAYLEN(x) (sizeof(x)/sizeof((x)[0])) #endif -void print_result(char *name, uint8_t *buf, size_t len); size_t nbytes(size_t nbits); uint32_t SwapBits(uint32_t value, int nrbits); uint32_t reflect(uint32_t v, int b); diff --git a/include/common.h b/include/common.h index 2a67bd879..3a253b9ca 100644 --- a/include/common.h +++ b/include/common.h @@ -18,6 +18,18 @@ #include typedef unsigned char byte_t; +// debug +// 0 - no debug messages 1 - error messages 2 - all messages 4 - extended debug mode +#define MF_DBG_NONE 0 +#define MF_DBG_ERROR 1 +#define MF_DBG_ALL 2 +#define MF_DBG_EXTENDED 4 +extern int MF_DBGLEVEL; + +// reader voltage field detector +#define MF_MINFIELDV 4000 + + #ifndef MIN # define MIN(a, b) (((a) < (b)) ? (a) : (b)) #endif