-
-
Notifications
You must be signed in to change notification settings - Fork 63
/
crc.h
72 lines (65 loc) · 2 KB
/
crc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* @file hash/crc.h
*
* @section License
* Copyright (C) 2015-2016, Erik Moqvist
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* This file is part of the Simba project.
*/
#ifndef __HASH_CRC_H__
#define __HASH_CRC_H__
#include "simba.h"
/**
* Calculate a 32 bits crc using the polynomial
* ``x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x^1+x^0``.
*
* @param[in] crc Initial crc. Often 0x00000000.
* @param[in] buf_p Buffer to calculate crc of.
* @param[in] size Size of the buffer.
*
* @return Calculated crc.
*/
uint32_t crc_32(uint32_t crc, const void *buf_p, size_t size);
/**
* Calculate a 16 bits crc using the CCITT algorithm (polynomial
* ``x^16+x^12+x^5+x^1``).
*
* @param[in] crc Initial crc. Should be 0xffff for CCITT.
* @param[in] buf_p Buffer to calculate crc of.
* @param[in] size Size of the buffer.
*
* @return Calculated crc.
*/
uint16_t crc_ccitt(uint16_t crc, const void *buf_p, size_t size);
/**
* Calculate a 16 bits crc using the XModem algorithm (polynomial
* ``x^16+x^12+x^5+x^1``).
*
* @param[in] crc Initial crc. Should be 0x0000 for XModem.
* @param[in] buf_p Buffer to calculate crc of.
* @param[in] size Size of the buffer.
*
* @return Calculated crc.
*/
uint16_t crc_xmodem(uint16_t crc, const void *buf_p, size_t size);
/**
* Calculate a 8 bits crc using the CRC-7 algorithm (polynomial
* ``x^7+x^3+1``).
*
* @param[in] buf_p Buffer to calculate crc of.
* @param[in] size Size of the buffer.
*
* @return Calculated crc.
*/
uint8_t crc_7(const void* buf_p, size_t size);
#endif