// 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
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
//-----------------------------------------------------------------------------
#include "crc.h"
#include "util.h"
-#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
}
//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);
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;
-}
+
// 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) { \