CHG: 'hf 15' - swapped crc impl to table based.

This commit is contained in:
iceman1001 2018-01-29 15:55:56 +01:00
parent 29c15b3480
commit 095b3af43b
4 changed files with 29 additions and 22 deletions

View file

@ -73,6 +73,7 @@ void reset_table(void) {
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) {
// 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;
}
// bit looped solution
uint16_t update_crc16_ex( uint16_t crc, uint8_t c, uint16_t polynomial ) {
uint16_t i, v, tmp = 0;

View file

@ -12,6 +12,7 @@
// v buffer with data
// n length
// returns crc as 16bit value
/*
uint16_t Iso15693Crc(uint8_t *v, int n)
{
uint32_t reg;
@ -30,27 +31,33 @@ uint16_t Iso15693Crc(uint8_t *v, int n)
}
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
// req[] iso15963 frame without crc
// n length without crc
// d[] iso15963 frame without crc
// n length without crc
// returns the new length of the dataframe.
int Iso15693AddCrc(uint8_t *req, int n) {
uint16_t crc = Iso15693Crc(req, n);
req[n] = crc & 0xff;
req[n+1] = crc >> 8;
return n+2;
int Iso15693AddCrc(uint8_t *d, size_t n) {
uint16_t crc = Iso15693Crc(d, n);
d[n] = crc & 0xff;
d[n+1] = crc >> 8;
return n + 2;
}
// check the CRC as described in ISO 15693-Part 3-Annex C
// v buffer with data
// n length (including crc)
// returns true if the crc is valid, else return false
bool Iso15693CheckCrc(uint8_t *v, int n) {
uint16_t crc = Iso15693Crc(v, n-2);
if ( (( crc & 0xff ) == v[n-2]) && (( crc >> 8 ) == v[n-1]) )
return true;
return false;
// If calculated with crc bytes, the residue should be 0xF0B8
bool Iso15693CheckCrc(uint8_t *d, size_t n) {
return (Iso15693Crc(d, n) == ISO15_CRC_CHECK );
//uint16_t crc = Iso15693Crc(v, n-2);
// if ( (( crc & 0xff ) == v[n-2]) && (( crc >> 8 ) == v[n-1]) )
// return true;
// return false;
}
int sprintf(char *str, const char *format, ...);
@ -77,13 +84,14 @@ uint16_t iclass_crc16(uint8_t *d, uint16_t n) {
unsigned int data;
uint16_t crc = 0xffff;
if (n == 0)
return (~crc);
do {
for (uint8_t i=0, data = *d++; i < 8; i++, data >>= 1) {
if ((crc & 0x0001) ^ (data & 0x0001))
crc = (crc >> 1) ^ POLY;
crc = (crc >> 1) ^ ISO15_CRC_POLY;
else
crc >>= 1;
}

View file

@ -7,9 +7,7 @@
#include "proxmark3.h"
#include <stdint.h>
#include <stdlib.h>
#define POLY 0x8408
#include "crc16.h"
// ISO15693 CRC
#define ISO15_CRC_PRESET (uint16_t)0xFFFF
@ -74,10 +72,10 @@
#define ISO15_CMD_SECSTATUS 0x2C
uint16_t Iso15693Crc(uint8_t *v, int n);
int Iso15693AddCrc(uint8_t *req, int n);
bool Iso15693CheckCrc(uint8_t *d, int n);
char* Iso15693sprintUID(char *target,uint8_t *uid);
uint16_t Iso15693Crc(uint8_t *d, size_t n);
int Iso15693AddCrc(uint8_t *d, size_t n);
bool Iso15693CheckCrc(uint8_t *d, size_t n);
char* Iso15693sprintUID(char *target, uint8_t *uid);
uint16_t iclass_crc16(uint8_t *d, uint16_t n);

View file

@ -119,7 +119,6 @@ typedef struct{
#define CMD_ISO_15693_COMMAND 0x0313
#define CMD_ISO_15693_COMMAND_DONE 0x0314
#define CMD_ISO_15693_FIND_AFI 0x0315
#define CMD_ISO_15693_DEBUG 0x0316
#define CMD_LF_SNOOP_RAW_ADC_SAMPLES 0x0317
// For Hitag2 transponders