authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-27 09:32:09+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-27 09:32:09+02:00
log1581601ffa1fe36f579c81fb5c774f99dbc20942
tree6162a3381e6ad392bb7d7fa2a125a03cc5f79783
parent8f7febfa6f5900e64bee1636c2bbc13bd5a52bd6
parent072534bb2ab27addea2c8ffa2574e5c267b9de44

Merge pull request 'std.hash.crc: full namespace audit' (#35952) from crc-namespace into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/35952

10 files changed, 738 insertions(+), 693 deletions(-)

lib/std/compress/xz/Decompress.zig+2-2
...@@ -2,8 +2,8 @@ const Decompress = @This();...@@ -2,8 +2,8 @@ const Decompress = @This();
2const std = @import("../../std.zig");2const std = @import("../../std.zig");
3const Allocator = std.mem.Allocator;3const Allocator = std.mem.Allocator;
4const ArrayList = std.ArrayList;4const ArrayList = std.ArrayList;
5const Crc32 = std.hash.Crc32;5const Crc32 = std.hash.crc.@"CRC-32/ISO-HDLC";
6const Crc64 = std.hash.crc.Crc64Xz;6const Crc64 = std.hash.crc.@"CRC-64/XZ";
7const Sha256 = std.crypto.hash.sha2.Sha256;7const Sha256 = std.crypto.hash.sha2.Sha256;
8const lzma2 = std.compress.lzma2;8const lzma2 = std.compress.lzma2;
9const Writer = std.Io.Writer;9const Writer = std.Io.Writer;
lib/std/debug/ElfFile.zig+1-1
...@@ -455,7 +455,7 @@ fn loadInner(...@@ -455,7 +455,7 @@ fn loadInner(
455 };455 };
456456
457 if (opt_crc) |crc| {457 if (opt_crc) |crc| {
458 if (std.hash.crc.Crc32.hash(mapped_mem) != crc) {458 if (std.hash.Crc32.hash(mapped_mem) != crc) {
459 return error.CrcMismatch;459 return error.CrcMismatch;
460 }460 }
461 }461 }
lib/std/hash.zig+1-2
...@@ -5,9 +5,8 @@ pub const autoHash = auto_hash.autoHash;...@@ -5,9 +5,8 @@ pub const autoHash = auto_hash.autoHash;
5pub const autoHashStrat = auto_hash.hash;5pub const autoHashStrat = auto_hash.hash;
6pub const Strategy = auto_hash.HashStrategy;6pub const Strategy = auto_hash.HashStrategy;
77
8// pub for polynomials + generic crc32 construction
9pub const crc = @import("hash/crc.zig");8pub const crc = @import("hash/crc.zig");
10pub const Crc32 = crc.Crc32;9pub const Crc32 = crc.@"CRC-32/ISO-HDLC";
1110
12const fnv = @import("hash/fnv.zig");11const fnv = @import("hash/fnv.zig");
13pub const Fnv1a_32 = fnv.Fnv1a_32;12pub const Fnv1a_32 = fnv.Fnv1a_32;
lib/std/hash/benchmark.zig+1-1
...@@ -61,7 +61,7 @@ const hashes = [_]Hash{...@@ -61,7 +61,7 @@ const hashes = [_]Hash{
61 .init_default = true,61 .init_default = true,
62 },62 },
63 Hash{63 Hash{
64 .ty = hash.crc.Crc32,64 .ty = hash.Crc32,
65 .name = "crc32",65 .name = "crc32",
66 },66 },
67 Hash{67 Hash{
lib/std/hash/crc.zig+222-135
...@@ -1,31 +1,8 @@...@@ -1,31 +1,8 @@
1//! This file is auto-generated by tools/update_crc_catalog.zig.1//! This file is auto-generated by tools/update_crc_catalog.zig.
22
3const builtin = @import("builtin");3const builtin = @import("builtin");
4const impl = @import("crc/impl.zig");
54
6pub const Crc = impl.Crc;5pub const @"CRC-3/GSM" = Generic(u3, .{
7pub const Polynomial = impl.Polynomial;
8pub const Crc32WithPoly = impl.Crc32WithPoly;
9pub const Crc32SmallWithPoly = impl.Crc32SmallWithPoly;
10
11pub const Crc32 = Crc32IsoHdlc;
12
13test {
14 _ = @import("crc/test.zig");
15}
16
17pub const Crc32Iscsi = switch (builtin.cpu.hasAll(.x86, &.{ .@"64bit", .crc32 })) {
18 true => @import("crc/Crc32c.zig"),
19 else => Crc(u32, .{
20 .polynomial = 0x1edc6f41,
21 .initial = 0xffffffff,
22 .reflect_input = true,
23 .reflect_output = true,
24 .xor_output = 0xffffffff,
25 }),
26};
27
28pub const Crc3Gsm = Crc(u3, .{
29 .polynomial = 0x3,6 .polynomial = 0x3,
30 .initial = 0x0,7 .initial = 0x0,
31 .reflect_input = false,8 .reflect_input = false,
...@@ -33,7 +10,7 @@ pub const Crc3Gsm = Crc(u3, .{...@@ -33,7 +10,7 @@ pub const Crc3Gsm = Crc(u3, .{
33 .xor_output = 0x7,10 .xor_output = 0x7,
34});11});
3512
36pub const Crc3Rohc = Crc(u3, .{13pub const @"CRC-3/ROHC" = Generic(u3, .{
37 .polynomial = 0x3,14 .polynomial = 0x3,
38 .initial = 0x7,15 .initial = 0x7,
39 .reflect_input = true,16 .reflect_input = true,
...@@ -41,7 +18,7 @@ pub const Crc3Rohc = Crc(u3, .{...@@ -41,7 +18,7 @@ pub const Crc3Rohc = Crc(u3, .{
41 .xor_output = 0x0,18 .xor_output = 0x0,
42});19});
4320
44pub const Crc4G704 = Crc(u4, .{21pub const @"CRC-4/G-704" = Generic(u4, .{
45 .polynomial = 0x3,22 .polynomial = 0x3,
46 .initial = 0x0,23 .initial = 0x0,
47 .reflect_input = true,24 .reflect_input = true,
...@@ -49,7 +26,7 @@ pub const Crc4G704 = Crc(u4, .{...@@ -49,7 +26,7 @@ pub const Crc4G704 = Crc(u4, .{
49 .xor_output = 0x0,26 .xor_output = 0x0,
50});27});
5128
52pub const Crc4Interlaken = Crc(u4, .{29pub const @"CRC-4/INTERLAKEN" = Generic(u4, .{
53 .polynomial = 0x3,30 .polynomial = 0x3,
54 .initial = 0xf,31 .initial = 0xf,
55 .reflect_input = false,32 .reflect_input = false,
...@@ -57,7 +34,7 @@ pub const Crc4Interlaken = Crc(u4, .{...@@ -57,7 +34,7 @@ pub const Crc4Interlaken = Crc(u4, .{
57 .xor_output = 0xf,34 .xor_output = 0xf,
58});35});
5936
60pub const Crc5EpcC1g2 = Crc(u5, .{37pub const @"CRC-5/EPC-C1G2" = Generic(u5, .{
61 .polynomial = 0x09,38 .polynomial = 0x09,
62 .initial = 0x09,39 .initial = 0x09,
63 .reflect_input = false,40 .reflect_input = false,
...@@ -65,7 +42,7 @@ pub const Crc5EpcC1g2 = Crc(u5, .{...@@ -65,7 +42,7 @@ pub const Crc5EpcC1g2 = Crc(u5, .{
65 .xor_output = 0x00,42 .xor_output = 0x00,
66});43});
6744
68pub const Crc5G704 = Crc(u5, .{45pub const @"CRC-5/G-704" = Generic(u5, .{
69 .polynomial = 0x15,46 .polynomial = 0x15,
70 .initial = 0x00,47 .initial = 0x00,
71 .reflect_input = true,48 .reflect_input = true,
...@@ -73,7 +50,7 @@ pub const Crc5G704 = Crc(u5, .{...@@ -73,7 +50,7 @@ pub const Crc5G704 = Crc(u5, .{
73 .xor_output = 0x00,50 .xor_output = 0x00,
74});51});
7552
76pub const Crc5Usb = Crc(u5, .{53pub const @"CRC-5/USB" = Generic(u5, .{
77 .polynomial = 0x05,54 .polynomial = 0x05,
78 .initial = 0x1f,55 .initial = 0x1f,
79 .reflect_input = true,56 .reflect_input = true,
...@@ -81,7 +58,7 @@ pub const Crc5Usb = Crc(u5, .{...@@ -81,7 +58,7 @@ pub const Crc5Usb = Crc(u5, .{
81 .xor_output = 0x1f,58 .xor_output = 0x1f,
82});59});
8360
84pub const Crc6Cdma2000A = Crc(u6, .{61pub const @"CRC-6/CDMA2000-A" = Generic(u6, .{
85 .polynomial = 0x27,62 .polynomial = 0x27,
86 .initial = 0x3f,63 .initial = 0x3f,
87 .reflect_input = false,64 .reflect_input = false,
...@@ -89,7 +66,7 @@ pub const Crc6Cdma2000A = Crc(u6, .{...@@ -89,7 +66,7 @@ pub const Crc6Cdma2000A = Crc(u6, .{
89 .xor_output = 0x00,66 .xor_output = 0x00,
90});67});
9168
92pub const Crc6Cdma2000B = Crc(u6, .{69pub const @"CRC-6/CDMA2000-B" = Generic(u6, .{
93 .polynomial = 0x07,70 .polynomial = 0x07,
94 .initial = 0x3f,71 .initial = 0x3f,
95 .reflect_input = false,72 .reflect_input = false,
...@@ -97,7 +74,7 @@ pub const Crc6Cdma2000B = Crc(u6, .{...@@ -97,7 +74,7 @@ pub const Crc6Cdma2000B = Crc(u6, .{
97 .xor_output = 0x00,74 .xor_output = 0x00,
98});75});
9976
100pub const Crc6Darc = Crc(u6, .{77pub const @"CRC-6/DARC" = Generic(u6, .{
101 .polynomial = 0x19,78 .polynomial = 0x19,
102 .initial = 0x00,79 .initial = 0x00,
103 .reflect_input = true,80 .reflect_input = true,
...@@ -105,7 +82,7 @@ pub const Crc6Darc = Crc(u6, .{...@@ -105,7 +82,7 @@ pub const Crc6Darc = Crc(u6, .{
105 .xor_output = 0x00,82 .xor_output = 0x00,
106});83});
10784
108pub const Crc6G704 = Crc(u6, .{85pub const @"CRC-6/G-704" = Generic(u6, .{
109 .polynomial = 0x03,86 .polynomial = 0x03,
110 .initial = 0x00,87 .initial = 0x00,
111 .reflect_input = true,88 .reflect_input = true,
...@@ -113,7 +90,7 @@ pub const Crc6G704 = Crc(u6, .{...@@ -113,7 +90,7 @@ pub const Crc6G704 = Crc(u6, .{
113 .xor_output = 0x00,90 .xor_output = 0x00,
114});91});
11592
116pub const Crc6Gsm = Crc(u6, .{93pub const @"CRC-6/GSM" = Generic(u6, .{
117 .polynomial = 0x2f,94 .polynomial = 0x2f,
118 .initial = 0x00,95 .initial = 0x00,
119 .reflect_input = false,96 .reflect_input = false,
...@@ -121,7 +98,7 @@ pub const Crc6Gsm = Crc(u6, .{...@@ -121,7 +98,7 @@ pub const Crc6Gsm = Crc(u6, .{
121 .xor_output = 0x3f,98 .xor_output = 0x3f,
122});99});
123100
124pub const Crc7Mmc = Crc(u7, .{101pub const @"CRC-7/MMC" = Generic(u7, .{
125 .polynomial = 0x09,102 .polynomial = 0x09,
126 .initial = 0x00,103 .initial = 0x00,
127 .reflect_input = false,104 .reflect_input = false,
...@@ -129,7 +106,7 @@ pub const Crc7Mmc = Crc(u7, .{...@@ -129,7 +106,7 @@ pub const Crc7Mmc = Crc(u7, .{
129 .xor_output = 0x00,106 .xor_output = 0x00,
130});107});
131108
132pub const Crc7Rohc = Crc(u7, .{109pub const @"CRC-7/ROHC" = Generic(u7, .{
133 .polynomial = 0x4f,110 .polynomial = 0x4f,
134 .initial = 0x7f,111 .initial = 0x7f,
135 .reflect_input = true,112 .reflect_input = true,
...@@ -137,7 +114,7 @@ pub const Crc7Rohc = Crc(u7, .{...@@ -137,7 +114,7 @@ pub const Crc7Rohc = Crc(u7, .{
137 .xor_output = 0x00,114 .xor_output = 0x00,
138});115});
139116
140pub const Crc7Umts = Crc(u7, .{117pub const @"CRC-7/UMTS" = Generic(u7, .{
141 .polynomial = 0x45,118 .polynomial = 0x45,
142 .initial = 0x00,119 .initial = 0x00,
143 .reflect_input = false,120 .reflect_input = false,
...@@ -145,7 +122,7 @@ pub const Crc7Umts = Crc(u7, .{...@@ -145,7 +122,7 @@ pub const Crc7Umts = Crc(u7, .{
145 .xor_output = 0x00,122 .xor_output = 0x00,
146});123});
147124
148pub const Crc8Autosar = Crc(u8, .{125pub const @"CRC-8/AUTOSAR" = Generic(u8, .{
149 .polynomial = 0x2f,126 .polynomial = 0x2f,
150 .initial = 0xff,127 .initial = 0xff,
151 .reflect_input = false,128 .reflect_input = false,
...@@ -153,7 +130,7 @@ pub const Crc8Autosar = Crc(u8, .{...@@ -153,7 +130,7 @@ pub const Crc8Autosar = Crc(u8, .{
153 .xor_output = 0xff,130 .xor_output = 0xff,
154});131});
155132
156pub const Crc8Bluetooth = Crc(u8, .{133pub const @"CRC-8/BLUETOOTH" = Generic(u8, .{
157 .polynomial = 0xa7,134 .polynomial = 0xa7,
158 .initial = 0x00,135 .initial = 0x00,
159 .reflect_input = true,136 .reflect_input = true,
...@@ -161,7 +138,7 @@ pub const Crc8Bluetooth = Crc(u8, .{...@@ -161,7 +138,7 @@ pub const Crc8Bluetooth = Crc(u8, .{
161 .xor_output = 0x00,138 .xor_output = 0x00,
162});139});
163140
164pub const Crc8Cdma2000 = Crc(u8, .{141pub const @"CRC-8/CDMA2000" = Generic(u8, .{
165 .polynomial = 0x9b,142 .polynomial = 0x9b,
166 .initial = 0xff,143 .initial = 0xff,
167 .reflect_input = false,144 .reflect_input = false,
...@@ -169,7 +146,7 @@ pub const Crc8Cdma2000 = Crc(u8, .{...@@ -169,7 +146,7 @@ pub const Crc8Cdma2000 = Crc(u8, .{
169 .xor_output = 0x00,146 .xor_output = 0x00,
170});147});
171148
172pub const Crc8Darc = Crc(u8, .{149pub const @"CRC-8/DARC" = Generic(u8, .{
173 .polynomial = 0x39,150 .polynomial = 0x39,
174 .initial = 0x00,151 .initial = 0x00,
175 .reflect_input = true,152 .reflect_input = true,
...@@ -177,7 +154,7 @@ pub const Crc8Darc = Crc(u8, .{...@@ -177,7 +154,7 @@ pub const Crc8Darc = Crc(u8, .{
177 .xor_output = 0x00,154 .xor_output = 0x00,
178});155});
179156
180pub const Crc8DvbS2 = Crc(u8, .{157pub const @"CRC-8/DVB-S2" = Generic(u8, .{
181 .polynomial = 0xd5,158 .polynomial = 0xd5,
182 .initial = 0x00,159 .initial = 0x00,
183 .reflect_input = false,160 .reflect_input = false,
...@@ -185,7 +162,7 @@ pub const Crc8DvbS2 = Crc(u8, .{...@@ -185,7 +162,7 @@ pub const Crc8DvbS2 = Crc(u8, .{
185 .xor_output = 0x00,162 .xor_output = 0x00,
186});163});
187164
188pub const Crc8GsmA = Crc(u8, .{165pub const @"CRC-8/GSM-A" = Generic(u8, .{
189 .polynomial = 0x1d,166 .polynomial = 0x1d,
190 .initial = 0x00,167 .initial = 0x00,
191 .reflect_input = false,168 .reflect_input = false,
...@@ -193,7 +170,7 @@ pub const Crc8GsmA = Crc(u8, .{...@@ -193,7 +170,7 @@ pub const Crc8GsmA = Crc(u8, .{
193 .xor_output = 0x00,170 .xor_output = 0x00,
194});171});
195172
196pub const Crc8GsmB = Crc(u8, .{173pub const @"CRC-8/GSM-B" = Generic(u8, .{
197 .polynomial = 0x49,174 .polynomial = 0x49,
198 .initial = 0x00,175 .initial = 0x00,
199 .reflect_input = false,176 .reflect_input = false,
...@@ -201,7 +178,7 @@ pub const Crc8GsmB = Crc(u8, .{...@@ -201,7 +178,7 @@ pub const Crc8GsmB = Crc(u8, .{
201 .xor_output = 0xff,178 .xor_output = 0xff,
202});179});
203180
204pub const Crc8Hitag = Crc(u8, .{181pub const @"CRC-8/HITAG" = Generic(u8, .{
205 .polynomial = 0x1d,182 .polynomial = 0x1d,
206 .initial = 0xff,183 .initial = 0xff,
207 .reflect_input = false,184 .reflect_input = false,
...@@ -209,7 +186,7 @@ pub const Crc8Hitag = Crc(u8, .{...@@ -209,7 +186,7 @@ pub const Crc8Hitag = Crc(u8, .{
209 .xor_output = 0x00,186 .xor_output = 0x00,
210});187});
211188
212pub const Crc8I4321 = Crc(u8, .{189pub const @"CRC-8/I-432-1" = Generic(u8, .{
213 .polynomial = 0x07,190 .polynomial = 0x07,
214 .initial = 0x00,191 .initial = 0x00,
215 .reflect_input = false,192 .reflect_input = false,
...@@ -217,7 +194,7 @@ pub const Crc8I4321 = Crc(u8, .{...@@ -217,7 +194,7 @@ pub const Crc8I4321 = Crc(u8, .{
217 .xor_output = 0x55,194 .xor_output = 0x55,
218});195});
219196
220pub const Crc8ICode = Crc(u8, .{197pub const @"CRC-8/I-CODE" = Generic(u8, .{
221 .polynomial = 0x1d,198 .polynomial = 0x1d,
222 .initial = 0xfd,199 .initial = 0xfd,
223 .reflect_input = false,200 .reflect_input = false,
...@@ -225,7 +202,7 @@ pub const Crc8ICode = Crc(u8, .{...@@ -225,7 +202,7 @@ pub const Crc8ICode = Crc(u8, .{
225 .xor_output = 0x00,202 .xor_output = 0x00,
226});203});
227204
228pub const Crc8Lte = Crc(u8, .{205pub const @"CRC-8/LTE" = Generic(u8, .{
229 .polynomial = 0x9b,206 .polynomial = 0x9b,
230 .initial = 0x00,207 .initial = 0x00,
231 .reflect_input = false,208 .reflect_input = false,
...@@ -233,7 +210,7 @@ pub const Crc8Lte = Crc(u8, .{...@@ -233,7 +210,7 @@ pub const Crc8Lte = Crc(u8, .{
233 .xor_output = 0x00,210 .xor_output = 0x00,
234});211});
235212
236pub const Crc8MaximDow = Crc(u8, .{213pub const @"CRC-8/MAXIM-DOW" = Generic(u8, .{
237 .polynomial = 0x31,214 .polynomial = 0x31,
238 .initial = 0x00,215 .initial = 0x00,
239 .reflect_input = true,216 .reflect_input = true,
...@@ -241,7 +218,7 @@ pub const Crc8MaximDow = Crc(u8, .{...@@ -241,7 +218,7 @@ pub const Crc8MaximDow = Crc(u8, .{
241 .xor_output = 0x00,218 .xor_output = 0x00,
242});219});
243220
244pub const Crc8MifareMad = Crc(u8, .{221pub const @"CRC-8/MIFARE-MAD" = Generic(u8, .{
245 .polynomial = 0x1d,222 .polynomial = 0x1d,
246 .initial = 0xc7,223 .initial = 0xc7,
247 .reflect_input = false,224 .reflect_input = false,
...@@ -249,7 +226,7 @@ pub const Crc8MifareMad = Crc(u8, .{...@@ -249,7 +226,7 @@ pub const Crc8MifareMad = Crc(u8, .{
249 .xor_output = 0x00,226 .xor_output = 0x00,
250});227});
251228
252pub const Crc8Nrsc5 = Crc(u8, .{229pub const @"CRC-8/NRSC-5" = Generic(u8, .{
253 .polynomial = 0x31,230 .polynomial = 0x31,
254 .initial = 0xff,231 .initial = 0xff,
255 .reflect_input = false,232 .reflect_input = false,
...@@ -257,7 +234,7 @@ pub const Crc8Nrsc5 = Crc(u8, .{...@@ -257,7 +234,7 @@ pub const Crc8Nrsc5 = Crc(u8, .{
257 .xor_output = 0x00,234 .xor_output = 0x00,
258});235});
259236
260pub const Crc8Opensafety = Crc(u8, .{237pub const @"CRC-8/OPENSAFETY" = Generic(u8, .{
261 .polynomial = 0x2f,238 .polynomial = 0x2f,
262 .initial = 0x00,239 .initial = 0x00,
263 .reflect_input = false,240 .reflect_input = false,
...@@ -265,7 +242,7 @@ pub const Crc8Opensafety = Crc(u8, .{...@@ -265,7 +242,7 @@ pub const Crc8Opensafety = Crc(u8, .{
265 .xor_output = 0x00,242 .xor_output = 0x00,
266});243});
267244
268pub const Crc8Rohc = Crc(u8, .{245pub const @"CRC-8/ROHC" = Generic(u8, .{
269 .polynomial = 0x07,246 .polynomial = 0x07,
270 .initial = 0xff,247 .initial = 0xff,
271 .reflect_input = true,248 .reflect_input = true,
...@@ -273,7 +250,7 @@ pub const Crc8Rohc = Crc(u8, .{...@@ -273,7 +250,7 @@ pub const Crc8Rohc = Crc(u8, .{
273 .xor_output = 0x00,250 .xor_output = 0x00,
274});251});
275252
276pub const Crc8SaeJ1850 = Crc(u8, .{253pub const @"CRC-8/SAE-J1850" = Generic(u8, .{
277 .polynomial = 0x1d,254 .polynomial = 0x1d,
278 .initial = 0xff,255 .initial = 0xff,
279 .reflect_input = false,256 .reflect_input = false,
...@@ -281,7 +258,7 @@ pub const Crc8SaeJ1850 = Crc(u8, .{...@@ -281,7 +258,7 @@ pub const Crc8SaeJ1850 = Crc(u8, .{
281 .xor_output = 0xff,258 .xor_output = 0xff,
282});259});
283260
284pub const Crc8Smbus = Crc(u8, .{261pub const @"CRC-8/SMBUS" = Generic(u8, .{
285 .polynomial = 0x07,262 .polynomial = 0x07,
286 .initial = 0x00,263 .initial = 0x00,
287 .reflect_input = false,264 .reflect_input = false,
...@@ -289,7 +266,7 @@ pub const Crc8Smbus = Crc(u8, .{...@@ -289,7 +266,7 @@ pub const Crc8Smbus = Crc(u8, .{
289 .xor_output = 0x00,266 .xor_output = 0x00,
290});267});
291268
292pub const Crc8Tech3250 = Crc(u8, .{269pub const @"CRC-8/TECH-3250" = Generic(u8, .{
293 .polynomial = 0x1d,270 .polynomial = 0x1d,
294 .initial = 0xff,271 .initial = 0xff,
295 .reflect_input = true,272 .reflect_input = true,
...@@ -297,7 +274,7 @@ pub const Crc8Tech3250 = Crc(u8, .{...@@ -297,7 +274,7 @@ pub const Crc8Tech3250 = Crc(u8, .{
297 .xor_output = 0x00,274 .xor_output = 0x00,
298});275});
299276
300pub const Crc8Wcdma = Crc(u8, .{277pub const @"CRC-8/WCDMA" = Generic(u8, .{
301 .polynomial = 0x9b,278 .polynomial = 0x9b,
302 .initial = 0x00,279 .initial = 0x00,
303 .reflect_input = true,280 .reflect_input = true,
...@@ -305,7 +282,7 @@ pub const Crc8Wcdma = Crc(u8, .{...@@ -305,7 +282,7 @@ pub const Crc8Wcdma = Crc(u8, .{
305 .xor_output = 0x00,282 .xor_output = 0x00,
306});283});
307284
308pub const Crc10Atm = Crc(u10, .{285pub const @"CRC-10/ATM" = Generic(u10, .{
309 .polynomial = 0x233,286 .polynomial = 0x233,
310 .initial = 0x000,287 .initial = 0x000,
311 .reflect_input = false,288 .reflect_input = false,
...@@ -313,7 +290,7 @@ pub const Crc10Atm = Crc(u10, .{...@@ -313,7 +290,7 @@ pub const Crc10Atm = Crc(u10, .{
313 .xor_output = 0x000,290 .xor_output = 0x000,
314});291});
315292
316pub const Crc10Cdma2000 = Crc(u10, .{293pub const @"CRC-10/CDMA2000" = Generic(u10, .{
317 .polynomial = 0x3d9,294 .polynomial = 0x3d9,
318 .initial = 0x3ff,295 .initial = 0x3ff,
319 .reflect_input = false,296 .reflect_input = false,
...@@ -321,7 +298,7 @@ pub const Crc10Cdma2000 = Crc(u10, .{...@@ -321,7 +298,7 @@ pub const Crc10Cdma2000 = Crc(u10, .{
321 .xor_output = 0x000,298 .xor_output = 0x000,
322});299});
323300
324pub const Crc10Gsm = Crc(u10, .{301pub const @"CRC-10/GSM" = Generic(u10, .{
325 .polynomial = 0x175,302 .polynomial = 0x175,
326 .initial = 0x000,303 .initial = 0x000,
327 .reflect_input = false,304 .reflect_input = false,
...@@ -329,7 +306,7 @@ pub const Crc10Gsm = Crc(u10, .{...@@ -329,7 +306,7 @@ pub const Crc10Gsm = Crc(u10, .{
329 .xor_output = 0x3ff,306 .xor_output = 0x3ff,
330});307});
331308
332pub const Crc11Flexray = Crc(u11, .{309pub const @"CRC-11/FLEXRAY" = Generic(u11, .{
333 .polynomial = 0x385,310 .polynomial = 0x385,
334 .initial = 0x01a,311 .initial = 0x01a,
335 .reflect_input = false,312 .reflect_input = false,
...@@ -337,7 +314,7 @@ pub const Crc11Flexray = Crc(u11, .{...@@ -337,7 +314,7 @@ pub const Crc11Flexray = Crc(u11, .{
337 .xor_output = 0x000,314 .xor_output = 0x000,
338});315});
339316
340pub const Crc11Umts = Crc(u11, .{317pub const @"CRC-11/UMTS" = Generic(u11, .{
341 .polynomial = 0x307,318 .polynomial = 0x307,
342 .initial = 0x000,319 .initial = 0x000,
343 .reflect_input = false,320 .reflect_input = false,
...@@ -345,7 +322,7 @@ pub const Crc11Umts = Crc(u11, .{...@@ -345,7 +322,7 @@ pub const Crc11Umts = Crc(u11, .{
345 .xor_output = 0x000,322 .xor_output = 0x000,
346});323});
347324
348pub const Crc12Cdma2000 = Crc(u12, .{325pub const @"CRC-12/CDMA2000" = Generic(u12, .{
349 .polynomial = 0xf13,326 .polynomial = 0xf13,
350 .initial = 0xfff,327 .initial = 0xfff,
351 .reflect_input = false,328 .reflect_input = false,
...@@ -353,7 +330,7 @@ pub const Crc12Cdma2000 = Crc(u12, .{...@@ -353,7 +330,7 @@ pub const Crc12Cdma2000 = Crc(u12, .{
353 .xor_output = 0x000,330 .xor_output = 0x000,
354});331});
355332
356pub const Crc12Dect = Crc(u12, .{333pub const @"CRC-12/DECT" = Generic(u12, .{
357 .polynomial = 0x80f,334 .polynomial = 0x80f,
358 .initial = 0x000,335 .initial = 0x000,
359 .reflect_input = false,336 .reflect_input = false,
...@@ -361,7 +338,7 @@ pub const Crc12Dect = Crc(u12, .{...@@ -361,7 +338,7 @@ pub const Crc12Dect = Crc(u12, .{
361 .xor_output = 0x000,338 .xor_output = 0x000,
362});339});
363340
364pub const Crc12Gsm = Crc(u12, .{341pub const @"CRC-12/GSM" = Generic(u12, .{
365 .polynomial = 0xd31,342 .polynomial = 0xd31,
366 .initial = 0x000,343 .initial = 0x000,
367 .reflect_input = false,344 .reflect_input = false,
...@@ -369,7 +346,7 @@ pub const Crc12Gsm = Crc(u12, .{...@@ -369,7 +346,7 @@ pub const Crc12Gsm = Crc(u12, .{
369 .xor_output = 0xfff,346 .xor_output = 0xfff,
370});347});
371348
372pub const Crc12Umts = Crc(u12, .{349pub const @"CRC-12/UMTS" = Generic(u12, .{
373 .polynomial = 0x80f,350 .polynomial = 0x80f,
374 .initial = 0x000,351 .initial = 0x000,
375 .reflect_input = false,352 .reflect_input = false,
...@@ -377,7 +354,7 @@ pub const Crc12Umts = Crc(u12, .{...@@ -377,7 +354,7 @@ pub const Crc12Umts = Crc(u12, .{
377 .xor_output = 0x000,354 .xor_output = 0x000,
378});355});
379356
380pub const Crc13Bbc = Crc(u13, .{357pub const @"CRC-13/BBC" = Generic(u13, .{
381 .polynomial = 0x1cf5,358 .polynomial = 0x1cf5,
382 .initial = 0x0000,359 .initial = 0x0000,
383 .reflect_input = false,360 .reflect_input = false,
...@@ -385,7 +362,7 @@ pub const Crc13Bbc = Crc(u13, .{...@@ -385,7 +362,7 @@ pub const Crc13Bbc = Crc(u13, .{
385 .xor_output = 0x0000,362 .xor_output = 0x0000,
386});363});
387364
388pub const Crc14Darc = Crc(u14, .{365pub const @"CRC-14/DARC" = Generic(u14, .{
389 .polynomial = 0x0805,366 .polynomial = 0x0805,
390 .initial = 0x0000,367 .initial = 0x0000,
391 .reflect_input = true,368 .reflect_input = true,
...@@ -393,7 +370,7 @@ pub const Crc14Darc = Crc(u14, .{...@@ -393,7 +370,7 @@ pub const Crc14Darc = Crc(u14, .{
393 .xor_output = 0x0000,370 .xor_output = 0x0000,
394});371});
395372
396pub const Crc14Gsm = Crc(u14, .{373pub const @"CRC-14/GSM" = Generic(u14, .{
397 .polynomial = 0x202d,374 .polynomial = 0x202d,
398 .initial = 0x0000,375 .initial = 0x0000,
399 .reflect_input = false,376 .reflect_input = false,
...@@ -401,7 +378,7 @@ pub const Crc14Gsm = Crc(u14, .{...@@ -401,7 +378,7 @@ pub const Crc14Gsm = Crc(u14, .{
401 .xor_output = 0x3fff,378 .xor_output = 0x3fff,
402});379});
403380
404pub const Crc15Can = Crc(u15, .{381pub const @"CRC-15/CAN" = Generic(u15, .{
405 .polynomial = 0x4599,382 .polynomial = 0x4599,
406 .initial = 0x0000,383 .initial = 0x0000,
407 .reflect_input = false,384 .reflect_input = false,
...@@ -409,7 +386,7 @@ pub const Crc15Can = Crc(u15, .{...@@ -409,7 +386,7 @@ pub const Crc15Can = Crc(u15, .{
409 .xor_output = 0x0000,386 .xor_output = 0x0000,
410});387});
411388
412pub const Crc15Mpt1327 = Crc(u15, .{389pub const @"CRC-15/MPT1327" = Generic(u15, .{
413 .polynomial = 0x6815,390 .polynomial = 0x6815,
414 .initial = 0x0000,391 .initial = 0x0000,
415 .reflect_input = false,392 .reflect_input = false,
...@@ -417,7 +394,7 @@ pub const Crc15Mpt1327 = Crc(u15, .{...@@ -417,7 +394,7 @@ pub const Crc15Mpt1327 = Crc(u15, .{
417 .xor_output = 0x0001,394 .xor_output = 0x0001,
418});395});
419396
420pub const Crc16Arc = Crc(u16, .{397pub const @"CRC-16/ARC" = Generic(u16, .{
421 .polynomial = 0x8005,398 .polynomial = 0x8005,
422 .initial = 0x0000,399 .initial = 0x0000,
423 .reflect_input = true,400 .reflect_input = true,
...@@ -425,7 +402,7 @@ pub const Crc16Arc = Crc(u16, .{...@@ -425,7 +402,7 @@ pub const Crc16Arc = Crc(u16, .{
425 .xor_output = 0x0000,402 .xor_output = 0x0000,
426});403});
427404
428pub const Crc16Cdma2000 = Crc(u16, .{405pub const @"CRC-16/CDMA2000" = Generic(u16, .{
429 .polynomial = 0xc867,406 .polynomial = 0xc867,
430 .initial = 0xffff,407 .initial = 0xffff,
431 .reflect_input = false,408 .reflect_input = false,
...@@ -433,7 +410,7 @@ pub const Crc16Cdma2000 = Crc(u16, .{...@@ -433,7 +410,7 @@ pub const Crc16Cdma2000 = Crc(u16, .{
433 .xor_output = 0x0000,410 .xor_output = 0x0000,
434});411});
435412
436pub const Crc16Cms = Crc(u16, .{413pub const @"CRC-16/CMS" = Generic(u16, .{
437 .polynomial = 0x8005,414 .polynomial = 0x8005,
438 .initial = 0xffff,415 .initial = 0xffff,
439 .reflect_input = false,416 .reflect_input = false,
...@@ -441,7 +418,7 @@ pub const Crc16Cms = Crc(u16, .{...@@ -441,7 +418,7 @@ pub const Crc16Cms = Crc(u16, .{
441 .xor_output = 0x0000,418 .xor_output = 0x0000,
442});419});
443420
444pub const Crc16Dds110 = Crc(u16, .{421pub const @"CRC-16/DDS-110" = Generic(u16, .{
445 .polynomial = 0x8005,422 .polynomial = 0x8005,
446 .initial = 0x800d,423 .initial = 0x800d,
447 .reflect_input = false,424 .reflect_input = false,
...@@ -449,7 +426,7 @@ pub const Crc16Dds110 = Crc(u16, .{...@@ -449,7 +426,7 @@ pub const Crc16Dds110 = Crc(u16, .{
449 .xor_output = 0x0000,426 .xor_output = 0x0000,
450});427});
451428
452pub const Crc16DectR = Crc(u16, .{429pub const @"CRC-16/DECT-R" = Generic(u16, .{
453 .polynomial = 0x0589,430 .polynomial = 0x0589,
454 .initial = 0x0000,431 .initial = 0x0000,
455 .reflect_input = false,432 .reflect_input = false,
...@@ -457,7 +434,7 @@ pub const Crc16DectR = Crc(u16, .{...@@ -457,7 +434,7 @@ pub const Crc16DectR = Crc(u16, .{
457 .xor_output = 0x0001,434 .xor_output = 0x0001,
458});435});
459436
460pub const Crc16DectX = Crc(u16, .{437pub const @"CRC-16/DECT-X" = Generic(u16, .{
461 .polynomial = 0x0589,438 .polynomial = 0x0589,
462 .initial = 0x0000,439 .initial = 0x0000,
463 .reflect_input = false,440 .reflect_input = false,
...@@ -465,7 +442,7 @@ pub const Crc16DectX = Crc(u16, .{...@@ -465,7 +442,7 @@ pub const Crc16DectX = Crc(u16, .{
465 .xor_output = 0x0000,442 .xor_output = 0x0000,
466});443});
467444
468pub const Crc16Dnp = Crc(u16, .{445pub const @"CRC-16/DNP" = Generic(u16, .{
469 .polynomial = 0x3d65,446 .polynomial = 0x3d65,
470 .initial = 0x0000,447 .initial = 0x0000,
471 .reflect_input = true,448 .reflect_input = true,
...@@ -473,7 +450,7 @@ pub const Crc16Dnp = Crc(u16, .{...@@ -473,7 +450,7 @@ pub const Crc16Dnp = Crc(u16, .{
473 .xor_output = 0xffff,450 .xor_output = 0xffff,
474});451});
475452
476pub const Crc16En13757 = Crc(u16, .{453pub const @"CRC-16/EN-13757" = Generic(u16, .{
477 .polynomial = 0x3d65,454 .polynomial = 0x3d65,
478 .initial = 0x0000,455 .initial = 0x0000,
479 .reflect_input = false,456 .reflect_input = false,
...@@ -481,7 +458,7 @@ pub const Crc16En13757 = Crc(u16, .{...@@ -481,7 +458,7 @@ pub const Crc16En13757 = Crc(u16, .{
481 .xor_output = 0xffff,458 .xor_output = 0xffff,
482});459});
483460
484pub const Crc16Genibus = Crc(u16, .{461pub const @"CRC-16/GENIBUS" = Generic(u16, .{
485 .polynomial = 0x1021,462 .polynomial = 0x1021,
486 .initial = 0xffff,463 .initial = 0xffff,
487 .reflect_input = false,464 .reflect_input = false,
...@@ -489,7 +466,7 @@ pub const Crc16Genibus = Crc(u16, .{...@@ -489,7 +466,7 @@ pub const Crc16Genibus = Crc(u16, .{
489 .xor_output = 0xffff,466 .xor_output = 0xffff,
490});467});
491468
492pub const Crc16Gsm = Crc(u16, .{469pub const @"CRC-16/GSM" = Generic(u16, .{
493 .polynomial = 0x1021,470 .polynomial = 0x1021,
494 .initial = 0x0000,471 .initial = 0x0000,
495 .reflect_input = false,472 .reflect_input = false,
...@@ -497,7 +474,7 @@ pub const Crc16Gsm = Crc(u16, .{...@@ -497,7 +474,7 @@ pub const Crc16Gsm = Crc(u16, .{
497 .xor_output = 0xffff,474 .xor_output = 0xffff,
498});475});
499476
500pub const Crc16Ibm3740 = Crc(u16, .{477pub const @"CRC-16/IBM-3740" = Generic(u16, .{
501 .polynomial = 0x1021,478 .polynomial = 0x1021,
502 .initial = 0xffff,479 .initial = 0xffff,
503 .reflect_input = false,480 .reflect_input = false,
...@@ -505,7 +482,7 @@ pub const Crc16Ibm3740 = Crc(u16, .{...@@ -505,7 +482,7 @@ pub const Crc16Ibm3740 = Crc(u16, .{
505 .xor_output = 0x0000,482 .xor_output = 0x0000,
506});483});
507484
508pub const Crc16IbmSdlc = Crc(u16, .{485pub const @"CRC-16/IBM-SDLC" = Generic(u16, .{
509 .polynomial = 0x1021,486 .polynomial = 0x1021,
510 .initial = 0xffff,487 .initial = 0xffff,
511 .reflect_input = true,488 .reflect_input = true,
...@@ -513,7 +490,7 @@ pub const Crc16IbmSdlc = Crc(u16, .{...@@ -513,7 +490,7 @@ pub const Crc16IbmSdlc = Crc(u16, .{
513 .xor_output = 0xffff,490 .xor_output = 0xffff,
514});491});
515492
516pub const Crc16IsoIec144433A = Crc(u16, .{493pub const @"CRC-16/ISO-IEC-14443-3-A" = Generic(u16, .{
517 .polynomial = 0x1021,494 .polynomial = 0x1021,
518 .initial = 0xc6c6,495 .initial = 0xc6c6,
519 .reflect_input = true,496 .reflect_input = true,
...@@ -521,7 +498,7 @@ pub const Crc16IsoIec144433A = Crc(u16, .{...@@ -521,7 +498,7 @@ pub const Crc16IsoIec144433A = Crc(u16, .{
521 .xor_output = 0x0000,498 .xor_output = 0x0000,
522});499});
523500
524pub const Crc16Kermit = Crc(u16, .{501pub const @"CRC-16/KERMIT" = Generic(u16, .{
525 .polynomial = 0x1021,502 .polynomial = 0x1021,
526 .initial = 0x0000,503 .initial = 0x0000,
527 .reflect_input = true,504 .reflect_input = true,
...@@ -529,7 +506,7 @@ pub const Crc16Kermit = Crc(u16, .{...@@ -529,7 +506,7 @@ pub const Crc16Kermit = Crc(u16, .{
529 .xor_output = 0x0000,506 .xor_output = 0x0000,
530});507});
531508
532pub const Crc16Lj1200 = Crc(u16, .{509pub const @"CRC-16/LJ1200" = Generic(u16, .{
533 .polynomial = 0x6f63,510 .polynomial = 0x6f63,
534 .initial = 0x0000,511 .initial = 0x0000,
535 .reflect_input = false,512 .reflect_input = false,
...@@ -537,7 +514,7 @@ pub const Crc16Lj1200 = Crc(u16, .{...@@ -537,7 +514,7 @@ pub const Crc16Lj1200 = Crc(u16, .{
537 .xor_output = 0x0000,514 .xor_output = 0x0000,
538});515});
539516
540pub const Crc16M17 = Crc(u16, .{517pub const @"CRC-16/M17" = Generic(u16, .{
541 .polynomial = 0x5935,518 .polynomial = 0x5935,
542 .initial = 0xffff,519 .initial = 0xffff,
543 .reflect_input = false,520 .reflect_input = false,
...@@ -545,7 +522,7 @@ pub const Crc16M17 = Crc(u16, .{...@@ -545,7 +522,7 @@ pub const Crc16M17 = Crc(u16, .{
545 .xor_output = 0x0000,522 .xor_output = 0x0000,
546});523});
547524
548pub const Crc16MaximDow = Crc(u16, .{525pub const @"CRC-16/MAXIM-DOW" = Generic(u16, .{
549 .polynomial = 0x8005,526 .polynomial = 0x8005,
550 .initial = 0x0000,527 .initial = 0x0000,
551 .reflect_input = true,528 .reflect_input = true,
...@@ -553,7 +530,7 @@ pub const Crc16MaximDow = Crc(u16, .{...@@ -553,7 +530,7 @@ pub const Crc16MaximDow = Crc(u16, .{
553 .xor_output = 0xffff,530 .xor_output = 0xffff,
554});531});
555532
556pub const Crc16Mcrf4xx = Crc(u16, .{533pub const @"CRC-16/MCRF4XX" = Generic(u16, .{
557 .polynomial = 0x1021,534 .polynomial = 0x1021,
558 .initial = 0xffff,535 .initial = 0xffff,
559 .reflect_input = true,536 .reflect_input = true,
...@@ -561,7 +538,7 @@ pub const Crc16Mcrf4xx = Crc(u16, .{...@@ -561,7 +538,7 @@ pub const Crc16Mcrf4xx = Crc(u16, .{
561 .xor_output = 0x0000,538 .xor_output = 0x0000,
562});539});
563540
564pub const Crc16Modbus = Crc(u16, .{541pub const @"CRC-16/MODBUS" = Generic(u16, .{
565 .polynomial = 0x8005,542 .polynomial = 0x8005,
566 .initial = 0xffff,543 .initial = 0xffff,
567 .reflect_input = true,544 .reflect_input = true,
...@@ -569,7 +546,7 @@ pub const Crc16Modbus = Crc(u16, .{...@@ -569,7 +546,7 @@ pub const Crc16Modbus = Crc(u16, .{
569 .xor_output = 0x0000,546 .xor_output = 0x0000,
570});547});
571548
572pub const Crc16Nrsc5 = Crc(u16, .{549pub const @"CRC-16/NRSC-5" = Generic(u16, .{
573 .polynomial = 0x080b,550 .polynomial = 0x080b,
574 .initial = 0xffff,551 .initial = 0xffff,
575 .reflect_input = true,552 .reflect_input = true,
...@@ -577,7 +554,7 @@ pub const Crc16Nrsc5 = Crc(u16, .{...@@ -577,7 +554,7 @@ pub const Crc16Nrsc5 = Crc(u16, .{
577 .xor_output = 0x0000,554 .xor_output = 0x0000,
578});555});
579556
580pub const Crc16OpensafetyA = Crc(u16, .{557pub const @"CRC-16/OPENSAFETY-A" = Generic(u16, .{
581 .polynomial = 0x5935,558 .polynomial = 0x5935,
582 .initial = 0x0000,559 .initial = 0x0000,
583 .reflect_input = false,560 .reflect_input = false,
...@@ -585,7 +562,7 @@ pub const Crc16OpensafetyA = Crc(u16, .{...@@ -585,7 +562,7 @@ pub const Crc16OpensafetyA = Crc(u16, .{
585 .xor_output = 0x0000,562 .xor_output = 0x0000,
586});563});
587564
588pub const Crc16OpensafetyB = Crc(u16, .{565pub const @"CRC-16/OPENSAFETY-B" = Generic(u16, .{
589 .polynomial = 0x755b,566 .polynomial = 0x755b,
590 .initial = 0x0000,567 .initial = 0x0000,
591 .reflect_input = false,568 .reflect_input = false,
...@@ -593,7 +570,7 @@ pub const Crc16OpensafetyB = Crc(u16, .{...@@ -593,7 +570,7 @@ pub const Crc16OpensafetyB = Crc(u16, .{
593 .xor_output = 0x0000,570 .xor_output = 0x0000,
594});571});
595572
596pub const Crc16Profibus = Crc(u16, .{573pub const @"CRC-16/PROFIBUS" = Generic(u16, .{
597 .polynomial = 0x1dcf,574 .polynomial = 0x1dcf,
598 .initial = 0xffff,575 .initial = 0xffff,
599 .reflect_input = false,576 .reflect_input = false,
...@@ -601,7 +578,7 @@ pub const Crc16Profibus = Crc(u16, .{...@@ -601,7 +578,7 @@ pub const Crc16Profibus = Crc(u16, .{
601 .xor_output = 0xffff,578 .xor_output = 0xffff,
602});579});
603580
604pub const Crc16Riello = Crc(u16, .{581pub const @"CRC-16/RIELLO" = Generic(u16, .{
605 .polynomial = 0x1021,582 .polynomial = 0x1021,
606 .initial = 0xb2aa,583 .initial = 0xb2aa,
607 .reflect_input = true,584 .reflect_input = true,
...@@ -609,7 +586,7 @@ pub const Crc16Riello = Crc(u16, .{...@@ -609,7 +586,7 @@ pub const Crc16Riello = Crc(u16, .{
609 .xor_output = 0x0000,586 .xor_output = 0x0000,
610});587});
611588
612pub const Crc16SpiFujitsu = Crc(u16, .{589pub const @"CRC-16/SPI-FUJITSU" = Generic(u16, .{
613 .polynomial = 0x1021,590 .polynomial = 0x1021,
614 .initial = 0x1d0f,591 .initial = 0x1d0f,
615 .reflect_input = false,592 .reflect_input = false,
...@@ -617,7 +594,7 @@ pub const Crc16SpiFujitsu = Crc(u16, .{...@@ -617,7 +594,7 @@ pub const Crc16SpiFujitsu = Crc(u16, .{
617 .xor_output = 0x0000,594 .xor_output = 0x0000,
618});595});
619596
620pub const Crc16T10Dif = Crc(u16, .{597pub const @"CRC-16/T10-DIF" = Generic(u16, .{
621 .polynomial = 0x8bb7,598 .polynomial = 0x8bb7,
622 .initial = 0x0000,599 .initial = 0x0000,
623 .reflect_input = false,600 .reflect_input = false,
...@@ -625,7 +602,7 @@ pub const Crc16T10Dif = Crc(u16, .{...@@ -625,7 +602,7 @@ pub const Crc16T10Dif = Crc(u16, .{
625 .xor_output = 0x0000,602 .xor_output = 0x0000,
626});603});
627604
628pub const Crc16Teledisk = Crc(u16, .{605pub const @"CRC-16/TELEDISK" = Generic(u16, .{
629 .polynomial = 0xa097,606 .polynomial = 0xa097,
630 .initial = 0x0000,607 .initial = 0x0000,
631 .reflect_input = false,608 .reflect_input = false,
...@@ -633,7 +610,7 @@ pub const Crc16Teledisk = Crc(u16, .{...@@ -633,7 +610,7 @@ pub const Crc16Teledisk = Crc(u16, .{
633 .xor_output = 0x0000,610 .xor_output = 0x0000,
634});611});
635612
636pub const Crc16Tms37157 = Crc(u16, .{613pub const @"CRC-16/TMS37157" = Generic(u16, .{
637 .polynomial = 0x1021,614 .polynomial = 0x1021,
638 .initial = 0x89ec,615 .initial = 0x89ec,
639 .reflect_input = true,616 .reflect_input = true,
...@@ -641,7 +618,7 @@ pub const Crc16Tms37157 = Crc(u16, .{...@@ -641,7 +618,7 @@ pub const Crc16Tms37157 = Crc(u16, .{
641 .xor_output = 0x0000,618 .xor_output = 0x0000,
642});619});
643620
644pub const Crc16Umts = Crc(u16, .{621pub const @"CRC-16/UMTS" = Generic(u16, .{
645 .polynomial = 0x8005,622 .polynomial = 0x8005,
646 .initial = 0x0000,623 .initial = 0x0000,
647 .reflect_input = false,624 .reflect_input = false,
...@@ -649,7 +626,7 @@ pub const Crc16Umts = Crc(u16, .{...@@ -649,7 +626,7 @@ pub const Crc16Umts = Crc(u16, .{
649 .xor_output = 0x0000,626 .xor_output = 0x0000,
650});627});
651628
652pub const Crc16Usb = Crc(u16, .{629pub const @"CRC-16/USB" = Generic(u16, .{
653 .polynomial = 0x8005,630 .polynomial = 0x8005,
654 .initial = 0xffff,631 .initial = 0xffff,
655 .reflect_input = true,632 .reflect_input = true,
...@@ -657,7 +634,7 @@ pub const Crc16Usb = Crc(u16, .{...@@ -657,7 +634,7 @@ pub const Crc16Usb = Crc(u16, .{
657 .xor_output = 0xffff,634 .xor_output = 0xffff,
658});635});
659636
660pub const Crc16Xmodem = Crc(u16, .{637pub const @"CRC-16/XMODEM" = Generic(u16, .{
661 .polynomial = 0x1021,638 .polynomial = 0x1021,
662 .initial = 0x0000,639 .initial = 0x0000,
663 .reflect_input = false,640 .reflect_input = false,
...@@ -665,7 +642,7 @@ pub const Crc16Xmodem = Crc(u16, .{...@@ -665,7 +642,7 @@ pub const Crc16Xmodem = Crc(u16, .{
665 .xor_output = 0x0000,642 .xor_output = 0x0000,
666});643});
667644
668pub const Crc17CanFd = Crc(u17, .{645pub const @"CRC-17/CAN-FD" = Generic(u17, .{
669 .polynomial = 0x1685b,646 .polynomial = 0x1685b,
670 .initial = 0x00000,647 .initial = 0x00000,
671 .reflect_input = false,648 .reflect_input = false,
...@@ -673,7 +650,7 @@ pub const Crc17CanFd = Crc(u17, .{...@@ -673,7 +650,7 @@ pub const Crc17CanFd = Crc(u17, .{
673 .xor_output = 0x00000,650 .xor_output = 0x00000,
674});651});
675652
676pub const Crc21CanFd = Crc(u21, .{653pub const @"CRC-21/CAN-FD" = Generic(u21, .{
677 .polynomial = 0x102899,654 .polynomial = 0x102899,
678 .initial = 0x000000,655 .initial = 0x000000,
679 .reflect_input = false,656 .reflect_input = false,
...@@ -681,7 +658,7 @@ pub const Crc21CanFd = Crc(u21, .{...@@ -681,7 +658,7 @@ pub const Crc21CanFd = Crc(u21, .{
681 .xor_output = 0x000000,658 .xor_output = 0x000000,
682});659});
683660
684pub const Crc24Ble = Crc(u24, .{661pub const @"CRC-24/BLE" = Generic(u24, .{
685 .polynomial = 0x00065b,662 .polynomial = 0x00065b,
686 .initial = 0x555555,663 .initial = 0x555555,
687 .reflect_input = true,664 .reflect_input = true,
...@@ -689,7 +666,7 @@ pub const Crc24Ble = Crc(u24, .{...@@ -689,7 +666,7 @@ pub const Crc24Ble = Crc(u24, .{
689 .xor_output = 0x000000,666 .xor_output = 0x000000,
690});667});
691668
692pub const Crc24FlexrayA = Crc(u24, .{669pub const @"CRC-24/FLEXRAY-A" = Generic(u24, .{
693 .polynomial = 0x5d6dcb,670 .polynomial = 0x5d6dcb,
694 .initial = 0xfedcba,671 .initial = 0xfedcba,
695 .reflect_input = false,672 .reflect_input = false,
...@@ -697,7 +674,7 @@ pub const Crc24FlexrayA = Crc(u24, .{...@@ -697,7 +674,7 @@ pub const Crc24FlexrayA = Crc(u24, .{
697 .xor_output = 0x000000,674 .xor_output = 0x000000,
698});675});
699676
700pub const Crc24FlexrayB = Crc(u24, .{677pub const @"CRC-24/FLEXRAY-B" = Generic(u24, .{
701 .polynomial = 0x5d6dcb,678 .polynomial = 0x5d6dcb,
702 .initial = 0xabcdef,679 .initial = 0xabcdef,
703 .reflect_input = false,680 .reflect_input = false,
...@@ -705,7 +682,7 @@ pub const Crc24FlexrayB = Crc(u24, .{...@@ -705,7 +682,7 @@ pub const Crc24FlexrayB = Crc(u24, .{
705 .xor_output = 0x000000,682 .xor_output = 0x000000,
706});683});
707684
708pub const Crc24Interlaken = Crc(u24, .{685pub const @"CRC-24/INTERLAKEN" = Generic(u24, .{
709 .polynomial = 0x328b63,686 .polynomial = 0x328b63,
710 .initial = 0xffffff,687 .initial = 0xffffff,
711 .reflect_input = false,688 .reflect_input = false,
...@@ -713,7 +690,7 @@ pub const Crc24Interlaken = Crc(u24, .{...@@ -713,7 +690,7 @@ pub const Crc24Interlaken = Crc(u24, .{
713 .xor_output = 0xffffff,690 .xor_output = 0xffffff,
714});691});
715692
716pub const Crc24LteA = Crc(u24, .{693pub const @"CRC-24/LTE-A" = Generic(u24, .{
717 .polynomial = 0x864cfb,694 .polynomial = 0x864cfb,
718 .initial = 0x000000,695 .initial = 0x000000,
719 .reflect_input = false,696 .reflect_input = false,
...@@ -721,7 +698,7 @@ pub const Crc24LteA = Crc(u24, .{...@@ -721,7 +698,7 @@ pub const Crc24LteA = Crc(u24, .{
721 .xor_output = 0x000000,698 .xor_output = 0x000000,
722});699});
723700
724pub const Crc24LteB = Crc(u24, .{701pub const @"CRC-24/LTE-B" = Generic(u24, .{
725 .polynomial = 0x800063,702 .polynomial = 0x800063,
726 .initial = 0x000000,703 .initial = 0x000000,
727 .reflect_input = false,704 .reflect_input = false,
...@@ -729,7 +706,7 @@ pub const Crc24LteB = Crc(u24, .{...@@ -729,7 +706,7 @@ pub const Crc24LteB = Crc(u24, .{
729 .xor_output = 0x000000,706 .xor_output = 0x000000,
730});707});
731708
732pub const Crc24Openpgp = Crc(u24, .{709pub const @"CRC-24/OPENPGP" = Generic(u24, .{
733 .polynomial = 0x864cfb,710 .polynomial = 0x864cfb,
734 .initial = 0xb704ce,711 .initial = 0xb704ce,
735 .reflect_input = false,712 .reflect_input = false,
...@@ -737,7 +714,7 @@ pub const Crc24Openpgp = Crc(u24, .{...@@ -737,7 +714,7 @@ pub const Crc24Openpgp = Crc(u24, .{
737 .xor_output = 0x000000,714 .xor_output = 0x000000,
738});715});
739716
740pub const Crc24Os9 = Crc(u24, .{717pub const @"CRC-24/OS-9" = Generic(u24, .{
741 .polynomial = 0x800063,718 .polynomial = 0x800063,
742 .initial = 0xffffff,719 .initial = 0xffffff,
743 .reflect_input = false,720 .reflect_input = false,
...@@ -745,7 +722,7 @@ pub const Crc24Os9 = Crc(u24, .{...@@ -745,7 +722,7 @@ pub const Crc24Os9 = Crc(u24, .{
745 .xor_output = 0xffffff,722 .xor_output = 0xffffff,
746});723});
747724
748pub const Crc30Cdma = Crc(u30, .{725pub const @"CRC-30/CDMA" = Generic(u30, .{
749 .polynomial = 0x2030b9c7,726 .polynomial = 0x2030b9c7,
750 .initial = 0x3fffffff,727 .initial = 0x3fffffff,
751 .reflect_input = false,728 .reflect_input = false,
...@@ -753,7 +730,7 @@ pub const Crc30Cdma = Crc(u30, .{...@@ -753,7 +730,7 @@ pub const Crc30Cdma = Crc(u30, .{
753 .xor_output = 0x3fffffff,730 .xor_output = 0x3fffffff,
754});731});
755732
756pub const Crc31Philips = Crc(u31, .{733pub const @"CRC-31/PHILIPS" = Generic(u31, .{
757 .polynomial = 0x04c11db7,734 .polynomial = 0x04c11db7,
758 .initial = 0x7fffffff,735 .initial = 0x7fffffff,
759 .reflect_input = false,736 .reflect_input = false,
...@@ -761,7 +738,7 @@ pub const Crc31Philips = Crc(u31, .{...@@ -761,7 +738,7 @@ pub const Crc31Philips = Crc(u31, .{
761 .xor_output = 0x7fffffff,738 .xor_output = 0x7fffffff,
762});739});
763740
764pub const Crc32Aixm = Crc(u32, .{741pub const @"CRC-32/AIXM" = Generic(u32, .{
765 .polynomial = 0x814141ab,742 .polynomial = 0x814141ab,
766 .initial = 0x00000000,743 .initial = 0x00000000,
767 .reflect_input = false,744 .reflect_input = false,
...@@ -769,7 +746,7 @@ pub const Crc32Aixm = Crc(u32, .{...@@ -769,7 +746,7 @@ pub const Crc32Aixm = Crc(u32, .{
769 .xor_output = 0x00000000,746 .xor_output = 0x00000000,
770});747});
771748
772pub const Crc32Autosar = Crc(u32, .{749pub const @"CRC-32/AUTOSAR" = Generic(u32, .{
773 .polynomial = 0xf4acfb13,750 .polynomial = 0xf4acfb13,
774 .initial = 0xffffffff,751 .initial = 0xffffffff,
775 .reflect_input = true,752 .reflect_input = true,
...@@ -777,7 +754,7 @@ pub const Crc32Autosar = Crc(u32, .{...@@ -777,7 +754,7 @@ pub const Crc32Autosar = Crc(u32, .{
777 .xor_output = 0xffffffff,754 .xor_output = 0xffffffff,
778});755});
779756
780pub const Crc32Base91D = Crc(u32, .{757pub const @"CRC-32/BASE91-D" = Generic(u32, .{
781 .polynomial = 0xa833982b,758 .polynomial = 0xa833982b,
782 .initial = 0xffffffff,759 .initial = 0xffffffff,
783 .reflect_input = true,760 .reflect_input = true,
...@@ -785,7 +762,7 @@ pub const Crc32Base91D = Crc(u32, .{...@@ -785,7 +762,7 @@ pub const Crc32Base91D = Crc(u32, .{
785 .xor_output = 0xffffffff,762 .xor_output = 0xffffffff,
786});763});
787764
788pub const Crc32Bzip2 = Crc(u32, .{765pub const @"CRC-32/BZIP2" = Generic(u32, .{
789 .polynomial = 0x04c11db7,766 .polynomial = 0x04c11db7,
790 .initial = 0xffffffff,767 .initial = 0xffffffff,
791 .reflect_input = false,768 .reflect_input = false,
...@@ -793,7 +770,7 @@ pub const Crc32Bzip2 = Crc(u32, .{...@@ -793,7 +770,7 @@ pub const Crc32Bzip2 = Crc(u32, .{
793 .xor_output = 0xffffffff,770 .xor_output = 0xffffffff,
794});771});
795772
796pub const Crc32CdRomEdc = Crc(u32, .{773pub const @"CRC-32/CD-ROM-EDC" = Generic(u32, .{
797 .polynomial = 0x8001801b,774 .polynomial = 0x8001801b,
798 .initial = 0x00000000,775 .initial = 0x00000000,
799 .reflect_input = true,776 .reflect_input = true,
...@@ -801,7 +778,7 @@ pub const Crc32CdRomEdc = Crc(u32, .{...@@ -801,7 +778,7 @@ pub const Crc32CdRomEdc = Crc(u32, .{
801 .xor_output = 0x00000000,778 .xor_output = 0x00000000,
802});779});
803780
804pub const Crc32Cksum = Crc(u32, .{781pub const @"CRC-32/CKSUM" = Generic(u32, .{
805 .polynomial = 0x04c11db7,782 .polynomial = 0x04c11db7,
806 .initial = 0x00000000,783 .initial = 0x00000000,
807 .reflect_input = false,784 .reflect_input = false,
...@@ -809,7 +786,18 @@ pub const Crc32Cksum = Crc(u32, .{...@@ -809,7 +786,18 @@ pub const Crc32Cksum = Crc(u32, .{
809 .xor_output = 0xffffffff,786 .xor_output = 0xffffffff,
810});787});
811788
812pub const Crc32IsoHdlc = Crc(u32, .{789pub const @"CRC-32/ISCSI" = if (builtin.cpu.hasAll(.x86, &.{ .@"64bit", .crc32 }))
790 @import("crc/Crc32c.zig")
791else
792 Generic(u32, .{
793 .polynomial = 0x1edc6f41,
794 .initial = 0xffffffff,
795 .reflect_input = true,
796 .reflect_output = true,
797 .xor_output = 0xffffffff,
798 });
799
800pub const @"CRC-32/ISO-HDLC" = Generic(u32, .{
813 .polynomial = 0x04c11db7,801 .polynomial = 0x04c11db7,
814 .initial = 0xffffffff,802 .initial = 0xffffffff,
815 .reflect_input = true,803 .reflect_input = true,
...@@ -817,7 +805,7 @@ pub const Crc32IsoHdlc = Crc(u32, .{...@@ -817,7 +805,7 @@ pub const Crc32IsoHdlc = Crc(u32, .{
817 .xor_output = 0xffffffff,805 .xor_output = 0xffffffff,
818});806});
819807
820pub const Crc32Jamcrc = Crc(u32, .{808pub const @"CRC-32/JAMCRC" = Generic(u32, .{
821 .polynomial = 0x04c11db7,809 .polynomial = 0x04c11db7,
822 .initial = 0xffffffff,810 .initial = 0xffffffff,
823 .reflect_input = true,811 .reflect_input = true,
...@@ -825,7 +813,7 @@ pub const Crc32Jamcrc = Crc(u32, .{...@@ -825,7 +813,7 @@ pub const Crc32Jamcrc = Crc(u32, .{
825 .xor_output = 0x00000000,813 .xor_output = 0x00000000,
826});814});
827815
828pub const Crc32Koopman = Crc(u32, .{816pub const @"CRC-32/KOOPMAN" = Generic(u32, .{
829 .polynomial = 0x741b8cd7,817 .polynomial = 0x741b8cd7,
830 .initial = 0xffffffff,818 .initial = 0xffffffff,
831 .reflect_input = true,819 .reflect_input = true,
...@@ -833,7 +821,7 @@ pub const Crc32Koopman = Crc(u32, .{...@@ -833,7 +821,7 @@ pub const Crc32Koopman = Crc(u32, .{
833 .xor_output = 0xffffffff,821 .xor_output = 0xffffffff,
834});822});
835823
836pub const Crc32Mef = Crc(u32, .{824pub const @"CRC-32/MEF" = Generic(u32, .{
837 .polynomial = 0x741b8cd7,825 .polynomial = 0x741b8cd7,
838 .initial = 0xffffffff,826 .initial = 0xffffffff,
839 .reflect_input = true,827 .reflect_input = true,
...@@ -841,7 +829,7 @@ pub const Crc32Mef = Crc(u32, .{...@@ -841,7 +829,7 @@ pub const Crc32Mef = Crc(u32, .{
841 .xor_output = 0x00000000,829 .xor_output = 0x00000000,
842});830});
843831
844pub const Crc32Mpeg2 = Crc(u32, .{832pub const @"CRC-32/MPEG-2" = Generic(u32, .{
845 .polynomial = 0x04c11db7,833 .polynomial = 0x04c11db7,
846 .initial = 0xffffffff,834 .initial = 0xffffffff,
847 .reflect_input = false,835 .reflect_input = false,
...@@ -849,7 +837,7 @@ pub const Crc32Mpeg2 = Crc(u32, .{...@@ -849,7 +837,7 @@ pub const Crc32Mpeg2 = Crc(u32, .{
849 .xor_output = 0x00000000,837 .xor_output = 0x00000000,
850});838});
851839
852pub const Crc32Xfer = Crc(u32, .{840pub const @"CRC-32/XFER" = Generic(u32, .{
853 .polynomial = 0x000000af,841 .polynomial = 0x000000af,
854 .initial = 0x00000000,842 .initial = 0x00000000,
855 .reflect_input = false,843 .reflect_input = false,
...@@ -857,7 +845,7 @@ pub const Crc32Xfer = Crc(u32, .{...@@ -857,7 +845,7 @@ pub const Crc32Xfer = Crc(u32, .{
857 .xor_output = 0x00000000,845 .xor_output = 0x00000000,
858});846});
859847
860pub const Crc40Gsm = Crc(u40, .{848pub const @"CRC-40/GSM" = Generic(u40, .{
861 .polynomial = 0x0004820009,849 .polynomial = 0x0004820009,
862 .initial = 0x0000000000,850 .initial = 0x0000000000,
863 .reflect_input = false,851 .reflect_input = false,
...@@ -865,7 +853,7 @@ pub const Crc40Gsm = Crc(u40, .{...@@ -865,7 +853,7 @@ pub const Crc40Gsm = Crc(u40, .{
865 .xor_output = 0xffffffffff,853 .xor_output = 0xffffffffff,
866});854});
867855
868pub const Crc64Ecma182 = Crc(u64, .{856pub const @"CRC-64/ECMA-182" = Generic(u64, .{
869 .polynomial = 0x42f0e1eba9ea3693,857 .polynomial = 0x42f0e1eba9ea3693,
870 .initial = 0x0000000000000000,858 .initial = 0x0000000000000000,
871 .reflect_input = false,859 .reflect_input = false,
...@@ -873,7 +861,7 @@ pub const Crc64Ecma182 = Crc(u64, .{...@@ -873,7 +861,7 @@ pub const Crc64Ecma182 = Crc(u64, .{
873 .xor_output = 0x0000000000000000,861 .xor_output = 0x0000000000000000,
874});862});
875863
876pub const Crc64GoIso = Crc(u64, .{864pub const @"CRC-64/GO-ISO" = Generic(u64, .{
877 .polynomial = 0x000000000000001b,865 .polynomial = 0x000000000000001b,
878 .initial = 0xffffffffffffffff,866 .initial = 0xffffffffffffffff,
879 .reflect_input = true,867 .reflect_input = true,
...@@ -881,7 +869,7 @@ pub const Crc64GoIso = Crc(u64, .{...@@ -881,7 +869,7 @@ pub const Crc64GoIso = Crc(u64, .{
881 .xor_output = 0xffffffffffffffff,869 .xor_output = 0xffffffffffffffff,
882});870});
883871
884pub const Crc64Ms = Crc(u64, .{872pub const @"CRC-64/MS" = Generic(u64, .{
885 .polynomial = 0x259c84cba6426349,873 .polynomial = 0x259c84cba6426349,
886 .initial = 0xffffffffffffffff,874 .initial = 0xffffffffffffffff,
887 .reflect_input = true,875 .reflect_input = true,
...@@ -889,7 +877,7 @@ pub const Crc64Ms = Crc(u64, .{...@@ -889,7 +877,7 @@ pub const Crc64Ms = Crc(u64, .{
889 .xor_output = 0x0000000000000000,877 .xor_output = 0x0000000000000000,
890});878});
891879
892pub const Crc64Redis = Crc(u64, .{880pub const @"CRC-64/REDIS" = Generic(u64, .{
893 .polynomial = 0xad93d23594c935a9,881 .polynomial = 0xad93d23594c935a9,
894 .initial = 0x0000000000000000,882 .initial = 0x0000000000000000,
895 .reflect_input = true,883 .reflect_input = true,
...@@ -897,7 +885,7 @@ pub const Crc64Redis = Crc(u64, .{...@@ -897,7 +885,7 @@ pub const Crc64Redis = Crc(u64, .{
897 .xor_output = 0x0000000000000000,885 .xor_output = 0x0000000000000000,
898});886});
899887
900pub const Crc64We = Crc(u64, .{888pub const @"CRC-64/WE" = Generic(u64, .{
901 .polynomial = 0x42f0e1eba9ea3693,889 .polynomial = 0x42f0e1eba9ea3693,
902 .initial = 0xffffffffffffffff,890 .initial = 0xffffffffffffffff,
903 .reflect_input = false,891 .reflect_input = false,
...@@ -905,7 +893,7 @@ pub const Crc64We = Crc(u64, .{...@@ -905,7 +893,7 @@ pub const Crc64We = Crc(u64, .{
905 .xor_output = 0xffffffffffffffff,893 .xor_output = 0xffffffffffffffff,
906});894});
907895
908pub const Crc64Xz = Crc(u64, .{896pub const @"CRC-64/XZ" = Generic(u64, .{
909 .polynomial = 0x42f0e1eba9ea3693,897 .polynomial = 0x42f0e1eba9ea3693,
910 .initial = 0xffffffffffffffff,898 .initial = 0xffffffffffffffff,
911 .reflect_input = true,899 .reflect_input = true,
...@@ -913,10 +901,109 @@ pub const Crc64Xz = Crc(u64, .{...@@ -913,10 +901,109 @@ pub const Crc64Xz = Crc(u64, .{
913 .xor_output = 0xffffffffffffffff,901 .xor_output = 0xffffffffffffffff,
914});902});
915903
916pub const Crc82Darc = Crc(u82, .{904pub const @"CRC-82/DARC" = Generic(u82, .{
917 .polynomial = 0x0308c0111011401440411,905 .polynomial = 0x0308c0111011401440411,
918 .initial = 0x000000000000000000000,906 .initial = 0x000000000000000000000,
919 .reflect_input = true,907 .reflect_input = true,
920 .reflect_output = true,908 .reflect_output = true,
921 .xor_output = 0x000000000000000000000,909 .xor_output = 0x000000000000000000000,
922});910});
911
912pub fn Algorithm(comptime W: type) type {
913 return struct {
914 polynomial: W,
915 initial: W,
916 reflect_input: bool,
917 reflect_output: bool,
918 xor_output: W,
919 };
920}
921
922pub fn Generic(comptime W: type, comptime algorithm: Algorithm(W)) type {
923 return struct {
924 const Self = @This();
925 const I = if (@bitSizeOf(W) < 8) u8 else W;
926 const lookup_table = blk: {
927 @setEvalBranchQuota(2500);
928 const poly = reflect(algorithm.polynomial);
929 var table: [256]I = undefined;
930 for (&table, 0..) |*e, i| {
931 var crc: I = i;
932 if (algorithm.reflect_input) {
933 var j: usize = 0;
934 while (j < 8) : (j += 1) {
935 crc = (crc >> 1) ^ ((crc & 1) * poly);
936 }
937 } else {
938 crc <<= @bitSizeOf(I) - 8;
939 var j: usize = 0;
940 while (j < 8) : (j += 1) {
941 crc = (crc << 1) ^ (((crc >> (@bitSizeOf(I) - 1)) & 1) * poly);
942 }
943 }
944 e.* = crc;
945 }
946 break :blk table;
947 };
948
949 crc: I,
950
951 pub fn init() Self {
952 const initial = reflect(algorithm.initial);
953 return .{ .crc = initial };
954 }
955
956 inline fn tableEntry(index: I) I {
957 const short: u8 = @truncate(index);
958 return lookup_table[short];
959 }
960
961 pub fn update(self: *Self, bytes: []const u8) void {
962 var i: usize = 0;
963 if (@bitSizeOf(I) <= 8) {
964 while (i < bytes.len) : (i += 1) {
965 self.crc = tableEntry(self.crc ^ bytes[i]);
966 }
967 } else if (algorithm.reflect_input) {
968 while (i < bytes.len) : (i += 1) {
969 const table_index = self.crc ^ bytes[i];
970 self.crc = tableEntry(table_index) ^ (self.crc >> 8);
971 }
972 } else {
973 while (i < bytes.len) : (i += 1) {
974 const table_index = (self.crc >> (@bitSizeOf(I) - 8)) ^ bytes[i];
975 self.crc = tableEntry(table_index) ^ (self.crc << 8);
976 }
977 }
978 }
979
980 pub fn final(self: Self) W {
981 var c = self.crc;
982 if (algorithm.reflect_input != algorithm.reflect_output) {
983 c = @bitReverse(c);
984 }
985 if (!algorithm.reflect_output) {
986 c >>= @bitSizeOf(I) - @bitSizeOf(W);
987 }
988 return @intCast(c ^ algorithm.xor_output);
989 }
990
991 pub fn hash(bytes: []const u8) W {
992 var c = Self.init();
993 c.update(bytes);
994 return c.final();
995 }
996
997 fn reflect(x: I) I {
998 const offset = @bitSizeOf(I) - @bitSizeOf(W);
999 if (algorithm.reflect_input)
1000 return @bitReverse(x) >> offset
1001 else
1002 return x << offset;
1003 }
1004 };
1005}
1006
1007test {
1008 _ = @import("crc/test.zig");
1009}
lib/std/hash/crc/impl.zig deleted-103
...@@ -1,103 +0,0 @@
1// There is a generic CRC implementation "Crc()" which can be parameterized via
2// the Algorithm struct for a plethora of uses.
3//
4// The primary interface for all of the standard CRC algorithms is the
5// generated file "crc.zig", which uses the implementation code here to define
6// many standard CRCs.
7
8const std = @import("std");
9
10pub fn Algorithm(comptime W: type) type {
11 return struct {
12 polynomial: W,
13 initial: W,
14 reflect_input: bool,
15 reflect_output: bool,
16 xor_output: W,
17 };
18}
19
20pub fn Crc(comptime W: type, comptime algorithm: Algorithm(W)) type {
21 return struct {
22 const Self = @This();
23 const I = if (@bitSizeOf(W) < 8) u8 else W;
24 const lookup_table = blk: {
25 @setEvalBranchQuota(2500);
26 const poly = reflect(algorithm.polynomial);
27 var table: [256]I = undefined;
28 for (&table, 0..) |*e, i| {
29 var crc: I = i;
30 if (algorithm.reflect_input) {
31 var j: usize = 0;
32 while (j < 8) : (j += 1) {
33 crc = (crc >> 1) ^ ((crc & 1) * poly);
34 }
35 } else {
36 crc <<= @bitSizeOf(I) - 8;
37 var j: usize = 0;
38 while (j < 8) : (j += 1) {
39 crc = (crc << 1) ^ (((crc >> (@bitSizeOf(I) - 1)) & 1) * poly);
40 }
41 }
42 e.* = crc;
43 }
44 break :blk table;
45 };
46
47 crc: I,
48
49 pub fn init() Self {
50 const initial = reflect(algorithm.initial);
51 return .{ .crc = initial };
52 }
53
54 inline fn tableEntry(index: I) I {
55 const short: u8 = @truncate(index);
56 return lookup_table[short];
57 }
58
59 pub fn update(self: *Self, bytes: []const u8) void {
60 var i: usize = 0;
61 if (@bitSizeOf(I) <= 8) {
62 while (i < bytes.len) : (i += 1) {
63 self.crc = tableEntry(self.crc ^ bytes[i]);
64 }
65 } else if (algorithm.reflect_input) {
66 while (i < bytes.len) : (i += 1) {
67 const table_index = self.crc ^ bytes[i];
68 self.crc = tableEntry(table_index) ^ (self.crc >> 8);
69 }
70 } else {
71 while (i < bytes.len) : (i += 1) {
72 const table_index = (self.crc >> (@bitSizeOf(I) - 8)) ^ bytes[i];
73 self.crc = tableEntry(table_index) ^ (self.crc << 8);
74 }
75 }
76 }
77
78 pub fn final(self: Self) W {
79 var c = self.crc;
80 if (algorithm.reflect_input != algorithm.reflect_output) {
81 c = @bitReverse(c);
82 }
83 if (!algorithm.reflect_output) {
84 c >>= @bitSizeOf(I) - @bitSizeOf(W);
85 }
86 return @intCast(c ^ algorithm.xor_output);
87 }
88
89 pub fn hash(bytes: []const u8) W {
90 var c = Self.init();
91 c.update(bytes);
92 return c.final();
93 }
94
95 fn reflect(x: I) I {
96 const offset = @bitSizeOf(I) - @bitSizeOf(W);
97 if (algorithm.reflect_input)
98 return @bitReverse(x) >> offset
99 else
100 return x << offset;
101 }
102 };
103}
lib/std/hash/crc/test.zig+359-359
...@@ -6,1264 +6,1264 @@ const verify = @import("../verify.zig");...@@ -6,1264 +6,1264 @@ const verify = @import("../verify.zig");
6const crc = @import("../crc.zig");6const crc = @import("../crc.zig");
77
8test "crc32 ieee regression" {8test "crc32 ieee regression" {
9 const crc32 = crc.Crc32IsoHdlc;9 const Crc = crc.@"CRC-32/ISO-HDLC";
10 try testing.expectEqual(crc32.hash(""), 0x00000000);10 try testing.expectEqual(Crc.hash(""), 0x00000000);
11 try testing.expectEqual(crc32.hash("a"), 0xe8b7be43);11 try testing.expectEqual(Crc.hash("a"), 0xe8b7be43);
12 try testing.expectEqual(crc32.hash("abc"), 0x352441c2);12 try testing.expectEqual(Crc.hash("abc"), 0x352441c2);
13}13}
1414
15test "crc32 castagnoli regression" {15test "crc32 castagnoli regression" {
16 const crc32 = crc.Crc32Iscsi;16 const Crc = crc.@"CRC-32/ISCSI";
17 try testing.expectEqual(crc32.hash(""), 0x00000000);17 try testing.expectEqual(Crc.hash(""), 0x00000000);
18 try testing.expectEqual(crc32.hash("a"), 0xc1d04330);18 try testing.expectEqual(Crc.hash("a"), 0xc1d04330);
19 try testing.expectEqual(crc32.hash("abc"), 0x364b3fb7);19 try testing.expectEqual(Crc.hash("abc"), 0x364b3fb7);
20}20}
2121
22test "crc32 koopman regression" {22test "crc32 koopman regression" {
23 const crc32 = crc.Crc32Koopman;23 const Crc = crc.@"CRC-32/KOOPMAN";
24 try testing.expectEqual(crc32.hash(""), 0x00000000);24 try testing.expectEqual(Crc.hash(""), 0x00000000);
25 try testing.expectEqual(crc32.hash("a"), 0x0da2aa8a);25 try testing.expectEqual(Crc.hash("a"), 0x0da2aa8a);
26 try testing.expectEqual(crc32.hash("abc"), 0xba2322ac);26 try testing.expectEqual(Crc.hash("abc"), 0xba2322ac);
27}
28
29test "CRC-32/ISCSI" {
30 const Crc32Iscsi = crc.Crc32Iscsi;
31
32 try testing.expectEqual(@as(u32, 0xe3069283), Crc32Iscsi.hash("123456789"));
33
34 var c = Crc32Iscsi.init();
35 c.update("1234");
36 c.update("56789");
37 try testing.expectEqual(@as(u32, 0xe3069283), c.final());
38}27}
3928
40test "CRC-3/GSM" {29test "CRC-3/GSM" {
41 const Crc3Gsm = crc.Crc3Gsm;30 const Crc = crc.@"CRC-3/GSM";
4231
43 try testing.expectEqual(@as(u3, 0x4), Crc3Gsm.hash("123456789"));32 try testing.expectEqual(@as(u3, 0x4), Crc.hash("123456789"));
4433
45 var c = Crc3Gsm.init();34 var c = Crc.init();
46 c.update("1234");35 c.update("1234");
47 c.update("56789");36 c.update("56789");
48 try testing.expectEqual(@as(u3, 0x4), c.final());37 try testing.expectEqual(@as(u3, 0x4), c.final());
49}38}
5039
51test "CRC-3/ROHC" {40test "CRC-3/ROHC" {
52 const Crc3Rohc = crc.Crc3Rohc;41 const Crc = crc.@"CRC-3/ROHC";
5342
54 try testing.expectEqual(@as(u3, 0x6), Crc3Rohc.hash("123456789"));43 try testing.expectEqual(@as(u3, 0x6), Crc.hash("123456789"));
5544
56 var c = Crc3Rohc.init();45 var c = Crc.init();
57 c.update("1234");46 c.update("1234");
58 c.update("56789");47 c.update("56789");
59 try testing.expectEqual(@as(u3, 0x6), c.final());48 try testing.expectEqual(@as(u3, 0x6), c.final());
60}49}
6150
62test "CRC-4/G-704" {51test "CRC-4/G-704" {
63 const Crc4G704 = crc.Crc4G704;52 const Crc = crc.@"CRC-4/G-704";
6453
65 try testing.expectEqual(@as(u4, 0x7), Crc4G704.hash("123456789"));54 try testing.expectEqual(@as(u4, 0x7), Crc.hash("123456789"));
6655
67 var c = Crc4G704.init();56 var c = Crc.init();
68 c.update("1234");57 c.update("1234");
69 c.update("56789");58 c.update("56789");
70 try testing.expectEqual(@as(u4, 0x7), c.final());59 try testing.expectEqual(@as(u4, 0x7), c.final());
71}60}
7261
73test "CRC-4/INTERLAKEN" {62test "CRC-4/INTERLAKEN" {
74 const Crc4Interlaken = crc.Crc4Interlaken;63 const Crc = crc.@"CRC-4/INTERLAKEN";
7564
76 try testing.expectEqual(@as(u4, 0xb), Crc4Interlaken.hash("123456789"));65 try testing.expectEqual(@as(u4, 0xb), Crc.hash("123456789"));
7766
78 var c = Crc4Interlaken.init();67 var c = Crc.init();
79 c.update("1234");68 c.update("1234");
80 c.update("56789");69 c.update("56789");
81 try testing.expectEqual(@as(u4, 0xb), c.final());70 try testing.expectEqual(@as(u4, 0xb), c.final());
82}71}
8372
84test "CRC-5/EPC-C1G2" {73test "CRC-5/EPC-C1G2" {
85 const Crc5EpcC1g2 = crc.Crc5EpcC1g2;74 const Crc = crc.@"CRC-5/EPC-C1G2";
8675
87 try testing.expectEqual(@as(u5, 0x00), Crc5EpcC1g2.hash("123456789"));76 try testing.expectEqual(@as(u5, 0x00), Crc.hash("123456789"));
8877
89 var c = Crc5EpcC1g2.init();78 var c = Crc.init();
90 c.update("1234");79 c.update("1234");
91 c.update("56789");80 c.update("56789");
92 try testing.expectEqual(@as(u5, 0x00), c.final());81 try testing.expectEqual(@as(u5, 0x00), c.final());
93}82}
9483
95test "CRC-5/G-704" {84test "CRC-5/G-704" {
96 const Crc5G704 = crc.Crc5G704;85 const Crc = crc.@"CRC-5/G-704";
9786
98 try testing.expectEqual(@as(u5, 0x07), Crc5G704.hash("123456789"));87 try testing.expectEqual(@as(u5, 0x07), Crc.hash("123456789"));
9988
100 var c = Crc5G704.init();89 var c = Crc.init();
101 c.update("1234");90 c.update("1234");
102 c.update("56789");91 c.update("56789");
103 try testing.expectEqual(@as(u5, 0x07), c.final());92 try testing.expectEqual(@as(u5, 0x07), c.final());
104}93}
10594
106test "CRC-5/USB" {95test "CRC-5/USB" {
107 const Crc5Usb = crc.Crc5Usb;96 const Crc = crc.@"CRC-5/USB";
10897
109 try testing.expectEqual(@as(u5, 0x19), Crc5Usb.hash("123456789"));98 try testing.expectEqual(@as(u5, 0x19), Crc.hash("123456789"));
11099
111 var c = Crc5Usb.init();100 var c = Crc.init();
112 c.update("1234");101 c.update("1234");
113 c.update("56789");102 c.update("56789");
114 try testing.expectEqual(@as(u5, 0x19), c.final());103 try testing.expectEqual(@as(u5, 0x19), c.final());
115}104}
116105
117test "CRC-6/CDMA2000-A" {106test "CRC-6/CDMA2000-A" {
118 const Crc6Cdma2000A = crc.Crc6Cdma2000A;107 const Crc = crc.@"CRC-6/CDMA2000-A";
119108
120 try testing.expectEqual(@as(u6, 0x0d), Crc6Cdma2000A.hash("123456789"));109 try testing.expectEqual(@as(u6, 0x0d), Crc.hash("123456789"));
121110
122 var c = Crc6Cdma2000A.init();111 var c = Crc.init();
123 c.update("1234");112 c.update("1234");
124 c.update("56789");113 c.update("56789");
125 try testing.expectEqual(@as(u6, 0x0d), c.final());114 try testing.expectEqual(@as(u6, 0x0d), c.final());
126}115}
127116
128test "CRC-6/CDMA2000-B" {117test "CRC-6/CDMA2000-B" {
129 const Crc6Cdma2000B = crc.Crc6Cdma2000B;118 const Crc = crc.@"CRC-6/CDMA2000-B";
130119
131 try testing.expectEqual(@as(u6, 0x3b), Crc6Cdma2000B.hash("123456789"));120 try testing.expectEqual(@as(u6, 0x3b), Crc.hash("123456789"));
132121
133 var c = Crc6Cdma2000B.init();122 var c = Crc.init();
134 c.update("1234");123 c.update("1234");
135 c.update("56789");124 c.update("56789");
136 try testing.expectEqual(@as(u6, 0x3b), c.final());125 try testing.expectEqual(@as(u6, 0x3b), c.final());
137}126}
138127
139test "CRC-6/DARC" {128test "CRC-6/DARC" {
140 const Crc6Darc = crc.Crc6Darc;129 const Crc = crc.@"CRC-6/DARC";
141130
142 try testing.expectEqual(@as(u6, 0x26), Crc6Darc.hash("123456789"));131 try testing.expectEqual(@as(u6, 0x26), Crc.hash("123456789"));
143132
144 var c = Crc6Darc.init();133 var c = Crc.init();
145 c.update("1234");134 c.update("1234");
146 c.update("56789");135 c.update("56789");
147 try testing.expectEqual(@as(u6, 0x26), c.final());136 try testing.expectEqual(@as(u6, 0x26), c.final());
148}137}
149138
150test "CRC-6/G-704" {139test "CRC-6/G-704" {
151 const Crc6G704 = crc.Crc6G704;140 const Crc = crc.@"CRC-6/G-704";
152141
153 try testing.expectEqual(@as(u6, 0x06), Crc6G704.hash("123456789"));142 try testing.expectEqual(@as(u6, 0x06), Crc.hash("123456789"));
154143
155 var c = Crc6G704.init();144 var c = Crc.init();
156 c.update("1234");145 c.update("1234");
157 c.update("56789");146 c.update("56789");
158 try testing.expectEqual(@as(u6, 0x06), c.final());147 try testing.expectEqual(@as(u6, 0x06), c.final());
159}148}
160149
161test "CRC-6/GSM" {150test "CRC-6/GSM" {
162 const Crc6Gsm = crc.Crc6Gsm;151 const Crc = crc.@"CRC-6/GSM";
163152
164 try testing.expectEqual(@as(u6, 0x13), Crc6Gsm.hash("123456789"));153 try testing.expectEqual(@as(u6, 0x13), Crc.hash("123456789"));
165154
166 var c = Crc6Gsm.init();155 var c = Crc.init();
167 c.update("1234");156 c.update("1234");
168 c.update("56789");157 c.update("56789");
169 try testing.expectEqual(@as(u6, 0x13), c.final());158 try testing.expectEqual(@as(u6, 0x13), c.final());
170}159}
171160
172test "CRC-7/MMC" {161test "CRC-7/MMC" {
173 const Crc7Mmc = crc.Crc7Mmc;162 const Crc = crc.@"CRC-7/MMC";
174163
175 try testing.expectEqual(@as(u7, 0x75), Crc7Mmc.hash("123456789"));164 try testing.expectEqual(@as(u7, 0x75), Crc.hash("123456789"));
176165
177 var c = Crc7Mmc.init();166 var c = Crc.init();
178 c.update("1234");167 c.update("1234");
179 c.update("56789");168 c.update("56789");
180 try testing.expectEqual(@as(u7, 0x75), c.final());169 try testing.expectEqual(@as(u7, 0x75), c.final());
181}170}
182171
183test "CRC-7/ROHC" {172test "CRC-7/ROHC" {
184 const Crc7Rohc = crc.Crc7Rohc;173 const Crc = crc.@"CRC-7/ROHC";
185174
186 try testing.expectEqual(@as(u7, 0x53), Crc7Rohc.hash("123456789"));175 try testing.expectEqual(@as(u7, 0x53), Crc.hash("123456789"));
187176
188 var c = Crc7Rohc.init();177 var c = Crc.init();
189 c.update("1234");178 c.update("1234");
190 c.update("56789");179 c.update("56789");
191 try testing.expectEqual(@as(u7, 0x53), c.final());180 try testing.expectEqual(@as(u7, 0x53), c.final());
192}181}
193182
194test "CRC-7/UMTS" {183test "CRC-7/UMTS" {
195 const Crc7Umts = crc.Crc7Umts;184 const Crc = crc.@"CRC-7/UMTS";
196185
197 try testing.expectEqual(@as(u7, 0x61), Crc7Umts.hash("123456789"));186 try testing.expectEqual(@as(u7, 0x61), Crc.hash("123456789"));
198187
199 var c = Crc7Umts.init();188 var c = Crc.init();
200 c.update("1234");189 c.update("1234");
201 c.update("56789");190 c.update("56789");
202 try testing.expectEqual(@as(u7, 0x61), c.final());191 try testing.expectEqual(@as(u7, 0x61), c.final());
203}192}
204193
205test "CRC-8/AUTOSAR" {194test "CRC-8/AUTOSAR" {
206 const Crc8Autosar = crc.Crc8Autosar;195 const Crc = crc.@"CRC-8/AUTOSAR";
207196
208 try testing.expectEqual(@as(u8, 0xdf), Crc8Autosar.hash("123456789"));197 try testing.expectEqual(@as(u8, 0xdf), Crc.hash("123456789"));
209198
210 var c = Crc8Autosar.init();199 var c = Crc.init();
211 c.update("1234");200 c.update("1234");
212 c.update("56789");201 c.update("56789");
213 try testing.expectEqual(@as(u8, 0xdf), c.final());202 try testing.expectEqual(@as(u8, 0xdf), c.final());
214}203}
215204
216test "CRC-8/BLUETOOTH" {205test "CRC-8/BLUETOOTH" {
217 const Crc8Bluetooth = crc.Crc8Bluetooth;206 const Crc = crc.@"CRC-8/BLUETOOTH";
218207
219 try testing.expectEqual(@as(u8, 0x26), Crc8Bluetooth.hash("123456789"));208 try testing.expectEqual(@as(u8, 0x26), Crc.hash("123456789"));
220209
221 var c = Crc8Bluetooth.init();210 var c = Crc.init();
222 c.update("1234");211 c.update("1234");
223 c.update("56789");212 c.update("56789");
224 try testing.expectEqual(@as(u8, 0x26), c.final());213 try testing.expectEqual(@as(u8, 0x26), c.final());
225}214}
226215
227test "CRC-8/CDMA2000" {216test "CRC-8/CDMA2000" {
228 const Crc8Cdma2000 = crc.Crc8Cdma2000;217 const Crc = crc.@"CRC-8/CDMA2000";
229218
230 try testing.expectEqual(@as(u8, 0xda), Crc8Cdma2000.hash("123456789"));219 try testing.expectEqual(@as(u8, 0xda), Crc.hash("123456789"));
231220
232 var c = Crc8Cdma2000.init();221 var c = Crc.init();
233 c.update("1234");222 c.update("1234");
234 c.update("56789");223 c.update("56789");
235 try testing.expectEqual(@as(u8, 0xda), c.final());224 try testing.expectEqual(@as(u8, 0xda), c.final());
236}225}
237226
238test "CRC-8/DARC" {227test "CRC-8/DARC" {
239 const Crc8Darc = crc.Crc8Darc;228 const Crc = crc.@"CRC-8/DARC";
240229
241 try testing.expectEqual(@as(u8, 0x15), Crc8Darc.hash("123456789"));230 try testing.expectEqual(@as(u8, 0x15), Crc.hash("123456789"));
242231
243 var c = Crc8Darc.init();232 var c = Crc.init();
244 c.update("1234");233 c.update("1234");
245 c.update("56789");234 c.update("56789");
246 try testing.expectEqual(@as(u8, 0x15), c.final());235 try testing.expectEqual(@as(u8, 0x15), c.final());
247}236}
248237
249test "CRC-8/DVB-S2" {238test "CRC-8/DVB-S2" {
250 const Crc8DvbS2 = crc.Crc8DvbS2;239 const Crc = crc.@"CRC-8/DVB-S2";
251240
252 try testing.expectEqual(@as(u8, 0xbc), Crc8DvbS2.hash("123456789"));241 try testing.expectEqual(@as(u8, 0xbc), Crc.hash("123456789"));
253242
254 var c = Crc8DvbS2.init();243 var c = Crc.init();
255 c.update("1234");244 c.update("1234");
256 c.update("56789");245 c.update("56789");
257 try testing.expectEqual(@as(u8, 0xbc), c.final());246 try testing.expectEqual(@as(u8, 0xbc), c.final());
258}247}
259248
260test "CRC-8/GSM-A" {249test "CRC-8/GSM-A" {
261 const Crc8GsmA = crc.Crc8GsmA;250 const Crc = crc.@"CRC-8/GSM-A";
262251
263 try testing.expectEqual(@as(u8, 0x37), Crc8GsmA.hash("123456789"));252 try testing.expectEqual(@as(u8, 0x37), Crc.hash("123456789"));
264253
265 var c = Crc8GsmA.init();254 var c = Crc.init();
266 c.update("1234");255 c.update("1234");
267 c.update("56789");256 c.update("56789");
268 try testing.expectEqual(@as(u8, 0x37), c.final());257 try testing.expectEqual(@as(u8, 0x37), c.final());
269}258}
270259
271test "CRC-8/GSM-B" {260test "CRC-8/GSM-B" {
272 const Crc8GsmB = crc.Crc8GsmB;261 const Crc = crc.@"CRC-8/GSM-B";
273262
274 try testing.expectEqual(@as(u8, 0x94), Crc8GsmB.hash("123456789"));263 try testing.expectEqual(@as(u8, 0x94), Crc.hash("123456789"));
275264
276 var c = Crc8GsmB.init();265 var c = Crc.init();
277 c.update("1234");266 c.update("1234");
278 c.update("56789");267 c.update("56789");
279 try testing.expectEqual(@as(u8, 0x94), c.final());268 try testing.expectEqual(@as(u8, 0x94), c.final());
280}269}
281270
282test "CRC-8/HITAG" {271test "CRC-8/HITAG" {
283 const Crc8Hitag = crc.Crc8Hitag;272 const Crc = crc.@"CRC-8/HITAG";
284273
285 try testing.expectEqual(@as(u8, 0xb4), Crc8Hitag.hash("123456789"));274 try testing.expectEqual(@as(u8, 0xb4), Crc.hash("123456789"));
286275
287 var c = Crc8Hitag.init();276 var c = Crc.init();
288 c.update("1234");277 c.update("1234");
289 c.update("56789");278 c.update("56789");
290 try testing.expectEqual(@as(u8, 0xb4), c.final());279 try testing.expectEqual(@as(u8, 0xb4), c.final());
291}280}
292281
293test "CRC-8/I-432-1" {282test "CRC-8/I-432-1" {
294 const Crc8I4321 = crc.Crc8I4321;283 const Crc = crc.@"CRC-8/I-432-1";
295284
296 try testing.expectEqual(@as(u8, 0xa1), Crc8I4321.hash("123456789"));285 try testing.expectEqual(@as(u8, 0xa1), Crc.hash("123456789"));
297286
298 var c = Crc8I4321.init();287 var c = Crc.init();
299 c.update("1234");288 c.update("1234");
300 c.update("56789");289 c.update("56789");
301 try testing.expectEqual(@as(u8, 0xa1), c.final());290 try testing.expectEqual(@as(u8, 0xa1), c.final());
302}291}
303292
304test "CRC-8/I-CODE" {293test "CRC-8/I-CODE" {
305 const Crc8ICode = crc.Crc8ICode;294 const Crc = crc.@"CRC-8/I-CODE";
306295
307 try testing.expectEqual(@as(u8, 0x7e), Crc8ICode.hash("123456789"));296 try testing.expectEqual(@as(u8, 0x7e), Crc.hash("123456789"));
308297
309 var c = Crc8ICode.init();298 var c = Crc.init();
310 c.update("1234");299 c.update("1234");
311 c.update("56789");300 c.update("56789");
312 try testing.expectEqual(@as(u8, 0x7e), c.final());301 try testing.expectEqual(@as(u8, 0x7e), c.final());
313}302}
314303
315test "CRC-8/LTE" {304test "CRC-8/LTE" {
316 const Crc8Lte = crc.Crc8Lte;305 const Crc = crc.@"CRC-8/LTE";
317306
318 try testing.expectEqual(@as(u8, 0xea), Crc8Lte.hash("123456789"));307 try testing.expectEqual(@as(u8, 0xea), Crc.hash("123456789"));
319308
320 var c = Crc8Lte.init();309 var c = Crc.init();
321 c.update("1234");310 c.update("1234");
322 c.update("56789");311 c.update("56789");
323 try testing.expectEqual(@as(u8, 0xea), c.final());312 try testing.expectEqual(@as(u8, 0xea), c.final());
324}313}
325314
326test "CRC-8/MAXIM-DOW" {315test "CRC-8/MAXIM-DOW" {
327 const Crc8MaximDow = crc.Crc8MaximDow;316 const Crc = crc.@"CRC-8/MAXIM-DOW";
328317
329 try testing.expectEqual(@as(u8, 0xa1), Crc8MaximDow.hash("123456789"));318 try testing.expectEqual(@as(u8, 0xa1), Crc.hash("123456789"));
330319
331 var c = Crc8MaximDow.init();320 var c = Crc.init();
332 c.update("1234");321 c.update("1234");
333 c.update("56789");322 c.update("56789");
334 try testing.expectEqual(@as(u8, 0xa1), c.final());323 try testing.expectEqual(@as(u8, 0xa1), c.final());
335}324}
336325
337test "CRC-8/MIFARE-MAD" {326test "CRC-8/MIFARE-MAD" {
338 const Crc8MifareMad = crc.Crc8MifareMad;327 const Crc = crc.@"CRC-8/MIFARE-MAD";
339328
340 try testing.expectEqual(@as(u8, 0x99), Crc8MifareMad.hash("123456789"));329 try testing.expectEqual(@as(u8, 0x99), Crc.hash("123456789"));
341330
342 var c = Crc8MifareMad.init();331 var c = Crc.init();
343 c.update("1234");332 c.update("1234");
344 c.update("56789");333 c.update("56789");
345 try testing.expectEqual(@as(u8, 0x99), c.final());334 try testing.expectEqual(@as(u8, 0x99), c.final());
346}335}
347336
348test "CRC-8/NRSC-5" {337test "CRC-8/NRSC-5" {
349 const Crc8Nrsc5 = crc.Crc8Nrsc5;338 const Crc = crc.@"CRC-8/NRSC-5";
350339
351 try testing.expectEqual(@as(u8, 0xf7), Crc8Nrsc5.hash("123456789"));340 try testing.expectEqual(@as(u8, 0xf7), Crc.hash("123456789"));
352341
353 var c = Crc8Nrsc5.init();342 var c = Crc.init();
354 c.update("1234");343 c.update("1234");
355 c.update("56789");344 c.update("56789");
356 try testing.expectEqual(@as(u8, 0xf7), c.final());345 try testing.expectEqual(@as(u8, 0xf7), c.final());
357}346}
358347
359test "CRC-8/OPENSAFETY" {348test "CRC-8/OPENSAFETY" {
360 const Crc8Opensafety = crc.Crc8Opensafety;349 const Crc = crc.@"CRC-8/OPENSAFETY";
361350
362 try testing.expectEqual(@as(u8, 0x3e), Crc8Opensafety.hash("123456789"));351 try testing.expectEqual(@as(u8, 0x3e), Crc.hash("123456789"));
363352
364 var c = Crc8Opensafety.init();353 var c = Crc.init();
365 c.update("1234");354 c.update("1234");
366 c.update("56789");355 c.update("56789");
367 try testing.expectEqual(@as(u8, 0x3e), c.final());356 try testing.expectEqual(@as(u8, 0x3e), c.final());
368}357}
369358
370test "CRC-8/ROHC" {359test "CRC-8/ROHC" {
371 const Crc8Rohc = crc.Crc8Rohc;360 const Crc = crc.@"CRC-8/ROHC";
372361
373 try testing.expectEqual(@as(u8, 0xd0), Crc8Rohc.hash("123456789"));362 try testing.expectEqual(@as(u8, 0xd0), Crc.hash("123456789"));
374363
375 var c = Crc8Rohc.init();364 var c = Crc.init();
376 c.update("1234");365 c.update("1234");
377 c.update("56789");366 c.update("56789");
378 try testing.expectEqual(@as(u8, 0xd0), c.final());367 try testing.expectEqual(@as(u8, 0xd0), c.final());
379}368}
380369
381test "CRC-8/SAE-J1850" {370test "CRC-8/SAE-J1850" {
382 const Crc8SaeJ1850 = crc.Crc8SaeJ1850;371 const Crc = crc.@"CRC-8/SAE-J1850";
383372
384 try testing.expectEqual(@as(u8, 0x4b), Crc8SaeJ1850.hash("123456789"));373 try testing.expectEqual(@as(u8, 0x4b), Crc.hash("123456789"));
385374
386 var c = Crc8SaeJ1850.init();375 var c = Crc.init();
387 c.update("1234");376 c.update("1234");
388 c.update("56789");377 c.update("56789");
389 try testing.expectEqual(@as(u8, 0x4b), c.final());378 try testing.expectEqual(@as(u8, 0x4b), c.final());
390}379}
391380
392test "CRC-8/SMBUS" {381test "CRC-8/SMBUS" {
393 const Crc8Smbus = crc.Crc8Smbus;382 const Crc = crc.@"CRC-8/SMBUS";
394383
395 try testing.expectEqual(@as(u8, 0xf4), Crc8Smbus.hash("123456789"));384 try testing.expectEqual(@as(u8, 0xf4), Crc.hash("123456789"));
396385
397 var c = Crc8Smbus.init();386 var c = Crc.init();
398 c.update("1234");387 c.update("1234");
399 c.update("56789");388 c.update("56789");
400 try testing.expectEqual(@as(u8, 0xf4), c.final());389 try testing.expectEqual(@as(u8, 0xf4), c.final());
401}390}
402391
403test "CRC-8/TECH-3250" {392test "CRC-8/TECH-3250" {
404 const Crc8Tech3250 = crc.Crc8Tech3250;393 const Crc = crc.@"CRC-8/TECH-3250";
405394
406 try testing.expectEqual(@as(u8, 0x97), Crc8Tech3250.hash("123456789"));395 try testing.expectEqual(@as(u8, 0x97), Crc.hash("123456789"));
407396
408 var c = Crc8Tech3250.init();397 var c = Crc.init();
409 c.update("1234");398 c.update("1234");
410 c.update("56789");399 c.update("56789");
411 try testing.expectEqual(@as(u8, 0x97), c.final());400 try testing.expectEqual(@as(u8, 0x97), c.final());
412}401}
413402
414test "CRC-8/WCDMA" {403test "CRC-8/WCDMA" {
415 const Crc8Wcdma = crc.Crc8Wcdma;404 const Crc = crc.@"CRC-8/WCDMA";
416405
417 try testing.expectEqual(@as(u8, 0x25), Crc8Wcdma.hash("123456789"));406 try testing.expectEqual(@as(u8, 0x25), Crc.hash("123456789"));
418407
419 var c = Crc8Wcdma.init();408 var c = Crc.init();
420 c.update("1234");409 c.update("1234");
421 c.update("56789");410 c.update("56789");
422 try testing.expectEqual(@as(u8, 0x25), c.final());411 try testing.expectEqual(@as(u8, 0x25), c.final());
423}412}
424413
425test "CRC-10/ATM" {414test "CRC-10/ATM" {
426 const Crc10Atm = crc.Crc10Atm;415 const Crc = crc.@"CRC-10/ATM";
427416
428 try testing.expectEqual(@as(u10, 0x199), Crc10Atm.hash("123456789"));417 try testing.expectEqual(@as(u10, 0x199), Crc.hash("123456789"));
429418
430 var c = Crc10Atm.init();419 var c = Crc.init();
431 c.update("1234");420 c.update("1234");
432 c.update("56789");421 c.update("56789");
433 try testing.expectEqual(@as(u10, 0x199), c.final());422 try testing.expectEqual(@as(u10, 0x199), c.final());
434}423}
435424
436test "CRC-10/CDMA2000" {425test "CRC-10/CDMA2000" {
437 const Crc10Cdma2000 = crc.Crc10Cdma2000;426 const Crc = crc.@"CRC-10/CDMA2000";
438427
439 try testing.expectEqual(@as(u10, 0x233), Crc10Cdma2000.hash("123456789"));428 try testing.expectEqual(@as(u10, 0x233), Crc.hash("123456789"));
440429
441 var c = Crc10Cdma2000.init();430 var c = Crc.init();
442 c.update("1234");431 c.update("1234");
443 c.update("56789");432 c.update("56789");
444 try testing.expectEqual(@as(u10, 0x233), c.final());433 try testing.expectEqual(@as(u10, 0x233), c.final());
445}434}
446435
447test "CRC-10/GSM" {436test "CRC-10/GSM" {
448 const Crc10Gsm = crc.Crc10Gsm;437 const Crc = crc.@"CRC-10/GSM";
449438
450 try testing.expectEqual(@as(u10, 0x12a), Crc10Gsm.hash("123456789"));439 try testing.expectEqual(@as(u10, 0x12a), Crc.hash("123456789"));
451440
452 var c = Crc10Gsm.init();441 var c = Crc.init();
453 c.update("1234");442 c.update("1234");
454 c.update("56789");443 c.update("56789");
455 try testing.expectEqual(@as(u10, 0x12a), c.final());444 try testing.expectEqual(@as(u10, 0x12a), c.final());
456}445}
457446
458test "CRC-11/FLEXRAY" {447test "CRC-11/FLEXRAY" {
459 const Crc11Flexray = crc.Crc11Flexray;448 const Crc = crc.@"CRC-11/FLEXRAY";
460449
461 try testing.expectEqual(@as(u11, 0x5a3), Crc11Flexray.hash("123456789"));450 try testing.expectEqual(@as(u11, 0x5a3), Crc.hash("123456789"));
462451
463 var c = Crc11Flexray.init();452 var c = Crc.init();
464 c.update("1234");453 c.update("1234");
465 c.update("56789");454 c.update("56789");
466 try testing.expectEqual(@as(u11, 0x5a3), c.final());455 try testing.expectEqual(@as(u11, 0x5a3), c.final());
467}456}
468457
469test "CRC-11/UMTS" {458test "CRC-11/UMTS" {
470 const Crc11Umts = crc.Crc11Umts;459 const Crc = crc.@"CRC-11/UMTS";
471460
472 try testing.expectEqual(@as(u11, 0x061), Crc11Umts.hash("123456789"));461 try testing.expectEqual(@as(u11, 0x061), Crc.hash("123456789"));
473462
474 var c = Crc11Umts.init();463 var c = Crc.init();
475 c.update("1234");464 c.update("1234");
476 c.update("56789");465 c.update("56789");
477 try testing.expectEqual(@as(u11, 0x061), c.final());466 try testing.expectEqual(@as(u11, 0x061), c.final());
478}467}
479468
480test "CRC-12/CDMA2000" {469test "CRC-12/CDMA2000" {
481 const Crc12Cdma2000 = crc.Crc12Cdma2000;470 const Crc = crc.@"CRC-12/CDMA2000";
482471
483 try testing.expectEqual(@as(u12, 0xd4d), Crc12Cdma2000.hash("123456789"));472 try testing.expectEqual(@as(u12, 0xd4d), Crc.hash("123456789"));
484473
485 var c = Crc12Cdma2000.init();474 var c = Crc.init();
486 c.update("1234");475 c.update("1234");
487 c.update("56789");476 c.update("56789");
488 try testing.expectEqual(@as(u12, 0xd4d), c.final());477 try testing.expectEqual(@as(u12, 0xd4d), c.final());
489}478}
490479
491test "CRC-12/DECT" {480test "CRC-12/DECT" {
492 const Crc12Dect = crc.Crc12Dect;481 const Crc = crc.@"CRC-12/DECT";
493482
494 try testing.expectEqual(@as(u12, 0xf5b), Crc12Dect.hash("123456789"));483 try testing.expectEqual(@as(u12, 0xf5b), Crc.hash("123456789"));
495484
496 var c = Crc12Dect.init();485 var c = Crc.init();
497 c.update("1234");486 c.update("1234");
498 c.update("56789");487 c.update("56789");
499 try testing.expectEqual(@as(u12, 0xf5b), c.final());488 try testing.expectEqual(@as(u12, 0xf5b), c.final());
500}489}
501490
502test "CRC-12/GSM" {491test "CRC-12/GSM" {
503 const Crc12Gsm = crc.Crc12Gsm;492 const Crc = crc.@"CRC-12/GSM";
504493
505 try testing.expectEqual(@as(u12, 0xb34), Crc12Gsm.hash("123456789"));494 try testing.expectEqual(@as(u12, 0xb34), Crc.hash("123456789"));
506495
507 var c = Crc12Gsm.init();496 var c = Crc.init();
508 c.update("1234");497 c.update("1234");
509 c.update("56789");498 c.update("56789");
510 try testing.expectEqual(@as(u12, 0xb34), c.final());499 try testing.expectEqual(@as(u12, 0xb34), c.final());
511}500}
512501
513test "CRC-12/UMTS" {502test "CRC-12/UMTS" {
514 const Crc12Umts = crc.Crc12Umts;503 const Crc = crc.@"CRC-12/UMTS";
515504
516 try testing.expectEqual(@as(u12, 0xdaf), Crc12Umts.hash("123456789"));505 try testing.expectEqual(@as(u12, 0xdaf), Crc.hash("123456789"));
517506
518 var c = Crc12Umts.init();507 var c = Crc.init();
519 c.update("1234");508 c.update("1234");
520 c.update("56789");509 c.update("56789");
521 try testing.expectEqual(@as(u12, 0xdaf), c.final());510 try testing.expectEqual(@as(u12, 0xdaf), c.final());
522}511}
523512
524test "CRC-13/BBC" {513test "CRC-13/BBC" {
525 const Crc13Bbc = crc.Crc13Bbc;514 const Crc = crc.@"CRC-13/BBC";
526515
527 try testing.expectEqual(@as(u13, 0x04fa), Crc13Bbc.hash("123456789"));516 try testing.expectEqual(@as(u13, 0x04fa), Crc.hash("123456789"));
528517
529 var c = Crc13Bbc.init();518 var c = Crc.init();
530 c.update("1234");519 c.update("1234");
531 c.update("56789");520 c.update("56789");
532 try testing.expectEqual(@as(u13, 0x04fa), c.final());521 try testing.expectEqual(@as(u13, 0x04fa), c.final());
533}522}
534523
535test "CRC-14/DARC" {524test "CRC-14/DARC" {
536 const Crc14Darc = crc.Crc14Darc;525 const Crc = crc.@"CRC-14/DARC";
537526
538 try testing.expectEqual(@as(u14, 0x082d), Crc14Darc.hash("123456789"));527 try testing.expectEqual(@as(u14, 0x082d), Crc.hash("123456789"));
539528
540 var c = Crc14Darc.init();529 var c = Crc.init();
541 c.update("1234");530 c.update("1234");
542 c.update("56789");531 c.update("56789");
543 try testing.expectEqual(@as(u14, 0x082d), c.final());532 try testing.expectEqual(@as(u14, 0x082d), c.final());
544}533}
545534
546test "CRC-14/GSM" {535test "CRC-14/GSM" {
547 const Crc14Gsm = crc.Crc14Gsm;536 const Crc = crc.@"CRC-14/GSM";
548537
549 try testing.expectEqual(@as(u14, 0x30ae), Crc14Gsm.hash("123456789"));538 try testing.expectEqual(@as(u14, 0x30ae), Crc.hash("123456789"));
550539
551 var c = Crc14Gsm.init();540 var c = Crc.init();
552 c.update("1234");541 c.update("1234");
553 c.update("56789");542 c.update("56789");
554 try testing.expectEqual(@as(u14, 0x30ae), c.final());543 try testing.expectEqual(@as(u14, 0x30ae), c.final());
555}544}
556545
557test "CRC-15/CAN" {546test "CRC-15/CAN" {
558 const Crc15Can = crc.Crc15Can;547 const Crc = crc.@"CRC-15/CAN";
559548
560 try testing.expectEqual(@as(u15, 0x059e), Crc15Can.hash("123456789"));549 try testing.expectEqual(@as(u15, 0x059e), Crc.hash("123456789"));
561550
562 var c = Crc15Can.init();551 var c = Crc.init();
563 c.update("1234");552 c.update("1234");
564 c.update("56789");553 c.update("56789");
565 try testing.expectEqual(@as(u15, 0x059e), c.final());554 try testing.expectEqual(@as(u15, 0x059e), c.final());
566}555}
567556
568test "CRC-15/MPT1327" {557test "CRC-15/MPT1327" {
569 const Crc15Mpt1327 = crc.Crc15Mpt1327;558 const Crc = crc.@"CRC-15/MPT1327";
570559
571 try testing.expectEqual(@as(u15, 0x2566), Crc15Mpt1327.hash("123456789"));560 try testing.expectEqual(@as(u15, 0x2566), Crc.hash("123456789"));
572561
573 var c = Crc15Mpt1327.init();562 var c = Crc.init();
574 c.update("1234");563 c.update("1234");
575 c.update("56789");564 c.update("56789");
576 try testing.expectEqual(@as(u15, 0x2566), c.final());565 try testing.expectEqual(@as(u15, 0x2566), c.final());
577}566}
578567
579test "CRC-16/ARC" {568test "CRC-16/ARC" {
580 const Crc16Arc = crc.Crc16Arc;569 const Crc = crc.@"CRC-16/ARC";
581570
582 try testing.expectEqual(@as(u16, 0xbb3d), Crc16Arc.hash("123456789"));571 try testing.expectEqual(@as(u16, 0xbb3d), Crc.hash("123456789"));
583572
584 var c = Crc16Arc.init();573 var c = Crc.init();
585 c.update("1234");574 c.update("1234");
586 c.update("56789");575 c.update("56789");
587 try testing.expectEqual(@as(u16, 0xbb3d), c.final());576 try testing.expectEqual(@as(u16, 0xbb3d), c.final());
588}577}
589578
590test "CRC-16/CDMA2000" {579test "CRC-16/CDMA2000" {
591 const Crc16Cdma2000 = crc.Crc16Cdma2000;580 const Crc = crc.@"CRC-16/CDMA2000";
592581
593 try testing.expectEqual(@as(u16, 0x4c06), Crc16Cdma2000.hash("123456789"));582 try testing.expectEqual(@as(u16, 0x4c06), Crc.hash("123456789"));
594583
595 var c = Crc16Cdma2000.init();584 var c = Crc.init();
596 c.update("1234");585 c.update("1234");
597 c.update("56789");586 c.update("56789");
598 try testing.expectEqual(@as(u16, 0x4c06), c.final());587 try testing.expectEqual(@as(u16, 0x4c06), c.final());
599}588}
600589
601test "CRC-16/CMS" {590test "CRC-16/CMS" {
602 const Crc16Cms = crc.Crc16Cms;591 const Crc = crc.@"CRC-16/CMS";
603592
604 try testing.expectEqual(@as(u16, 0xaee7), Crc16Cms.hash("123456789"));593 try testing.expectEqual(@as(u16, 0xaee7), Crc.hash("123456789"));
605594
606 var c = Crc16Cms.init();595 var c = Crc.init();
607 c.update("1234");596 c.update("1234");
608 c.update("56789");597 c.update("56789");
609 try testing.expectEqual(@as(u16, 0xaee7), c.final());598 try testing.expectEqual(@as(u16, 0xaee7), c.final());
610}599}
611600
612test "CRC-16/DDS-110" {601test "CRC-16/DDS-110" {
613 const Crc16Dds110 = crc.Crc16Dds110;602 const Crc = crc.@"CRC-16/DDS-110";
614603
615 try testing.expectEqual(@as(u16, 0x9ecf), Crc16Dds110.hash("123456789"));604 try testing.expectEqual(@as(u16, 0x9ecf), Crc.hash("123456789"));
616605
617 var c = Crc16Dds110.init();606 var c = Crc.init();
618 c.update("1234");607 c.update("1234");
619 c.update("56789");608 c.update("56789");
620 try testing.expectEqual(@as(u16, 0x9ecf), c.final());609 try testing.expectEqual(@as(u16, 0x9ecf), c.final());
621}610}
622611
623test "CRC-16/DECT-R" {612test "CRC-16/DECT-R" {
624 const Crc16DectR = crc.Crc16DectR;613 const Crc = crc.@"CRC-16/DECT-R";
625614
626 try testing.expectEqual(@as(u16, 0x007e), Crc16DectR.hash("123456789"));615 try testing.expectEqual(@as(u16, 0x007e), Crc.hash("123456789"));
627616
628 var c = Crc16DectR.init();617 var c = Crc.init();
629 c.update("1234");618 c.update("1234");
630 c.update("56789");619 c.update("56789");
631 try testing.expectEqual(@as(u16, 0x007e), c.final());620 try testing.expectEqual(@as(u16, 0x007e), c.final());
632}621}
633622
634test "CRC-16/DECT-X" {623test "CRC-16/DECT-X" {
635 const Crc16DectX = crc.Crc16DectX;624 const Crc = crc.@"CRC-16/DECT-X";
636625
637 try testing.expectEqual(@as(u16, 0x007f), Crc16DectX.hash("123456789"));626 try testing.expectEqual(@as(u16, 0x007f), Crc.hash("123456789"));
638627
639 var c = Crc16DectX.init();628 var c = Crc.init();
640 c.update("1234");629 c.update("1234");
641 c.update("56789");630 c.update("56789");
642 try testing.expectEqual(@as(u16, 0x007f), c.final());631 try testing.expectEqual(@as(u16, 0x007f), c.final());
643}632}
644633
645test "CRC-16/DNP" {634test "CRC-16/DNP" {
646 const Crc16Dnp = crc.Crc16Dnp;635 const Crc = crc.@"CRC-16/DNP";
647636
648 try testing.expectEqual(@as(u16, 0xea82), Crc16Dnp.hash("123456789"));637 try testing.expectEqual(@as(u16, 0xea82), Crc.hash("123456789"));
649638
650 var c = Crc16Dnp.init();639 var c = Crc.init();
651 c.update("1234");640 c.update("1234");
652 c.update("56789");641 c.update("56789");
653 try testing.expectEqual(@as(u16, 0xea82), c.final());642 try testing.expectEqual(@as(u16, 0xea82), c.final());
654}643}
655644
656test "CRC-16/EN-13757" {645test "CRC-16/EN-13757" {
657 const Crc16En13757 = crc.Crc16En13757;646 const Crc = crc.@"CRC-16/EN-13757";
658647
659 try testing.expectEqual(@as(u16, 0xc2b7), Crc16En13757.hash("123456789"));648 try testing.expectEqual(@as(u16, 0xc2b7), Crc.hash("123456789"));
660649
661 var c = Crc16En13757.init();650 var c = Crc.init();
662 c.update("1234");651 c.update("1234");
663 c.update("56789");652 c.update("56789");
664 try testing.expectEqual(@as(u16, 0xc2b7), c.final());653 try testing.expectEqual(@as(u16, 0xc2b7), c.final());
665}654}
666655
667test "CRC-16/GENIBUS" {656test "CRC-16/GENIBUS" {
668 const Crc16Genibus = crc.Crc16Genibus;657 const Crc = crc.@"CRC-16/GENIBUS";
669658
670 try testing.expectEqual(@as(u16, 0xd64e), Crc16Genibus.hash("123456789"));659 try testing.expectEqual(@as(u16, 0xd64e), Crc.hash("123456789"));
671660
672 var c = Crc16Genibus.init();661 var c = Crc.init();
673 c.update("1234");662 c.update("1234");
674 c.update("56789");663 c.update("56789");
675 try testing.expectEqual(@as(u16, 0xd64e), c.final());664 try testing.expectEqual(@as(u16, 0xd64e), c.final());
676}665}
677666
678test "CRC-16/GSM" {667test "CRC-16/GSM" {
679 const Crc16Gsm = crc.Crc16Gsm;668 const Crc = crc.@"CRC-16/GSM";
680669
681 try testing.expectEqual(@as(u16, 0xce3c), Crc16Gsm.hash("123456789"));670 try testing.expectEqual(@as(u16, 0xce3c), Crc.hash("123456789"));
682671
683 var c = Crc16Gsm.init();672 var c = Crc.init();
684 c.update("1234");673 c.update("1234");
685 c.update("56789");674 c.update("56789");
686 try testing.expectEqual(@as(u16, 0xce3c), c.final());675 try testing.expectEqual(@as(u16, 0xce3c), c.final());
687}676}
688677
689test "CRC-16/IBM-3740" {678test "CRC-16/IBM-3740" {
690 const Crc16Ibm3740 = crc.Crc16Ibm3740;679 const Crc = crc.@"CRC-16/IBM-3740";
691680
692 try testing.expectEqual(@as(u16, 0x29b1), Crc16Ibm3740.hash("123456789"));681 try testing.expectEqual(@as(u16, 0x29b1), Crc.hash("123456789"));
693682
694 var c = Crc16Ibm3740.init();683 var c = Crc.init();
695 c.update("1234");684 c.update("1234");
696 c.update("56789");685 c.update("56789");
697 try testing.expectEqual(@as(u16, 0x29b1), c.final());686 try testing.expectEqual(@as(u16, 0x29b1), c.final());
698}687}
699688
700test "CRC-16/IBM-SDLC" {689test "CRC-16/IBM-SDLC" {
701 const Crc16IbmSdlc = crc.Crc16IbmSdlc;690 const Crc = crc.@"CRC-16/IBM-SDLC";
702691
703 try testing.expectEqual(@as(u16, 0x906e), Crc16IbmSdlc.hash("123456789"));692 try testing.expectEqual(@as(u16, 0x906e), Crc.hash("123456789"));
704693
705 var c = Crc16IbmSdlc.init();694 var c = Crc.init();
706 c.update("1234");695 c.update("1234");
707 c.update("56789");696 c.update("56789");
708 try testing.expectEqual(@as(u16, 0x906e), c.final());697 try testing.expectEqual(@as(u16, 0x906e), c.final());
709}698}
710699
711test "CRC-16/ISO-IEC-14443-3-A" {700test "CRC-16/ISO-IEC-14443-3-A" {
712 const Crc16IsoIec144433A = crc.Crc16IsoIec144433A;701 const Crc = crc.@"CRC-16/ISO-IEC-14443-3-A";
713702
714 try testing.expectEqual(@as(u16, 0xbf05), Crc16IsoIec144433A.hash("123456789"));703 try testing.expectEqual(@as(u16, 0xbf05), Crc.hash("123456789"));
715704
716 var c = Crc16IsoIec144433A.init();705 var c = Crc.init();
717 c.update("1234");706 c.update("1234");
718 c.update("56789");707 c.update("56789");
719 try testing.expectEqual(@as(u16, 0xbf05), c.final());708 try testing.expectEqual(@as(u16, 0xbf05), c.final());
720}709}
721710
722test "CRC-16/KERMIT" {711test "CRC-16/KERMIT" {
723 const Crc16Kermit = crc.Crc16Kermit;712 const Crc = crc.@"CRC-16/KERMIT";
724713
725 try testing.expectEqual(@as(u16, 0x2189), Crc16Kermit.hash("123456789"));714 try testing.expectEqual(@as(u16, 0x2189), Crc.hash("123456789"));
726715
727 var c = Crc16Kermit.init();716 var c = Crc.init();
728 c.update("1234");717 c.update("1234");
729 c.update("56789");718 c.update("56789");
730 try testing.expectEqual(@as(u16, 0x2189), c.final());719 try testing.expectEqual(@as(u16, 0x2189), c.final());
731}720}
732721
733test "CRC-16/LJ1200" {722test "CRC-16/LJ1200" {
734 const Crc16Lj1200 = crc.Crc16Lj1200;723 const Crc = crc.@"CRC-16/LJ1200";
735724
736 try testing.expectEqual(@as(u16, 0xbdf4), Crc16Lj1200.hash("123456789"));725 try testing.expectEqual(@as(u16, 0xbdf4), Crc.hash("123456789"));
737726
738 var c = Crc16Lj1200.init();727 var c = Crc.init();
739 c.update("1234");728 c.update("1234");
740 c.update("56789");729 c.update("56789");
741 try testing.expectEqual(@as(u16, 0xbdf4), c.final());730 try testing.expectEqual(@as(u16, 0xbdf4), c.final());
742}731}
743732
744test "CRC-16/M17" {733test "CRC-16/M17" {
745 const Crc16M17 = crc.Crc16M17;734 const Crc = crc.@"CRC-16/M17";
746735
747 try testing.expectEqual(@as(u16, 0x772b), Crc16M17.hash("123456789"));736 try testing.expectEqual(@as(u16, 0x772b), Crc.hash("123456789"));
748737
749 var c = Crc16M17.init();738 var c = Crc.init();
750 c.update("1234");739 c.update("1234");
751 c.update("56789");740 c.update("56789");
752 try testing.expectEqual(@as(u16, 0x772b), c.final());741 try testing.expectEqual(@as(u16, 0x772b), c.final());
753}742}
754743
755test "CRC-16/MAXIM-DOW" {744test "CRC-16/MAXIM-DOW" {
756 const Crc16MaximDow = crc.Crc16MaximDow;745 const Crc = crc.@"CRC-16/MAXIM-DOW";
757746
758 try testing.expectEqual(@as(u16, 0x44c2), Crc16MaximDow.hash("123456789"));747 try testing.expectEqual(@as(u16, 0x44c2), Crc.hash("123456789"));
759748
760 var c = Crc16MaximDow.init();749 var c = Crc.init();
761 c.update("1234");750 c.update("1234");
762 c.update("56789");751 c.update("56789");
763 try testing.expectEqual(@as(u16, 0x44c2), c.final());752 try testing.expectEqual(@as(u16, 0x44c2), c.final());
764}753}
765754
766test "CRC-16/MCRF4XX" {755test "CRC-16/MCRF4XX" {
767 const Crc16Mcrf4xx = crc.Crc16Mcrf4xx;756 const Crc = crc.@"CRC-16/MCRF4XX";
768757
769 try testing.expectEqual(@as(u16, 0x6f91), Crc16Mcrf4xx.hash("123456789"));758 try testing.expectEqual(@as(u16, 0x6f91), Crc.hash("123456789"));
770759
771 var c = Crc16Mcrf4xx.init();760 var c = Crc.init();
772 c.update("1234");761 c.update("1234");
773 c.update("56789");762 c.update("56789");
774 try testing.expectEqual(@as(u16, 0x6f91), c.final());763 try testing.expectEqual(@as(u16, 0x6f91), c.final());
775}764}
776765
777test "CRC-16/MODBUS" {766test "CRC-16/MODBUS" {
778 const Crc16Modbus = crc.Crc16Modbus;767 const Crc = crc.@"CRC-16/MODBUS";
779768
780 try testing.expectEqual(@as(u16, 0x4b37), Crc16Modbus.hash("123456789"));769 try testing.expectEqual(@as(u16, 0x4b37), Crc.hash("123456789"));
781770
782 var c = Crc16Modbus.init();771 var c = Crc.init();
783 c.update("1234");772 c.update("1234");
784 c.update("56789");773 c.update("56789");
785 try testing.expectEqual(@as(u16, 0x4b37), c.final());774 try testing.expectEqual(@as(u16, 0x4b37), c.final());
786}775}
787776
788test "CRC-16/NRSC-5" {777test "CRC-16/NRSC-5" {
789 const Crc16Nrsc5 = crc.Crc16Nrsc5;778 const Crc = crc.@"CRC-16/NRSC-5";
790779
791 try testing.expectEqual(@as(u16, 0xa066), Crc16Nrsc5.hash("123456789"));780 try testing.expectEqual(@as(u16, 0xa066), Crc.hash("123456789"));
792781
793 var c = Crc16Nrsc5.init();782 var c = Crc.init();
794 c.update("1234");783 c.update("1234");
795 c.update("56789");784 c.update("56789");
796 try testing.expectEqual(@as(u16, 0xa066), c.final());785 try testing.expectEqual(@as(u16, 0xa066), c.final());
797}786}
798787
799test "CRC-16/OPENSAFETY-A" {788test "CRC-16/OPENSAFETY-A" {
800 const Crc16OpensafetyA = crc.Crc16OpensafetyA;789 const Crc = crc.@"CRC-16/OPENSAFETY-A";
801790
802 try testing.expectEqual(@as(u16, 0x5d38), Crc16OpensafetyA.hash("123456789"));791 try testing.expectEqual(@as(u16, 0x5d38), Crc.hash("123456789"));
803792
804 var c = Crc16OpensafetyA.init();793 var c = Crc.init();
805 c.update("1234");794 c.update("1234");
806 c.update("56789");795 c.update("56789");
807 try testing.expectEqual(@as(u16, 0x5d38), c.final());796 try testing.expectEqual(@as(u16, 0x5d38), c.final());
808}797}
809798
810test "CRC-16/OPENSAFETY-B" {799test "CRC-16/OPENSAFETY-B" {
811 const Crc16OpensafetyB = crc.Crc16OpensafetyB;800 const Crc = crc.@"CRC-16/OPENSAFETY-B";
812801
813 try testing.expectEqual(@as(u16, 0x20fe), Crc16OpensafetyB.hash("123456789"));802 try testing.expectEqual(@as(u16, 0x20fe), Crc.hash("123456789"));
814803
815 var c = Crc16OpensafetyB.init();804 var c = Crc.init();
816 c.update("1234");805 c.update("1234");
817 c.update("56789");806 c.update("56789");
818 try testing.expectEqual(@as(u16, 0x20fe), c.final());807 try testing.expectEqual(@as(u16, 0x20fe), c.final());
819}808}
820809
821test "CRC-16/PROFIBUS" {810test "CRC-16/PROFIBUS" {
822 const Crc16Profibus = crc.Crc16Profibus;811 const Crc = crc.@"CRC-16/PROFIBUS";
823812
824 try testing.expectEqual(@as(u16, 0xa819), Crc16Profibus.hash("123456789"));813 try testing.expectEqual(@as(u16, 0xa819), Crc.hash("123456789"));
825814
826 var c = Crc16Profibus.init();815 var c = Crc.init();
827 c.update("1234");816 c.update("1234");
828 c.update("56789");817 c.update("56789");
829 try testing.expectEqual(@as(u16, 0xa819), c.final());818 try testing.expectEqual(@as(u16, 0xa819), c.final());
830}819}
831820
832test "CRC-16/RIELLO" {821test "CRC-16/RIELLO" {
833 const Crc16Riello = crc.Crc16Riello;822 const Crc = crc.@"CRC-16/RIELLO";
834823
835 try testing.expectEqual(@as(u16, 0x63d0), Crc16Riello.hash("123456789"));824 try testing.expectEqual(@as(u16, 0x63d0), Crc.hash("123456789"));
836825
837 var c = Crc16Riello.init();826 var c = Crc.init();
838 c.update("1234");827 c.update("1234");
839 c.update("56789");828 c.update("56789");
840 try testing.expectEqual(@as(u16, 0x63d0), c.final());829 try testing.expectEqual(@as(u16, 0x63d0), c.final());
841}830}
842831
843test "CRC-16/SPI-FUJITSU" {832test "CRC-16/SPI-FUJITSU" {
844 const Crc16SpiFujitsu = crc.Crc16SpiFujitsu;833 const Crc = crc.@"CRC-16/SPI-FUJITSU";
845834
846 try testing.expectEqual(@as(u16, 0xe5cc), Crc16SpiFujitsu.hash("123456789"));835 try testing.expectEqual(@as(u16, 0xe5cc), Crc.hash("123456789"));
847836
848 var c = Crc16SpiFujitsu.init();837 var c = Crc.init();
849 c.update("1234");838 c.update("1234");
850 c.update("56789");839 c.update("56789");
851 try testing.expectEqual(@as(u16, 0xe5cc), c.final());840 try testing.expectEqual(@as(u16, 0xe5cc), c.final());
852}841}
853842
854test "CRC-16/T10-DIF" {843test "CRC-16/T10-DIF" {
855 const Crc16T10Dif = crc.Crc16T10Dif;844 const Crc = crc.@"CRC-16/T10-DIF";
856845
857 try testing.expectEqual(@as(u16, 0xd0db), Crc16T10Dif.hash("123456789"));846 try testing.expectEqual(@as(u16, 0xd0db), Crc.hash("123456789"));
858847
859 var c = Crc16T10Dif.init();848 var c = Crc.init();
860 c.update("1234");849 c.update("1234");
861 c.update("56789");850 c.update("56789");
862 try testing.expectEqual(@as(u16, 0xd0db), c.final());851 try testing.expectEqual(@as(u16, 0xd0db), c.final());
863}852}
864853
865test "CRC-16/TELEDISK" {854test "CRC-16/TELEDISK" {
866 const Crc16Teledisk = crc.Crc16Teledisk;855 const Crc = crc.@"CRC-16/TELEDISK";
867856
868 try testing.expectEqual(@as(u16, 0x0fb3), Crc16Teledisk.hash("123456789"));857 try testing.expectEqual(@as(u16, 0x0fb3), Crc.hash("123456789"));
869858
870 var c = Crc16Teledisk.init();859 var c = Crc.init();
871 c.update("1234");860 c.update("1234");
872 c.update("56789");861 c.update("56789");
873 try testing.expectEqual(@as(u16, 0x0fb3), c.final());862 try testing.expectEqual(@as(u16, 0x0fb3), c.final());
874}863}
875864
876test "CRC-16/TMS37157" {865test "CRC-16/TMS37157" {
877 const Crc16Tms37157 = crc.Crc16Tms37157;866 const Crc = crc.@"CRC-16/TMS37157";
878867
879 try testing.expectEqual(@as(u16, 0x26b1), Crc16Tms37157.hash("123456789"));868 try testing.expectEqual(@as(u16, 0x26b1), Crc.hash("123456789"));
880869
881 var c = Crc16Tms37157.init();870 var c = Crc.init();
882 c.update("1234");871 c.update("1234");
883 c.update("56789");872 c.update("56789");
884 try testing.expectEqual(@as(u16, 0x26b1), c.final());873 try testing.expectEqual(@as(u16, 0x26b1), c.final());
885}874}
886875
887test "CRC-16/UMTS" {876test "CRC-16/UMTS" {
888 const Crc16Umts = crc.Crc16Umts;877 const Crc = crc.@"CRC-16/UMTS";
889878
890 try testing.expectEqual(@as(u16, 0xfee8), Crc16Umts.hash("123456789"));879 try testing.expectEqual(@as(u16, 0xfee8), Crc.hash("123456789"));
891880
892 var c = Crc16Umts.init();881 var c = Crc.init();
893 c.update("1234");882 c.update("1234");
894 c.update("56789");883 c.update("56789");
895 try testing.expectEqual(@as(u16, 0xfee8), c.final());884 try testing.expectEqual(@as(u16, 0xfee8), c.final());
896}885}
897886
898test "CRC-16/USB" {887test "CRC-16/USB" {
899 const Crc16Usb = crc.Crc16Usb;888 const Crc = crc.@"CRC-16/USB";
900889
901 try testing.expectEqual(@as(u16, 0xb4c8), Crc16Usb.hash("123456789"));890 try testing.expectEqual(@as(u16, 0xb4c8), Crc.hash("123456789"));
902891
903 var c = Crc16Usb.init();892 var c = Crc.init();
904 c.update("1234");893 c.update("1234");
905 c.update("56789");894 c.update("56789");
906 try testing.expectEqual(@as(u16, 0xb4c8), c.final());895 try testing.expectEqual(@as(u16, 0xb4c8), c.final());
907}896}
908897
909test "CRC-16/XMODEM" {898test "CRC-16/XMODEM" {
910 const Crc16Xmodem = crc.Crc16Xmodem;899 const Crc = crc.@"CRC-16/XMODEM";
911900
912 try testing.expectEqual(@as(u16, 0x31c3), Crc16Xmodem.hash("123456789"));901 try testing.expectEqual(@as(u16, 0x31c3), Crc.hash("123456789"));
913902
914 var c = Crc16Xmodem.init();903 var c = Crc.init();
915 c.update("1234");904 c.update("1234");
916 c.update("56789");905 c.update("56789");
917 try testing.expectEqual(@as(u16, 0x31c3), c.final());906 try testing.expectEqual(@as(u16, 0x31c3), c.final());
918}907}
919908
920test "CRC-17/CAN-FD" {909test "CRC-17/CAN-FD" {
921 const Crc17CanFd = crc.Crc17CanFd;910 const Crc = crc.@"CRC-17/CAN-FD";
922911
923 try testing.expectEqual(@as(u17, 0x04f03), Crc17CanFd.hash("123456789"));912 try testing.expectEqual(@as(u17, 0x04f03), Crc.hash("123456789"));
924913
925 var c = Crc17CanFd.init();914 var c = Crc.init();
926 c.update("1234");915 c.update("1234");
927 c.update("56789");916 c.update("56789");
928 try testing.expectEqual(@as(u17, 0x04f03), c.final());917 try testing.expectEqual(@as(u17, 0x04f03), c.final());
929}918}
930919
931test "CRC-21/CAN-FD" {920test "CRC-21/CAN-FD" {
932 const Crc21CanFd = crc.Crc21CanFd;921 const Crc = crc.@"CRC-21/CAN-FD";
933922
934 try testing.expectEqual(@as(u21, 0x0ed841), Crc21CanFd.hash("123456789"));923 try testing.expectEqual(@as(u21, 0x0ed841), Crc.hash("123456789"));
935924
936 var c = Crc21CanFd.init();925 var c = Crc.init();
937 c.update("1234");926 c.update("1234");
938 c.update("56789");927 c.update("56789");
939 try testing.expectEqual(@as(u21, 0x0ed841), c.final());928 try testing.expectEqual(@as(u21, 0x0ed841), c.final());
940}929}
941930
942test "CRC-24/BLE" {931test "CRC-24/BLE" {
943 const Crc24Ble = crc.Crc24Ble;932 const Crc = crc.@"CRC-24/BLE";
944933
945 try testing.expectEqual(@as(u24, 0xc25a56), Crc24Ble.hash("123456789"));934 try testing.expectEqual(@as(u24, 0xc25a56), Crc.hash("123456789"));
946935
947 var c = Crc24Ble.init();936 var c = Crc.init();
948 c.update("1234");937 c.update("1234");
949 c.update("56789");938 c.update("56789");
950 try testing.expectEqual(@as(u24, 0xc25a56), c.final());939 try testing.expectEqual(@as(u24, 0xc25a56), c.final());
951}940}
952941
953test "CRC-24/FLEXRAY-A" {942test "CRC-24/FLEXRAY-A" {
954 const Crc24FlexrayA = crc.Crc24FlexrayA;943 const Crc = crc.@"CRC-24/FLEXRAY-A";
955944
956 try testing.expectEqual(@as(u24, 0x7979bd), Crc24FlexrayA.hash("123456789"));945 try testing.expectEqual(@as(u24, 0x7979bd), Crc.hash("123456789"));
957946
958 var c = Crc24FlexrayA.init();947 var c = Crc.init();
959 c.update("1234");948 c.update("1234");
960 c.update("56789");949 c.update("56789");
961 try testing.expectEqual(@as(u24, 0x7979bd), c.final());950 try testing.expectEqual(@as(u24, 0x7979bd), c.final());
962}951}
963952
964test "CRC-24/FLEXRAY-B" {953test "CRC-24/FLEXRAY-B" {
965 const Crc24FlexrayB = crc.Crc24FlexrayB;954 const Crc = crc.@"CRC-24/FLEXRAY-B";
966955
967 try testing.expectEqual(@as(u24, 0x1f23b8), Crc24FlexrayB.hash("123456789"));956 try testing.expectEqual(@as(u24, 0x1f23b8), Crc.hash("123456789"));
968957
969 var c = Crc24FlexrayB.init();958 var c = Crc.init();
970 c.update("1234");959 c.update("1234");
971 c.update("56789");960 c.update("56789");
972 try testing.expectEqual(@as(u24, 0x1f23b8), c.final());961 try testing.expectEqual(@as(u24, 0x1f23b8), c.final());
973}962}
974963
975test "CRC-24/INTERLAKEN" {964test "CRC-24/INTERLAKEN" {
976 const Crc24Interlaken = crc.Crc24Interlaken;965 const Crc = crc.@"CRC-24/INTERLAKEN";
977966
978 try testing.expectEqual(@as(u24, 0xb4f3e6), Crc24Interlaken.hash("123456789"));967 try testing.expectEqual(@as(u24, 0xb4f3e6), Crc.hash("123456789"));
979968
980 var c = Crc24Interlaken.init();969 var c = Crc.init();
981 c.update("1234");970 c.update("1234");
982 c.update("56789");971 c.update("56789");
983 try testing.expectEqual(@as(u24, 0xb4f3e6), c.final());972 try testing.expectEqual(@as(u24, 0xb4f3e6), c.final());
984}973}
985974
986test "CRC-24/LTE-A" {975test "CRC-24/LTE-A" {
987 const Crc24LteA = crc.Crc24LteA;976 const Crc = crc.@"CRC-24/LTE-A";
988977
989 try testing.expectEqual(@as(u24, 0xcde703), Crc24LteA.hash("123456789"));978 try testing.expectEqual(@as(u24, 0xcde703), Crc.hash("123456789"));
990979
991 var c = Crc24LteA.init();980 var c = Crc.init();
992 c.update("1234");981 c.update("1234");
993 c.update("56789");982 c.update("56789");
994 try testing.expectEqual(@as(u24, 0xcde703), c.final());983 try testing.expectEqual(@as(u24, 0xcde703), c.final());
995}984}
996985
997test "CRC-24/LTE-B" {986test "CRC-24/LTE-B" {
998 const Crc24LteB = crc.Crc24LteB;987 const Crc = crc.@"CRC-24/LTE-B";
999988
1000 try testing.expectEqual(@as(u24, 0x23ef52), Crc24LteB.hash("123456789"));989 try testing.expectEqual(@as(u24, 0x23ef52), Crc.hash("123456789"));
1001990
1002 var c = Crc24LteB.init();991 var c = Crc.init();
1003 c.update("1234");992 c.update("1234");
1004 c.update("56789");993 c.update("56789");
1005 try testing.expectEqual(@as(u24, 0x23ef52), c.final());994 try testing.expectEqual(@as(u24, 0x23ef52), c.final());
1006}995}
1007996
1008test "CRC-24/OPENPGP" {997test "CRC-24/OPENPGP" {
1009 const Crc24Openpgp = crc.Crc24Openpgp;998 const Crc = crc.@"CRC-24/OPENPGP";
1010999
1011 try testing.expectEqual(@as(u24, 0x21cf02), Crc24Openpgp.hash("123456789"));1000 try testing.expectEqual(@as(u24, 0x21cf02), Crc.hash("123456789"));
10121001
1013 var c = Crc24Openpgp.init();1002 var c = Crc.init();
1014 c.update("1234");1003 c.update("1234");
1015 c.update("56789");1004 c.update("56789");
1016 try testing.expectEqual(@as(u24, 0x21cf02), c.final());1005 try testing.expectEqual(@as(u24, 0x21cf02), c.final());
1017}1006}
10181007
1019test "CRC-24/OS-9" {1008test "CRC-24/OS-9" {
1020 const Crc24Os9 = crc.Crc24Os9;1009 const Crc = crc.@"CRC-24/OS-9";
10211010
1022 try testing.expectEqual(@as(u24, 0x200fa5), Crc24Os9.hash("123456789"));1011 try testing.expectEqual(@as(u24, 0x200fa5), Crc.hash("123456789"));
10231012
1024 var c = Crc24Os9.init();1013 var c = Crc.init();
1025 c.update("1234");1014 c.update("1234");
1026 c.update("56789");1015 c.update("56789");
1027 try testing.expectEqual(@as(u24, 0x200fa5), c.final());1016 try testing.expectEqual(@as(u24, 0x200fa5), c.final());
1028}1017}
10291018
1030test "CRC-30/CDMA" {1019test "CRC-30/CDMA" {
1031 const Crc30Cdma = crc.Crc30Cdma;1020 const Crc = crc.@"CRC-30/CDMA";
10321021
1033 try testing.expectEqual(@as(u30, 0x04c34abf), Crc30Cdma.hash("123456789"));1022 try testing.expectEqual(@as(u30, 0x04c34abf), Crc.hash("123456789"));
10341023
1035 var c = Crc30Cdma.init();1024 var c = Crc.init();
1036 c.update("1234");1025 c.update("1234");
1037 c.update("56789");1026 c.update("56789");
1038 try testing.expectEqual(@as(u30, 0x04c34abf), c.final());1027 try testing.expectEqual(@as(u30, 0x04c34abf), c.final());
1039}1028}
10401029
1041test "CRC-31/PHILIPS" {1030test "CRC-31/PHILIPS" {
1042 const Crc31Philips = crc.Crc31Philips;1031 const Crc = crc.@"CRC-31/PHILIPS";
10431032
1044 try testing.expectEqual(@as(u31, 0x0ce9e46c), Crc31Philips.hash("123456789"));1033 try testing.expectEqual(@as(u31, 0x0ce9e46c), Crc.hash("123456789"));
10451034
1046 var c = Crc31Philips.init();1035 var c = Crc.init();
1047 c.update("1234");1036 c.update("1234");
1048 c.update("56789");1037 c.update("56789");
1049 try testing.expectEqual(@as(u31, 0x0ce9e46c), c.final());1038 try testing.expectEqual(@as(u31, 0x0ce9e46c), c.final());
1050}1039}
10511040
1052test "CRC-32/AIXM" {1041test "CRC-32/AIXM" {
1053 const Crc32Aixm = crc.Crc32Aixm;1042 const Crc = crc.@"CRC-32/AIXM";
10541043
1055 try testing.expectEqual(@as(u32, 0x3010bf7f), Crc32Aixm.hash("123456789"));1044 try testing.expectEqual(@as(u32, 0x3010bf7f), Crc.hash("123456789"));
10561045
1057 var c = Crc32Aixm.init();1046 var c = Crc.init();
1058 c.update("1234");1047 c.update("1234");
1059 c.update("56789");1048 c.update("56789");
1060 try testing.expectEqual(@as(u32, 0x3010bf7f), c.final());1049 try testing.expectEqual(@as(u32, 0x3010bf7f), c.final());
1061}1050}
10621051
1063test "CRC-32/AUTOSAR" {1052test "CRC-32/AUTOSAR" {
1064 const Crc32Autosar = crc.Crc32Autosar;1053 const Crc = crc.@"CRC-32/AUTOSAR";
10651054
1066 try testing.expectEqual(@as(u32, 0x1697d06a), Crc32Autosar.hash("123456789"));1055 try testing.expectEqual(@as(u32, 0x1697d06a), Crc.hash("123456789"));
10671056
1068 var c = Crc32Autosar.init();1057 var c = Crc.init();
1069 c.update("1234");1058 c.update("1234");
1070 c.update("56789");1059 c.update("56789");
1071 try testing.expectEqual(@as(u32, 0x1697d06a), c.final());1060 try testing.expectEqual(@as(u32, 0x1697d06a), c.final());
1072}1061}
10731062
1074test "CRC-32/BASE91-D" {1063test "CRC-32/BASE91-D" {
1075 const Crc32Base91D = crc.Crc32Base91D;1064 const Crc = crc.@"CRC-32/BASE91-D";
10761065
1077 try testing.expectEqual(@as(u32, 0x87315576), Crc32Base91D.hash("123456789"));1066 try testing.expectEqual(@as(u32, 0x87315576), Crc.hash("123456789"));
10781067
1079 var c = Crc32Base91D.init();1068 var c = Crc.init();
1080 c.update("1234");1069 c.update("1234");
1081 c.update("56789");1070 c.update("56789");
1082 try testing.expectEqual(@as(u32, 0x87315576), c.final());1071 try testing.expectEqual(@as(u32, 0x87315576), c.final());
1083}1072}
10841073
1085test "CRC-32/BZIP2" {1074test "CRC-32/BZIP2" {
1086 const Crc32Bzip2 = crc.Crc32Bzip2;1075 const Crc = crc.@"CRC-32/BZIP2";
10871076
1088 try testing.expectEqual(@as(u32, 0xfc891918), Crc32Bzip2.hash("123456789"));1077 try testing.expectEqual(@as(u32, 0xfc891918), Crc.hash("123456789"));
10891078
1090 var c = Crc32Bzip2.init();1079 var c = Crc.init();
1091 c.update("1234");1080 c.update("1234");
1092 c.update("56789");1081 c.update("56789");
1093 try testing.expectEqual(@as(u32, 0xfc891918), c.final());1082 try testing.expectEqual(@as(u32, 0xfc891918), c.final());
1094}1083}
10951084
1096test "CRC-32/CD-ROM-EDC" {1085test "CRC-32/CD-ROM-EDC" {
1097 const Crc32CdRomEdc = crc.Crc32CdRomEdc;1086 const Crc = crc.@"CRC-32/CD-ROM-EDC";
10981087
1099 try testing.expectEqual(@as(u32, 0x6ec2edc4), Crc32CdRomEdc.hash("123456789"));1088 try testing.expectEqual(@as(u32, 0x6ec2edc4), Crc.hash("123456789"));
11001089
1101 var c = Crc32CdRomEdc.init();1090 var c = Crc.init();
1102 c.update("1234");1091 c.update("1234");
1103 c.update("56789");1092 c.update("56789");
1104 try testing.expectEqual(@as(u32, 0x6ec2edc4), c.final());1093 try testing.expectEqual(@as(u32, 0x6ec2edc4), c.final());
1105}1094}
11061095
1107test "CRC-32/CKSUM" {1096test "CRC-32/CKSUM" {
1108 const Crc32Cksum = crc.Crc32Cksum;1097 const Crc = crc.@"CRC-32/CKSUM";
11091098
1110 try testing.expectEqual(@as(u32, 0x765e7680), Crc32Cksum.hash("123456789"));1099 try testing.expectEqual(@as(u32, 0x765e7680), Crc.hash("123456789"));
11111100
1112 var c = Crc32Cksum.init();1101 var c = Crc.init();
1113 c.update("1234");1102 c.update("1234");
1114 c.update("56789");1103 c.update("56789");
1115 try testing.expectEqual(@as(u32, 0x765e7680), c.final());1104 try testing.expectEqual(@as(u32, 0x765e7680), c.final());
1116}1105}
11171106
1107test "CRC-32/ISCSI" {
1108 const Crc = crc.@"CRC-32/ISCSI";
1109
1110 try testing.expectEqual(@as(u32, 0xe3069283), Crc.hash("123456789"));
1111
1112 var c = Crc.init();
1113 c.update("1234");
1114 c.update("56789");
1115 try testing.expectEqual(@as(u32, 0xe3069283), c.final());
1116}
1117
1118test "CRC-32/ISO-HDLC" {1118test "CRC-32/ISO-HDLC" {
1119 const Crc32IsoHdlc = crc.Crc32IsoHdlc;1119 const Crc = crc.@"CRC-32/ISO-HDLC";
11201120
1121 try testing.expectEqual(@as(u32, 0xcbf43926), Crc32IsoHdlc.hash("123456789"));1121 try testing.expectEqual(@as(u32, 0xcbf43926), Crc.hash("123456789"));
11221122
1123 var c = Crc32IsoHdlc.init();1123 var c = Crc.init();
1124 c.update("1234");1124 c.update("1234");
1125 c.update("56789");1125 c.update("56789");
1126 try testing.expectEqual(@as(u32, 0xcbf43926), c.final());1126 try testing.expectEqual(@as(u32, 0xcbf43926), c.final());
1127}1127}
11281128
1129test "CRC-32/JAMCRC" {1129test "CRC-32/JAMCRC" {
1130 const Crc32Jamcrc = crc.Crc32Jamcrc;1130 const Crc = crc.@"CRC-32/JAMCRC";
11311131
1132 try testing.expectEqual(@as(u32, 0x340bc6d9), Crc32Jamcrc.hash("123456789"));1132 try testing.expectEqual(@as(u32, 0x340bc6d9), Crc.hash("123456789"));
11331133
1134 var c = Crc32Jamcrc.init();1134 var c = Crc.init();
1135 c.update("1234");1135 c.update("1234");
1136 c.update("56789");1136 c.update("56789");
1137 try testing.expectEqual(@as(u32, 0x340bc6d9), c.final());1137 try testing.expectEqual(@as(u32, 0x340bc6d9), c.final());
1138}1138}
11391139
1140test "CRC-32/KOOPMAN" {1140test "CRC-32/KOOPMAN" {
1141 const Crc32Koopman = crc.Crc32Koopman;1141 const Crc = crc.@"CRC-32/KOOPMAN";
11421142
1143 try testing.expectEqual(@as(u32, 0x2d3dd0ae), Crc32Koopman.hash("123456789"));1143 try testing.expectEqual(@as(u32, 0x2d3dd0ae), Crc.hash("123456789"));
11441144
1145 var c = Crc32Koopman.init();1145 var c = Crc.init();
1146 c.update("1234");1146 c.update("1234");
1147 c.update("56789");1147 c.update("56789");
1148 try testing.expectEqual(@as(u32, 0x2d3dd0ae), c.final());1148 try testing.expectEqual(@as(u32, 0x2d3dd0ae), c.final());
1149}1149}
11501150
1151test "CRC-32/MEF" {1151test "CRC-32/MEF" {
1152 const Crc32Mef = crc.Crc32Mef;1152 const Crc = crc.@"CRC-32/MEF";
11531153
1154 try testing.expectEqual(@as(u32, 0xd2c22f51), Crc32Mef.hash("123456789"));1154 try testing.expectEqual(@as(u32, 0xd2c22f51), Crc.hash("123456789"));
11551155
1156 var c = Crc32Mef.init();1156 var c = Crc.init();
1157 c.update("1234");1157 c.update("1234");
1158 c.update("56789");1158 c.update("56789");
1159 try testing.expectEqual(@as(u32, 0xd2c22f51), c.final());1159 try testing.expectEqual(@as(u32, 0xd2c22f51), c.final());
1160}1160}
11611161
1162test "CRC-32/MPEG-2" {1162test "CRC-32/MPEG-2" {
1163 const Crc32Mpeg2 = crc.Crc32Mpeg2;1163 const Crc = crc.@"CRC-32/MPEG-2";
11641164
1165 try testing.expectEqual(@as(u32, 0x0376e6e7), Crc32Mpeg2.hash("123456789"));1165 try testing.expectEqual(@as(u32, 0x0376e6e7), Crc.hash("123456789"));
11661166
1167 var c = Crc32Mpeg2.init();1167 var c = Crc.init();
1168 c.update("1234");1168 c.update("1234");
1169 c.update("56789");1169 c.update("56789");
1170 try testing.expectEqual(@as(u32, 0x0376e6e7), c.final());1170 try testing.expectEqual(@as(u32, 0x0376e6e7), c.final());
1171}1171}
11721172
1173test "CRC-32/XFER" {1173test "CRC-32/XFER" {
1174 const Crc32Xfer = crc.Crc32Xfer;1174 const Crc = crc.@"CRC-32/XFER";
11751175
1176 try testing.expectEqual(@as(u32, 0xbd0be338), Crc32Xfer.hash("123456789"));1176 try testing.expectEqual(@as(u32, 0xbd0be338), Crc.hash("123456789"));
11771177
1178 var c = Crc32Xfer.init();1178 var c = Crc.init();
1179 c.update("1234");1179 c.update("1234");
1180 c.update("56789");1180 c.update("56789");
1181 try testing.expectEqual(@as(u32, 0xbd0be338), c.final());1181 try testing.expectEqual(@as(u32, 0xbd0be338), c.final());
1182}1182}
11831183
1184test "CRC-40/GSM" {1184test "CRC-40/GSM" {
1185 const Crc40Gsm = crc.Crc40Gsm;1185 const Crc = crc.@"CRC-40/GSM";
11861186
1187 try testing.expectEqual(@as(u40, 0xd4164fc646), Crc40Gsm.hash("123456789"));1187 try testing.expectEqual(@as(u40, 0xd4164fc646), Crc.hash("123456789"));
11881188
1189 var c = Crc40Gsm.init();1189 var c = Crc.init();
1190 c.update("1234");1190 c.update("1234");
1191 c.update("56789");1191 c.update("56789");
1192 try testing.expectEqual(@as(u40, 0xd4164fc646), c.final());1192 try testing.expectEqual(@as(u40, 0xd4164fc646), c.final());
1193}1193}
11941194
1195test "CRC-64/ECMA-182" {1195test "CRC-64/ECMA-182" {
1196 const Crc64Ecma182 = crc.Crc64Ecma182;1196 const Crc = crc.@"CRC-64/ECMA-182";
11971197
1198 try testing.expectEqual(@as(u64, 0x6c40df5f0b497347), Crc64Ecma182.hash("123456789"));1198 try testing.expectEqual(@as(u64, 0x6c40df5f0b497347), Crc.hash("123456789"));
11991199
1200 var c = Crc64Ecma182.init();1200 var c = Crc.init();
1201 c.update("1234");1201 c.update("1234");
1202 c.update("56789");1202 c.update("56789");
1203 try testing.expectEqual(@as(u64, 0x6c40df5f0b497347), c.final());1203 try testing.expectEqual(@as(u64, 0x6c40df5f0b497347), c.final());
1204}1204}
12051205
1206test "CRC-64/GO-ISO" {1206test "CRC-64/GO-ISO" {
1207 const Crc64GoIso = crc.Crc64GoIso;1207 const Crc = crc.@"CRC-64/GO-ISO";
12081208
1209 try testing.expectEqual(@as(u64, 0xb90956c775a41001), Crc64GoIso.hash("123456789"));1209 try testing.expectEqual(@as(u64, 0xb90956c775a41001), Crc.hash("123456789"));
12101210
1211 var c = Crc64GoIso.init();1211 var c = Crc.init();
1212 c.update("1234");1212 c.update("1234");
1213 c.update("56789");1213 c.update("56789");
1214 try testing.expectEqual(@as(u64, 0xb90956c775a41001), c.final());1214 try testing.expectEqual(@as(u64, 0xb90956c775a41001), c.final());
1215}1215}
12161216
1217test "CRC-64/MS" {1217test "CRC-64/MS" {
1218 const Crc64Ms = crc.Crc64Ms;1218 const Crc = crc.@"CRC-64/MS";
12191219
1220 try testing.expectEqual(@as(u64, 0x75d4b74f024eceea), Crc64Ms.hash("123456789"));1220 try testing.expectEqual(@as(u64, 0x75d4b74f024eceea), Crc.hash("123456789"));
12211221
1222 var c = Crc64Ms.init();1222 var c = Crc.init();
1223 c.update("1234");1223 c.update("1234");
1224 c.update("56789");1224 c.update("56789");
1225 try testing.expectEqual(@as(u64, 0x75d4b74f024eceea), c.final());1225 try testing.expectEqual(@as(u64, 0x75d4b74f024eceea), c.final());
1226}1226}
12271227
1228test "CRC-64/REDIS" {1228test "CRC-64/REDIS" {
1229 const Crc64Redis = crc.Crc64Redis;1229 const Crc = crc.@"CRC-64/REDIS";
12301230
1231 try testing.expectEqual(@as(u64, 0xe9c6d914c4b8d9ca), Crc64Redis.hash("123456789"));1231 try testing.expectEqual(@as(u64, 0xe9c6d914c4b8d9ca), Crc.hash("123456789"));
12321232
1233 var c = Crc64Redis.init();1233 var c = Crc.init();
1234 c.update("1234");1234 c.update("1234");
1235 c.update("56789");1235 c.update("56789");
1236 try testing.expectEqual(@as(u64, 0xe9c6d914c4b8d9ca), c.final());1236 try testing.expectEqual(@as(u64, 0xe9c6d914c4b8d9ca), c.final());
1237}1237}
12381238
1239test "CRC-64/WE" {1239test "CRC-64/WE" {
1240 const Crc64We = crc.Crc64We;1240 const Crc = crc.@"CRC-64/WE";
12411241
1242 try testing.expectEqual(@as(u64, 0x62ec59e3f1a4f00a), Crc64We.hash("123456789"));1242 try testing.expectEqual(@as(u64, 0x62ec59e3f1a4f00a), Crc.hash("123456789"));
12431243
1244 var c = Crc64We.init();1244 var c = Crc.init();
1245 c.update("1234");1245 c.update("1234");
1246 c.update("56789");1246 c.update("56789");
1247 try testing.expectEqual(@as(u64, 0x62ec59e3f1a4f00a), c.final());1247 try testing.expectEqual(@as(u64, 0x62ec59e3f1a4f00a), c.final());
1248}1248}
12491249
1250test "CRC-64/XZ" {1250test "CRC-64/XZ" {
1251 const Crc64Xz = crc.Crc64Xz;1251 const Crc = crc.@"CRC-64/XZ";
12521252
1253 try testing.expectEqual(@as(u64, 0x995dc9bbdf1939fa), Crc64Xz.hash("123456789"));1253 try testing.expectEqual(@as(u64, 0x995dc9bbdf1939fa), Crc.hash("123456789"));
12541254
1255 var c = Crc64Xz.init();1255 var c = Crc.init();
1256 c.update("1234");1256 c.update("1234");
1257 c.update("56789");1257 c.update("56789");
1258 try testing.expectEqual(@as(u64, 0x995dc9bbdf1939fa), c.final());1258 try testing.expectEqual(@as(u64, 0x995dc9bbdf1939fa), c.final());
1259}1259}
12601260
1261test "CRC-82/DARC" {1261test "CRC-82/DARC" {
1262 const Crc82Darc = crc.Crc82Darc;1262 const Crc = crc.@"CRC-82/DARC";
12631263
1264 try testing.expectEqual(@as(u82, 0x09ea83f625023801fd612), Crc82Darc.hash("123456789"));1264 try testing.expectEqual(@as(u82, 0x09ea83f625023801fd612), Crc.hash("123456789"));
12651265
1266 var c = Crc82Darc.init();1266 var c = Crc.init();
1267 c.update("1234");1267 c.update("1234");
1268 c.update("56789");1268 c.update("56789");
1269 try testing.expectEqual(@as(u82, 0x09ea83f625023801fd612), c.final());1269 try testing.expectEqual(@as(u82, 0x09ea83f625023801fd612), c.final());
src/link/Coff.zig+2-1
...@@ -7,6 +7,7 @@ const std = @import("std");...@@ -7,6 +7,7 @@ const std = @import("std");
7const Io = std.Io;7const Io = std.Io;
8const assert = std.debug.assert;8const assert = std.debug.assert;
9const log = std.log.scoped(.link);9const log = std.log.scoped(.link);
10const Crc32 = std.hash.crc.@"CRC-32/JAMCRC";
1011
11const codegen = @import("../codegen.zig");12const codegen = @import("../codegen.zig");
12const Compilation = @import("../Compilation.zig");13const Compilation = @import("../Compilation.zig");
...@@ -4599,7 +4600,7 @@ fn loadObject(...@@ -4599,7 +4600,7 @@ fn loadObject(
4599 const sym = si.get(coff);4600 const sym = si.get(coff);
4600 const existing_crc = switch (coff.getNode(sym.ni)) {4601 const existing_crc = switch (coff.getNode(sym.ni)) {
4601 .input_section => |isi| isi.inputSection(coff).crc,4602 .input_section => |isi| isi.inputSection(coff).crc,
4602 else => std.hash.crc.Crc32Jamcrc.hash(sym.ni.sliceConst(&coff.mf)),4603 else => Crc32.hash(sym.ni.sliceConst(&coff.mf)),
4603 };4604 };
46044605
4605 if (existing_crc == section.comdat_crc) {4606 if (existing_crc == section.comdat_crc) {
tools/crc/catalog.txt+1-2
...@@ -97,8 +97,7 @@ width=32 poly=0xa833982b init=0xffffffff refin=true refout=true xorout=0xff...@@ -97,8 +97,7 @@ width=32 poly=0xa833982b init=0xffffffff refin=true refout=true xorout=0xff
97width=32 poly=0x04c11db7 init=0xffffffff refin=false refout=false xorout=0xffffffff check=0xfc891918 residue=0xc704dd7b name="CRC-32/BZIP2"97width=32 poly=0x04c11db7 init=0xffffffff refin=false refout=false xorout=0xffffffff check=0xfc891918 residue=0xc704dd7b name="CRC-32/BZIP2"
98width=32 poly=0x8001801b init=0x00000000 refin=true refout=true xorout=0x00000000 check=0x6ec2edc4 residue=0x00000000 name="CRC-32/CD-ROM-EDC"98width=32 poly=0x8001801b init=0x00000000 refin=true refout=true xorout=0x00000000 check=0x6ec2edc4 residue=0x00000000 name="CRC-32/CD-ROM-EDC"
99width=32 poly=0x04c11db7 init=0x00000000 refin=false refout=false xorout=0xffffffff check=0x765e7680 residue=0xc704dd7b name="CRC-32/CKSUM"99width=32 poly=0x04c11db7 init=0x00000000 refin=false refout=false xorout=0xffffffff check=0x765e7680 residue=0xc704dd7b name="CRC-32/CKSUM"
100# CRC-32C implementation is defined manually, since it has an accelerated variant.100width=32 poly=0x1edc6f41 init=0xffffffff refin=true refout=true xorout=0xffffffff check=0xe3069283 residue=0xb798b438 name="CRC-32/ISCSI"
101# width=32 poly=0x1edc6f41 init=0xffffffff refin=true refout=true xorout=0xffffffff check=0xe3069283 residue=0xb798b438 name="CRC-32/ISCSI"
102width=32 poly=0x04c11db7 init=0xffffffff refin=true refout=true xorout=0xffffffff check=0xcbf43926 residue=0xdebb20e3 name="CRC-32/ISO-HDLC"101width=32 poly=0x04c11db7 init=0xffffffff refin=true refout=true xorout=0xffffffff check=0xcbf43926 residue=0xdebb20e3 name="CRC-32/ISO-HDLC"
103width=32 poly=0x04c11db7 init=0xffffffff refin=true refout=true xorout=0x00000000 check=0x340bc6d9 residue=0x00000000 name="CRC-32/JAMCRC"102width=32 poly=0x04c11db7 init=0xffffffff refin=true refout=true xorout=0x00000000 check=0x340bc6d9 residue=0x00000000 name="CRC-32/JAMCRC"
104width=32 poly=0x741b8cd7 init=0xffffffff refin=true refout=true xorout=0xffffffff check=0x2d3dd0ae residue=0x00000000 name="CRC-32/KOOPMAN"103width=32 poly=0x741b8cd7 init=0xffffffff refin=true refout=true xorout=0xffffffff check=0x2d3dd0ae residue=0x00000000 name="CRC-32/KOOPMAN"
tools/update_crc_catalog.zig+149-87
...@@ -2,7 +2,6 @@ const std = @import("std");...@@ -2,7 +2,6 @@ const std = @import("std");
2const Io = std.Io;2const Io = std.Io;
3const Dir = std.Io.Dir;3const Dir = std.Io.Dir;
4const mem = std.mem;4const mem = std.mem;
5const ascii = std.ascii;
65
7const catalog_txt = @embedFile("crc/catalog.txt");6const catalog_txt = @embedFile("crc/catalog.txt");
87
...@@ -32,6 +31,7 @@ fn @"i like cheese"(arena: std.mem.Allocator, io: Io, args: []const []const u8)...@@ -32,6 +31,7 @@ fn @"i like cheese"(arena: std.mem.Allocator, io: Io, args: []const []const u8)
3231
33 var zig_code_file = try hash_target_dir.createFile(io, "crc.zig", .{});32 var zig_code_file = try hash_target_dir.createFile(io, "crc.zig", .{});
34 defer zig_code_file.close(io);33 defer zig_code_file.close(io);
34
35 var zig_code_file_buffer: [4096]u8 = undefined;35 var zig_code_file_buffer: [4096]u8 = undefined;
36 var zig_code_file_writer = zig_code_file.writer(io, &zig_code_file_buffer);36 var zig_code_file_writer = zig_code_file.writer(io, &zig_code_file_buffer);
37 const code_writer = &zig_code_file_writer.interface;37 const code_writer = &zig_code_file_writer.interface;
...@@ -40,34 +40,12 @@ fn @"i like cheese"(arena: std.mem.Allocator, io: Io, args: []const []const u8)...@@ -40,34 +40,12 @@ fn @"i like cheese"(arena: std.mem.Allocator, io: Io, args: []const []const u8)
40 \\//! This file is auto-generated by tools/update_crc_catalog.zig.40 \\//! This file is auto-generated by tools/update_crc_catalog.zig.
41 \\41 \\
42 \\const builtin = @import("builtin");42 \\const builtin = @import("builtin");
43 \\const impl = @import("crc/impl.zig");
44 \\
45 \\pub const Crc = impl.Crc;
46 \\pub const Polynomial = impl.Polynomial;
47 \\pub const Crc32WithPoly = impl.Crc32WithPoly;
48 \\pub const Crc32SmallWithPoly = impl.Crc32SmallWithPoly;
49 \\
50 \\pub const Crc32 = Crc32IsoHdlc;
51 \\
52 \\test {
53 \\ _ = @import("crc/test.zig");
54 \\}
55 \\
56 \\pub const Crc32Iscsi = switch (builtin.cpu.hasAll(.x86, &.{ .@"64bit", .crc32 })) {
57 \\ true => @import("crc/Crc32c.zig"),
58 \\ else => Crc(u32, .{
59 \\ .polynomial = 0x1edc6f41,
60 \\ .initial = 0xffffffff,
61 \\ .reflect_input = true,
62 \\ .reflect_output = true,
63 \\ .xor_output = 0xffffffff,
64 \\ }),
65 \\};
66 \\43 \\
67 );44 );
6845
69 var zig_test_file = try crc_target_dir.createFile(io, "test.zig", .{});46 var zig_test_file = try crc_target_dir.createFile(io, "test.zig", .{});
70 defer zig_test_file.close(io);47 defer zig_test_file.close(io);
48
71 var zig_test_file_buffer: [4096]u8 = undefined;49 var zig_test_file_buffer: [4096]u8 = undefined;
72 var zig_test_file_writer = zig_test_file.writer(io, &zig_test_file_buffer);50 var zig_test_file_writer = zig_test_file.writer(io, &zig_test_file_buffer);
73 const test_writer = &zig_test_file_writer.interface;51 const test_writer = &zig_test_file_writer.interface;
...@@ -81,35 +59,24 @@ fn @"i like cheese"(arena: std.mem.Allocator, io: Io, args: []const []const u8)...@@ -81,35 +59,24 @@ fn @"i like cheese"(arena: std.mem.Allocator, io: Io, args: []const []const u8)
81 \\const crc = @import("../crc.zig");59 \\const crc = @import("../crc.zig");
82 \\60 \\
83 \\test "crc32 ieee regression" {61 \\test "crc32 ieee regression" {
84 \\ const crc32 = crc.Crc32IsoHdlc;62 \\ const Crc = crc.@"CRC-32/ISO-HDLC";
85 \\ try testing.expectEqual(crc32.hash(""), 0x00000000);63 \\ try testing.expectEqual(Crc.hash(""), 0x00000000);
86 \\ try testing.expectEqual(crc32.hash("a"), 0xe8b7be43);64 \\ try testing.expectEqual(Crc.hash("a"), 0xe8b7be43);
87 \\ try testing.expectEqual(crc32.hash("abc"), 0x352441c2);65 \\ try testing.expectEqual(Crc.hash("abc"), 0x352441c2);
88 \\}66 \\}
89 \\67 \\
90 \\test "crc32 castagnoli regression" {68 \\test "crc32 castagnoli regression" {
91 \\ const crc32 = crc.Crc32Iscsi;69 \\ const Crc = crc.@"CRC-32/ISCSI";
92 \\ try testing.expectEqual(crc32.hash(""), 0x00000000);70 \\ try testing.expectEqual(Crc.hash(""), 0x00000000);
93 \\ try testing.expectEqual(crc32.hash("a"), 0xc1d04330);71 \\ try testing.expectEqual(Crc.hash("a"), 0xc1d04330);
94 \\ try testing.expectEqual(crc32.hash("abc"), 0x364b3fb7);72 \\ try testing.expectEqual(Crc.hash("abc"), 0x364b3fb7);
95 \\}73 \\}
96 \\74 \\
97 \\test "crc32 koopman regression" {75 \\test "crc32 koopman regression" {
98 \\ const crc32 = crc.Crc32Koopman;76 \\ const Crc = crc.@"CRC-32/KOOPMAN";
99 \\ try testing.expectEqual(crc32.hash(""), 0x00000000);77 \\ try testing.expectEqual(Crc.hash(""), 0x00000000);
100 \\ try testing.expectEqual(crc32.hash("a"), 0x0da2aa8a);78 \\ try testing.expectEqual(Crc.hash("a"), 0x0da2aa8a);
101 \\ try testing.expectEqual(crc32.hash("abc"), 0xba2322ac);79 \\ try testing.expectEqual(Crc.hash("abc"), 0xba2322ac);
102 \\}
103 \\
104 \\test "CRC-32/ISCSI" {
105 \\ const Crc32Iscsi = crc.Crc32Iscsi;
106 \\
107 \\ try testing.expectEqual(@as(u32, 0xe3069283), Crc32Iscsi.hash("123456789"));
108 \\
109 \\ var c = Crc32Iscsi.init();
110 \\ c.update("1234");
111 \\ c.update("56789");
112 \\ try testing.expectEqual(@as(u32, 0xe3069283), c.final());
113 \\}80 \\}
114 \\81 \\
115 );82 );
...@@ -158,59 +125,154 @@ fn @"i like cheese"(arena: std.mem.Allocator, io: Io, args: []const []const u8)...@@ -158,59 +125,154 @@ fn @"i like cheese"(arena: std.mem.Allocator, io: Io, args: []const []const u8)
158 }125 }
159 }126 }
160127
161 const snakecase = try ascii.allocLowerString(arena, name);128 if (mem.eql(u8, name, "CRC-32/ISCSI")) {
162 defer arena.free(snakecase);129 try code_writer.print(
163130 \\
164 _ = mem.replace(u8, snakecase, "-", "_", snakecase);131 \\pub const {f} = if (builtin.cpu.hasAll(.x86, &.{{ .@"64bit", .crc32 }}))
165 _ = mem.replace(u8, snakecase, "/", "_", snakecase);132 \\ @import("crc/Crc32c.zig")
166133 \\else
167 var buf = try std.array_list.Managed(u8).initCapacity(arena, snakecase.len);134 \\ Generic(u{s}, .{{
168 defer buf.deinit();135 \\ .polynomial = {s},
169136 \\ .initial = {s},
170 var prev: u8 = 0;137 \\ .reflect_input = {s},
171 for (snakecase, 0..) |c, i| {138 \\ .reflect_output = {s},
172 if (c == '_') {139 \\ .xor_output = {s},
173 // do nothing140 \\ }});
174 } else if (i == 0) {141 \\
175 buf.appendAssumeCapacity(ascii.toUpper(c));142 , .{ std.zig.fmtId(name), width, poly, init, refin, refout, xorout });
176 } else if (prev == '_') {143 } else {
177 buf.appendAssumeCapacity(ascii.toUpper(c));144 try code_writer.print(
178 } else {145 \\
179 buf.appendAssumeCapacity(c);146 \\pub const {f} = Generic(u{s}, .{{
180 }147 \\ .polynomial = {s},
181 prev = c;148 \\ .initial = {s},
149 \\ .reflect_input = {s},
150 \\ .reflect_output = {s},
151 \\ .xor_output = {s},
152 \\}});
153 \\
154 , .{ std.zig.fmtId(name), width, poly, init, refin, refout, xorout });
182 }155 }
183156
184 const camelcase = buf.items;157 try test_writer.print(
185
186 try code_writer.writeAll(try std.fmt.allocPrint(arena,
187 \\
188 \\pub const {s} = Crc(u{s}, .{{
189 \\ .polynomial = {s},
190 \\ .initial = {s},
191 \\ .reflect_input = {s},
192 \\ .reflect_output = {s},
193 \\ .xor_output = {s},
194 \\}});
195 \\
196 , .{ camelcase, width, poly, init, refin, refout, xorout }));
197
198 try test_writer.writeAll(try std.fmt.allocPrint(arena,
199 \\158 \\
200 \\test "{0s}" {{159 \\test "{0s}" {{
201 \\ const {1s} = crc.{1s};160 \\ const Crc = crc.{1f};
202 \\161 \\
203 \\ try testing.expectEqual(@as(u{2s}, {3s}), {1s}.hash("123456789"));162 \\ try testing.expectEqual(@as(u{2s}, {3s}), Crc.hash("123456789"));
204 \\163 \\
205 \\ var c = {1s}.init();164 \\ var c = Crc.init();
206 \\ c.update("1234");165 \\ c.update("1234");
207 \\ c.update("56789");166 \\ c.update("56789");
208 \\ try testing.expectEqual(@as(u{2s}, {3s}), c.final());167 \\ try testing.expectEqual(@as(u{2s}, {3s}), c.final());
209 \\}}168 \\}}
210 \\169 \\
211 , .{ name, camelcase, width, check }));170 , .{ name, std.zig.fmtId(name), width, check });
212 }171 }
213172
173 try code_writer.writeAll(
174 \\
175 \\pub fn Algorithm(comptime W: type) type {
176 \\ return struct {
177 \\ polynomial: W,
178 \\ initial: W,
179 \\ reflect_input: bool,
180 \\ reflect_output: bool,
181 \\ xor_output: W,
182 \\ };
183 \\}
184 \\
185 \\pub fn Generic(comptime W: type, comptime algorithm: Algorithm(W)) type {
186 \\ return struct {
187 \\ const Self = @This();
188 \\ const I = if (@bitSizeOf(W) < 8) u8 else W;
189 \\ const lookup_table = blk: {
190 \\ @setEvalBranchQuota(2500);
191 \\ const poly = reflect(algorithm.polynomial);
192 \\ var table: [256]I = undefined;
193 \\ for (&table, 0..) |*e, i| {
194 \\ var crc: I = i;
195 \\ if (algorithm.reflect_input) {
196 \\ var j: usize = 0;
197 \\ while (j < 8) : (j += 1) {
198 \\ crc = (crc >> 1) ^ ((crc & 1) * poly);
199 \\ }
200 \\ } else {
201 \\ crc <<= @bitSizeOf(I) - 8;
202 \\ var j: usize = 0;
203 \\ while (j < 8) : (j += 1) {
204 \\ crc = (crc << 1) ^ (((crc >> (@bitSizeOf(I) - 1)) & 1) * poly);
205 \\ }
206 \\ }
207 \\ e.* = crc;
208 \\ }
209 \\ break :blk table;
210 \\ };
211 \\
212 \\ crc: I,
213 \\
214 \\ pub fn init() Self {
215 \\ const initial = reflect(algorithm.initial);
216 \\ return .{ .crc = initial };
217 \\ }
218 \\
219 \\ inline fn tableEntry(index: I) I {
220 \\ const short: u8 = @truncate(index);
221 \\ return lookup_table[short];
222 \\ }
223 \\
224 \\ pub fn update(self: *Self, bytes: []const u8) void {
225 \\ var i: usize = 0;
226 \\ if (@bitSizeOf(I) <= 8) {
227 \\ while (i < bytes.len) : (i += 1) {
228 \\ self.crc = tableEntry(self.crc ^ bytes[i]);
229 \\ }
230 \\ } else if (algorithm.reflect_input) {
231 \\ while (i < bytes.len) : (i += 1) {
232 \\ const table_index = self.crc ^ bytes[i];
233 \\ self.crc = tableEntry(table_index) ^ (self.crc >> 8);
234 \\ }
235 \\ } else {
236 \\ while (i < bytes.len) : (i += 1) {
237 \\ const table_index = (self.crc >> (@bitSizeOf(I) - 8)) ^ bytes[i];
238 \\ self.crc = tableEntry(table_index) ^ (self.crc << 8);
239 \\ }
240 \\ }
241 \\ }
242 \\
243 \\ pub fn final(self: Self) W {
244 \\ var c = self.crc;
245 \\ if (algorithm.reflect_input != algorithm.reflect_output) {
246 \\ c = @bitReverse(c);
247 \\ }
248 \\ if (!algorithm.reflect_output) {
249 \\ c >>= @bitSizeOf(I) - @bitSizeOf(W);
250 \\ }
251 \\ return @intCast(c ^ algorithm.xor_output);
252 \\ }
253 \\
254 \\ pub fn hash(bytes: []const u8) W {
255 \\ var c = Self.init();
256 \\ c.update(bytes);
257 \\ return c.final();
258 \\ }
259 \\
260 \\ fn reflect(x: I) I {
261 \\ const offset = @bitSizeOf(I) - @bitSizeOf(W);
262 \\ if (algorithm.reflect_input)
263 \\ return @bitReverse(x) >> offset
264 \\ else
265 \\ return x << offset;
266 \\ }
267 \\ };
268 \\}
269 \\
270 \\test {
271 \\ _ = @import("crc/test.zig");
272 \\}
273 \\
274 );
275
214 try code_writer.flush();276 try code_writer.flush();
215 try test_writer.flush();277 try test_writer.flush();
216}278}