CHG: Syntax suger

This commit is contained in:
iceman1001 2016-01-25 20:17:08 +01:00
commit da198be4b5
7 changed files with 44 additions and 61 deletions

View file

@ -27,7 +27,7 @@ static uint16_t BigBuf_hi = BIGBUF_SIZE;
static uint8_t *emulator_memory = NULL; static uint8_t *emulator_memory = NULL;
// trace related variables // trace related variables
static uint16_t traceLen = 0; static uint16_t traceLen;
int tracing = 1; //Last global one.. todo static? int tracing = 1; //Last global one.. todo static?
// get the address of BigBuf // get the address of BigBuf

View file

@ -1152,7 +1152,7 @@ int main()
if( AesCtxIni(&ctx, iv, key, KEY128, CBC) < 0) if( AesCtxIni(&ctx, iv, key, KEY128, CBC) < 0)
printf("init error\n"); 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"); printf("error in encryption\n");
// initialize context and decrypt cipher at other end // initialize context and decrypt cipher at other end
@ -1160,7 +1160,7 @@ int main()
if( AesCtxIni(&ctx, iv, key, KEY128, CBC) < 0) if( AesCtxIni(&ctx, iv, key, KEY128, CBC) < 0)
printf("init error\n"); 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("error in decryption\n");
printf("%s\n", databuf); printf("%s\n", databuf);

View file

@ -57,19 +57,17 @@ void ToSendReset(void)
ToSendBit = 8; ToSendBit = 8;
} }
void ToSendStuffBit(int b) void ToSendStuffBit(int b) {
{
if(ToSendBit >= 8) { if(ToSendBit >= 8) {
ToSendMax++; ++ToSendMax;
ToSend[ToSendMax] = 0; ToSend[ToSendMax] = 0;
ToSendBit = 0; ToSendBit = 0;
} }
if(b) { if(b)
ToSend[ToSendMax] |= (1 << (7 - ToSendBit)); ToSend[ToSendMax] |= (1 << (7 - ToSendBit));
}
ToSendBit++; ++ToSendBit;
if(ToSendMax >= sizeof(ToSend)) { if(ToSendMax >= sizeof(ToSend)) {
ToSendBit = 0; ToSendBit = 0;
@ -81,22 +79,20 @@ void ToSendStuffBit(int b)
// Debug print functions, to go out over USB, to the usual PC-side client. // Debug print functions, to go out over USB, to the usual PC-side client.
//============================================================================= //=============================================================================
void DbpString(char *str) void DbpString(char *str) {
{
byte_t len = strlen(str); byte_t len = strlen(str);
cmd_send(CMD_DEBUG_PRINT_STRING,len,0,0,(byte_t*)str,len); cmd_send(CMD_DEBUG_PRINT_STRING,len,0,0,(byte_t*)str,len);
} }
#if 0 #if 0
void DbpIntegers(int x1, int x2, int x3) void DbpIntegers(int x1, int x2, int x3) {
{
cmd_send(CMD_DEBUG_PRINT_INTEGERS,x1,x2,x3,0,0); cmd_send(CMD_DEBUG_PRINT_INTEGERS,x1,x2,x3,0,0);
} }
#endif #endif
void Dbprintf(const char *fmt, ...) { void Dbprintf(const char *fmt, ...) {
// should probably limit size here; oh well, let's just use a big buffer // should probably limit size here; oh well, let's just use a big buffer
char output_string[128]; char output_string[128] = {0x00};
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
@ -108,28 +104,27 @@ void Dbprintf(const char *fmt, ...) {
// prints HEX & ASCII // prints HEX & ASCII
void Dbhexdump(int len, uint8_t *d, bool bAsci) { void Dbhexdump(int len, uint8_t *d, bool bAsci) {
int l=0,i; int l=0, i;
char ascii[9]; char ascii[9];
while (len>0) { while (len>0) {
if (len>8) l=8;
else l=len; l = (len>8) ? 8 : len;
memcpy(ascii,d,l); memcpy(ascii,d,l);
ascii[l]=0; ascii[l]=0;
// filter safe ascii // filter safe ascii
for (i=0;i<l;i++) for (i=0; i<l; ++i)
if (ascii[i]<32 || ascii[i]>126) ascii[i]='.'; if (ascii[i]<32 || ascii[i]>126) ascii[i]='.';
if (bAsci) { if (bAsci)
Dbprintf("%-8s %*D",ascii,l,d," "); Dbprintf("%-8s %*D",ascii,l,d," ");
} else { else
Dbprintf("%*D",l,d," "); Dbprintf("%*D",l,d," ");
}
len-=8; len -= 8;
d+=8; d += 8;
} }
} }
@ -163,10 +158,9 @@ static int ReadAdc(int ch)
AT91C_BASE_ADC->ADC_CR = AT91C_ADC_START; AT91C_BASE_ADC->ADC_CR = AT91C_ADC_START;
while(!(AT91C_BASE_ADC->ADC_SR & ADC_END_OF_CONVERSION(ch))) while (!(AT91C_BASE_ADC->ADC_SR & ADC_END_OF_CONVERSION(ch))) ;
;
d = AT91C_BASE_ADC->ADC_CDR[ch];
d = AT91C_BASE_ADC->ADC_CDR[ch];
return d; return d;
} }
@ -175,15 +169,13 @@ int AvgAdc(int ch) // was static - merlok
int i; int i;
int a = 0; int a = 0;
for(i = 0; i < 32; i++) { for(i = 0; i < 32; ++i)
a += ReadAdc(ch); a += ReadAdc(ch);
}
return (a + 15) >> 5; return (a + 15) >> 5;
} }
void MeasureAntennaTuning(void) void MeasureAntennaTuning(void) {
{
uint8_t LF_Results[256]; uint8_t LF_Results[256];
int i, adcval = 0, peak = 0, peakv = 0, peakf = 0; //ptr = 0 int i, adcval = 0, peak = 0, peakv = 0, peakf = 0; //ptr = 0
int vLf125 = 0, vLf134 = 0, vHf = 0; // in mV int vLf125 = 0, vLf134 = 0, vHf = 0; // in mV
@ -201,8 +193,9 @@ void MeasureAntennaTuning(void)
FpgaDownloadAndGo(FPGA_BITSTREAM_LF); FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD); FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD);
for (i=255; i>=19; i--) { for (i=255; i>=19; i--) {
WDT_HIT(); WDT_HIT();
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, i); FpgaSendCommand(FPGA_CMD_SET_DIVISOR, i);
SpinDelay(20); SpinDelay(20);
adcval = ((MAX_ADC_LF_VOLTAGE * AvgAdc(ADC_CHAN_LF)) >> 10); adcval = ((MAX_ADC_LF_VOLTAGE * AvgAdc(ADC_CHAN_LF)) >> 10);
@ -229,13 +222,11 @@ void MeasureAntennaTuning(void)
cmd_send(CMD_MEASURED_ANTENNA_TUNING, vLf125 | (vLf134<<16), vHf, peakf | (peakv<<16), LF_Results, 256); cmd_send(CMD_MEASURED_ANTENNA_TUNING, vLf125 | (vLf134<<16), vHf, peakf | (peakv<<16), LF_Results, 256);
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
LED_A_OFF();
LED_B_OFF(); LEDsoff();
return;
} }
void MeasureAntennaTuningHf(void) void MeasureAntennaTuningHf(void) {
{
int vHf = 0; // in mV int vHf = 0; // in mV
DbpString("Measuring HF antenna, press button to exit"); DbpString("Measuring HF antenna, press button to exit");
@ -251,15 +242,13 @@ void MeasureAntennaTuningHf(void)
Dbprintf("%d mV",vHf); Dbprintf("%d mV",vHf);
if (BUTTON_PRESS()) break; if (BUTTON_PRESS()) break;
} }
DbpString("cancelled"); DbpString("cancelled");
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
} }
void ReadMem(int addr) void ReadMem(int addr) {
{
const uint8_t *data = ((uint8_t *)addr); const uint8_t *data = ((uint8_t *)addr);
Dbprintf("%x: %02x %02x %02x %02x %02x %02x %02x %02x", Dbprintf("%x: %02x %02x %02x %02x %02x %02x %02x %02x",
@ -280,6 +269,7 @@ void SendVersion(void)
* pointer, then use it. * pointer, then use it.
*/ */
char *bootrom_version = *(char**)&_bootphase1_version_pointer; char *bootrom_version = *(char**)&_bootphase1_version_pointer;
if( bootrom_version < &_flash_start || bootrom_version >= &_flash_end ) { if( bootrom_version < &_flash_start || bootrom_version >= &_flash_end ) {
strcat(VersionString, "bootrom version information appears invalid\n"); strcat(VersionString, "bootrom version information appears invalid\n");
} else { } else {
@ -292,6 +282,7 @@ void SendVersion(void)
FpgaGatherVersion(FPGA_BITSTREAM_LF, temp, sizeof(temp)); FpgaGatherVersion(FPGA_BITSTREAM_LF, temp, sizeof(temp));
strncat(VersionString, temp, sizeof(VersionString) - strlen(VersionString) - 1); strncat(VersionString, temp, sizeof(VersionString) - strlen(VersionString) - 1);
FpgaGatherVersion(FPGA_BITSTREAM_HF, temp, sizeof(temp)); FpgaGatherVersion(FPGA_BITSTREAM_HF, temp, sizeof(temp));
strncat(VersionString, temp, sizeof(VersionString) - strlen(VersionString) - 1); strncat(VersionString, temp, sizeof(VersionString) - strlen(VersionString) - 1);
@ -333,8 +324,7 @@ void printUSBSpeed(void)
/** /**
* Prints runtime information about the PM3. * Prints runtime information about the PM3.
**/ **/
void SendStatus(void) void SendStatus(void) {
{
BigBuf_print_status(); BigBuf_print_status();
Fpga_print_status(); Fpga_print_status();
printConfig(); //LF Sampling config printConfig(); //LF Sampling config
@ -782,16 +772,14 @@ static const char LIGHT_SCHEME[] = {
}; };
static const int LIGHT_LEN = sizeof(LIGHT_SCHEME)/sizeof(LIGHT_SCHEME[0]); static const int LIGHT_LEN = sizeof(LIGHT_SCHEME)/sizeof(LIGHT_SCHEME[0]);
void ListenReaderField(int limit) void ListenReaderField(int limit) {
{
int lf_av, lf_av_new, lf_baseline= 0, lf_max;
int hf_av, hf_av_new, hf_baseline= 0, hf_max;
int mode=1, display_val, display_max, i;
#define LF_ONLY 1 #define LF_ONLY 1
#define HF_ONLY 2 #define HF_ONLY 2
#define REPORT_CHANGE 10 // report new values only if they have changed at least by REPORT_CHANGE #define REPORT_CHANGE 10 // report new values only if they have changed at least by REPORT_CHANGE
int lf_av, lf_av_new, lf_baseline= 0, lf_max;
int hf_av, hf_av_new, hf_baseline= 0, hf_max;
int mode=1, display_val, display_max, i;
// switch off FPGA - we don't want to measure our own signal // switch off FPGA - we don't want to measure our own signal
FpgaDownloadAndGo(FPGA_BITSTREAM_HF); FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
@ -1400,9 +1388,8 @@ void __attribute__((noreturn)) AppMain(void)
for(;;) { for(;;) {
if (usb_poll()) { if (usb_poll()) {
rx_len = usb_read(rx,sizeof(UsbCommand)); rx_len = usb_read(rx,sizeof(UsbCommand));
if (rx_len) { if (rx_len)
UsbPacketReceived(rx,rx_len); UsbPacketReceived(rx,rx_len);
}
} }
WDT_HIT(); WDT_HIT();

View file

@ -24,9 +24,9 @@
static uint8_t filterlut[1 << 20]; static uint8_t filterlut[1 << 20];
static void __attribute__((constructor)) fill_lut() static void __attribute__((constructor)) fill_lut()
{ {
uint32_t i; uint32_t i;
for(i = 0; i < 1 << 20; ++i) for(i = 0; i < 1 << 20; ++i)
filterlut[i] = filter(i); filterlut[i] = filter(i);
} }
#define filter(x) (filterlut[(x) & 0xfffff]) #define filter(x) (filterlut[(x) & 0xfffff])
#endif #endif
@ -509,7 +509,6 @@ static struct Crypto1State* check_pfx_parity(uint32_t prefix, uint32_t rresp, ui
* It returns a zero terminated list of possible cipher states after the * It returns a zero terminated list of possible cipher states after the
* tag nonce was fed in * tag nonce was fed in
*/ */
struct Crypto1State* lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8]) struct Crypto1State* lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8])
{ {
struct Crypto1State *statelist, *s; struct Crypto1State *statelist, *s;

View file

@ -20,18 +20,15 @@
#include "crapto1.h" #include "crapto1.h"
#include <stdlib.h> #include <stdlib.h>
void crypto1_create(struct Crypto1State *s, uint64_t key) void crypto1_create(struct Crypto1State *s, uint64_t key)
{ {
// struct Crypto1State *s = malloc(sizeof(*s)); // struct Crypto1State *s = malloc(sizeof(*s));
s->odd = s->even = 0;
int i; int i;
for(i = 47;s && i > 0; i -= 2) { for(i = 47;s && i > 0; i -= 2) {
s->odd = s->odd << 1 | BIT(key, (i - 1) ^ 7); s->odd = s->odd << 1 | BIT(key, (i - 1) ^ 7);
s->even = s->even << 1 | BIT(key, i ^ 7); s->even = s->even << 1 | BIT(key, i ^ 7);
} }
return;
} }
void crypto1_destroy(struct Crypto1State *state) void crypto1_destroy(struct Crypto1State *state)
{ {

View file

@ -226,8 +226,8 @@ void* mifare_cryto_preprocess_data (desfiretag_t tag, void *data, size_t *nbytes
cmac (key, DESFIRE (tag)->ivect, res, *nbytes, DESFIRE (tag)->cmac); cmac (key, DESFIRE (tag)->ivect, res, *nbytes, DESFIRE (tag)->cmac);
if (append_mac) { if (append_mac) {
maced_data_length (key, *nbytes); size_t len = maced_data_length (key, *nbytes);
++len;
memcpy (res, data, *nbytes); memcpy (res, data, *nbytes);
memcpy (res + *nbytes, DESFIRE (tag)->cmac, CMAC_LENGTH); memcpy (res + *nbytes, DESFIRE (tag)->cmac, CMAC_LENGTH);
*nbytes += CMAC_LENGTH; *nbytes += CMAC_LENGTH;

View file

@ -102,7 +102,7 @@ static struct {
static uint8_t apdu_lengths_replay[5]; static uint8_t apdu_lengths_replay[5];
// type of card (ISO 14443 A or B) // type of card (ISO 14443 A or B)
static char iso_type = 0; static char iso_type;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Wrapper for sending APDUs to type A and B cards // Wrapper for sending APDUs to type A and B cards