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.
- checksums.yaml +7 -0
- data/.github/workflows/cibuildgem.yaml +89 -0
- data/.github/workflows/integration.yml +26 -0
- data/.github/workflows/ruby.yml +33 -0
- data/.gitignore +11 -0
- data/.rspec +1 -0
- data/.yardopts +1 -0
- data/ChangeLog.md +212 -0
- data/Gemfile +16 -0
- data/LICENSE.txt +20 -0
- data/README.md +401 -0
- data/Rakefile +57 -0
- data/benchmarks.rb +59 -0
- data/digest-crc.gemspec +65 -0
- data/ext/digest/Rakefile +46 -0
- data/ext/digest/compat/ruby.h +11 -0
- data/ext/digest/crc12_3gpp/crc12_3gpp.c +68 -0
- data/ext/digest/crc12_3gpp/crc12_3gpp.h +11 -0
- data/ext/digest/crc12_3gpp/crc12_3gpp_ext.c +32 -0
- data/ext/digest/crc12_3gpp/extconf.rb +7 -0
- data/ext/digest/crc15/crc15.c +54 -0
- data/ext/digest/crc15/crc15.h +11 -0
- data/ext/digest/crc15/crc15_ext.c +33 -0
- data/ext/digest/crc15/extconf.rb +7 -0
- data/ext/digest/crc16/crc16.c +70 -0
- data/ext/digest/crc16/crc16.h +11 -0
- data/ext/digest/crc16/crc16_ext.c +33 -0
- data/ext/digest/crc16/extconf.rb +7 -0
- data/ext/digest/crc16_ccitt/crc16_ccitt.c +70 -0
- data/ext/digest/crc16_ccitt/crc16_ccitt.h +8 -0
- data/ext/digest/crc16_ccitt/crc16_ccitt_ext.c +33 -0
- data/ext/digest/crc16_ccitt/extconf.rb +7 -0
- data/ext/digest/crc16_dnp/crc16_dnp.c +54 -0
- data/ext/digest/crc16_dnp/crc16_dnp.h +8 -0
- data/ext/digest/crc16_dnp/crc16_dnp_ext.c +33 -0
- data/ext/digest/crc16_dnp/extconf.rb +7 -0
- data/ext/digest/crc16_genibus/crc16_genibus.c +70 -0
- data/ext/digest/crc16_genibus/crc16_genibus.h +8 -0
- data/ext/digest/crc16_genibus/crc16_genibus_ext.c +33 -0
- data/ext/digest/crc16_genibus/extconf.rb +7 -0
- data/ext/digest/crc16_kermit/crc16_kermit.c +70 -0
- data/ext/digest/crc16_kermit/crc16_kermit.h +8 -0
- data/ext/digest/crc16_kermit/crc16_kermit_ext.c +33 -0
- data/ext/digest/crc16_kermit/extconf.rb +7 -0
- data/ext/digest/crc16_modbus/crc16_modbus.c +70 -0
- data/ext/digest/crc16_modbus/crc16_modbus.h +8 -0
- data/ext/digest/crc16_modbus/crc16_modbus_ext.c +32 -0
- data/ext/digest/crc16_modbus/extconf.rb +7 -0
- data/ext/digest/crc16_usb/crc16_usb.c +70 -0
- data/ext/digest/crc16_usb/crc16_usb.h +8 -0
- data/ext/digest/crc16_usb/crc16_usb_ext.c +32 -0
- data/ext/digest/crc16_usb/extconf.rb +7 -0
- data/ext/digest/crc16_x_25/crc16_x_25.c +70 -0
- data/ext/digest/crc16_x_25/crc16_x_25.h +8 -0
- data/ext/digest/crc16_x_25/crc16_x_25_ext.c +32 -0
- data/ext/digest/crc16_x_25/extconf.rb +7 -0
- data/ext/digest/crc16_xmodem/crc16_xmodem.c +70 -0
- data/ext/digest/crc16_xmodem/crc16_xmodem.h +8 -0
- data/ext/digest/crc16_xmodem/crc16_xmodem_ext.c +33 -0
- data/ext/digest/crc16_xmodem/extconf.rb +7 -0
- data/ext/digest/crc16_zmodem/crc16_zmodem.c +70 -0
- data/ext/digest/crc16_zmodem/crc16_zmodem.h +8 -0
- data/ext/digest/crc16_zmodem/crc16_zmodem_ext.c +33 -0
- data/ext/digest/crc16_zmodem/extconf.rb +7 -0
- data/ext/digest/crc24/crc24.c +70 -0
- data/ext/digest/crc24/crc24.h +11 -0
- data/ext/digest/crc24/crc24_ext.c +32 -0
- data/ext/digest/crc24/extconf.rb +7 -0
- data/ext/digest/crc32/crc32.c +69 -0
- data/ext/digest/crc32/crc32.h +11 -0
- data/ext/digest/crc32/crc32_ext.c +32 -0
- data/ext/digest/crc32/extconf.rb +7 -0
- data/ext/digest/crc32_bzip2/crc32_bzip2.c +70 -0
- data/ext/digest/crc32_bzip2/crc32_bzip2.h +8 -0
- data/ext/digest/crc32_bzip2/crc32_bzip2_ext.c +32 -0
- data/ext/digest/crc32_bzip2/extconf.rb +7 -0
- data/ext/digest/crc32_jam/crc32_jam.c +70 -0
- data/ext/digest/crc32_jam/crc32_jam.h +8 -0
- data/ext/digest/crc32_jam/crc32_jam_ext.c +31 -0
- data/ext/digest/crc32_jam/extconf.rb +7 -0
- data/ext/digest/crc32_mpeg/crc32_mpeg.c +70 -0
- data/ext/digest/crc32_mpeg/crc32_mpeg.h +8 -0
- data/ext/digest/crc32_mpeg/crc32_mpeg_ext.c +32 -0
- data/ext/digest/crc32_mpeg/extconf.rb +7 -0
- data/ext/digest/crc32_posix/crc32_posix.c +70 -0
- data/ext/digest/crc32_posix/crc32_posix.h +8 -0
- data/ext/digest/crc32_posix/crc32_posix_ext.c +32 -0
- data/ext/digest/crc32_posix/extconf.rb +7 -0
- data/ext/digest/crc32_xfer/crc32_xfer.c +70 -0
- data/ext/digest/crc32_xfer/crc32_xfer.h +8 -0
- data/ext/digest/crc32_xfer/crc32_xfer_ext.c +32 -0
- data/ext/digest/crc32_xfer/extconf.rb +7 -0
- data/ext/digest/crc32c/crc32c.c +70 -0
- data/ext/digest/crc32c/crc32c.h +8 -0
- data/ext/digest/crc32c/crc32c_ext.c +31 -0
- data/ext/digest/crc32c/extconf.rb +7 -0
- data/ext/digest/crc5/crc5.c +54 -0
- data/ext/digest/crc5/crc5.h +11 -0
- data/ext/digest/crc5/crc5_ext.c +32 -0
- data/ext/digest/crc5/extconf.rb +7 -0
- data/ext/digest/crc64/crc64.c +102 -0
- data/ext/digest/crc64/crc64.h +11 -0
- data/ext/digest/crc64/crc64_ext.c +32 -0
- data/ext/digest/crc64/extconf.rb +7 -0
- data/ext/digest/crc64_jones/crc64_jones.c +102 -0
- data/ext/digest/crc64_jones/crc64_jones.h +8 -0
- data/ext/digest/crc64_jones/crc64_jones_ext.c +31 -0
- data/ext/digest/crc64_jones/extconf.rb +7 -0
- data/ext/digest/crc64_nvme/crc64_nvme.c +102 -0
- data/ext/digest/crc64_nvme/crc64_nvme.h +8 -0
- data/ext/digest/crc64_nvme/crc64_nvme_ext.c +31 -0
- data/ext/digest/crc64_nvme/extconf.rb +7 -0
- data/ext/digest/crc64_xz/crc64_xz.c +102 -0
- data/ext/digest/crc64_xz/crc64_xz.h +8 -0
- data/ext/digest/crc64_xz/crc64_xz_ext.c +31 -0
- data/ext/digest/crc64_xz/extconf.rb +7 -0
- data/ext/digest/crc8/crc8.c +54 -0
- data/ext/digest/crc8/crc8.h +11 -0
- data/ext/digest/crc8/crc8_ext.c +32 -0
- data/ext/digest/crc8/extconf.rb +7 -0
- data/ext/digest/crc8_1wire/crc8_1wire.c +54 -0
- data/ext/digest/crc8_1wire/crc8_1wire.h +8 -0
- data/ext/digest/crc8_1wire/crc8_1wire_ext.c +31 -0
- data/ext/digest/crc8_1wire/extconf.rb +7 -0
- data/gemspec.yml +25 -0
- data/lib/digest/crc.rb +211 -0
- data/lib/digest/crc1.rb +37 -0
- data/lib/digest/crc15.rb +45 -0
- data/lib/digest/crc16.rb +61 -0
- data/lib/digest/crc16_ccitt.rb +59 -0
- data/lib/digest/crc16_dnp.rb +62 -0
- data/lib/digest/crc16_genibus.rb +65 -0
- data/lib/digest/crc16_kermit.rb +59 -0
- data/lib/digest/crc16_modbus.rb +57 -0
- data/lib/digest/crc16_qt.rb +11 -0
- data/lib/digest/crc16_usb.rb +23 -0
- data/lib/digest/crc16_x_25.rb +63 -0
- data/lib/digest/crc16_xmodem.rb +57 -0
- data/lib/digest/crc16_zmodem.rb +57 -0
- data/lib/digest/crc24.rb +61 -0
- data/lib/digest/crc32.rb +95 -0
- data/lib/digest/crc32_bzip2.rb +57 -0
- data/lib/digest/crc32_jam.rb +16 -0
- data/lib/digest/crc32_mpeg.rb +94 -0
- data/lib/digest/crc32_posix.rb +58 -0
- data/lib/digest/crc32_xfer.rb +61 -0
- data/lib/digest/crc32c.rb +87 -0
- data/lib/digest/crc5.rb +58 -0
- data/lib/digest/crc64.rb +95 -0
- data/lib/digest/crc64_jones.rb +93 -0
- data/lib/digest/crc64_nvme.rb +95 -0
- data/lib/digest/crc64_xz.rb +95 -0
- data/lib/digest/crc8.rb +45 -0
- data/lib/digest/crc8_1wire.rb +42 -0
- metadata +265 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* \file
|
|
3
|
+
* Functions and types for CRC checks.
|
|
4
|
+
*
|
|
5
|
+
* Generated on Sat Feb 29 02:01:47 2020
|
|
6
|
+
* by pycrc v0.9.2, https://pycrc.org
|
|
7
|
+
* using the configuration:
|
|
8
|
+
* - Width = 8
|
|
9
|
+
* - Poly = 0x07
|
|
10
|
+
* - XorIn = 0x00
|
|
11
|
+
* - ReflectIn = False
|
|
12
|
+
* - XorOut = 0x00
|
|
13
|
+
* - ReflectOut = False
|
|
14
|
+
* - Algorithm = table-driven
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
#include "crc8.h"
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Static table used for the table_driven implementation.
|
|
21
|
+
*/
|
|
22
|
+
static const crc8_t crc8_1wire_table[256] = {
|
|
23
|
+
0x00, 0x07, 0x0e, 0x09, 0x1c, 0x1b, 0x12, 0x15, 0x38, 0x3f, 0x36, 0x31, 0x24, 0x23, 0x2a, 0x2d,
|
|
24
|
+
0x70, 0x77, 0x7e, 0x79, 0x6c, 0x6b, 0x62, 0x65, 0x48, 0x4f, 0x46, 0x41, 0x54, 0x53, 0x5a, 0x5d,
|
|
25
|
+
0xe0, 0xe7, 0xee, 0xe9, 0xfc, 0xfb, 0xf2, 0xf5, 0xd8, 0xdf, 0xd6, 0xd1, 0xc4, 0xc3, 0xca, 0xcd,
|
|
26
|
+
0x90, 0x97, 0x9e, 0x99, 0x8c, 0x8b, 0x82, 0x85, 0xa8, 0xaf, 0xa6, 0xa1, 0xb4, 0xb3, 0xba, 0xbd,
|
|
27
|
+
0xc7, 0xc0, 0xc9, 0xce, 0xdb, 0xdc, 0xd5, 0xd2, 0xff, 0xf8, 0xf1, 0xf6, 0xe3, 0xe4, 0xed, 0xea,
|
|
28
|
+
0xb7, 0xb0, 0xb9, 0xbe, 0xab, 0xac, 0xa5, 0xa2, 0x8f, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9d, 0x9a,
|
|
29
|
+
0x27, 0x20, 0x29, 0x2e, 0x3b, 0x3c, 0x35, 0x32, 0x1f, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0d, 0x0a,
|
|
30
|
+
0x57, 0x50, 0x59, 0x5e, 0x4b, 0x4c, 0x45, 0x42, 0x6f, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7d, 0x7a,
|
|
31
|
+
0x89, 0x8e, 0x87, 0x80, 0x95, 0x92, 0x9b, 0x9c, 0xb1, 0xb6, 0xbf, 0xb8, 0xad, 0xaa, 0xa3, 0xa4,
|
|
32
|
+
0xf9, 0xfe, 0xf7, 0xf0, 0xe5, 0xe2, 0xeb, 0xec, 0xc1, 0xc6, 0xcf, 0xc8, 0xdd, 0xda, 0xd3, 0xd4,
|
|
33
|
+
0x69, 0x6e, 0x67, 0x60, 0x75, 0x72, 0x7b, 0x7c, 0x51, 0x56, 0x5f, 0x58, 0x4d, 0x4a, 0x43, 0x44,
|
|
34
|
+
0x19, 0x1e, 0x17, 0x10, 0x05, 0x02, 0x0b, 0x0c, 0x21, 0x26, 0x2f, 0x28, 0x3d, 0x3a, 0x33, 0x34,
|
|
35
|
+
0x4e, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5c, 0x5b, 0x76, 0x71, 0x78, 0x7f, 0x6a, 0x6d, 0x64, 0x63,
|
|
36
|
+
0x3e, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2c, 0x2b, 0x06, 0x01, 0x08, 0x0f, 0x1a, 0x1d, 0x14, 0x13,
|
|
37
|
+
0xae, 0xa9, 0xa0, 0xa7, 0xb2, 0xb5, 0xbc, 0xbb, 0x96, 0x91, 0x98, 0x9f, 0x8a, 0x8d, 0x84, 0x83,
|
|
38
|
+
0xde, 0xd9, 0xd0, 0xd7, 0xc2, 0xc5, 0xcc, 0xcb, 0xe6, 0xe1, 0xe8, 0xef, 0xfa, 0xfd, 0xf4, 0xf3
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
crc8_t crc8_update(crc8_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;
|
|
49
|
+
crc = crc8_1wire_table[tbl_idx] & 0xff;
|
|
50
|
+
d++;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return crc & 0xff;
|
|
54
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#include "ruby.h"
|
|
2
|
+
#include "extconf.h"
|
|
3
|
+
|
|
4
|
+
#include "crc8.h"
|
|
5
|
+
|
|
6
|
+
VALUE Digest_CRC8_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
|
+
crc8_t crc = NUM2CHR(crc_ivar);
|
|
11
|
+
|
|
12
|
+
const char *data_ptr = StringValuePtr(data);
|
|
13
|
+
size_t length = RSTRING_LEN(data);
|
|
14
|
+
|
|
15
|
+
crc = crc8_update(crc,data_ptr,length);
|
|
16
|
+
|
|
17
|
+
rb_ivar_set(self, crc_ivar_name, UINT2NUM(crc));
|
|
18
|
+
return self;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
void Init_crc8_ext()
|
|
22
|
+
{
|
|
23
|
+
VALUE mDigest = rb_const_get(rb_cObject, rb_intern("Digest"));
|
|
24
|
+
VALUE cCRC8 = rb_const_get(mDigest, rb_intern("CRC8"));
|
|
25
|
+
|
|
26
|
+
#ifdef HAVE_RB_EXT_RACTOR_SAFE
|
|
27
|
+
rb_ext_ractor_safe(true);
|
|
28
|
+
#endif
|
|
29
|
+
|
|
30
|
+
rb_undef_method(cCRC8, "update");
|
|
31
|
+
rb_define_method(cCRC8, "update", Digest_CRC8_update, 1);
|
|
32
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* \file
|
|
3
|
+
* Functions and types for CRC checks.
|
|
4
|
+
*
|
|
5
|
+
* Generated on Sat Feb 29 02:02:50 2020
|
|
6
|
+
* by pycrc v0.9.2, https://pycrc.org
|
|
7
|
+
* using the configuration:
|
|
8
|
+
* - Width = 8
|
|
9
|
+
* - Poly = 0x31
|
|
10
|
+
* - XorIn = 0x00
|
|
11
|
+
* - ReflectIn = True
|
|
12
|
+
* - XorOut = 0x00
|
|
13
|
+
* - ReflectOut = True
|
|
14
|
+
* - Algorithm = table-driven
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
#include "crc8_1wire.h"
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Static table used for the table_driven implementation.
|
|
21
|
+
*/
|
|
22
|
+
static const crc8_t crc8_table[256] = {
|
|
23
|
+
0x00, 0x5e, 0xbc, 0xe2, 0x61, 0x3f, 0xdd, 0x83, 0xc2, 0x9c, 0x7e, 0x20, 0xa3, 0xfd, 0x1f, 0x41,
|
|
24
|
+
0x9d, 0xc3, 0x21, 0x7f, 0xfc, 0xa2, 0x40, 0x1e, 0x5f, 0x01, 0xe3, 0xbd, 0x3e, 0x60, 0x82, 0xdc,
|
|
25
|
+
0x23, 0x7d, 0x9f, 0xc1, 0x42, 0x1c, 0xfe, 0xa0, 0xe1, 0xbf, 0x5d, 0x03, 0x80, 0xde, 0x3c, 0x62,
|
|
26
|
+
0xbe, 0xe0, 0x02, 0x5c, 0xdf, 0x81, 0x63, 0x3d, 0x7c, 0x22, 0xc0, 0x9e, 0x1d, 0x43, 0xa1, 0xff,
|
|
27
|
+
0x46, 0x18, 0xfa, 0xa4, 0x27, 0x79, 0x9b, 0xc5, 0x84, 0xda, 0x38, 0x66, 0xe5, 0xbb, 0x59, 0x07,
|
|
28
|
+
0xdb, 0x85, 0x67, 0x39, 0xba, 0xe4, 0x06, 0x58, 0x19, 0x47, 0xa5, 0xfb, 0x78, 0x26, 0xc4, 0x9a,
|
|
29
|
+
0x65, 0x3b, 0xd9, 0x87, 0x04, 0x5a, 0xb8, 0xe6, 0xa7, 0xf9, 0x1b, 0x45, 0xc6, 0x98, 0x7a, 0x24,
|
|
30
|
+
0xf8, 0xa6, 0x44, 0x1a, 0x99, 0xc7, 0x25, 0x7b, 0x3a, 0x64, 0x86, 0xd8, 0x5b, 0x05, 0xe7, 0xb9,
|
|
31
|
+
0x8c, 0xd2, 0x30, 0x6e, 0xed, 0xb3, 0x51, 0x0f, 0x4e, 0x10, 0xf2, 0xac, 0x2f, 0x71, 0x93, 0xcd,
|
|
32
|
+
0x11, 0x4f, 0xad, 0xf3, 0x70, 0x2e, 0xcc, 0x92, 0xd3, 0x8d, 0x6f, 0x31, 0xb2, 0xec, 0x0e, 0x50,
|
|
33
|
+
0xaf, 0xf1, 0x13, 0x4d, 0xce, 0x90, 0x72, 0x2c, 0x6d, 0x33, 0xd1, 0x8f, 0x0c, 0x52, 0xb0, 0xee,
|
|
34
|
+
0x32, 0x6c, 0x8e, 0xd0, 0x53, 0x0d, 0xef, 0xb1, 0xf0, 0xae, 0x4c, 0x12, 0x91, 0xcf, 0x2d, 0x73,
|
|
35
|
+
0xca, 0x94, 0x76, 0x28, 0xab, 0xf5, 0x17, 0x49, 0x08, 0x56, 0xb4, 0xea, 0x69, 0x37, 0xd5, 0x8b,
|
|
36
|
+
0x57, 0x09, 0xeb, 0xb5, 0x36, 0x68, 0x8a, 0xd4, 0x95, 0xcb, 0x29, 0x77, 0xf4, 0xaa, 0x48, 0x16,
|
|
37
|
+
0xe9, 0xb7, 0x55, 0x0b, 0x88, 0xd6, 0x34, 0x6a, 0x2b, 0x75, 0x97, 0xc9, 0x4a, 0x14, 0xf6, 0xa8,
|
|
38
|
+
0x74, 0x2a, 0xc8, 0x96, 0x15, 0x4b, 0xa9, 0xf7, 0xb6, 0xe8, 0x0a, 0x54, 0xd7, 0x89, 0x6b, 0x35
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
crc8_t crc8_1wire_update(crc8_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;
|
|
49
|
+
crc = (crc8_table[tbl_idx] ^ (crc >> 8)) & 0xff;
|
|
50
|
+
d++;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return crc & 0xff;
|
|
54
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#include "ruby.h"
|
|
2
|
+
#include "extconf.h"
|
|
3
|
+
|
|
4
|
+
#include "crc8_1wire.h"
|
|
5
|
+
|
|
6
|
+
VALUE Digest_CRC81Wire_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
|
+
crc8_t crc = NUM2CHR(crc_ivar);
|
|
11
|
+
|
|
12
|
+
const char *data_ptr = StringValuePtr(data);
|
|
13
|
+
size_t length = RSTRING_LEN(data);
|
|
14
|
+
|
|
15
|
+
crc = crc8_1wire_update(crc,data_ptr,length);
|
|
16
|
+
|
|
17
|
+
rb_ivar_set(self, crc_ivar_name, UINT2NUM(crc));
|
|
18
|
+
return self;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
void Init_crc8_1wire_ext()
|
|
22
|
+
{
|
|
23
|
+
VALUE mDigest = rb_const_get(rb_cObject, rb_intern("Digest"));
|
|
24
|
+
VALUE cCRC81Wire = rb_const_get(mDigest, rb_intern("CRC8_1Wire"));
|
|
25
|
+
|
|
26
|
+
#ifdef HAVE_RB_EXT_RACTOR_SAFE
|
|
27
|
+
rb_ext_ractor_safe(true);
|
|
28
|
+
#endif
|
|
29
|
+
|
|
30
|
+
rb_define_method(cCRC81Wire, "update", Digest_CRC81Wire_update, 1);
|
|
31
|
+
}
|
data/gemspec.yml
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
name: precompiled-digest-crc
|
|
2
|
+
version: 0.7.0
|
|
3
|
+
summary: A Cyclic Redundancy Check (CRC) library for Ruby.
|
|
4
|
+
description:
|
|
5
|
+
Adds support for calculating Cyclic Redundancy Check (CRC) to the Digest
|
|
6
|
+
module.
|
|
7
|
+
|
|
8
|
+
license: MIT
|
|
9
|
+
authors: Postmodern
|
|
10
|
+
email: postmodern.mod3@gmail.com
|
|
11
|
+
homepage: https://github.com/postmodern/digest-crc#readme
|
|
12
|
+
|
|
13
|
+
metadata:
|
|
14
|
+
documentation_uri: https://rubydoc.info/gems/digest-crc
|
|
15
|
+
source_code_uri: https://github.com/postmodern/digest-crc
|
|
16
|
+
bug_tracker_uri: https://github.com/postmodern/digest-crc/issues
|
|
17
|
+
changelog_uri: https://github.com/postmodern/digest-crc/blob/master/ChangeLog.md
|
|
18
|
+
|
|
19
|
+
required_ruby_version: '>= 3.0.0'
|
|
20
|
+
|
|
21
|
+
dependencies:
|
|
22
|
+
rake: ">= 12.0.0, < 14.0.0"
|
|
23
|
+
|
|
24
|
+
development_dependencies:
|
|
25
|
+
bundler: ">= 2.0.0"
|
data/lib/digest/crc.rb
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
require 'digest'
|
|
2
|
+
|
|
3
|
+
module Digest
|
|
4
|
+
#
|
|
5
|
+
# Base class for all CRC algorithms.
|
|
6
|
+
#
|
|
7
|
+
class CRC < Digest::Class
|
|
8
|
+
|
|
9
|
+
include Digest::Instance
|
|
10
|
+
|
|
11
|
+
# The initial value of the CRC checksum
|
|
12
|
+
INIT_CRC = 0x00
|
|
13
|
+
|
|
14
|
+
# The XOR mask to apply to the resulting CRC checksum
|
|
15
|
+
XOR_MASK = 0x00
|
|
16
|
+
|
|
17
|
+
# The bit width of the CRC checksum
|
|
18
|
+
WIDTH = 0
|
|
19
|
+
|
|
20
|
+
# Define true or false whether the input direction is bit reversed or not of the CRC checksum
|
|
21
|
+
REFLECT_INPUT = nil
|
|
22
|
+
|
|
23
|
+
# Default place holder CRC table
|
|
24
|
+
TABLE = [].freeze
|
|
25
|
+
|
|
26
|
+
#
|
|
27
|
+
# Calculates the CRC checksum.
|
|
28
|
+
#
|
|
29
|
+
# @param [String] data
|
|
30
|
+
# The given data.
|
|
31
|
+
#
|
|
32
|
+
# @return [Integer]
|
|
33
|
+
# The CRC checksum.
|
|
34
|
+
#
|
|
35
|
+
def self.checksum(data)
|
|
36
|
+
crc = self.new
|
|
37
|
+
crc << data
|
|
38
|
+
|
|
39
|
+
return crc.checksum
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
#
|
|
43
|
+
# Packs the given CRC checksum.
|
|
44
|
+
#
|
|
45
|
+
# @param [Integer] crc
|
|
46
|
+
# The raw CRC checksum.
|
|
47
|
+
#
|
|
48
|
+
# @return [String]
|
|
49
|
+
# The packed CRC checksum.
|
|
50
|
+
#
|
|
51
|
+
def self.pack(crc)
|
|
52
|
+
unless (width = self::WIDTH) > 0
|
|
53
|
+
raise(NotImplementedError, "#{self} is incompleted as CRC")
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
bitclass = width + (-width & 0x07)
|
|
57
|
+
byte_count = bitclass / 8
|
|
58
|
+
|
|
59
|
+
crc &= ~(-1 << width)
|
|
60
|
+
|
|
61
|
+
result = [crc].pack("Q>")
|
|
62
|
+
result[0, result.bytesize - byte_count] = ""
|
|
63
|
+
result
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
#
|
|
67
|
+
# Determines whether the library is using the optimized C extensions
|
|
68
|
+
# implementation, or the pure-Ruby implementation.
|
|
69
|
+
#
|
|
70
|
+
# @return [:c_ext, :pure]
|
|
71
|
+
#
|
|
72
|
+
# @since 0.7.0
|
|
73
|
+
#
|
|
74
|
+
def self.implementation
|
|
75
|
+
if instance_method(:update).source_location.nil?
|
|
76
|
+
:c_ext
|
|
77
|
+
else
|
|
78
|
+
:pure
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
#
|
|
83
|
+
# Initializes the CRC checksum.
|
|
84
|
+
#
|
|
85
|
+
def initialize
|
|
86
|
+
@init_crc = self.class.const_get(:INIT_CRC)
|
|
87
|
+
@xor_mask = self.class.const_get(:XOR_MASK)
|
|
88
|
+
@width = self.class.const_get(:WIDTH)
|
|
89
|
+
@reflect_input = self.class.const_get(:REFLECT_INPUT)
|
|
90
|
+
@table = self.class.const_get(:TABLE)
|
|
91
|
+
|
|
92
|
+
reset
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
#
|
|
96
|
+
# The input block length.
|
|
97
|
+
#
|
|
98
|
+
# @return [1]
|
|
99
|
+
#
|
|
100
|
+
def block_length
|
|
101
|
+
1
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
#
|
|
105
|
+
# The length of the digest.
|
|
106
|
+
#
|
|
107
|
+
# @return [Integer]
|
|
108
|
+
# The length in bytes.
|
|
109
|
+
#
|
|
110
|
+
def digest_length
|
|
111
|
+
(@width / 8.0).ceil
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
#
|
|
115
|
+
# Updates the CRC checksum with the given data.
|
|
116
|
+
#
|
|
117
|
+
# @param [String] data
|
|
118
|
+
# The data to update the CRC checksum with.
|
|
119
|
+
#
|
|
120
|
+
# @raise [NotImplementedError]
|
|
121
|
+
# If WIDTH, TABLE, or REFLECT_INPUT constants are not set properly.
|
|
122
|
+
#
|
|
123
|
+
def update(data)
|
|
124
|
+
unless @width >= 1
|
|
125
|
+
raise(NotImplementedError, "incompleted #{self.class} as CRC (expected WIDTH to be 1 or more)")
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
if @table.empty?
|
|
129
|
+
raise(NotImplementedError, "incompleted #{self.class} as CRC (expected TABLE to be not empty)")
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
if @reflect_input.nil?
|
|
133
|
+
raise(NotImplementedError, "incompleted #{self.class} as CRC (expected REFLECT_INPUT to be not nil)")
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
table = @table
|
|
137
|
+
crc = @crc
|
|
138
|
+
|
|
139
|
+
if @reflect_input
|
|
140
|
+
if @width > 8
|
|
141
|
+
data.each_byte do |b|
|
|
142
|
+
crc = table[b ^ (0xff & crc)] ^ (crc >> 8)
|
|
143
|
+
end
|
|
144
|
+
else
|
|
145
|
+
data.each_byte do |b|
|
|
146
|
+
# Omit (crc >> 8) since bits upper than the lower 8 bits are always 0
|
|
147
|
+
crc = table[b ^ (0xff & crc)]
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
else
|
|
151
|
+
if @width > 8
|
|
152
|
+
higher_bit_off = @width - 8
|
|
153
|
+
remain_mask = ~(-1 << higher_bit_off)
|
|
154
|
+
|
|
155
|
+
data.each_byte do |b|
|
|
156
|
+
crc = table[b ^ (0xff & (crc >> higher_bit_off))] ^ ((remain_mask & crc) << 8)
|
|
157
|
+
end
|
|
158
|
+
else
|
|
159
|
+
padding = 8 - @width
|
|
160
|
+
|
|
161
|
+
data.each_byte do |b|
|
|
162
|
+
# Omit (crc << 8) since bits lower than the upper 8 bits are always 0
|
|
163
|
+
crc = table[b ^ (0xff & (crc << padding))]
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
@crc = crc
|
|
169
|
+
|
|
170
|
+
self
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
#
|
|
174
|
+
# @see #update
|
|
175
|
+
#
|
|
176
|
+
def <<(data)
|
|
177
|
+
update(data)
|
|
178
|
+
return self
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
#
|
|
182
|
+
# Resets the CRC checksum.
|
|
183
|
+
#
|
|
184
|
+
# @return [Integer]
|
|
185
|
+
# The default value of the CRC checksum.
|
|
186
|
+
#
|
|
187
|
+
def reset
|
|
188
|
+
@crc = @init_crc
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
#
|
|
192
|
+
# The resulting CRC checksum.
|
|
193
|
+
#
|
|
194
|
+
# @return [Integer]
|
|
195
|
+
# The resulting CRC checksum.
|
|
196
|
+
#
|
|
197
|
+
def checksum
|
|
198
|
+
@crc ^ @xor_mask
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
#
|
|
202
|
+
# Finishes the CRC checksum calculation.
|
|
203
|
+
#
|
|
204
|
+
# @see pack
|
|
205
|
+
#
|
|
206
|
+
def finish
|
|
207
|
+
self.class.pack(checksum)
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
end
|
|
211
|
+
end
|
data/lib/digest/crc1.rb
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'digest/crc'
|
|
2
|
+
|
|
3
|
+
module Digest
|
|
4
|
+
#
|
|
5
|
+
# Implements the CRC1 algorithm.
|
|
6
|
+
#
|
|
7
|
+
class CRC1 < CRC
|
|
8
|
+
|
|
9
|
+
WIDTH = 1
|
|
10
|
+
|
|
11
|
+
#
|
|
12
|
+
# Packs the CRC1 checksum.
|
|
13
|
+
#
|
|
14
|
+
# @return [String]
|
|
15
|
+
# The CRC1 checksum.
|
|
16
|
+
#
|
|
17
|
+
def self.pack(crc)
|
|
18
|
+
[crc].pack('c*')
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
#
|
|
22
|
+
# Updates the CRC1 checksum.
|
|
23
|
+
#
|
|
24
|
+
# @param [String] data
|
|
25
|
+
# The data to update the checksum with.
|
|
26
|
+
#
|
|
27
|
+
def update(data)
|
|
28
|
+
accum = 0
|
|
29
|
+
data.each_byte { |b| accum += b }
|
|
30
|
+
|
|
31
|
+
@crc += (accum % 256)
|
|
32
|
+
|
|
33
|
+
return self
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
end
|
data/lib/digest/crc15.rb
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'digest/crc'
|
|
2
|
+
|
|
3
|
+
module Digest
|
|
4
|
+
#
|
|
5
|
+
# Implements the CRC15 algorithm.
|
|
6
|
+
#
|
|
7
|
+
# @since 0.5.0
|
|
8
|
+
#
|
|
9
|
+
class CRC15 < CRC
|
|
10
|
+
|
|
11
|
+
WIDTH = 15
|
|
12
|
+
|
|
13
|
+
REFLECT_INPUT = false
|
|
14
|
+
|
|
15
|
+
# Generated by `./pycrc.py --algorithm=table-driven --model=crc-16 --generate=c`
|
|
16
|
+
TABLE = [
|
|
17
|
+
0x0000, 0x4599, 0x4eab, 0x0b32, 0x58cf, 0x1d56, 0x1664, 0x53fd, 0x7407, 0x319e, 0x3aac, 0x7f35, 0x2cc8, 0x6951, 0x6263, 0x27fa,
|
|
18
|
+
0x2d97, 0x680e, 0x633c, 0x26a5, 0x7558, 0x30c1, 0x3bf3, 0x7e6a, 0x5990, 0x1c09, 0x173b, 0x52a2, 0x015f, 0x44c6, 0x4ff4, 0x0a6d,
|
|
19
|
+
0x5b2e, 0x1eb7, 0x1585, 0x501c, 0x03e1, 0x4678, 0x4d4a, 0x08d3, 0x2f29, 0x6ab0, 0x6182, 0x241b, 0x77e6, 0x327f, 0x394d, 0x7cd4,
|
|
20
|
+
0x76b9, 0x3320, 0x3812, 0x7d8b, 0x2e76, 0x6bef, 0x60dd, 0x2544, 0x02be, 0x4727, 0x4c15, 0x098c, 0x5a71, 0x1fe8, 0x14da, 0x5143,
|
|
21
|
+
0x73c5, 0x365c, 0x3d6e, 0x78f7, 0x2b0a, 0x6e93, 0x65a1, 0x2038, 0x07c2, 0x425b, 0x4969, 0x0cf0, 0x5f0d, 0x1a94, 0x11a6, 0x543f,
|
|
22
|
+
0x5e52, 0x1bcb, 0x10f9, 0x5560, 0x069d, 0x4304, 0x4836, 0x0daf, 0x2a55, 0x6fcc, 0x64fe, 0x2167, 0x729a, 0x3703, 0x3c31, 0x79a8,
|
|
23
|
+
0x28eb, 0x6d72, 0x6640, 0x23d9, 0x7024, 0x35bd, 0x3e8f, 0x7b16, 0x5cec, 0x1975, 0x1247, 0x57de, 0x0423, 0x41ba, 0x4a88, 0x0f11,
|
|
24
|
+
0x057c, 0x40e5, 0x4bd7, 0x0e4e, 0x5db3, 0x182a, 0x1318, 0x5681, 0x717b, 0x34e2, 0x3fd0, 0x7a49, 0x29b4, 0x6c2d, 0x671f, 0x2286,
|
|
25
|
+
0x2213, 0x678a, 0x6cb8, 0x2921, 0x7adc, 0x3f45, 0x3477, 0x71ee, 0x5614, 0x138d, 0x18bf, 0x5d26, 0x0edb, 0x4b42, 0x4070, 0x05e9,
|
|
26
|
+
0x0f84, 0x4a1d, 0x412f, 0x04b6, 0x574b, 0x12d2, 0x19e0, 0x5c79, 0x7b83, 0x3e1a, 0x3528, 0x70b1, 0x234c, 0x66d5, 0x6de7, 0x287e,
|
|
27
|
+
0x793d, 0x3ca4, 0x3796, 0x720f, 0x21f2, 0x646b, 0x6f59, 0x2ac0, 0x0d3a, 0x48a3, 0x4391, 0x0608, 0x55f5, 0x106c, 0x1b5e, 0x5ec7,
|
|
28
|
+
0x54aa, 0x1133, 0x1a01, 0x5f98, 0x0c65, 0x49fc, 0x42ce, 0x0757, 0x20ad, 0x6534, 0x6e06, 0x2b9f, 0x7862, 0x3dfb, 0x36c9, 0x7350,
|
|
29
|
+
0x51d6, 0x144f, 0x1f7d, 0x5ae4, 0x0919, 0x4c80, 0x47b2, 0x022b, 0x25d1, 0x6048, 0x6b7a, 0x2ee3, 0x7d1e, 0x3887, 0x33b5, 0x762c,
|
|
30
|
+
0x7c41, 0x39d8, 0x32ea, 0x7773, 0x248e, 0x6117, 0x6a25, 0x2fbc, 0x0846, 0x4ddf, 0x46ed, 0x0374, 0x5089, 0x1510, 0x1e22, 0x5bbb,
|
|
31
|
+
0x0af8, 0x4f61, 0x4453, 0x01ca, 0x5237, 0x17ae, 0x1c9c, 0x5905, 0x7eff, 0x3b66, 0x3054, 0x75cd, 0x2630, 0x63a9, 0x689b, 0x2d02,
|
|
32
|
+
0x276f, 0x62f6, 0x69c4, 0x2c5d, 0x7fa0, 0x3a39, 0x310b, 0x7492, 0x5368, 0x16f1, 0x1dc3, 0x585a, 0x0ba7, 0x4e3e, 0x450c, 0x0095
|
|
33
|
+
].freeze
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
if RUBY_ENGINE == 'ruby'
|
|
39
|
+
begin
|
|
40
|
+
ruby_version = /(\d+\.\d+)/.match(RUBY_VERSION)
|
|
41
|
+
require "digest/crc15/#{ruby_version}/crc15_ext"
|
|
42
|
+
rescue LoadError
|
|
43
|
+
begin; require 'digest/crc15/crc15_ext'; rescue LoadError; end
|
|
44
|
+
end
|
|
45
|
+
end
|
data/lib/digest/crc16.rb
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
require 'digest/crc'
|
|
2
|
+
|
|
3
|
+
module Digest
|
|
4
|
+
#
|
|
5
|
+
# Implements the CRC16 algorithm.
|
|
6
|
+
#
|
|
7
|
+
class CRC16 < CRC
|
|
8
|
+
|
|
9
|
+
WIDTH = 16
|
|
10
|
+
|
|
11
|
+
REFLECT_INPUT = true
|
|
12
|
+
|
|
13
|
+
INIT_CRC = 0x0000
|
|
14
|
+
|
|
15
|
+
# Generated by `./pycrc.py --algorithm=table-driven --model=crc-16`
|
|
16
|
+
TABLE = [
|
|
17
|
+
0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241,
|
|
18
|
+
0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440,
|
|
19
|
+
0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40,
|
|
20
|
+
0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841,
|
|
21
|
+
0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40,
|
|
22
|
+
0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41,
|
|
23
|
+
0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641,
|
|
24
|
+
0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040,
|
|
25
|
+
0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240,
|
|
26
|
+
0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441,
|
|
27
|
+
0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41,
|
|
28
|
+
0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840,
|
|
29
|
+
0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41,
|
|
30
|
+
0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40,
|
|
31
|
+
0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640,
|
|
32
|
+
0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041,
|
|
33
|
+
0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240,
|
|
34
|
+
0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441,
|
|
35
|
+
0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41,
|
|
36
|
+
0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840,
|
|
37
|
+
0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41,
|
|
38
|
+
0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40,
|
|
39
|
+
0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640,
|
|
40
|
+
0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041,
|
|
41
|
+
0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241,
|
|
42
|
+
0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440,
|
|
43
|
+
0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40,
|
|
44
|
+
0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841,
|
|
45
|
+
0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40,
|
|
46
|
+
0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41,
|
|
47
|
+
0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641,
|
|
48
|
+
0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040
|
|
49
|
+
].freeze
|
|
50
|
+
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
if RUBY_ENGINE == 'ruby'
|
|
55
|
+
begin
|
|
56
|
+
ruby_version = /(\d+\.\d+)/.match(RUBY_VERSION)
|
|
57
|
+
require "digest/crc16/#{ruby_version}/crc16_ext"
|
|
58
|
+
rescue LoadError
|
|
59
|
+
begin; require 'digest/crc16/crc16_ext'; rescue LoadError; end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
require 'digest/crc16'
|
|
2
|
+
|
|
3
|
+
module Digest
|
|
4
|
+
#
|
|
5
|
+
# Implements the CRC16 CCITT algorithm.
|
|
6
|
+
#
|
|
7
|
+
class CRC16CCITT < CRC16
|
|
8
|
+
|
|
9
|
+
REFLECT_INPUT = false
|
|
10
|
+
|
|
11
|
+
INIT_CRC = 0xffff
|
|
12
|
+
|
|
13
|
+
# Generated by `./pycrc.py --algorithm=table-driven --model=crc-16-ccitt --generate=c`
|
|
14
|
+
TABLE = [
|
|
15
|
+
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
|
|
16
|
+
0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
|
|
17
|
+
0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
|
|
18
|
+
0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
|
|
19
|
+
0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
|
|
20
|
+
0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
|
|
21
|
+
0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
|
|
22
|
+
0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
|
|
23
|
+
0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
|
|
24
|
+
0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
|
|
25
|
+
0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
|
|
26
|
+
0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
|
|
27
|
+
0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
|
|
28
|
+
0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
|
|
29
|
+
0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
|
|
30
|
+
0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
|
|
31
|
+
0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
|
|
32
|
+
0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
|
|
33
|
+
0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
|
|
34
|
+
0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
|
|
35
|
+
0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
|
|
36
|
+
0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
|
|
37
|
+
0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
|
|
38
|
+
0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
|
|
39
|
+
0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
|
|
40
|
+
0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
|
|
41
|
+
0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
|
|
42
|
+
0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
|
|
43
|
+
0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
|
|
44
|
+
0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
|
|
45
|
+
0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
|
|
46
|
+
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
|
|
47
|
+
].freeze
|
|
48
|
+
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
if RUBY_ENGINE == 'ruby'
|
|
53
|
+
begin
|
|
54
|
+
ruby_version = /(\d+\.\d+)/.match(RUBY_VERSION)
|
|
55
|
+
require "digest/crc16_ccitt/#{ruby_version}/crc16_ccitt_ext"
|
|
56
|
+
rescue LoadError
|
|
57
|
+
begin; require 'digest/crc16_ccitt/crc16_ccitt_ext'; rescue LoadError; end
|
|
58
|
+
end
|
|
59
|
+
end
|