authorgravatar for bblack@wikimedia.orgBrandon Black <bblack@wikimedia.org> 2024-04-06 10:27:59-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-04-11 14:42:04-07:00
log271d8964468529a1c67b3b1c6a4dd69693e98500
tree401a41299c3b664675c15b6f566153f05d3cc64a
parent786876c05efc55ecc9c9c05e89f754f813860436

std.hash.crc: get rid of usingnamespace

This flips things around such that std/hash/crc.zig is generated by the catalog-based generation tool, and the real code that used to be in that file is moved out to std/hash/crc/impl.zig. The generated tests are moved to std/hash/crc/test.zig. By going this route, we eliminate the need for usingnamespace without changing anything for callers of these interfaces. The Crc32 tests are simply added to the fixed part of the generated output and compactified a bit. This was the second-to-last usage of usingnamespace left in std.

6 files changed, 2440 insertions(+), 2426 deletions(-)

lib/std/hash/crc.zig+903-277
...@@ -1,285 +1,911 @@...@@ -1,285 +1,911 @@
1// There are two implementations of CRC32 implemented with the following key characteristics:1//! This file is auto-generated by tools/update_crc_catalog.zig.
2//
3// - Crc32WithPoly uses 8Kb of tables but is ~10x faster than the small method.
4//
5// - Crc32SmallWithPoly uses only 64 bytes of memory but is slower. Be aware that this is
6// still moderately fast just slow relative to the slicing approach.
7
8const std = @import("std");
9const builtin = @import("builtin");
10const debug = std.debug;
11const testing = std.testing;
12
13pub usingnamespace @import("crc/catalog.zig");
14
15pub fn Algorithm(comptime W: type) type {
16 return struct {
17 polynomial: W,
18 initial: W,
19 reflect_input: bool,
20 reflect_output: bool,
21 xor_output: W,
22 };
23}
242
25pub fn Crc(comptime W: type, comptime algorithm: Algorithm(W)) type {3const impl = @import("crc/impl.zig");
26 return struct {
27 const Self = @This();
28 const I = if (@bitSizeOf(W) < 8) u8 else W;
29 const lookup_table = blk: {
30 @setEvalBranchQuota(2500);
31
32 const poly = if (algorithm.reflect_input)
33 @bitReverse(@as(I, algorithm.polynomial)) >> (@bitSizeOf(I) - @bitSizeOf(W))
34 else
35 @as(I, algorithm.polynomial) << (@bitSizeOf(I) - @bitSizeOf(W));
36
37 var table: [256]I = undefined;
38 for (&table, 0..) |*e, i| {
39 var crc: I = i;
40 if (algorithm.reflect_input) {
41 var j: usize = 0;
42 while (j < 8) : (j += 1) {
43 crc = (crc >> 1) ^ ((crc & 1) * poly);
44 }
45 } else {
46 crc <<= @bitSizeOf(I) - 8;
47 var j: usize = 0;
48 while (j < 8) : (j += 1) {
49 crc = (crc << 1) ^ (((crc >> (@bitSizeOf(I) - 1)) & 1) * poly);
50 }
51 }
52 e.* = crc;
53 }
54 break :blk table;
55 };
56
57 crc: I,
58
59 pub fn init() Self {
60 const initial = if (algorithm.reflect_input)
61 @bitReverse(@as(I, algorithm.initial)) >> (@bitSizeOf(I) - @bitSizeOf(W))
62 else
63 @as(I, algorithm.initial) << (@bitSizeOf(I) - @bitSizeOf(W));
64 return Self{ .crc = initial };
65 }
66
67 inline fn tableEntry(index: I) I {
68 return lookup_table[@as(u8, @intCast(index & 0xFF))];
69 }
70
71 pub fn update(self: *Self, bytes: []const u8) void {
72 var i: usize = 0;
73 if (@bitSizeOf(I) <= 8) {
74 while (i < bytes.len) : (i += 1) {
75 self.crc = tableEntry(self.crc ^ bytes[i]);
76 }
77 } else if (algorithm.reflect_input) {
78 while (i < bytes.len) : (i += 1) {
79 const table_index = self.crc ^ bytes[i];
80 self.crc = tableEntry(table_index) ^ (self.crc >> 8);
81 }
82 } else {
83 while (i < bytes.len) : (i += 1) {
84 const table_index = (self.crc >> (@bitSizeOf(I) - 8)) ^ bytes[i];
85 self.crc = tableEntry(table_index) ^ (self.crc << 8);
86 }
87 }
88 }
89
90 pub fn final(self: Self) W {
91 var c = self.crc;
92 if (algorithm.reflect_input != algorithm.reflect_output) {
93 c = @bitReverse(c);
94 }
95 if (!algorithm.reflect_output) {
96 c >>= @bitSizeOf(I) - @bitSizeOf(W);
97 }
98 return @as(W, @intCast(c ^ algorithm.xor_output));
99 }
100
101 pub fn hash(bytes: []const u8) W {
102 var c = Self.init();
103 c.update(bytes);
104 return c.final();
105 }
106 };
107}
1084
109pub const Polynomial = enum(u32) {5pub const Crc = impl.Crc;
110 IEEE = 0xedb88320,6pub const Polynomial = impl.Polynomial;
111 Castagnoli = 0x82f63b78,7pub const Crc32WithPoly = impl.Crc32WithPoly;
112 Koopman = 0xeb31d82e,8pub const Crc32SmallWithPoly = impl.Crc32SmallWithPoly;
113 _,
114};
1159
116// IEEE is by far the most common CRC and so is aliased by default.10// IEEE is by far the most common CRC and so is aliased by default.
117pub const Crc32 = Crc32WithPoly(.IEEE);11pub const Crc32 = Crc32WithPoly(.IEEE);
11812
119// slicing-by-8 crc32 implementation.13test {
120pub fn Crc32WithPoly(comptime poly: Polynomial) type {14 _ = @import("crc/test.zig");
121 return struct {
122 const Self = @This();
123 const lookup_tables = block: {
124 @setEvalBranchQuota(20000);
125 var tables: [8][256]u32 = undefined;
126
127 for (&tables[0], 0..) |*e, i| {
128 var crc = @as(u32, @intCast(i));
129 var j: usize = 0;
130 while (j < 8) : (j += 1) {
131 if (crc & 1 == 1) {
132 crc = (crc >> 1) ^ @intFromEnum(poly);
133 } else {
134 crc = (crc >> 1);
135 }
136 }
137 e.* = crc;
138 }
139
140 var i: usize = 0;
141 while (i < 256) : (i += 1) {
142 var crc = tables[0][i];
143 var j: usize = 1;
144 while (j < 8) : (j += 1) {
145 const index: u8 = @truncate(crc);
146 crc = tables[0][index] ^ (crc >> 8);
147 tables[j][i] = crc;
148 }
149 }
150
151 break :block tables;
152 };
153
154 crc: u32,
155
156 pub fn init() Self {
157 return Self{ .crc = 0xffffffff };
158 }
159
160 pub fn update(self: *Self, input: []const u8) void {
161 var i: usize = 0;
162 while (i + 8 <= input.len) : (i += 8) {
163 const p = input[i..][0..8];
164
165 // Unrolling this way gives ~50Mb/s increase
166 self.crc ^= std.mem.readInt(u32, p[0..4], .little);
167
168 self.crc =
169 lookup_tables[0][p[7]] ^
170 lookup_tables[1][p[6]] ^
171 lookup_tables[2][p[5]] ^
172 lookup_tables[3][p[4]] ^
173 lookup_tables[4][@as(u8, @truncate(self.crc >> 24))] ^
174 lookup_tables[5][@as(u8, @truncate(self.crc >> 16))] ^
175 lookup_tables[6][@as(u8, @truncate(self.crc >> 8))] ^
176 lookup_tables[7][@as(u8, @truncate(self.crc >> 0))];
177 }
178
179 while (i < input.len) : (i += 1) {
180 const index = @as(u8, @truncate(self.crc)) ^ input[i];
181 self.crc = (self.crc >> 8) ^ lookup_tables[0][index];
182 }
183 }
184
185 pub fn final(self: *Self) u32 {
186 return ~self.crc;
187 }
188
189 pub fn hash(input: []const u8) u32 {
190 var c = Self.init();
191 c.update(input);
192 return c.final();
193 }
194 };
195}
196
197const verify = @import("verify.zig");
198
199test "crc32 ieee" {
200 const Crc32Ieee = Crc32WithPoly(.IEEE);
201
202 try testing.expect(Crc32Ieee.hash("") == 0x00000000);
203 try testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43);
204 try testing.expect(Crc32Ieee.hash("abc") == 0x352441c2);
205}
206
207test "crc32 castagnoli" {
208 const Crc32Castagnoli = Crc32WithPoly(.Castagnoli);
209
210 try testing.expect(Crc32Castagnoli.hash("") == 0x00000000);
211 try testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330);
212 try testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7);
213}
214
215test "crc32 iterative" {
216 try verify.iterativeApi(Crc32WithPoly(.IEEE));
217}
218
219// half-byte lookup table implementation.
220pub fn Crc32SmallWithPoly(comptime poly: Polynomial) type {
221 return struct {
222 const Self = @This();
223 const lookup_table = block: {
224 var table: [16]u32 = undefined;
225
226 for (&table, 0..) |*e, i| {
227 var crc = @as(u32, @intCast(i * 16));
228 var j: usize = 0;
229 while (j < 8) : (j += 1) {
230 if (crc & 1 == 1) {
231 crc = (crc >> 1) ^ @intFromEnum(poly);
232 } else {
233 crc = (crc >> 1);
234 }
235 }
236 e.* = crc;
237 }
238
239 break :block table;
240 };
241
242 crc: u32,
243
244 pub fn init() Self {
245 return Self{ .crc = 0xffffffff };
246 }
247
248 pub fn update(self: *Self, input: []const u8) void {
249 for (input) |b| {
250 self.crc = lookup_table[@as(u4, @truncate(self.crc ^ (b >> 0)))] ^ (self.crc >> 4);
251 self.crc = lookup_table[@as(u4, @truncate(self.crc ^ (b >> 4)))] ^ (self.crc >> 4);
252 }
253 }
254
255 pub fn final(self: *Self) u32 {
256 return ~self.crc;
257 }
258
259 pub fn hash(input: []const u8) u32 {
260 var c = Self.init();
261 c.update(input);
262 return c.final();
263 }
264 };
265}
266
267test "small crc32 iterative" {
268 try verify.iterativeApi(Crc32SmallWithPoly(.IEEE));
269}15}
27016
271test "small crc32 ieee" {17pub const Crc3Gsm = Crc(u3, .{
272 const Crc32Ieee = Crc32SmallWithPoly(.IEEE);18 .polynomial = 0x3,
27319 .initial = 0x0,
274 try testing.expect(Crc32Ieee.hash("") == 0x00000000);20 .reflect_input = false,
275 try testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43);21 .reflect_output = false,
276 try testing.expect(Crc32Ieee.hash("abc") == 0x352441c2);22 .xor_output = 0x7,
277}23});
27824
279test "small crc32 castagnoli" {25pub const Crc3Rohc = Crc(u3, .{
280 const Crc32Castagnoli = Crc32SmallWithPoly(.Castagnoli);26 .polynomial = 0x3,
28127 .initial = 0x7,
282 try testing.expect(Crc32Castagnoli.hash("") == 0x00000000);28 .reflect_input = true,
283 try testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330);29 .reflect_output = true,
284 try testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7);30 .xor_output = 0x0,
285}31});
32
33pub const Crc4G704 = Crc(u4, .{
34 .polynomial = 0x3,
35 .initial = 0x0,
36 .reflect_input = true,
37 .reflect_output = true,
38 .xor_output = 0x0,
39});
40
41pub const Crc4Interlaken = Crc(u4, .{
42 .polynomial = 0x3,
43 .initial = 0xf,
44 .reflect_input = false,
45 .reflect_output = false,
46 .xor_output = 0xf,
47});
48
49pub const Crc5EpcC1g2 = Crc(u5, .{
50 .polynomial = 0x09,
51 .initial = 0x09,
52 .reflect_input = false,
53 .reflect_output = false,
54 .xor_output = 0x00,
55});
56
57pub const Crc5G704 = Crc(u5, .{
58 .polynomial = 0x15,
59 .initial = 0x00,
60 .reflect_input = true,
61 .reflect_output = true,
62 .xor_output = 0x00,
63});
64
65pub const Crc5Usb = Crc(u5, .{
66 .polynomial = 0x05,
67 .initial = 0x1f,
68 .reflect_input = true,
69 .reflect_output = true,
70 .xor_output = 0x1f,
71});
72
73pub const Crc6Cdma2000A = Crc(u6, .{
74 .polynomial = 0x27,
75 .initial = 0x3f,
76 .reflect_input = false,
77 .reflect_output = false,
78 .xor_output = 0x00,
79});
80
81pub const Crc6Cdma2000B = Crc(u6, .{
82 .polynomial = 0x07,
83 .initial = 0x3f,
84 .reflect_input = false,
85 .reflect_output = false,
86 .xor_output = 0x00,
87});
88
89pub const Crc6Darc = Crc(u6, .{
90 .polynomial = 0x19,
91 .initial = 0x00,
92 .reflect_input = true,
93 .reflect_output = true,
94 .xor_output = 0x00,
95});
96
97pub const Crc6G704 = Crc(u6, .{
98 .polynomial = 0x03,
99 .initial = 0x00,
100 .reflect_input = true,
101 .reflect_output = true,
102 .xor_output = 0x00,
103});
104
105pub const Crc6Gsm = Crc(u6, .{
106 .polynomial = 0x2f,
107 .initial = 0x00,
108 .reflect_input = false,
109 .reflect_output = false,
110 .xor_output = 0x3f,
111});
112
113pub const Crc7Mmc = Crc(u7, .{
114 .polynomial = 0x09,
115 .initial = 0x00,
116 .reflect_input = false,
117 .reflect_output = false,
118 .xor_output = 0x00,
119});
120
121pub const Crc7Rohc = Crc(u7, .{
122 .polynomial = 0x4f,
123 .initial = 0x7f,
124 .reflect_input = true,
125 .reflect_output = true,
126 .xor_output = 0x00,
127});
128
129pub const Crc7Umts = Crc(u7, .{
130 .polynomial = 0x45,
131 .initial = 0x00,
132 .reflect_input = false,
133 .reflect_output = false,
134 .xor_output = 0x00,
135});
136
137pub const Crc8Autosar = Crc(u8, .{
138 .polynomial = 0x2f,
139 .initial = 0xff,
140 .reflect_input = false,
141 .reflect_output = false,
142 .xor_output = 0xff,
143});
144
145pub const Crc8Bluetooth = Crc(u8, .{
146 .polynomial = 0xa7,
147 .initial = 0x00,
148 .reflect_input = true,
149 .reflect_output = true,
150 .xor_output = 0x00,
151});
152
153pub const Crc8Cdma2000 = Crc(u8, .{
154 .polynomial = 0x9b,
155 .initial = 0xff,
156 .reflect_input = false,
157 .reflect_output = false,
158 .xor_output = 0x00,
159});
160
161pub const Crc8Darc = Crc(u8, .{
162 .polynomial = 0x39,
163 .initial = 0x00,
164 .reflect_input = true,
165 .reflect_output = true,
166 .xor_output = 0x00,
167});
168
169pub const Crc8DvbS2 = Crc(u8, .{
170 .polynomial = 0xd5,
171 .initial = 0x00,
172 .reflect_input = false,
173 .reflect_output = false,
174 .xor_output = 0x00,
175});
176
177pub const Crc8GsmA = Crc(u8, .{
178 .polynomial = 0x1d,
179 .initial = 0x00,
180 .reflect_input = false,
181 .reflect_output = false,
182 .xor_output = 0x00,
183});
184
185pub const Crc8GsmB = Crc(u8, .{
186 .polynomial = 0x49,
187 .initial = 0x00,
188 .reflect_input = false,
189 .reflect_output = false,
190 .xor_output = 0xff,
191});
192
193pub const Crc8Hitag = Crc(u8, .{
194 .polynomial = 0x1d,
195 .initial = 0xff,
196 .reflect_input = false,
197 .reflect_output = false,
198 .xor_output = 0x00,
199});
200
201pub const Crc8I4321 = Crc(u8, .{
202 .polynomial = 0x07,
203 .initial = 0x00,
204 .reflect_input = false,
205 .reflect_output = false,
206 .xor_output = 0x55,
207});
208
209pub const Crc8ICode = Crc(u8, .{
210 .polynomial = 0x1d,
211 .initial = 0xfd,
212 .reflect_input = false,
213 .reflect_output = false,
214 .xor_output = 0x00,
215});
216
217pub const Crc8Lte = Crc(u8, .{
218 .polynomial = 0x9b,
219 .initial = 0x00,
220 .reflect_input = false,
221 .reflect_output = false,
222 .xor_output = 0x00,
223});
224
225pub const Crc8MaximDow = Crc(u8, .{
226 .polynomial = 0x31,
227 .initial = 0x00,
228 .reflect_input = true,
229 .reflect_output = true,
230 .xor_output = 0x00,
231});
232
233pub const Crc8MifareMad = Crc(u8, .{
234 .polynomial = 0x1d,
235 .initial = 0xc7,
236 .reflect_input = false,
237 .reflect_output = false,
238 .xor_output = 0x00,
239});
240
241pub const Crc8Nrsc5 = Crc(u8, .{
242 .polynomial = 0x31,
243 .initial = 0xff,
244 .reflect_input = false,
245 .reflect_output = false,
246 .xor_output = 0x00,
247});
248
249pub const Crc8Opensafety = Crc(u8, .{
250 .polynomial = 0x2f,
251 .initial = 0x00,
252 .reflect_input = false,
253 .reflect_output = false,
254 .xor_output = 0x00,
255});
256
257pub const Crc8Rohc = Crc(u8, .{
258 .polynomial = 0x07,
259 .initial = 0xff,
260 .reflect_input = true,
261 .reflect_output = true,
262 .xor_output = 0x00,
263});
264
265pub const Crc8SaeJ1850 = Crc(u8, .{
266 .polynomial = 0x1d,
267 .initial = 0xff,
268 .reflect_input = false,
269 .reflect_output = false,
270 .xor_output = 0xff,
271});
272
273pub const Crc8Smbus = Crc(u8, .{
274 .polynomial = 0x07,
275 .initial = 0x00,
276 .reflect_input = false,
277 .reflect_output = false,
278 .xor_output = 0x00,
279});
280
281pub const Crc8Tech3250 = Crc(u8, .{
282 .polynomial = 0x1d,
283 .initial = 0xff,
284 .reflect_input = true,
285 .reflect_output = true,
286 .xor_output = 0x00,
287});
288
289pub const Crc8Wcdma = Crc(u8, .{
290 .polynomial = 0x9b,
291 .initial = 0x00,
292 .reflect_input = true,
293 .reflect_output = true,
294 .xor_output = 0x00,
295});
296
297pub const Crc10Atm = Crc(u10, .{
298 .polynomial = 0x233,
299 .initial = 0x000,
300 .reflect_input = false,
301 .reflect_output = false,
302 .xor_output = 0x000,
303});
304
305pub const Crc10Cdma2000 = Crc(u10, .{
306 .polynomial = 0x3d9,
307 .initial = 0x3ff,
308 .reflect_input = false,
309 .reflect_output = false,
310 .xor_output = 0x000,
311});
312
313pub const Crc10Gsm = Crc(u10, .{
314 .polynomial = 0x175,
315 .initial = 0x000,
316 .reflect_input = false,
317 .reflect_output = false,
318 .xor_output = 0x3ff,
319});
320
321pub const Crc11Flexray = Crc(u11, .{
322 .polynomial = 0x385,
323 .initial = 0x01a,
324 .reflect_input = false,
325 .reflect_output = false,
326 .xor_output = 0x000,
327});
328
329pub const Crc11Umts = Crc(u11, .{
330 .polynomial = 0x307,
331 .initial = 0x000,
332 .reflect_input = false,
333 .reflect_output = false,
334 .xor_output = 0x000,
335});
336
337pub const Crc12Cdma2000 = Crc(u12, .{
338 .polynomial = 0xf13,
339 .initial = 0xfff,
340 .reflect_input = false,
341 .reflect_output = false,
342 .xor_output = 0x000,
343});
344
345pub const Crc12Dect = Crc(u12, .{
346 .polynomial = 0x80f,
347 .initial = 0x000,
348 .reflect_input = false,
349 .reflect_output = false,
350 .xor_output = 0x000,
351});
352
353pub const Crc12Gsm = Crc(u12, .{
354 .polynomial = 0xd31,
355 .initial = 0x000,
356 .reflect_input = false,
357 .reflect_output = false,
358 .xor_output = 0xfff,
359});
360
361pub const Crc12Umts = Crc(u12, .{
362 .polynomial = 0x80f,
363 .initial = 0x000,
364 .reflect_input = false,
365 .reflect_output = true,
366 .xor_output = 0x000,
367});
368
369pub const Crc13Bbc = Crc(u13, .{
370 .polynomial = 0x1cf5,
371 .initial = 0x0000,
372 .reflect_input = false,
373 .reflect_output = false,
374 .xor_output = 0x0000,
375});
376
377pub const Crc14Darc = Crc(u14, .{
378 .polynomial = 0x0805,
379 .initial = 0x0000,
380 .reflect_input = true,
381 .reflect_output = true,
382 .xor_output = 0x0000,
383});
384
385pub const Crc14Gsm = Crc(u14, .{
386 .polynomial = 0x202d,
387 .initial = 0x0000,
388 .reflect_input = false,
389 .reflect_output = false,
390 .xor_output = 0x3fff,
391});
392
393pub const Crc15Can = Crc(u15, .{
394 .polynomial = 0x4599,
395 .initial = 0x0000,
396 .reflect_input = false,
397 .reflect_output = false,
398 .xor_output = 0x0000,
399});
400
401pub const Crc15Mpt1327 = Crc(u15, .{
402 .polynomial = 0x6815,
403 .initial = 0x0000,
404 .reflect_input = false,
405 .reflect_output = false,
406 .xor_output = 0x0001,
407});
408
409pub const Crc16Arc = Crc(u16, .{
410 .polynomial = 0x8005,
411 .initial = 0x0000,
412 .reflect_input = true,
413 .reflect_output = true,
414 .xor_output = 0x0000,
415});
416
417pub const Crc16Cdma2000 = Crc(u16, .{
418 .polynomial = 0xc867,
419 .initial = 0xffff,
420 .reflect_input = false,
421 .reflect_output = false,
422 .xor_output = 0x0000,
423});
424
425pub const Crc16Cms = Crc(u16, .{
426 .polynomial = 0x8005,
427 .initial = 0xffff,
428 .reflect_input = false,
429 .reflect_output = false,
430 .xor_output = 0x0000,
431});
432
433pub const Crc16Dds110 = Crc(u16, .{
434 .polynomial = 0x8005,
435 .initial = 0x800d,
436 .reflect_input = false,
437 .reflect_output = false,
438 .xor_output = 0x0000,
439});
440
441pub const Crc16DectR = Crc(u16, .{
442 .polynomial = 0x0589,
443 .initial = 0x0000,
444 .reflect_input = false,
445 .reflect_output = false,
446 .xor_output = 0x0001,
447});
448
449pub const Crc16DectX = Crc(u16, .{
450 .polynomial = 0x0589,
451 .initial = 0x0000,
452 .reflect_input = false,
453 .reflect_output = false,
454 .xor_output = 0x0000,
455});
456
457pub const Crc16Dnp = Crc(u16, .{
458 .polynomial = 0x3d65,
459 .initial = 0x0000,
460 .reflect_input = true,
461 .reflect_output = true,
462 .xor_output = 0xffff,
463});
464
465pub const Crc16En13757 = Crc(u16, .{
466 .polynomial = 0x3d65,
467 .initial = 0x0000,
468 .reflect_input = false,
469 .reflect_output = false,
470 .xor_output = 0xffff,
471});
472
473pub const Crc16Genibus = Crc(u16, .{
474 .polynomial = 0x1021,
475 .initial = 0xffff,
476 .reflect_input = false,
477 .reflect_output = false,
478 .xor_output = 0xffff,
479});
480
481pub const Crc16Gsm = Crc(u16, .{
482 .polynomial = 0x1021,
483 .initial = 0x0000,
484 .reflect_input = false,
485 .reflect_output = false,
486 .xor_output = 0xffff,
487});
488
489pub const Crc16Ibm3740 = Crc(u16, .{
490 .polynomial = 0x1021,
491 .initial = 0xffff,
492 .reflect_input = false,
493 .reflect_output = false,
494 .xor_output = 0x0000,
495});
496
497pub const Crc16IbmSdlc = Crc(u16, .{
498 .polynomial = 0x1021,
499 .initial = 0xffff,
500 .reflect_input = true,
501 .reflect_output = true,
502 .xor_output = 0xffff,
503});
504
505pub const Crc16IsoIec144433A = Crc(u16, .{
506 .polynomial = 0x1021,
507 .initial = 0xc6c6,
508 .reflect_input = true,
509 .reflect_output = true,
510 .xor_output = 0x0000,
511});
512
513pub const Crc16Kermit = Crc(u16, .{
514 .polynomial = 0x1021,
515 .initial = 0x0000,
516 .reflect_input = true,
517 .reflect_output = true,
518 .xor_output = 0x0000,
519});
520
521pub const Crc16Lj1200 = Crc(u16, .{
522 .polynomial = 0x6f63,
523 .initial = 0x0000,
524 .reflect_input = false,
525 .reflect_output = false,
526 .xor_output = 0x0000,
527});
528
529pub const Crc16M17 = Crc(u16, .{
530 .polynomial = 0x5935,
531 .initial = 0xffff,
532 .reflect_input = false,
533 .reflect_output = false,
534 .xor_output = 0x0000,
535});
536
537pub const Crc16MaximDow = Crc(u16, .{
538 .polynomial = 0x8005,
539 .initial = 0x0000,
540 .reflect_input = true,
541 .reflect_output = true,
542 .xor_output = 0xffff,
543});
544
545pub const Crc16Mcrf4xx = Crc(u16, .{
546 .polynomial = 0x1021,
547 .initial = 0xffff,
548 .reflect_input = true,
549 .reflect_output = true,
550 .xor_output = 0x0000,
551});
552
553pub const Crc16Modbus = Crc(u16, .{
554 .polynomial = 0x8005,
555 .initial = 0xffff,
556 .reflect_input = true,
557 .reflect_output = true,
558 .xor_output = 0x0000,
559});
560
561pub const Crc16Nrsc5 = Crc(u16, .{
562 .polynomial = 0x080b,
563 .initial = 0xffff,
564 .reflect_input = true,
565 .reflect_output = true,
566 .xor_output = 0x0000,
567});
568
569pub const Crc16OpensafetyA = Crc(u16, .{
570 .polynomial = 0x5935,
571 .initial = 0x0000,
572 .reflect_input = false,
573 .reflect_output = false,
574 .xor_output = 0x0000,
575});
576
577pub const Crc16OpensafetyB = Crc(u16, .{
578 .polynomial = 0x755b,
579 .initial = 0x0000,
580 .reflect_input = false,
581 .reflect_output = false,
582 .xor_output = 0x0000,
583});
584
585pub const Crc16Profibus = Crc(u16, .{
586 .polynomial = 0x1dcf,
587 .initial = 0xffff,
588 .reflect_input = false,
589 .reflect_output = false,
590 .xor_output = 0xffff,
591});
592
593pub const Crc16Riello = Crc(u16, .{
594 .polynomial = 0x1021,
595 .initial = 0xb2aa,
596 .reflect_input = true,
597 .reflect_output = true,
598 .xor_output = 0x0000,
599});
600
601pub const Crc16SpiFujitsu = Crc(u16, .{
602 .polynomial = 0x1021,
603 .initial = 0x1d0f,
604 .reflect_input = false,
605 .reflect_output = false,
606 .xor_output = 0x0000,
607});
608
609pub const Crc16T10Dif = Crc(u16, .{
610 .polynomial = 0x8bb7,
611 .initial = 0x0000,
612 .reflect_input = false,
613 .reflect_output = false,
614 .xor_output = 0x0000,
615});
616
617pub const Crc16Teledisk = Crc(u16, .{
618 .polynomial = 0xa097,
619 .initial = 0x0000,
620 .reflect_input = false,
621 .reflect_output = false,
622 .xor_output = 0x0000,
623});
624
625pub const Crc16Tms37157 = Crc(u16, .{
626 .polynomial = 0x1021,
627 .initial = 0x89ec,
628 .reflect_input = true,
629 .reflect_output = true,
630 .xor_output = 0x0000,
631});
632
633pub const Crc16Umts = Crc(u16, .{
634 .polynomial = 0x8005,
635 .initial = 0x0000,
636 .reflect_input = false,
637 .reflect_output = false,
638 .xor_output = 0x0000,
639});
640
641pub const Crc16Usb = Crc(u16, .{
642 .polynomial = 0x8005,
643 .initial = 0xffff,
644 .reflect_input = true,
645 .reflect_output = true,
646 .xor_output = 0xffff,
647});
648
649pub const Crc16Xmodem = Crc(u16, .{
650 .polynomial = 0x1021,
651 .initial = 0x0000,
652 .reflect_input = false,
653 .reflect_output = false,
654 .xor_output = 0x0000,
655});
656
657pub const Crc17CanFd = Crc(u17, .{
658 .polynomial = 0x1685b,
659 .initial = 0x00000,
660 .reflect_input = false,
661 .reflect_output = false,
662 .xor_output = 0x00000,
663});
664
665pub const Crc21CanFd = Crc(u21, .{
666 .polynomial = 0x102899,
667 .initial = 0x000000,
668 .reflect_input = false,
669 .reflect_output = false,
670 .xor_output = 0x000000,
671});
672
673pub const Crc24Ble = Crc(u24, .{
674 .polynomial = 0x00065b,
675 .initial = 0x555555,
676 .reflect_input = true,
677 .reflect_output = true,
678 .xor_output = 0x000000,
679});
680
681pub const Crc24FlexrayA = Crc(u24, .{
682 .polynomial = 0x5d6dcb,
683 .initial = 0xfedcba,
684 .reflect_input = false,
685 .reflect_output = false,
686 .xor_output = 0x000000,
687});
688
689pub const Crc24FlexrayB = Crc(u24, .{
690 .polynomial = 0x5d6dcb,
691 .initial = 0xabcdef,
692 .reflect_input = false,
693 .reflect_output = false,
694 .xor_output = 0x000000,
695});
696
697pub const Crc24Interlaken = Crc(u24, .{
698 .polynomial = 0x328b63,
699 .initial = 0xffffff,
700 .reflect_input = false,
701 .reflect_output = false,
702 .xor_output = 0xffffff,
703});
704
705pub const Crc24LteA = Crc(u24, .{
706 .polynomial = 0x864cfb,
707 .initial = 0x000000,
708 .reflect_input = false,
709 .reflect_output = false,
710 .xor_output = 0x000000,
711});
712
713pub const Crc24LteB = Crc(u24, .{
714 .polynomial = 0x800063,
715 .initial = 0x000000,
716 .reflect_input = false,
717 .reflect_output = false,
718 .xor_output = 0x000000,
719});
720
721pub const Crc24Openpgp = Crc(u24, .{
722 .polynomial = 0x864cfb,
723 .initial = 0xb704ce,
724 .reflect_input = false,
725 .reflect_output = false,
726 .xor_output = 0x000000,
727});
728
729pub const Crc24Os9 = Crc(u24, .{
730 .polynomial = 0x800063,
731 .initial = 0xffffff,
732 .reflect_input = false,
733 .reflect_output = false,
734 .xor_output = 0xffffff,
735});
736
737pub const Crc30Cdma = Crc(u30, .{
738 .polynomial = 0x2030b9c7,
739 .initial = 0x3fffffff,
740 .reflect_input = false,
741 .reflect_output = false,
742 .xor_output = 0x3fffffff,
743});
744
745pub const Crc31Philips = Crc(u31, .{
746 .polynomial = 0x04c11db7,
747 .initial = 0x7fffffff,
748 .reflect_input = false,
749 .reflect_output = false,
750 .xor_output = 0x7fffffff,
751});
752
753pub const Crc32Aixm = Crc(u32, .{
754 .polynomial = 0x814141ab,
755 .initial = 0x00000000,
756 .reflect_input = false,
757 .reflect_output = false,
758 .xor_output = 0x00000000,
759});
760
761pub const Crc32Autosar = Crc(u32, .{
762 .polynomial = 0xf4acfb13,
763 .initial = 0xffffffff,
764 .reflect_input = true,
765 .reflect_output = true,
766 .xor_output = 0xffffffff,
767});
768
769pub const Crc32Base91D = Crc(u32, .{
770 .polynomial = 0xa833982b,
771 .initial = 0xffffffff,
772 .reflect_input = true,
773 .reflect_output = true,
774 .xor_output = 0xffffffff,
775});
776
777pub const Crc32Bzip2 = Crc(u32, .{
778 .polynomial = 0x04c11db7,
779 .initial = 0xffffffff,
780 .reflect_input = false,
781 .reflect_output = false,
782 .xor_output = 0xffffffff,
783});
784
785pub const Crc32CdRomEdc = Crc(u32, .{
786 .polynomial = 0x8001801b,
787 .initial = 0x00000000,
788 .reflect_input = true,
789 .reflect_output = true,
790 .xor_output = 0x00000000,
791});
792
793pub const Crc32Cksum = Crc(u32, .{
794 .polynomial = 0x04c11db7,
795 .initial = 0x00000000,
796 .reflect_input = false,
797 .reflect_output = false,
798 .xor_output = 0xffffffff,
799});
800
801pub const Crc32Iscsi = Crc(u32, .{
802 .polynomial = 0x1edc6f41,
803 .initial = 0xffffffff,
804 .reflect_input = true,
805 .reflect_output = true,
806 .xor_output = 0xffffffff,
807});
808
809pub const Crc32IsoHdlc = Crc(u32, .{
810 .polynomial = 0x04c11db7,
811 .initial = 0xffffffff,
812 .reflect_input = true,
813 .reflect_output = true,
814 .xor_output = 0xffffffff,
815});
816
817pub const Crc32Jamcrc = Crc(u32, .{
818 .polynomial = 0x04c11db7,
819 .initial = 0xffffffff,
820 .reflect_input = true,
821 .reflect_output = true,
822 .xor_output = 0x00000000,
823});
824
825pub const Crc32Mef = Crc(u32, .{
826 .polynomial = 0x741b8cd7,
827 .initial = 0xffffffff,
828 .reflect_input = true,
829 .reflect_output = true,
830 .xor_output = 0x00000000,
831});
832
833pub const Crc32Mpeg2 = Crc(u32, .{
834 .polynomial = 0x04c11db7,
835 .initial = 0xffffffff,
836 .reflect_input = false,
837 .reflect_output = false,
838 .xor_output = 0x00000000,
839});
840
841pub const Crc32Xfer = Crc(u32, .{
842 .polynomial = 0x000000af,
843 .initial = 0x00000000,
844 .reflect_input = false,
845 .reflect_output = false,
846 .xor_output = 0x00000000,
847});
848
849pub const Crc40Gsm = Crc(u40, .{
850 .polynomial = 0x0004820009,
851 .initial = 0x0000000000,
852 .reflect_input = false,
853 .reflect_output = false,
854 .xor_output = 0xffffffffff,
855});
856
857pub const Crc64Ecma182 = Crc(u64, .{
858 .polynomial = 0x42f0e1eba9ea3693,
859 .initial = 0x0000000000000000,
860 .reflect_input = false,
861 .reflect_output = false,
862 .xor_output = 0x0000000000000000,
863});
864
865pub const Crc64GoIso = Crc(u64, .{
866 .polynomial = 0x000000000000001b,
867 .initial = 0xffffffffffffffff,
868 .reflect_input = true,
869 .reflect_output = true,
870 .xor_output = 0xffffffffffffffff,
871});
872
873pub const Crc64Ms = Crc(u64, .{
874 .polynomial = 0x259c84cba6426349,
875 .initial = 0xffffffffffffffff,
876 .reflect_input = true,
877 .reflect_output = true,
878 .xor_output = 0x0000000000000000,
879});
880
881pub const Crc64Redis = Crc(u64, .{
882 .polynomial = 0xad93d23594c935a9,
883 .initial = 0x0000000000000000,
884 .reflect_input = true,
885 .reflect_output = true,
886 .xor_output = 0x0000000000000000,
887});
888
889pub const Crc64We = Crc(u64, .{
890 .polynomial = 0x42f0e1eba9ea3693,
891 .initial = 0xffffffffffffffff,
892 .reflect_input = false,
893 .reflect_output = false,
894 .xor_output = 0xffffffffffffffff,
895});
896
897pub const Crc64Xz = Crc(u64, .{
898 .polynomial = 0x42f0e1eba9ea3693,
899 .initial = 0xffffffffffffffff,
900 .reflect_input = true,
901 .reflect_output = true,
902 .xor_output = 0xffffffffffffffff,
903});
904
905pub const Crc82Darc = Crc(u82, .{
906 .polynomial = 0x0308c0111011401440411,
907 .initial = 0x000000000000000000000,
908 .reflect_input = true,
909 .reflect_output = true,
910 .xor_output = 0x000000000000000000000,
911});
lib/std/hash/crc/catalog.zig deleted-903
...@@ -1,903 +0,0 @@
1//! This file is auto-generated by tools/update_crc_catalog.zig.
2
3const Crc = @import("../crc.zig").Crc;
4
5test {
6 _ = @import("catalog_test.zig");
7}
8
9pub const Crc3Gsm = Crc(u3, .{
10 .polynomial = 0x3,
11 .initial = 0x0,
12 .reflect_input = false,
13 .reflect_output = false,
14 .xor_output = 0x7,
15});
16
17pub const Crc3Rohc = Crc(u3, .{
18 .polynomial = 0x3,
19 .initial = 0x7,
20 .reflect_input = true,
21 .reflect_output = true,
22 .xor_output = 0x0,
23});
24
25pub const Crc4G704 = Crc(u4, .{
26 .polynomial = 0x3,
27 .initial = 0x0,
28 .reflect_input = true,
29 .reflect_output = true,
30 .xor_output = 0x0,
31});
32
33pub const Crc4Interlaken = Crc(u4, .{
34 .polynomial = 0x3,
35 .initial = 0xf,
36 .reflect_input = false,
37 .reflect_output = false,
38 .xor_output = 0xf,
39});
40
41pub const Crc5EpcC1g2 = Crc(u5, .{
42 .polynomial = 0x09,
43 .initial = 0x09,
44 .reflect_input = false,
45 .reflect_output = false,
46 .xor_output = 0x00,
47});
48
49pub const Crc5G704 = Crc(u5, .{
50 .polynomial = 0x15,
51 .initial = 0x00,
52 .reflect_input = true,
53 .reflect_output = true,
54 .xor_output = 0x00,
55});
56
57pub const Crc5Usb = Crc(u5, .{
58 .polynomial = 0x05,
59 .initial = 0x1f,
60 .reflect_input = true,
61 .reflect_output = true,
62 .xor_output = 0x1f,
63});
64
65pub const Crc6Cdma2000A = Crc(u6, .{
66 .polynomial = 0x27,
67 .initial = 0x3f,
68 .reflect_input = false,
69 .reflect_output = false,
70 .xor_output = 0x00,
71});
72
73pub const Crc6Cdma2000B = Crc(u6, .{
74 .polynomial = 0x07,
75 .initial = 0x3f,
76 .reflect_input = false,
77 .reflect_output = false,
78 .xor_output = 0x00,
79});
80
81pub const Crc6Darc = Crc(u6, .{
82 .polynomial = 0x19,
83 .initial = 0x00,
84 .reflect_input = true,
85 .reflect_output = true,
86 .xor_output = 0x00,
87});
88
89pub const Crc6G704 = Crc(u6, .{
90 .polynomial = 0x03,
91 .initial = 0x00,
92 .reflect_input = true,
93 .reflect_output = true,
94 .xor_output = 0x00,
95});
96
97pub const Crc6Gsm = Crc(u6, .{
98 .polynomial = 0x2f,
99 .initial = 0x00,
100 .reflect_input = false,
101 .reflect_output = false,
102 .xor_output = 0x3f,
103});
104
105pub const Crc7Mmc = Crc(u7, .{
106 .polynomial = 0x09,
107 .initial = 0x00,
108 .reflect_input = false,
109 .reflect_output = false,
110 .xor_output = 0x00,
111});
112
113pub const Crc7Rohc = Crc(u7, .{
114 .polynomial = 0x4f,
115 .initial = 0x7f,
116 .reflect_input = true,
117 .reflect_output = true,
118 .xor_output = 0x00,
119});
120
121pub const Crc7Umts = Crc(u7, .{
122 .polynomial = 0x45,
123 .initial = 0x00,
124 .reflect_input = false,
125 .reflect_output = false,
126 .xor_output = 0x00,
127});
128
129pub const Crc8Autosar = Crc(u8, .{
130 .polynomial = 0x2f,
131 .initial = 0xff,
132 .reflect_input = false,
133 .reflect_output = false,
134 .xor_output = 0xff,
135});
136
137pub const Crc8Bluetooth = Crc(u8, .{
138 .polynomial = 0xa7,
139 .initial = 0x00,
140 .reflect_input = true,
141 .reflect_output = true,
142 .xor_output = 0x00,
143});
144
145pub const Crc8Cdma2000 = Crc(u8, .{
146 .polynomial = 0x9b,
147 .initial = 0xff,
148 .reflect_input = false,
149 .reflect_output = false,
150 .xor_output = 0x00,
151});
152
153pub const Crc8Darc = Crc(u8, .{
154 .polynomial = 0x39,
155 .initial = 0x00,
156 .reflect_input = true,
157 .reflect_output = true,
158 .xor_output = 0x00,
159});
160
161pub const Crc8DvbS2 = Crc(u8, .{
162 .polynomial = 0xd5,
163 .initial = 0x00,
164 .reflect_input = false,
165 .reflect_output = false,
166 .xor_output = 0x00,
167});
168
169pub const Crc8GsmA = Crc(u8, .{
170 .polynomial = 0x1d,
171 .initial = 0x00,
172 .reflect_input = false,
173 .reflect_output = false,
174 .xor_output = 0x00,
175});
176
177pub const Crc8GsmB = Crc(u8, .{
178 .polynomial = 0x49,
179 .initial = 0x00,
180 .reflect_input = false,
181 .reflect_output = false,
182 .xor_output = 0xff,
183});
184
185pub const Crc8Hitag = Crc(u8, .{
186 .polynomial = 0x1d,
187 .initial = 0xff,
188 .reflect_input = false,
189 .reflect_output = false,
190 .xor_output = 0x00,
191});
192
193pub const Crc8I4321 = Crc(u8, .{
194 .polynomial = 0x07,
195 .initial = 0x00,
196 .reflect_input = false,
197 .reflect_output = false,
198 .xor_output = 0x55,
199});
200
201pub const Crc8ICode = Crc(u8, .{
202 .polynomial = 0x1d,
203 .initial = 0xfd,
204 .reflect_input = false,
205 .reflect_output = false,
206 .xor_output = 0x00,
207});
208
209pub const Crc8Lte = Crc(u8, .{
210 .polynomial = 0x9b,
211 .initial = 0x00,
212 .reflect_input = false,
213 .reflect_output = false,
214 .xor_output = 0x00,
215});
216
217pub const Crc8MaximDow = Crc(u8, .{
218 .polynomial = 0x31,
219 .initial = 0x00,
220 .reflect_input = true,
221 .reflect_output = true,
222 .xor_output = 0x00,
223});
224
225pub const Crc8MifareMad = Crc(u8, .{
226 .polynomial = 0x1d,
227 .initial = 0xc7,
228 .reflect_input = false,
229 .reflect_output = false,
230 .xor_output = 0x00,
231});
232
233pub const Crc8Nrsc5 = Crc(u8, .{
234 .polynomial = 0x31,
235 .initial = 0xff,
236 .reflect_input = false,
237 .reflect_output = false,
238 .xor_output = 0x00,
239});
240
241pub const Crc8Opensafety = Crc(u8, .{
242 .polynomial = 0x2f,
243 .initial = 0x00,
244 .reflect_input = false,
245 .reflect_output = false,
246 .xor_output = 0x00,
247});
248
249pub const Crc8Rohc = Crc(u8, .{
250 .polynomial = 0x07,
251 .initial = 0xff,
252 .reflect_input = true,
253 .reflect_output = true,
254 .xor_output = 0x00,
255});
256
257pub const Crc8SaeJ1850 = Crc(u8, .{
258 .polynomial = 0x1d,
259 .initial = 0xff,
260 .reflect_input = false,
261 .reflect_output = false,
262 .xor_output = 0xff,
263});
264
265pub const Crc8Smbus = Crc(u8, .{
266 .polynomial = 0x07,
267 .initial = 0x00,
268 .reflect_input = false,
269 .reflect_output = false,
270 .xor_output = 0x00,
271});
272
273pub const Crc8Tech3250 = Crc(u8, .{
274 .polynomial = 0x1d,
275 .initial = 0xff,
276 .reflect_input = true,
277 .reflect_output = true,
278 .xor_output = 0x00,
279});
280
281pub const Crc8Wcdma = Crc(u8, .{
282 .polynomial = 0x9b,
283 .initial = 0x00,
284 .reflect_input = true,
285 .reflect_output = true,
286 .xor_output = 0x00,
287});
288
289pub const Crc10Atm = Crc(u10, .{
290 .polynomial = 0x233,
291 .initial = 0x000,
292 .reflect_input = false,
293 .reflect_output = false,
294 .xor_output = 0x000,
295});
296
297pub const Crc10Cdma2000 = Crc(u10, .{
298 .polynomial = 0x3d9,
299 .initial = 0x3ff,
300 .reflect_input = false,
301 .reflect_output = false,
302 .xor_output = 0x000,
303});
304
305pub const Crc10Gsm = Crc(u10, .{
306 .polynomial = 0x175,
307 .initial = 0x000,
308 .reflect_input = false,
309 .reflect_output = false,
310 .xor_output = 0x3ff,
311});
312
313pub const Crc11Flexray = Crc(u11, .{
314 .polynomial = 0x385,
315 .initial = 0x01a,
316 .reflect_input = false,
317 .reflect_output = false,
318 .xor_output = 0x000,
319});
320
321pub const Crc11Umts = Crc(u11, .{
322 .polynomial = 0x307,
323 .initial = 0x000,
324 .reflect_input = false,
325 .reflect_output = false,
326 .xor_output = 0x000,
327});
328
329pub const Crc12Cdma2000 = Crc(u12, .{
330 .polynomial = 0xf13,
331 .initial = 0xfff,
332 .reflect_input = false,
333 .reflect_output = false,
334 .xor_output = 0x000,
335});
336
337pub const Crc12Dect = Crc(u12, .{
338 .polynomial = 0x80f,
339 .initial = 0x000,
340 .reflect_input = false,
341 .reflect_output = false,
342 .xor_output = 0x000,
343});
344
345pub const Crc12Gsm = Crc(u12, .{
346 .polynomial = 0xd31,
347 .initial = 0x000,
348 .reflect_input = false,
349 .reflect_output = false,
350 .xor_output = 0xfff,
351});
352
353pub const Crc12Umts = Crc(u12, .{
354 .polynomial = 0x80f,
355 .initial = 0x000,
356 .reflect_input = false,
357 .reflect_output = true,
358 .xor_output = 0x000,
359});
360
361pub const Crc13Bbc = Crc(u13, .{
362 .polynomial = 0x1cf5,
363 .initial = 0x0000,
364 .reflect_input = false,
365 .reflect_output = false,
366 .xor_output = 0x0000,
367});
368
369pub const Crc14Darc = Crc(u14, .{
370 .polynomial = 0x0805,
371 .initial = 0x0000,
372 .reflect_input = true,
373 .reflect_output = true,
374 .xor_output = 0x0000,
375});
376
377pub const Crc14Gsm = Crc(u14, .{
378 .polynomial = 0x202d,
379 .initial = 0x0000,
380 .reflect_input = false,
381 .reflect_output = false,
382 .xor_output = 0x3fff,
383});
384
385pub const Crc15Can = Crc(u15, .{
386 .polynomial = 0x4599,
387 .initial = 0x0000,
388 .reflect_input = false,
389 .reflect_output = false,
390 .xor_output = 0x0000,
391});
392
393pub const Crc15Mpt1327 = Crc(u15, .{
394 .polynomial = 0x6815,
395 .initial = 0x0000,
396 .reflect_input = false,
397 .reflect_output = false,
398 .xor_output = 0x0001,
399});
400
401pub const Crc16Arc = Crc(u16, .{
402 .polynomial = 0x8005,
403 .initial = 0x0000,
404 .reflect_input = true,
405 .reflect_output = true,
406 .xor_output = 0x0000,
407});
408
409pub const Crc16Cdma2000 = Crc(u16, .{
410 .polynomial = 0xc867,
411 .initial = 0xffff,
412 .reflect_input = false,
413 .reflect_output = false,
414 .xor_output = 0x0000,
415});
416
417pub const Crc16Cms = Crc(u16, .{
418 .polynomial = 0x8005,
419 .initial = 0xffff,
420 .reflect_input = false,
421 .reflect_output = false,
422 .xor_output = 0x0000,
423});
424
425pub const Crc16Dds110 = Crc(u16, .{
426 .polynomial = 0x8005,
427 .initial = 0x800d,
428 .reflect_input = false,
429 .reflect_output = false,
430 .xor_output = 0x0000,
431});
432
433pub const Crc16DectR = Crc(u16, .{
434 .polynomial = 0x0589,
435 .initial = 0x0000,
436 .reflect_input = false,
437 .reflect_output = false,
438 .xor_output = 0x0001,
439});
440
441pub const Crc16DectX = Crc(u16, .{
442 .polynomial = 0x0589,
443 .initial = 0x0000,
444 .reflect_input = false,
445 .reflect_output = false,
446 .xor_output = 0x0000,
447});
448
449pub const Crc16Dnp = Crc(u16, .{
450 .polynomial = 0x3d65,
451 .initial = 0x0000,
452 .reflect_input = true,
453 .reflect_output = true,
454 .xor_output = 0xffff,
455});
456
457pub const Crc16En13757 = Crc(u16, .{
458 .polynomial = 0x3d65,
459 .initial = 0x0000,
460 .reflect_input = false,
461 .reflect_output = false,
462 .xor_output = 0xffff,
463});
464
465pub const Crc16Genibus = Crc(u16, .{
466 .polynomial = 0x1021,
467 .initial = 0xffff,
468 .reflect_input = false,
469 .reflect_output = false,
470 .xor_output = 0xffff,
471});
472
473pub const Crc16Gsm = Crc(u16, .{
474 .polynomial = 0x1021,
475 .initial = 0x0000,
476 .reflect_input = false,
477 .reflect_output = false,
478 .xor_output = 0xffff,
479});
480
481pub const Crc16Ibm3740 = Crc(u16, .{
482 .polynomial = 0x1021,
483 .initial = 0xffff,
484 .reflect_input = false,
485 .reflect_output = false,
486 .xor_output = 0x0000,
487});
488
489pub const Crc16IbmSdlc = Crc(u16, .{
490 .polynomial = 0x1021,
491 .initial = 0xffff,
492 .reflect_input = true,
493 .reflect_output = true,
494 .xor_output = 0xffff,
495});
496
497pub const Crc16IsoIec144433A = Crc(u16, .{
498 .polynomial = 0x1021,
499 .initial = 0xc6c6,
500 .reflect_input = true,
501 .reflect_output = true,
502 .xor_output = 0x0000,
503});
504
505pub const Crc16Kermit = Crc(u16, .{
506 .polynomial = 0x1021,
507 .initial = 0x0000,
508 .reflect_input = true,
509 .reflect_output = true,
510 .xor_output = 0x0000,
511});
512
513pub const Crc16Lj1200 = Crc(u16, .{
514 .polynomial = 0x6f63,
515 .initial = 0x0000,
516 .reflect_input = false,
517 .reflect_output = false,
518 .xor_output = 0x0000,
519});
520
521pub const Crc16M17 = Crc(u16, .{
522 .polynomial = 0x5935,
523 .initial = 0xffff,
524 .reflect_input = false,
525 .reflect_output = false,
526 .xor_output = 0x0000,
527});
528
529pub const Crc16MaximDow = Crc(u16, .{
530 .polynomial = 0x8005,
531 .initial = 0x0000,
532 .reflect_input = true,
533 .reflect_output = true,
534 .xor_output = 0xffff,
535});
536
537pub const Crc16Mcrf4xx = Crc(u16, .{
538 .polynomial = 0x1021,
539 .initial = 0xffff,
540 .reflect_input = true,
541 .reflect_output = true,
542 .xor_output = 0x0000,
543});
544
545pub const Crc16Modbus = Crc(u16, .{
546 .polynomial = 0x8005,
547 .initial = 0xffff,
548 .reflect_input = true,
549 .reflect_output = true,
550 .xor_output = 0x0000,
551});
552
553pub const Crc16Nrsc5 = Crc(u16, .{
554 .polynomial = 0x080b,
555 .initial = 0xffff,
556 .reflect_input = true,
557 .reflect_output = true,
558 .xor_output = 0x0000,
559});
560
561pub const Crc16OpensafetyA = Crc(u16, .{
562 .polynomial = 0x5935,
563 .initial = 0x0000,
564 .reflect_input = false,
565 .reflect_output = false,
566 .xor_output = 0x0000,
567});
568
569pub const Crc16OpensafetyB = Crc(u16, .{
570 .polynomial = 0x755b,
571 .initial = 0x0000,
572 .reflect_input = false,
573 .reflect_output = false,
574 .xor_output = 0x0000,
575});
576
577pub const Crc16Profibus = Crc(u16, .{
578 .polynomial = 0x1dcf,
579 .initial = 0xffff,
580 .reflect_input = false,
581 .reflect_output = false,
582 .xor_output = 0xffff,
583});
584
585pub const Crc16Riello = Crc(u16, .{
586 .polynomial = 0x1021,
587 .initial = 0xb2aa,
588 .reflect_input = true,
589 .reflect_output = true,
590 .xor_output = 0x0000,
591});
592
593pub const Crc16SpiFujitsu = Crc(u16, .{
594 .polynomial = 0x1021,
595 .initial = 0x1d0f,
596 .reflect_input = false,
597 .reflect_output = false,
598 .xor_output = 0x0000,
599});
600
601pub const Crc16T10Dif = Crc(u16, .{
602 .polynomial = 0x8bb7,
603 .initial = 0x0000,
604 .reflect_input = false,
605 .reflect_output = false,
606 .xor_output = 0x0000,
607});
608
609pub const Crc16Teledisk = Crc(u16, .{
610 .polynomial = 0xa097,
611 .initial = 0x0000,
612 .reflect_input = false,
613 .reflect_output = false,
614 .xor_output = 0x0000,
615});
616
617pub const Crc16Tms37157 = Crc(u16, .{
618 .polynomial = 0x1021,
619 .initial = 0x89ec,
620 .reflect_input = true,
621 .reflect_output = true,
622 .xor_output = 0x0000,
623});
624
625pub const Crc16Umts = Crc(u16, .{
626 .polynomial = 0x8005,
627 .initial = 0x0000,
628 .reflect_input = false,
629 .reflect_output = false,
630 .xor_output = 0x0000,
631});
632
633pub const Crc16Usb = Crc(u16, .{
634 .polynomial = 0x8005,
635 .initial = 0xffff,
636 .reflect_input = true,
637 .reflect_output = true,
638 .xor_output = 0xffff,
639});
640
641pub const Crc16Xmodem = Crc(u16, .{
642 .polynomial = 0x1021,
643 .initial = 0x0000,
644 .reflect_input = false,
645 .reflect_output = false,
646 .xor_output = 0x0000,
647});
648
649pub const Crc17CanFd = Crc(u17, .{
650 .polynomial = 0x1685b,
651 .initial = 0x00000,
652 .reflect_input = false,
653 .reflect_output = false,
654 .xor_output = 0x00000,
655});
656
657pub const Crc21CanFd = Crc(u21, .{
658 .polynomial = 0x102899,
659 .initial = 0x000000,
660 .reflect_input = false,
661 .reflect_output = false,
662 .xor_output = 0x000000,
663});
664
665pub const Crc24Ble = Crc(u24, .{
666 .polynomial = 0x00065b,
667 .initial = 0x555555,
668 .reflect_input = true,
669 .reflect_output = true,
670 .xor_output = 0x000000,
671});
672
673pub const Crc24FlexrayA = Crc(u24, .{
674 .polynomial = 0x5d6dcb,
675 .initial = 0xfedcba,
676 .reflect_input = false,
677 .reflect_output = false,
678 .xor_output = 0x000000,
679});
680
681pub const Crc24FlexrayB = Crc(u24, .{
682 .polynomial = 0x5d6dcb,
683 .initial = 0xabcdef,
684 .reflect_input = false,
685 .reflect_output = false,
686 .xor_output = 0x000000,
687});
688
689pub const Crc24Interlaken = Crc(u24, .{
690 .polynomial = 0x328b63,
691 .initial = 0xffffff,
692 .reflect_input = false,
693 .reflect_output = false,
694 .xor_output = 0xffffff,
695});
696
697pub const Crc24LteA = Crc(u24, .{
698 .polynomial = 0x864cfb,
699 .initial = 0x000000,
700 .reflect_input = false,
701 .reflect_output = false,
702 .xor_output = 0x000000,
703});
704
705pub const Crc24LteB = Crc(u24, .{
706 .polynomial = 0x800063,
707 .initial = 0x000000,
708 .reflect_input = false,
709 .reflect_output = false,
710 .xor_output = 0x000000,
711});
712
713pub const Crc24Openpgp = Crc(u24, .{
714 .polynomial = 0x864cfb,
715 .initial = 0xb704ce,
716 .reflect_input = false,
717 .reflect_output = false,
718 .xor_output = 0x000000,
719});
720
721pub const Crc24Os9 = Crc(u24, .{
722 .polynomial = 0x800063,
723 .initial = 0xffffff,
724 .reflect_input = false,
725 .reflect_output = false,
726 .xor_output = 0xffffff,
727});
728
729pub const Crc30Cdma = Crc(u30, .{
730 .polynomial = 0x2030b9c7,
731 .initial = 0x3fffffff,
732 .reflect_input = false,
733 .reflect_output = false,
734 .xor_output = 0x3fffffff,
735});
736
737pub const Crc31Philips = Crc(u31, .{
738 .polynomial = 0x04c11db7,
739 .initial = 0x7fffffff,
740 .reflect_input = false,
741 .reflect_output = false,
742 .xor_output = 0x7fffffff,
743});
744
745pub const Crc32Aixm = Crc(u32, .{
746 .polynomial = 0x814141ab,
747 .initial = 0x00000000,
748 .reflect_input = false,
749 .reflect_output = false,
750 .xor_output = 0x00000000,
751});
752
753pub const Crc32Autosar = Crc(u32, .{
754 .polynomial = 0xf4acfb13,
755 .initial = 0xffffffff,
756 .reflect_input = true,
757 .reflect_output = true,
758 .xor_output = 0xffffffff,
759});
760
761pub const Crc32Base91D = Crc(u32, .{
762 .polynomial = 0xa833982b,
763 .initial = 0xffffffff,
764 .reflect_input = true,
765 .reflect_output = true,
766 .xor_output = 0xffffffff,
767});
768
769pub const Crc32Bzip2 = Crc(u32, .{
770 .polynomial = 0x04c11db7,
771 .initial = 0xffffffff,
772 .reflect_input = false,
773 .reflect_output = false,
774 .xor_output = 0xffffffff,
775});
776
777pub const Crc32CdRomEdc = Crc(u32, .{
778 .polynomial = 0x8001801b,
779 .initial = 0x00000000,
780 .reflect_input = true,
781 .reflect_output = true,
782 .xor_output = 0x00000000,
783});
784
785pub const Crc32Cksum = Crc(u32, .{
786 .polynomial = 0x04c11db7,
787 .initial = 0x00000000,
788 .reflect_input = false,
789 .reflect_output = false,
790 .xor_output = 0xffffffff,
791});
792
793pub const Crc32Iscsi = Crc(u32, .{
794 .polynomial = 0x1edc6f41,
795 .initial = 0xffffffff,
796 .reflect_input = true,
797 .reflect_output = true,
798 .xor_output = 0xffffffff,
799});
800
801pub const Crc32IsoHdlc = Crc(u32, .{
802 .polynomial = 0x04c11db7,
803 .initial = 0xffffffff,
804 .reflect_input = true,
805 .reflect_output = true,
806 .xor_output = 0xffffffff,
807});
808
809pub const Crc32Jamcrc = Crc(u32, .{
810 .polynomial = 0x04c11db7,
811 .initial = 0xffffffff,
812 .reflect_input = true,
813 .reflect_output = true,
814 .xor_output = 0x00000000,
815});
816
817pub const Crc32Mef = Crc(u32, .{
818 .polynomial = 0x741b8cd7,
819 .initial = 0xffffffff,
820 .reflect_input = true,
821 .reflect_output = true,
822 .xor_output = 0x00000000,
823});
824
825pub const Crc32Mpeg2 = Crc(u32, .{
826 .polynomial = 0x04c11db7,
827 .initial = 0xffffffff,
828 .reflect_input = false,
829 .reflect_output = false,
830 .xor_output = 0x00000000,
831});
832
833pub const Crc32Xfer = Crc(u32, .{
834 .polynomial = 0x000000af,
835 .initial = 0x00000000,
836 .reflect_input = false,
837 .reflect_output = false,
838 .xor_output = 0x00000000,
839});
840
841pub const Crc40Gsm = Crc(u40, .{
842 .polynomial = 0x0004820009,
843 .initial = 0x0000000000,
844 .reflect_input = false,
845 .reflect_output = false,
846 .xor_output = 0xffffffffff,
847});
848
849pub const Crc64Ecma182 = Crc(u64, .{
850 .polynomial = 0x42f0e1eba9ea3693,
851 .initial = 0x0000000000000000,
852 .reflect_input = false,
853 .reflect_output = false,
854 .xor_output = 0x0000000000000000,
855});
856
857pub const Crc64GoIso = Crc(u64, .{
858 .polynomial = 0x000000000000001b,
859 .initial = 0xffffffffffffffff,
860 .reflect_input = true,
861 .reflect_output = true,
862 .xor_output = 0xffffffffffffffff,
863});
864
865pub const Crc64Ms = Crc(u64, .{
866 .polynomial = 0x259c84cba6426349,
867 .initial = 0xffffffffffffffff,
868 .reflect_input = true,
869 .reflect_output = true,
870 .xor_output = 0x0000000000000000,
871});
872
873pub const Crc64Redis = Crc(u64, .{
874 .polynomial = 0xad93d23594c935a9,
875 .initial = 0x0000000000000000,
876 .reflect_input = true,
877 .reflect_output = true,
878 .xor_output = 0x0000000000000000,
879});
880
881pub const Crc64We = Crc(u64, .{
882 .polynomial = 0x42f0e1eba9ea3693,
883 .initial = 0xffffffffffffffff,
884 .reflect_input = false,
885 .reflect_output = false,
886 .xor_output = 0xffffffffffffffff,
887});
888
889pub const Crc64Xz = Crc(u64, .{
890 .polynomial = 0x42f0e1eba9ea3693,
891 .initial = 0xffffffffffffffff,
892 .reflect_input = true,
893 .reflect_output = true,
894 .xor_output = 0xffffffffffffffff,
895});
896
897pub const Crc82Darc = Crc(u82, .{
898 .polynomial = 0x0308c0111011401440411,
899 .initial = 0x000000000000000000000,
900 .reflect_input = true,
901 .reflect_output = true,
902 .xor_output = 0x000000000000000000000,
903});
lib/std/hash/crc/catalog_test.zig deleted-1237
...@@ -1,1237 +0,0 @@
1//! This file is auto-generated by tools/update_crc_catalog.zig.
2
3const std = @import("std");
4const testing = std.testing;
5const catalog = @import("catalog.zig");
6
7test "CRC-3/GSM" {
8 const Crc3Gsm = catalog.Crc3Gsm;
9
10 try testing.expectEqual(@as(u3, 0x4), Crc3Gsm.hash("123456789"));
11
12 var c = Crc3Gsm.init();
13 c.update("1234");
14 c.update("56789");
15 try testing.expectEqual(@as(u3, 0x4), c.final());
16}
17
18test "CRC-3/ROHC" {
19 const Crc3Rohc = catalog.Crc3Rohc;
20
21 try testing.expectEqual(@as(u3, 0x6), Crc3Rohc.hash("123456789"));
22
23 var c = Crc3Rohc.init();
24 c.update("1234");
25 c.update("56789");
26 try testing.expectEqual(@as(u3, 0x6), c.final());
27}
28
29test "CRC-4/G-704" {
30 const Crc4G704 = catalog.Crc4G704;
31
32 try testing.expectEqual(@as(u4, 0x7), Crc4G704.hash("123456789"));
33
34 var c = Crc4G704.init();
35 c.update("1234");
36 c.update("56789");
37 try testing.expectEqual(@as(u4, 0x7), c.final());
38}
39
40test "CRC-4/INTERLAKEN" {
41 const Crc4Interlaken = catalog.Crc4Interlaken;
42
43 try testing.expectEqual(@as(u4, 0xb), Crc4Interlaken.hash("123456789"));
44
45 var c = Crc4Interlaken.init();
46 c.update("1234");
47 c.update("56789");
48 try testing.expectEqual(@as(u4, 0xb), c.final());
49}
50
51test "CRC-5/EPC-C1G2" {
52 const Crc5EpcC1g2 = catalog.Crc5EpcC1g2;
53
54 try testing.expectEqual(@as(u5, 0x00), Crc5EpcC1g2.hash("123456789"));
55
56 var c = Crc5EpcC1g2.init();
57 c.update("1234");
58 c.update("56789");
59 try testing.expectEqual(@as(u5, 0x00), c.final());
60}
61
62test "CRC-5/G-704" {
63 const Crc5G704 = catalog.Crc5G704;
64
65 try testing.expectEqual(@as(u5, 0x07), Crc5G704.hash("123456789"));
66
67 var c = Crc5G704.init();
68 c.update("1234");
69 c.update("56789");
70 try testing.expectEqual(@as(u5, 0x07), c.final());
71}
72
73test "CRC-5/USB" {
74 const Crc5Usb = catalog.Crc5Usb;
75
76 try testing.expectEqual(@as(u5, 0x19), Crc5Usb.hash("123456789"));
77
78 var c = Crc5Usb.init();
79 c.update("1234");
80 c.update("56789");
81 try testing.expectEqual(@as(u5, 0x19), c.final());
82}
83
84test "CRC-6/CDMA2000-A" {
85 const Crc6Cdma2000A = catalog.Crc6Cdma2000A;
86
87 try testing.expectEqual(@as(u6, 0x0d), Crc6Cdma2000A.hash("123456789"));
88
89 var c = Crc6Cdma2000A.init();
90 c.update("1234");
91 c.update("56789");
92 try testing.expectEqual(@as(u6, 0x0d), c.final());
93}
94
95test "CRC-6/CDMA2000-B" {
96 const Crc6Cdma2000B = catalog.Crc6Cdma2000B;
97
98 try testing.expectEqual(@as(u6, 0x3b), Crc6Cdma2000B.hash("123456789"));
99
100 var c = Crc6Cdma2000B.init();
101 c.update("1234");
102 c.update("56789");
103 try testing.expectEqual(@as(u6, 0x3b), c.final());
104}
105
106test "CRC-6/DARC" {
107 const Crc6Darc = catalog.Crc6Darc;
108
109 try testing.expectEqual(@as(u6, 0x26), Crc6Darc.hash("123456789"));
110
111 var c = Crc6Darc.init();
112 c.update("1234");
113 c.update("56789");
114 try testing.expectEqual(@as(u6, 0x26), c.final());
115}
116
117test "CRC-6/G-704" {
118 const Crc6G704 = catalog.Crc6G704;
119
120 try testing.expectEqual(@as(u6, 0x06), Crc6G704.hash("123456789"));
121
122 var c = Crc6G704.init();
123 c.update("1234");
124 c.update("56789");
125 try testing.expectEqual(@as(u6, 0x06), c.final());
126}
127
128test "CRC-6/GSM" {
129 const Crc6Gsm = catalog.Crc6Gsm;
130
131 try testing.expectEqual(@as(u6, 0x13), Crc6Gsm.hash("123456789"));
132
133 var c = Crc6Gsm.init();
134 c.update("1234");
135 c.update("56789");
136 try testing.expectEqual(@as(u6, 0x13), c.final());
137}
138
139test "CRC-7/MMC" {
140 const Crc7Mmc = catalog.Crc7Mmc;
141
142 try testing.expectEqual(@as(u7, 0x75), Crc7Mmc.hash("123456789"));
143
144 var c = Crc7Mmc.init();
145 c.update("1234");
146 c.update("56789");
147 try testing.expectEqual(@as(u7, 0x75), c.final());
148}
149
150test "CRC-7/ROHC" {
151 const Crc7Rohc = catalog.Crc7Rohc;
152
153 try testing.expectEqual(@as(u7, 0x53), Crc7Rohc.hash("123456789"));
154
155 var c = Crc7Rohc.init();
156 c.update("1234");
157 c.update("56789");
158 try testing.expectEqual(@as(u7, 0x53), c.final());
159}
160
161test "CRC-7/UMTS" {
162 const Crc7Umts = catalog.Crc7Umts;
163
164 try testing.expectEqual(@as(u7, 0x61), Crc7Umts.hash("123456789"));
165
166 var c = Crc7Umts.init();
167 c.update("1234");
168 c.update("56789");
169 try testing.expectEqual(@as(u7, 0x61), c.final());
170}
171
172test "CRC-8/AUTOSAR" {
173 const Crc8Autosar = catalog.Crc8Autosar;
174
175 try testing.expectEqual(@as(u8, 0xdf), Crc8Autosar.hash("123456789"));
176
177 var c = Crc8Autosar.init();
178 c.update("1234");
179 c.update("56789");
180 try testing.expectEqual(@as(u8, 0xdf), c.final());
181}
182
183test "CRC-8/BLUETOOTH" {
184 const Crc8Bluetooth = catalog.Crc8Bluetooth;
185
186 try testing.expectEqual(@as(u8, 0x26), Crc8Bluetooth.hash("123456789"));
187
188 var c = Crc8Bluetooth.init();
189 c.update("1234");
190 c.update("56789");
191 try testing.expectEqual(@as(u8, 0x26), c.final());
192}
193
194test "CRC-8/CDMA2000" {
195 const Crc8Cdma2000 = catalog.Crc8Cdma2000;
196
197 try testing.expectEqual(@as(u8, 0xda), Crc8Cdma2000.hash("123456789"));
198
199 var c = Crc8Cdma2000.init();
200 c.update("1234");
201 c.update("56789");
202 try testing.expectEqual(@as(u8, 0xda), c.final());
203}
204
205test "CRC-8/DARC" {
206 const Crc8Darc = catalog.Crc8Darc;
207
208 try testing.expectEqual(@as(u8, 0x15), Crc8Darc.hash("123456789"));
209
210 var c = Crc8Darc.init();
211 c.update("1234");
212 c.update("56789");
213 try testing.expectEqual(@as(u8, 0x15), c.final());
214}
215
216test "CRC-8/DVB-S2" {
217 const Crc8DvbS2 = catalog.Crc8DvbS2;
218
219 try testing.expectEqual(@as(u8, 0xbc), Crc8DvbS2.hash("123456789"));
220
221 var c = Crc8DvbS2.init();
222 c.update("1234");
223 c.update("56789");
224 try testing.expectEqual(@as(u8, 0xbc), c.final());
225}
226
227test "CRC-8/GSM-A" {
228 const Crc8GsmA = catalog.Crc8GsmA;
229
230 try testing.expectEqual(@as(u8, 0x37), Crc8GsmA.hash("123456789"));
231
232 var c = Crc8GsmA.init();
233 c.update("1234");
234 c.update("56789");
235 try testing.expectEqual(@as(u8, 0x37), c.final());
236}
237
238test "CRC-8/GSM-B" {
239 const Crc8GsmB = catalog.Crc8GsmB;
240
241 try testing.expectEqual(@as(u8, 0x94), Crc8GsmB.hash("123456789"));
242
243 var c = Crc8GsmB.init();
244 c.update("1234");
245 c.update("56789");
246 try testing.expectEqual(@as(u8, 0x94), c.final());
247}
248
249test "CRC-8/HITAG" {
250 const Crc8Hitag = catalog.Crc8Hitag;
251
252 try testing.expectEqual(@as(u8, 0xb4), Crc8Hitag.hash("123456789"));
253
254 var c = Crc8Hitag.init();
255 c.update("1234");
256 c.update("56789");
257 try testing.expectEqual(@as(u8, 0xb4), c.final());
258}
259
260test "CRC-8/I-432-1" {
261 const Crc8I4321 = catalog.Crc8I4321;
262
263 try testing.expectEqual(@as(u8, 0xa1), Crc8I4321.hash("123456789"));
264
265 var c = Crc8I4321.init();
266 c.update("1234");
267 c.update("56789");
268 try testing.expectEqual(@as(u8, 0xa1), c.final());
269}
270
271test "CRC-8/I-CODE" {
272 const Crc8ICode = catalog.Crc8ICode;
273
274 try testing.expectEqual(@as(u8, 0x7e), Crc8ICode.hash("123456789"));
275
276 var c = Crc8ICode.init();
277 c.update("1234");
278 c.update("56789");
279 try testing.expectEqual(@as(u8, 0x7e), c.final());
280}
281
282test "CRC-8/LTE" {
283 const Crc8Lte = catalog.Crc8Lte;
284
285 try testing.expectEqual(@as(u8, 0xea), Crc8Lte.hash("123456789"));
286
287 var c = Crc8Lte.init();
288 c.update("1234");
289 c.update("56789");
290 try testing.expectEqual(@as(u8, 0xea), c.final());
291}
292
293test "CRC-8/MAXIM-DOW" {
294 const Crc8MaximDow = catalog.Crc8MaximDow;
295
296 try testing.expectEqual(@as(u8, 0xa1), Crc8MaximDow.hash("123456789"));
297
298 var c = Crc8MaximDow.init();
299 c.update("1234");
300 c.update("56789");
301 try testing.expectEqual(@as(u8, 0xa1), c.final());
302}
303
304test "CRC-8/MIFARE-MAD" {
305 const Crc8MifareMad = catalog.Crc8MifareMad;
306
307 try testing.expectEqual(@as(u8, 0x99), Crc8MifareMad.hash("123456789"));
308
309 var c = Crc8MifareMad.init();
310 c.update("1234");
311 c.update("56789");
312 try testing.expectEqual(@as(u8, 0x99), c.final());
313}
314
315test "CRC-8/NRSC-5" {
316 const Crc8Nrsc5 = catalog.Crc8Nrsc5;
317
318 try testing.expectEqual(@as(u8, 0xf7), Crc8Nrsc5.hash("123456789"));
319
320 var c = Crc8Nrsc5.init();
321 c.update("1234");
322 c.update("56789");
323 try testing.expectEqual(@as(u8, 0xf7), c.final());
324}
325
326test "CRC-8/OPENSAFETY" {
327 const Crc8Opensafety = catalog.Crc8Opensafety;
328
329 try testing.expectEqual(@as(u8, 0x3e), Crc8Opensafety.hash("123456789"));
330
331 var c = Crc8Opensafety.init();
332 c.update("1234");
333 c.update("56789");
334 try testing.expectEqual(@as(u8, 0x3e), c.final());
335}
336
337test "CRC-8/ROHC" {
338 const Crc8Rohc = catalog.Crc8Rohc;
339
340 try testing.expectEqual(@as(u8, 0xd0), Crc8Rohc.hash("123456789"));
341
342 var c = Crc8Rohc.init();
343 c.update("1234");
344 c.update("56789");
345 try testing.expectEqual(@as(u8, 0xd0), c.final());
346}
347
348test "CRC-8/SAE-J1850" {
349 const Crc8SaeJ1850 = catalog.Crc8SaeJ1850;
350
351 try testing.expectEqual(@as(u8, 0x4b), Crc8SaeJ1850.hash("123456789"));
352
353 var c = Crc8SaeJ1850.init();
354 c.update("1234");
355 c.update("56789");
356 try testing.expectEqual(@as(u8, 0x4b), c.final());
357}
358
359test "CRC-8/SMBUS" {
360 const Crc8Smbus = catalog.Crc8Smbus;
361
362 try testing.expectEqual(@as(u8, 0xf4), Crc8Smbus.hash("123456789"));
363
364 var c = Crc8Smbus.init();
365 c.update("1234");
366 c.update("56789");
367 try testing.expectEqual(@as(u8, 0xf4), c.final());
368}
369
370test "CRC-8/TECH-3250" {
371 const Crc8Tech3250 = catalog.Crc8Tech3250;
372
373 try testing.expectEqual(@as(u8, 0x97), Crc8Tech3250.hash("123456789"));
374
375 var c = Crc8Tech3250.init();
376 c.update("1234");
377 c.update("56789");
378 try testing.expectEqual(@as(u8, 0x97), c.final());
379}
380
381test "CRC-8/WCDMA" {
382 const Crc8Wcdma = catalog.Crc8Wcdma;
383
384 try testing.expectEqual(@as(u8, 0x25), Crc8Wcdma.hash("123456789"));
385
386 var c = Crc8Wcdma.init();
387 c.update("1234");
388 c.update("56789");
389 try testing.expectEqual(@as(u8, 0x25), c.final());
390}
391
392test "CRC-10/ATM" {
393 const Crc10Atm = catalog.Crc10Atm;
394
395 try testing.expectEqual(@as(u10, 0x199), Crc10Atm.hash("123456789"));
396
397 var c = Crc10Atm.init();
398 c.update("1234");
399 c.update("56789");
400 try testing.expectEqual(@as(u10, 0x199), c.final());
401}
402
403test "CRC-10/CDMA2000" {
404 const Crc10Cdma2000 = catalog.Crc10Cdma2000;
405
406 try testing.expectEqual(@as(u10, 0x233), Crc10Cdma2000.hash("123456789"));
407
408 var c = Crc10Cdma2000.init();
409 c.update("1234");
410 c.update("56789");
411 try testing.expectEqual(@as(u10, 0x233), c.final());
412}
413
414test "CRC-10/GSM" {
415 const Crc10Gsm = catalog.Crc10Gsm;
416
417 try testing.expectEqual(@as(u10, 0x12a), Crc10Gsm.hash("123456789"));
418
419 var c = Crc10Gsm.init();
420 c.update("1234");
421 c.update("56789");
422 try testing.expectEqual(@as(u10, 0x12a), c.final());
423}
424
425test "CRC-11/FLEXRAY" {
426 const Crc11Flexray = catalog.Crc11Flexray;
427
428 try testing.expectEqual(@as(u11, 0x5a3), Crc11Flexray.hash("123456789"));
429
430 var c = Crc11Flexray.init();
431 c.update("1234");
432 c.update("56789");
433 try testing.expectEqual(@as(u11, 0x5a3), c.final());
434}
435
436test "CRC-11/UMTS" {
437 const Crc11Umts = catalog.Crc11Umts;
438
439 try testing.expectEqual(@as(u11, 0x061), Crc11Umts.hash("123456789"));
440
441 var c = Crc11Umts.init();
442 c.update("1234");
443 c.update("56789");
444 try testing.expectEqual(@as(u11, 0x061), c.final());
445}
446
447test "CRC-12/CDMA2000" {
448 const Crc12Cdma2000 = catalog.Crc12Cdma2000;
449
450 try testing.expectEqual(@as(u12, 0xd4d), Crc12Cdma2000.hash("123456789"));
451
452 var c = Crc12Cdma2000.init();
453 c.update("1234");
454 c.update("56789");
455 try testing.expectEqual(@as(u12, 0xd4d), c.final());
456}
457
458test "CRC-12/DECT" {
459 const Crc12Dect = catalog.Crc12Dect;
460
461 try testing.expectEqual(@as(u12, 0xf5b), Crc12Dect.hash("123456789"));
462
463 var c = Crc12Dect.init();
464 c.update("1234");
465 c.update("56789");
466 try testing.expectEqual(@as(u12, 0xf5b), c.final());
467}
468
469test "CRC-12/GSM" {
470 const Crc12Gsm = catalog.Crc12Gsm;
471
472 try testing.expectEqual(@as(u12, 0xb34), Crc12Gsm.hash("123456789"));
473
474 var c = Crc12Gsm.init();
475 c.update("1234");
476 c.update("56789");
477 try testing.expectEqual(@as(u12, 0xb34), c.final());
478}
479
480test "CRC-12/UMTS" {
481 const Crc12Umts = catalog.Crc12Umts;
482
483 try testing.expectEqual(@as(u12, 0xdaf), Crc12Umts.hash("123456789"));
484
485 var c = Crc12Umts.init();
486 c.update("1234");
487 c.update("56789");
488 try testing.expectEqual(@as(u12, 0xdaf), c.final());
489}
490
491test "CRC-13/BBC" {
492 const Crc13Bbc = catalog.Crc13Bbc;
493
494 try testing.expectEqual(@as(u13, 0x04fa), Crc13Bbc.hash("123456789"));
495
496 var c = Crc13Bbc.init();
497 c.update("1234");
498 c.update("56789");
499 try testing.expectEqual(@as(u13, 0x04fa), c.final());
500}
501
502test "CRC-14/DARC" {
503 const Crc14Darc = catalog.Crc14Darc;
504
505 try testing.expectEqual(@as(u14, 0x082d), Crc14Darc.hash("123456789"));
506
507 var c = Crc14Darc.init();
508 c.update("1234");
509 c.update("56789");
510 try testing.expectEqual(@as(u14, 0x082d), c.final());
511}
512
513test "CRC-14/GSM" {
514 const Crc14Gsm = catalog.Crc14Gsm;
515
516 try testing.expectEqual(@as(u14, 0x30ae), Crc14Gsm.hash("123456789"));
517
518 var c = Crc14Gsm.init();
519 c.update("1234");
520 c.update("56789");
521 try testing.expectEqual(@as(u14, 0x30ae), c.final());
522}
523
524test "CRC-15/CAN" {
525 const Crc15Can = catalog.Crc15Can;
526
527 try testing.expectEqual(@as(u15, 0x059e), Crc15Can.hash("123456789"));
528
529 var c = Crc15Can.init();
530 c.update("1234");
531 c.update("56789");
532 try testing.expectEqual(@as(u15, 0x059e), c.final());
533}
534
535test "CRC-15/MPT1327" {
536 const Crc15Mpt1327 = catalog.Crc15Mpt1327;
537
538 try testing.expectEqual(@as(u15, 0x2566), Crc15Mpt1327.hash("123456789"));
539
540 var c = Crc15Mpt1327.init();
541 c.update("1234");
542 c.update("56789");
543 try testing.expectEqual(@as(u15, 0x2566), c.final());
544}
545
546test "CRC-16/ARC" {
547 const Crc16Arc = catalog.Crc16Arc;
548
549 try testing.expectEqual(@as(u16, 0xbb3d), Crc16Arc.hash("123456789"));
550
551 var c = Crc16Arc.init();
552 c.update("1234");
553 c.update("56789");
554 try testing.expectEqual(@as(u16, 0xbb3d), c.final());
555}
556
557test "CRC-16/CDMA2000" {
558 const Crc16Cdma2000 = catalog.Crc16Cdma2000;
559
560 try testing.expectEqual(@as(u16, 0x4c06), Crc16Cdma2000.hash("123456789"));
561
562 var c = Crc16Cdma2000.init();
563 c.update("1234");
564 c.update("56789");
565 try testing.expectEqual(@as(u16, 0x4c06), c.final());
566}
567
568test "CRC-16/CMS" {
569 const Crc16Cms = catalog.Crc16Cms;
570
571 try testing.expectEqual(@as(u16, 0xaee7), Crc16Cms.hash("123456789"));
572
573 var c = Crc16Cms.init();
574 c.update("1234");
575 c.update("56789");
576 try testing.expectEqual(@as(u16, 0xaee7), c.final());
577}
578
579test "CRC-16/DDS-110" {
580 const Crc16Dds110 = catalog.Crc16Dds110;
581
582 try testing.expectEqual(@as(u16, 0x9ecf), Crc16Dds110.hash("123456789"));
583
584 var c = Crc16Dds110.init();
585 c.update("1234");
586 c.update("56789");
587 try testing.expectEqual(@as(u16, 0x9ecf), c.final());
588}
589
590test "CRC-16/DECT-R" {
591 const Crc16DectR = catalog.Crc16DectR;
592
593 try testing.expectEqual(@as(u16, 0x007e), Crc16DectR.hash("123456789"));
594
595 var c = Crc16DectR.init();
596 c.update("1234");
597 c.update("56789");
598 try testing.expectEqual(@as(u16, 0x007e), c.final());
599}
600
601test "CRC-16/DECT-X" {
602 const Crc16DectX = catalog.Crc16DectX;
603
604 try testing.expectEqual(@as(u16, 0x007f), Crc16DectX.hash("123456789"));
605
606 var c = Crc16DectX.init();
607 c.update("1234");
608 c.update("56789");
609 try testing.expectEqual(@as(u16, 0x007f), c.final());
610}
611
612test "CRC-16/DNP" {
613 const Crc16Dnp = catalog.Crc16Dnp;
614
615 try testing.expectEqual(@as(u16, 0xea82), Crc16Dnp.hash("123456789"));
616
617 var c = Crc16Dnp.init();
618 c.update("1234");
619 c.update("56789");
620 try testing.expectEqual(@as(u16, 0xea82), c.final());
621}
622
623test "CRC-16/EN-13757" {
624 const Crc16En13757 = catalog.Crc16En13757;
625
626 try testing.expectEqual(@as(u16, 0xc2b7), Crc16En13757.hash("123456789"));
627
628 var c = Crc16En13757.init();
629 c.update("1234");
630 c.update("56789");
631 try testing.expectEqual(@as(u16, 0xc2b7), c.final());
632}
633
634test "CRC-16/GENIBUS" {
635 const Crc16Genibus = catalog.Crc16Genibus;
636
637 try testing.expectEqual(@as(u16, 0xd64e), Crc16Genibus.hash("123456789"));
638
639 var c = Crc16Genibus.init();
640 c.update("1234");
641 c.update("56789");
642 try testing.expectEqual(@as(u16, 0xd64e), c.final());
643}
644
645test "CRC-16/GSM" {
646 const Crc16Gsm = catalog.Crc16Gsm;
647
648 try testing.expectEqual(@as(u16, 0xce3c), Crc16Gsm.hash("123456789"));
649
650 var c = Crc16Gsm.init();
651 c.update("1234");
652 c.update("56789");
653 try testing.expectEqual(@as(u16, 0xce3c), c.final());
654}
655
656test "CRC-16/IBM-3740" {
657 const Crc16Ibm3740 = catalog.Crc16Ibm3740;
658
659 try testing.expectEqual(@as(u16, 0x29b1), Crc16Ibm3740.hash("123456789"));
660
661 var c = Crc16Ibm3740.init();
662 c.update("1234");
663 c.update("56789");
664 try testing.expectEqual(@as(u16, 0x29b1), c.final());
665}
666
667test "CRC-16/IBM-SDLC" {
668 const Crc16IbmSdlc = catalog.Crc16IbmSdlc;
669
670 try testing.expectEqual(@as(u16, 0x906e), Crc16IbmSdlc.hash("123456789"));
671
672 var c = Crc16IbmSdlc.init();
673 c.update("1234");
674 c.update("56789");
675 try testing.expectEqual(@as(u16, 0x906e), c.final());
676}
677
678test "CRC-16/ISO-IEC-14443-3-A" {
679 const Crc16IsoIec144433A = catalog.Crc16IsoIec144433A;
680
681 try testing.expectEqual(@as(u16, 0xbf05), Crc16IsoIec144433A.hash("123456789"));
682
683 var c = Crc16IsoIec144433A.init();
684 c.update("1234");
685 c.update("56789");
686 try testing.expectEqual(@as(u16, 0xbf05), c.final());
687}
688
689test "CRC-16/KERMIT" {
690 const Crc16Kermit = catalog.Crc16Kermit;
691
692 try testing.expectEqual(@as(u16, 0x2189), Crc16Kermit.hash("123456789"));
693
694 var c = Crc16Kermit.init();
695 c.update("1234");
696 c.update("56789");
697 try testing.expectEqual(@as(u16, 0x2189), c.final());
698}
699
700test "CRC-16/LJ1200" {
701 const Crc16Lj1200 = catalog.Crc16Lj1200;
702
703 try testing.expectEqual(@as(u16, 0xbdf4), Crc16Lj1200.hash("123456789"));
704
705 var c = Crc16Lj1200.init();
706 c.update("1234");
707 c.update("56789");
708 try testing.expectEqual(@as(u16, 0xbdf4), c.final());
709}
710
711test "CRC-16/M17" {
712 const Crc16M17 = catalog.Crc16M17;
713
714 try testing.expectEqual(@as(u16, 0x772b), Crc16M17.hash("123456789"));
715
716 var c = Crc16M17.init();
717 c.update("1234");
718 c.update("56789");
719 try testing.expectEqual(@as(u16, 0x772b), c.final());
720}
721
722test "CRC-16/MAXIM-DOW" {
723 const Crc16MaximDow = catalog.Crc16MaximDow;
724
725 try testing.expectEqual(@as(u16, 0x44c2), Crc16MaximDow.hash("123456789"));
726
727 var c = Crc16MaximDow.init();
728 c.update("1234");
729 c.update("56789");
730 try testing.expectEqual(@as(u16, 0x44c2), c.final());
731}
732
733test "CRC-16/MCRF4XX" {
734 const Crc16Mcrf4xx = catalog.Crc16Mcrf4xx;
735
736 try testing.expectEqual(@as(u16, 0x6f91), Crc16Mcrf4xx.hash("123456789"));
737
738 var c = Crc16Mcrf4xx.init();
739 c.update("1234");
740 c.update("56789");
741 try testing.expectEqual(@as(u16, 0x6f91), c.final());
742}
743
744test "CRC-16/MODBUS" {
745 const Crc16Modbus = catalog.Crc16Modbus;
746
747 try testing.expectEqual(@as(u16, 0x4b37), Crc16Modbus.hash("123456789"));
748
749 var c = Crc16Modbus.init();
750 c.update("1234");
751 c.update("56789");
752 try testing.expectEqual(@as(u16, 0x4b37), c.final());
753}
754
755test "CRC-16/NRSC-5" {
756 const Crc16Nrsc5 = catalog.Crc16Nrsc5;
757
758 try testing.expectEqual(@as(u16, 0xa066), Crc16Nrsc5.hash("123456789"));
759
760 var c = Crc16Nrsc5.init();
761 c.update("1234");
762 c.update("56789");
763 try testing.expectEqual(@as(u16, 0xa066), c.final());
764}
765
766test "CRC-16/OPENSAFETY-A" {
767 const Crc16OpensafetyA = catalog.Crc16OpensafetyA;
768
769 try testing.expectEqual(@as(u16, 0x5d38), Crc16OpensafetyA.hash("123456789"));
770
771 var c = Crc16OpensafetyA.init();
772 c.update("1234");
773 c.update("56789");
774 try testing.expectEqual(@as(u16, 0x5d38), c.final());
775}
776
777test "CRC-16/OPENSAFETY-B" {
778 const Crc16OpensafetyB = catalog.Crc16OpensafetyB;
779
780 try testing.expectEqual(@as(u16, 0x20fe), Crc16OpensafetyB.hash("123456789"));
781
782 var c = Crc16OpensafetyB.init();
783 c.update("1234");
784 c.update("56789");
785 try testing.expectEqual(@as(u16, 0x20fe), c.final());
786}
787
788test "CRC-16/PROFIBUS" {
789 const Crc16Profibus = catalog.Crc16Profibus;
790
791 try testing.expectEqual(@as(u16, 0xa819), Crc16Profibus.hash("123456789"));
792
793 var c = Crc16Profibus.init();
794 c.update("1234");
795 c.update("56789");
796 try testing.expectEqual(@as(u16, 0xa819), c.final());
797}
798
799test "CRC-16/RIELLO" {
800 const Crc16Riello = catalog.Crc16Riello;
801
802 try testing.expectEqual(@as(u16, 0x63d0), Crc16Riello.hash("123456789"));
803
804 var c = Crc16Riello.init();
805 c.update("1234");
806 c.update("56789");
807 try testing.expectEqual(@as(u16, 0x63d0), c.final());
808}
809
810test "CRC-16/SPI-FUJITSU" {
811 const Crc16SpiFujitsu = catalog.Crc16SpiFujitsu;
812
813 try testing.expectEqual(@as(u16, 0xe5cc), Crc16SpiFujitsu.hash("123456789"));
814
815 var c = Crc16SpiFujitsu.init();
816 c.update("1234");
817 c.update("56789");
818 try testing.expectEqual(@as(u16, 0xe5cc), c.final());
819}
820
821test "CRC-16/T10-DIF" {
822 const Crc16T10Dif = catalog.Crc16T10Dif;
823
824 try testing.expectEqual(@as(u16, 0xd0db), Crc16T10Dif.hash("123456789"));
825
826 var c = Crc16T10Dif.init();
827 c.update("1234");
828 c.update("56789");
829 try testing.expectEqual(@as(u16, 0xd0db), c.final());
830}
831
832test "CRC-16/TELEDISK" {
833 const Crc16Teledisk = catalog.Crc16Teledisk;
834
835 try testing.expectEqual(@as(u16, 0x0fb3), Crc16Teledisk.hash("123456789"));
836
837 var c = Crc16Teledisk.init();
838 c.update("1234");
839 c.update("56789");
840 try testing.expectEqual(@as(u16, 0x0fb3), c.final());
841}
842
843test "CRC-16/TMS37157" {
844 const Crc16Tms37157 = catalog.Crc16Tms37157;
845
846 try testing.expectEqual(@as(u16, 0x26b1), Crc16Tms37157.hash("123456789"));
847
848 var c = Crc16Tms37157.init();
849 c.update("1234");
850 c.update("56789");
851 try testing.expectEqual(@as(u16, 0x26b1), c.final());
852}
853
854test "CRC-16/UMTS" {
855 const Crc16Umts = catalog.Crc16Umts;
856
857 try testing.expectEqual(@as(u16, 0xfee8), Crc16Umts.hash("123456789"));
858
859 var c = Crc16Umts.init();
860 c.update("1234");
861 c.update("56789");
862 try testing.expectEqual(@as(u16, 0xfee8), c.final());
863}
864
865test "CRC-16/USB" {
866 const Crc16Usb = catalog.Crc16Usb;
867
868 try testing.expectEqual(@as(u16, 0xb4c8), Crc16Usb.hash("123456789"));
869
870 var c = Crc16Usb.init();
871 c.update("1234");
872 c.update("56789");
873 try testing.expectEqual(@as(u16, 0xb4c8), c.final());
874}
875
876test "CRC-16/XMODEM" {
877 const Crc16Xmodem = catalog.Crc16Xmodem;
878
879 try testing.expectEqual(@as(u16, 0x31c3), Crc16Xmodem.hash("123456789"));
880
881 var c = Crc16Xmodem.init();
882 c.update("1234");
883 c.update("56789");
884 try testing.expectEqual(@as(u16, 0x31c3), c.final());
885}
886
887test "CRC-17/CAN-FD" {
888 const Crc17CanFd = catalog.Crc17CanFd;
889
890 try testing.expectEqual(@as(u17, 0x04f03), Crc17CanFd.hash("123456789"));
891
892 var c = Crc17CanFd.init();
893 c.update("1234");
894 c.update("56789");
895 try testing.expectEqual(@as(u17, 0x04f03), c.final());
896}
897
898test "CRC-21/CAN-FD" {
899 const Crc21CanFd = catalog.Crc21CanFd;
900
901 try testing.expectEqual(@as(u21, 0x0ed841), Crc21CanFd.hash("123456789"));
902
903 var c = Crc21CanFd.init();
904 c.update("1234");
905 c.update("56789");
906 try testing.expectEqual(@as(u21, 0x0ed841), c.final());
907}
908
909test "CRC-24/BLE" {
910 const Crc24Ble = catalog.Crc24Ble;
911
912 try testing.expectEqual(@as(u24, 0xc25a56), Crc24Ble.hash("123456789"));
913
914 var c = Crc24Ble.init();
915 c.update("1234");
916 c.update("56789");
917 try testing.expectEqual(@as(u24, 0xc25a56), c.final());
918}
919
920test "CRC-24/FLEXRAY-A" {
921 const Crc24FlexrayA = catalog.Crc24FlexrayA;
922
923 try testing.expectEqual(@as(u24, 0x7979bd), Crc24FlexrayA.hash("123456789"));
924
925 var c = Crc24FlexrayA.init();
926 c.update("1234");
927 c.update("56789");
928 try testing.expectEqual(@as(u24, 0x7979bd), c.final());
929}
930
931test "CRC-24/FLEXRAY-B" {
932 const Crc24FlexrayB = catalog.Crc24FlexrayB;
933
934 try testing.expectEqual(@as(u24, 0x1f23b8), Crc24FlexrayB.hash("123456789"));
935
936 var c = Crc24FlexrayB.init();
937 c.update("1234");
938 c.update("56789");
939 try testing.expectEqual(@as(u24, 0x1f23b8), c.final());
940}
941
942test "CRC-24/INTERLAKEN" {
943 const Crc24Interlaken = catalog.Crc24Interlaken;
944
945 try testing.expectEqual(@as(u24, 0xb4f3e6), Crc24Interlaken.hash("123456789"));
946
947 var c = Crc24Interlaken.init();
948 c.update("1234");
949 c.update("56789");
950 try testing.expectEqual(@as(u24, 0xb4f3e6), c.final());
951}
952
953test "CRC-24/LTE-A" {
954 const Crc24LteA = catalog.Crc24LteA;
955
956 try testing.expectEqual(@as(u24, 0xcde703), Crc24LteA.hash("123456789"));
957
958 var c = Crc24LteA.init();
959 c.update("1234");
960 c.update("56789");
961 try testing.expectEqual(@as(u24, 0xcde703), c.final());
962}
963
964test "CRC-24/LTE-B" {
965 const Crc24LteB = catalog.Crc24LteB;
966
967 try testing.expectEqual(@as(u24, 0x23ef52), Crc24LteB.hash("123456789"));
968
969 var c = Crc24LteB.init();
970 c.update("1234");
971 c.update("56789");
972 try testing.expectEqual(@as(u24, 0x23ef52), c.final());
973}
974
975test "CRC-24/OPENPGP" {
976 const Crc24Openpgp = catalog.Crc24Openpgp;
977
978 try testing.expectEqual(@as(u24, 0x21cf02), Crc24Openpgp.hash("123456789"));
979
980 var c = Crc24Openpgp.init();
981 c.update("1234");
982 c.update("56789");
983 try testing.expectEqual(@as(u24, 0x21cf02), c.final());
984}
985
986test "CRC-24/OS-9" {
987 const Crc24Os9 = catalog.Crc24Os9;
988
989 try testing.expectEqual(@as(u24, 0x200fa5), Crc24Os9.hash("123456789"));
990
991 var c = Crc24Os9.init();
992 c.update("1234");
993 c.update("56789");
994 try testing.expectEqual(@as(u24, 0x200fa5), c.final());
995}
996
997test "CRC-30/CDMA" {
998 const Crc30Cdma = catalog.Crc30Cdma;
999
1000 try testing.expectEqual(@as(u30, 0x04c34abf), Crc30Cdma.hash("123456789"));
1001
1002 var c = Crc30Cdma.init();
1003 c.update("1234");
1004 c.update("56789");
1005 try testing.expectEqual(@as(u30, 0x04c34abf), c.final());
1006}
1007
1008test "CRC-31/PHILIPS" {
1009 const Crc31Philips = catalog.Crc31Philips;
1010
1011 try testing.expectEqual(@as(u31, 0x0ce9e46c), Crc31Philips.hash("123456789"));
1012
1013 var c = Crc31Philips.init();
1014 c.update("1234");
1015 c.update("56789");
1016 try testing.expectEqual(@as(u31, 0x0ce9e46c), c.final());
1017}
1018
1019test "CRC-32/AIXM" {
1020 const Crc32Aixm = catalog.Crc32Aixm;
1021
1022 try testing.expectEqual(@as(u32, 0x3010bf7f), Crc32Aixm.hash("123456789"));
1023
1024 var c = Crc32Aixm.init();
1025 c.update("1234");
1026 c.update("56789");
1027 try testing.expectEqual(@as(u32, 0x3010bf7f), c.final());
1028}
1029
1030test "CRC-32/AUTOSAR" {
1031 const Crc32Autosar = catalog.Crc32Autosar;
1032
1033 try testing.expectEqual(@as(u32, 0x1697d06a), Crc32Autosar.hash("123456789"));
1034
1035 var c = Crc32Autosar.init();
1036 c.update("1234");
1037 c.update("56789");
1038 try testing.expectEqual(@as(u32, 0x1697d06a), c.final());
1039}
1040
1041test "CRC-32/BASE91-D" {
1042 const Crc32Base91D = catalog.Crc32Base91D;
1043
1044 try testing.expectEqual(@as(u32, 0x87315576), Crc32Base91D.hash("123456789"));
1045
1046 var c = Crc32Base91D.init();
1047 c.update("1234");
1048 c.update("56789");
1049 try testing.expectEqual(@as(u32, 0x87315576), c.final());
1050}
1051
1052test "CRC-32/BZIP2" {
1053 const Crc32Bzip2 = catalog.Crc32Bzip2;
1054
1055 try testing.expectEqual(@as(u32, 0xfc891918), Crc32Bzip2.hash("123456789"));
1056
1057 var c = Crc32Bzip2.init();
1058 c.update("1234");
1059 c.update("56789");
1060 try testing.expectEqual(@as(u32, 0xfc891918), c.final());
1061}
1062
1063test "CRC-32/CD-ROM-EDC" {
1064 const Crc32CdRomEdc = catalog.Crc32CdRomEdc;
1065
1066 try testing.expectEqual(@as(u32, 0x6ec2edc4), Crc32CdRomEdc.hash("123456789"));
1067
1068 var c = Crc32CdRomEdc.init();
1069 c.update("1234");
1070 c.update("56789");
1071 try testing.expectEqual(@as(u32, 0x6ec2edc4), c.final());
1072}
1073
1074test "CRC-32/CKSUM" {
1075 const Crc32Cksum = catalog.Crc32Cksum;
1076
1077 try testing.expectEqual(@as(u32, 0x765e7680), Crc32Cksum.hash("123456789"));
1078
1079 var c = Crc32Cksum.init();
1080 c.update("1234");
1081 c.update("56789");
1082 try testing.expectEqual(@as(u32, 0x765e7680), c.final());
1083}
1084
1085test "CRC-32/ISCSI" {
1086 const Crc32Iscsi = catalog.Crc32Iscsi;
1087
1088 try testing.expectEqual(@as(u32, 0xe3069283), Crc32Iscsi.hash("123456789"));
1089
1090 var c = Crc32Iscsi.init();
1091 c.update("1234");
1092 c.update("56789");
1093 try testing.expectEqual(@as(u32, 0xe3069283), c.final());
1094}
1095
1096test "CRC-32/ISO-HDLC" {
1097 const Crc32IsoHdlc = catalog.Crc32IsoHdlc;
1098
1099 try testing.expectEqual(@as(u32, 0xcbf43926), Crc32IsoHdlc.hash("123456789"));
1100
1101 var c = Crc32IsoHdlc.init();
1102 c.update("1234");
1103 c.update("56789");
1104 try testing.expectEqual(@as(u32, 0xcbf43926), c.final());
1105}
1106
1107test "CRC-32/JAMCRC" {
1108 const Crc32Jamcrc = catalog.Crc32Jamcrc;
1109
1110 try testing.expectEqual(@as(u32, 0x340bc6d9), Crc32Jamcrc.hash("123456789"));
1111
1112 var c = Crc32Jamcrc.init();
1113 c.update("1234");
1114 c.update("56789");
1115 try testing.expectEqual(@as(u32, 0x340bc6d9), c.final());
1116}
1117
1118test "CRC-32/MEF" {
1119 const Crc32Mef = catalog.Crc32Mef;
1120
1121 try testing.expectEqual(@as(u32, 0xd2c22f51), Crc32Mef.hash("123456789"));
1122
1123 var c = Crc32Mef.init();
1124 c.update("1234");
1125 c.update("56789");
1126 try testing.expectEqual(@as(u32, 0xd2c22f51), c.final());
1127}
1128
1129test "CRC-32/MPEG-2" {
1130 const Crc32Mpeg2 = catalog.Crc32Mpeg2;
1131
1132 try testing.expectEqual(@as(u32, 0x0376e6e7), Crc32Mpeg2.hash("123456789"));
1133
1134 var c = Crc32Mpeg2.init();
1135 c.update("1234");
1136 c.update("56789");
1137 try testing.expectEqual(@as(u32, 0x0376e6e7), c.final());
1138}
1139
1140test "CRC-32/XFER" {
1141 const Crc32Xfer = catalog.Crc32Xfer;
1142
1143 try testing.expectEqual(@as(u32, 0xbd0be338), Crc32Xfer.hash("123456789"));
1144
1145 var c = Crc32Xfer.init();
1146 c.update("1234");
1147 c.update("56789");
1148 try testing.expectEqual(@as(u32, 0xbd0be338), c.final());
1149}
1150
1151test "CRC-40/GSM" {
1152 const Crc40Gsm = catalog.Crc40Gsm;
1153
1154 try testing.expectEqual(@as(u40, 0xd4164fc646), Crc40Gsm.hash("123456789"));
1155
1156 var c = Crc40Gsm.init();
1157 c.update("1234");
1158 c.update("56789");
1159 try testing.expectEqual(@as(u40, 0xd4164fc646), c.final());
1160}
1161
1162test "CRC-64/ECMA-182" {
1163 const Crc64Ecma182 = catalog.Crc64Ecma182;
1164
1165 try testing.expectEqual(@as(u64, 0x6c40df5f0b497347), Crc64Ecma182.hash("123456789"));
1166
1167 var c = Crc64Ecma182.init();
1168 c.update("1234");
1169 c.update("56789");
1170 try testing.expectEqual(@as(u64, 0x6c40df5f0b497347), c.final());
1171}
1172
1173test "CRC-64/GO-ISO" {
1174 const Crc64GoIso = catalog.Crc64GoIso;
1175
1176 try testing.expectEqual(@as(u64, 0xb90956c775a41001), Crc64GoIso.hash("123456789"));
1177
1178 var c = Crc64GoIso.init();
1179 c.update("1234");
1180 c.update("56789");
1181 try testing.expectEqual(@as(u64, 0xb90956c775a41001), c.final());
1182}
1183
1184test "CRC-64/MS" {
1185 const Crc64Ms = catalog.Crc64Ms;
1186
1187 try testing.expectEqual(@as(u64, 0x75d4b74f024eceea), Crc64Ms.hash("123456789"));
1188
1189 var c = Crc64Ms.init();
1190 c.update("1234");
1191 c.update("56789");
1192 try testing.expectEqual(@as(u64, 0x75d4b74f024eceea), c.final());
1193}
1194
1195test "CRC-64/REDIS" {
1196 const Crc64Redis = catalog.Crc64Redis;
1197
1198 try testing.expectEqual(@as(u64, 0xe9c6d914c4b8d9ca), Crc64Redis.hash("123456789"));
1199
1200 var c = Crc64Redis.init();
1201 c.update("1234");
1202 c.update("56789");
1203 try testing.expectEqual(@as(u64, 0xe9c6d914c4b8d9ca), c.final());
1204}
1205
1206test "CRC-64/WE" {
1207 const Crc64We = catalog.Crc64We;
1208
1209 try testing.expectEqual(@as(u64, 0x62ec59e3f1a4f00a), Crc64We.hash("123456789"));
1210
1211 var c = Crc64We.init();
1212 c.update("1234");
1213 c.update("56789");
1214 try testing.expectEqual(@as(u64, 0x62ec59e3f1a4f00a), c.final());
1215}
1216
1217test "CRC-64/XZ" {
1218 const Crc64Xz = catalog.Crc64Xz;
1219
1220 try testing.expectEqual(@as(u64, 0x995dc9bbdf1939fa), Crc64Xz.hash("123456789"));
1221
1222 var c = Crc64Xz.init();
1223 c.update("1234");
1224 c.update("56789");
1225 try testing.expectEqual(@as(u64, 0x995dc9bbdf1939fa), c.final());
1226}
1227
1228test "CRC-82/DARC" {
1229 const Crc82Darc = catalog.Crc82Darc;
1230
1231 try testing.expectEqual(@as(u82, 0x09ea83f625023801fd612), Crc82Darc.hash("123456789"));
1232
1233 var c = Crc82Darc.init();
1234 c.update("1234");
1235 c.update("56789");
1236 try testing.expectEqual(@as(u82, 0x09ea83f625023801fd612), c.final());
1237}
lib/std/hash/crc/impl.zig created+241
...@@ -0,0 +1,241 @@
1// There is a generic CRC implementation "Crc()" which can be paramterized via
2// the Algorithm struct for a plethora of uses, along with two implementations
3// of CRC32 implemented with the following key characteristics:
4//
5// - Crc32WithPoly uses 8Kb of tables but is ~10x faster than the small method.
6//
7// - Crc32SmallWithPoly uses only 64 bytes of memory but is slower. Be aware that this is
8// still moderately fast just slow relative to the slicing approach.
9//
10// The primary interface for all of the standard CRC algorithms is the
11// generated file "crc.zig", which uses the implementation code here to define
12// many standard CRCs.
13
14const std = @import("std");
15
16pub fn Algorithm(comptime W: type) type {
17 return struct {
18 polynomial: W,
19 initial: W,
20 reflect_input: bool,
21 reflect_output: bool,
22 xor_output: W,
23 };
24}
25
26pub fn Crc(comptime W: type, comptime algorithm: Algorithm(W)) type {
27 return struct {
28 const Self = @This();
29 const I = if (@bitSizeOf(W) < 8) u8 else W;
30 const lookup_table = blk: {
31 @setEvalBranchQuota(2500);
32
33 const poly = if (algorithm.reflect_input)
34 @bitReverse(@as(I, algorithm.polynomial)) >> (@bitSizeOf(I) - @bitSizeOf(W))
35 else
36 @as(I, algorithm.polynomial) << (@bitSizeOf(I) - @bitSizeOf(W));
37
38 var table: [256]I = undefined;
39 for (&table, 0..) |*e, i| {
40 var crc: I = i;
41 if (algorithm.reflect_input) {
42 var j: usize = 0;
43 while (j < 8) : (j += 1) {
44 crc = (crc >> 1) ^ ((crc & 1) * poly);
45 }
46 } else {
47 crc <<= @bitSizeOf(I) - 8;
48 var j: usize = 0;
49 while (j < 8) : (j += 1) {
50 crc = (crc << 1) ^ (((crc >> (@bitSizeOf(I) - 1)) & 1) * poly);
51 }
52 }
53 e.* = crc;
54 }
55 break :blk table;
56 };
57
58 crc: I,
59
60 pub fn init() Self {
61 const initial = if (algorithm.reflect_input)
62 @bitReverse(@as(I, algorithm.initial)) >> (@bitSizeOf(I) - @bitSizeOf(W))
63 else
64 @as(I, algorithm.initial) << (@bitSizeOf(I) - @bitSizeOf(W));
65 return Self{ .crc = initial };
66 }
67
68 inline fn tableEntry(index: I) I {
69 return lookup_table[@as(u8, @intCast(index & 0xFF))];
70 }
71
72 pub fn update(self: *Self, bytes: []const u8) void {
73 var i: usize = 0;
74 if (@bitSizeOf(I) <= 8) {
75 while (i < bytes.len) : (i += 1) {
76 self.crc = tableEntry(self.crc ^ bytes[i]);
77 }
78 } else if (algorithm.reflect_input) {
79 while (i < bytes.len) : (i += 1) {
80 const table_index = self.crc ^ bytes[i];
81 self.crc = tableEntry(table_index) ^ (self.crc >> 8);
82 }
83 } else {
84 while (i < bytes.len) : (i += 1) {
85 const table_index = (self.crc >> (@bitSizeOf(I) - 8)) ^ bytes[i];
86 self.crc = tableEntry(table_index) ^ (self.crc << 8);
87 }
88 }
89 }
90
91 pub fn final(self: Self) W {
92 var c = self.crc;
93 if (algorithm.reflect_input != algorithm.reflect_output) {
94 c = @bitReverse(c);
95 }
96 if (!algorithm.reflect_output) {
97 c >>= @bitSizeOf(I) - @bitSizeOf(W);
98 }
99 return @as(W, @intCast(c ^ algorithm.xor_output));
100 }
101
102 pub fn hash(bytes: []const u8) W {
103 var c = Self.init();
104 c.update(bytes);
105 return c.final();
106 }
107 };
108}
109
110pub const Polynomial = enum(u32) {
111 IEEE = 0xedb88320,
112 Castagnoli = 0x82f63b78,
113 Koopman = 0xeb31d82e,
114 _,
115};
116
117// slicing-by-8 crc32 implementation.
118pub fn Crc32WithPoly(comptime poly: Polynomial) type {
119 return struct {
120 const Self = @This();
121 const lookup_tables = block: {
122 @setEvalBranchQuota(20000);
123 var tables: [8][256]u32 = undefined;
124
125 for (&tables[0], 0..) |*e, i| {
126 var crc = @as(u32, @intCast(i));
127 var j: usize = 0;
128 while (j < 8) : (j += 1) {
129 if (crc & 1 == 1) {
130 crc = (crc >> 1) ^ @intFromEnum(poly);
131 } else {
132 crc = (crc >> 1);
133 }
134 }
135 e.* = crc;
136 }
137
138 var i: usize = 0;
139 while (i < 256) : (i += 1) {
140 var crc = tables[0][i];
141 var j: usize = 1;
142 while (j < 8) : (j += 1) {
143 const index: u8 = @truncate(crc);
144 crc = tables[0][index] ^ (crc >> 8);
145 tables[j][i] = crc;
146 }
147 }
148
149 break :block tables;
150 };
151
152 crc: u32,
153
154 pub fn init() Self {
155 return Self{ .crc = 0xffffffff };
156 }
157
158 pub fn update(self: *Self, input: []const u8) void {
159 var i: usize = 0;
160 while (i + 8 <= input.len) : (i += 8) {
161 const p = input[i..][0..8];
162
163 // Unrolling this way gives ~50Mb/s increase
164 self.crc ^= std.mem.readInt(u32, p[0..4], .little);
165
166 self.crc =
167 lookup_tables[0][p[7]] ^
168 lookup_tables[1][p[6]] ^
169 lookup_tables[2][p[5]] ^
170 lookup_tables[3][p[4]] ^
171 lookup_tables[4][@as(u8, @truncate(self.crc >> 24))] ^
172 lookup_tables[5][@as(u8, @truncate(self.crc >> 16))] ^
173 lookup_tables[6][@as(u8, @truncate(self.crc >> 8))] ^
174 lookup_tables[7][@as(u8, @truncate(self.crc >> 0))];
175 }
176
177 while (i < input.len) : (i += 1) {
178 const index = @as(u8, @truncate(self.crc)) ^ input[i];
179 self.crc = (self.crc >> 8) ^ lookup_tables[0][index];
180 }
181 }
182
183 pub fn final(self: *Self) u32 {
184 return ~self.crc;
185 }
186
187 pub fn hash(input: []const u8) u32 {
188 var c = Self.init();
189 c.update(input);
190 return c.final();
191 }
192 };
193}
194
195// half-byte lookup table implementation.
196pub fn Crc32SmallWithPoly(comptime poly: Polynomial) type {
197 return struct {
198 const Self = @This();
199 const lookup_table = block: {
200 var table: [16]u32 = undefined;
201
202 for (&table, 0..) |*e, i| {
203 var crc = @as(u32, @intCast(i * 16));
204 var j: usize = 0;
205 while (j < 8) : (j += 1) {
206 if (crc & 1 == 1) {
207 crc = (crc >> 1) ^ @intFromEnum(poly);
208 } else {
209 crc = (crc >> 1);
210 }
211 }
212 e.* = crc;
213 }
214
215 break :block table;
216 };
217
218 crc: u32,
219
220 pub fn init() Self {
221 return Self{ .crc = 0xffffffff };
222 }
223
224 pub fn update(self: *Self, input: []const u8) void {
225 for (input) |b| {
226 self.crc = lookup_table[@as(u4, @truncate(self.crc ^ (b >> 0)))] ^ (self.crc >> 4);
227 self.crc = lookup_table[@as(u4, @truncate(self.crc ^ (b >> 4)))] ^ (self.crc >> 4);
228 }
229 }
230
231 pub fn final(self: *Self) u32 {
232 return ~self.crc;
233 }
234
235 pub fn hash(input: []const u8) u32 {
236 var c = Self.init();
237 c.update(input);
238 return c.final();
239 }
240 };
241}
lib/std/hash/crc/test.zig created+1256
...@@ -0,0 +1,1256 @@
1//! This file is auto-generated by tools/update_crc_catalog.zig.
2
3const std = @import("std");
4const testing = std.testing;
5const verify = @import("../verify.zig");
6const crc = @import("../crc.zig");
7
8test "crc32 ieee" {
9 inline for ([2]type{ crc.Crc32WithPoly(.IEEE), crc.Crc32SmallWithPoly(.IEEE) }) |ieee| {
10 try testing.expect(ieee.hash("") == 0x00000000);
11 try testing.expect(ieee.hash("a") == 0xe8b7be43);
12 try testing.expect(ieee.hash("abc") == 0x352441c2);
13 try verify.iterativeApi(ieee);
14 }
15}
16
17test "crc32 castagnoli" {
18 inline for ([2]type{ crc.Crc32WithPoly(.Castagnoli), crc.Crc32SmallWithPoly(.Castagnoli) }) |casta| {
19 try testing.expect(casta.hash("") == 0x00000000);
20 try testing.expect(casta.hash("a") == 0xc1d04330);
21 try testing.expect(casta.hash("abc") == 0x364b3fb7);
22 try verify.iterativeApi(casta);
23 }
24}
25
26test "CRC-3/GSM" {
27 const Crc3Gsm = crc.Crc3Gsm;
28
29 try testing.expectEqual(@as(u3, 0x4), Crc3Gsm.hash("123456789"));
30
31 var c = Crc3Gsm.init();
32 c.update("1234");
33 c.update("56789");
34 try testing.expectEqual(@as(u3, 0x4), c.final());
35}
36
37test "CRC-3/ROHC" {
38 const Crc3Rohc = crc.Crc3Rohc;
39
40 try testing.expectEqual(@as(u3, 0x6), Crc3Rohc.hash("123456789"));
41
42 var c = Crc3Rohc.init();
43 c.update("1234");
44 c.update("56789");
45 try testing.expectEqual(@as(u3, 0x6), c.final());
46}
47
48test "CRC-4/G-704" {
49 const Crc4G704 = crc.Crc4G704;
50
51 try testing.expectEqual(@as(u4, 0x7), Crc4G704.hash("123456789"));
52
53 var c = Crc4G704.init();
54 c.update("1234");
55 c.update("56789");
56 try testing.expectEqual(@as(u4, 0x7), c.final());
57}
58
59test "CRC-4/INTERLAKEN" {
60 const Crc4Interlaken = crc.Crc4Interlaken;
61
62 try testing.expectEqual(@as(u4, 0xb), Crc4Interlaken.hash("123456789"));
63
64 var c = Crc4Interlaken.init();
65 c.update("1234");
66 c.update("56789");
67 try testing.expectEqual(@as(u4, 0xb), c.final());
68}
69
70test "CRC-5/EPC-C1G2" {
71 const Crc5EpcC1g2 = crc.Crc5EpcC1g2;
72
73 try testing.expectEqual(@as(u5, 0x00), Crc5EpcC1g2.hash("123456789"));
74
75 var c = Crc5EpcC1g2.init();
76 c.update("1234");
77 c.update("56789");
78 try testing.expectEqual(@as(u5, 0x00), c.final());
79}
80
81test "CRC-5/G-704" {
82 const Crc5G704 = crc.Crc5G704;
83
84 try testing.expectEqual(@as(u5, 0x07), Crc5G704.hash("123456789"));
85
86 var c = Crc5G704.init();
87 c.update("1234");
88 c.update("56789");
89 try testing.expectEqual(@as(u5, 0x07), c.final());
90}
91
92test "CRC-5/USB" {
93 const Crc5Usb = crc.Crc5Usb;
94
95 try testing.expectEqual(@as(u5, 0x19), Crc5Usb.hash("123456789"));
96
97 var c = Crc5Usb.init();
98 c.update("1234");
99 c.update("56789");
100 try testing.expectEqual(@as(u5, 0x19), c.final());
101}
102
103test "CRC-6/CDMA2000-A" {
104 const Crc6Cdma2000A = crc.Crc6Cdma2000A;
105
106 try testing.expectEqual(@as(u6, 0x0d), Crc6Cdma2000A.hash("123456789"));
107
108 var c = Crc6Cdma2000A.init();
109 c.update("1234");
110 c.update("56789");
111 try testing.expectEqual(@as(u6, 0x0d), c.final());
112}
113
114test "CRC-6/CDMA2000-B" {
115 const Crc6Cdma2000B = crc.Crc6Cdma2000B;
116
117 try testing.expectEqual(@as(u6, 0x3b), Crc6Cdma2000B.hash("123456789"));
118
119 var c = Crc6Cdma2000B.init();
120 c.update("1234");
121 c.update("56789");
122 try testing.expectEqual(@as(u6, 0x3b), c.final());
123}
124
125test "CRC-6/DARC" {
126 const Crc6Darc = crc.Crc6Darc;
127
128 try testing.expectEqual(@as(u6, 0x26), Crc6Darc.hash("123456789"));
129
130 var c = Crc6Darc.init();
131 c.update("1234");
132 c.update("56789");
133 try testing.expectEqual(@as(u6, 0x26), c.final());
134}
135
136test "CRC-6/G-704" {
137 const Crc6G704 = crc.Crc6G704;
138
139 try testing.expectEqual(@as(u6, 0x06), Crc6G704.hash("123456789"));
140
141 var c = Crc6G704.init();
142 c.update("1234");
143 c.update("56789");
144 try testing.expectEqual(@as(u6, 0x06), c.final());
145}
146
147test "CRC-6/GSM" {
148 const Crc6Gsm = crc.Crc6Gsm;
149
150 try testing.expectEqual(@as(u6, 0x13), Crc6Gsm.hash("123456789"));
151
152 var c = Crc6Gsm.init();
153 c.update("1234");
154 c.update("56789");
155 try testing.expectEqual(@as(u6, 0x13), c.final());
156}
157
158test "CRC-7/MMC" {
159 const Crc7Mmc = crc.Crc7Mmc;
160
161 try testing.expectEqual(@as(u7, 0x75), Crc7Mmc.hash("123456789"));
162
163 var c = Crc7Mmc.init();
164 c.update("1234");
165 c.update("56789");
166 try testing.expectEqual(@as(u7, 0x75), c.final());
167}
168
169test "CRC-7/ROHC" {
170 const Crc7Rohc = crc.Crc7Rohc;
171
172 try testing.expectEqual(@as(u7, 0x53), Crc7Rohc.hash("123456789"));
173
174 var c = Crc7Rohc.init();
175 c.update("1234");
176 c.update("56789");
177 try testing.expectEqual(@as(u7, 0x53), c.final());
178}
179
180test "CRC-7/UMTS" {
181 const Crc7Umts = crc.Crc7Umts;
182
183 try testing.expectEqual(@as(u7, 0x61), Crc7Umts.hash("123456789"));
184
185 var c = Crc7Umts.init();
186 c.update("1234");
187 c.update("56789");
188 try testing.expectEqual(@as(u7, 0x61), c.final());
189}
190
191test "CRC-8/AUTOSAR" {
192 const Crc8Autosar = crc.Crc8Autosar;
193
194 try testing.expectEqual(@as(u8, 0xdf), Crc8Autosar.hash("123456789"));
195
196 var c = Crc8Autosar.init();
197 c.update("1234");
198 c.update("56789");
199 try testing.expectEqual(@as(u8, 0xdf), c.final());
200}
201
202test "CRC-8/BLUETOOTH" {
203 const Crc8Bluetooth = crc.Crc8Bluetooth;
204
205 try testing.expectEqual(@as(u8, 0x26), Crc8Bluetooth.hash("123456789"));
206
207 var c = Crc8Bluetooth.init();
208 c.update("1234");
209 c.update("56789");
210 try testing.expectEqual(@as(u8, 0x26), c.final());
211}
212
213test "CRC-8/CDMA2000" {
214 const Crc8Cdma2000 = crc.Crc8Cdma2000;
215
216 try testing.expectEqual(@as(u8, 0xda), Crc8Cdma2000.hash("123456789"));
217
218 var c = Crc8Cdma2000.init();
219 c.update("1234");
220 c.update("56789");
221 try testing.expectEqual(@as(u8, 0xda), c.final());
222}
223
224test "CRC-8/DARC" {
225 const Crc8Darc = crc.Crc8Darc;
226
227 try testing.expectEqual(@as(u8, 0x15), Crc8Darc.hash("123456789"));
228
229 var c = Crc8Darc.init();
230 c.update("1234");
231 c.update("56789");
232 try testing.expectEqual(@as(u8, 0x15), c.final());
233}
234
235test "CRC-8/DVB-S2" {
236 const Crc8DvbS2 = crc.Crc8DvbS2;
237
238 try testing.expectEqual(@as(u8, 0xbc), Crc8DvbS2.hash("123456789"));
239
240 var c = Crc8DvbS2.init();
241 c.update("1234");
242 c.update("56789");
243 try testing.expectEqual(@as(u8, 0xbc), c.final());
244}
245
246test "CRC-8/GSM-A" {
247 const Crc8GsmA = crc.Crc8GsmA;
248
249 try testing.expectEqual(@as(u8, 0x37), Crc8GsmA.hash("123456789"));
250
251 var c = Crc8GsmA.init();
252 c.update("1234");
253 c.update("56789");
254 try testing.expectEqual(@as(u8, 0x37), c.final());
255}
256
257test "CRC-8/GSM-B" {
258 const Crc8GsmB = crc.Crc8GsmB;
259
260 try testing.expectEqual(@as(u8, 0x94), Crc8GsmB.hash("123456789"));
261
262 var c = Crc8GsmB.init();
263 c.update("1234");
264 c.update("56789");
265 try testing.expectEqual(@as(u8, 0x94), c.final());
266}
267
268test "CRC-8/HITAG" {
269 const Crc8Hitag = crc.Crc8Hitag;
270
271 try testing.expectEqual(@as(u8, 0xb4), Crc8Hitag.hash("123456789"));
272
273 var c = Crc8Hitag.init();
274 c.update("1234");
275 c.update("56789");
276 try testing.expectEqual(@as(u8, 0xb4), c.final());
277}
278
279test "CRC-8/I-432-1" {
280 const Crc8I4321 = crc.Crc8I4321;
281
282 try testing.expectEqual(@as(u8, 0xa1), Crc8I4321.hash("123456789"));
283
284 var c = Crc8I4321.init();
285 c.update("1234");
286 c.update("56789");
287 try testing.expectEqual(@as(u8, 0xa1), c.final());
288}
289
290test "CRC-8/I-CODE" {
291 const Crc8ICode = crc.Crc8ICode;
292
293 try testing.expectEqual(@as(u8, 0x7e), Crc8ICode.hash("123456789"));
294
295 var c = Crc8ICode.init();
296 c.update("1234");
297 c.update("56789");
298 try testing.expectEqual(@as(u8, 0x7e), c.final());
299}
300
301test "CRC-8/LTE" {
302 const Crc8Lte = crc.Crc8Lte;
303
304 try testing.expectEqual(@as(u8, 0xea), Crc8Lte.hash("123456789"));
305
306 var c = Crc8Lte.init();
307 c.update("1234");
308 c.update("56789");
309 try testing.expectEqual(@as(u8, 0xea), c.final());
310}
311
312test "CRC-8/MAXIM-DOW" {
313 const Crc8MaximDow = crc.Crc8MaximDow;
314
315 try testing.expectEqual(@as(u8, 0xa1), Crc8MaximDow.hash("123456789"));
316
317 var c = Crc8MaximDow.init();
318 c.update("1234");
319 c.update("56789");
320 try testing.expectEqual(@as(u8, 0xa1), c.final());
321}
322
323test "CRC-8/MIFARE-MAD" {
324 const Crc8MifareMad = crc.Crc8MifareMad;
325
326 try testing.expectEqual(@as(u8, 0x99), Crc8MifareMad.hash("123456789"));
327
328 var c = Crc8MifareMad.init();
329 c.update("1234");
330 c.update("56789");
331 try testing.expectEqual(@as(u8, 0x99), c.final());
332}
333
334test "CRC-8/NRSC-5" {
335 const Crc8Nrsc5 = crc.Crc8Nrsc5;
336
337 try testing.expectEqual(@as(u8, 0xf7), Crc8Nrsc5.hash("123456789"));
338
339 var c = Crc8Nrsc5.init();
340 c.update("1234");
341 c.update("56789");
342 try testing.expectEqual(@as(u8, 0xf7), c.final());
343}
344
345test "CRC-8/OPENSAFETY" {
346 const Crc8Opensafety = crc.Crc8Opensafety;
347
348 try testing.expectEqual(@as(u8, 0x3e), Crc8Opensafety.hash("123456789"));
349
350 var c = Crc8Opensafety.init();
351 c.update("1234");
352 c.update("56789");
353 try testing.expectEqual(@as(u8, 0x3e), c.final());
354}
355
356test "CRC-8/ROHC" {
357 const Crc8Rohc = crc.Crc8Rohc;
358
359 try testing.expectEqual(@as(u8, 0xd0), Crc8Rohc.hash("123456789"));
360
361 var c = Crc8Rohc.init();
362 c.update("1234");
363 c.update("56789");
364 try testing.expectEqual(@as(u8, 0xd0), c.final());
365}
366
367test "CRC-8/SAE-J1850" {
368 const Crc8SaeJ1850 = crc.Crc8SaeJ1850;
369
370 try testing.expectEqual(@as(u8, 0x4b), Crc8SaeJ1850.hash("123456789"));
371
372 var c = Crc8SaeJ1850.init();
373 c.update("1234");
374 c.update("56789");
375 try testing.expectEqual(@as(u8, 0x4b), c.final());
376}
377
378test "CRC-8/SMBUS" {
379 const Crc8Smbus = crc.Crc8Smbus;
380
381 try testing.expectEqual(@as(u8, 0xf4), Crc8Smbus.hash("123456789"));
382
383 var c = Crc8Smbus.init();
384 c.update("1234");
385 c.update("56789");
386 try testing.expectEqual(@as(u8, 0xf4), c.final());
387}
388
389test "CRC-8/TECH-3250" {
390 const Crc8Tech3250 = crc.Crc8Tech3250;
391
392 try testing.expectEqual(@as(u8, 0x97), Crc8Tech3250.hash("123456789"));
393
394 var c = Crc8Tech3250.init();
395 c.update("1234");
396 c.update("56789");
397 try testing.expectEqual(@as(u8, 0x97), c.final());
398}
399
400test "CRC-8/WCDMA" {
401 const Crc8Wcdma = crc.Crc8Wcdma;
402
403 try testing.expectEqual(@as(u8, 0x25), Crc8Wcdma.hash("123456789"));
404
405 var c = Crc8Wcdma.init();
406 c.update("1234");
407 c.update("56789");
408 try testing.expectEqual(@as(u8, 0x25), c.final());
409}
410
411test "CRC-10/ATM" {
412 const Crc10Atm = crc.Crc10Atm;
413
414 try testing.expectEqual(@as(u10, 0x199), Crc10Atm.hash("123456789"));
415
416 var c = Crc10Atm.init();
417 c.update("1234");
418 c.update("56789");
419 try testing.expectEqual(@as(u10, 0x199), c.final());
420}
421
422test "CRC-10/CDMA2000" {
423 const Crc10Cdma2000 = crc.Crc10Cdma2000;
424
425 try testing.expectEqual(@as(u10, 0x233), Crc10Cdma2000.hash("123456789"));
426
427 var c = Crc10Cdma2000.init();
428 c.update("1234");
429 c.update("56789");
430 try testing.expectEqual(@as(u10, 0x233), c.final());
431}
432
433test "CRC-10/GSM" {
434 const Crc10Gsm = crc.Crc10Gsm;
435
436 try testing.expectEqual(@as(u10, 0x12a), Crc10Gsm.hash("123456789"));
437
438 var c = Crc10Gsm.init();
439 c.update("1234");
440 c.update("56789");
441 try testing.expectEqual(@as(u10, 0x12a), c.final());
442}
443
444test "CRC-11/FLEXRAY" {
445 const Crc11Flexray = crc.Crc11Flexray;
446
447 try testing.expectEqual(@as(u11, 0x5a3), Crc11Flexray.hash("123456789"));
448
449 var c = Crc11Flexray.init();
450 c.update("1234");
451 c.update("56789");
452 try testing.expectEqual(@as(u11, 0x5a3), c.final());
453}
454
455test "CRC-11/UMTS" {
456 const Crc11Umts = crc.Crc11Umts;
457
458 try testing.expectEqual(@as(u11, 0x061), Crc11Umts.hash("123456789"));
459
460 var c = Crc11Umts.init();
461 c.update("1234");
462 c.update("56789");
463 try testing.expectEqual(@as(u11, 0x061), c.final());
464}
465
466test "CRC-12/CDMA2000" {
467 const Crc12Cdma2000 = crc.Crc12Cdma2000;
468
469 try testing.expectEqual(@as(u12, 0xd4d), Crc12Cdma2000.hash("123456789"));
470
471 var c = Crc12Cdma2000.init();
472 c.update("1234");
473 c.update("56789");
474 try testing.expectEqual(@as(u12, 0xd4d), c.final());
475}
476
477test "CRC-12/DECT" {
478 const Crc12Dect = crc.Crc12Dect;
479
480 try testing.expectEqual(@as(u12, 0xf5b), Crc12Dect.hash("123456789"));
481
482 var c = Crc12Dect.init();
483 c.update("1234");
484 c.update("56789");
485 try testing.expectEqual(@as(u12, 0xf5b), c.final());
486}
487
488test "CRC-12/GSM" {
489 const Crc12Gsm = crc.Crc12Gsm;
490
491 try testing.expectEqual(@as(u12, 0xb34), Crc12Gsm.hash("123456789"));
492
493 var c = Crc12Gsm.init();
494 c.update("1234");
495 c.update("56789");
496 try testing.expectEqual(@as(u12, 0xb34), c.final());
497}
498
499test "CRC-12/UMTS" {
500 const Crc12Umts = crc.Crc12Umts;
501
502 try testing.expectEqual(@as(u12, 0xdaf), Crc12Umts.hash("123456789"));
503
504 var c = Crc12Umts.init();
505 c.update("1234");
506 c.update("56789");
507 try testing.expectEqual(@as(u12, 0xdaf), c.final());
508}
509
510test "CRC-13/BBC" {
511 const Crc13Bbc = crc.Crc13Bbc;
512
513 try testing.expectEqual(@as(u13, 0x04fa), Crc13Bbc.hash("123456789"));
514
515 var c = Crc13Bbc.init();
516 c.update("1234");
517 c.update("56789");
518 try testing.expectEqual(@as(u13, 0x04fa), c.final());
519}
520
521test "CRC-14/DARC" {
522 const Crc14Darc = crc.Crc14Darc;
523
524 try testing.expectEqual(@as(u14, 0x082d), Crc14Darc.hash("123456789"));
525
526 var c = Crc14Darc.init();
527 c.update("1234");
528 c.update("56789");
529 try testing.expectEqual(@as(u14, 0x082d), c.final());
530}
531
532test "CRC-14/GSM" {
533 const Crc14Gsm = crc.Crc14Gsm;
534
535 try testing.expectEqual(@as(u14, 0x30ae), Crc14Gsm.hash("123456789"));
536
537 var c = Crc14Gsm.init();
538 c.update("1234");
539 c.update("56789");
540 try testing.expectEqual(@as(u14, 0x30ae), c.final());
541}
542
543test "CRC-15/CAN" {
544 const Crc15Can = crc.Crc15Can;
545
546 try testing.expectEqual(@as(u15, 0x059e), Crc15Can.hash("123456789"));
547
548 var c = Crc15Can.init();
549 c.update("1234");
550 c.update("56789");
551 try testing.expectEqual(@as(u15, 0x059e), c.final());
552}
553
554test "CRC-15/MPT1327" {
555 const Crc15Mpt1327 = crc.Crc15Mpt1327;
556
557 try testing.expectEqual(@as(u15, 0x2566), Crc15Mpt1327.hash("123456789"));
558
559 var c = Crc15Mpt1327.init();
560 c.update("1234");
561 c.update("56789");
562 try testing.expectEqual(@as(u15, 0x2566), c.final());
563}
564
565test "CRC-16/ARC" {
566 const Crc16Arc = crc.Crc16Arc;
567
568 try testing.expectEqual(@as(u16, 0xbb3d), Crc16Arc.hash("123456789"));
569
570 var c = Crc16Arc.init();
571 c.update("1234");
572 c.update("56789");
573 try testing.expectEqual(@as(u16, 0xbb3d), c.final());
574}
575
576test "CRC-16/CDMA2000" {
577 const Crc16Cdma2000 = crc.Crc16Cdma2000;
578
579 try testing.expectEqual(@as(u16, 0x4c06), Crc16Cdma2000.hash("123456789"));
580
581 var c = Crc16Cdma2000.init();
582 c.update("1234");
583 c.update("56789");
584 try testing.expectEqual(@as(u16, 0x4c06), c.final());
585}
586
587test "CRC-16/CMS" {
588 const Crc16Cms = crc.Crc16Cms;
589
590 try testing.expectEqual(@as(u16, 0xaee7), Crc16Cms.hash("123456789"));
591
592 var c = Crc16Cms.init();
593 c.update("1234");
594 c.update("56789");
595 try testing.expectEqual(@as(u16, 0xaee7), c.final());
596}
597
598test "CRC-16/DDS-110" {
599 const Crc16Dds110 = crc.Crc16Dds110;
600
601 try testing.expectEqual(@as(u16, 0x9ecf), Crc16Dds110.hash("123456789"));
602
603 var c = Crc16Dds110.init();
604 c.update("1234");
605 c.update("56789");
606 try testing.expectEqual(@as(u16, 0x9ecf), c.final());
607}
608
609test "CRC-16/DECT-R" {
610 const Crc16DectR = crc.Crc16DectR;
611
612 try testing.expectEqual(@as(u16, 0x007e), Crc16DectR.hash("123456789"));
613
614 var c = Crc16DectR.init();
615 c.update("1234");
616 c.update("56789");
617 try testing.expectEqual(@as(u16, 0x007e), c.final());
618}
619
620test "CRC-16/DECT-X" {
621 const Crc16DectX = crc.Crc16DectX;
622
623 try testing.expectEqual(@as(u16, 0x007f), Crc16DectX.hash("123456789"));
624
625 var c = Crc16DectX.init();
626 c.update("1234");
627 c.update("56789");
628 try testing.expectEqual(@as(u16, 0x007f), c.final());
629}
630
631test "CRC-16/DNP" {
632 const Crc16Dnp = crc.Crc16Dnp;
633
634 try testing.expectEqual(@as(u16, 0xea82), Crc16Dnp.hash("123456789"));
635
636 var c = Crc16Dnp.init();
637 c.update("1234");
638 c.update("56789");
639 try testing.expectEqual(@as(u16, 0xea82), c.final());
640}
641
642test "CRC-16/EN-13757" {
643 const Crc16En13757 = crc.Crc16En13757;
644
645 try testing.expectEqual(@as(u16, 0xc2b7), Crc16En13757.hash("123456789"));
646
647 var c = Crc16En13757.init();
648 c.update("1234");
649 c.update("56789");
650 try testing.expectEqual(@as(u16, 0xc2b7), c.final());
651}
652
653test "CRC-16/GENIBUS" {
654 const Crc16Genibus = crc.Crc16Genibus;
655
656 try testing.expectEqual(@as(u16, 0xd64e), Crc16Genibus.hash("123456789"));
657
658 var c = Crc16Genibus.init();
659 c.update("1234");
660 c.update("56789");
661 try testing.expectEqual(@as(u16, 0xd64e), c.final());
662}
663
664test "CRC-16/GSM" {
665 const Crc16Gsm = crc.Crc16Gsm;
666
667 try testing.expectEqual(@as(u16, 0xce3c), Crc16Gsm.hash("123456789"));
668
669 var c = Crc16Gsm.init();
670 c.update("1234");
671 c.update("56789");
672 try testing.expectEqual(@as(u16, 0xce3c), c.final());
673}
674
675test "CRC-16/IBM-3740" {
676 const Crc16Ibm3740 = crc.Crc16Ibm3740;
677
678 try testing.expectEqual(@as(u16, 0x29b1), Crc16Ibm3740.hash("123456789"));
679
680 var c = Crc16Ibm3740.init();
681 c.update("1234");
682 c.update("56789");
683 try testing.expectEqual(@as(u16, 0x29b1), c.final());
684}
685
686test "CRC-16/IBM-SDLC" {
687 const Crc16IbmSdlc = crc.Crc16IbmSdlc;
688
689 try testing.expectEqual(@as(u16, 0x906e), Crc16IbmSdlc.hash("123456789"));
690
691 var c = Crc16IbmSdlc.init();
692 c.update("1234");
693 c.update("56789");
694 try testing.expectEqual(@as(u16, 0x906e), c.final());
695}
696
697test "CRC-16/ISO-IEC-14443-3-A" {
698 const Crc16IsoIec144433A = crc.Crc16IsoIec144433A;
699
700 try testing.expectEqual(@as(u16, 0xbf05), Crc16IsoIec144433A.hash("123456789"));
701
702 var c = Crc16IsoIec144433A.init();
703 c.update("1234");
704 c.update("56789");
705 try testing.expectEqual(@as(u16, 0xbf05), c.final());
706}
707
708test "CRC-16/KERMIT" {
709 const Crc16Kermit = crc.Crc16Kermit;
710
711 try testing.expectEqual(@as(u16, 0x2189), Crc16Kermit.hash("123456789"));
712
713 var c = Crc16Kermit.init();
714 c.update("1234");
715 c.update("56789");
716 try testing.expectEqual(@as(u16, 0x2189), c.final());
717}
718
719test "CRC-16/LJ1200" {
720 const Crc16Lj1200 = crc.Crc16Lj1200;
721
722 try testing.expectEqual(@as(u16, 0xbdf4), Crc16Lj1200.hash("123456789"));
723
724 var c = Crc16Lj1200.init();
725 c.update("1234");
726 c.update("56789");
727 try testing.expectEqual(@as(u16, 0xbdf4), c.final());
728}
729
730test "CRC-16/M17" {
731 const Crc16M17 = crc.Crc16M17;
732
733 try testing.expectEqual(@as(u16, 0x772b), Crc16M17.hash("123456789"));
734
735 var c = Crc16M17.init();
736 c.update("1234");
737 c.update("56789");
738 try testing.expectEqual(@as(u16, 0x772b), c.final());
739}
740
741test "CRC-16/MAXIM-DOW" {
742 const Crc16MaximDow = crc.Crc16MaximDow;
743
744 try testing.expectEqual(@as(u16, 0x44c2), Crc16MaximDow.hash("123456789"));
745
746 var c = Crc16MaximDow.init();
747 c.update("1234");
748 c.update("56789");
749 try testing.expectEqual(@as(u16, 0x44c2), c.final());
750}
751
752test "CRC-16/MCRF4XX" {
753 const Crc16Mcrf4xx = crc.Crc16Mcrf4xx;
754
755 try testing.expectEqual(@as(u16, 0x6f91), Crc16Mcrf4xx.hash("123456789"));
756
757 var c = Crc16Mcrf4xx.init();
758 c.update("1234");
759 c.update("56789");
760 try testing.expectEqual(@as(u16, 0x6f91), c.final());
761}
762
763test "CRC-16/MODBUS" {
764 const Crc16Modbus = crc.Crc16Modbus;
765
766 try testing.expectEqual(@as(u16, 0x4b37), Crc16Modbus.hash("123456789"));
767
768 var c = Crc16Modbus.init();
769 c.update("1234");
770 c.update("56789");
771 try testing.expectEqual(@as(u16, 0x4b37), c.final());
772}
773
774test "CRC-16/NRSC-5" {
775 const Crc16Nrsc5 = crc.Crc16Nrsc5;
776
777 try testing.expectEqual(@as(u16, 0xa066), Crc16Nrsc5.hash("123456789"));
778
779 var c = Crc16Nrsc5.init();
780 c.update("1234");
781 c.update("56789");
782 try testing.expectEqual(@as(u16, 0xa066), c.final());
783}
784
785test "CRC-16/OPENSAFETY-A" {
786 const Crc16OpensafetyA = crc.Crc16OpensafetyA;
787
788 try testing.expectEqual(@as(u16, 0x5d38), Crc16OpensafetyA.hash("123456789"));
789
790 var c = Crc16OpensafetyA.init();
791 c.update("1234");
792 c.update("56789");
793 try testing.expectEqual(@as(u16, 0x5d38), c.final());
794}
795
796test "CRC-16/OPENSAFETY-B" {
797 const Crc16OpensafetyB = crc.Crc16OpensafetyB;
798
799 try testing.expectEqual(@as(u16, 0x20fe), Crc16OpensafetyB.hash("123456789"));
800
801 var c = Crc16OpensafetyB.init();
802 c.update("1234");
803 c.update("56789");
804 try testing.expectEqual(@as(u16, 0x20fe), c.final());
805}
806
807test "CRC-16/PROFIBUS" {
808 const Crc16Profibus = crc.Crc16Profibus;
809
810 try testing.expectEqual(@as(u16, 0xa819), Crc16Profibus.hash("123456789"));
811
812 var c = Crc16Profibus.init();
813 c.update("1234");
814 c.update("56789");
815 try testing.expectEqual(@as(u16, 0xa819), c.final());
816}
817
818test "CRC-16/RIELLO" {
819 const Crc16Riello = crc.Crc16Riello;
820
821 try testing.expectEqual(@as(u16, 0x63d0), Crc16Riello.hash("123456789"));
822
823 var c = Crc16Riello.init();
824 c.update("1234");
825 c.update("56789");
826 try testing.expectEqual(@as(u16, 0x63d0), c.final());
827}
828
829test "CRC-16/SPI-FUJITSU" {
830 const Crc16SpiFujitsu = crc.Crc16SpiFujitsu;
831
832 try testing.expectEqual(@as(u16, 0xe5cc), Crc16SpiFujitsu.hash("123456789"));
833
834 var c = Crc16SpiFujitsu.init();
835 c.update("1234");
836 c.update("56789");
837 try testing.expectEqual(@as(u16, 0xe5cc), c.final());
838}
839
840test "CRC-16/T10-DIF" {
841 const Crc16T10Dif = crc.Crc16T10Dif;
842
843 try testing.expectEqual(@as(u16, 0xd0db), Crc16T10Dif.hash("123456789"));
844
845 var c = Crc16T10Dif.init();
846 c.update("1234");
847 c.update("56789");
848 try testing.expectEqual(@as(u16, 0xd0db), c.final());
849}
850
851test "CRC-16/TELEDISK" {
852 const Crc16Teledisk = crc.Crc16Teledisk;
853
854 try testing.expectEqual(@as(u16, 0x0fb3), Crc16Teledisk.hash("123456789"));
855
856 var c = Crc16Teledisk.init();
857 c.update("1234");
858 c.update("56789");
859 try testing.expectEqual(@as(u16, 0x0fb3), c.final());
860}
861
862test "CRC-16/TMS37157" {
863 const Crc16Tms37157 = crc.Crc16Tms37157;
864
865 try testing.expectEqual(@as(u16, 0x26b1), Crc16Tms37157.hash("123456789"));
866
867 var c = Crc16Tms37157.init();
868 c.update("1234");
869 c.update("56789");
870 try testing.expectEqual(@as(u16, 0x26b1), c.final());
871}
872
873test "CRC-16/UMTS" {
874 const Crc16Umts = crc.Crc16Umts;
875
876 try testing.expectEqual(@as(u16, 0xfee8), Crc16Umts.hash("123456789"));
877
878 var c = Crc16Umts.init();
879 c.update("1234");
880 c.update("56789");
881 try testing.expectEqual(@as(u16, 0xfee8), c.final());
882}
883
884test "CRC-16/USB" {
885 const Crc16Usb = crc.Crc16Usb;
886
887 try testing.expectEqual(@as(u16, 0xb4c8), Crc16Usb.hash("123456789"));
888
889 var c = Crc16Usb.init();
890 c.update("1234");
891 c.update("56789");
892 try testing.expectEqual(@as(u16, 0xb4c8), c.final());
893}
894
895test "CRC-16/XMODEM" {
896 const Crc16Xmodem = crc.Crc16Xmodem;
897
898 try testing.expectEqual(@as(u16, 0x31c3), Crc16Xmodem.hash("123456789"));
899
900 var c = Crc16Xmodem.init();
901 c.update("1234");
902 c.update("56789");
903 try testing.expectEqual(@as(u16, 0x31c3), c.final());
904}
905
906test "CRC-17/CAN-FD" {
907 const Crc17CanFd = crc.Crc17CanFd;
908
909 try testing.expectEqual(@as(u17, 0x04f03), Crc17CanFd.hash("123456789"));
910
911 var c = Crc17CanFd.init();
912 c.update("1234");
913 c.update("56789");
914 try testing.expectEqual(@as(u17, 0x04f03), c.final());
915}
916
917test "CRC-21/CAN-FD" {
918 const Crc21CanFd = crc.Crc21CanFd;
919
920 try testing.expectEqual(@as(u21, 0x0ed841), Crc21CanFd.hash("123456789"));
921
922 var c = Crc21CanFd.init();
923 c.update("1234");
924 c.update("56789");
925 try testing.expectEqual(@as(u21, 0x0ed841), c.final());
926}
927
928test "CRC-24/BLE" {
929 const Crc24Ble = crc.Crc24Ble;
930
931 try testing.expectEqual(@as(u24, 0xc25a56), Crc24Ble.hash("123456789"));
932
933 var c = Crc24Ble.init();
934 c.update("1234");
935 c.update("56789");
936 try testing.expectEqual(@as(u24, 0xc25a56), c.final());
937}
938
939test "CRC-24/FLEXRAY-A" {
940 const Crc24FlexrayA = crc.Crc24FlexrayA;
941
942 try testing.expectEqual(@as(u24, 0x7979bd), Crc24FlexrayA.hash("123456789"));
943
944 var c = Crc24FlexrayA.init();
945 c.update("1234");
946 c.update("56789");
947 try testing.expectEqual(@as(u24, 0x7979bd), c.final());
948}
949
950test "CRC-24/FLEXRAY-B" {
951 const Crc24FlexrayB = crc.Crc24FlexrayB;
952
953 try testing.expectEqual(@as(u24, 0x1f23b8), Crc24FlexrayB.hash("123456789"));
954
955 var c = Crc24FlexrayB.init();
956 c.update("1234");
957 c.update("56789");
958 try testing.expectEqual(@as(u24, 0x1f23b8), c.final());
959}
960
961test "CRC-24/INTERLAKEN" {
962 const Crc24Interlaken = crc.Crc24Interlaken;
963
964 try testing.expectEqual(@as(u24, 0xb4f3e6), Crc24Interlaken.hash("123456789"));
965
966 var c = Crc24Interlaken.init();
967 c.update("1234");
968 c.update("56789");
969 try testing.expectEqual(@as(u24, 0xb4f3e6), c.final());
970}
971
972test "CRC-24/LTE-A" {
973 const Crc24LteA = crc.Crc24LteA;
974
975 try testing.expectEqual(@as(u24, 0xcde703), Crc24LteA.hash("123456789"));
976
977 var c = Crc24LteA.init();
978 c.update("1234");
979 c.update("56789");
980 try testing.expectEqual(@as(u24, 0xcde703), c.final());
981}
982
983test "CRC-24/LTE-B" {
984 const Crc24LteB = crc.Crc24LteB;
985
986 try testing.expectEqual(@as(u24, 0x23ef52), Crc24LteB.hash("123456789"));
987
988 var c = Crc24LteB.init();
989 c.update("1234");
990 c.update("56789");
991 try testing.expectEqual(@as(u24, 0x23ef52), c.final());
992}
993
994test "CRC-24/OPENPGP" {
995 const Crc24Openpgp = crc.Crc24Openpgp;
996
997 try testing.expectEqual(@as(u24, 0x21cf02), Crc24Openpgp.hash("123456789"));
998
999 var c = Crc24Openpgp.init();
1000 c.update("1234");
1001 c.update("56789");
1002 try testing.expectEqual(@as(u24, 0x21cf02), c.final());
1003}
1004
1005test "CRC-24/OS-9" {
1006 const Crc24Os9 = crc.Crc24Os9;
1007
1008 try testing.expectEqual(@as(u24, 0x200fa5), Crc24Os9.hash("123456789"));
1009
1010 var c = Crc24Os9.init();
1011 c.update("1234");
1012 c.update("56789");
1013 try testing.expectEqual(@as(u24, 0x200fa5), c.final());
1014}
1015
1016test "CRC-30/CDMA" {
1017 const Crc30Cdma = crc.Crc30Cdma;
1018
1019 try testing.expectEqual(@as(u30, 0x04c34abf), Crc30Cdma.hash("123456789"));
1020
1021 var c = Crc30Cdma.init();
1022 c.update("1234");
1023 c.update("56789");
1024 try testing.expectEqual(@as(u30, 0x04c34abf), c.final());
1025}
1026
1027test "CRC-31/PHILIPS" {
1028 const Crc31Philips = crc.Crc31Philips;
1029
1030 try testing.expectEqual(@as(u31, 0x0ce9e46c), Crc31Philips.hash("123456789"));
1031
1032 var c = Crc31Philips.init();
1033 c.update("1234");
1034 c.update("56789");
1035 try testing.expectEqual(@as(u31, 0x0ce9e46c), c.final());
1036}
1037
1038test "CRC-32/AIXM" {
1039 const Crc32Aixm = crc.Crc32Aixm;
1040
1041 try testing.expectEqual(@as(u32, 0x3010bf7f), Crc32Aixm.hash("123456789"));
1042
1043 var c = Crc32Aixm.init();
1044 c.update("1234");
1045 c.update("56789");
1046 try testing.expectEqual(@as(u32, 0x3010bf7f), c.final());
1047}
1048
1049test "CRC-32/AUTOSAR" {
1050 const Crc32Autosar = crc.Crc32Autosar;
1051
1052 try testing.expectEqual(@as(u32, 0x1697d06a), Crc32Autosar.hash("123456789"));
1053
1054 var c = Crc32Autosar.init();
1055 c.update("1234");
1056 c.update("56789");
1057 try testing.expectEqual(@as(u32, 0x1697d06a), c.final());
1058}
1059
1060test "CRC-32/BASE91-D" {
1061 const Crc32Base91D = crc.Crc32Base91D;
1062
1063 try testing.expectEqual(@as(u32, 0x87315576), Crc32Base91D.hash("123456789"));
1064
1065 var c = Crc32Base91D.init();
1066 c.update("1234");
1067 c.update("56789");
1068 try testing.expectEqual(@as(u32, 0x87315576), c.final());
1069}
1070
1071test "CRC-32/BZIP2" {
1072 const Crc32Bzip2 = crc.Crc32Bzip2;
1073
1074 try testing.expectEqual(@as(u32, 0xfc891918), Crc32Bzip2.hash("123456789"));
1075
1076 var c = Crc32Bzip2.init();
1077 c.update("1234");
1078 c.update("56789");
1079 try testing.expectEqual(@as(u32, 0xfc891918), c.final());
1080}
1081
1082test "CRC-32/CD-ROM-EDC" {
1083 const Crc32CdRomEdc = crc.Crc32CdRomEdc;
1084
1085 try testing.expectEqual(@as(u32, 0x6ec2edc4), Crc32CdRomEdc.hash("123456789"));
1086
1087 var c = Crc32CdRomEdc.init();
1088 c.update("1234");
1089 c.update("56789");
1090 try testing.expectEqual(@as(u32, 0x6ec2edc4), c.final());
1091}
1092
1093test "CRC-32/CKSUM" {
1094 const Crc32Cksum = crc.Crc32Cksum;
1095
1096 try testing.expectEqual(@as(u32, 0x765e7680), Crc32Cksum.hash("123456789"));
1097
1098 var c = Crc32Cksum.init();
1099 c.update("1234");
1100 c.update("56789");
1101 try testing.expectEqual(@as(u32, 0x765e7680), c.final());
1102}
1103
1104test "CRC-32/ISCSI" {
1105 const Crc32Iscsi = crc.Crc32Iscsi;
1106
1107 try testing.expectEqual(@as(u32, 0xe3069283), Crc32Iscsi.hash("123456789"));
1108
1109 var c = Crc32Iscsi.init();
1110 c.update("1234");
1111 c.update("56789");
1112 try testing.expectEqual(@as(u32, 0xe3069283), c.final());
1113}
1114
1115test "CRC-32/ISO-HDLC" {
1116 const Crc32IsoHdlc = crc.Crc32IsoHdlc;
1117
1118 try testing.expectEqual(@as(u32, 0xcbf43926), Crc32IsoHdlc.hash("123456789"));
1119
1120 var c = Crc32IsoHdlc.init();
1121 c.update("1234");
1122 c.update("56789");
1123 try testing.expectEqual(@as(u32, 0xcbf43926), c.final());
1124}
1125
1126test "CRC-32/JAMCRC" {
1127 const Crc32Jamcrc = crc.Crc32Jamcrc;
1128
1129 try testing.expectEqual(@as(u32, 0x340bc6d9), Crc32Jamcrc.hash("123456789"));
1130
1131 var c = Crc32Jamcrc.init();
1132 c.update("1234");
1133 c.update("56789");
1134 try testing.expectEqual(@as(u32, 0x340bc6d9), c.final());
1135}
1136
1137test "CRC-32/MEF" {
1138 const Crc32Mef = crc.Crc32Mef;
1139
1140 try testing.expectEqual(@as(u32, 0xd2c22f51), Crc32Mef.hash("123456789"));
1141
1142 var c = Crc32Mef.init();
1143 c.update("1234");
1144 c.update("56789");
1145 try testing.expectEqual(@as(u32, 0xd2c22f51), c.final());
1146}
1147
1148test "CRC-32/MPEG-2" {
1149 const Crc32Mpeg2 = crc.Crc32Mpeg2;
1150
1151 try testing.expectEqual(@as(u32, 0x0376e6e7), Crc32Mpeg2.hash("123456789"));
1152
1153 var c = Crc32Mpeg2.init();
1154 c.update("1234");
1155 c.update("56789");
1156 try testing.expectEqual(@as(u32, 0x0376e6e7), c.final());
1157}
1158
1159test "CRC-32/XFER" {
1160 const Crc32Xfer = crc.Crc32Xfer;
1161
1162 try testing.expectEqual(@as(u32, 0xbd0be338), Crc32Xfer.hash("123456789"));
1163
1164 var c = Crc32Xfer.init();
1165 c.update("1234");
1166 c.update("56789");
1167 try testing.expectEqual(@as(u32, 0xbd0be338), c.final());
1168}
1169
1170test "CRC-40/GSM" {
1171 const Crc40Gsm = crc.Crc40Gsm;
1172
1173 try testing.expectEqual(@as(u40, 0xd4164fc646), Crc40Gsm.hash("123456789"));
1174
1175 var c = Crc40Gsm.init();
1176 c.update("1234");
1177 c.update("56789");
1178 try testing.expectEqual(@as(u40, 0xd4164fc646), c.final());
1179}
1180
1181test "CRC-64/ECMA-182" {
1182 const Crc64Ecma182 = crc.Crc64Ecma182;
1183
1184 try testing.expectEqual(@as(u64, 0x6c40df5f0b497347), Crc64Ecma182.hash("123456789"));
1185
1186 var c = Crc64Ecma182.init();
1187 c.update("1234");
1188 c.update("56789");
1189 try testing.expectEqual(@as(u64, 0x6c40df5f0b497347), c.final());
1190}
1191
1192test "CRC-64/GO-ISO" {
1193 const Crc64GoIso = crc.Crc64GoIso;
1194
1195 try testing.expectEqual(@as(u64, 0xb90956c775a41001), Crc64GoIso.hash("123456789"));
1196
1197 var c = Crc64GoIso.init();
1198 c.update("1234");
1199 c.update("56789");
1200 try testing.expectEqual(@as(u64, 0xb90956c775a41001), c.final());
1201}
1202
1203test "CRC-64/MS" {
1204 const Crc64Ms = crc.Crc64Ms;
1205
1206 try testing.expectEqual(@as(u64, 0x75d4b74f024eceea), Crc64Ms.hash("123456789"));
1207
1208 var c = Crc64Ms.init();
1209 c.update("1234");
1210 c.update("56789");
1211 try testing.expectEqual(@as(u64, 0x75d4b74f024eceea), c.final());
1212}
1213
1214test "CRC-64/REDIS" {
1215 const Crc64Redis = crc.Crc64Redis;
1216
1217 try testing.expectEqual(@as(u64, 0xe9c6d914c4b8d9ca), Crc64Redis.hash("123456789"));
1218
1219 var c = Crc64Redis.init();
1220 c.update("1234");
1221 c.update("56789");
1222 try testing.expectEqual(@as(u64, 0xe9c6d914c4b8d9ca), c.final());
1223}
1224
1225test "CRC-64/WE" {
1226 const Crc64We = crc.Crc64We;
1227
1228 try testing.expectEqual(@as(u64, 0x62ec59e3f1a4f00a), Crc64We.hash("123456789"));
1229
1230 var c = Crc64We.init();
1231 c.update("1234");
1232 c.update("56789");
1233 try testing.expectEqual(@as(u64, 0x62ec59e3f1a4f00a), c.final());
1234}
1235
1236test "CRC-64/XZ" {
1237 const Crc64Xz = crc.Crc64Xz;
1238
1239 try testing.expectEqual(@as(u64, 0x995dc9bbdf1939fa), Crc64Xz.hash("123456789"));
1240
1241 var c = Crc64Xz.init();
1242 c.update("1234");
1243 c.update("56789");
1244 try testing.expectEqual(@as(u64, 0x995dc9bbdf1939fa), c.final());
1245}
1246
1247test "CRC-82/DARC" {
1248 const Crc82Darc = crc.Crc82Darc;
1249
1250 try testing.expectEqual(@as(u82, 0x09ea83f625023801fd612), Crc82Darc.hash("123456789"));
1251
1252 var c = Crc82Darc.init();
1253 c.update("1234");
1254 c.update("56789");
1255 try testing.expectEqual(@as(u82, 0x09ea83f625023801fd612), c.final());
1256}
tools/update_crc_catalog.zig+40-9
...@@ -23,11 +23,15 @@ pub fn main() anyerror!void {...@@ -23,11 +23,15 @@ pub fn main() anyerror!void {
23 var zig_src_dir = try fs.cwd().openDir(zig_src_root, .{});23 var zig_src_dir = try fs.cwd().openDir(zig_src_root, .{});
24 defer zig_src_dir.close();24 defer zig_src_dir.close();
2525
26 const target_sub_path = try fs.path.join(arena, &.{ "lib", "std", "hash", "crc" });26 const hash_sub_path = try fs.path.join(arena, &.{ "lib", "std", "hash" });
27 var target_dir = try zig_src_dir.makeOpenPath(target_sub_path, .{});27 var hash_target_dir = try zig_src_dir.makeOpenPath(hash_sub_path, .{});
28 defer target_dir.close();28 defer hash_target_dir.close();
2929
30 var zig_code_file = try target_dir.createFile("catalog.zig", .{});30 const crc_sub_path = try fs.path.join(arena, &.{ "lib", "std", "hash", "crc" });
31 var crc_target_dir = try zig_src_dir.makeOpenPath(crc_sub_path, .{});
32 defer crc_target_dir.close();
33
34 var zig_code_file = try hash_target_dir.createFile("crc.zig", .{});
31 defer zig_code_file.close();35 defer zig_code_file.close();
3236
33 var cbw = std.io.bufferedWriter(zig_code_file.writer());37 var cbw = std.io.bufferedWriter(zig_code_file.writer());
...@@ -37,15 +41,23 @@ pub fn main() anyerror!void {...@@ -37,15 +41,23 @@ pub fn main() anyerror!void {
37 try code_writer.writeAll(41 try code_writer.writeAll(
38 \\//! This file is auto-generated by tools/update_crc_catalog.zig.42 \\//! This file is auto-generated by tools/update_crc_catalog.zig.
39 \\43 \\
40 \\const Crc = @import("../crc.zig").Crc;44 \\const impl = @import("crc/impl.zig");
45 \\
46 \\pub const Crc = impl.Crc;
47 \\pub const Polynomial = impl.Polynomial;
48 \\pub const Crc32WithPoly = impl.Crc32WithPoly;
49 \\pub const Crc32SmallWithPoly = impl.Crc32SmallWithPoly;
50 \\
51 \\// IEEE is by far the most common CRC and so is aliased by default.
52 \\pub const Crc32 = Crc32WithPoly(.IEEE);
41 \\53 \\
42 \\test {54 \\test {
43 \\ _ = @import("catalog_test.zig");55 \\ _ = @import("crc/test.zig");
44 \\}56 \\}
45 \\57 \\
46 );58 );
4759
48 var zig_test_file = try target_dir.createFile("catalog_test.zig", .{});60 var zig_test_file = try crc_target_dir.createFile("test.zig", .{});
49 defer zig_test_file.close();61 defer zig_test_file.close();
5062
51 var tbw = std.io.bufferedWriter(zig_test_file.writer());63 var tbw = std.io.bufferedWriter(zig_test_file.writer());
...@@ -57,7 +69,26 @@ pub fn main() anyerror!void {...@@ -57,7 +69,26 @@ pub fn main() anyerror!void {
57 \\69 \\
58 \\const std = @import("std");70 \\const std = @import("std");
59 \\const testing = std.testing;71 \\const testing = std.testing;
60 \\const catalog = @import("catalog.zig");72 \\const verify = @import("../verify.zig");
73 \\const crc = @import("../crc.zig");
74 \\
75 \\test "crc32 ieee" {
76 \\ inline for ([2]type{ crc.Crc32WithPoly(.IEEE), crc.Crc32SmallWithPoly(.IEEE) }) |ieee| {
77 \\ try testing.expect(ieee.hash("") == 0x00000000);
78 \\ try testing.expect(ieee.hash("a") == 0xe8b7be43);
79 \\ try testing.expect(ieee.hash("abc") == 0x352441c2);
80 \\ try verify.iterativeApi(ieee);
81 \\ }
82 \\}
83 \\
84 \\test "crc32 castagnoli" {
85 \\ inline for ([2]type{ crc.Crc32WithPoly(.Castagnoli), crc.Crc32SmallWithPoly(.Castagnoli) }) |casta| {
86 \\ try testing.expect(casta.hash("") == 0x00000000);
87 \\ try testing.expect(casta.hash("a") == 0xc1d04330);
88 \\ try testing.expect(casta.hash("abc") == 0x364b3fb7);
89 \\ try verify.iterativeApi(casta);
90 \\ }
91 \\}
61 \\92 \\
62 );93 );
6394
...@@ -146,7 +177,7 @@ pub fn main() anyerror!void {...@@ -146,7 +177,7 @@ pub fn main() anyerror!void {
146 try test_writer.writeAll(try std.fmt.allocPrint(arena,177 try test_writer.writeAll(try std.fmt.allocPrint(arena,
147 \\178 \\
148 \\test "{0s}" {{179 \\test "{0s}" {{
149 \\ const {1s} = catalog.{1s};180 \\ const {1s} = crc.{1s};
150 \\181 \\
151 \\ try testing.expectEqual(@as(u{2s}, {3s}), {1s}.hash("123456789"));182 \\ try testing.expectEqual(@as(u{2s}, {3s}), {1s}.hash("123456789"));
152 \\183 \\