mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2024-09-21 15:56:21 +08:00
Merge branch 'master' of https://github.com/iceman1001/proxmark3
This commit is contained in:
commit
a70991cf6d
|
@ -84,6 +84,7 @@ void cmac (const desfirekey_t key, uint8_t *ivect, const uint8_t *data, size_t l
|
||||||
mifare_cypher_blocks_chained (NULL, key, ivect, buffer, len, MCD_SEND, MCO_ENCYPHER);
|
mifare_cypher_blocks_chained (NULL, key, ivect, buffer, len, MCD_SEND, MCO_ENCYPHER);
|
||||||
|
|
||||||
memcpy (cmac, ivect, kbs);
|
memcpy (cmac, ivect, kbs);
|
||||||
|
free(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t key_block_size (const desfirekey_t key) {
|
size_t key_block_size (const desfirekey_t key) {
|
||||||
|
|
|
@ -158,9 +158,8 @@ void FpgaSetupSsc(void)
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
bool FpgaSetupSscDma(uint8_t *buf, int len)
|
bool FpgaSetupSscDma(uint8_t *buf, int len)
|
||||||
{
|
{
|
||||||
if (buf == NULL) {
|
if (buf == NULL)
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS; // Disable DMA Transfer
|
AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS; // Disable DMA Transfer
|
||||||
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) buf; // transfer to this memory address
|
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) buf; // transfer to this memory address
|
||||||
|
@ -184,15 +183,15 @@ static int get_from_fpga_combined_stream(z_streamp compressed_fpga_stream, uint8
|
||||||
compressed_fpga_stream->avail_out = OUTPUT_BUFFER_LEN;
|
compressed_fpga_stream->avail_out = OUTPUT_BUFFER_LEN;
|
||||||
fpga_image_ptr = output_buffer;
|
fpga_image_ptr = output_buffer;
|
||||||
int res = inflate(compressed_fpga_stream, Z_SYNC_FLUSH);
|
int res = inflate(compressed_fpga_stream, Z_SYNC_FLUSH);
|
||||||
if (res != Z_OK) {
|
|
||||||
|
if (res != Z_OK)
|
||||||
Dbprintf("inflate returned: %d, %s", res, compressed_fpga_stream->msg);
|
Dbprintf("inflate returned: %d, %s", res, compressed_fpga_stream->msg);
|
||||||
}
|
|
||||||
if (res < 0) {
|
if (res < 0)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
uncompressed_bytes_cnt++;
|
++uncompressed_bytes_cnt;
|
||||||
|
|
||||||
return *fpga_image_ptr++;
|
return *fpga_image_ptr++;
|
||||||
}
|
}
|
||||||
|
@ -210,7 +209,6 @@ static int get_from_fpga_stream(int bitstream_version, z_streamp compressed_fpga
|
||||||
}
|
}
|
||||||
|
|
||||||
return get_from_fpga_combined_stream(compressed_fpga_stream, output_buffer);
|
return get_from_fpga_combined_stream(compressed_fpga_stream, output_buffer);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -247,17 +245,15 @@ static bool reset_fpga_stream(int bitstream_version, z_streamp compressed_fpga_s
|
||||||
|
|
||||||
fpga_image_ptr = output_buffer;
|
fpga_image_ptr = output_buffer;
|
||||||
|
|
||||||
for (uint16_t i = 0; i < FPGA_BITSTREAM_FIXED_HEADER_SIZE; i++) {
|
for (uint16_t i = 0; i < FPGA_BITSTREAM_FIXED_HEADER_SIZE; i++)
|
||||||
header[i] = get_from_fpga_stream(bitstream_version, compressed_fpga_stream, output_buffer);
|
header[i] = get_from_fpga_stream(bitstream_version, compressed_fpga_stream, output_buffer);
|
||||||
}
|
|
||||||
|
|
||||||
// Check for a valid .bit file (starts with _bitparse_fixed_header)
|
// Check for a valid .bit file (starts with _bitparse_fixed_header)
|
||||||
if(memcmp(_bitparse_fixed_header, header, FPGA_BITSTREAM_FIXED_HEADER_SIZE) == 0) {
|
if(memcmp(_bitparse_fixed_header, header, FPGA_BITSTREAM_FIXED_HEADER_SIZE) == 0)
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void DownloadFPGA_byte(unsigned char w)
|
static void DownloadFPGA_byte(unsigned char w)
|
||||||
|
@ -413,7 +409,7 @@ static int bitparse_find_section(int bitstream_version, char section_name, unsig
|
||||||
void FpgaDownloadAndGo(int bitstream_version)
|
void FpgaDownloadAndGo(int bitstream_version)
|
||||||
{
|
{
|
||||||
z_stream compressed_fpga_stream;
|
z_stream compressed_fpga_stream;
|
||||||
uint8_t output_buffer[OUTPUT_BUFFER_LEN];
|
uint8_t output_buffer[OUTPUT_BUFFER_LEN] = {0x00};
|
||||||
|
|
||||||
// check whether or not the bitstream is already loaded
|
// check whether or not the bitstream is already loaded
|
||||||
if (downloaded_bitstream == bitstream_version)
|
if (downloaded_bitstream == bitstream_version)
|
||||||
|
@ -447,18 +443,17 @@ void FpgaDownloadAndGo(int bitstream_version)
|
||||||
void FpgaGatherVersion(int bitstream_version, char *dst, int len)
|
void FpgaGatherVersion(int bitstream_version, char *dst, int len)
|
||||||
{
|
{
|
||||||
unsigned int fpga_info_len;
|
unsigned int fpga_info_len;
|
||||||
char tempstr[40];
|
char tempstr[40] = {0x00};
|
||||||
z_stream compressed_fpga_stream;
|
z_stream compressed_fpga_stream;
|
||||||
uint8_t output_buffer[OUTPUT_BUFFER_LEN];
|
uint8_t output_buffer[OUTPUT_BUFFER_LEN] = {0x00};
|
||||||
|
|
||||||
dst[0] = '\0';
|
dst[0] = '\0';
|
||||||
|
|
||||||
// ensure that we can allocate enough memory for decompression:
|
// ensure that we can allocate enough memory for decompression:
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
|
|
||||||
if (!reset_fpga_stream(bitstream_version, &compressed_fpga_stream, output_buffer)) {
|
if (!reset_fpga_stream(bitstream_version, &compressed_fpga_stream, output_buffer))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if(bitparse_find_section(bitstream_version, 'a', &fpga_info_len, &compressed_fpga_stream, output_buffer)) {
|
if(bitparse_find_section(bitstream_version, 'a', &fpga_info_len, &compressed_fpga_stream, output_buffer)) {
|
||||||
for (uint16_t i = 0; i < fpga_info_len; i++) {
|
for (uint16_t i = 0; i < fpga_info_len; i++) {
|
||||||
|
|
|
@ -633,8 +633,6 @@ static RAMFUNC int ManchesterDecoding(int v)
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void RAMFUNC SnoopIClass(void)
|
void RAMFUNC SnoopIClass(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
// We won't start recording the frames that we acquire until we trigger;
|
// 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
|
// a good trigger condition to get started is probably when we see a
|
||||||
// response from the tag.
|
// response from the tag.
|
||||||
|
@ -705,8 +703,8 @@ void RAMFUNC SnoopIClass(void)
|
||||||
for(;;) {
|
for(;;) {
|
||||||
LED_A_ON();
|
LED_A_ON();
|
||||||
WDT_HIT();
|
WDT_HIT();
|
||||||
int behindBy = (lastRxCounter - AT91C_BASE_PDC_SSC->PDC_RCR) &
|
int behindBy = (lastRxCounter - AT91C_BASE_PDC_SSC->PDC_RCR) & (DMA_BUFFER_SIZE-1);
|
||||||
(DMA_BUFFER_SIZE-1);
|
|
||||||
if ( behindBy > maxBehindBy) {
|
if ( behindBy > maxBehindBy) {
|
||||||
maxBehindBy = behindBy;
|
maxBehindBy = behindBy;
|
||||||
if ( behindBy > (9 * DMA_BUFFER_SIZE / 10)) {
|
if ( behindBy > (9 * DMA_BUFFER_SIZE / 10)) {
|
||||||
|
@ -730,16 +728,16 @@ void RAMFUNC SnoopIClass(void)
|
||||||
//samples += 4;
|
//samples += 4;
|
||||||
samples += 1;
|
samples += 1;
|
||||||
|
|
||||||
if(smpl & 0xF) {
|
if(smpl & 0xF)
|
||||||
decbyte ^= (1 << (3 - div));
|
decbyte ^= (1 << (3 - div));
|
||||||
}
|
|
||||||
|
|
||||||
// FOR READER SIDE COMMUMICATION...
|
// FOR READER SIDE COMMUMICATION...
|
||||||
|
|
||||||
decbyter <<= 2;
|
decbyter <<= 2;
|
||||||
decbyter ^= (smpl & 0x30);
|
decbyter ^= (smpl & 0x30);
|
||||||
|
|
||||||
div++;
|
++div;
|
||||||
|
|
||||||
if (( div + 1) % 2 == 0) {
|
if (( div + 1) % 2 == 0) {
|
||||||
smpl = decbyter;
|
smpl = decbyter;
|
||||||
|
@ -756,7 +754,6 @@ void RAMFUNC SnoopIClass(void)
|
||||||
LogTrace(Uart.output,Uart.byteCnt, time_start, time_stop, parity, TRUE);
|
LogTrace(Uart.output,Uart.byteCnt, time_start, time_stop, parity, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* And ready to receive another command. */
|
/* And ready to receive another command. */
|
||||||
Uart.state = STATE_UNSYNCD;
|
Uart.state = STATE_UNSYNCD;
|
||||||
/* And also reset the demod code, which might have been */
|
/* And also reset the demod code, which might have been */
|
||||||
|
@ -796,7 +793,6 @@ void RAMFUNC SnoopIClass(void)
|
||||||
div = 0;
|
div = 0;
|
||||||
decbyte = 0x00;
|
decbyte = 0x00;
|
||||||
}
|
}
|
||||||
//}
|
|
||||||
|
|
||||||
if (BUTTON_PRESS()) {
|
if (BUTTON_PRESS()) {
|
||||||
DbpString("cancelled_a");
|
DbpString("cancelled_a");
|
||||||
|
@ -813,19 +809,15 @@ done:
|
||||||
AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS;
|
AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS;
|
||||||
Dbprintf("%x %x %x", maxBehindBy, Uart.state, Uart.byteCnt);
|
Dbprintf("%x %x %x", maxBehindBy, Uart.state, Uart.byteCnt);
|
||||||
Dbprintf("%x %x %x", Uart.byteCntMax, BigBuf_get_traceLen(), (int)Uart.output[0]);
|
Dbprintf("%x %x %x", Uart.byteCntMax, BigBuf_get_traceLen(), (int)Uart.output[0]);
|
||||||
LED_A_OFF();
|
LEDsoff();
|
||||||
LED_B_OFF();
|
|
||||||
LED_C_OFF();
|
|
||||||
LED_D_OFF();
|
|
||||||
set_tracing(FALSE);
|
set_tracing(FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rotateCSN(uint8_t* originalCSN, uint8_t* rotatedCSN) {
|
void rotateCSN(uint8_t* originalCSN, uint8_t* rotatedCSN) {
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < 8; i++) {
|
for(i = 0; i < 8; i++)
|
||||||
rotatedCSN[i] = (originalCSN[i] >> 3) | (originalCSN[(i+1)%8] << 5);
|
rotatedCSN[i] = (originalCSN[i] >> 3) | (originalCSN[(i+1)%8] << 5);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Wait for commands from reader
|
// Wait for commands from reader
|
||||||
|
@ -1339,15 +1331,11 @@ int doIClassSimulation( int simulationMode, uint8_t *reader_mac_buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Dbprintf("%x", cmdsRecvd);
|
LEDsoff();
|
||||||
LED_A_OFF();
|
|
||||||
LED_B_OFF();
|
|
||||||
LED_C_OFF();
|
|
||||||
|
|
||||||
if(buttonPressed)
|
if(buttonPressed)
|
||||||
{
|
|
||||||
DbpString("Button pressed");
|
DbpString("Button pressed");
|
||||||
}
|
|
||||||
return buttonPressed;
|
return buttonPressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2399,10 +2399,10 @@ void ReaderMifare(bool first_try)
|
||||||
isOK = -4; // Card's PRNG runs at an unexpected frequency or resets unexpectedly
|
isOK = -4; // Card's PRNG runs at an unexpected frequency or resets unexpectedly
|
||||||
break;
|
break;
|
||||||
} else { // continue for a while, just to collect some debug info
|
} else { // continue for a while, just to collect some debug info
|
||||||
|
++debug_info_nr;
|
||||||
debug_info[strategy][debug_info_nr] = nt_distance;
|
debug_info[strategy][debug_info_nr] = nt_distance;
|
||||||
debug_info_nr++;
|
|
||||||
if (debug_info_nr == NUM_DEBUG_INFOS) {
|
if (debug_info_nr == NUM_DEBUG_INFOS) {
|
||||||
strategy++;
|
++strategy;
|
||||||
debug_info_nr = 0;
|
debug_info_nr = 0;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
@ -2427,7 +2427,7 @@ void ReaderMifare(bool first_try)
|
||||||
}
|
}
|
||||||
catch_up_cycles /= elapsed_prng_sequences;
|
catch_up_cycles /= elapsed_prng_sequences;
|
||||||
if (catch_up_cycles == last_catch_up) {
|
if (catch_up_cycles == last_catch_up) {
|
||||||
consecutive_resyncs++;
|
++consecutive_resyncs;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
last_catch_up = catch_up_cycles;
|
last_catch_up = catch_up_cycles;
|
||||||
|
@ -2488,8 +2488,8 @@ void ReaderMifare(bool first_try)
|
||||||
|
|
||||||
if (isOK == -4) {
|
if (isOK == -4) {
|
||||||
if (MF_DBGLEVEL >= 3) {
|
if (MF_DBGLEVEL >= 3) {
|
||||||
for (uint16_t i = 0; i <= MAX_STRATEGY; i++) {
|
for (uint16_t i = 0; i <= MAX_STRATEGY; ++i) {
|
||||||
for(uint16_t j = 0; j < NUM_DEBUG_INFOS; j++) {
|
for(uint16_t j = 0; j < NUM_DEBUG_INFOS; ++j) {
|
||||||
Dbprintf("collected debug info[%d][%d] = %d", i, j, debug_info[i][j]);
|
Dbprintf("collected debug info[%d][%d] = %d", i, j, debug_info[i][j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -903,10 +903,7 @@ int SendDataTag(uint8_t *send, int sendlen, int init, int speed, uint8_t **recv)
|
||||||
*recv=answer;
|
*recv=answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
LED_A_OFF();
|
LEDsoff();
|
||||||
LED_B_OFF();
|
|
||||||
LED_C_OFF();
|
|
||||||
LED_D_OFF();
|
|
||||||
|
|
||||||
return answerLen;
|
return answerLen;
|
||||||
}
|
}
|
||||||
|
|
|
@ -608,7 +608,7 @@ void MifareAcquireEncryptedNonces(uint32_t arg0, uint32_t arg1, uint32_t flags,
|
||||||
{
|
{
|
||||||
uint64_t ui64Key = 0;
|
uint64_t ui64Key = 0;
|
||||||
uint8_t uid[10];
|
uint8_t uid[10];
|
||||||
uint32_t cuid;
|
uint32_t cuid = 0;
|
||||||
uint8_t cascade_levels = 0;
|
uint8_t cascade_levels = 0;
|
||||||
struct Crypto1State mpcs = {0, 0};
|
struct Crypto1State mpcs = {0, 0};
|
||||||
struct Crypto1State *pcs;
|
struct Crypto1State *pcs;
|
||||||
|
@ -1348,7 +1348,7 @@ void MifareCollectNonces(uint32_t arg0, uint32_t arg1){
|
||||||
|
|
||||||
void Mifare_DES_Auth1(uint8_t arg0, uint8_t *datain){
|
void Mifare_DES_Auth1(uint8_t arg0, uint8_t *datain){
|
||||||
|
|
||||||
byte_t dataout[11] = {0x00};
|
byte_t dataout[12] = {0x00};
|
||||||
uint8_t uid[10] = {0x00};
|
uint8_t uid[10] = {0x00};
|
||||||
uint32_t cuid = 0x00;
|
uint32_t cuid = 0x00;
|
||||||
|
|
||||||
|
|
|
@ -473,8 +473,11 @@ chkres(int *resc, model_t **result, const poly_t divisor, const poly_t init, int
|
||||||
pfree(&xor);
|
pfree(&xor);
|
||||||
if(aptr != eptr) return;
|
if(aptr != eptr) return;
|
||||||
|
|
||||||
if(!(*result = realloc(*result, ++*resc * sizeof(model_t))))
|
*result = realloc(*result, ++*resc * sizeof(model_t));
|
||||||
|
if (!*result) {
|
||||||
uerror("cannot reallocate result array");
|
uerror("cannot reallocate result array");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
rptr = *result + *resc - 1;
|
rptr = *result + *resc - 1;
|
||||||
rptr->spoly = pclone(divisor);
|
rptr->spoly = pclone(divisor);
|
||||||
|
|
Loading…
Reference in a new issue