digest-crc 0.6.0 → 0.6.1
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 +4 -4
- data/ChangeLog.md +5 -1
- data/README.md +107 -0
- data/ext/digest/crc12_3gpp/crc12_3gpp.c +19 -17
- data/ext/digest/crc15/crc15.c +10 -9
- data/ext/digest/crc16/crc16.c +42 -41
- data/ext/digest/crc16_ccitt/crc16_ccitt.c +42 -41
- data/ext/digest/crc16_dnp/crc16_dnp.c +42 -41
- data/ext/digest/crc16_genibus/crc16_genibus.c +42 -41
- data/ext/digest/crc16_kermit/crc16_kermit.c +42 -41
- data/ext/digest/crc16_modbus/crc16_modbus.c +42 -41
- data/ext/digest/crc16_usb/crc16_usb.c +42 -41
- data/ext/digest/crc16_x_25/crc16_x_25.c +42 -41
- data/ext/digest/crc16_xmodem/crc16_xmodem.c +42 -41
- data/ext/digest/crc16_zmodem/crc16_zmodem.c +42 -41
- data/ext/digest/crc24/crc24.c +42 -41
- data/ext/digest/crc32/crc32.c +42 -41
- data/ext/digest/crc32_bzip2/crc32_bzip2.c +42 -41
- data/ext/digest/crc32_jam/crc32_jam.c +42 -41
- data/ext/digest/crc32_mpeg/crc32_mpeg.c +42 -41
- data/ext/digest/crc32_posix/crc32_posix.c +42 -41
- data/ext/digest/crc32_xfer/crc32_xfer.c +42 -41
- data/ext/digest/crc32c/crc32c.c +42 -41
- data/ext/digest/crc5/crc5.c +26 -25
- data/ext/digest/crc64/crc64.c +74 -74
- data/ext/digest/crc64_jones/crc64_jones.c +74 -74
- data/ext/digest/crc64_xz/crc64_xz.c +74 -74
- data/ext/digest/crc8/crc8.c +26 -25
- data/ext/digest/crc8_1wire/crc8_1wire.c +26 -25
- data/gemspec.yml +4 -1
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f6be5490751ab763c1fdd99f95a2e4ae0a22a073969623f14170159cb55c5b0
|
4
|
+
data.tar.gz: 7f152d312932b784ce074ce9d463bf07dd2bccf5035d9b1bc98dd8c804daa377
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e9e53d3fc14577e50276ea0f13b663bf62fcafbc2a063491e076bdec99d467f0c57ad0d0cb5b794af1dbadc6794db4070cb6d956b13f4525c5c30af3dea618b
|
7
|
+
data.tar.gz: '07198de582c8e350def1763a6c2593ad8a42065c675826c278e3326e81d1a1960b613879a7df017727e12cdc4a4ffc36c15350108a3f6d87076e1f28e4d81afe'
|
data/ChangeLog.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
### 0.6.1 / 2020-07-02
|
2
|
+
|
3
|
+
* Fix installation issues under bundler by adding rake as an explicit dependency
|
4
|
+
(@rogerluan).
|
5
|
+
|
1
6
|
### 0.6.0 / 2020-07-01
|
2
7
|
|
3
8
|
* Implement _optional_ C extensions for all CRC algorithms, resulting in an
|
@@ -174,4 +179,3 @@
|
|
174
179
|
* CRC32
|
175
180
|
* CRC32 Mpeg
|
176
181
|
* CRC64
|
177
|
-
|
data/README.md
CHANGED
@@ -119,6 +119,113 @@ module Digest
|
|
119
119
|
end
|
120
120
|
```
|
121
121
|
|
122
|
+
## Benchmarks
|
123
|
+
|
124
|
+
### Pure Ruby (ruby 2.7.1)
|
125
|
+
|
126
|
+
$ bundle exec rake clean
|
127
|
+
$ bundle exec ./benchmarks.rb
|
128
|
+
Loading Digest::CRC classes ...
|
129
|
+
Generating 1000 8Kb lengthed strings ...
|
130
|
+
Benchmarking Digest::CRC classes ...
|
131
|
+
user system total real
|
132
|
+
Digest::CRC1#update 0.349756 0.000002 0.349758 ( 0.351427)
|
133
|
+
Digest::CRC5#update 1.175206 0.000049 1.175255 ( 1.180975)
|
134
|
+
Digest::CRC8#update 1.023536 0.000015 1.023551 ( 1.029017)
|
135
|
+
Digest::CRC8_1Wire#update 1.012156 0.000000 1.012156 ( 1.017342)
|
136
|
+
Digest::CRC15#update 1.187286 0.000005 1.187291 ( 1.193634)
|
137
|
+
Digest::CRC16#update 0.998527 0.000013 0.998540 ( 1.003940)
|
138
|
+
Digest::CRC16CCITT#update 1.179864 0.000005 1.179869 ( 1.186134)
|
139
|
+
Digest::CRC16DNP#update 1.018969 0.000003 1.018972 ( 1.025248)
|
140
|
+
Digest::CRC16Genibus#update 1.196754 0.000065 1.196819 ( 1.203605)
|
141
|
+
Digest::CRC16Modbus#update 1.007367 0.000000 1.007367 ( 1.012325)
|
142
|
+
Digest::CRC16X25#update 1.044127 0.000000 1.044127 ( 1.052010)
|
143
|
+
Digest::CRC16USB#update 1.012804 0.000000 1.012804 ( 1.018324)
|
144
|
+
Digest::CRC16X25#update 1.009694 0.000000 1.009694 ( 1.015890)
|
145
|
+
Digest::CRC16XModem#update 1.210814 0.000000 1.210814 ( 1.217951)
|
146
|
+
Digest::CRC16ZModem#update 1.175239 0.000000 1.175239 ( 1.181395)
|
147
|
+
Digest::CRC24#update 1.207431 0.000000 1.207431 ( 1.213373)
|
148
|
+
Digest::CRC32#update 1.012334 0.000000 1.012334 ( 1.017671)
|
149
|
+
Digest::CRC32BZip2#update 1.190351 0.000000 1.190351 ( 1.196567)
|
150
|
+
Digest::CRC32c#update 1.021147 0.000000 1.021147 ( 1.027035)
|
151
|
+
Digest::CRC32Jam#update 1.002365 0.000000 1.002365 ( 1.007202)
|
152
|
+
Digest::CRC32MPEG#update 1.161925 0.000000 1.161925 ( 1.168058)
|
153
|
+
Digest::CRC32POSIX#update 1.191860 0.000967 1.192827 ( 1.198722)
|
154
|
+
Digest::CRC32XFER#update 1.217692 0.000000 1.217692 ( 1.224075)
|
155
|
+
Digest::CRC64#update 3.084106 0.000000 3.084106 ( 3.106840)
|
156
|
+
Digest::CRC64Jones#update 3.016687 0.000000 3.016687 ( 3.038963)
|
157
|
+
Digest::CRC64XZ#update 3.019690 0.000000 3.019690 ( 3.040971)
|
158
|
+
|
159
|
+
### C extensions (ruby 2.7.1)
|
160
|
+
o
|
161
|
+
$ bundle exec rake build:c_exts
|
162
|
+
...
|
163
|
+
$ bundle exec ./benchmarks.rb
|
164
|
+
Loading Digest::CRC classes ...
|
165
|
+
Generating 1000 8Kb lengthed strings ...
|
166
|
+
Benchmarking Digest::CRC classes ...
|
167
|
+
user system total real
|
168
|
+
Digest::CRC1#update 0.356025 0.000016 0.356041 ( 0.365345)
|
169
|
+
Digest::CRC5#update 0.023957 0.000001 0.023958 ( 0.024835)
|
170
|
+
Digest::CRC8#update 0.021254 0.000007 0.021261 ( 0.024647)
|
171
|
+
Digest::CRC8_1Wire#update 0.039129 0.000000 0.039129 ( 0.042417)
|
172
|
+
Digest::CRC15#update 0.030285 0.000000 0.030285 ( 0.030560)
|
173
|
+
Digest::CRC16#update 0.023003 0.000000 0.023003 ( 0.023267)
|
174
|
+
Digest::CRC16CCITT#update 0.028207 0.000000 0.028207 ( 0.028467)
|
175
|
+
Digest::CRC16DNP#update 0.022861 0.000000 0.022861 ( 0.023111)
|
176
|
+
Digest::CRC16Genibus#update 0.028041 0.000000 0.028041 ( 0.028359)
|
177
|
+
Digest::CRC16Modbus#update 0.022931 0.000009 0.022940 ( 0.023560)
|
178
|
+
Digest::CRC16X25#update 0.022808 0.000000 0.022808 ( 0.023054)
|
179
|
+
Digest::CRC16USB#update 0.022258 0.000882 0.023140 ( 0.023418)
|
180
|
+
Digest::CRC16X25#update 0.022816 0.000000 0.022816 ( 0.023084)
|
181
|
+
Digest::CRC16XModem#update 0.027984 0.000000 0.027984 ( 0.028269)
|
182
|
+
Digest::CRC16ZModem#update 0.027968 0.000000 0.027968 ( 0.028214)
|
183
|
+
Digest::CRC24#update 0.028426 0.000000 0.028426 ( 0.028687)
|
184
|
+
Digest::CRC32#update 0.022805 0.000000 0.022805 ( 0.023043)
|
185
|
+
Digest::CRC32BZip2#update 0.025519 0.000000 0.025519 ( 0.025797)
|
186
|
+
Digest::CRC32c#update 0.022807 0.000000 0.022807 ( 0.023069)
|
187
|
+
Digest::CRC32Jam#update 0.023006 0.000000 0.023006 ( 0.023231)
|
188
|
+
Digest::CRC32MPEG#update 0.025536 0.000000 0.025536 ( 0.025861)
|
189
|
+
Digest::CRC32POSIX#update 0.025557 0.000000 0.025557 ( 0.025841)
|
190
|
+
Digest::CRC32XFER#update 0.025310 0.000000 0.025310 ( 0.025599)
|
191
|
+
Digest::CRC64#update 0.023182 0.000000 0.023182 ( 0.023421)
|
192
|
+
Digest::CRC64Jones#update 0.022916 0.000000 0.022916 ( 0.023139)
|
193
|
+
Digest::CRC64XZ#update 0.022879 0.000000 0.022879 ( 0.023131)
|
194
|
+
|
195
|
+
### Pure Ruby (jruby 9.2.12.0)
|
196
|
+
|
197
|
+
$ bundle exec ./benchmarks.rb
|
198
|
+
Loading Digest::CRC classes ...
|
199
|
+
Generating 1000 8Kb lengthed strings ...
|
200
|
+
Benchmarking Digest::CRC classes ...
|
201
|
+
user system total real
|
202
|
+
Digest::CRC1#update 1.030000 0.090000 1.120000 ( 0.511189)
|
203
|
+
Digest::CRC5#update 1.620000 0.060000 1.680000 ( 1.096031)
|
204
|
+
Digest::CRC8#update 1.560000 0.070000 1.630000 ( 1.083921)
|
205
|
+
Digest::CRC8_1Wire#update 0.930000 0.040000 0.970000 ( 0.927024)
|
206
|
+
Digest::CRC15#update 1.590000 0.070000 1.660000 ( 1.132566)
|
207
|
+
Digest::CRC16#update 1.650000 0.060000 1.710000 ( 1.074508)
|
208
|
+
Digest::CRC16CCITT#update 1.610000 0.060000 1.670000 ( 1.190860)
|
209
|
+
Digest::CRC16DNP#update 1.270000 0.010000 1.280000 ( 0.938132)
|
210
|
+
Digest::CRC16Genibus#update 1.620000 0.030000 1.650000 ( 1.148556)
|
211
|
+
Digest::CRC16Modbus#update 1.070000 0.020000 1.090000 ( 0.881455)
|
212
|
+
Digest::CRC16X25#update 1.110000 0.010000 1.120000 ( 0.945366)
|
213
|
+
Digest::CRC16USB#update 1.140000 0.000000 1.140000 ( 0.984367)
|
214
|
+
Digest::CRC16X25#update 0.920000 0.010000 0.930000 ( 0.872541)
|
215
|
+
Digest::CRC16XModem#update 1.530000 0.010000 1.540000 ( 1.092838)
|
216
|
+
Digest::CRC16ZModem#update 1.720000 0.010000 1.730000 ( 1.164787)
|
217
|
+
Digest::CRC24#update 1.810000 0.020000 1.830000 ( 1.084953)
|
218
|
+
Digest::CRC32#update 1.590000 0.010000 1.600000 ( 1.105553)
|
219
|
+
Digest::CRC32BZip2#update 1.520000 0.010000 1.530000 ( 1.070839)
|
220
|
+
Digest::CRC32c#update 0.960000 0.010000 0.970000 ( 0.881989)
|
221
|
+
Digest::CRC32Jam#update 1.030000 0.010000 1.040000 ( 0.907208)
|
222
|
+
Digest::CRC32MPEG#update 1.420000 0.010000 1.430000 ( 0.994035)
|
223
|
+
Digest::CRC32POSIX#update 1.530000 0.020000 1.550000 ( 1.106366)
|
224
|
+
Digest::CRC32XFER#update 1.650000 0.010000 1.660000 ( 1.097647)
|
225
|
+
Digest::CRC64#update 3.440000 0.030000 3.470000 ( 2.771806)
|
226
|
+
Digest::CRC64Jones#update 2.630000 0.010000 2.640000 ( 2.628016)
|
227
|
+
Digest::CRC64XZ#update 3.200000 0.020000 3.220000 ( 2.913442)
|
228
|
+
|
122
229
|
## Thanks
|
123
230
|
|
124
231
|
Special thanks go out to the [pycrc](http://www.tty1.net/pycrc/) library
|
@@ -40,27 +40,29 @@ static const crc12_t crc12_table[256] = {
|
|
40
40
|
|
41
41
|
crc12_t crc_reflect(crc12_t data, size_t data_len)
|
42
42
|
{
|
43
|
-
|
44
|
-
|
43
|
+
unsigned int i;
|
44
|
+
crc12_t ret = data & 0x01;
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
return ret;
|
52
|
-
}
|
46
|
+
for (i = 1; i < data_len; i++)
|
47
|
+
{
|
48
|
+
data >>= 1;
|
49
|
+
ret = (ret << 1) | (data & 0x01);
|
50
|
+
}
|
53
51
|
|
52
|
+
return ret;
|
53
|
+
}
|
54
54
|
|
55
55
|
crc12_t crc12_3gpp_update(crc12_t crc, const void *data, size_t data_len)
|
56
56
|
{
|
57
|
-
|
58
|
-
|
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
|
+
}
|
59
66
|
|
60
|
-
|
61
|
-
tbl_idx = ((crc >> 4) ^ *d) & 0xff;
|
62
|
-
crc = (crc12_table[tbl_idx] ^ (crc << 8)) & 0xfff;
|
63
|
-
d++;
|
64
|
-
}
|
65
|
-
return crc & 0xfff;
|
67
|
+
return crc & 0xfff;
|
66
68
|
}
|
data/ext/digest/crc15/crc15.c
CHANGED
@@ -38,16 +38,17 @@ static const crc15_t crc15_table[256] = {
|
|
38
38
|
0x276f, 0x62f6, 0x69c4, 0x2c5d, 0x7fa0, 0x3a39, 0x310b, 0x7492, 0x5368, 0x16f1, 0x1dc3, 0x585a, 0x0ba7, 0x4e3e, 0x450c, 0x0095
|
39
39
|
};
|
40
40
|
|
41
|
-
|
42
41
|
crc15_t crc15_update(crc15_t crc, const void *data, size_t data_len)
|
43
42
|
{
|
44
|
-
|
45
|
-
|
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
|
+
}
|
46
52
|
|
47
|
-
|
48
|
-
tbl_idx = ((crc >> 7) ^ *d) & 0xff;
|
49
|
-
crc = (crc15_table[tbl_idx] ^ (crc << 8)) & 0x7fff;
|
50
|
-
d++;
|
51
|
-
}
|
52
|
-
return crc & 0x7fff;
|
53
|
+
return crc & 0x7fff;
|
53
54
|
}
|
data/ext/digest/crc16/crc16.c
CHANGED
@@ -20,50 +20,51 @@
|
|
20
20
|
* Static table used for the table_driven implementation.
|
21
21
|
*/
|
22
22
|
static const crc16_t crc16_table[256] = {
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
55
|
};
|
56
56
|
|
57
|
-
|
58
57
|
crc16_t crc16_update(crc16_t crc, const void *data, size_t data_len)
|
59
58
|
{
|
60
|
-
|
61
|
-
|
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
|
+
}
|
62
68
|
|
63
|
-
|
64
|
-
tbl_idx = (crc ^ *d) & 0xff;
|
65
|
-
crc = (crc16_table[tbl_idx] ^ (crc >> 8)) & 0xffff;
|
66
|
-
d++;
|
67
|
-
}
|
68
|
-
return crc & 0xffff;
|
69
|
+
return crc & 0xffff;
|
69
70
|
}
|
@@ -20,50 +20,51 @@
|
|
20
20
|
* Static table used for the table_driven implementation.
|
21
21
|
*/
|
22
22
|
static const crc16_t crc16_ccitt_table[256] = {
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
55
|
};
|
56
56
|
|
57
|
-
|
58
57
|
crc16_t crc16_ccitt_update(crc16_t crc, const void *data, size_t data_len)
|
59
58
|
{
|
60
|
-
|
61
|
-
|
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
|
+
}
|
62
68
|
|
63
|
-
|
64
|
-
tbl_idx = ((crc >> 8) ^ *d) & 0xff;
|
65
|
-
crc = (crc16_ccitt_table[tbl_idx] ^ (crc << 8)) & 0xffff;
|
66
|
-
d++;
|
67
|
-
}
|
68
|
-
return crc & 0xffff;
|
69
|
+
return crc & 0xffff;
|
69
70
|
}
|
@@ -4,50 +4,51 @@
|
|
4
4
|
* Static table used for the table_driven implementation.
|
5
5
|
*/
|
6
6
|
static const crc16_t crc16_dnp_table[256] = {
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
39
|
};
|
40
40
|
|
41
|
-
|
42
41
|
crc16_t crc16_dnp_update(crc16_t crc, const void *data, size_t data_len)
|
43
42
|
{
|
44
|
-
|
45
|
-
|
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
|
+
}
|
46
52
|
|
47
|
-
|
48
|
-
tbl_idx = (crc ^ *d) & 0xff;
|
49
|
-
crc = (crc << 8) ^ crc16_dnp_table[tbl_idx];
|
50
|
-
d++;
|
51
|
-
}
|
52
|
-
return crc & 0xffff;
|
53
|
+
return crc & 0xffff;
|
53
54
|
}
|