]> git.proxmox.com Git - mirror_qemu.git/blame - include/qemu/crc-ccitt.h
Merge tag 'pull-loongarch-20231221' of https://gitlab.com/gaosong/qemu into staging
[mirror_qemu.git] / include / qemu / crc-ccitt.h
CommitLineData
0b73ce30
BM
1/*
2 * CRC16 (CCITT) Checksum Algorithm
3 *
4 * Copyright (c) 2021 Wind River Systems, Inc.
5 *
6 * Author:
7 * Bin Meng <bin.meng@windriver.com>
8 *
9 * From Linux kernel v5.10 include/linux/crc-ccitt.h
10 *
11 * SPDX-License-Identifier: GPL-2.0
12 */
13
9c092804
MA
14#ifndef CRC_CCITT_H
15#define CRC_CCITT_H
0b73ce30
BM
16
17extern uint16_t const crc_ccitt_table[256];
18extern uint16_t const crc_ccitt_false_table[256];
19
f703f1ef
PMD
20uint16_t crc_ccitt(uint16_t crc, const uint8_t *buffer, size_t len);
21uint16_t crc_ccitt_false(uint16_t crc, const uint8_t *buffer, size_t len);
0b73ce30
BM
22
23static inline uint16_t crc_ccitt_byte(uint16_t crc, const uint8_t c)
24{
25 return (crc >> 8) ^ crc_ccitt_table[(crc ^ c) & 0xff];
26}
27
28static inline uint16_t crc_ccitt_false_byte(uint16_t crc, const uint8_t c)
29{
30 return (crc << 8) ^ crc_ccitt_false_table[(crc >> 8) ^ c];
31}
32
9c092804 33#endif /* CRC_CCITT_H */