CHG: had to move the SwapBits method.

This commit is contained in:
iceman1001 2016-02-12 16:19:18 +01:00
commit 6bb7609cad
4 changed files with 13 additions and 13 deletions

View file

@ -503,10 +503,18 @@ uint32_t PackBits(uint8_t start, uint8_t len, uint8_t* bits) {
// RotateLeft - Ultralight, Desfire, works on byte level // RotateLeft - Ultralight, Desfire, works on byte level
// 00-01-02 >> 01-02-00 // 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]; uint8_t first = data[0];
for (size_t i = 0; i < len-1; i++) { for (size_t i = 0; i < len-1; i++) {
data[i] = data[i+1]; data[i] = data[i+1];
} }
data[len-1] = first; 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;
} }

View file

@ -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); void xor(unsigned char * dst, unsigned char * src, size_t len);
int32_t le24toh (uint8_t data[3]); int32_t le24toh (uint8_t data[3]);
uint32_t PackBits(uint8_t start, uint8_t len, uint8_t* bits); uint32_t PackBits(uint8_t start, uint8_t len, uint8_t* bits);
void rol(uint8_t *data, const size_t len); void rol(uint8_t *data, const size_t len);
uint32_t SwapBits(uint32_t value, int nrbits);

View file

@ -7,7 +7,6 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include "crc.h" #include "crc.h"
#include "util.h" #include "util.h"
#include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
@ -44,8 +43,7 @@ uint32_t crc_finish(crc_t *crc)
} }
//credits to iceman //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_t crc;
crc_init(&crc, 9, 0x8c, 0x00, 0x00); crc_init(&crc, 9, 0x8c, 0x00, 0x00);
crc_clear(&crc); crc_clear(&crc);
@ -68,10 +66,4 @@ uint32_t CRC8Legic(uint8_t *buff, size_t size) {
return SwapBits(crc_finish(&crc), 8); 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;
}

View file

@ -42,7 +42,6 @@ uint32_t CRC8Maxim(uint8_t *buff, size_t size);
// Calculate CRC-8/Legic checksum // Calculate CRC-8/Legic checksum
uint32_t CRC8Legic(uint8_t *buff, size_t size); uint32_t CRC8Legic(uint8_t *buff, size_t size);
uint32_t SwapBits(uint32_t value, int nrbits);
/* Static initialization of a crc structure */ /* Static initialization of a crc structure */
#define CRC_INITIALIZER(_order, _polynom, _initial_value, _final_xor) { \ #define CRC_INITIALIZER(_order, _polynom, _initial_value, _final_xor) { \