Source

CRC / crc.c

Full commit
#include "crc.h"



void crc16_init(uint16_t* crc)
{
    *crc = CRC16_INIT;
}

void crc16_finish(uint16_t* crc)
{

}

// Most Significant Bit first
void crc16_update(uint16_t* crc, uint8_t* data, size_t length)
{
    int i;
    uint16_t byte;
    while (length-- > 0)
    {
        byte = (uint16_t)*data++ << 8;
        for (i=0; i<8; i++)
        {
            if ( (*crc & 0x8000) ^ (byte & 0x8000) )
            {
                *crc = (*crc << 1) ^ CRC16_POLY;
            }
            else
            {
                *crc <<= 1;
            }
            byte <<= 1;
        }
    }
}

uint16_t crc16(uint8_t* data, size_t length)
{
    uint16_t crc;
    crc16_init(&crc);
    crc16_update(&crc, data, length);
    crc16_finish(&crc);
    return crc;
}