From: iceman1001 Date: Fri, 12 Feb 2016 15:19:18 +0000 (+0100) Subject: CHG: had to move the SwapBits method. X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/commitdiff_plain/6bb7609cadc5868663fea41064779b767c6e382f CHG: had to move the SwapBits method. --- diff --git a/client/util.c b/client/util.c index 9d4c83ee..fcda9bde 100644 --- a/client/util.c +++ b/client/util.c @@ -503,10 +503,18 @@ uint32_t PackBits(uint8_t start, uint8_t len, uint8_t* bits) { // RotateLeft - Ultralight, Desfire, works on byte level // 00-01-02 >> 01-02-00 -void rol(uint8_t *data, const size_t len){ +void rol(uint8_t *data, const size_t len){ uint8_t first = data[0]; for (size_t i = 0; i < len-1; i++) { data[i] = data[i+1]; } data[len-1] = first; +} + +uint32_t SwapBits(uint32_t value, int nrbits) { + uint32_t newvalue = 0; + for(int i = 0; i < nrbits; i++) { + newvalue ^= ((value >> i) & 1) << (nrbits - 1 - i); + } + return newvalue; } \ No newline at end of file diff --git a/client/util.h b/client/util.h index 39ed51b4..ce3bc247 100644 --- a/client/util.h +++ b/client/util.h @@ -78,4 +78,5 @@ void wiegand_add_parity(uint8_t *target, uint8_t *source, uint8_t length); void xor(unsigned char * dst, unsigned char * src, size_t len); int32_t le24toh (uint8_t data[3]); uint32_t PackBits(uint8_t start, uint8_t len, uint8_t* bits); -void rol(uint8_t *data, const size_t len); \ No newline at end of file +void rol(uint8_t *data, const size_t len); +uint32_t SwapBits(uint32_t value, int nrbits); \ No newline at end of file diff --git a/common/crc.c b/common/crc.c index 21019da9..8e9f3996 100644 --- a/common/crc.c +++ b/common/crc.c @@ -7,7 +7,6 @@ //----------------------------------------------------------------------------- #include "crc.h" #include "util.h" -#include #include #include @@ -44,8 +43,7 @@ uint32_t crc_finish(crc_t *crc) } //credits to iceman -uint32_t CRC8Maxim(uint8_t *buff, size_t size) -{ +uint32_t CRC8Maxim(uint8_t *buff, size_t size) { crc_t crc; crc_init(&crc, 9, 0x8c, 0x00, 0x00); crc_clear(&crc); @@ -68,10 +66,4 @@ uint32_t CRC8Legic(uint8_t *buff, size_t size) { return SwapBits(crc_finish(&crc), 8); } -uint32_t SwapBits(uint32_t value, int nrbits) { - uint32_t newvalue = 0; - for(int i = 0; i < nrbits; i++) { - newvalue ^= ((value >> i) & 1) << (nrbits - 1 - i); - } - return newvalue; -} + diff --git a/common/crc.h b/common/crc.h index 0c0770a4..fc76dc48 100644 --- a/common/crc.h +++ b/common/crc.h @@ -42,7 +42,6 @@ uint32_t CRC8Maxim(uint8_t *buff, size_t size); // Calculate CRC-8/Legic checksum uint32_t CRC8Legic(uint8_t *buff, size_t size); -uint32_t SwapBits(uint32_t value, int nrbits); /* Static initialization of a crc structure */ #define CRC_INITIALIZER(_order, _polynom, _initial_value, _final_xor) { \