CHG: 'hf 15' - swapped crc impl to table based.
This commit is contained in:
@@ -73,6 +73,7 @@ void reset_table(void) {
|
|||||||
crc_type = CRC_NONE;
|
crc_type = CRC_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// table lookup LUT solution
|
||||||
uint16_t crc16_fast(uint8_t const *d, size_t n, uint16_t initval, bool refin, bool refout) {
|
uint16_t crc16_fast(uint8_t const *d, size_t n, uint16_t initval, bool refin, bool refout) {
|
||||||
|
|
||||||
// fast lookup table algorithm without augmented zero bytes, e.g. used in pkzip.
|
// fast lookup table algorithm without augmented zero bytes, e.g. used in pkzip.
|
||||||
@@ -96,6 +97,7 @@ uint16_t crc16_fast(uint8_t const *d, size_t n, uint16_t initval, bool refin, bo
|
|||||||
return crc;
|
return crc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// bit looped solution
|
||||||
uint16_t update_crc16_ex( uint16_t crc, uint8_t c, uint16_t polynomial ) {
|
uint16_t update_crc16_ex( uint16_t crc, uint8_t c, uint16_t polynomial ) {
|
||||||
uint16_t i, v, tmp = 0;
|
uint16_t i, v, tmp = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
// v buffer with data
|
// v buffer with data
|
||||||
// n length
|
// n length
|
||||||
// returns crc as 16bit value
|
// returns crc as 16bit value
|
||||||
|
/*
|
||||||
uint16_t Iso15693Crc(uint8_t *v, int n)
|
uint16_t Iso15693Crc(uint8_t *v, int n)
|
||||||
{
|
{
|
||||||
uint32_t reg;
|
uint32_t reg;
|
||||||
@@ -30,27 +31,33 @@ uint16_t Iso15693Crc(uint8_t *v, int n)
|
|||||||
}
|
}
|
||||||
return ~(uint16_t)(reg & 0xffff);
|
return ~(uint16_t)(reg & 0xffff);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
uint16_t Iso15693Crc(uint8_t *d, size_t n){
|
||||||
|
init_table(CRC_15);
|
||||||
|
return crc16_x25(d, n);
|
||||||
|
}
|
||||||
|
|
||||||
// adds a CRC to a dataframe
|
// adds a CRC to a dataframe
|
||||||
// req[] iso15963 frame without crc
|
// d[] iso15963 frame without crc
|
||||||
// n length without crc
|
// n length without crc
|
||||||
// returns the new length of the dataframe.
|
// returns the new length of the dataframe.
|
||||||
int Iso15693AddCrc(uint8_t *req, int n) {
|
int Iso15693AddCrc(uint8_t *d, size_t n) {
|
||||||
uint16_t crc = Iso15693Crc(req, n);
|
uint16_t crc = Iso15693Crc(d, n);
|
||||||
req[n] = crc & 0xff;
|
d[n] = crc & 0xff;
|
||||||
req[n+1] = crc >> 8;
|
d[n+1] = crc >> 8;
|
||||||
return n+2;
|
return n + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check the CRC as described in ISO 15693-Part 3-Annex C
|
// check the CRC as described in ISO 15693-Part 3-Annex C
|
||||||
// v buffer with data
|
// v buffer with data
|
||||||
// n length (including crc)
|
// n length (including crc)
|
||||||
// returns true if the crc is valid, else return false
|
// If calculated with crc bytes, the residue should be 0xF0B8
|
||||||
bool Iso15693CheckCrc(uint8_t *v, int n) {
|
bool Iso15693CheckCrc(uint8_t *d, size_t n) {
|
||||||
uint16_t crc = Iso15693Crc(v, n-2);
|
return (Iso15693Crc(d, n) == ISO15_CRC_CHECK );
|
||||||
if ( (( crc & 0xff ) == v[n-2]) && (( crc >> 8 ) == v[n-1]) )
|
//uint16_t crc = Iso15693Crc(v, n-2);
|
||||||
return true;
|
// if ( (( crc & 0xff ) == v[n-2]) && (( crc >> 8 ) == v[n-1]) )
|
||||||
return false;
|
// return true;
|
||||||
|
// return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sprintf(char *str, const char *format, ...);
|
int sprintf(char *str, const char *format, ...);
|
||||||
@@ -77,13 +84,14 @@ uint16_t iclass_crc16(uint8_t *d, uint16_t n) {
|
|||||||
unsigned int data;
|
unsigned int data;
|
||||||
uint16_t crc = 0xffff;
|
uint16_t crc = 0xffff;
|
||||||
|
|
||||||
|
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
return (~crc);
|
return (~crc);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
for (uint8_t i=0, data = *d++; i < 8; i++, data >>= 1) {
|
for (uint8_t i=0, data = *d++; i < 8; i++, data >>= 1) {
|
||||||
if ((crc & 0x0001) ^ (data & 0x0001))
|
if ((crc & 0x0001) ^ (data & 0x0001))
|
||||||
crc = (crc >> 1) ^ POLY;
|
crc = (crc >> 1) ^ ISO15_CRC_POLY;
|
||||||
else
|
else
|
||||||
crc >>= 1;
|
crc >>= 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,7 @@
|
|||||||
#include "proxmark3.h"
|
#include "proxmark3.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include "crc16.h"
|
||||||
#define POLY 0x8408
|
|
||||||
|
|
||||||
|
|
||||||
// ISO15693 CRC
|
// ISO15693 CRC
|
||||||
#define ISO15_CRC_PRESET (uint16_t)0xFFFF
|
#define ISO15_CRC_PRESET (uint16_t)0xFFFF
|
||||||
@@ -74,10 +72,10 @@
|
|||||||
#define ISO15_CMD_SECSTATUS 0x2C
|
#define ISO15_CMD_SECSTATUS 0x2C
|
||||||
|
|
||||||
|
|
||||||
uint16_t Iso15693Crc(uint8_t *v, int n);
|
uint16_t Iso15693Crc(uint8_t *d, size_t n);
|
||||||
int Iso15693AddCrc(uint8_t *req, int n);
|
int Iso15693AddCrc(uint8_t *d, size_t n);
|
||||||
bool Iso15693CheckCrc(uint8_t *d, int n);
|
bool Iso15693CheckCrc(uint8_t *d, size_t n);
|
||||||
char* Iso15693sprintUID(char *target,uint8_t *uid);
|
char* Iso15693sprintUID(char *target, uint8_t *uid);
|
||||||
|
|
||||||
uint16_t iclass_crc16(uint8_t *d, uint16_t n);
|
uint16_t iclass_crc16(uint8_t *d, uint16_t n);
|
||||||
|
|
||||||
|
|||||||
@@ -119,7 +119,6 @@ typedef struct{
|
|||||||
#define CMD_ISO_15693_COMMAND 0x0313
|
#define CMD_ISO_15693_COMMAND 0x0313
|
||||||
#define CMD_ISO_15693_COMMAND_DONE 0x0314
|
#define CMD_ISO_15693_COMMAND_DONE 0x0314
|
||||||
#define CMD_ISO_15693_FIND_AFI 0x0315
|
#define CMD_ISO_15693_FIND_AFI 0x0315
|
||||||
#define CMD_ISO_15693_DEBUG 0x0316
|
|
||||||
#define CMD_LF_SNOOP_RAW_ADC_SAMPLES 0x0317
|
#define CMD_LF_SNOOP_RAW_ADC_SAMPLES 0x0317
|
||||||
|
|
||||||
// For Hitag2 transponders
|
// For Hitag2 transponders
|
||||||
|
|||||||
Reference in New Issue
Block a user