mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2026-05-12 11:18:11 -07:00
make style
This commit is contained in:
@@ -90,6 +90,11 @@ print-%: ; @echo $* = $($*)
|
||||
|
||||
style:
|
||||
find . \( -name "*.[ch]" -or -name "*.cpp" -or -name "*.lua" \) -exec perl -pi -e 's/[ \t\r]+$$//' {} \;
|
||||
find . \( -name "*.[ch]" -or -name "*.cpp" \) -exec astyle --formatted --mode=c --suffix=none \
|
||||
--indent=spaces=4 --indent-switches --indent-preprocessor \
|
||||
--keep-one-line-blocks --max-instatement-indent=60 \
|
||||
--style=linux --pad-oper --unpad-paren --pad-header \
|
||||
--align-pointer=name {} \;
|
||||
|
||||
# Dummy target to test for GNU make availability
|
||||
_test:
|
||||
|
||||
+42
-23
@@ -13,7 +13,7 @@
|
||||
// BigBuf is the large multi-purpose buffer, typically used to hold A/D samples or traces.
|
||||
// Also used to hold various smaller buffers and the Mifare Emulator Memory.
|
||||
// declare it as uint32_t to achieve alignment to 4 Byte boundary
|
||||
static uint32_t BigBuf[BIGBUF_SIZE/sizeof(uint32_t)];
|
||||
static uint32_t BigBuf[BIGBUF_SIZE / sizeof(uint32_t)];
|
||||
|
||||
/* BigBuf memory layout:
|
||||
Pointer to highest available memory: BigBuf_hi
|
||||
@@ -34,12 +34,14 @@ static uint32_t traceLen = 0;
|
||||
static bool tracing = true; //todo static?
|
||||
|
||||
// get the address of BigBuf
|
||||
uint8_t *BigBuf_get_addr(void) {
|
||||
uint8_t *BigBuf_get_addr(void)
|
||||
{
|
||||
return (uint8_t *)BigBuf;
|
||||
}
|
||||
|
||||
// get the address of the emulator memory. Allocate part of Bigbuf for it, if not yet done
|
||||
uint8_t *BigBuf_get_EM_addr(void) {
|
||||
uint8_t *BigBuf_get_EM_addr(void)
|
||||
{
|
||||
// not yet allocated
|
||||
if (emulator_memory == NULL)
|
||||
emulator_memory = BigBuf_malloc(CARD_MEMORY_SIZE);
|
||||
@@ -48,28 +50,33 @@ uint8_t *BigBuf_get_EM_addr(void) {
|
||||
}
|
||||
|
||||
// clear ALL of BigBuf
|
||||
void BigBuf_Clear(void) {
|
||||
void BigBuf_Clear(void)
|
||||
{
|
||||
BigBuf_Clear_ext(true);
|
||||
}
|
||||
|
||||
// clear ALL of BigBuf
|
||||
void BigBuf_Clear_ext(bool verbose) {
|
||||
void BigBuf_Clear_ext(bool verbose)
|
||||
{
|
||||
memset(BigBuf, 0, BIGBUF_SIZE);
|
||||
if (verbose)
|
||||
Dbprintf("Buffer cleared (%i bytes)", BIGBUF_SIZE);
|
||||
}
|
||||
|
||||
void BigBuf_Clear_EM(void) {
|
||||
void BigBuf_Clear_EM(void)
|
||||
{
|
||||
memset(BigBuf_get_EM_addr(), 0, CARD_MEMORY_SIZE);
|
||||
}
|
||||
|
||||
void BigBuf_Clear_keep_EM(void) {
|
||||
void BigBuf_Clear_keep_EM(void)
|
||||
{
|
||||
memset(BigBuf, 0, BigBuf_hi);
|
||||
}
|
||||
|
||||
// allocate a chunk of memory from BigBuf. We allocate high memory first. The unallocated memory
|
||||
// at the beginning of BigBuf is always for traces/samples
|
||||
uint8_t *BigBuf_malloc(uint16_t chunksize) {
|
||||
uint8_t *BigBuf_malloc(uint16_t chunksize)
|
||||
{
|
||||
if (BigBuf_hi - chunksize < 0)
|
||||
return NULL; // no memory left
|
||||
|
||||
@@ -79,14 +86,16 @@ uint8_t *BigBuf_malloc(uint16_t chunksize) {
|
||||
}
|
||||
|
||||
// free ALL allocated chunks. The whole BigBuf is available for traces or samples again.
|
||||
void BigBuf_free(void){
|
||||
void BigBuf_free(void)
|
||||
{
|
||||
BigBuf_hi = BIGBUF_SIZE;
|
||||
emulator_memory = NULL;
|
||||
// shouldn't this empty BigBuf also?
|
||||
}
|
||||
|
||||
// free allocated chunks EXCEPT the emulator memory
|
||||
void BigBuf_free_keep_EM(void) {
|
||||
void BigBuf_free_keep_EM(void)
|
||||
{
|
||||
if (emulator_memory != NULL)
|
||||
BigBuf_hi = emulator_memory - (uint8_t *)BigBuf;
|
||||
else
|
||||
@@ -95,7 +104,8 @@ void BigBuf_free_keep_EM(void) {
|
||||
// shouldn't this empty BigBuf also?
|
||||
}
|
||||
|
||||
void BigBuf_print_status(void) {
|
||||
void BigBuf_print_status(void)
|
||||
{
|
||||
Dbprintf("Memory");
|
||||
Dbprintf(" BIGBUF_SIZE.............%d", BIGBUF_SIZE);
|
||||
Dbprintf(" Available memory........%d", BigBuf_hi);
|
||||
@@ -105,21 +115,26 @@ void BigBuf_print_status(void) {
|
||||
}
|
||||
|
||||
// return the maximum trace length (i.e. the unallocated size of BigBuf)
|
||||
uint16_t BigBuf_max_traceLen(void) {
|
||||
uint16_t BigBuf_max_traceLen(void)
|
||||
{
|
||||
return BigBuf_hi;
|
||||
}
|
||||
|
||||
void clear_trace(void) {
|
||||
void clear_trace(void)
|
||||
{
|
||||
traceLen = 0;
|
||||
}
|
||||
void set_tracelen(uint32_t value) {
|
||||
void set_tracelen(uint32_t value)
|
||||
{
|
||||
traceLen = value;
|
||||
}
|
||||
void set_tracing(bool enable) {
|
||||
void set_tracing(bool enable)
|
||||
{
|
||||
tracing = enable;
|
||||
}
|
||||
|
||||
bool get_tracing(void) {
|
||||
bool get_tracing(void)
|
||||
{
|
||||
return tracing;
|
||||
}
|
||||
|
||||
@@ -127,7 +142,8 @@ bool get_tracing(void) {
|
||||
* Get the number of bytes traced
|
||||
* @return
|
||||
*/
|
||||
uint32_t BigBuf_get_traceLen(void) {
|
||||
uint32_t BigBuf_get_traceLen(void)
|
||||
{
|
||||
return traceLen;
|
||||
}
|
||||
|
||||
@@ -137,12 +153,13 @@ uint32_t BigBuf_get_traceLen(void) {
|
||||
by 'hf list raw', alternatively 'hf list <proto>' for protocol-specific
|
||||
annotation of commands/responses.
|
||||
**/
|
||||
bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_start, uint32_t timestamp_end, uint8_t *parity, bool readerToTag) {
|
||||
bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_start, uint32_t timestamp_end, uint8_t *parity, bool readerToTag)
|
||||
{
|
||||
if (!tracing) return false;
|
||||
|
||||
uint8_t *trace = BigBuf_get_addr();
|
||||
|
||||
uint32_t num_paritybytes = (iLen-1)/8 + 1; // number of valid paritybytes in *parity
|
||||
uint32_t num_paritybytes = (iLen - 1) / 8 + 1; // number of valid paritybytes in *parity
|
||||
uint32_t duration = timestamp_end - timestamp_start;
|
||||
|
||||
// Return when trace is full
|
||||
@@ -195,7 +212,8 @@ bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_
|
||||
return true;
|
||||
}
|
||||
|
||||
int LogTraceHitag(const uint8_t * btBytes, int iBits, int iSamples, uint32_t dwParity, int readerToTag) {
|
||||
int LogTraceHitag(const uint8_t *btBytes, int iBits, int iSamples, uint32_t dwParity, int readerToTag)
|
||||
{
|
||||
/**
|
||||
Todo, rewrite the logger to use the generic functionality instead. It should be noted, however,
|
||||
that this logger takes number of bits as argument, not number of bytes.
|
||||
@@ -237,10 +255,11 @@ int LogTraceHitag(const uint8_t * btBytes, int iBits, int iSamples, uint32_t dwP
|
||||
}
|
||||
|
||||
// Emulator memory
|
||||
uint8_t emlSet(uint8_t *data, uint32_t offset, uint32_t length){
|
||||
uint8_t* mem = BigBuf_get_EM_addr();
|
||||
uint8_t emlSet(uint8_t *data, uint32_t offset, uint32_t length)
|
||||
{
|
||||
uint8_t *mem = BigBuf_get_EM_addr();
|
||||
if (offset + length < CARD_MEMORY_SIZE) {
|
||||
memcpy(mem+offset, data, length);
|
||||
memcpy(mem + offset, data, length);
|
||||
return 0;
|
||||
}
|
||||
Dbprintf("Error, trying to set memory outside of bounds! %d > %d", (offset + length), CARD_MEMORY_SIZE);
|
||||
|
||||
+1
-1
@@ -42,6 +42,6 @@ extern void set_tracing(bool enable);
|
||||
extern void set_tracelen(uint32_t value);
|
||||
extern bool get_tracing(void);
|
||||
extern bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_start, uint32_t timestamp_end, uint8_t *parity, bool readerToTag);
|
||||
extern int LogTraceHitag(const uint8_t * btBytes, int iBits, int iSamples, uint32_t dwParity, int bReader);
|
||||
extern int LogTraceHitag(const uint8_t *btBytes, int iBits, int iSamples, uint32_t dwParity, int bReader);
|
||||
extern uint8_t emlSet(uint8_t *data, uint32_t offset, uint32_t length);
|
||||
#endif /* __BIGBUF_H */
|
||||
|
||||
+40
-42
@@ -13,7 +13,7 @@ void LCDSend(unsigned int data)
|
||||
while ((AT91C_BASE_SPI->SPI_SR & AT91C_SPI_TXEMPTY) == 0); // wait for the transfer to complete
|
||||
// For clarity's sake we pass data with 9th bit clear and commands with 9th
|
||||
// bit set since they're implemented as defines, se we need to invert bit
|
||||
AT91C_BASE_SPI->SPI_TDR = data^0x100; // Send the data/command
|
||||
AT91C_BASE_SPI->SPI_TDR = data ^ 0x100; // Send the data/command
|
||||
}
|
||||
|
||||
void LCDSetXY(unsigned char x, unsigned char y)
|
||||
@@ -29,29 +29,28 @@ void LCDSetXY(unsigned char x, unsigned char y)
|
||||
|
||||
void LCDSetPixel(unsigned char x, unsigned char y, unsigned char color)
|
||||
{
|
||||
LCDSetXY(x,y); // Set position
|
||||
LCDSetXY(x, y); // Set position
|
||||
LCDSend(PRAMWR); // Now write the pixel to the display
|
||||
LCDSend(color); // Write the data in the specified Color
|
||||
}
|
||||
|
||||
void LCDFill (unsigned char xs,unsigned char ys,unsigned char width,unsigned char height, unsigned char color)
|
||||
void LCDFill(unsigned char xs, unsigned char ys, unsigned char width, unsigned char height, unsigned char color)
|
||||
{
|
||||
unsigned char i,j;
|
||||
unsigned char i, j;
|
||||
|
||||
for (i=0;i < height;i++) // Number of horizontal lines
|
||||
{
|
||||
LCDSetXY(xs,ys+i); // Goto start of fill area (Top Left)
|
||||
for (i = 0; i < height; i++) { // Number of horizontal lines
|
||||
LCDSetXY(xs, ys + i); // Goto start of fill area (Top Left)
|
||||
LCDSend(PRAMWR); // Write to display
|
||||
|
||||
for (j=0;j < width;j++) // pixels per line
|
||||
for (j = 0; j < width; j++) // pixels per line
|
||||
LCDSend(color);
|
||||
}
|
||||
}
|
||||
|
||||
void LCDString (char *lcd_string, const char *font_style,unsigned char x, unsigned char y, unsigned char fcolor, unsigned char bcolor)
|
||||
void LCDString(char *lcd_string, const char *font_style, unsigned char x, unsigned char y, unsigned char fcolor, unsigned char bcolor)
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned char mask=0, px, py, xme, yme, offset;
|
||||
unsigned char mask = 0, px, py, xme, yme, offset;
|
||||
const char *data;
|
||||
|
||||
data = font_style; // point to the start of the font table
|
||||
@@ -62,29 +61,28 @@ void LCDString (char *lcd_string, const char *font_style,unsigned char x, unsign
|
||||
data++;
|
||||
offset = *data; // get data bytes per font
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
// point to data in table to be loaded
|
||||
data = (font_style + offset) + (offset * (int)(*lcd_string - 32));
|
||||
data = (font_style + offset) + (offset * (int)(*lcd_string - 32));
|
||||
|
||||
for (i=0;i < yme;i++) {
|
||||
mask |=0x80;
|
||||
for (i = 0; i < yme; i++) {
|
||||
mask |= 0x80;
|
||||
|
||||
for (px=x; px < (x + xme); px++) {
|
||||
py= y + i;
|
||||
for (px = x; px < (x + xme); px++) {
|
||||
py = y + i;
|
||||
|
||||
if (*data & mask) LCDSetPixel (px,py,fcolor);
|
||||
else LCDSetPixel (px,py,bcolor);
|
||||
if (*data & mask) LCDSetPixel(px, py, fcolor);
|
||||
else LCDSetPixel(px, py, bcolor);
|
||||
|
||||
mask>>=1;
|
||||
mask >>= 1;
|
||||
}
|
||||
data++;
|
||||
}
|
||||
x+=xme;
|
||||
x += xme;
|
||||
|
||||
lcd_string++; // next character in string
|
||||
|
||||
} while(*lcd_string !='\0'); // keep spitting chars out until end of string
|
||||
} while (*lcd_string != '\0'); // keep spitting chars out until end of string
|
||||
}
|
||||
|
||||
void LCDReset(void)
|
||||
@@ -121,29 +119,29 @@ void LCDInit(void)
|
||||
LCDSend(0xDC);
|
||||
|
||||
// clear display
|
||||
LCDSetXY(0,0);
|
||||
LCDSetXY(0, 0);
|
||||
LCDSend(PRAMWR); // Write to display
|
||||
i=LCD_XRES*LCD_YRES;
|
||||
while(i--) LCDSend(WHITE);
|
||||
i = LCD_XRES * LCD_YRES;
|
||||
while (i--) LCDSend(WHITE);
|
||||
|
||||
// test text on different colored backgrounds
|
||||
LCDString(" The quick brown fox ", (char *)&FONT6x8,1,1+8*0,WHITE ,BLACK );
|
||||
LCDString(" jumped over the ", (char *)&FONT6x8,1,1+8*1,BLACK ,WHITE );
|
||||
LCDString(" lazy dog. ", (char *)&FONT6x8,1,1+8*2,YELLOW ,RED );
|
||||
LCDString(" AaBbCcDdEeFfGgHhIiJj ", (char *)&FONT6x8,1,1+8*3,RED ,GREEN );
|
||||
LCDString(" KkLlMmNnOoPpQqRrSsTt ", (char *)&FONT6x8,1,1+8*4,MAGENTA,BLUE );
|
||||
LCDString("UuVvWwXxYyZz0123456789", (char *)&FONT6x8,1,1+8*5,BLUE ,YELLOW);
|
||||
LCDString("`-=[]_;',./~!@#$%^&*()", (char *)&FONT6x8,1,1+8*6,BLACK ,CYAN );
|
||||
LCDString(" _+{}|:\\\"<>? ", (char *)&FONT6x8,1,1+8*7,BLUE ,MAGENTA);
|
||||
// test text on different colored backgrounds
|
||||
LCDString(" The quick brown fox ", (char *)&FONT6x8, 1, 1 + 8 * 0, WHITE, BLACK);
|
||||
LCDString(" jumped over the ", (char *)&FONT6x8, 1, 1 + 8 * 1, BLACK, WHITE);
|
||||
LCDString(" lazy dog. ", (char *)&FONT6x8, 1, 1 + 8 * 2, YELLOW, RED);
|
||||
LCDString(" AaBbCcDdEeFfGgHhIiJj ", (char *)&FONT6x8, 1, 1 + 8 * 3, RED, GREEN);
|
||||
LCDString(" KkLlMmNnOoPpQqRrSsTt ", (char *)&FONT6x8, 1, 1 + 8 * 4, MAGENTA, BLUE);
|
||||
LCDString("UuVvWwXxYyZz0123456789", (char *)&FONT6x8, 1, 1 + 8 * 5, BLUE, YELLOW);
|
||||
LCDString("`-=[]_;',./~!@#$%^&*()", (char *)&FONT6x8, 1, 1 + 8 * 6, BLACK, CYAN);
|
||||
LCDString(" _+{}|:\\\"<>? ", (char *)&FONT6x8, 1, 1 + 8 * 7, BLUE, MAGENTA);
|
||||
|
||||
// color bands
|
||||
LCDFill(0, 1+8* 8, 132, 8, BLACK);
|
||||
LCDFill(0, 1+8* 9, 132, 8, WHITE);
|
||||
LCDFill(0, 1+8*10, 132, 8, RED);
|
||||
LCDFill(0, 1+8*11, 132, 8, GREEN);
|
||||
LCDFill(0, 1+8*12, 132, 8, BLUE);
|
||||
LCDFill(0, 1+8*13, 132, 8, YELLOW);
|
||||
LCDFill(0, 1+8*14, 132, 8, CYAN);
|
||||
LCDFill(0, 1+8*15, 132, 8, MAGENTA);
|
||||
LCDFill(0, 1 + 8 * 8, 132, 8, BLACK);
|
||||
LCDFill(0, 1 + 8 * 9, 132, 8, WHITE);
|
||||
LCDFill(0, 1 + 8 * 10, 132, 8, RED);
|
||||
LCDFill(0, 1 + 8 * 11, 132, 8, GREEN);
|
||||
LCDFill(0, 1 + 8 * 12, 132, 8, BLUE);
|
||||
LCDFill(0, 1 + 8 * 13, 132, 8, YELLOW);
|
||||
LCDFill(0, 1 + 8 * 14, 132, 8, CYAN);
|
||||
LCDFill(0, 1 + 8 * 15, 132, 8, MAGENTA);
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -124,7 +124,7 @@ void LCDInit(void);
|
||||
void LCDReset(void);
|
||||
void LCDSetXY(unsigned char x, unsigned char y);
|
||||
void LCDSetPixel(unsigned char x, unsigned char y, unsigned char color);
|
||||
void LCDString (char *lcd_string, const char *font_style,unsigned char x, unsigned char y, unsigned char fcolor, unsigned char bcolor);
|
||||
void LCDFill (unsigned char xs,unsigned char ys,unsigned char width,unsigned char height, unsigned char color);
|
||||
void LCDString(char *lcd_string, const char *font_style, unsigned char x, unsigned char y, unsigned char fcolor, unsigned char bcolor);
|
||||
void LCDFill(unsigned char xs, unsigned char ys, unsigned char width, unsigned char height, unsigned char color);
|
||||
|
||||
#endif
|
||||
|
||||
+26
-24
@@ -27,13 +27,13 @@ from the client to view the stored quadlets.
|
||||
// Maximum number of auth attempts per standalone session
|
||||
#define MAX_PWDS_PER_SESSION 64
|
||||
|
||||
uint8_t FindOffsetInFlash() {
|
||||
uint8_t FindOffsetInFlash()
|
||||
{
|
||||
uint8_t mem[4] = { 0x00, 0x00, 0x00, 0x00 };
|
||||
uint8_t eom[4] = { 0xFF, 0xFF, 0xFF, 0xFF };
|
||||
uint8_t memcnt = 0;
|
||||
|
||||
while (memcnt < 0xFF)
|
||||
{
|
||||
while (memcnt < 0xFF) {
|
||||
Flash_ReadData(memcnt, mem, 4);
|
||||
if (memcmp(mem, eom, 4) == 0) {
|
||||
return memcnt;
|
||||
@@ -44,14 +44,15 @@ uint8_t FindOffsetInFlash() {
|
||||
return 0; // wrap-around
|
||||
}
|
||||
|
||||
void EraseMemory() {
|
||||
if (!FlashInit()){
|
||||
void EraseMemory()
|
||||
{
|
||||
if (!FlashInit()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Flash_CheckBusy(BUSY_TIMEOUT);
|
||||
Flash_WriteEnable();
|
||||
Flash_Erase4k(0,0);
|
||||
Flash_Erase4k(0, 0);
|
||||
|
||||
if (MF_DBGLEVEL > 1) Dbprintf("[!] Erased flash!");
|
||||
FlashStop();
|
||||
@@ -59,13 +60,15 @@ void EraseMemory() {
|
||||
}
|
||||
|
||||
// This is actually copied from SniffIso14443a
|
||||
void RAMFUNC SniffAndStore(uint8_t param) {
|
||||
void RAMFUNC SniffAndStore(uint8_t param)
|
||||
{
|
||||
|
||||
iso14443a_setup(FPGA_HF_ISO14443A_SNIFFER);
|
||||
|
||||
// Allocate memory from BigBuf for some buffers
|
||||
// free all previous allocations first
|
||||
BigBuf_free(); BigBuf_Clear_ext(false);
|
||||
BigBuf_free();
|
||||
BigBuf_Clear_ext(false);
|
||||
clear_trace();
|
||||
set_tracing(true);
|
||||
|
||||
@@ -96,13 +99,13 @@ void RAMFUNC SniffAndStore(uint8_t param) {
|
||||
UartInit(receivedCmd, receivedCmdPar);
|
||||
|
||||
// Setup and start DMA.
|
||||
if ( !FpgaSetupSscDma((uint8_t*) dmaBuf, DMA_BUFFER_SIZE) ){
|
||||
if (!FpgaSetupSscDma((uint8_t *) dmaBuf, DMA_BUFFER_SIZE)) {
|
||||
if (MF_DBGLEVEL > 1) Dbprintf("FpgaSetupSscDma failed. Exiting");
|
||||
return;
|
||||
}
|
||||
|
||||
tUart* uart = GetUart();
|
||||
tDemod* demod = GetDemod();
|
||||
tUart *uart = GetUart();
|
||||
tDemod *demod = GetDemod();
|
||||
|
||||
// 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
|
||||
@@ -155,7 +158,7 @@ void RAMFUNC SniffAndStore(uint8_t param) {
|
||||
|
||||
if (!TagIsActive) { // no need to try decoding reader data if the tag is sending
|
||||
uint8_t readerdata = (previous_data & 0xF0) | (*data >> 4);
|
||||
if (MillerDecoding(readerdata, (rsamples-1)*4)) {
|
||||
if (MillerDecoding(readerdata, (rsamples - 1) * 4)) {
|
||||
LED_C_ON();
|
||||
|
||||
// check - if there is a short 7bit request from reader
|
||||
@@ -166,14 +169,14 @@ void RAMFUNC SniffAndStore(uint8_t param) {
|
||||
if (MF_DBGLEVEL > 1) Dbprintf("PWD-AUTH KEY: 0x%02x%02x%02x%02x", receivedCmd[1], receivedCmd[2], receivedCmd[3], receivedCmd[4]);
|
||||
|
||||
// temporarily save the captured pwd in our array
|
||||
memcpy(&capturedPwds[4 * auth_attempts], receivedCmd+1, 4);
|
||||
memcpy(&capturedPwds[4 * auth_attempts], receivedCmd + 1, 4);
|
||||
auth_attempts++;
|
||||
}
|
||||
|
||||
if (!LogTrace(receivedCmd,
|
||||
uart->len,
|
||||
uart->startTime*16 - DELAY_READER_AIR2ARM_AS_SNIFFER,
|
||||
uart->endTime*16 - DELAY_READER_AIR2ARM_AS_SNIFFER,
|
||||
uart->startTime * 16 - DELAY_READER_AIR2ARM_AS_SNIFFER,
|
||||
uart->endTime * 16 - DELAY_READER_AIR2ARM_AS_SNIFFER,
|
||||
uart->parity,
|
||||
true)) break;
|
||||
}
|
||||
@@ -190,13 +193,13 @@ void RAMFUNC SniffAndStore(uint8_t param) {
|
||||
// no need to try decoding tag data if the reader is sending - and we cannot afford the time
|
||||
if (!ReaderIsActive) {
|
||||
uint8_t tagdata = (previous_data << 4) | (*data & 0x0F);
|
||||
if (ManchesterDecoding(tagdata, 0, (rsamples-1)*4)) {
|
||||
if (ManchesterDecoding(tagdata, 0, (rsamples - 1) * 4)) {
|
||||
LED_B_ON();
|
||||
|
||||
if (!LogTrace(receivedResp,
|
||||
demod->len,
|
||||
demod->startTime*16 - DELAY_TAG_AIR2ARM_AS_SNIFFER,
|
||||
demod->endTime*16 - DELAY_TAG_AIR2ARM_AS_SNIFFER,
|
||||
demod->startTime * 16 - DELAY_TAG_AIR2ARM_AS_SNIFFER,
|
||||
demod->endTime * 16 - DELAY_TAG_AIR2ARM_AS_SNIFFER,
|
||||
demod->parity,
|
||||
false)) break;
|
||||
|
||||
@@ -239,8 +242,7 @@ void RAMFUNC SniffAndStore(uint8_t param) {
|
||||
uint8_t memoffset = FindOffsetInFlash();
|
||||
if (MF_DBGLEVEL > 1) Dbprintf("[!] Memory offset = %u", memoffset);
|
||||
|
||||
if ((memoffset + 4 * auth_attempts) > 0xFF)
|
||||
{
|
||||
if ((memoffset + 4 * auth_attempts) > 0xFF) {
|
||||
// We opt to keep the new data only
|
||||
memoffset = 0;
|
||||
if (MF_DBGLEVEL > 1) Dbprintf("[!] Size of total data > 256 bytes. Discarding the old data.");
|
||||
@@ -248,8 +250,7 @@ void RAMFUNC SniffAndStore(uint8_t param) {
|
||||
|
||||
// Get previous data from flash mem
|
||||
uint8_t *previousdata = BigBuf_malloc(memoffset);
|
||||
if (memoffset > 0)
|
||||
{
|
||||
if (memoffset > 0) {
|
||||
uint16_t readlen = Flash_ReadData(0, previousdata, memoffset);
|
||||
if (MF_DBGLEVEL > 1) Dbprintf("[!] Read %u bytes from flash mem", readlen);
|
||||
}
|
||||
@@ -271,7 +272,7 @@ void RAMFUNC SniffAndStore(uint8_t param) {
|
||||
uint16_t writelen = Flash_WriteData(0, total_data, memoffset + 4 * auth_attempts);
|
||||
if (MF_DBGLEVEL > 1) Dbprintf("[!] Wrote %u bytes into flash mem", writelen);
|
||||
|
||||
// If pwd saved successfully, blink led A three times
|
||||
// If pwd saved successfully, blink led A three times
|
||||
if (writelen > 0) {
|
||||
SpinErr(0, 200, 5); // blink led A
|
||||
}
|
||||
@@ -283,7 +284,8 @@ void RAMFUNC SniffAndStore(uint8_t param) {
|
||||
}
|
||||
}
|
||||
|
||||
void RunMod() {
|
||||
void RunMod()
|
||||
{
|
||||
|
||||
StandAloneMode();
|
||||
|
||||
|
||||
+293
-364
File diff suppressed because it is too large
Load Diff
@@ -67,49 +67,40 @@ static int saMifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_
|
||||
uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE];
|
||||
|
||||
// reset FPGA and LED
|
||||
if (workFlags & 0x08)
|
||||
{
|
||||
if (workFlags & 0x08) {
|
||||
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
||||
set_tracing(false);
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
while (true) {
|
||||
// get UID from chip
|
||||
if (workFlags & 0x01)
|
||||
{
|
||||
if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true))
|
||||
{
|
||||
if (workFlags & 0x01) {
|
||||
if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {
|
||||
DbprintfEx(FLAG_NOLOG, "Can't select card");
|
||||
break;
|
||||
};
|
||||
|
||||
if (mifare_classic_halt(NULL, cuid))
|
||||
{
|
||||
if (mifare_classic_halt(NULL, cuid)) {
|
||||
DbprintfEx(FLAG_NOLOG, "Halt error");
|
||||
break;
|
||||
};
|
||||
};
|
||||
|
||||
// reset chip
|
||||
if (needWipe)
|
||||
{
|
||||
if (needWipe) {
|
||||
ReaderTransmitBitsPar(wupC1, 7, 0, NULL);
|
||||
if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a))
|
||||
{
|
||||
if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {
|
||||
DbprintfEx(FLAG_NOLOG, "wupC1 error");
|
||||
break;
|
||||
};
|
||||
|
||||
ReaderTransmit(wipeC, sizeof(wipeC), NULL);
|
||||
if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a))
|
||||
{
|
||||
if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {
|
||||
DbprintfEx(FLAG_NOLOG, "wipeC error");
|
||||
break;
|
||||
};
|
||||
|
||||
if (mifare_classic_halt(NULL, cuid))
|
||||
{
|
||||
if (mifare_classic_halt(NULL, cuid)) {
|
||||
DbprintfEx(FLAG_NOLOG, "Halt error");
|
||||
break;
|
||||
};
|
||||
@@ -117,25 +108,21 @@ static int saMifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_
|
||||
|
||||
// chaud
|
||||
// write block
|
||||
if (workFlags & 0x02)
|
||||
{
|
||||
if (workFlags & 0x02) {
|
||||
ReaderTransmitBitsPar(wupC1, 7, 0, NULL);
|
||||
if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a))
|
||||
{
|
||||
if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {
|
||||
DbprintfEx(FLAG_NOLOG, "wupC1 error");
|
||||
break;
|
||||
};
|
||||
|
||||
ReaderTransmit(wupC2, sizeof(wupC2), NULL);
|
||||
if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a))
|
||||
{
|
||||
if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {
|
||||
DbprintfEx(FLAG_NOLOG, "wupC2 errorv");
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
if ((mifare_sendcmd_short(NULL, 0, 0xA0, blockNo, receivedAnswer, receivedAnswerPar, NULL) != 1) || (receivedAnswer[0] != 0x0a))
|
||||
{
|
||||
if ((mifare_sendcmd_short(NULL, 0, 0xA0, blockNo, receivedAnswer, receivedAnswerPar, NULL) != 1) || (receivedAnswer[0] != 0x0a)) {
|
||||
DbprintfEx(FLAG_NOLOG, "write block send command error");
|
||||
break;
|
||||
};
|
||||
@@ -143,16 +130,13 @@ static int saMifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_
|
||||
memcpy(d_block, datain, 16);
|
||||
AddCrc14A(d_block, 16);
|
||||
ReaderTransmit(d_block, sizeof(d_block), NULL);
|
||||
if ((ReaderReceive(receivedAnswer, receivedAnswerPar) != 1) || (receivedAnswer[0] != 0x0a))
|
||||
{
|
||||
if ((ReaderReceive(receivedAnswer, receivedAnswerPar) != 1) || (receivedAnswer[0] != 0x0a)) {
|
||||
DbprintfEx(FLAG_NOLOG, "write block send data error");
|
||||
break;
|
||||
};
|
||||
|
||||
if (workFlags & 0x04)
|
||||
{
|
||||
if (mifare_classic_halt(NULL, cuid))
|
||||
{
|
||||
if (workFlags & 0x04) {
|
||||
if (mifare_classic_halt(NULL, cuid)) {
|
||||
DbprintfEx(FLAG_NOLOG, "Halt error");
|
||||
break;
|
||||
};
|
||||
@@ -162,8 +146,7 @@ static int saMifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_
|
||||
break;
|
||||
}
|
||||
|
||||
if ((workFlags & 0x10) || (!isOK))
|
||||
{
|
||||
if ((workFlags & 0x10) || (!isOK)) {
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
}
|
||||
|
||||
@@ -182,20 +165,17 @@ static int saMifareChkKeys(uint8_t blockNo, uint8_t keyType, bool clearTrace, ui
|
||||
struct Crypto1State *pcs;
|
||||
pcs = &mpcs;
|
||||
|
||||
for (int i = 0; i < keyCount; ++i)
|
||||
{
|
||||
for (int i = 0; i < keyCount; ++i) {
|
||||
|
||||
/* no need for anticollision. just verify tag is still here */
|
||||
// if (!iso14443a_fast_select_card(cjuid, 0)) {
|
||||
if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true))
|
||||
{
|
||||
if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {
|
||||
DbprintfEx(FLAG_NOLOG, "FATAL : E_MF_LOSTTAG");
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint64_t ui64Key = bytes_to_num(datain + i * 6, 6);
|
||||
if (mifare_classic_auth(pcs, cuid, blockNo, keyType, ui64Key, AUTH_FIRST))
|
||||
{
|
||||
if (mifare_classic_auth(pcs, cuid, blockNo, keyType, ui64Key, AUTH_FIRST)) {
|
||||
uint8_t dummy_answer = 0;
|
||||
ReaderTransmit(&dummy_answer, 1, NULL);
|
||||
// wait for the card to become ready again
|
||||
@@ -214,7 +194,8 @@ static int saMifareChkKeys(uint8_t blockNo, uint8_t keyType, bool clearTrace, ui
|
||||
}
|
||||
|
||||
|
||||
void RunMod() {
|
||||
void RunMod()
|
||||
{
|
||||
StandAloneMode();
|
||||
Dbprintf(">> Matty mifare chk/dump/sim a.k.a MattyRun Started <<");
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||
@@ -249,7 +230,7 @@ void RunMod() {
|
||||
uint16_t mifare_size = 1024; // Mifare 1k (only 1k supported for now)
|
||||
uint8_t sectorSize = 64; // 1k's sector size is 64 bytes.
|
||||
uint8_t blockNo = 3; // Security block is number 3 for each sector.
|
||||
uint8_t sectorsCnt = (mifare_size/sectorSize);
|
||||
uint8_t sectorsCnt = (mifare_size / sectorSize);
|
||||
uint8_t keyType = 2; // Keytype buffer
|
||||
uint64_t key64; // Defines current key
|
||||
uint8_t *keyBlock = NULL; // Where the keys will be held in memory.
|
||||
@@ -284,7 +265,7 @@ void RunMod() {
|
||||
int mfKeysCnt = sizeof(mfKeys) / sizeof(uint64_t);
|
||||
|
||||
for (int mfKeyCounter = 0; mfKeyCounter < mfKeysCnt; mfKeyCounter++) {
|
||||
num_to_bytes(mfKeys[mfKeyCounter], 6, (uint8_t*)(keyBlock + mfKeyCounter * 6));
|
||||
num_to_bytes(mfKeys[mfKeyCounter], 6, (uint8_t *)(keyBlock + mfKeyCounter * 6));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -294,8 +275,8 @@ void RunMod() {
|
||||
Dbprintf("[+] Printing mf keys");
|
||||
for (uint8_t keycnt = 0; keycnt < mfKeysCnt; keycnt++)
|
||||
Dbprintf("[-] chk mf key[%2d] %02x%02x%02x%02x%02x%02x", keycnt,
|
||||
(keyBlock + 6*keycnt)[0], (keyBlock + 6*keycnt)[1], (keyBlock + 6*keycnt)[2],
|
||||
(keyBlock + 6*keycnt)[3], (keyBlock + 6*keycnt)[4], (keyBlock + 6*keycnt)[5], 6);
|
||||
(keyBlock + 6 * keycnt)[0], (keyBlock + 6 * keycnt)[1], (keyBlock + 6 * keycnt)[2],
|
||||
(keyBlock + 6 * keycnt)[3], (keyBlock + 6 * keycnt)[4], (keyBlock + 6 * keycnt)[5], 6);
|
||||
DbpString("--------------------------------------------------------");
|
||||
}
|
||||
|
||||
@@ -327,7 +308,7 @@ void RunMod() {
|
||||
for (int type = !keyType; type < 2 && !err; keyType == 2 ? (type++) : (type = 2)) {
|
||||
block = blockNo;
|
||||
for (int sec = 0; sec < sectorsCnt && !err; ++sec) {
|
||||
Dbprintf("\tCurrent sector:%3d, block:%3d, key type: %c, key count: %i ", sec, block, type ? 'B':'A', mfKeysCnt);
|
||||
Dbprintf("\tCurrent sector:%3d, block:%3d, key type: %c, key count: %i ", sec, block, type ? 'B' : 'A', mfKeysCnt);
|
||||
key = saMifareChkKeys(block, type, true, size, &keyBlock[0], &key64);
|
||||
if (key == -1) {
|
||||
LED(LED_RED, 50); //red
|
||||
@@ -342,9 +323,9 @@ void RunMod() {
|
||||
validKey[type][sec] = true;
|
||||
keyFound = true;
|
||||
Dbprintf("\t✓ Found valid key: [%02x%02x%02x%02x%02x%02x]\n",
|
||||
(keyBlock + 6*key)[0], (keyBlock + 6*key)[1], (keyBlock + 6*key)[2],
|
||||
(keyBlock + 6*key)[3], (keyBlock + 6*key)[4], (keyBlock + 6*key)[5]
|
||||
);
|
||||
(keyBlock + 6 * key)[0], (keyBlock + 6 * key)[1], (keyBlock + 6 * key)[2],
|
||||
(keyBlock + 6 * key)[3], (keyBlock + 6 * key)[4], (keyBlock + 6 * key)[5]
|
||||
);
|
||||
}
|
||||
|
||||
block < 127 ? (block += 4) : (block += 16);
|
||||
@@ -378,14 +359,14 @@ void RunMod() {
|
||||
for (uint16_t sectorNo = 0; sectorNo < sectorsCnt; sectorNo++) {
|
||||
if (validKey[0][sectorNo] || validKey[1][sectorNo]) {
|
||||
emlGetMem(mblock, FirstBlockOfSector(sectorNo) + NumBlocksPerSector(sectorNo) - 1, 1); // data, block num, blocks count (max 4)
|
||||
for (uint16_t t = 0; t < 2; t++) {
|
||||
if (validKey[t][sectorNo]) {
|
||||
memcpy(mblock + t*10, foundKey[t][sectorNo], 6);
|
||||
}
|
||||
for (uint16_t t = 0; t < 2; t++) {
|
||||
if (validKey[t][sectorNo]) {
|
||||
memcpy(mblock + t * 10, foundKey[t][sectorNo], 6);
|
||||
}
|
||||
emlSetMem(mblock, FirstBlockOfSector(sectorNo) + NumBlocksPerSector(sectorNo) - 1, 1);
|
||||
}
|
||||
emlSetMem(mblock, FirstBlockOfSector(sectorNo) + NumBlocksPerSector(sectorNo) - 1, 1);
|
||||
}
|
||||
}
|
||||
Dbprintf("\t✓ Found keys have been transferred to the emulator memory.");
|
||||
if (ecfill) {
|
||||
|
||||
@@ -409,7 +390,7 @@ void RunMod() {
|
||||
|
||||
LED_B_ON(); // green
|
||||
// assuming arg0==0, use hardcoded uid 0xdeadbeaf
|
||||
Mifare1ksim( FLAG_4B_UID_IN_DATA | FLAG_UID_IN_EMUL, 0, 0, uid);
|
||||
Mifare1ksim(FLAG_4B_UID_IN_DATA | FLAG_UID_IN_EMUL, 0, 0, uid);
|
||||
LED_B_OFF();
|
||||
|
||||
/*
|
||||
|
||||
@@ -18,7 +18,8 @@ typedef struct {
|
||||
} __attribute__((__packed__)) card_clone_t;
|
||||
|
||||
|
||||
void RunMod() {
|
||||
void RunMod()
|
||||
{
|
||||
StandAloneMode();
|
||||
Dbprintf(">> Craig Young Mifare sniff UID/clone uid 2 magic/sim a.k.a YoungRun Started <<");
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||
@@ -59,9 +60,9 @@ void RunMod() {
|
||||
if (cardRead[selected]) {
|
||||
Dbprintf("Button press detected -- replaying card in bank[%d]", selected);
|
||||
break;
|
||||
} else if (cardRead[(selected+1) % OPTS]) {
|
||||
Dbprintf("Button press detected but no card in bank[%d] so playing from bank[%d]", selected, (selected+1)%OPTS);
|
||||
selected = (selected+1) % OPTS;
|
||||
} else if (cardRead[(selected + 1) % OPTS]) {
|
||||
Dbprintf("Button press detected but no card in bank[%d] so playing from bank[%d]", selected, (selected + 1) % OPTS);
|
||||
selected = (selected + 1) % OPTS;
|
||||
break; // playing = 1;
|
||||
} else {
|
||||
Dbprintf("Button press detected but no stored tag to play. (Ignoring button)");
|
||||
@@ -75,12 +76,12 @@ void RunMod() {
|
||||
Dbprintf("Read UID:");
|
||||
Dbhexdump(card[selected].uidlen, card[selected].uid, 0);
|
||||
|
||||
if (memcmp(uids[(selected+1)%OPTS].uid, card[selected].uid, card[selected].uidlen ) == 0 ) {
|
||||
if (memcmp(uids[(selected + 1) % OPTS].uid, card[selected].uid, card[selected].uidlen) == 0) {
|
||||
Dbprintf("Card selected has same UID as what is stored in the other bank. Skipping.");
|
||||
} else {
|
||||
uids[selected].sak = card[selected].sak;
|
||||
uids[selected].uidlen = card[selected].uidlen;
|
||||
memcpy(uids[selected].uid , card[selected].uid, uids[selected].uidlen);
|
||||
memcpy(uids[selected].uid, card[selected].uid, uids[selected].uidlen);
|
||||
memcpy(uids[selected].atqa, card[selected].atqa, 2);
|
||||
|
||||
if (uids[selected].uidlen > 4)
|
||||
@@ -110,8 +111,8 @@ void RunMod() {
|
||||
}
|
||||
|
||||
/* MF Classic UID clone */
|
||||
else if (iGotoClone==1) {
|
||||
iGotoClone=0;
|
||||
else if (iGotoClone == 1) {
|
||||
iGotoClone = 0;
|
||||
LEDsoff();
|
||||
LED(selected + 1, 0);
|
||||
LED(LED_ORANGE, 250);
|
||||
@@ -176,7 +177,7 @@ void RunMod() {
|
||||
MifareCSetBlock(params, 0, newBlock0);
|
||||
MifareCGetBlock(params, 0, testBlock0);
|
||||
|
||||
if (memcmp(testBlock0, newBlock0, 16)==0) {
|
||||
if (memcmp(testBlock0, newBlock0, 16) == 0) {
|
||||
DbpString("Cloned successfull!");
|
||||
cardRead[selected] = 0; // Only if the card was cloned successfully should we clear it
|
||||
playing = 0;
|
||||
@@ -193,19 +194,19 @@ void RunMod() {
|
||||
|
||||
// Change where to record (or begin playing)
|
||||
// button_pressed == BUTTON_SINGLE_CLICK && cardRead[selected])
|
||||
else if (playing==1) {
|
||||
else if (playing == 1) {
|
||||
LEDsoff();
|
||||
LED(selected + 1, 0);
|
||||
|
||||
// Begin transmitting
|
||||
LED(LED_GREEN, 0);
|
||||
DbpString("Playing");
|
||||
for ( ; ; ) {
|
||||
for (; ;) {
|
||||
// exit from Standalone Mode, send a usbcommand.
|
||||
if (usb_poll_validate_length()) return;
|
||||
|
||||
int button_action = BUTTON_HELD(1000);
|
||||
if ( button_action == 0) { // No button action, proceed with sim
|
||||
if (button_action == 0) { // No button action, proceed with sim
|
||||
|
||||
uint8_t flags = FLAG_4B_UID_IN_DATA;
|
||||
uint8_t data[USB_CMD_DATA_SIZE] = {0}; // in case there is a read command received we shouldn't break
|
||||
@@ -214,7 +215,7 @@ void RunMod() {
|
||||
|
||||
uint64_t tmpuid = bytes_to_num(uids[selected].uid, uids[selected].uidlen);
|
||||
|
||||
if ( uids[selected].uidlen == 7 ) {
|
||||
if (uids[selected].uidlen == 7) {
|
||||
flags = FLAG_7B_UID_IN_DATA;
|
||||
Dbprintf("Simulating ISO14443a tag with uid: %014" PRIx64 " [Bank: %d]", tmpuid, selected);
|
||||
} else {
|
||||
|
||||
@@ -27,7 +27,8 @@
|
||||
#include "lf_hidbrute.h"
|
||||
|
||||
// samy's sniff and repeat routine for LF
|
||||
void RunMod() {
|
||||
void RunMod()
|
||||
{
|
||||
StandAloneMode();
|
||||
Dbprintf(">> LF HID corporate bruteforce a.k.a CorporateBrute Started <<");
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
||||
@@ -60,7 +61,7 @@ void RunMod() {
|
||||
DbpString("[=] starting recording");
|
||||
|
||||
// wait for button to be released
|
||||
while(BUTTON_PRESS())
|
||||
while (BUTTON_PRESS())
|
||||
WDT_HIT();
|
||||
|
||||
/* need this delay to prevent catching some weird data */
|
||||
@@ -76,8 +77,7 @@ void RunMod() {
|
||||
// so next button push begins playing what we recorded
|
||||
playing = 0;
|
||||
cardRead = 1;
|
||||
}
|
||||
else if (button_pressed > 0 && cardRead == 1) {
|
||||
} else if (button_pressed > 0 && cardRead == 1) {
|
||||
LEDsoff();
|
||||
LED(selected + 1, 0);
|
||||
LED(LED_ORANGE, 0);
|
||||
@@ -86,7 +86,7 @@ void RunMod() {
|
||||
Dbprintf("[=] cloning %x %x %08x", selected, high[selected], low[selected]);
|
||||
|
||||
// wait for button to be released
|
||||
while(BUTTON_PRESS())
|
||||
while (BUTTON_PRESS())
|
||||
WDT_HIT();
|
||||
|
||||
/* need this delay to prevent catching some weird data */
|
||||
@@ -141,15 +141,13 @@ void RunMod() {
|
||||
playing = !playing;
|
||||
LEDsoff();
|
||||
LED(selected + 1, 0);
|
||||
}
|
||||
else if (playing && selected == 2)
|
||||
{
|
||||
} else if (playing && selected == 2) {
|
||||
// Now it work only with HID Corporate 1000 (35bit), but is easily extensible to others RFID.
|
||||
// It is necessary only to calculate the correct parity.
|
||||
|
||||
// Brute force code
|
||||
// Check if the badge is an HID Corporate 1000
|
||||
if( (high[selected] & 0xFFFFFFF8) != 0x28 ) {
|
||||
if ((high[selected] & 0xFFFFFFF8) != 0x28) {
|
||||
DbpString("[-] Card is not a HID Corporate 1000. Skipping bruteforce.");
|
||||
continue;
|
||||
}
|
||||
@@ -162,7 +160,7 @@ void RunMod() {
|
||||
|
||||
// Calculate Facility Code and Card Number from high and low
|
||||
uint32_t cardnum = (low[selected] >> 1) & 0xFFFFF;
|
||||
uint32_t fc = ((high[selected] & 1 ) << 11 ) | (low[selected] >> 21);
|
||||
uint32_t fc = ((high[selected] & 1) << 11) | (low[selected] >> 21);
|
||||
uint32_t original_cardnum = cardnum;
|
||||
|
||||
Dbprintf("[=] Proxbrute - starting decrementing card number");
|
||||
@@ -235,7 +233,7 @@ void RunMod() {
|
||||
LED(selected + 1, 0);
|
||||
|
||||
} else {
|
||||
while(BUTTON_PRESS())
|
||||
while (BUTTON_PRESS())
|
||||
WDT_HIT();
|
||||
}
|
||||
}
|
||||
@@ -247,7 +245,8 @@ out:
|
||||
}
|
||||
|
||||
// Function that calculate next value for the brutforce of HID corporate 1000
|
||||
void hid_corporate_1000_calculate_checksum_and_set( uint32_t *high, uint32_t *low, uint32_t cardnum, uint32_t fc) {
|
||||
void hid_corporate_1000_calculate_checksum_and_set(uint32_t *high, uint32_t *low, uint32_t cardnum, uint32_t fc)
|
||||
{
|
||||
|
||||
uint32_t new_high = 0;
|
||||
uint32_t new_low = 0;
|
||||
@@ -264,8 +263,8 @@ void hid_corporate_1000_calculate_checksum_and_set( uint32_t *high, uint32_t *lo
|
||||
uint32_t parity_bit_34_low = new_low & 0xB6DB6DB6;
|
||||
n_ones = 0;
|
||||
// Calculate number of ones in low number
|
||||
for ( i = 1; i != 0; i <<= 1) {
|
||||
if( parity_bit_34_low & i )
|
||||
for (i = 1; i != 0; i <<= 1) {
|
||||
if (parity_bit_34_low & i)
|
||||
n_ones++;
|
||||
}
|
||||
// Calculate number of ones in high number
|
||||
@@ -282,15 +281,15 @@ void hid_corporate_1000_calculate_checksum_and_set( uint32_t *high, uint32_t *lo
|
||||
n_ones = 0;
|
||||
|
||||
// Calculate number of ones in low number
|
||||
for ( i=1; i != 0; i <<= 1) {
|
||||
if( parity_bit_1_low & i )
|
||||
for (i = 1; i != 0; i <<= 1) {
|
||||
if (parity_bit_1_low & i)
|
||||
n_ones++;
|
||||
}
|
||||
// Calculate number of ones in high number
|
||||
if ( new_high & 0x1)
|
||||
if (new_high & 0x1)
|
||||
n_ones++;
|
||||
|
||||
if ( new_high & 0x2)
|
||||
if (new_high & 0x2)
|
||||
n_ones++;
|
||||
|
||||
// Set parity bit (Odd parity)
|
||||
@@ -301,14 +300,14 @@ void hid_corporate_1000_calculate_checksum_and_set( uint32_t *high, uint32_t *lo
|
||||
n_ones = 0;
|
||||
// Calculate number of ones in low number (all bit of low, bitmask unnecessary)
|
||||
for (i = 1; i != 0; i <<= 1) {
|
||||
if ( new_low & i )
|
||||
if (new_low & i)
|
||||
n_ones++;
|
||||
}
|
||||
// Calculate number of ones in high number
|
||||
if ( new_high & 0x1)
|
||||
if (new_high & 0x1)
|
||||
n_ones++;
|
||||
|
||||
if ( new_high & 0x2)
|
||||
if (new_high & 0x2)
|
||||
n_ones++;
|
||||
|
||||
// Set parity bit (Odd parity)
|
||||
|
||||
@@ -19,6 +19,6 @@
|
||||
|
||||
#define OPTS 3
|
||||
|
||||
void hid_corporate_1000_calculate_checksum_and_set( uint32_t *high, uint32_t *low, uint32_t cardnum, uint32_t fc);
|
||||
void hid_corporate_1000_calculate_checksum_and_set(uint32_t *high, uint32_t *low, uint32_t cardnum, uint32_t fc);
|
||||
|
||||
#endif /* __LF_HIDBRUTE_H */
|
||||
@@ -12,7 +12,8 @@
|
||||
#include "lf_proxbrute.h"
|
||||
|
||||
// samy's sniff and repeat routine for LF
|
||||
void RunMod() {
|
||||
void RunMod()
|
||||
{
|
||||
StandAloneMode();
|
||||
Dbprintf(">> LF HID proxII bruteforce a.k.a ProxBrute Started (Brad Antoniewicz) <<");
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
||||
@@ -61,8 +62,7 @@ void RunMod() {
|
||||
// so next button push begins playing what we recorded
|
||||
playing = 0;
|
||||
cardRead = 1;
|
||||
}
|
||||
else if (button_pressed > 0 && cardRead == 1) {
|
||||
} else if (button_pressed > 0 && cardRead == 1) {
|
||||
LEDsoff();
|
||||
LED(selected + 1, 0);
|
||||
LED(LED_ORANGE, 0);
|
||||
@@ -119,12 +119,12 @@ void RunMod() {
|
||||
worked or not, so its a crap shoot. One option is to time how long
|
||||
it takes to get a valid ID then start from scratch every time.
|
||||
*/
|
||||
if ( selected == 1 ) {
|
||||
if (selected == 1) {
|
||||
DbpString("[=] entering ProxBrute Mode");
|
||||
Dbprintf("[=] current Tag: Selected = %x Facility = %08x ID = %08x", selected, high[selected], low[selected]);
|
||||
LED(LED_ORANGE, 0);
|
||||
LED(LED_RED, 0);
|
||||
for (uint16_t i = low[selected]-1; i > 0; i--) {
|
||||
for (uint16_t i = low[selected] - 1; i > 0; i--) {
|
||||
if (BUTTON_PRESS()) {
|
||||
DbpString("[-] told to stop");
|
||||
break;
|
||||
@@ -156,8 +156,7 @@ void RunMod() {
|
||||
playing = !playing;
|
||||
LEDsoff();
|
||||
LED(selected + 1, 0);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
while (BUTTON_PRESS())
|
||||
WDT_HIT();
|
||||
}
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
#include "lf_samyrun.h"
|
||||
|
||||
// samy's sniff and repeat routine for LF
|
||||
void RunMod() {
|
||||
void RunMod()
|
||||
{
|
||||
StandAloneMode();
|
||||
Dbprintf(">> LF HID Read/Clone/Sim a.k.a SamyRun Started <<");
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
||||
@@ -64,8 +65,7 @@ void RunMod() {
|
||||
cardRead = 1;
|
||||
|
||||
gotCard = true;
|
||||
}
|
||||
else if (button_pressed > 0 && cardRead == 1) {
|
||||
} else if (button_pressed > 0 && cardRead == 1) {
|
||||
LEDsoff();
|
||||
LED(selected + 1, 0);
|
||||
LED(LED_ORANGE, 0);
|
||||
@@ -129,8 +129,7 @@ void RunMod() {
|
||||
playing = !playing;
|
||||
LEDsoff();
|
||||
LED(selected + 1, 0);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
while (BUTTON_PRESS())
|
||||
WDT_HIT();
|
||||
}
|
||||
|
||||
+81
-73
@@ -672,9 +672,9 @@ static const unsigned int rcon[] = {
|
||||
((unsigned int)(pt)[3]))
|
||||
|
||||
#define PUTU32(ct, st) { (ct)[0] = (unsigned char)((st) >> 24); \
|
||||
(ct)[1] = (unsigned char)((st) >> 16); \
|
||||
(ct)[2] = (unsigned char)((st) >> 8); \
|
||||
(ct)[3] = (unsigned char)(st); }
|
||||
(ct)[1] = (unsigned char)((st) >> 16); \
|
||||
(ct)[2] = (unsigned char)((st) >> 8); \
|
||||
(ct)[3] = (unsigned char)(st); }
|
||||
|
||||
/*
|
||||
* Expand the cipher key into the encryption key schedule and return the
|
||||
@@ -685,7 +685,7 @@ int aes_setkey_enc(unsigned int rk[], const unsigned char cipherKey[], int keyBy
|
||||
int i = 0;
|
||||
unsigned int temp;
|
||||
|
||||
rk[0] = GETU32(cipherKey );
|
||||
rk[0] = GETU32(cipherKey);
|
||||
rk[1] = GETU32(cipherKey + 4);
|
||||
rk[2] = GETU32(cipherKey + 8);
|
||||
rk[3] = GETU32(cipherKey + 12);
|
||||
@@ -693,11 +693,11 @@ int aes_setkey_enc(unsigned int rk[], const unsigned char cipherKey[], int keyBy
|
||||
for (;;) {
|
||||
temp = rk[3];
|
||||
rk[4] = rk[0] ^
|
||||
(Te4[(temp >> 16) & 0xff] & 0xff000000) ^
|
||||
(Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
|
||||
(Te4[(temp ) & 0xff] & 0x0000ff00) ^
|
||||
(Te4[(temp >> 24) ] & 0x000000ff) ^
|
||||
rcon[i];
|
||||
(Te4[(temp >> 16) & 0xff] & 0xff000000) ^
|
||||
(Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
|
||||
(Te4[(temp) & 0xff] & 0x0000ff00) ^
|
||||
(Te4[(temp >> 24) ] & 0x000000ff) ^
|
||||
rcon[i];
|
||||
rk[5] = rk[1] ^ rk[4];
|
||||
rk[6] = rk[2] ^ rk[5];
|
||||
rk[7] = rk[3] ^ rk[6];
|
||||
@@ -713,11 +713,11 @@ int aes_setkey_enc(unsigned int rk[], const unsigned char cipherKey[], int keyBy
|
||||
for (;;) {
|
||||
temp = rk[ 5];
|
||||
rk[ 6] = rk[ 0] ^
|
||||
(Te4[(temp >> 16) & 0xff] & 0xff000000) ^
|
||||
(Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
|
||||
(Te4[(temp ) & 0xff] & 0x0000ff00) ^
|
||||
(Te4[(temp >> 24) ] & 0x000000ff) ^
|
||||
rcon[i];
|
||||
(Te4[(temp >> 16) & 0xff] & 0xff000000) ^
|
||||
(Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
|
||||
(Te4[(temp) & 0xff] & 0x0000ff00) ^
|
||||
(Te4[(temp >> 24) ] & 0x000000ff) ^
|
||||
rcon[i];
|
||||
rk[ 7] = rk[ 1] ^ rk[ 6];
|
||||
rk[ 8] = rk[ 2] ^ rk[ 7];
|
||||
rk[ 9] = rk[ 3] ^ rk[ 8];
|
||||
@@ -735,11 +735,11 @@ int aes_setkey_enc(unsigned int rk[], const unsigned char cipherKey[], int keyBy
|
||||
for (;;) {
|
||||
temp = rk[ 7];
|
||||
rk[ 8] = rk[ 0] ^
|
||||
(Te4[(temp >> 16) & 0xff] & 0xff000000) ^
|
||||
(Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
|
||||
(Te4[(temp ) & 0xff] & 0x0000ff00) ^
|
||||
(Te4[(temp >> 24) ] & 0x000000ff) ^
|
||||
rcon[i];
|
||||
(Te4[(temp >> 16) & 0xff] & 0xff000000) ^
|
||||
(Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
|
||||
(Te4[(temp) & 0xff] & 0x0000ff00) ^
|
||||
(Te4[(temp >> 24) ] & 0x000000ff) ^
|
||||
rcon[i];
|
||||
rk[ 9] = rk[ 1] ^ rk[ 8];
|
||||
rk[10] = rk[ 2] ^ rk[ 9];
|
||||
rk[11] = rk[ 3] ^ rk[10];
|
||||
@@ -748,10 +748,10 @@ int aes_setkey_enc(unsigned int rk[], const unsigned char cipherKey[], int keyBy
|
||||
}
|
||||
temp = rk[11];
|
||||
rk[12] = rk[ 4] ^
|
||||
(Te4[(temp >> 24) ] & 0xff000000) ^
|
||||
(Te4[(temp >> 16) & 0xff] & 0x00ff0000) ^
|
||||
(Te4[(temp >> 8) & 0xff] & 0x0000ff00) ^
|
||||
(Te4[(temp ) & 0xff] & 0x000000ff);
|
||||
(Te4[(temp >> 24) ] & 0xff000000) ^
|
||||
(Te4[(temp >> 16) & 0xff] & 0x00ff0000) ^
|
||||
(Te4[(temp >> 8) & 0xff] & 0x0000ff00) ^
|
||||
(Te4[(temp) & 0xff] & 0x000000ff);
|
||||
rk[13] = rk[ 5] ^ rk[12];
|
||||
rk[14] = rk[ 6] ^ rk[13];
|
||||
rk[15] = rk[ 7] ^ rk[14];
|
||||
@@ -779,10 +779,10 @@ int AesGenKeySched(unsigned int rk[], unsigned int rrk[], const unsigned char ci
|
||||
rrk[2] = rk[2];
|
||||
rrk[3] = rk[3];
|
||||
|
||||
/*
|
||||
* apply the inverse MixColumn transform to all round keys but the first
|
||||
* and the last
|
||||
*/
|
||||
/*
|
||||
* apply the inverse MixColumn transform to all round keys but the first
|
||||
* and the last
|
||||
*/
|
||||
for (i = 1; i < Nr; i++) {
|
||||
rrk -= 4;
|
||||
rk += 4;
|
||||
@@ -790,22 +790,22 @@ int AesGenKeySched(unsigned int rk[], unsigned int rrk[], const unsigned char ci
|
||||
Td0[Te4[(rk[0] >> 24) ] & 0xff] ^
|
||||
Td1[Te4[(rk[0] >> 16) & 0xff] & 0xff] ^
|
||||
Td2[Te4[(rk[0] >> 8) & 0xff] & 0xff] ^
|
||||
Td3[Te4[(rk[0] ) & 0xff] & 0xff];
|
||||
Td3[Te4[(rk[0]) & 0xff] & 0xff];
|
||||
rrk[1] =
|
||||
Td0[Te4[(rk[1] >> 24) ] & 0xff] ^
|
||||
Td1[Te4[(rk[1] >> 16) & 0xff] & 0xff] ^
|
||||
Td2[Te4[(rk[1] >> 8) & 0xff] & 0xff] ^
|
||||
Td3[Te4[(rk[1] ) & 0xff] & 0xff];
|
||||
Td3[Te4[(rk[1]) & 0xff] & 0xff];
|
||||
rrk[2] =
|
||||
Td0[Te4[(rk[2] >> 24) ] & 0xff] ^
|
||||
Td1[Te4[(rk[2] >> 16) & 0xff] & 0xff] ^
|
||||
Td2[Te4[(rk[2] >> 8) & 0xff] & 0xff] ^
|
||||
Td3[Te4[(rk[2] ) & 0xff] & 0xff];
|
||||
Td3[Te4[(rk[2]) & 0xff] & 0xff];
|
||||
rrk[3] =
|
||||
Td0[Te4[(rk[3] >> 24) ] & 0xff] ^
|
||||
Td1[Te4[(rk[3] >> 16) & 0xff] & 0xff] ^
|
||||
Td2[Te4[(rk[3] >> 8) & 0xff] & 0xff] ^
|
||||
Td3[Te4[(rk[3] ) & 0xff] & 0xff];
|
||||
Td3[Te4[(rk[3]) & 0xff] & 0xff];
|
||||
}
|
||||
// invert the order of the last round keys
|
||||
rrk -= 4;
|
||||
@@ -833,7 +833,7 @@ void AesEncBlk(AesCtx *pCtx, const unsigned char pt[], unsigned char ct[])
|
||||
* map byte array block to cipher state
|
||||
* and add initial round key:
|
||||
*/
|
||||
s0 = GETU32(pt ) ^ rk[0];
|
||||
s0 = GETU32(pt) ^ rk[0];
|
||||
s1 = GETU32(pt + 4) ^ rk[1];
|
||||
s2 = GETU32(pt + 8) ^ rk[2];
|
||||
s3 = GETU32(pt + 12) ^ rk[3];
|
||||
@@ -852,25 +852,25 @@ void AesEncBlk(AesCtx *pCtx, const unsigned char pt[], unsigned char ct[])
|
||||
Te0[(s0 >> 24) ] ^
|
||||
Te1[(s1 >> 16) & 0xff] ^
|
||||
Te2[(s2 >> 8) & 0xff] ^
|
||||
Te3[(s3 ) & 0xff] ^
|
||||
Te3[(s3) & 0xff] ^
|
||||
rk[4];
|
||||
t1 =
|
||||
Te0[(s1 >> 24) ] ^
|
||||
Te1[(s2 >> 16) & 0xff] ^
|
||||
Te2[(s3 >> 8) & 0xff] ^
|
||||
Te3[(s0 ) & 0xff] ^
|
||||
Te3[(s0) & 0xff] ^
|
||||
rk[5];
|
||||
t2 =
|
||||
Te0[(s2 >> 24) ] ^
|
||||
Te1[(s3 >> 16) & 0xff] ^
|
||||
Te2[(s0 >> 8) & 0xff] ^
|
||||
Te3[(s1 ) & 0xff] ^
|
||||
Te3[(s1) & 0xff] ^
|
||||
rk[6];
|
||||
t3 =
|
||||
Te0[(s3 >> 24) ] ^
|
||||
Te1[(s0 >> 16) & 0xff] ^
|
||||
Te2[(s1 >> 8) & 0xff] ^
|
||||
Te3[(s2 ) & 0xff] ^
|
||||
Te3[(s2) & 0xff] ^
|
||||
rk[7];
|
||||
|
||||
rk += 8;
|
||||
@@ -882,25 +882,25 @@ void AesEncBlk(AesCtx *pCtx, const unsigned char pt[], unsigned char ct[])
|
||||
Te0[(t0 >> 24) ] ^
|
||||
Te1[(t1 >> 16) & 0xff] ^
|
||||
Te2[(t2 >> 8) & 0xff] ^
|
||||
Te3[(t3 ) & 0xff] ^
|
||||
Te3[(t3) & 0xff] ^
|
||||
rk[0];
|
||||
s1 =
|
||||
Te0[(t1 >> 24) ] ^
|
||||
Te1[(t2 >> 16) & 0xff] ^
|
||||
Te2[(t3 >> 8) & 0xff] ^
|
||||
Te3[(t0 ) & 0xff] ^
|
||||
Te3[(t0) & 0xff] ^
|
||||
rk[1];
|
||||
s2 =
|
||||
Te0[(t2 >> 24) ] ^
|
||||
Te1[(t3 >> 16) & 0xff] ^
|
||||
Te2[(t0 >> 8) & 0xff] ^
|
||||
Te3[(t1 ) & 0xff] ^
|
||||
Te3[(t1) & 0xff] ^
|
||||
rk[2];
|
||||
s3 =
|
||||
Te0[(t3 >> 24) ] ^
|
||||
Te1[(t0 >> 16) & 0xff] ^
|
||||
Te2[(t1 >> 8) & 0xff] ^
|
||||
Te3[(t2 ) & 0xff] ^
|
||||
Te3[(t2) & 0xff] ^
|
||||
rk[3];
|
||||
}
|
||||
/*
|
||||
@@ -911,28 +911,28 @@ void AesEncBlk(AesCtx *pCtx, const unsigned char pt[], unsigned char ct[])
|
||||
(Te4[(t0 >> 24) ] & 0xff000000) ^
|
||||
(Te4[(t1 >> 16) & 0xff] & 0x00ff0000) ^
|
||||
(Te4[(t2 >> 8) & 0xff] & 0x0000ff00) ^
|
||||
(Te4[(t3 ) & 0xff] & 0x000000ff) ^
|
||||
(Te4[(t3) & 0xff] & 0x000000ff) ^
|
||||
rk[0];
|
||||
PUTU32(ct , s0);
|
||||
PUTU32(ct, s0);
|
||||
s1 =
|
||||
(Te4[(t1 >> 24) ] & 0xff000000) ^
|
||||
(Te4[(t2 >> 16) & 0xff] & 0x00ff0000) ^
|
||||
(Te4[(t3 >> 8) & 0xff] & 0x0000ff00) ^
|
||||
(Te4[(t0 ) & 0xff] & 0x000000ff) ^
|
||||
(Te4[(t0) & 0xff] & 0x000000ff) ^
|
||||
rk[1];
|
||||
PUTU32(ct + 4, s1);
|
||||
s2 =
|
||||
(Te4[(t2 >> 24) ] & 0xff000000) ^
|
||||
(Te4[(t3 >> 16) & 0xff] & 0x00ff0000) ^
|
||||
(Te4[(t0 >> 8) & 0xff] & 0x0000ff00) ^
|
||||
(Te4[(t1 ) & 0xff] & 0x000000ff) ^
|
||||
(Te4[(t1) & 0xff] & 0x000000ff) ^
|
||||
rk[2];
|
||||
PUTU32(ct + 8, s2);
|
||||
s3 =
|
||||
(Te4[(t3 >> 24) ] & 0xff000000) ^
|
||||
(Te4[(t0 >> 16) & 0xff] & 0x00ff0000) ^
|
||||
(Te4[(t1 >> 8) & 0xff] & 0x0000ff00) ^
|
||||
(Te4[(t2 ) & 0xff] & 0x000000ff) ^
|
||||
(Te4[(t2) & 0xff] & 0x000000ff) ^
|
||||
rk[3];
|
||||
PUTU32(ct + 12, s3);
|
||||
|
||||
@@ -959,10 +959,14 @@ void AesDecBlk(AesCtx *pCtx, const unsigned char ct[], unsigned char pt[])
|
||||
* map byte array block to cipher state
|
||||
* and add initial round key:
|
||||
*/
|
||||
v0 = GETU32(ct ); s0 = v0 ^ rk[0];
|
||||
v1 = GETU32(ct + 4); s1 = v1 ^ rk[1];
|
||||
v2 = GETU32(ct + 8); s2 = v2 ^ rk[2];
|
||||
v3 = GETU32(ct + 12); s3 = v3 ^ rk[3];
|
||||
v0 = GETU32(ct);
|
||||
s0 = v0 ^ rk[0];
|
||||
v1 = GETU32(ct + 4);
|
||||
s1 = v1 ^ rk[1];
|
||||
v2 = GETU32(ct + 8);
|
||||
s2 = v2 ^ rk[2];
|
||||
v3 = GETU32(ct + 12);
|
||||
s3 = v3 ^ rk[3];
|
||||
/*
|
||||
* Nr - 1 full rounds:
|
||||
*/
|
||||
@@ -972,25 +976,25 @@ void AesDecBlk(AesCtx *pCtx, const unsigned char ct[], unsigned char pt[])
|
||||
Td0[(s0 >> 24) ] ^
|
||||
Td1[(s3 >> 16) & 0xff] ^
|
||||
Td2[(s2 >> 8) & 0xff] ^
|
||||
Td3[(s1 ) & 0xff] ^
|
||||
Td3[(s1) & 0xff] ^
|
||||
rk[4];
|
||||
t1 =
|
||||
Td0[(s1 >> 24) ] ^
|
||||
Td1[(s0 >> 16) & 0xff] ^
|
||||
Td2[(s3 >> 8) & 0xff] ^
|
||||
Td3[(s2 ) & 0xff] ^
|
||||
Td3[(s2) & 0xff] ^
|
||||
rk[5];
|
||||
t2 =
|
||||
Td0[(s2 >> 24) ] ^
|
||||
Td1[(s1 >> 16) & 0xff] ^
|
||||
Td2[(s0 >> 8) & 0xff] ^
|
||||
Td3[(s3 ) & 0xff] ^
|
||||
Td3[(s3) & 0xff] ^
|
||||
rk[6];
|
||||
t3 =
|
||||
Td0[(s3 >> 24) ] ^
|
||||
Td1[(s2 >> 16) & 0xff] ^
|
||||
Td2[(s1 >> 8) & 0xff] ^
|
||||
Td3[(s0 ) & 0xff] ^
|
||||
Td3[(s0) & 0xff] ^
|
||||
rk[7];
|
||||
|
||||
rk += 8;
|
||||
@@ -1002,25 +1006,25 @@ void AesDecBlk(AesCtx *pCtx, const unsigned char ct[], unsigned char pt[])
|
||||
Td0[(t0 >> 24) ] ^
|
||||
Td1[(t3 >> 16) & 0xff] ^
|
||||
Td2[(t2 >> 8) & 0xff] ^
|
||||
Td3[(t1 ) & 0xff] ^
|
||||
Td3[(t1) & 0xff] ^
|
||||
rk[0];
|
||||
s1 =
|
||||
Td0[(t1 >> 24) ] ^
|
||||
Td1[(t0 >> 16) & 0xff] ^
|
||||
Td2[(t3 >> 8) & 0xff] ^
|
||||
Td3[(t2 ) & 0xff] ^
|
||||
Td3[(t2) & 0xff] ^
|
||||
rk[1];
|
||||
s2 =
|
||||
Td0[(t2 >> 24) ] ^
|
||||
Td1[(t1 >> 16) & 0xff] ^
|
||||
Td2[(t0 >> 8) & 0xff] ^
|
||||
Td3[(t3 ) & 0xff] ^
|
||||
Td3[(t3) & 0xff] ^
|
||||
rk[2];
|
||||
s3 =
|
||||
Td0[(t3 >> 24) ] ^
|
||||
Td1[(t2 >> 16) & 0xff] ^
|
||||
Td2[(t1 >> 8) & 0xff] ^
|
||||
Td3[(t0 ) & 0xff] ^
|
||||
Td3[(t0) & 0xff] ^
|
||||
rk[3];
|
||||
}
|
||||
/*
|
||||
@@ -1031,35 +1035,39 @@ void AesDecBlk(AesCtx *pCtx, const unsigned char ct[], unsigned char pt[])
|
||||
(Td4[(t0 >> 24) ] & 0xff000000) ^
|
||||
(Td4[(t3 >> 16) & 0xff] & 0x00ff0000) ^
|
||||
(Td4[(t2 >> 8) & 0xff] & 0x0000ff00) ^
|
||||
(Td4[(t1 ) & 0xff] & 0x000000ff) ^
|
||||
(Td4[(t1) & 0xff] & 0x000000ff) ^
|
||||
rk[0];
|
||||
s1 =
|
||||
(Td4[(t1 >> 24) ] & 0xff000000) ^
|
||||
(Td4[(t0 >> 16) & 0xff] & 0x00ff0000) ^
|
||||
(Td4[(t3 >> 8) & 0xff] & 0x0000ff00) ^
|
||||
(Td4[(t2 ) & 0xff] & 0x000000ff) ^
|
||||
(Td4[(t2) & 0xff] & 0x000000ff) ^
|
||||
rk[1];
|
||||
s2 =
|
||||
(Td4[(t2 >> 24) ] & 0xff000000) ^
|
||||
(Td4[(t1 >> 16) & 0xff] & 0x00ff0000) ^
|
||||
(Td4[(t0 >> 8) & 0xff] & 0x0000ff00) ^
|
||||
(Td4[(t3 ) & 0xff] & 0x000000ff) ^
|
||||
(Td4[(t3) & 0xff] & 0x000000ff) ^
|
||||
rk[2];
|
||||
s3 =
|
||||
(Td4[(t3 >> 24) ] & 0xff000000) ^
|
||||
(Td4[(t2 >> 16) & 0xff] & 0x00ff0000) ^
|
||||
(Td4[(t1 >> 8) & 0xff] & 0x0000ff00) ^
|
||||
(Td4[(t0 ) & 0xff] & 0x000000ff) ^
|
||||
(Td4[(t0) & 0xff] & 0x000000ff) ^
|
||||
rk[3];
|
||||
|
||||
if (pCtx->Mode) {
|
||||
s0 = s0 ^ iv[0]; iv[0] = v0;
|
||||
s1 = s1 ^ iv[1]; iv[1] = v1;
|
||||
s2 = s2 ^ iv[2]; iv[2] = v2;
|
||||
s3 = s3 ^ iv[3]; iv[3] = v3;
|
||||
s0 = s0 ^ iv[0];
|
||||
iv[0] = v0;
|
||||
s1 = s1 ^ iv[1];
|
||||
iv[1] = v1;
|
||||
s2 = s2 ^ iv[2];
|
||||
iv[2] = v2;
|
||||
s3 = s3 ^ iv[3];
|
||||
iv[3] = v3;
|
||||
}
|
||||
|
||||
PUTU32(pt , s0);
|
||||
PUTU32(pt, s0);
|
||||
PUTU32(pt + 4, s1);
|
||||
PUTU32(pt + 8, s2);
|
||||
PUTU32(pt + 12, s3);
|
||||
@@ -1082,9 +1090,9 @@ int AesCtxIni(AesCtx *pCtx, unsigned char *pIV, unsigned char *pKey, unsigned in
|
||||
|
||||
// initialize IV
|
||||
if (pIV != 0) {
|
||||
pCtx->Iv[0] = GETU32(pIV );
|
||||
pCtx->Iv[1] = GETU32(pIV + 4 );
|
||||
pCtx->Iv[2] = GETU32(pIV + 8 );
|
||||
pCtx->Iv[0] = GETU32(pIV);
|
||||
pCtx->Iv[1] = GETU32(pIV + 4);
|
||||
pCtx->Iv[2] = GETU32(pIV + 8);
|
||||
pCtx->Iv[3] = GETU32(pIV + 12);
|
||||
}
|
||||
|
||||
@@ -1149,18 +1157,18 @@ int main()
|
||||
|
||||
// initialize context and encrypt data at one end
|
||||
|
||||
if( AesCtxIni(&ctx, iv, key, KEY128, CBC) < 0)
|
||||
if (AesCtxIni(&ctx, iv, key, KEY128, CBC) < 0)
|
||||
printf("init error\n");
|
||||
|
||||
if (AesEncrypt(&ctx, databuf, databuf, sizeof(databuf) ) < 0)
|
||||
if (AesEncrypt(&ctx, databuf, databuf, sizeof(databuf)) < 0)
|
||||
printf("error in encryption\n");
|
||||
|
||||
// initialize context and decrypt cipher at other end
|
||||
|
||||
if( AesCtxIni(&ctx, iv, key, KEY128, CBC) < 0)
|
||||
if (AesCtxIni(&ctx, iv, key, KEY128, CBC) < 0)
|
||||
printf("init error\n");
|
||||
|
||||
if (AesDecrypt(&ctx, databuf, databuf, sizeof(databuf) ) < 0)
|
||||
if (AesDecrypt(&ctx, databuf, databuf, sizeof(databuf)) < 0)
|
||||
printf("error in decryption\n");
|
||||
|
||||
printf("%s\n", databuf);
|
||||
|
||||
+5
-5
@@ -8,11 +8,11 @@
|
||||
|
||||
// AES context structure
|
||||
typedef struct {
|
||||
unsigned int Ek[60];
|
||||
unsigned int Dk[60];
|
||||
unsigned int Iv[4];
|
||||
unsigned char Nr;
|
||||
unsigned char Mode;
|
||||
unsigned int Ek[60];
|
||||
unsigned int Dk[60];
|
||||
unsigned int Iv[4];
|
||||
unsigned char Nr;
|
||||
unsigned char Mode;
|
||||
} AesCtx;
|
||||
|
||||
// key length in bytes
|
||||
|
||||
+203
-168
File diff suppressed because it is too large
Load Diff
+31
-31
@@ -110,7 +110,7 @@ void EM4xReadWord(uint8_t addr, uint32_t pwd, uint8_t usepwd);
|
||||
void EM4xWriteWord(uint32_t flag, uint32_t data, uint32_t pwd);
|
||||
void Cotag(uint32_t arg0);
|
||||
void setT55xxConfig(uint8_t arg0, t55xx_config *c);
|
||||
t55xx_config * getT55xxConfig(void);
|
||||
t55xx_config *getT55xxConfig(void);
|
||||
void printT55xxConfig(void);
|
||||
void loadT55xxConfig(void);
|
||||
|
||||
@@ -133,11 +133,11 @@ void ReaderIso14443a(UsbCommand *c);
|
||||
void GetParity(const uint8_t *pbtCmd, uint16_t len, uint8_t *parity);
|
||||
void iso14a_set_trigger(bool enable);
|
||||
// also used in emv
|
||||
bool prepare_allocated_tag_modulation(tag_response_info_t * response_info);
|
||||
bool prepare_allocated_tag_modulation(tag_response_info_t *response_info);
|
||||
int GetIso14443aCommandFromReader(uint8_t *received, uint8_t *parity, int *len);
|
||||
|
||||
// epa.h
|
||||
void EPA_PACE_Collect_Nonce(UsbCommand * c);
|
||||
void EPA_PACE_Collect_Nonce(UsbCommand *c);
|
||||
void EPA_PACE_Replay(UsbCommand *c);
|
||||
|
||||
// mifarecmd.h
|
||||
@@ -169,35 +169,35 @@ void OnSuccessMagic();
|
||||
void OnErrorMagic(uint8_t reason);
|
||||
|
||||
int32_t dist_nt(uint32_t nt1, uint32_t nt2);
|
||||
void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype );
|
||||
void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype);
|
||||
//void RAMFUNC SniffMifare(uint8_t param);
|
||||
|
||||
//desfire
|
||||
void Mifare_DES_Auth1(uint8_t arg0,uint8_t *datain);
|
||||
void Mifare_DES_Auth1(uint8_t arg0, uint8_t *datain);
|
||||
void Mifare_DES_Auth2(uint32_t arg0, uint8_t *datain);
|
||||
|
||||
// mifaredesfire.h
|
||||
bool InitDesfireCard();
|
||||
void MifareSendCommand(uint8_t arg0,uint8_t arg1, uint8_t *datain);
|
||||
void MifareSendCommand(uint8_t arg0, uint8_t arg1, uint8_t *datain);
|
||||
void MifareDesfireGetInformation();
|
||||
void MifareDES_Auth1(uint8_t arg0,uint8_t arg1,uint8_t arg2, uint8_t *datain);
|
||||
void ReaderMifareDES(uint32_t param, uint32_t param2, uint8_t * datain);
|
||||
void MifareDES_Auth1(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain);
|
||||
void ReaderMifareDES(uint32_t param, uint32_t param2, uint8_t *datain);
|
||||
int DesfireAPDU(uint8_t *cmd, size_t cmd_len, uint8_t *dataout);
|
||||
size_t CreateAPDU( uint8_t *datain, size_t len, uint8_t *dataout);
|
||||
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);
|
||||
void mifare_cypher_single_block (desfirekey_t key, uint8_t *data, uint8_t *ivect, MifareCryptoDirection direction, MifareCryptoOperation operation, size_t block_size);
|
||||
void mifare_cypher_blocks_chained (desfiretag_t tag, desfirekey_t key, uint8_t *ivect, uint8_t *data, size_t data_size, MifareCryptoDirection direction, MifareCryptoOperation operation);
|
||||
size_t key_block_size (const desfirekey_t key);
|
||||
size_t padded_data_length (const size_t nbytes, const size_t block_size);
|
||||
size_t maced_data_length (const desfirekey_t key, const size_t nbytes);
|
||||
size_t enciphered_data_length (const desfiretag_t tag, const size_t nbytes, int communication_settings);
|
||||
void cmac_generate_subkeys (desfirekey_t key);
|
||||
void cmac (const desfirekey_t key, uint8_t *ivect, const uint8_t *data, size_t len, uint8_t *cmac);
|
||||
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 mifare_cypher_single_block(desfirekey_t key, uint8_t *data, uint8_t *ivect, MifareCryptoDirection direction, MifareCryptoOperation operation, size_t block_size);
|
||||
void mifare_cypher_blocks_chained(desfiretag_t tag, desfirekey_t key, uint8_t *ivect, uint8_t *data, size_t data_size, MifareCryptoDirection direction, MifareCryptoOperation operation);
|
||||
size_t key_block_size(const desfirekey_t key);
|
||||
size_t padded_data_length(const size_t nbytes, const size_t block_size);
|
||||
size_t maced_data_length(const desfirekey_t key, const size_t nbytes);
|
||||
size_t enciphered_data_length(const desfiretag_t tag, const size_t nbytes, int communication_settings);
|
||||
void cmac_generate_subkeys(desfirekey_t key);
|
||||
void cmac(const desfirekey_t key, uint8_t *ivect, const uint8_t *data, size_t len, uint8_t *cmac);
|
||||
|
||||
// iso15693.h
|
||||
void RecordRawAdcSamplesIso15693(void);
|
||||
@@ -205,14 +205,14 @@ void AcquireRawAdcSamplesIso15693(void);
|
||||
void ReaderIso15693(uint32_t parameter); // Simulate an ISO15693 reader - greg
|
||||
void SimTagIso15693(uint32_t parameter, uint8_t *uid); // simulate an ISO15693 tag - greg
|
||||
void BruteforceIso15693Afi(uint32_t speed); // find an AFI of a tag - atrox
|
||||
void DirectTag15693Command(uint32_t datalen,uint32_t speed, uint32_t recv, uint8_t *data); // send arbitrary commands from CLI - atrox
|
||||
void DirectTag15693Command(uint32_t datalen, uint32_t speed, uint32_t recv, uint8_t *data); // send arbitrary commands from CLI - atrox
|
||||
void Iso15693InitReader(void);
|
||||
|
||||
// iclass.h
|
||||
void RAMFUNC SniffIClass(void);
|
||||
void SimulateIClass(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
|
||||
void ReaderIClass(uint8_t arg0);
|
||||
void ReaderIClass_Replay(uint8_t arg0,uint8_t *MAC);
|
||||
void ReaderIClass_Replay(uint8_t arg0, uint8_t *MAC);
|
||||
void iClass_Authentication(uint8_t *MAC);
|
||||
void iClass_Authentication_fast(uint64_t arg0, uint64_t arg1, uint8_t *datain);
|
||||
void iClass_WriteBlock(uint8_t blockNo, uint8_t *data);
|
||||
@@ -224,22 +224,22 @@ void iClass_ReadCheck(uint8_t blockNo, uint8_t keyType);
|
||||
|
||||
// hitag2.h
|
||||
void SnoopHitag(uint32_t type);
|
||||
void SimulateHitagTag(bool tag_mem_supplied, byte_t* data);
|
||||
void ReaderHitag(hitag_function htf, hitag_data* htd);
|
||||
void WriterHitag(hitag_function htf, hitag_data* htd, int page);
|
||||
void SimulateHitagTag(bool tag_mem_supplied, byte_t *data);
|
||||
void ReaderHitag(hitag_function htf, hitag_data *htd);
|
||||
void WriterHitag(hitag_function htf, hitag_data *htd, int page);
|
||||
|
||||
//hitagS.h
|
||||
void SimulateHitagSTag(bool tag_mem_supplied, byte_t* data);
|
||||
void ReadHitagS(hitag_function htf, hitag_data* htd);
|
||||
void WritePageHitagS(hitag_function htf, hitag_data* htd,int page);
|
||||
void check_challenges(bool file_given, byte_t* data);
|
||||
void SimulateHitagSTag(bool tag_mem_supplied, byte_t *data);
|
||||
void ReadHitagS(hitag_function htf, hitag_data *htd);
|
||||
void WritePageHitagS(hitag_function htf, hitag_data *htd, int page);
|
||||
void check_challenges(bool file_given, byte_t *data);
|
||||
|
||||
// cmd.h
|
||||
uint8_t cmd_receive(UsbCommand* cmd);
|
||||
uint8_t cmd_send(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void* data, size_t len);
|
||||
uint8_t cmd_receive(UsbCommand *cmd);
|
||||
uint8_t cmd_send(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len);
|
||||
|
||||
// util.h
|
||||
void HfSnoop(int , int);
|
||||
void HfSnoop(int, int);
|
||||
|
||||
//felica.c
|
||||
extern void felica_sendraw(UsbCommand *c);
|
||||
|
||||
+27
-22
@@ -1,41 +1,46 @@
|
||||
#include "buzzer.h"
|
||||
|
||||
void Ring_BEE_ONCE(uint16_t music_note) {
|
||||
void Ring_BEE_ONCE(uint16_t music_note)
|
||||
{
|
||||
BEE_ON();
|
||||
SpinDelayUs(music_note);
|
||||
BEE_OFF();
|
||||
SpinDelayUs(music_note);
|
||||
}
|
||||
|
||||
void ring_2_7khz(uint16_t count) {
|
||||
Ring_BEE_TIME(n_2_7khz,count);
|
||||
void ring_2_7khz(uint16_t count)
|
||||
{
|
||||
Ring_BEE_TIME(n_2_7khz, count);
|
||||
}
|
||||
|
||||
void Ring_BEE_TIME(uint16_t music_note,uint16_t count) {
|
||||
for(uint16_t i=0 ; i < count; i++)
|
||||
void Ring_BEE_TIME(uint16_t music_note, uint16_t count)
|
||||
{
|
||||
for (uint16_t i = 0 ; i < count; i++)
|
||||
Ring_BEE_ONCE(music_note);
|
||||
SpinDelay(9);
|
||||
}
|
||||
|
||||
void Ring_ALL(uint16_t count) {
|
||||
Ring_BEE_TIME(note_1, count);
|
||||
Ring_BEE_TIME(note_2, count);
|
||||
Ring_BEE_TIME(note_3, count);
|
||||
Ring_BEE_TIME(note_4, count);
|
||||
Ring_BEE_TIME(note_5, count);
|
||||
Ring_BEE_TIME(note_6, count);
|
||||
Ring_BEE_TIME(note_7, count);
|
||||
SpinDelay(10);
|
||||
void Ring_ALL(uint16_t count)
|
||||
{
|
||||
Ring_BEE_TIME(note_1, count);
|
||||
Ring_BEE_TIME(note_2, count);
|
||||
Ring_BEE_TIME(note_3, count);
|
||||
Ring_BEE_TIME(note_4, count);
|
||||
Ring_BEE_TIME(note_5, count);
|
||||
Ring_BEE_TIME(note_6, count);
|
||||
Ring_BEE_TIME(note_7, count);
|
||||
SpinDelay(10);
|
||||
}
|
||||
|
||||
void Ring_Little_Star(uint16_t count) {
|
||||
Ring_BEE_TIME(note_1,count);
|
||||
Ring_BEE_TIME(note_1,count);
|
||||
Ring_BEE_TIME(note_5,count);
|
||||
Ring_BEE_TIME(note_5,count);
|
||||
Ring_BEE_TIME(note_6,count);
|
||||
Ring_BEE_TIME(note_6,count);
|
||||
Ring_BEE_TIME(note_5,2*count);
|
||||
void Ring_Little_Star(uint16_t count)
|
||||
{
|
||||
Ring_BEE_TIME(note_1, count);
|
||||
Ring_BEE_TIME(note_1, count);
|
||||
Ring_BEE_TIME(note_5, count);
|
||||
Ring_BEE_TIME(note_5, count);
|
||||
Ring_BEE_TIME(note_6, count);
|
||||
Ring_BEE_TIME(note_6, count);
|
||||
Ring_BEE_TIME(note_5, 2 * count);
|
||||
LED_A_ON();
|
||||
/*
|
||||
Ring_BEE_TIME(note_4,count);
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@
|
||||
#define note_8 0
|
||||
|
||||
extern void Ring_BEE_ONCE(uint16_t music_note);
|
||||
extern void Ring_BEE_TIME(uint16_t music_note,uint16_t count);
|
||||
extern void Ring_BEE_TIME(uint16_t music_note, uint16_t count);
|
||||
extern void ring_2_7khz(uint16_t count);
|
||||
extern void Ring_ALL(uint16_t count);
|
||||
extern void Ring_Little_Star(uint16_t count);
|
||||
|
||||
+159
-148
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user