CHG: trying to unify the crc algos in one place.

This commit is contained in:
iceman1001 2016-08-04 21:52:32 +02:00
commit 82e690f48b
4 changed files with 32 additions and 14 deletions

View file

@ -82,7 +82,6 @@ uint32_t CRC8Maxim(uint8_t *buff, size_t size) {
return crc_finish(&crc);
}
// width=4 poly=0xC, reversed poly=0x7 init=0x5 refin=true refout=true xorout=0x0000 check= name="CRC-4/LEGIC"
// width=8 poly=0x63, reversed poly=0x8D init=0x55 refin=true refout=true xorout=0x0000 check=0xC6 name="CRC-8/LEGIC"
// the CRC needs to be reversed before returned.
@ -126,4 +125,21 @@ uint32_t CRC16_CCITT(uint8_t *buff, size_t size) {
for ( int i=0; i < size; ++i)
crc_update(&crc, buff[i], 8);
return crc_finish(&crc);
}
//width=16 poly=0x8408 init=0xffff refin=false refout=true xorout=0xffff check=0xF0B8 name="CRC-16/ISO/IEC 13239"
uint32_t CRC16_Iso15693(uint8_t *buff, size_t size) {
crc_t crc;
crc_init_ref(&crc, 16, 0x8408, 0xFFFF, 0xFFFF, true, false);
for ( int i=0; i < size; ++i)
crc_update(&crc, buff[i], 8);
return reflect(crc_finish(&crc), 16);
}
//width=16 poly=0x8408 init=0xffff refin=true refout=true xorout=0x0BC3 check=0xF0B8 name="CRC-16/ICLASS"
uint32_t CRC16_ICLASS(uint8_t *buff, size_t size) {
crc_t crc;
crc_init_ref(&crc, 16, 0x8408, 0xFFFF, 0x0BC3, false, false);
for ( int i=0; i < size; ++i)
crc_update(&crc, buff[i], 8);
return crc_finish(&crc);
}

View file

@ -68,6 +68,8 @@ uint32_t CRC16Legic(uint8_t *buff, size_t size, uint8_t uidcrc);
// test crc 16.
uint32_t CRC16_DNP(uint8_t *buff, size_t size);
uint32_t CRC16_CCITT(uint8_t *buff, size_t size);
uint32_t CRC16_Iso15693(uint8_t *buff, size_t size);
uint32_t CRC16_ICLASS(uint8_t *buff, size_t size);
/* Static initialization of a crc structure */
#define CRC_INITIALIZER(_order, _polynom, _initial_value, _final_xor) { \

View file

@ -6,14 +6,7 @@
// ISO15693 CRC & other commons
//-----------------------------------------------------------------------------
#include "proxmark3.h"
#include <stdint.h>
#include <stdlib.h>
//#include "iso15693tools.h"
#define POLY 0x8408
#include "iso15693tools.h"
// The CRC as described in ISO 15693-Part 3-Annex C
// v buffer with data
@ -59,11 +52,11 @@ int sprintf(char *str, const char *format, ...);
// uid[] the UID in transmission order
// return: ptr to string
char* Iso15693sprintUID(char *target,uint8_t *uid) {
static char tempbuf[2*8+1]="";
if (target==NULL) target=tempbuf;
sprintf(target,"%02X%02X%02X%02X%02X%02X%02X%02X",
uid[7],uid[6],uid[5],uid[4],uid[3],uid[2],uid[1],uid[0]);
return target;
static char tempbuf[2*8+1] = "";
if (target==NULL) target=tempbuf;
sprintf(target,"%02X%02X%02X%02X%02X%02X%02X%02X",
uid[7],uid[6],uid[5],uid[4],uid[3],uid[2],uid[1],uid[0]);
return target;
}
uint16_t iclass_crc16(char *data_p, unsigned short length)

View file

@ -4,6 +4,13 @@
#ifndef ISO15693_H__
#define ISO15693_H__
#include "proxmark3.h"
#include <stdint.h>
#include <stdlib.h>
#define POLY 0x8408
// ISO15693 CRC
#define ISO15_CRC_PRESET (uint16_t)0xFFFF
#define ISO15_CRC_POLY (uint16_t)0x8408