diff options
| author | hibby <d@vehibberd.com> | 2018-02-16 15:18:44 +0000 |
|---|---|---|
| committer | hibby <d@vehibberd.com> | 2018-02-16 15:18:44 +0000 |
| commit | 368f5331a7641772aa7e0cd1feea57d09a394a36 (patch) | |
| tree | b421ac60cc6eb726896ea268ea24e47fc4ce7c88 /lib/crc12.cpp | |
| parent | 71c717edc92fa771c857b3c2e5ed65f523f68f90 (diff) | |
| parent | 37f727ac0746fd85504aa46c1f023c09b3eff33a (diff) | |
Update upstream source from tag 'upstream/1.8.0+repack'
Update to upstream version '1.8.0+repack'
with Debian dir a83ef78cb70a32d1211871fdc08f3ffa295e45a8
Diffstat (limited to 'lib/crc12.cpp')
| -rw-r--r-- | lib/crc12.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/crc12.cpp b/lib/crc12.cpp new file mode 100644 index 00000000..44e50fe7 --- /dev/null +++ b/lib/crc12.cpp @@ -0,0 +1,31 @@ +#include <boost/crc.hpp> +#include <boost/config.hpp> + +extern "C" +{ + short crc12 (unsigned char const * data, int length); + bool crc12_check (unsigned char const * data, int length); +} + +#define POLY 0xc06 + +#ifdef BOOST_NO_CXX11_CONSTEXPR +#define TRUNCATED_POLYNOMIAL POLY +#else +namespace +{ + unsigned long constexpr TRUNCATED_POLYNOMIAL = POLY; +} +#endif + +// assumes CRC is last 16 bits of the data and is set to zero +// caller should assign the returned CRC into the message in big endian byte order +short crc12 (unsigned char const * data, int length) +{ + return boost::augmented_crc<12, TRUNCATED_POLYNOMIAL> (data, length); +} + +bool crc12_check (unsigned char const * data, int length) +{ + return !boost::augmented_crc<12, TRUNCATED_POLYNOMIAL> (data, length); +} |
