librnr  1.14.5
RoadNarrows Robotics Common Library 1
checksum.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 /*! \file
3  *
4  * \brief Checksum algorithms.
5  *
6  * \pkgsynopsis
7  * RoadNarrows Robotics Common Library 1
8  *
9  * \pkgcomponent{Library}
10  * librnr
11  *
12  * \pkgfile{rnr/checksum.h}
13  *
14  * \author Daniel Packard (daniel@roadnarrows.com)
15  * \author Robin Knight (robin.knight@roadnarrows.com)
16  *
17  * \pkgcopyright{2010-2018,RoadNarrows LLC.,http://www.roadnarrows.com}
18  *
19  * \license{MIT}
20  *
21  * \EulaBegin
22  * See the README and EULA files for any copyright and licensing information.
23  * \EulaEnd
24  */
25 ////////////////////////////////////////////////////////////////////////////////
26 
27 #ifndef _RNR_CHECKSUM_H
28 #define _RNR_CHECKSUM_H
29 
30 #include <sys/types.h>
31 
32 #include "rnr/rnrconfig.h"
33 
34 #define CRC32_POLY_NORM 0x04c11db7 ///< 32-bit crc in normal (MSB) form
35 
37 
38 /*!
39  * \brief Computes the modular 8-bit checksum over buffer.
40  *
41  * The two's complitment is not taken.
42  *
43  * \param buf Buffer to checksum.
44  * \param len Number of bytes in buf.
45  *
46  * \return 8-bit sum of bytes, discarding overflow.
47  */
48 extern u8_t generate_checksum8(byte_t buf[], size_t len);
49 
50 /*!
51  * \brief Computes the modular 16-bit checksum over buffer.
52  *
53  * The two's complitment is not taken.
54  *
55  * \param buf Buffer to checksum.
56  * \param len Number of bytes in buf.
57  *
58  * \return 16-bit sum of bytes, discarding overflow.
59  */
60 extern u16_t generate_checksum16(byte_t buf[], size_t len);
61 
62 /*!
63  * \brief Computes the modular 32-bit checksum over buffer.
64  *
65  * The two's complitment is not taken.
66  *
67  * \param buf Buffer to checksum
68  * \param len Number of bytes in buf.
69  *
70  * \return 32-bit sum of bytes, discarding overflow.
71  */
72 extern u32_t generate_checksum32(byte_t buf[], size_t len);
73 
74 /*!
75  *
76  * \brief Computes the 32-bit cyclic redundance check over buffer.
77  *
78  * CRC polynomial: 0x04C11DB7 (normal representation).
79  *
80  * This CRC-32 is used by Ethernet, MPEG-2, gzip, gzip2, and others.
81  *
82  * \par This CRC can be specified as:
83  * \termblock
84  * \term width \termdata 32 \endterm
85  * \term poly \termdata 0x04c11db7 \endterm
86  * \term init \termdata 0xffffffff \endterm
87  * \term refin \termdata false \endterm
88  * \term refout \termdata false \endterm
89  * \term xorout \termdata true \endterm
90  * \endtermblock
91  *
92  * \param buf Buffer to checksum
93  * \param len Number of bytes in buf.
94  *
95  * \return 32-bit CRC
96  */
97 extern u32_t generate_crc32(byte_t buf[], size_t len);
98 
100 
101 #endif // _RNR_CHECKSUM_H
u8_t generate_checksum8(byte_t buf[], size_t len)
Computes the modular 8-bit checksum over buffer.
Definition: checksum.c:100
__uint16_t u16_t
16-bit unsigned integer
Definition: rnrconfig.h:168
u32_t generate_crc32(byte_t buf[], size_t len)
Computes the 32-bit cyclic redundance check over buffer.
Definition: checksum.c:139
#define C_DECLS_BEGIN
C declaration block begin in C.
Definition: rnrconfig.h:71
__uint8_t u8_t
8-bit unsigned integer
Definition: rnrconfig.h:166
RoadNarrows Robotics common configuration file.
__uint32_t u32_t
32-bit unsigned integer
Definition: rnrconfig.h:170
u8_t byte_t
8-bit byte
Definition: rnrconfig.h:177
#define C_DECLS_END
C declaration block end in C.
Definition: rnrconfig.h:72
u16_t generate_checksum16(byte_t buf[], size_t len)
Computes the modular 16-bit checksum over buffer.
Definition: checksum.c:113
u32_t generate_checksum32(byte_t buf[], size_t len)
Computes the modular 32-bit checksum over buffer.
Definition: checksum.c:126