#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
#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
$(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
// executes.
//-----------------------------------------------------------------------------
#include "usb_cdc.h"
-//#include "cmd.h"
#include "proxmark3.h"
#include "apps.h"
#include "util.h"
#include "printf.h"
#include "string.h"
-#include <stdarg.h>
#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"
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.
//=============================================================================
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;
#ifndef __APPS_H
#define __APPS_H
-#include <stdint.h>
-#include <stddef.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#include <stdlib.h>
-//#include <sys/types.h>
+#include <stdarg.h>
#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;
#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);
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);
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);
void EMVloadvalue(uint32_t tag, uint8_t* datain);
void EMVdumpcard(void);
+#ifdef __cplusplus
+}
+#endif
+
#endif
* \license GPLv3 or later
*
*/
-#include <stdint.h>
-#include <string.h>
+
+#include "des.h"
const uint8_t sbox[256] = {
/* S-box 1 */
* \license GPLv3 or later
*
*/
-#ifndef DES_H_
-#define DES_H_
+#ifndef __DES_H_
+#define __DES_H_
+
+#include <stdint.h>
+#include <string.h>
/* 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 */
* \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
* \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
* \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_*/
size_t key_block_size (const desfirekey_t key) {
size_t block_size = 8;
-
switch (key->type) {
case T_DES:
case T_3DES:
block_size = 16;
break;
}
-
return block_size;
}
*/
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:
mac_length = CMAC_LENGTH;
break;
}
-
return mac_length;
}
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) {
#ifndef __DESFIRE_CRYPTO_H
#define __DESFIRE_CRYPTO_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#include <string.h>
-#include <stdarg.h>
+//#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
#include <stdlib.h>
#include <stdint.h>
+#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);
//--------------------------------------------------------------------------------
//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;
#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
// 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};
{"\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
#include <stdint.h>
+typedef struct tagdescription tagdescription;
+
//Known AIDs
extern const uint8_t AID_VISA[5];
extern const uint8_t AID_VISA_DB[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[] ;
//-----------------------------------------------------------------------------
// various EMV related functions.
//-----------------------------------------------------------------------------
-#include <stdarg.h>
-#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);
//-----------------------------------------------------------------------------
#ifndef __EMVUTIL_H
#define __EMVUTIL_H
+
#include <stdarg.h>
#include <stdint.h>
-#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
//
//-----------------------------------------------------------------------------
-#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;
static int timeout = 4096;
-
static int SendIClassAnswer(uint8_t *resp, int respLen, int delay);
//-----------------------------------------------------------------------------
enum {
STATE_UNSYNCD,
STATE_START_OF_COMMUNICATION,
- STATE_RECEIVING
+ STATE_RECEIVING
} state;
uint16_t shiftReg;
int bitCnt;
#ifndef __ISO14443A_H
#define __ISO14443A_H
-#include "common.h"
-#include "proxmark3.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "cmd.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
-
-
typedef struct {
enum {
DEMOD_UNSYNCD,
#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"
#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);
return &config;
}
-typedef struct {
+struct BitstreamOut {
uint8_t * buffer;
uint32_t numbits;
uint32_t position;
-} BitstreamOut;
+};
/**
* @brief Pushes bit onto the stream
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) {
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;
-#ifndef LFSAMPLING_H
-#define LFSAMPLING_H
+#ifndef __LFSAMPLING_H
+#define __LFSAMPLING_H
#include "proxmark3.h"
#include "apps.h"
#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.
void printConfig();
-#endif // LFSAMPLING_H
+#endif // __LFSAMPLING_H
#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
//-----------------------------------------------------------------------------\r
// Work with mifare cards.\r
//-----------------------------------------------------------------------------\r
-\r
#include "mifareutil.h"\r
\r
int MF_DBGLEVEL = MF_DBG_ALL;\r
memcpy(enc_random_b,resp+1,8);\r
\r
// decrypt nonce.\r
- tdes_2key_dec(random_b, enc_random_b, sizeof(random_b), key, IV );\r
+ tdes_2key_dec((void*)random_b, (void*)enc_random_b, sizeof(random_b), (const void*)key, IV );\r
rol(random_b,8);\r
memcpy(rnd_ab ,random_a,8);\r
memcpy(rnd_ab+8,random_b,8);\r
#ifndef __MIFAREUTIL_H\r
#define __MIFAREUTIL_H\r
\r
-\r
#include "proxmark3.h"\r
#include "apps.h"\r
+#include "parity.h"\r
#include "util.h"\r
#include "string.h"\r
#include "iso14443crc.h"\r
#include "iso14443a.h"\r
#include "crapto1.h"\r
-#include "parity.h"\r
-//#include "des.h"\r
+#include "des.h"\r
\r
// mifare authentication\r
#define CRYPT_NONE 0\r
#define AUTH_FIRST 0 \r
#define AUTH_NESTED 2\r
\r
-// reader voltage field detector\r
-#define MF_MINFIELDV 4000\r
-\r
-// debug\r
-// 0 - no debug messages 1 - error messages 2 - all messages 4 - extended debug mode\r
-#define MF_DBG_NONE 0\r
-#define MF_DBG_ERROR 1\r
-#define MF_DBG_ALL 2\r
-#define MF_DBG_EXTENDED 4\r
-\r
-extern int MF_DBGLEVEL;\r
-\r
//mifare emulator states\r
#define MFEMUL_NOFIELD 0\r
#define MFEMUL_IDLE 1\r
// with the linker script.
//-----------------------------------------------------------------------------
+#ifndef __START_H
+#define __START_H
+
#include "proxmark3.h"
#include "apps.h"
#include "zlib.h"
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;
return allocated_memory;
}
-
static void inflate_free(voidpf opaque, voidpf address)
{
// nothing to do
-
}
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 */
// end = &__data_end__;
// while(dst < end) *dst++ = *src++;
-
AppMain();
}
+#endif
\ No newline at end of file
//-----------------------------------------------------------------------------
#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);
}
#ifndef __UTIL_H
#define __UTIL_H
-#include <stddef.h>
-#include <stdint.h>
#include "common.h"
+#include "proxmark3.h"
#include "string.h"
-#include "apps.h"
#include "BigBuf.h"
-#include "proxmark3.h"
#include "ticks.h"
#define BYTEx(x, n) (((x) >> (n * 8)) & 0xff )
# 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);
#include <at91sam7s512.h>
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