precompiled-digest-crc 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/cibuildgem.yaml +89 -0
  3. data/.github/workflows/integration.yml +26 -0
  4. data/.github/workflows/ruby.yml +33 -0
  5. data/.gitignore +11 -0
  6. data/.rspec +1 -0
  7. data/.yardopts +1 -0
  8. data/ChangeLog.md +212 -0
  9. data/Gemfile +16 -0
  10. data/LICENSE.txt +20 -0
  11. data/README.md +401 -0
  12. data/Rakefile +57 -0
  13. data/benchmarks.rb +59 -0
  14. data/digest-crc.gemspec +65 -0
  15. data/ext/digest/Rakefile +46 -0
  16. data/ext/digest/compat/ruby.h +11 -0
  17. data/ext/digest/crc12_3gpp/crc12_3gpp.c +68 -0
  18. data/ext/digest/crc12_3gpp/crc12_3gpp.h +11 -0
  19. data/ext/digest/crc12_3gpp/crc12_3gpp_ext.c +32 -0
  20. data/ext/digest/crc12_3gpp/extconf.rb +7 -0
  21. data/ext/digest/crc15/crc15.c +54 -0
  22. data/ext/digest/crc15/crc15.h +11 -0
  23. data/ext/digest/crc15/crc15_ext.c +33 -0
  24. data/ext/digest/crc15/extconf.rb +7 -0
  25. data/ext/digest/crc16/crc16.c +70 -0
  26. data/ext/digest/crc16/crc16.h +11 -0
  27. data/ext/digest/crc16/crc16_ext.c +33 -0
  28. data/ext/digest/crc16/extconf.rb +7 -0
  29. data/ext/digest/crc16_ccitt/crc16_ccitt.c +70 -0
  30. data/ext/digest/crc16_ccitt/crc16_ccitt.h +8 -0
  31. data/ext/digest/crc16_ccitt/crc16_ccitt_ext.c +33 -0
  32. data/ext/digest/crc16_ccitt/extconf.rb +7 -0
  33. data/ext/digest/crc16_dnp/crc16_dnp.c +54 -0
  34. data/ext/digest/crc16_dnp/crc16_dnp.h +8 -0
  35. data/ext/digest/crc16_dnp/crc16_dnp_ext.c +33 -0
  36. data/ext/digest/crc16_dnp/extconf.rb +7 -0
  37. data/ext/digest/crc16_genibus/crc16_genibus.c +70 -0
  38. data/ext/digest/crc16_genibus/crc16_genibus.h +8 -0
  39. data/ext/digest/crc16_genibus/crc16_genibus_ext.c +33 -0
  40. data/ext/digest/crc16_genibus/extconf.rb +7 -0
  41. data/ext/digest/crc16_kermit/crc16_kermit.c +70 -0
  42. data/ext/digest/crc16_kermit/crc16_kermit.h +8 -0
  43. data/ext/digest/crc16_kermit/crc16_kermit_ext.c +33 -0
  44. data/ext/digest/crc16_kermit/extconf.rb +7 -0
  45. data/ext/digest/crc16_modbus/crc16_modbus.c +70 -0
  46. data/ext/digest/crc16_modbus/crc16_modbus.h +8 -0
  47. data/ext/digest/crc16_modbus/crc16_modbus_ext.c +32 -0
  48. data/ext/digest/crc16_modbus/extconf.rb +7 -0
  49. data/ext/digest/crc16_usb/crc16_usb.c +70 -0
  50. data/ext/digest/crc16_usb/crc16_usb.h +8 -0
  51. data/ext/digest/crc16_usb/crc16_usb_ext.c +32 -0
  52. data/ext/digest/crc16_usb/extconf.rb +7 -0
  53. data/ext/digest/crc16_x_25/crc16_x_25.c +70 -0
  54. data/ext/digest/crc16_x_25/crc16_x_25.h +8 -0
  55. data/ext/digest/crc16_x_25/crc16_x_25_ext.c +32 -0
  56. data/ext/digest/crc16_x_25/extconf.rb +7 -0
  57. data/ext/digest/crc16_xmodem/crc16_xmodem.c +70 -0
  58. data/ext/digest/crc16_xmodem/crc16_xmodem.h +8 -0
  59. data/ext/digest/crc16_xmodem/crc16_xmodem_ext.c +33 -0
  60. data/ext/digest/crc16_xmodem/extconf.rb +7 -0
  61. data/ext/digest/crc16_zmodem/crc16_zmodem.c +70 -0
  62. data/ext/digest/crc16_zmodem/crc16_zmodem.h +8 -0
  63. data/ext/digest/crc16_zmodem/crc16_zmodem_ext.c +33 -0
  64. data/ext/digest/crc16_zmodem/extconf.rb +7 -0
  65. data/ext/digest/crc24/crc24.c +70 -0
  66. data/ext/digest/crc24/crc24.h +11 -0
  67. data/ext/digest/crc24/crc24_ext.c +32 -0
  68. data/ext/digest/crc24/extconf.rb +7 -0
  69. data/ext/digest/crc32/crc32.c +69 -0
  70. data/ext/digest/crc32/crc32.h +11 -0
  71. data/ext/digest/crc32/crc32_ext.c +32 -0
  72. data/ext/digest/crc32/extconf.rb +7 -0
  73. data/ext/digest/crc32_bzip2/crc32_bzip2.c +70 -0
  74. data/ext/digest/crc32_bzip2/crc32_bzip2.h +8 -0
  75. data/ext/digest/crc32_bzip2/crc32_bzip2_ext.c +32 -0
  76. data/ext/digest/crc32_bzip2/extconf.rb +7 -0
  77. data/ext/digest/crc32_jam/crc32_jam.c +70 -0
  78. data/ext/digest/crc32_jam/crc32_jam.h +8 -0
  79. data/ext/digest/crc32_jam/crc32_jam_ext.c +31 -0
  80. data/ext/digest/crc32_jam/extconf.rb +7 -0
  81. data/ext/digest/crc32_mpeg/crc32_mpeg.c +70 -0
  82. data/ext/digest/crc32_mpeg/crc32_mpeg.h +8 -0
  83. data/ext/digest/crc32_mpeg/crc32_mpeg_ext.c +32 -0
  84. data/ext/digest/crc32_mpeg/extconf.rb +7 -0
  85. data/ext/digest/crc32_posix/crc32_posix.c +70 -0
  86. data/ext/digest/crc32_posix/crc32_posix.h +8 -0
  87. data/ext/digest/crc32_posix/crc32_posix_ext.c +32 -0
  88. data/ext/digest/crc32_posix/extconf.rb +7 -0
  89. data/ext/digest/crc32_xfer/crc32_xfer.c +70 -0
  90. data/ext/digest/crc32_xfer/crc32_xfer.h +8 -0
  91. data/ext/digest/crc32_xfer/crc32_xfer_ext.c +32 -0
  92. data/ext/digest/crc32_xfer/extconf.rb +7 -0
  93. data/ext/digest/crc32c/crc32c.c +70 -0
  94. data/ext/digest/crc32c/crc32c.h +8 -0
  95. data/ext/digest/crc32c/crc32c_ext.c +31 -0
  96. data/ext/digest/crc32c/extconf.rb +7 -0
  97. data/ext/digest/crc5/crc5.c +54 -0
  98. data/ext/digest/crc5/crc5.h +11 -0
  99. data/ext/digest/crc5/crc5_ext.c +32 -0
  100. data/ext/digest/crc5/extconf.rb +7 -0
  101. data/ext/digest/crc64/crc64.c +102 -0
  102. data/ext/digest/crc64/crc64.h +11 -0
  103. data/ext/digest/crc64/crc64_ext.c +32 -0
  104. data/ext/digest/crc64/extconf.rb +7 -0
  105. data/ext/digest/crc64_jones/crc64_jones.c +102 -0
  106. data/ext/digest/crc64_jones/crc64_jones.h +8 -0
  107. data/ext/digest/crc64_jones/crc64_jones_ext.c +31 -0
  108. data/ext/digest/crc64_jones/extconf.rb +7 -0
  109. data/ext/digest/crc64_nvme/crc64_nvme.c +102 -0
  110. data/ext/digest/crc64_nvme/crc64_nvme.h +8 -0
  111. data/ext/digest/crc64_nvme/crc64_nvme_ext.c +31 -0
  112. data/ext/digest/crc64_nvme/extconf.rb +7 -0
  113. data/ext/digest/crc64_xz/crc64_xz.c +102 -0
  114. data/ext/digest/crc64_xz/crc64_xz.h +8 -0
  115. data/ext/digest/crc64_xz/crc64_xz_ext.c +31 -0
  116. data/ext/digest/crc64_xz/extconf.rb +7 -0
  117. data/ext/digest/crc8/crc8.c +54 -0
  118. data/ext/digest/crc8/crc8.h +11 -0
  119. data/ext/digest/crc8/crc8_ext.c +32 -0
  120. data/ext/digest/crc8/extconf.rb +7 -0
  121. data/ext/digest/crc8_1wire/crc8_1wire.c +54 -0
  122. data/ext/digest/crc8_1wire/crc8_1wire.h +8 -0
  123. data/ext/digest/crc8_1wire/crc8_1wire_ext.c +31 -0
  124. data/ext/digest/crc8_1wire/extconf.rb +7 -0
  125. data/gemspec.yml +25 -0
  126. data/lib/digest/crc.rb +211 -0
  127. data/lib/digest/crc1.rb +37 -0
  128. data/lib/digest/crc15.rb +45 -0
  129. data/lib/digest/crc16.rb +61 -0
  130. data/lib/digest/crc16_ccitt.rb +59 -0
  131. data/lib/digest/crc16_dnp.rb +62 -0
  132. data/lib/digest/crc16_genibus.rb +65 -0
  133. data/lib/digest/crc16_kermit.rb +59 -0
  134. data/lib/digest/crc16_modbus.rb +57 -0
  135. data/lib/digest/crc16_qt.rb +11 -0
  136. data/lib/digest/crc16_usb.rb +23 -0
  137. data/lib/digest/crc16_x_25.rb +63 -0
  138. data/lib/digest/crc16_xmodem.rb +57 -0
  139. data/lib/digest/crc16_zmodem.rb +57 -0
  140. data/lib/digest/crc24.rb +61 -0
  141. data/lib/digest/crc32.rb +95 -0
  142. data/lib/digest/crc32_bzip2.rb +57 -0
  143. data/lib/digest/crc32_jam.rb +16 -0
  144. data/lib/digest/crc32_mpeg.rb +94 -0
  145. data/lib/digest/crc32_posix.rb +58 -0
  146. data/lib/digest/crc32_xfer.rb +61 -0
  147. data/lib/digest/crc32c.rb +87 -0
  148. data/lib/digest/crc5.rb +58 -0
  149. data/lib/digest/crc64.rb +95 -0
  150. data/lib/digest/crc64_jones.rb +93 -0
  151. data/lib/digest/crc64_nvme.rb +95 -0
  152. data/lib/digest/crc64_xz.rb +95 -0
  153. data/lib/digest/crc8.rb +45 -0
  154. data/lib/digest/crc8_1wire.rb +42 -0
  155. metadata +265 -0
@@ -0,0 +1,68 @@
1
+ /**
2
+ * \file
3
+ * Functions and types for CRC checks.
4
+ *
5
+ * Generated on Sat Feb 29 02:30:42 2020
6
+ * by pycrc v0.9.2, https://pycrc.org
7
+ * using the configuration:
8
+ * - Width = 12
9
+ * - Poly = 0x80f
10
+ * - XorIn = 0x000
11
+ * - ReflectIn = False
12
+ * - XorOut = 0x000
13
+ * - ReflectOut = True
14
+ * - Algorithm = table-driven
15
+ */
16
+
17
+ #include "crc12_3gpp.h"
18
+
19
+ /**
20
+ * Static table used for the table_driven implementation.
21
+ */
22
+ static const crc12_t crc12_table[256] = {
23
+ 0x000, 0x80f, 0x811, 0x01e, 0x82d, 0x022, 0x03c, 0x833, 0x855, 0x05a, 0x044, 0x84b, 0x078, 0x877, 0x869, 0x066,
24
+ 0x8a5, 0x0aa, 0x0b4, 0x8bb, 0x088, 0x887, 0x899, 0x096, 0x0f0, 0x8ff, 0x8e1, 0x0ee, 0x8dd, 0x0d2, 0x0cc, 0x8c3,
25
+ 0x945, 0x14a, 0x154, 0x95b, 0x168, 0x967, 0x979, 0x176, 0x110, 0x91f, 0x901, 0x10e, 0x93d, 0x132, 0x12c, 0x923,
26
+ 0x1e0, 0x9ef, 0x9f1, 0x1fe, 0x9cd, 0x1c2, 0x1dc, 0x9d3, 0x9b5, 0x1ba, 0x1a4, 0x9ab, 0x198, 0x997, 0x989, 0x186,
27
+ 0xa85, 0x28a, 0x294, 0xa9b, 0x2a8, 0xaa7, 0xab9, 0x2b6, 0x2d0, 0xadf, 0xac1, 0x2ce, 0xafd, 0x2f2, 0x2ec, 0xae3,
28
+ 0x220, 0xa2f, 0xa31, 0x23e, 0xa0d, 0x202, 0x21c, 0xa13, 0xa75, 0x27a, 0x264, 0xa6b, 0x258, 0xa57, 0xa49, 0x246,
29
+ 0x3c0, 0xbcf, 0xbd1, 0x3de, 0xbed, 0x3e2, 0x3fc, 0xbf3, 0xb95, 0x39a, 0x384, 0xb8b, 0x3b8, 0xbb7, 0xba9, 0x3a6,
30
+ 0xb65, 0x36a, 0x374, 0xb7b, 0x348, 0xb47, 0xb59, 0x356, 0x330, 0xb3f, 0xb21, 0x32e, 0xb1d, 0x312, 0x30c, 0xb03,
31
+ 0xd05, 0x50a, 0x514, 0xd1b, 0x528, 0xd27, 0xd39, 0x536, 0x550, 0xd5f, 0xd41, 0x54e, 0xd7d, 0x572, 0x56c, 0xd63,
32
+ 0x5a0, 0xdaf, 0xdb1, 0x5be, 0xd8d, 0x582, 0x59c, 0xd93, 0xdf5, 0x5fa, 0x5e4, 0xdeb, 0x5d8, 0xdd7, 0xdc9, 0x5c6,
33
+ 0x440, 0xc4f, 0xc51, 0x45e, 0xc6d, 0x462, 0x47c, 0xc73, 0xc15, 0x41a, 0x404, 0xc0b, 0x438, 0xc37, 0xc29, 0x426,
34
+ 0xce5, 0x4ea, 0x4f4, 0xcfb, 0x4c8, 0xcc7, 0xcd9, 0x4d6, 0x4b0, 0xcbf, 0xca1, 0x4ae, 0xc9d, 0x492, 0x48c, 0xc83,
35
+ 0x780, 0xf8f, 0xf91, 0x79e, 0xfad, 0x7a2, 0x7bc, 0xfb3, 0xfd5, 0x7da, 0x7c4, 0xfcb, 0x7f8, 0xff7, 0xfe9, 0x7e6,
36
+ 0xf25, 0x72a, 0x734, 0xf3b, 0x708, 0xf07, 0xf19, 0x716, 0x770, 0xf7f, 0xf61, 0x76e, 0xf5d, 0x752, 0x74c, 0xf43,
37
+ 0xec5, 0x6ca, 0x6d4, 0xedb, 0x6e8, 0xee7, 0xef9, 0x6f6, 0x690, 0xe9f, 0xe81, 0x68e, 0xebd, 0x6b2, 0x6ac, 0xea3,
38
+ 0x660, 0xe6f, 0xe71, 0x67e, 0xe4d, 0x642, 0x65c, 0xe53, 0xe35, 0x63a, 0x624, 0xe2b, 0x618, 0xe17, 0xe09, 0x606
39
+ };
40
+
41
+ crc12_t crc_reflect(crc12_t data, size_t data_len)
42
+ {
43
+ unsigned int i;
44
+ crc12_t ret = data & 0x01;
45
+
46
+ for (i = 1; i < data_len; i++)
47
+ {
48
+ data >>= 1;
49
+ ret = (ret << 1) | (data & 0x01);
50
+ }
51
+
52
+ return ret;
53
+ }
54
+
55
+ crc12_t crc12_3gpp_update(crc12_t crc, const void *data, size_t data_len)
56
+ {
57
+ const unsigned char *d = (const unsigned char *)data;
58
+ unsigned int tbl_idx;
59
+
60
+ while (data_len--)
61
+ {
62
+ tbl_idx = ((crc >> 4) ^ *d) & 0xff;
63
+ crc = (crc12_table[tbl_idx] ^ (crc << 8)) & 0xfff;
64
+ d++;
65
+ }
66
+
67
+ return crc & 0xfff;
68
+ }
@@ -0,0 +1,11 @@
1
+ #ifndef _CRC12_3GPP_H_
2
+ #define _CRC12_3GPP_H_
3
+
4
+ #include <stdint.h>
5
+ #include <stddef.h>
6
+
7
+ typedef uint16_t crc12_t;
8
+
9
+ crc12_t crc12_3gpp_update(crc12_t crc, const void *data, size_t data_len);
10
+
11
+ #endif
@@ -0,0 +1,32 @@
1
+ #include "ruby.h"
2
+ #include "extconf.h"
3
+
4
+ #include "crc12_3gpp.h"
5
+
6
+ VALUE Digest_CRC12_3GPP_update(VALUE self, VALUE data)
7
+ {
8
+ VALUE crc_ivar_name = rb_intern("@crc");
9
+ VALUE crc_ivar = rb_ivar_get(self, crc_ivar_name);
10
+ crc12_t crc = NUM2UINT(crc_ivar);
11
+
12
+ const char *data_ptr = StringValuePtr(data);
13
+ size_t length = RSTRING_LEN(data);
14
+
15
+ crc = crc12_3gpp_update(crc,data_ptr,length);
16
+
17
+ rb_ivar_set(self, crc_ivar_name, UINT2NUM(crc));
18
+ return self;
19
+ }
20
+
21
+ void Init_crc12_3gpp_ext()
22
+ {
23
+ VALUE mDigest = rb_const_get(rb_cObject, rb_intern("Digest"));
24
+ VALUE cCRC12_3GPP = rb_const_get(mDigest, rb_intern("CRC12_3GPP"));
25
+
26
+ #ifdef HAVE_RB_EXT_RACTOR_SAFE
27
+ rb_ext_ractor_safe(true);
28
+ #endif
29
+
30
+ rb_undef_method(cCRC12_3GPP, "update");
31
+ rb_define_method(cCRC12_3GPP, "update", Digest_CRC12_3GPP_update, 1);
32
+ }
@@ -0,0 +1,7 @@
1
+ require 'mkmf'
2
+
3
+ have_header("stdint.h")
4
+ have_header('stddef.h')
5
+
6
+ create_header
7
+ create_makefile "digest/crc12_3gpp/crc12_3gpp_ext"
@@ -0,0 +1,54 @@
1
+ /**
2
+ * \file
3
+ * Functions and types for CRC checks.
4
+ *
5
+ * Generated on Sat Feb 29 02:30:57 2020
6
+ * by pycrc v0.9.2, https://pycrc.org
7
+ * using the configuration:
8
+ * - Width = 15
9
+ * - Poly = 0x4599
10
+ * - XorIn = 0x0000
11
+ * - ReflectIn = False
12
+ * - XorOut = 0x0000
13
+ * - ReflectOut = False
14
+ * - Algorithm = table-driven
15
+ */
16
+
17
+ #include "crc15.h"
18
+
19
+ /**
20
+ * Static table used for the table_driven implementation.
21
+ */
22
+ static const crc15_t crc15_table[256] = {
23
+ 0x0000, 0x4599, 0x4eab, 0x0b32, 0x58cf, 0x1d56, 0x1664, 0x53fd, 0x7407, 0x319e, 0x3aac, 0x7f35, 0x2cc8, 0x6951, 0x6263, 0x27fa,
24
+ 0x2d97, 0x680e, 0x633c, 0x26a5, 0x7558, 0x30c1, 0x3bf3, 0x7e6a, 0x5990, 0x1c09, 0x173b, 0x52a2, 0x015f, 0x44c6, 0x4ff4, 0x0a6d,
25
+ 0x5b2e, 0x1eb7, 0x1585, 0x501c, 0x03e1, 0x4678, 0x4d4a, 0x08d3, 0x2f29, 0x6ab0, 0x6182, 0x241b, 0x77e6, 0x327f, 0x394d, 0x7cd4,
26
+ 0x76b9, 0x3320, 0x3812, 0x7d8b, 0x2e76, 0x6bef, 0x60dd, 0x2544, 0x02be, 0x4727, 0x4c15, 0x098c, 0x5a71, 0x1fe8, 0x14da, 0x5143,
27
+ 0x73c5, 0x365c, 0x3d6e, 0x78f7, 0x2b0a, 0x6e93, 0x65a1, 0x2038, 0x07c2, 0x425b, 0x4969, 0x0cf0, 0x5f0d, 0x1a94, 0x11a6, 0x543f,
28
+ 0x5e52, 0x1bcb, 0x10f9, 0x5560, 0x069d, 0x4304, 0x4836, 0x0daf, 0x2a55, 0x6fcc, 0x64fe, 0x2167, 0x729a, 0x3703, 0x3c31, 0x79a8,
29
+ 0x28eb, 0x6d72, 0x6640, 0x23d9, 0x7024, 0x35bd, 0x3e8f, 0x7b16, 0x5cec, 0x1975, 0x1247, 0x57de, 0x0423, 0x41ba, 0x4a88, 0x0f11,
30
+ 0x057c, 0x40e5, 0x4bd7, 0x0e4e, 0x5db3, 0x182a, 0x1318, 0x5681, 0x717b, 0x34e2, 0x3fd0, 0x7a49, 0x29b4, 0x6c2d, 0x671f, 0x2286,
31
+ 0x2213, 0x678a, 0x6cb8, 0x2921, 0x7adc, 0x3f45, 0x3477, 0x71ee, 0x5614, 0x138d, 0x18bf, 0x5d26, 0x0edb, 0x4b42, 0x4070, 0x05e9,
32
+ 0x0f84, 0x4a1d, 0x412f, 0x04b6, 0x574b, 0x12d2, 0x19e0, 0x5c79, 0x7b83, 0x3e1a, 0x3528, 0x70b1, 0x234c, 0x66d5, 0x6de7, 0x287e,
33
+ 0x793d, 0x3ca4, 0x3796, 0x720f, 0x21f2, 0x646b, 0x6f59, 0x2ac0, 0x0d3a, 0x48a3, 0x4391, 0x0608, 0x55f5, 0x106c, 0x1b5e, 0x5ec7,
34
+ 0x54aa, 0x1133, 0x1a01, 0x5f98, 0x0c65, 0x49fc, 0x42ce, 0x0757, 0x20ad, 0x6534, 0x6e06, 0x2b9f, 0x7862, 0x3dfb, 0x36c9, 0x7350,
35
+ 0x51d6, 0x144f, 0x1f7d, 0x5ae4, 0x0919, 0x4c80, 0x47b2, 0x022b, 0x25d1, 0x6048, 0x6b7a, 0x2ee3, 0x7d1e, 0x3887, 0x33b5, 0x762c,
36
+ 0x7c41, 0x39d8, 0x32ea, 0x7773, 0x248e, 0x6117, 0x6a25, 0x2fbc, 0x0846, 0x4ddf, 0x46ed, 0x0374, 0x5089, 0x1510, 0x1e22, 0x5bbb,
37
+ 0x0af8, 0x4f61, 0x4453, 0x01ca, 0x5237, 0x17ae, 0x1c9c, 0x5905, 0x7eff, 0x3b66, 0x3054, 0x75cd, 0x2630, 0x63a9, 0x689b, 0x2d02,
38
+ 0x276f, 0x62f6, 0x69c4, 0x2c5d, 0x7fa0, 0x3a39, 0x310b, 0x7492, 0x5368, 0x16f1, 0x1dc3, 0x585a, 0x0ba7, 0x4e3e, 0x450c, 0x0095
39
+ };
40
+
41
+ crc15_t crc15_update(crc15_t crc, const void *data, size_t data_len)
42
+ {
43
+ const unsigned char *d = (const unsigned char *)data;
44
+ unsigned int tbl_idx;
45
+
46
+ while (data_len--)
47
+ {
48
+ tbl_idx = ((crc >> 7) ^ *d) & 0xff;
49
+ crc = (crc15_table[tbl_idx] ^ (crc << 8)) & 0x7fff;
50
+ d++;
51
+ }
52
+
53
+ return crc & 0x7fff;
54
+ }
@@ -0,0 +1,11 @@
1
+ #ifndef _CRC15_H_
2
+ #define _CRC15_H_
3
+
4
+ #include <stdint.h>
5
+ #include <stddef.h>
6
+
7
+ typedef uint16_t crc15_t;
8
+
9
+ crc15_t crc15_update(crc15_t crc, const void *data, size_t data_len);
10
+
11
+ #endif
@@ -0,0 +1,33 @@
1
+ #include <ruby.h>
2
+ #include "../compat/ruby.h"
3
+
4
+ #include "extconf.h"
5
+ #include "crc15.h"
6
+
7
+ VALUE Digest_CRC15_update(VALUE self, VALUE data)
8
+ {
9
+ VALUE crc_ivar_name = rb_intern("@crc");
10
+ VALUE crc_ivar = rb_ivar_get(self, crc_ivar_name);
11
+ crc15_t crc = NUM2USHORT(crc_ivar);
12
+
13
+ const char *data_ptr = StringValuePtr(data);
14
+ size_t length = RSTRING_LEN(data);
15
+
16
+ crc = crc15_update(crc,data_ptr,length);
17
+
18
+ rb_ivar_set(self, crc_ivar_name, USHORT2NUM(crc));
19
+ return self;
20
+ }
21
+
22
+ void Init_crc15_ext()
23
+ {
24
+ VALUE mDigest = rb_const_get(rb_cObject, rb_intern("Digest"));
25
+ VALUE cCRC15 = rb_const_get(mDigest, rb_intern("CRC15"));
26
+
27
+ #ifdef HAVE_RB_EXT_RACTOR_SAFE
28
+ rb_ext_ractor_safe(true);
29
+ #endif
30
+
31
+ rb_undef_method(cCRC15, "update");
32
+ rb_define_method(cCRC15, "update", Digest_CRC15_update, 1);
33
+ }
@@ -0,0 +1,7 @@
1
+ require 'mkmf'
2
+
3
+ have_header("stdint.h")
4
+ have_header('stddef.h')
5
+
6
+ create_header
7
+ create_makefile "digest/crc15/crc15_ext"
@@ -0,0 +1,70 @@
1
+ /**
2
+ * \file
3
+ * Functions and types for CRC checks.
4
+ *
5
+ * Generated on Sat Feb 29 02:01:54 2020
6
+ * by pycrc v0.9.2, https://pycrc.org
7
+ * using the configuration:
8
+ * - Width = 16
9
+ * - Poly = 0x8005
10
+ * - XorIn = 0x0000
11
+ * - ReflectIn = True
12
+ * - XorOut = 0x0000
13
+ * - ReflectOut = True
14
+ * - Algorithm = table-driven
15
+ */
16
+
17
+ #include "crc16.h"
18
+
19
+ /**
20
+ * Static table used for the table_driven implementation.
21
+ */
22
+ static const crc16_t crc16_table[256] = {
23
+ 0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241,
24
+ 0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440,
25
+ 0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40,
26
+ 0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841,
27
+ 0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40,
28
+ 0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41,
29
+ 0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641,
30
+ 0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040,
31
+ 0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240,
32
+ 0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441,
33
+ 0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41,
34
+ 0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840,
35
+ 0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41,
36
+ 0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40,
37
+ 0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640,
38
+ 0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041,
39
+ 0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240,
40
+ 0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441,
41
+ 0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41,
42
+ 0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840,
43
+ 0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41,
44
+ 0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40,
45
+ 0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640,
46
+ 0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041,
47
+ 0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241,
48
+ 0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440,
49
+ 0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40,
50
+ 0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841,
51
+ 0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40,
52
+ 0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41,
53
+ 0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641,
54
+ 0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040
55
+ };
56
+
57
+ crc16_t crc16_update(crc16_t crc, const void *data, size_t data_len)
58
+ {
59
+ const unsigned char *d = (const unsigned char *)data;
60
+ unsigned int tbl_idx;
61
+
62
+ while (data_len--)
63
+ {
64
+ tbl_idx = (crc ^ *d) & 0xff;
65
+ crc = (crc16_table[tbl_idx] ^ (crc >> 8)) & 0xffff;
66
+ d++;
67
+ }
68
+
69
+ return crc & 0xffff;
70
+ }
@@ -0,0 +1,11 @@
1
+ #ifndef _CRC16_H_
2
+ #define _CRC16_H_
3
+
4
+ #include <stdint.h>
5
+ #include <stddef.h>
6
+
7
+ typedef uint16_t crc16_t;
8
+
9
+ crc16_t crc16_update(crc16_t crc, const void *data, size_t data_len);
10
+
11
+ #endif
@@ -0,0 +1,33 @@
1
+ #include <ruby.h>
2
+ #include "../compat/ruby.h"
3
+
4
+ #include "extconf.h"
5
+ #include "crc16.h"
6
+
7
+ VALUE Digest_CRC16_update(VALUE self, VALUE data)
8
+ {
9
+ VALUE crc_ivar_name = rb_intern("@crc");
10
+ VALUE crc_ivar = rb_ivar_get(self, crc_ivar_name);
11
+ crc16_t crc = NUM2USHORT(crc_ivar);
12
+
13
+ const char *data_ptr = StringValuePtr(data);
14
+ size_t length = RSTRING_LEN(data);
15
+
16
+ crc = crc16_update(crc,data_ptr,length);
17
+
18
+ rb_ivar_set(self, crc_ivar_name, USHORT2NUM(crc));
19
+ return self;
20
+ }
21
+
22
+ void Init_crc16_ext()
23
+ {
24
+ VALUE mDigest = rb_const_get(rb_cObject, rb_intern("Digest"));
25
+ VALUE cCRC16 = rb_const_get(mDigest, rb_intern("CRC16"));
26
+
27
+ #ifdef HAVE_RB_EXT_RACTOR_SAFE
28
+ rb_ext_ractor_safe(true);
29
+ #endif
30
+
31
+ rb_undef_method(cCRC16, "update");
32
+ rb_define_method(cCRC16, "update", Digest_CRC16_update, 1);
33
+ }
@@ -0,0 +1,7 @@
1
+ require 'mkmf'
2
+
3
+ have_header("stdint.h")
4
+ have_header('stddef.h')
5
+
6
+ create_header
7
+ create_makefile "digest/crc16/crc16_ext"
@@ -0,0 +1,70 @@
1
+ /**
2
+ * \file
3
+ * Functions and types for CRC checks.
4
+ *
5
+ * Generated on Sat Feb 29 02:04:06 2020
6
+ * by pycrc v0.9.2, https://pycrc.org
7
+ * using the configuration:
8
+ * - Width = 16
9
+ * - Poly = 0x1021
10
+ * - XorIn = 0x1d0f
11
+ * - ReflectIn = False
12
+ * - XorOut = 0x0000
13
+ * - ReflectOut = False
14
+ * - Algorithm = table-driven
15
+ */
16
+
17
+ #include "crc16_ccitt.h"
18
+
19
+ /**
20
+ * Static table used for the table_driven implementation.
21
+ */
22
+ static const crc16_t crc16_ccitt_table[256] = {
23
+ 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
24
+ 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
25
+ 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
26
+ 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
27
+ 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
28
+ 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
29
+ 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
30
+ 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
31
+ 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
32
+ 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
33
+ 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
34
+ 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
35
+ 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
36
+ 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
37
+ 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
38
+ 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
39
+ 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
40
+ 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
41
+ 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
42
+ 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
43
+ 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
44
+ 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
45
+ 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
46
+ 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
47
+ 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
48
+ 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
49
+ 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
50
+ 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
51
+ 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
52
+ 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
53
+ 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
54
+ 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
55
+ };
56
+
57
+ crc16_t crc16_ccitt_update(crc16_t crc, const void *data, size_t data_len)
58
+ {
59
+ const unsigned char *d = (const unsigned char *)data;
60
+ unsigned int tbl_idx;
61
+
62
+ while (data_len--)
63
+ {
64
+ tbl_idx = ((crc >> 8) ^ *d) & 0xff;
65
+ crc = (crc16_ccitt_table[tbl_idx] ^ (crc << 8)) & 0xffff;
66
+ d++;
67
+ }
68
+
69
+ return crc & 0xffff;
70
+ }
@@ -0,0 +1,8 @@
1
+ #ifndef _CRC16_CCITT_H_
2
+ #define _CRC16_CCITT_H_
3
+
4
+ #include "../crc16/crc16.h"
5
+
6
+ crc16_t crc16_ccitt_update(crc16_t crc, const void *data, size_t data_len);
7
+
8
+ #endif
@@ -0,0 +1,33 @@
1
+ #include <ruby.h>
2
+ #include "../compat/ruby.h"
3
+
4
+ #include "extconf.h"
5
+ #include "crc16_ccitt.h"
6
+
7
+ VALUE Digest_CRC16CCITT_update(VALUE self, VALUE data)
8
+ {
9
+ VALUE crc_ivar_name = rb_intern("@crc");
10
+ VALUE crc_ivar = rb_ivar_get(self, crc_ivar_name);
11
+ crc16_t crc = NUM2USHORT(crc_ivar);
12
+
13
+ const char *data_ptr = StringValuePtr(data);
14
+ size_t length = RSTRING_LEN(data);
15
+
16
+ crc = crc16_ccitt_update(crc,data_ptr,length);
17
+
18
+ rb_ivar_set(self, crc_ivar_name, USHORT2NUM(crc));
19
+ return self;
20
+ }
21
+
22
+ void Init_crc16_ccitt_ext()
23
+ {
24
+ VALUE mDigest = rb_const_get(rb_cObject, rb_intern("Digest"));
25
+ VALUE cCRC16CCITT = rb_const_get(mDigest, rb_intern("CRC16CCITT"));
26
+
27
+ #ifdef HAVE_RB_EXT_RACTOR_SAFE
28
+ rb_ext_ractor_safe(true);
29
+ #endif
30
+
31
+ rb_undef_method(cCRC16CCITT, "update");
32
+ rb_define_method(cCRC16CCITT, "update", Digest_CRC16CCITT_update, 1);
33
+ }
@@ -0,0 +1,7 @@
1
+ require 'mkmf'
2
+
3
+ have_header("stdint.h")
4
+ have_header('stddef.h')
5
+
6
+ create_header
7
+ create_makefile "digest/crc16_ccitt/crc16_ccitt_ext"
@@ -0,0 +1,54 @@
1
+ #include "crc16_dnp.h"
2
+
3
+ /**
4
+ * Static table used for the table_driven implementation.
5
+ */
6
+ static const crc16_t crc16_dnp_table[256] = {
7
+ 0x0000, 0x365e, 0x6cbc, 0x5ae2, 0xd978, 0xef26, 0xb5c4, 0x839a,
8
+ 0xff89, 0xc9d7, 0x9335, 0xa56b, 0x26f1, 0x10af, 0x4a4d, 0x7c13,
9
+ 0xb26b, 0x8435, 0xded7, 0xe889, 0x6b13, 0x5d4d, 0x07af, 0x31f1,
10
+ 0x4de2, 0x7bbc, 0x215e, 0x1700, 0x949a, 0xa2c4, 0xf826, 0xce78,
11
+ 0x29af, 0x1ff1, 0x4513, 0x734d, 0xf0d7, 0xc689, 0x9c6b, 0xaa35,
12
+ 0xd626, 0xe078, 0xba9a, 0x8cc4, 0x0f5e, 0x3900, 0x63e2, 0x55bc,
13
+ 0x9bc4, 0xad9a, 0xf778, 0xc126, 0x42bc, 0x74e2, 0x2e00, 0x185e,
14
+ 0x644d, 0x5213, 0x08f1, 0x3eaf, 0xbd35, 0x8b6b, 0xd189, 0xe7d7,
15
+ 0x535e, 0x6500, 0x3fe2, 0x09bc, 0x8a26, 0xbc78, 0xe69a, 0xd0c4,
16
+ 0xacd7, 0x9a89, 0xc06b, 0xf635, 0x75af, 0x43f1, 0x1913, 0x2f4d,
17
+ 0xe135, 0xd76b, 0x8d89, 0xbbd7, 0x384d, 0x0e13, 0x54f1, 0x62af,
18
+ 0x1ebc, 0x28e2, 0x7200, 0x445e, 0xc7c4, 0xf19a, 0xab78, 0x9d26,
19
+ 0x7af1, 0x4caf, 0x164d, 0x2013, 0xa389, 0x95d7, 0xcf35, 0xf96b,
20
+ 0x8578, 0xb326, 0xe9c4, 0xdf9a, 0x5c00, 0x6a5e, 0x30bc, 0x06e2,
21
+ 0xc89a, 0xfec4, 0xa426, 0x9278, 0x11e2, 0x27bc, 0x7d5e, 0x4b00,
22
+ 0x3713, 0x014d, 0x5baf, 0x6df1, 0xee6b, 0xd835, 0x82d7, 0xb489,
23
+ 0xa6bc, 0x90e2, 0xca00, 0xfc5e, 0x7fc4, 0x499a, 0x1378, 0x2526,
24
+ 0x5935, 0x6f6b, 0x3589, 0x03d7, 0x804d, 0xb613, 0xecf1, 0xdaaf,
25
+ 0x14d7, 0x2289, 0x786b, 0x4e35, 0xcdaf, 0xfbf1, 0xa113, 0x974d,
26
+ 0xeb5e, 0xdd00, 0x87e2, 0xb1bc, 0x3226, 0x0478, 0x5e9a, 0x68c4,
27
+ 0x8f13, 0xb94d, 0xe3af, 0xd5f1, 0x566b, 0x6035, 0x3ad7, 0x0c89,
28
+ 0x709a, 0x46c4, 0x1c26, 0x2a78, 0xa9e2, 0x9fbc, 0xc55e, 0xf300,
29
+ 0x3d78, 0x0b26, 0x51c4, 0x679a, 0xe400, 0xd25e, 0x88bc, 0xbee2,
30
+ 0xc2f1, 0xf4af, 0xae4d, 0x9813, 0x1b89, 0x2dd7, 0x7735, 0x416b,
31
+ 0xf5e2, 0xc3bc, 0x995e, 0xaf00, 0x2c9a, 0x1ac4, 0x4026, 0x7678,
32
+ 0x0a6b, 0x3c35, 0x66d7, 0x5089, 0xd313, 0xe54d, 0xbfaf, 0x89f1,
33
+ 0x4789, 0x71d7, 0x2b35, 0x1d6b, 0x9ef1, 0xa8af, 0xf24d, 0xc413,
34
+ 0xb800, 0x8e5e, 0xd4bc, 0xe2e2, 0x6178, 0x5726, 0x0dc4, 0x3b9a,
35
+ 0xdc4d, 0xea13, 0xb0f1, 0x86af, 0x0535, 0x336b, 0x6989, 0x5fd7,
36
+ 0x23c4, 0x159a, 0x4f78, 0x7926, 0xfabc, 0xcce2, 0x9600, 0xa05e,
37
+ 0x6e26, 0x5878, 0x029a, 0x34c4, 0xb75e, 0x8100, 0xdbe2, 0xedbc,
38
+ 0x91af, 0xa7f1, 0xfd13, 0xcb4d, 0x48d7, 0x7e89, 0x246b, 0x1235
39
+ };
40
+
41
+ crc16_t crc16_dnp_update(crc16_t crc, const void *data, size_t data_len)
42
+ {
43
+ const unsigned char *d = (const unsigned char *)data;
44
+ unsigned int tbl_idx;
45
+
46
+ while (data_len--)
47
+ {
48
+ tbl_idx = (crc ^ *d) & 0xff;
49
+ crc = (crc << 8) ^ crc16_dnp_table[tbl_idx];
50
+ d++;
51
+ }
52
+
53
+ return crc & 0xffff;
54
+ }
@@ -0,0 +1,8 @@
1
+ #ifndef _CRC16_GENIBUS_H_
2
+ #define _CRC16_GENIBUS_H_
3
+
4
+ #include "../crc16/crc16.h"
5
+
6
+ crc16_t crc16_dnp_update(crc16_t crc, const void *data, size_t data_len);
7
+
8
+ #endif
@@ -0,0 +1,33 @@
1
+ #include <ruby.h>
2
+ #include "../compat/ruby.h"
3
+
4
+ #include "extconf.h"
5
+ #include "crc16_dnp.h"
6
+
7
+ VALUE Digest_CRC16DNP_update(VALUE self, VALUE data)
8
+ {
9
+ VALUE crc_ivar_name = rb_intern("@crc");
10
+ VALUE crc_ivar = rb_ivar_get(self, crc_ivar_name);
11
+ crc16_t crc = NUM2USHORT(crc_ivar);
12
+
13
+ const char *data_ptr = StringValuePtr(data);
14
+ size_t length = RSTRING_LEN(data);
15
+
16
+ crc = crc16_dnp_update(crc,data_ptr,length);
17
+
18
+ rb_ivar_set(self, crc_ivar_name, USHORT2NUM(crc));
19
+ return self;
20
+ }
21
+
22
+ void Init_crc16_dnp_ext()
23
+ {
24
+ VALUE mDigest = rb_const_get(rb_cObject, rb_intern("Digest"));
25
+ VALUE cCRC16DNP = rb_const_get(mDigest, rb_intern("CRC16DNP"));
26
+
27
+ #ifdef HAVE_RB_EXT_RACTOR_SAFE
28
+ rb_ext_ractor_safe(true);
29
+ #endif
30
+
31
+ rb_undef_method(cCRC16DNP, "update");
32
+ rb_define_method(cCRC16DNP, "update", Digest_CRC16DNP_update, 1);
33
+ }
@@ -0,0 +1,7 @@
1
+ require 'mkmf'
2
+
3
+ have_header("stdint.h")
4
+ have_header('stddef.h')
5
+
6
+ create_header
7
+ create_makefile "digest/crc16_dnp/crc16_dnp_ext"
@@ -0,0 +1,70 @@
1
+ /**
2
+ * \file
3
+ * Functions and types for CRC checks.
4
+ *
5
+ * Generated on Sat Feb 29 02:31:25 2020
6
+ * by pycrc v0.9.2, https://pycrc.org
7
+ * using the configuration:
8
+ * - Width = 16
9
+ * - Poly = 0x1021
10
+ * - XorIn = 0xffff
11
+ * - ReflectIn = False
12
+ * - XorOut = 0xffff
13
+ * - ReflectOut = False
14
+ * - Algorithm = table-driven
15
+ */
16
+
17
+ #include "crc16_genibus.h"
18
+
19
+ /**
20
+ * Static table used for the table_driven implementation.
21
+ */
22
+ static const crc16_t crc16_genibus_table[256] = {
23
+ 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
24
+ 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
25
+ 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
26
+ 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
27
+ 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
28
+ 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
29
+ 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
30
+ 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
31
+ 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
32
+ 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
33
+ 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
34
+ 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
35
+ 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
36
+ 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
37
+ 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
38
+ 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
39
+ 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
40
+ 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
41
+ 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
42
+ 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
43
+ 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
44
+ 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
45
+ 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
46
+ 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
47
+ 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
48
+ 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
49
+ 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
50
+ 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
51
+ 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
52
+ 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
53
+ 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
54
+ 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
55
+ };
56
+
57
+ crc16_t crc16_genibus_update(crc16_t crc, const void *data, size_t data_len)
58
+ {
59
+ const unsigned char *d = (const unsigned char *)data;
60
+ unsigned int tbl_idx;
61
+
62
+ while (data_len--)
63
+ {
64
+ tbl_idx = ((crc >> 8) ^ *d) & 0xff;
65
+ crc = (crc16_genibus_table[tbl_idx] ^ (crc << 8)) & 0xffff;
66
+ d++;
67
+ }
68
+
69
+ return crc & 0xffff;
70
+ }
@@ -0,0 +1,8 @@
1
+ #ifndef _CRC16_GENIBUS_H_
2
+ #define _CRC16_GENIBUS_H_
3
+
4
+ #include "../crc16/crc16.h"
5
+
6
+ crc16_t crc16_genibus_update(crc16_t crc, const void *data, size_t data_len);
7
+
8
+ #endif