...
Register Value | Index | Value | Value=1? | Calculation | New Register Value (xor with LSFR Sequence starting at the 5th (0xF1) |
---|---|---|---|---|---|
00 | 23 -MSB | 1 | Yes | 00 xor f1 | f1 |
f1 | 22 | 1 | Yes | f1 xor e0 | 11 |
11 | 21 | 1 | Yes | 11 xor 70 | 61 |
... | |||||
13 | 0 | 0 | No | - | 13 |
...
Checksum Source Code
Code Block |
---|
#define MESSAGE_SIZE 32 #define OFFSET 4 uint8_t LSFR_sequence[MESSAGE_SIZE] = {0}; void calculateLSFR() { int i; uint8_t reg = 0x7C; uint8_t temp_reg = 0; for (i = 0; i < MESSAGE_SIZE; i++) { temp_reg = reg & 0x01; reg >>= 1; reg |= (temp_reg << 7); if (temp_reg) { reg ^= 0x18; } LSFR_sequence[i] = reg; //printf("%02x\n", LSFR_sequence[i]); } } uint8_t combineLSFR(uint8_t len, uint8_t *data) { uint8_t hash_reg = 0; // not 0x64 int byte_idx, bit_idx; uint8_t byte, bit; //printf("***COMBINE\n"); for (byte_idx = 0; byte_idx < len; byte_idx++) { for (bit_idx = 7; bit_idx >= 0; bit_idx--) { bit = (data[byte_idx] & (1 << bit_idx)) >> bit_idx; if (bit) { hash_reg ^= LSFR_sequence[byte_idx * 8 + (7 - bit_idx) + OFFSET]; //printf("[%d]: %02x\n", byte_idx * 8 + (7 - bit_idx), hash_reg); } bit = 0; } } return hash_reg; } uint8_t Checksum(int length, uint8_t *buff) { calculateLSFR(); return combineLSFR(length, buff); } |
...