From a0f74f218bd5c805d1c190af54d80ed781241148 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Fri, 23 Dec 2016 22:16:08 +0100 Subject: add CRC16-CCITT to libosmocore Use the implementation from Linux lib/crc-ccitt.c (GPLv2) Change-Id: I26bb54038f5ab36bbb34da7f5fb8ae6c0c0386a4 --- include/osmocom/core/crc16.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'include') diff --git a/include/osmocom/core/crc16.h b/include/osmocom/core/crc16.h index 83b2e5f7..f1564bd2 100644 --- a/include/osmocom/core/crc16.h +++ b/include/osmocom/core/crc16.h @@ -29,3 +29,15 @@ static inline uint16_t osmo_crc16_byte(uint16_t crc, const uint8_t data) { return (crc >> 8) ^ osmo_crc16_table[(crc ^ data) & 0xff]; } + + +/* CCITT polynome 0x8408. This corresponds to x^0 + x^5 + x^12 */ + +extern uint16_t const osmo_crc16_ccitt_table[256]; + +extern uint16_t osmo_crc16_ccitt(uint16_t crc, const uint8_t *buffer, size_t len); + +static inline uint16_t osmo_crc16_ccitt_byte(uint16_t crc, const uint8_t data) +{ + return (crc >> 8) ^ osmo_crc16_ccitt_table[(crc ^ data) & 0xff]; +} -- cgit v1.2.3