summaryrefslogtreecommitdiffstats
path: root/web/server/h2o/libh2o/deps/mruby/src/crc.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-03-09 13:19:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-03-09 13:20:02 +0000
commit58daab21cd043e1dc37024a7f99b396788372918 (patch)
tree96771e43bb69f7c1c2b0b4f7374cb74d7866d0cb /web/server/h2o/libh2o/deps/mruby/src/crc.c
parentReleasing debian version 1.43.2-1. (diff)
downloadnetdata-58daab21cd043e1dc37024a7f99b396788372918.tar.xz
netdata-58daab21cd043e1dc37024a7f99b396788372918.zip
Merging upstream version 1.44.3.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--web/server/h2o/libh2o/deps/mruby/src/crc.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/web/server/h2o/libh2o/deps/mruby/src/crc.c b/web/server/h2o/libh2o/deps/mruby/src/crc.c
new file mode 100644
index 000000000..290b2ca0e
--- /dev/null
+++ b/web/server/h2o/libh2o/deps/mruby/src/crc.c
@@ -0,0 +1,39 @@
+/*
+** crc.c - calculate CRC
+**
+** See Copyright Notice in mruby.h
+*/
+
+#include <limits.h>
+#include <stdint.h>
+#include <stddef.h>
+
+/* Calculate CRC (CRC-16-CCITT)
+**
+** 0000_0000_0000_0000_0000_0000_0000_0000
+** ^|------- CRC -------|- work --|
+** carry
+*/
+#define CRC_16_CCITT 0x11021ul /* x^16+x^12+x^5+1 */
+#define CRC_XOR_PATTERN (CRC_16_CCITT << 8)
+#define CRC_CARRY_BIT (0x01000000)
+
+uint16_t
+calc_crc_16_ccitt(const uint8_t *src, size_t nbytes, uint16_t crc)
+{
+ size_t ibyte;
+ uint32_t ibit;
+ uint32_t crcwk = crc << 8;
+
+ for (ibyte = 0; ibyte < nbytes; ibyte++) {
+ crcwk |= *src++;
+ for (ibit = 0; ibit < CHAR_BIT; ibit++) {
+ crcwk <<= 1;
+ if (crcwk & CRC_CARRY_BIT) {
+ crcwk ^= CRC_XOR_PATTERN;
+ }
+ }
+ }
+ return (uint16_t)(crcwk >> 8);
+}
+