mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-08-14 02:26:59 -07:00
FIX: The input handling for "hf 14b write" is now correct. Thanks Asper for spotting the fault.
ADD: crc32.c functionality
This commit is contained in:
parent
024b97c507
commit
b5be31f996
3 changed files with 68 additions and 10 deletions
35
common/crc32.c
Normal file
35
common/crc32.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "crc32.h"
|
||||
|
||||
#define htole32(x) (x)
|
||||
#define CRC32_PRESET 0xFFFFFFFF
|
||||
|
||||
|
||||
static void crc32_byte (uint32_t *crc, const uint8_t value);
|
||||
|
||||
static void crc32_byte (uint32_t *crc, const uint8_t value) {
|
||||
/* x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1 */
|
||||
const uint32_t poly = 0xEDB88320;
|
||||
|
||||
*crc ^= value;
|
||||
for (int current_bit = 7; current_bit >= 0; current_bit--) {
|
||||
int bit_out = (*crc) & 0x00000001;
|
||||
*crc >>= 1;
|
||||
if (bit_out)
|
||||
*crc ^= poly;
|
||||
}
|
||||
}
|
||||
|
||||
void crc32 (const uint8_t *data, const size_t len, uint8_t *crc) {
|
||||
uint32_t desfire_crc = CRC32_PRESET;
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
crc32_byte (&desfire_crc, data[i]);
|
||||
}
|
||||
|
||||
*((uint32_t *)(crc)) = htole32 (desfire_crc);
|
||||
}
|
||||
|
||||
void crc32_append (uint8_t *data, const size_t len) {
|
||||
crc32 (data, len, data + len);
|
||||
}
|
15
common/crc32.h
Normal file
15
common/crc32.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// CRC32
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __CRC32_H
|
||||
#define __CRC32_H
|
||||
|
||||
void crc32 (const uint8_t *data, const size_t len, uint8_t *crc);
|
||||
void crc32_append (uint8_t *data, const size_t len);
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue