hamnet70/impl/src/layer1/whitening.c

26 lines
494 B
C
Raw Normal View History

2022-02-12 22:06:49 +01:00
#include <stdio.h>
#include "whitening.h"
void whitening_apply_in_place(uint8_t *data, size_t length)
{
/* 9-bit LFSR according to CCITT data whitening procedure. */
uint16_t lfsr = 0x1FF;
for(size_t i = 0; i < length; i++) {
uint8_t byte = 0;
// advance the LFSR and collect the output in a byte.
for(int k = 0; k < 8; k++) {
byte <<= 1;
byte |= lfsr & 0x001;
uint16_t tmp = lfsr ^ (lfsr >> 5);
lfsr >>= 1;
lfsr |= (tmp & 0x001) << 8;
}
data[i] ^= byte;
}
}