mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-07-05 20:41:34 -07:00
Update Crc16 function to use bitlength instead of length
This commit is contained in:
parent
6a671616b9
commit
ff1289c03d
2 changed files with 10 additions and 5 deletions
|
@ -142,12 +142,17 @@ uint16_t update_crc16(uint16_t crc, uint8_t c) {
|
|||
}
|
||||
|
||||
// two ways. msb or lsb loop.
|
||||
uint16_t Crc16(uint8_t const *d, size_t length, uint16_t remainder, uint16_t polynomial, bool refin, bool refout) {
|
||||
if (length == 0)
|
||||
uint16_t Crc16(uint8_t const *d, size_t bitlength, uint16_t remainder, uint16_t polynomial, bool refin, bool refout) {
|
||||
if (bitlength == 0)
|
||||
return (~remainder);
|
||||
|
||||
for (uint32_t i = 0; i < length; ++i) {
|
||||
uint8_t c = d[i];
|
||||
uint8_t offset = 8 - (bitlength % 8);
|
||||
// front padding with 0s won't change the CRC result
|
||||
uint8_t prebits = 0;
|
||||
for (uint32_t i = 0; i < (bitlength + 7) / 8; ++i) {
|
||||
uint8_t c = prebits | d[i] >> offset;
|
||||
prebits = d[i] << (8 - offset);
|
||||
|
||||
if (refin) c = reflect8(c);
|
||||
|
||||
// xor in at msb
|
||||
|
|
|
@ -47,7 +47,7 @@ typedef enum {
|
|||
|
||||
uint16_t update_crc16_ex(uint16_t crc, uint8_t c, uint16_t polynomial);
|
||||
uint16_t update_crc16(uint16_t crc, uint8_t c);
|
||||
uint16_t Crc16(uint8_t const *d, size_t length, uint16_t remainder, uint16_t polynomial, bool refin, bool refout);
|
||||
uint16_t Crc16(uint8_t const *d, size_t bitlength, uint16_t remainder, uint16_t polynomial, bool refin, bool refout);
|
||||
|
||||
uint16_t Crc16ex(CrcType_t ct, const uint8_t *d, size_t n);
|
||||
void compute_crc(CrcType_t ct, const uint8_t *d, size_t n, uint8_t *first, uint8_t *second);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue