digest-crc 0.5.1 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -0
  3. data/.travis.yml +8 -0
  4. data/ChangeLog.md +116 -1
  5. data/README.md +110 -0
  6. data/Rakefile +25 -1
  7. data/benchmarks.rb +8 -4
  8. data/ext/digest/Rakefile +51 -0
  9. data/ext/digest/compat/ruby.h +11 -0
  10. data/ext/digest/crc12_3gpp/crc12_3gpp.c +68 -0
  11. data/ext/digest/crc12_3gpp/crc12_3gpp.h +11 -0
  12. data/ext/digest/crc12_3gpp/crc12_3gpp_ext.c +27 -0
  13. data/ext/digest/crc12_3gpp/extconf.rb +7 -0
  14. data/ext/digest/crc15/crc15.c +54 -0
  15. data/ext/digest/crc15/crc15.h +11 -0
  16. data/ext/digest/crc15/crc15_ext.c +28 -0
  17. data/ext/digest/crc15/extconf.rb +7 -0
  18. data/ext/digest/crc16/crc16.c +70 -0
  19. data/ext/digest/crc16/crc16.h +11 -0
  20. data/ext/digest/crc16/crc16_ext.c +28 -0
  21. data/ext/digest/crc16/extconf.rb +7 -0
  22. data/ext/digest/crc16_ccitt/crc16_ccitt.c +70 -0
  23. data/ext/digest/crc16_ccitt/crc16_ccitt.h +8 -0
  24. data/ext/digest/crc16_ccitt/crc16_ccitt_ext.c +28 -0
  25. data/ext/digest/crc16_ccitt/extconf.rb +7 -0
  26. data/ext/digest/crc16_dnp/crc16_dnp.c +54 -0
  27. data/ext/digest/crc16_dnp/crc16_dnp.h +8 -0
  28. data/ext/digest/crc16_dnp/crc16_dnp_ext.c +28 -0
  29. data/ext/digest/crc16_dnp/extconf.rb +7 -0
  30. data/ext/digest/crc16_genibus/crc16_genibus.c +70 -0
  31. data/ext/digest/crc16_genibus/crc16_genibus.h +8 -0
  32. data/ext/digest/crc16_genibus/crc16_genibus_ext.c +28 -0
  33. data/ext/digest/crc16_genibus/extconf.rb +7 -0
  34. data/ext/digest/crc16_kermit/crc16_kermit.c +70 -0
  35. data/ext/digest/crc16_kermit/crc16_kermit.h +8 -0
  36. data/ext/digest/crc16_kermit/crc16_kermit_ext.c +28 -0
  37. data/ext/digest/crc16_kermit/extconf.rb +7 -0
  38. data/ext/digest/crc16_modbus/crc16_modbus.c +70 -0
  39. data/ext/digest/crc16_modbus/crc16_modbus.h +8 -0
  40. data/ext/digest/crc16_modbus/crc16_modbus_ext.c +28 -0
  41. data/ext/digest/crc16_modbus/extconf.rb +7 -0
  42. data/ext/digest/crc16_usb/crc16_usb.c +70 -0
  43. data/ext/digest/crc16_usb/crc16_usb.h +8 -0
  44. data/ext/digest/crc16_usb/crc16_usb_ext.c +28 -0
  45. data/ext/digest/crc16_usb/extconf.rb +7 -0
  46. data/ext/digest/crc16_x_25/crc16_x_25.c +70 -0
  47. data/ext/digest/crc16_x_25/crc16_x_25.h +8 -0
  48. data/ext/digest/crc16_x_25/crc16_x_25_ext.c +28 -0
  49. data/ext/digest/crc16_x_25/extconf.rb +7 -0
  50. data/ext/digest/crc16_xmodem/crc16_xmodem.c +70 -0
  51. data/ext/digest/crc16_xmodem/crc16_xmodem.h +8 -0
  52. data/ext/digest/crc16_xmodem/crc16_xmodem_ext.c +28 -0
  53. data/ext/digest/crc16_xmodem/extconf.rb +7 -0
  54. data/ext/digest/crc16_zmodem/crc16_zmodem.c +70 -0
  55. data/ext/digest/crc16_zmodem/crc16_zmodem.h +8 -0
  56. data/ext/digest/crc16_zmodem/crc16_zmodem_ext.c +28 -0
  57. data/ext/digest/crc16_zmodem/extconf.rb +7 -0
  58. data/ext/digest/crc24/crc24.c +70 -0
  59. data/ext/digest/crc24/crc24.h +11 -0
  60. data/ext/digest/crc24/crc24_ext.c +27 -0
  61. data/ext/digest/crc24/extconf.rb +7 -0
  62. data/ext/digest/crc32/crc32.c +69 -0
  63. data/ext/digest/crc32/crc32.h +11 -0
  64. data/ext/digest/crc32/crc32_ext.c +27 -0
  65. data/ext/digest/crc32/extconf.rb +7 -0
  66. data/ext/digest/crc32_bzip2/crc32_bzip2.c +70 -0
  67. data/ext/digest/crc32_bzip2/crc32_bzip2.h +8 -0
  68. data/ext/digest/crc32_bzip2/crc32_bzip2_ext.c +27 -0
  69. data/ext/digest/crc32_bzip2/extconf.rb +7 -0
  70. data/ext/digest/crc32_jam/crc32_jam.c +70 -0
  71. data/ext/digest/crc32_jam/crc32_jam.h +8 -0
  72. data/ext/digest/crc32_jam/crc32_jam_ext.c +27 -0
  73. data/ext/digest/crc32_jam/extconf.rb +7 -0
  74. data/ext/digest/crc32_mpeg/crc32_mpeg.c +70 -0
  75. data/ext/digest/crc32_mpeg/crc32_mpeg.h +8 -0
  76. data/ext/digest/crc32_mpeg/crc32_mpeg_ext.c +27 -0
  77. data/ext/digest/crc32_mpeg/extconf.rb +7 -0
  78. data/ext/digest/crc32_posix/crc32_posix.c +70 -0
  79. data/ext/digest/crc32_posix/crc32_posix.h +8 -0
  80. data/ext/digest/crc32_posix/crc32_posix_ext.c +27 -0
  81. data/ext/digest/crc32_posix/extconf.rb +7 -0
  82. data/ext/digest/crc32_xfer/crc32_xfer.c +70 -0
  83. data/ext/digest/crc32_xfer/crc32_xfer.h +8 -0
  84. data/ext/digest/crc32_xfer/crc32_xfer_ext.c +27 -0
  85. data/ext/digest/crc32_xfer/extconf.rb +7 -0
  86. data/ext/digest/crc32c/crc32c.c +70 -0
  87. data/ext/digest/crc32c/crc32c.h +8 -0
  88. data/ext/digest/crc32c/crc32c_ext.c +27 -0
  89. data/ext/digest/crc32c/extconf.rb +7 -0
  90. data/ext/digest/crc5/crc5.c +54 -0
  91. data/ext/digest/crc5/crc5.h +11 -0
  92. data/ext/digest/crc5/crc5_ext.c +27 -0
  93. data/ext/digest/crc5/extconf.rb +7 -0
  94. data/ext/digest/crc64/crc64.c +102 -0
  95. data/ext/digest/crc64/crc64.h +11 -0
  96. data/ext/digest/crc64/crc64_ext.c +27 -0
  97. data/ext/digest/crc64/extconf.rb +7 -0
  98. data/ext/digest/crc64_jones/crc64_jones.c +102 -0
  99. data/ext/digest/crc64_jones/crc64_jones.h +8 -0
  100. data/ext/digest/crc64_jones/crc64_jones_ext.c +27 -0
  101. data/ext/digest/crc64_jones/extconf.rb +7 -0
  102. data/ext/digest/crc64_xz/crc64_xz.c +102 -0
  103. data/ext/digest/crc64_xz/crc64_xz.h +8 -0
  104. data/ext/digest/crc64_xz/crc64_xz_ext.c +27 -0
  105. data/ext/digest/crc64_xz/extconf.rb +7 -0
  106. data/ext/digest/crc8/crc8.c +54 -0
  107. data/ext/digest/crc8/crc8.h +11 -0
  108. data/ext/digest/crc8/crc8_ext.c +27 -0
  109. data/ext/digest/crc8/extconf.rb +7 -0
  110. data/ext/digest/crc8_1wire/crc8_1wire.c +54 -0
  111. data/ext/digest/crc8_1wire/crc8_1wire.h +8 -0
  112. data/ext/digest/crc8_1wire/crc8_1wire_ext.c +27 -0
  113. data/ext/digest/crc8_1wire/extconf.rb +7 -0
  114. data/gemspec.yml +7 -1
  115. data/lib/digest/crc15.rb +4 -0
  116. data/lib/digest/crc16.rb +4 -0
  117. data/lib/digest/crc16_ccitt.rb +4 -0
  118. data/lib/digest/crc16_dnp.rb +4 -0
  119. data/lib/digest/crc16_genibus.rb +4 -0
  120. data/lib/digest/crc16_kermit.rb +4 -0
  121. data/lib/digest/crc16_modbus.rb +4 -0
  122. data/lib/digest/crc16_qt.rb +3 -60
  123. data/lib/digest/crc16_usb.rb +4 -0
  124. data/lib/digest/crc16_x_25.rb +4 -0
  125. data/lib/digest/crc16_xmodem.rb +4 -0
  126. data/lib/digest/crc16_zmodem.rb +4 -0
  127. data/lib/digest/crc24.rb +4 -0
  128. data/lib/digest/crc32.rb +5 -1
  129. data/lib/digest/crc32_bzip2.rb +4 -0
  130. data/lib/digest/crc32_mpeg.rb +4 -0
  131. data/lib/digest/crc32_posix.rb +4 -0
  132. data/lib/digest/crc32_xfer.rb +4 -0
  133. data/lib/digest/crc32c.rb +4 -0
  134. data/lib/digest/crc5.rb +4 -0
  135. data/lib/digest/crc64.rb +4 -0
  136. data/lib/digest/crc64_jones.rb +4 -0
  137. data/lib/digest/crc64_xz.rb +4 -0
  138. data/lib/digest/crc8.rb +4 -0
  139. data/lib/digest/crc8_1wire.rb +4 -0
  140. data/spec/crc16_qt_spec.rb +5 -5
  141. metadata +125 -4
@@ -0,0 +1,8 @@
1
+ #ifndef _CRC16_USB_H_
2
+ #define _CRC16_USB_H_
3
+
4
+ #include "../crc16/crc16.h"
5
+
6
+ crc16_t crc16_usb_update(crc16_t crc, const void *data, size_t data_len);
7
+
8
+ #endif
@@ -0,0 +1,28 @@
1
+ #include <ruby.h>
2
+ #include "../compat/ruby.h"
3
+
4
+ #include "extconf.h"
5
+ #include "crc16_usb.h"
6
+
7
+ VALUE Digest_CRC16USB_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_usb_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_usb_ext()
23
+ {
24
+ VALUE mDigest = rb_const_get(rb_cObject, rb_intern("Digest"));
25
+ VALUE cCRC16USB = rb_const_get(mDigest, rb_intern("CRC16USB"));
26
+
27
+ rb_define_method(cCRC16USB, "update", Digest_CRC16USB_update, 1);
28
+ }
@@ -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 "crc16_usb_ext"
@@ -0,0 +1,70 @@
1
+ /**
2
+ * \file
3
+ * Functions and types for CRC checks.
4
+ *
5
+ * Generated on Sat Feb 29 02:32:07 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 = True
12
+ * - XorOut = 0xffff
13
+ * - ReflectOut = True
14
+ * - Algorithm = table-driven
15
+ */
16
+
17
+ #include "crc16_x_25.h"
18
+
19
+ /**
20
+ * Static table used for the table_driven implementation.
21
+ */
22
+ static const crc16_t crc_table[256] = {
23
+ 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
24
+ 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
25
+ 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
26
+ 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
27
+ 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
28
+ 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
29
+ 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
30
+ 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
31
+ 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
32
+ 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
33
+ 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
34
+ 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
35
+ 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
36
+ 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
37
+ 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
38
+ 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
39
+ 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
40
+ 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
41
+ 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
42
+ 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
43
+ 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
44
+ 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
45
+ 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
46
+ 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
47
+ 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
48
+ 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
49
+ 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
50
+ 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
51
+ 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
52
+ 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
53
+ 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
54
+ 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
55
+ };
56
+
57
+ crc16_t crc16_x_25_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 = (crc_table[tbl_idx] ^ (crc >> 8)) & 0xffff;
66
+ d++;
67
+ }
68
+
69
+ return crc & 0xffff;
70
+ }
@@ -0,0 +1,8 @@
1
+ #ifndef _CRC16_X_25_H_
2
+ #define _CRC16_X_25_H_
3
+
4
+ #include "../crc16/crc16.h"
5
+
6
+ crc16_t crc16_x_25_update(crc16_t crc, const void *data, size_t data_len);
7
+
8
+ #endif
@@ -0,0 +1,28 @@
1
+ #include <ruby.h>
2
+ #include "../compat/ruby.h"
3
+
4
+ #include "extconf.h"
5
+ #include "crc16_x_25.h"
6
+
7
+ VALUE Digest_CRC16X25_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_x_25_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_x_25_ext()
23
+ {
24
+ VALUE mDigest = rb_const_get(rb_cObject, rb_intern("Digest"));
25
+ VALUE cCRC16X25 = rb_const_get(mDigest, rb_intern("CRC16X25"));
26
+
27
+ rb_define_method(cCRC16X25, "update", Digest_CRC16X25_update, 1);
28
+ }
@@ -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 "crc16_x_25_ext"
@@ -0,0 +1,70 @@
1
+ /**
2
+ * \file
3
+ * Functions and types for CRC checks.
4
+ *
5
+ * Generated on Sat Feb 29 02:06:05 2020
6
+ * by pycrc v0.9.2, https://pycrc.org
7
+ * using the configuration:
8
+ * - Width = 16
9
+ * - Poly = 0x1021
10
+ * - XorIn = 0x0000
11
+ * - ReflectIn = False
12
+ * - XorOut = 0x0000
13
+ * - ReflectOut = False
14
+ * - Algorithm = table-driven
15
+ */
16
+
17
+ #include "crc16_xmodem.h"
18
+
19
+ /**
20
+ * Static table used for the table_driven implementation.
21
+ */
22
+ static const crc16_t crc16_xmodem_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_xmodem_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_xmodem_table[tbl_idx] ^ (crc << 8)) & 0xffff;
66
+ d++;
67
+ }
68
+
69
+ return crc & 0xffff;
70
+ }
@@ -0,0 +1,8 @@
1
+ #ifndef _CRC16_XMODEM_H_
2
+ #define _CRC16_XMODEM_H_
3
+
4
+ #include "../crc16/crc16.h"
5
+
6
+ crc16_t crc16_xmodem_update(crc16_t crc, const void *data, size_t data_len);
7
+
8
+ #endif
@@ -0,0 +1,28 @@
1
+ #include <ruby.h>
2
+ #include "../compat/ruby.h"
3
+
4
+ #include "extconf.h"
5
+ #include "crc16_xmodem.h"
6
+
7
+ VALUE Digest_CRC16XModem_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_xmodem_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_xmodem_ext()
23
+ {
24
+ VALUE mDigest = rb_const_get(rb_cObject, rb_intern("Digest"));
25
+ VALUE cCRC16XModem = rb_const_get(mDigest, rb_intern("CRC16XModem"));
26
+
27
+ rb_define_method(cCRC16XModem, "update", Digest_CRC16XModem_update, 1);
28
+ }
@@ -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 "crc16_xmodem_ext"
@@ -0,0 +1,70 @@
1
+ /**
2
+ * \file
3
+ * Functions and types for CRC checks.
4
+ *
5
+ * Generated on Sat Feb 29 02:06:11 2020
6
+ * by pycrc v0.9.2, https://pycrc.org
7
+ * using the configuration:
8
+ * - Width = 16
9
+ * - Poly = 0x1021
10
+ * - XorIn = 0x0000
11
+ * - ReflectIn = False
12
+ * - XorOut = 0x0000
13
+ * - ReflectOut = False
14
+ * - Algorithm = table-driven
15
+ */
16
+
17
+ #include "crc16_zmodem.h"
18
+
19
+ /**
20
+ * Static table used for the table_driven implementation.
21
+ */
22
+ static const crc16_t crc16_zmodem_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_zmodem_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_zmodem_table[tbl_idx] ^ (crc << 8)) & 0xffff;
66
+ d++;
67
+ }
68
+
69
+ return crc & 0xffff;
70
+ }
@@ -0,0 +1,8 @@
1
+ #ifndef _CRC16_ZMODEM_H_
2
+ #define _CRC16_ZMODEM_H_
3
+
4
+ #include "../crc16/crc16.h"
5
+
6
+ crc16_t crc16_zmodem_update(crc16_t crc, const void *data, size_t data_len);
7
+
8
+ #endif
@@ -0,0 +1,28 @@
1
+ #include <ruby.h>
2
+ #include "../compat/ruby.h"
3
+
4
+ #include "extconf.h"
5
+ #include "crc16_zmodem.h"
6
+
7
+ VALUE Digest_CRC16ZModem_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_zmodem_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_zmodem_ext()
23
+ {
24
+ VALUE mDigest = rb_const_get(rb_cObject, rb_intern("Digest"));
25
+ VALUE cCRC16ZModem = rb_const_get(mDigest, rb_intern("CRC16ZModem"));
26
+
27
+ rb_define_method(cCRC16ZModem, "update", Digest_CRC16ZModem_update, 1);
28
+ }
@@ -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 "crc16_zmodem_ext"
@@ -0,0 +1,70 @@
1
+ /**
2
+ * \file
3
+ * Functions and types for CRC checks.
4
+ *
5
+ * Generated on Sat Feb 29 02:02:04 2020
6
+ * by pycrc v0.9.2, https://pycrc.org
7
+ * using the configuration:
8
+ * - Width = 24
9
+ * - Poly = 0x864cfb
10
+ * - XorIn = 0xb704ce
11
+ * - ReflectIn = False
12
+ * - XorOut = 0x000000
13
+ * - ReflectOut = False
14
+ * - Algorithm = table-driven
15
+ */
16
+
17
+ #include "crc24.h"
18
+
19
+ /**
20
+ * Static table used for the table_driven implementation.
21
+ */
22
+ static const crc24_t crc24_table[256] = {
23
+ 0x000000, 0x864cfb, 0x8ad50d, 0x0c99f6, 0x93e6e1, 0x15aa1a, 0x1933ec, 0x9f7f17,
24
+ 0xa18139, 0x27cdc2, 0x2b5434, 0xad18cf, 0x3267d8, 0xb42b23, 0xb8b2d5, 0x3efe2e,
25
+ 0xc54e89, 0x430272, 0x4f9b84, 0xc9d77f, 0x56a868, 0xd0e493, 0xdc7d65, 0x5a319e,
26
+ 0x64cfb0, 0xe2834b, 0xee1abd, 0x685646, 0xf72951, 0x7165aa, 0x7dfc5c, 0xfbb0a7,
27
+ 0x0cd1e9, 0x8a9d12, 0x8604e4, 0x00481f, 0x9f3708, 0x197bf3, 0x15e205, 0x93aefe,
28
+ 0xad50d0, 0x2b1c2b, 0x2785dd, 0xa1c926, 0x3eb631, 0xb8faca, 0xb4633c, 0x322fc7,
29
+ 0xc99f60, 0x4fd39b, 0x434a6d, 0xc50696, 0x5a7981, 0xdc357a, 0xd0ac8c, 0x56e077,
30
+ 0x681e59, 0xee52a2, 0xe2cb54, 0x6487af, 0xfbf8b8, 0x7db443, 0x712db5, 0xf7614e,
31
+ 0x19a3d2, 0x9fef29, 0x9376df, 0x153a24, 0x8a4533, 0x0c09c8, 0x00903e, 0x86dcc5,
32
+ 0xb822eb, 0x3e6e10, 0x32f7e6, 0xb4bb1d, 0x2bc40a, 0xad88f1, 0xa11107, 0x275dfc,
33
+ 0xdced5b, 0x5aa1a0, 0x563856, 0xd074ad, 0x4f0bba, 0xc94741, 0xc5deb7, 0x43924c,
34
+ 0x7d6c62, 0xfb2099, 0xf7b96f, 0x71f594, 0xee8a83, 0x68c678, 0x645f8e, 0xe21375,
35
+ 0x15723b, 0x933ec0, 0x9fa736, 0x19ebcd, 0x8694da, 0x00d821, 0x0c41d7, 0x8a0d2c,
36
+ 0xb4f302, 0x32bff9, 0x3e260f, 0xb86af4, 0x2715e3, 0xa15918, 0xadc0ee, 0x2b8c15,
37
+ 0xd03cb2, 0x567049, 0x5ae9bf, 0xdca544, 0x43da53, 0xc596a8, 0xc90f5e, 0x4f43a5,
38
+ 0x71bd8b, 0xf7f170, 0xfb6886, 0x7d247d, 0xe25b6a, 0x641791, 0x688e67, 0xeec29c,
39
+ 0x3347a4, 0xb50b5f, 0xb992a9, 0x3fde52, 0xa0a145, 0x26edbe, 0x2a7448, 0xac38b3,
40
+ 0x92c69d, 0x148a66, 0x181390, 0x9e5f6b, 0x01207c, 0x876c87, 0x8bf571, 0x0db98a,
41
+ 0xf6092d, 0x7045d6, 0x7cdc20, 0xfa90db, 0x65efcc, 0xe3a337, 0xef3ac1, 0x69763a,
42
+ 0x578814, 0xd1c4ef, 0xdd5d19, 0x5b11e2, 0xc46ef5, 0x42220e, 0x4ebbf8, 0xc8f703,
43
+ 0x3f964d, 0xb9dab6, 0xb54340, 0x330fbb, 0xac70ac, 0x2a3c57, 0x26a5a1, 0xa0e95a,
44
+ 0x9e1774, 0x185b8f, 0x14c279, 0x928e82, 0x0df195, 0x8bbd6e, 0x872498, 0x016863,
45
+ 0xfad8c4, 0x7c943f, 0x700dc9, 0xf64132, 0x693e25, 0xef72de, 0xe3eb28, 0x65a7d3,
46
+ 0x5b59fd, 0xdd1506, 0xd18cf0, 0x57c00b, 0xc8bf1c, 0x4ef3e7, 0x426a11, 0xc426ea,
47
+ 0x2ae476, 0xaca88d, 0xa0317b, 0x267d80, 0xb90297, 0x3f4e6c, 0x33d79a, 0xb59b61,
48
+ 0x8b654f, 0x0d29b4, 0x01b042, 0x87fcb9, 0x1883ae, 0x9ecf55, 0x9256a3, 0x141a58,
49
+ 0xefaaff, 0x69e604, 0x657ff2, 0xe33309, 0x7c4c1e, 0xfa00e5, 0xf69913, 0x70d5e8,
50
+ 0x4e2bc6, 0xc8673d, 0xc4fecb, 0x42b230, 0xddcd27, 0x5b81dc, 0x57182a, 0xd154d1,
51
+ 0x26359f, 0xa07964, 0xace092, 0x2aac69, 0xb5d37e, 0x339f85, 0x3f0673, 0xb94a88,
52
+ 0x87b4a6, 0x01f85d, 0x0d61ab, 0x8b2d50, 0x145247, 0x921ebc, 0x9e874a, 0x18cbb1,
53
+ 0xe37b16, 0x6537ed, 0x69ae1b, 0xefe2e0, 0x709df7, 0xf6d10c, 0xfa48fa, 0x7c0401,
54
+ 0x42fa2f, 0xc4b6d4, 0xc82f22, 0x4e63d9, 0xd11cce, 0x575035, 0x5bc9c3, 0xdd8538
55
+ };
56
+
57
+ crc24_t crc24_update(crc24_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 >> 16) ^ *d) & 0xff;
65
+ crc = (crc24_table[tbl_idx] ^ (crc << 8)) & 0xffffff;
66
+ d++;
67
+ }
68
+
69
+ return crc & 0xffffff;
70
+ }