authorgravatar for fncontroloption@noreply.codeberg.orgFnControlOption <fncontroloption@noreply.codeberg.org> 2023-01-22 07:16:49-08:00
committergravatar for fncontroloption@noreply.codeberg.orgFnControlOption <fncontroloption@noreply.codeberg.org> 2023-01-22 07:16:49-08:00
log33682a29c6feadaf14cd8ad37f6a9480eda2d49a
tree05688e7537b6151eebea2977029d74148ece8e7e
parent6089ed9ee77ed034a39c2b557f4608cd8d779d3f

Rewrite update_crc_catalog in zig and move tests to separate file


6 files changed, 2438 insertions(+), 1521 deletions(-)

lib/std/hash/crc.zig+16-18
...@@ -14,13 +14,11 @@ pub usingnamespace @import("crc/catalog.zig");...@@ -14,13 +14,11 @@ pub usingnamespace @import("crc/catalog.zig");
1414
15pub fn Algorithm(comptime W: type) type {15pub fn Algorithm(comptime W: type) type {
16 return struct {16 return struct {
17 poly: W,17 polynomial: W,
18 init: W,18 initial: W,
19 refin: bool,19 reflect_input: bool,
20 refout: bool,20 reflect_output: bool,
21 xorout: W,21 xor_output: W,
22 check: W,
23 residue: W,
24 };22 };
25}23}
2624
...@@ -31,15 +29,15 @@ pub fn Crc(comptime W: type, comptime algorithm: Algorithm(W)) type {...@@ -31,15 +29,15 @@ pub fn Crc(comptime W: type, comptime algorithm: Algorithm(W)) type {
31 const lookup_table = blk: {29 const lookup_table = blk: {
32 @setEvalBranchQuota(2500);30 @setEvalBranchQuota(2500);
3331
34 const poly = if (algorithm.refin)32 const poly = if (algorithm.reflect_input)
35 @bitReverse(@as(I, algorithm.poly)) >> (@bitSizeOf(I) - @bitSizeOf(W))33 @bitReverse(@as(I, algorithm.polynomial)) >> (@bitSizeOf(I) - @bitSizeOf(W))
36 else34 else
37 @as(I, algorithm.poly) << (@bitSizeOf(I) - @bitSizeOf(W));35 @as(I, algorithm.polynomial) << (@bitSizeOf(I) - @bitSizeOf(W));
3836
39 var table: [256]I = undefined;37 var table: [256]I = undefined;
40 for (table) |*e, i| {38 for (table) |*e, i| {
41 var crc: I = i;39 var crc: I = i;
42 if (algorithm.refin) {40 if (algorithm.reflect_input) {
43 var j: usize = 0;41 var j: usize = 0;
44 while (j < 8) : (j += 1) {42 while (j < 8) : (j += 1) {
45 crc = (crc >> 1) ^ ((crc & 1) * poly);43 crc = (crc >> 1) ^ ((crc & 1) * poly);
...@@ -59,10 +57,10 @@ pub fn Crc(comptime W: type, comptime algorithm: Algorithm(W)) type {...@@ -59,10 +57,10 @@ pub fn Crc(comptime W: type, comptime algorithm: Algorithm(W)) type {
59 crc: I,57 crc: I,
6058
61 pub fn init() Self {59 pub fn init() Self {
62 const initial = if (algorithm.refin)60 const initial = if (algorithm.reflect_input)
63 @bitReverse(@as(I, algorithm.init)) >> (@bitSizeOf(I) - @bitSizeOf(W))61 @bitReverse(@as(I, algorithm.initial)) >> (@bitSizeOf(I) - @bitSizeOf(W))
64 else62 else
65 @as(I, algorithm.init) << (@bitSizeOf(I) - @bitSizeOf(W));63 @as(I, algorithm.initial) << (@bitSizeOf(I) - @bitSizeOf(W));
66 return Self{ .crc = initial };64 return Self{ .crc = initial };
67 }65 }
6866
...@@ -76,7 +74,7 @@ pub fn Crc(comptime W: type, comptime algorithm: Algorithm(W)) type {...@@ -76,7 +74,7 @@ pub fn Crc(comptime W: type, comptime algorithm: Algorithm(W)) type {
76 while (i < bytes.len) : (i += 1) {74 while (i < bytes.len) : (i += 1) {
77 self.crc = tableEntry(self.crc ^ bytes[i]);75 self.crc = tableEntry(self.crc ^ bytes[i]);
78 }76 }
79 } else if (algorithm.refin) {77 } else if (algorithm.reflect_input) {
80 while (i < bytes.len) : (i += 1) {78 while (i < bytes.len) : (i += 1) {
81 const table_index = self.crc ^ bytes[i];79 const table_index = self.crc ^ bytes[i];
82 self.crc = tableEntry(table_index) ^ (self.crc >> 8);80 self.crc = tableEntry(table_index) ^ (self.crc >> 8);
...@@ -91,13 +89,13 @@ pub fn Crc(comptime W: type, comptime algorithm: Algorithm(W)) type {...@@ -91,13 +89,13 @@ pub fn Crc(comptime W: type, comptime algorithm: Algorithm(W)) type {
9189
92 pub fn final(self: Self) W {90 pub fn final(self: Self) W {
93 var c = self.crc;91 var c = self.crc;
94 if (algorithm.refin != algorithm.refout) {92 if (algorithm.reflect_input != algorithm.reflect_output) {
95 c = @bitReverse(c);93 c = @bitReverse(c);
96 }94 }
97 if (!algorithm.refout) {95 if (!algorithm.reflect_output) {
98 c >>= @bitSizeOf(I) - @bitSizeOf(W);96 c >>= @bitSizeOf(I) - @bitSizeOf(W);
99 }97 }
100 return @intCast(W, c ^ algorithm.xorout);98 return @intCast(W, c ^ algorithm.xor_output);
101 }99 }
102100
103 pub fn hash(bytes: []const u8) W {101 pub fn hash(bytes: []const u8) W {
lib/std/hash/crc/catalog.zig+903-1463
...@@ -1,1463 +1,903 @@...@@ -1,1463 +1,903 @@
1//! This file is auto-generated by tools/update_crc_catalog.sh.1//! This file is auto-generated by tools/update_crc_catalog.zig.
22
3const std = @import("../../std.zig");3const Crc = @import("../crc.zig").Crc;
4const testing = std.testing;4
5const crc = @import("../crc.zig");5test {
6const Algorithm = crc.Algorithm;6 _ = @import("catalog_test.zig");
7const Crc = crc.Crc;7}
88
9const crc_3_gsm: Algorithm(u3) = .{ .poly = 0x3, .init = 0x0, .refin = false, .refout = false, .xorout = 0x7, .check = 0x4, .residue = 0x2 };9pub const Crc3Gsm = Crc(u3, .{
1010 .polynomial = 0x3,
11pub const Crc3Gsm = Crc(u3, crc_3_gsm);11 .initial = 0x0,
1212 .reflect_input = false,
13test "CRC-3/GSM" {13 .reflect_output = false,
14 try testing.expectEqual(crc_3_gsm.check, Crc3Gsm.hash("123456789"));14 .xor_output = 0x7,
1515});
16 var c = Crc3Gsm.init();16
17 c.update("1234");17pub const Crc3Rohc = Crc(u3, .{
18 c.update("56789");18 .polynomial = 0x3,
19 try testing.expectEqual(crc_3_gsm.check, c.final());19 .initial = 0x7,
20}20 .reflect_input = true,
2121 .reflect_output = true,
22const crc_3_rohc: Algorithm(u3) = .{ .poly = 0x3, .init = 0x7, .refin = true, .refout = true, .xorout = 0x0, .check = 0x6, .residue = 0x0 };22 .xor_output = 0x0,
2323});
24pub const Crc3Rohc = Crc(u3, crc_3_rohc);24
2525pub const Crc4G704 = Crc(u4, .{
26test "CRC-3/ROHC" {26 .polynomial = 0x3,
27 try testing.expectEqual(crc_3_rohc.check, Crc3Rohc.hash("123456789"));27 .initial = 0x0,
2828 .reflect_input = true,
29 var c = Crc3Rohc.init();29 .reflect_output = true,
30 c.update("1234");30 .xor_output = 0x0,
31 c.update("56789");31});
32 try testing.expectEqual(crc_3_rohc.check, c.final());32
33}33pub const Crc4Interlaken = Crc(u4, .{
3434 .polynomial = 0x3,
35const crc_4_g_704: Algorithm(u4) = .{ .poly = 0x3, .init = 0x0, .refin = true, .refout = true, .xorout = 0x0, .check = 0x7, .residue = 0x0 };35 .initial = 0xf,
3636 .reflect_input = false,
37pub const Crc4G704 = Crc(u4, crc_4_g_704);37 .reflect_output = false,
3838 .xor_output = 0xf,
39test "CRC-4/G-704" {39});
40 try testing.expectEqual(crc_4_g_704.check, Crc4G704.hash("123456789"));40
4141pub const Crc5EpcC1g2 = Crc(u5, .{
42 var c = Crc4G704.init();42 .polynomial = 0x09,
43 c.update("1234");43 .initial = 0x09,
44 c.update("56789");44 .reflect_input = false,
45 try testing.expectEqual(crc_4_g_704.check, c.final());45 .reflect_output = false,
46}46 .xor_output = 0x00,
4747});
48const crc_4_interlaken: Algorithm(u4) = .{ .poly = 0x3, .init = 0xf, .refin = false, .refout = false, .xorout = 0xf, .check = 0xb, .residue = 0x2 };48
4949pub const Crc5G704 = Crc(u5, .{
50pub const Crc4Interlaken = Crc(u4, crc_4_interlaken);50 .polynomial = 0x15,
5151 .initial = 0x00,
52test "CRC-4/INTERLAKEN" {52 .reflect_input = true,
53 try testing.expectEqual(crc_4_interlaken.check, Crc4Interlaken.hash("123456789"));53 .reflect_output = true,
5454 .xor_output = 0x00,
55 var c = Crc4Interlaken.init();55});
56 c.update("1234");56
57 c.update("56789");57pub const Crc5Usb = Crc(u5, .{
58 try testing.expectEqual(crc_4_interlaken.check, c.final());58 .polynomial = 0x05,
59}59 .initial = 0x1f,
6060 .reflect_input = true,
61const crc_5_epc_c1g2: Algorithm(u5) = .{ .poly = 0x09, .init = 0x09, .refin = false, .refout = false, .xorout = 0x00, .check = 0x00, .residue = 0x00 };61 .reflect_output = true,
6262 .xor_output = 0x1f,
63pub const Crc5EpcC1g2 = Crc(u5, crc_5_epc_c1g2);63});
6464
65test "CRC-5/EPC-C1G2" {65pub const Crc6Cdma2000A = Crc(u6, .{
66 try testing.expectEqual(crc_5_epc_c1g2.check, Crc5EpcC1g2.hash("123456789"));66 .polynomial = 0x27,
6767 .initial = 0x3f,
68 var c = Crc5EpcC1g2.init();68 .reflect_input = false,
69 c.update("1234");69 .reflect_output = false,
70 c.update("56789");70 .xor_output = 0x00,
71 try testing.expectEqual(crc_5_epc_c1g2.check, c.final());71});
72}72
7373pub const Crc6Cdma2000B = Crc(u6, .{
74const crc_5_g_704: Algorithm(u5) = .{ .poly = 0x15, .init = 0x00, .refin = true, .refout = true, .xorout = 0x00, .check = 0x07, .residue = 0x00 };74 .polynomial = 0x07,
7575 .initial = 0x3f,
76pub const Crc5G704 = Crc(u5, crc_5_g_704);76 .reflect_input = false,
7777 .reflect_output = false,
78test "CRC-5/G-704" {78 .xor_output = 0x00,
79 try testing.expectEqual(crc_5_g_704.check, Crc5G704.hash("123456789"));79});
8080
81 var c = Crc5G704.init();81pub const Crc6Darc = Crc(u6, .{
82 c.update("1234");82 .polynomial = 0x19,
83 c.update("56789");83 .initial = 0x00,
84 try testing.expectEqual(crc_5_g_704.check, c.final());84 .reflect_input = true,
85}85 .reflect_output = true,
8686 .xor_output = 0x00,
87const crc_5_usb: Algorithm(u5) = .{ .poly = 0x05, .init = 0x1f, .refin = true, .refout = true, .xorout = 0x1f, .check = 0x19, .residue = 0x06 };87});
8888
89pub const Crc5Usb = Crc(u5, crc_5_usb);89pub const Crc6G704 = Crc(u6, .{
9090 .polynomial = 0x03,
91test "CRC-5/USB" {91 .initial = 0x00,
92 try testing.expectEqual(crc_5_usb.check, Crc5Usb.hash("123456789"));92 .reflect_input = true,
9393 .reflect_output = true,
94 var c = Crc5Usb.init();94 .xor_output = 0x00,
95 c.update("1234");95});
96 c.update("56789");96
97 try testing.expectEqual(crc_5_usb.check, c.final());97pub const Crc6Gsm = Crc(u6, .{
98}98 .polynomial = 0x2f,
9999 .initial = 0x00,
100const crc_6_cdma2000_a: Algorithm(u6) = .{ .poly = 0x27, .init = 0x3f, .refin = false, .refout = false, .xorout = 0x00, .check = 0x0d, .residue = 0x00 };100 .reflect_input = false,
101101 .reflect_output = false,
102pub const Crc6Cdma2000A = Crc(u6, crc_6_cdma2000_a);102 .xor_output = 0x3f,
103103});
104test "CRC-6/CDMA2000-A" {104
105 try testing.expectEqual(crc_6_cdma2000_a.check, Crc6Cdma2000A.hash("123456789"));105pub const Crc7Mmc = Crc(u7, .{
106106 .polynomial = 0x09,
107 var c = Crc6Cdma2000A.init();107 .initial = 0x00,
108 c.update("1234");108 .reflect_input = false,
109 c.update("56789");109 .reflect_output = false,
110 try testing.expectEqual(crc_6_cdma2000_a.check, c.final());110 .xor_output = 0x00,
111}111});
112112
113const crc_6_cdma2000_b: Algorithm(u6) = .{ .poly = 0x07, .init = 0x3f, .refin = false, .refout = false, .xorout = 0x00, .check = 0x3b, .residue = 0x00 };113pub const Crc7Rohc = Crc(u7, .{
114114 .polynomial = 0x4f,
115pub const Crc6Cdma2000B = Crc(u6, crc_6_cdma2000_b);115 .initial = 0x7f,
116116 .reflect_input = true,
117test "CRC-6/CDMA2000-B" {117 .reflect_output = true,
118 try testing.expectEqual(crc_6_cdma2000_b.check, Crc6Cdma2000B.hash("123456789"));118 .xor_output = 0x00,
119119});
120 var c = Crc6Cdma2000B.init();120
121 c.update("1234");121pub const Crc7Umts = Crc(u7, .{
122 c.update("56789");122 .polynomial = 0x45,
123 try testing.expectEqual(crc_6_cdma2000_b.check, c.final());123 .initial = 0x00,
124}124 .reflect_input = false,
125125 .reflect_output = false,
126const crc_6_darc: Algorithm(u6) = .{ .poly = 0x19, .init = 0x00, .refin = true, .refout = true, .xorout = 0x00, .check = 0x26, .residue = 0x00 };126 .xor_output = 0x00,
127127});
128pub const Crc6Darc = Crc(u6, crc_6_darc);128
129129pub const Crc8Autosar = Crc(u8, .{
130test "CRC-6/DARC" {130 .polynomial = 0x2f,
131 try testing.expectEqual(crc_6_darc.check, Crc6Darc.hash("123456789"));131 .initial = 0xff,
132132 .reflect_input = false,
133 var c = Crc6Darc.init();133 .reflect_output = false,
134 c.update("1234");134 .xor_output = 0xff,
135 c.update("56789");135});
136 try testing.expectEqual(crc_6_darc.check, c.final());136
137}137pub const Crc8Bluetooth = Crc(u8, .{
138138 .polynomial = 0xa7,
139const crc_6_g_704: Algorithm(u6) = .{ .poly = 0x03, .init = 0x00, .refin = true, .refout = true, .xorout = 0x00, .check = 0x06, .residue = 0x00 };139 .initial = 0x00,
140140 .reflect_input = true,
141pub const Crc6G704 = Crc(u6, crc_6_g_704);141 .reflect_output = true,
142142 .xor_output = 0x00,
143test "CRC-6/G-704" {143});
144 try testing.expectEqual(crc_6_g_704.check, Crc6G704.hash("123456789"));144
145145pub const Crc8Cdma2000 = Crc(u8, .{
146 var c = Crc6G704.init();146 .polynomial = 0x9b,
147 c.update("1234");147 .initial = 0xff,
148 c.update("56789");148 .reflect_input = false,
149 try testing.expectEqual(crc_6_g_704.check, c.final());149 .reflect_output = false,
150}150 .xor_output = 0x00,
151151});
152const crc_6_gsm: Algorithm(u6) = .{ .poly = 0x2f, .init = 0x00, .refin = false, .refout = false, .xorout = 0x3f, .check = 0x13, .residue = 0x3a };152
153153pub const Crc8Darc = Crc(u8, .{
154pub const Crc6Gsm = Crc(u6, crc_6_gsm);154 .polynomial = 0x39,
155155 .initial = 0x00,
156test "CRC-6/GSM" {156 .reflect_input = true,
157 try testing.expectEqual(crc_6_gsm.check, Crc6Gsm.hash("123456789"));157 .reflect_output = true,
158158 .xor_output = 0x00,
159 var c = Crc6Gsm.init();159});
160 c.update("1234");160
161 c.update("56789");161pub const Crc8DvbS2 = Crc(u8, .{
162 try testing.expectEqual(crc_6_gsm.check, c.final());162 .polynomial = 0xd5,
163}163 .initial = 0x00,
164164 .reflect_input = false,
165const crc_7_mmc: Algorithm(u7) = .{ .poly = 0x09, .init = 0x00, .refin = false, .refout = false, .xorout = 0x00, .check = 0x75, .residue = 0x00 };165 .reflect_output = false,
166166 .xor_output = 0x00,
167pub const Crc7Mmc = Crc(u7, crc_7_mmc);167});
168168
169test "CRC-7/MMC" {169pub const Crc8GsmA = Crc(u8, .{
170 try testing.expectEqual(crc_7_mmc.check, Crc7Mmc.hash("123456789"));170 .polynomial = 0x1d,
171171 .initial = 0x00,
172 var c = Crc7Mmc.init();172 .reflect_input = false,
173 c.update("1234");173 .reflect_output = false,
174 c.update("56789");174 .xor_output = 0x00,
175 try testing.expectEqual(crc_7_mmc.check, c.final());175});
176}176
177177pub const Crc8GsmB = Crc(u8, .{
178const crc_7_rohc: Algorithm(u7) = .{ .poly = 0x4f, .init = 0x7f, .refin = true, .refout = true, .xorout = 0x00, .check = 0x53, .residue = 0x00 };178 .polynomial = 0x49,
179179 .initial = 0x00,
180pub const Crc7Rohc = Crc(u7, crc_7_rohc);180 .reflect_input = false,
181181 .reflect_output = false,
182test "CRC-7/ROHC" {182 .xor_output = 0xff,
183 try testing.expectEqual(crc_7_rohc.check, Crc7Rohc.hash("123456789"));183});
184184
185 var c = Crc7Rohc.init();185pub const Crc8Hitag = Crc(u8, .{
186 c.update("1234");186 .polynomial = 0x1d,
187 c.update("56789");187 .initial = 0xff,
188 try testing.expectEqual(crc_7_rohc.check, c.final());188 .reflect_input = false,
189}189 .reflect_output = false,
190190 .xor_output = 0x00,
191const crc_7_umts: Algorithm(u7) = .{ .poly = 0x45, .init = 0x00, .refin = false, .refout = false, .xorout = 0x00, .check = 0x61, .residue = 0x00 };191});
192192
193pub const Crc7Umts = Crc(u7, crc_7_umts);193pub const Crc8I4321 = Crc(u8, .{
194194 .polynomial = 0x07,
195test "CRC-7/UMTS" {195 .initial = 0x00,
196 try testing.expectEqual(crc_7_umts.check, Crc7Umts.hash("123456789"));196 .reflect_input = false,
197197 .reflect_output = false,
198 var c = Crc7Umts.init();198 .xor_output = 0x55,
199 c.update("1234");199});
200 c.update("56789");200
201 try testing.expectEqual(crc_7_umts.check, c.final());201pub const Crc8ICode = Crc(u8, .{
202}202 .polynomial = 0x1d,
203203 .initial = 0xfd,
204const crc_8_autosar: Algorithm(u8) = .{ .poly = 0x2f, .init = 0xff, .refin = false, .refout = false, .xorout = 0xff, .check = 0xdf, .residue = 0x42 };204 .reflect_input = false,
205205 .reflect_output = false,
206pub const Crc8Autosar = Crc(u8, crc_8_autosar);206 .xor_output = 0x00,
207207});
208test "CRC-8/AUTOSAR" {208
209 try testing.expectEqual(crc_8_autosar.check, Crc8Autosar.hash("123456789"));209pub const Crc8Lte = Crc(u8, .{
210210 .polynomial = 0x9b,
211 var c = Crc8Autosar.init();211 .initial = 0x00,
212 c.update("1234");212 .reflect_input = false,
213 c.update("56789");213 .reflect_output = false,
214 try testing.expectEqual(crc_8_autosar.check, c.final());214 .xor_output = 0x00,
215}215});
216216
217const crc_8_bluetooth: Algorithm(u8) = .{ .poly = 0xa7, .init = 0x00, .refin = true, .refout = true, .xorout = 0x00, .check = 0x26, .residue = 0x00 };217pub const Crc8MaximDow = Crc(u8, .{
218218 .polynomial = 0x31,
219pub const Crc8Bluetooth = Crc(u8, crc_8_bluetooth);219 .initial = 0x00,
220220 .reflect_input = true,
221test "CRC-8/BLUETOOTH" {221 .reflect_output = true,
222 try testing.expectEqual(crc_8_bluetooth.check, Crc8Bluetooth.hash("123456789"));222 .xor_output = 0x00,
223223});
224 var c = Crc8Bluetooth.init();224
225 c.update("1234");225pub const Crc8MifareMad = Crc(u8, .{
226 c.update("56789");226 .polynomial = 0x1d,
227 try testing.expectEqual(crc_8_bluetooth.check, c.final());227 .initial = 0xc7,
228}228 .reflect_input = false,
229229 .reflect_output = false,
230const crc_8_cdma2000: Algorithm(u8) = .{ .poly = 0x9b, .init = 0xff, .refin = false, .refout = false, .xorout = 0x00, .check = 0xda, .residue = 0x00 };230 .xor_output = 0x00,
231231});
232pub const Crc8Cdma2000 = Crc(u8, crc_8_cdma2000);232
233233pub const Crc8Nrsc5 = Crc(u8, .{
234test "CRC-8/CDMA2000" {234 .polynomial = 0x31,
235 try testing.expectEqual(crc_8_cdma2000.check, Crc8Cdma2000.hash("123456789"));235 .initial = 0xff,
236236 .reflect_input = false,
237 var c = Crc8Cdma2000.init();237 .reflect_output = false,
238 c.update("1234");238 .xor_output = 0x00,
239 c.update("56789");239});
240 try testing.expectEqual(crc_8_cdma2000.check, c.final());240
241}241pub const Crc8Opensafety = Crc(u8, .{
242242 .polynomial = 0x2f,
243const crc_8_darc: Algorithm(u8) = .{ .poly = 0x39, .init = 0x00, .refin = true, .refout = true, .xorout = 0x00, .check = 0x15, .residue = 0x00 };243 .initial = 0x00,
244244 .reflect_input = false,
245pub const Crc8Darc = Crc(u8, crc_8_darc);245 .reflect_output = false,
246246 .xor_output = 0x00,
247test "CRC-8/DARC" {247});
248 try testing.expectEqual(crc_8_darc.check, Crc8Darc.hash("123456789"));248
249249pub const Crc8Rohc = Crc(u8, .{
250 var c = Crc8Darc.init();250 .polynomial = 0x07,
251 c.update("1234");251 .initial = 0xff,
252 c.update("56789");252 .reflect_input = true,
253 try testing.expectEqual(crc_8_darc.check, c.final());253 .reflect_output = true,
254}254 .xor_output = 0x00,
255255});
256const crc_8_dvb_s2: Algorithm(u8) = .{ .poly = 0xd5, .init = 0x00, .refin = false, .refout = false, .xorout = 0x00, .check = 0xbc, .residue = 0x00 };256
257257pub const Crc8SaeJ1850 = Crc(u8, .{
258pub const Crc8DvbS2 = Crc(u8, crc_8_dvb_s2);258 .polynomial = 0x1d,
259259 .initial = 0xff,
260test "CRC-8/DVB-S2" {260 .reflect_input = false,
261 try testing.expectEqual(crc_8_dvb_s2.check, Crc8DvbS2.hash("123456789"));261 .reflect_output = false,
262262 .xor_output = 0xff,
263 var c = Crc8DvbS2.init();263});
264 c.update("1234");264
265 c.update("56789");265pub const Crc8Smbus = Crc(u8, .{
266 try testing.expectEqual(crc_8_dvb_s2.check, c.final());266 .polynomial = 0x07,
267}267 .initial = 0x00,
268268 .reflect_input = false,
269const crc_8_gsm_a: Algorithm(u8) = .{ .poly = 0x1d, .init = 0x00, .refin = false, .refout = false, .xorout = 0x00, .check = 0x37, .residue = 0x00 };269 .reflect_output = false,
270270 .xor_output = 0x00,
271pub const Crc8GsmA = Crc(u8, crc_8_gsm_a);271});
272272
273test "CRC-8/GSM-A" {273pub const Crc8Tech3250 = Crc(u8, .{
274 try testing.expectEqual(crc_8_gsm_a.check, Crc8GsmA.hash("123456789"));274 .polynomial = 0x1d,
275275 .initial = 0xff,
276 var c = Crc8GsmA.init();276 .reflect_input = true,
277 c.update("1234");277 .reflect_output = true,
278 c.update("56789");278 .xor_output = 0x00,
279 try testing.expectEqual(crc_8_gsm_a.check, c.final());279});
280}280
281281pub const Crc8Wcdma = Crc(u8, .{
282const crc_8_gsm_b: Algorithm(u8) = .{ .poly = 0x49, .init = 0x00, .refin = false, .refout = false, .xorout = 0xff, .check = 0x94, .residue = 0x53 };282 .polynomial = 0x9b,
283283 .initial = 0x00,
284pub const Crc8GsmB = Crc(u8, crc_8_gsm_b);284 .reflect_input = true,
285285 .reflect_output = true,
286test "CRC-8/GSM-B" {286 .xor_output = 0x00,
287 try testing.expectEqual(crc_8_gsm_b.check, Crc8GsmB.hash("123456789"));287});
288288
289 var c = Crc8GsmB.init();289pub const Crc10Atm = Crc(u10, .{
290 c.update("1234");290 .polynomial = 0x233,
291 c.update("56789");291 .initial = 0x000,
292 try testing.expectEqual(crc_8_gsm_b.check, c.final());292 .reflect_input = false,
293}293 .reflect_output = false,
294294 .xor_output = 0x000,
295const crc_8_hitag: Algorithm(u8) = .{ .poly = 0x1d, .init = 0xff, .refin = false, .refout = false, .xorout = 0x00, .check = 0xb4, .residue = 0x00 };295});
296296
297pub const Crc8Hitag = Crc(u8, crc_8_hitag);297pub const Crc10Cdma2000 = Crc(u10, .{
298298 .polynomial = 0x3d9,
299test "CRC-8/HITAG" {299 .initial = 0x3ff,
300 try testing.expectEqual(crc_8_hitag.check, Crc8Hitag.hash("123456789"));300 .reflect_input = false,
301301 .reflect_output = false,
302 var c = Crc8Hitag.init();302 .xor_output = 0x000,
303 c.update("1234");303});
304 c.update("56789");304
305 try testing.expectEqual(crc_8_hitag.check, c.final());305pub const Crc10Gsm = Crc(u10, .{
306}306 .polynomial = 0x175,
307307 .initial = 0x000,
308const crc_8_i_432_1: Algorithm(u8) = .{ .poly = 0x07, .init = 0x00, .refin = false, .refout = false, .xorout = 0x55, .check = 0xa1, .residue = 0xac };308 .reflect_input = false,
309309 .reflect_output = false,
310pub const Crc8I4321 = Crc(u8, crc_8_i_432_1);310 .xor_output = 0x3ff,
311311});
312test "CRC-8/I-432-1" {312
313 try testing.expectEqual(crc_8_i_432_1.check, Crc8I4321.hash("123456789"));313pub const Crc11Flexray = Crc(u11, .{
314314 .polynomial = 0x385,
315 var c = Crc8I4321.init();315 .initial = 0x01a,
316 c.update("1234");316 .reflect_input = false,
317 c.update("56789");317 .reflect_output = false,
318 try testing.expectEqual(crc_8_i_432_1.check, c.final());318 .xor_output = 0x000,
319}319});
320320
321const crc_8_i_code: Algorithm(u8) = .{ .poly = 0x1d, .init = 0xfd, .refin = false, .refout = false, .xorout = 0x00, .check = 0x7e, .residue = 0x00 };321pub const Crc11Umts = Crc(u11, .{
322322 .polynomial = 0x307,
323pub const Crc8ICode = Crc(u8, crc_8_i_code);323 .initial = 0x000,
324324 .reflect_input = false,
325test "CRC-8/I-CODE" {325 .reflect_output = false,
326 try testing.expectEqual(crc_8_i_code.check, Crc8ICode.hash("123456789"));326 .xor_output = 0x000,
327327});
328 var c = Crc8ICode.init();328
329 c.update("1234");329pub const Crc12Cdma2000 = Crc(u12, .{
330 c.update("56789");330 .polynomial = 0xf13,
331 try testing.expectEqual(crc_8_i_code.check, c.final());331 .initial = 0xfff,
332}332 .reflect_input = false,
333333 .reflect_output = false,
334const crc_8_lte: Algorithm(u8) = .{ .poly = 0x9b, .init = 0x00, .refin = false, .refout = false, .xorout = 0x00, .check = 0xea, .residue = 0x00 };334 .xor_output = 0x000,
335335});
336pub const Crc8Lte = Crc(u8, crc_8_lte);336
337337pub const Crc12Dect = Crc(u12, .{
338test "CRC-8/LTE" {338 .polynomial = 0x80f,
339 try testing.expectEqual(crc_8_lte.check, Crc8Lte.hash("123456789"));339 .initial = 0x000,
340340 .reflect_input = false,
341 var c = Crc8Lte.init();341 .reflect_output = false,
342 c.update("1234");342 .xor_output = 0x000,
343 c.update("56789");343});
344 try testing.expectEqual(crc_8_lte.check, c.final());344
345}345pub const Crc12Gsm = Crc(u12, .{
346346 .polynomial = 0xd31,
347const crc_8_maxim_dow: Algorithm(u8) = .{ .poly = 0x31, .init = 0x00, .refin = true, .refout = true, .xorout = 0x00, .check = 0xa1, .residue = 0x00 };347 .initial = 0x000,
348348 .reflect_input = false,
349pub const Crc8MaximDow = Crc(u8, crc_8_maxim_dow);349 .reflect_output = false,
350350 .xor_output = 0xfff,
351test "CRC-8/MAXIM-DOW" {351});
352 try testing.expectEqual(crc_8_maxim_dow.check, Crc8MaximDow.hash("123456789"));352
353353pub const Crc12Umts = Crc(u12, .{
354 var c = Crc8MaximDow.init();354 .polynomial = 0x80f,
355 c.update("1234");355 .initial = 0x000,
356 c.update("56789");356 .reflect_input = false,
357 try testing.expectEqual(crc_8_maxim_dow.check, c.final());357 .reflect_output = true,
358}358 .xor_output = 0x000,
359359});
360const crc_8_mifare_mad: Algorithm(u8) = .{ .poly = 0x1d, .init = 0xc7, .refin = false, .refout = false, .xorout = 0x00, .check = 0x99, .residue = 0x00 };360
361361pub const Crc13Bbc = Crc(u13, .{
362pub const Crc8MifareMad = Crc(u8, crc_8_mifare_mad);362 .polynomial = 0x1cf5,
363363 .initial = 0x0000,
364test "CRC-8/MIFARE-MAD" {364 .reflect_input = false,
365 try testing.expectEqual(crc_8_mifare_mad.check, Crc8MifareMad.hash("123456789"));365 .reflect_output = false,
366366 .xor_output = 0x0000,
367 var c = Crc8MifareMad.init();367});
368 c.update("1234");368
369 c.update("56789");369pub const Crc14Darc = Crc(u14, .{
370 try testing.expectEqual(crc_8_mifare_mad.check, c.final());370 .polynomial = 0x0805,
371}371 .initial = 0x0000,
372372 .reflect_input = true,
373const crc_8_nrsc_5: Algorithm(u8) = .{ .poly = 0x31, .init = 0xff, .refin = false, .refout = false, .xorout = 0x00, .check = 0xf7, .residue = 0x00 };373 .reflect_output = true,
374374 .xor_output = 0x0000,
375pub const Crc8Nrsc5 = Crc(u8, crc_8_nrsc_5);375});
376376
377test "CRC-8/NRSC-5" {377pub const Crc14Gsm = Crc(u14, .{
378 try testing.expectEqual(crc_8_nrsc_5.check, Crc8Nrsc5.hash("123456789"));378 .polynomial = 0x202d,
379379 .initial = 0x0000,
380 var c = Crc8Nrsc5.init();380 .reflect_input = false,
381 c.update("1234");381 .reflect_output = false,
382 c.update("56789");382 .xor_output = 0x3fff,
383 try testing.expectEqual(crc_8_nrsc_5.check, c.final());383});
384}384
385385pub const Crc15Can = Crc(u15, .{
386const crc_8_opensafety: Algorithm(u8) = .{ .poly = 0x2f, .init = 0x00, .refin = false, .refout = false, .xorout = 0x00, .check = 0x3e, .residue = 0x00 };386 .polynomial = 0x4599,
387387 .initial = 0x0000,
388pub const Crc8Opensafety = Crc(u8, crc_8_opensafety);388 .reflect_input = false,
389389 .reflect_output = false,
390test "CRC-8/OPENSAFETY" {390 .xor_output = 0x0000,
391 try testing.expectEqual(crc_8_opensafety.check, Crc8Opensafety.hash("123456789"));391});
392392
393 var c = Crc8Opensafety.init();393pub const Crc15Mpt1327 = Crc(u15, .{
394 c.update("1234");394 .polynomial = 0x6815,
395 c.update("56789");395 .initial = 0x0000,
396 try testing.expectEqual(crc_8_opensafety.check, c.final());396 .reflect_input = false,
397}397 .reflect_output = false,
398398 .xor_output = 0x0001,
399const crc_8_rohc: Algorithm(u8) = .{ .poly = 0x07, .init = 0xff, .refin = true, .refout = true, .xorout = 0x00, .check = 0xd0, .residue = 0x00 };399});
400400
401pub const Crc8Rohc = Crc(u8, crc_8_rohc);401pub const Crc16Arc = Crc(u16, .{
402402 .polynomial = 0x8005,
403test "CRC-8/ROHC" {403 .initial = 0x0000,
404 try testing.expectEqual(crc_8_rohc.check, Crc8Rohc.hash("123456789"));404 .reflect_input = true,
405405 .reflect_output = true,
406 var c = Crc8Rohc.init();406 .xor_output = 0x0000,
407 c.update("1234");407});
408 c.update("56789");408
409 try testing.expectEqual(crc_8_rohc.check, c.final());409pub const Crc16Cdma2000 = Crc(u16, .{
410}410 .polynomial = 0xc867,
411411 .initial = 0xffff,
412const crc_8_sae_j1850: Algorithm(u8) = .{ .poly = 0x1d, .init = 0xff, .refin = false, .refout = false, .xorout = 0xff, .check = 0x4b, .residue = 0xc4 };412 .reflect_input = false,
413413 .reflect_output = false,
414pub const Crc8SaeJ1850 = Crc(u8, crc_8_sae_j1850);414 .xor_output = 0x0000,
415415});
416test "CRC-8/SAE-J1850" {416
417 try testing.expectEqual(crc_8_sae_j1850.check, Crc8SaeJ1850.hash("123456789"));417pub const Crc16Cms = Crc(u16, .{
418418 .polynomial = 0x8005,
419 var c = Crc8SaeJ1850.init();419 .initial = 0xffff,
420 c.update("1234");420 .reflect_input = false,
421 c.update("56789");421 .reflect_output = false,
422 try testing.expectEqual(crc_8_sae_j1850.check, c.final());422 .xor_output = 0x0000,
423}423});
424424
425const crc_8_smbus: Algorithm(u8) = .{ .poly = 0x07, .init = 0x00, .refin = false, .refout = false, .xorout = 0x00, .check = 0xf4, .residue = 0x00 };425pub const Crc16Dds110 = Crc(u16, .{
426426 .polynomial = 0x8005,
427pub const Crc8Smbus = Crc(u8, crc_8_smbus);427 .initial = 0x800d,
428428 .reflect_input = false,
429test "CRC-8/SMBUS" {429 .reflect_output = false,
430 try testing.expectEqual(crc_8_smbus.check, Crc8Smbus.hash("123456789"));430 .xor_output = 0x0000,
431431});
432 var c = Crc8Smbus.init();432
433 c.update("1234");433pub const Crc16DectR = Crc(u16, .{
434 c.update("56789");434 .polynomial = 0x0589,
435 try testing.expectEqual(crc_8_smbus.check, c.final());435 .initial = 0x0000,
436}436 .reflect_input = false,
437437 .reflect_output = false,
438const crc_8_tech_3250: Algorithm(u8) = .{ .poly = 0x1d, .init = 0xff, .refin = true, .refout = true, .xorout = 0x00, .check = 0x97, .residue = 0x00 };438 .xor_output = 0x0001,
439439});
440pub const Crc8Tech3250 = Crc(u8, crc_8_tech_3250);440
441441pub const Crc16DectX = Crc(u16, .{
442test "CRC-8/TECH-3250" {442 .polynomial = 0x0589,
443 try testing.expectEqual(crc_8_tech_3250.check, Crc8Tech3250.hash("123456789"));443 .initial = 0x0000,
444444 .reflect_input = false,
445 var c = Crc8Tech3250.init();445 .reflect_output = false,
446 c.update("1234");446 .xor_output = 0x0000,
447 c.update("56789");447});
448 try testing.expectEqual(crc_8_tech_3250.check, c.final());448
449}449pub const Crc16Dnp = Crc(u16, .{
450450 .polynomial = 0x3d65,
451const crc_8_wcdma: Algorithm(u8) = .{ .poly = 0x9b, .init = 0x00, .refin = true, .refout = true, .xorout = 0x00, .check = 0x25, .residue = 0x00 };451 .initial = 0x0000,
452452 .reflect_input = true,
453pub const Crc8Wcdma = Crc(u8, crc_8_wcdma);453 .reflect_output = true,
454454 .xor_output = 0xffff,
455test "CRC-8/WCDMA" {455});
456 try testing.expectEqual(crc_8_wcdma.check, Crc8Wcdma.hash("123456789"));456
457457pub const Crc16En13757 = Crc(u16, .{
458 var c = Crc8Wcdma.init();458 .polynomial = 0x3d65,
459 c.update("1234");459 .initial = 0x0000,
460 c.update("56789");460 .reflect_input = false,
461 try testing.expectEqual(crc_8_wcdma.check, c.final());461 .reflect_output = false,
462}462 .xor_output = 0xffff,
463463});
464const crc_10_atm: Algorithm(u10) = .{ .poly = 0x233, .init = 0x000, .refin = false, .refout = false, .xorout = 0x000, .check = 0x199, .residue = 0x000 };464
465465pub const Crc16Genibus = Crc(u16, .{
466pub const Crc10Atm = Crc(u10, crc_10_atm);466 .polynomial = 0x1021,
467467 .initial = 0xffff,
468test "CRC-10/ATM" {468 .reflect_input = false,
469 try testing.expectEqual(crc_10_atm.check, Crc10Atm.hash("123456789"));469 .reflect_output = false,
470470 .xor_output = 0xffff,
471 var c = Crc10Atm.init();471});
472 c.update("1234");472
473 c.update("56789");473pub const Crc16Gsm = Crc(u16, .{
474 try testing.expectEqual(crc_10_atm.check, c.final());474 .polynomial = 0x1021,
475}475 .initial = 0x0000,
476476 .reflect_input = false,
477const crc_10_cdma2000: Algorithm(u10) = .{ .poly = 0x3d9, .init = 0x3ff, .refin = false, .refout = false, .xorout = 0x000, .check = 0x233, .residue = 0x000 };477 .reflect_output = false,
478478 .xor_output = 0xffff,
479pub const Crc10Cdma2000 = Crc(u10, crc_10_cdma2000);479});
480480
481test "CRC-10/CDMA2000" {481pub const Crc16Ibm3740 = Crc(u16, .{
482 try testing.expectEqual(crc_10_cdma2000.check, Crc10Cdma2000.hash("123456789"));482 .polynomial = 0x1021,
483483 .initial = 0xffff,
484 var c = Crc10Cdma2000.init();484 .reflect_input = false,
485 c.update("1234");485 .reflect_output = false,
486 c.update("56789");486 .xor_output = 0x0000,
487 try testing.expectEqual(crc_10_cdma2000.check, c.final());487});
488}488
489489pub const Crc16IbmSdlc = Crc(u16, .{
490const crc_10_gsm: Algorithm(u10) = .{ .poly = 0x175, .init = 0x000, .refin = false, .refout = false, .xorout = 0x3ff, .check = 0x12a, .residue = 0x0c6 };490 .polynomial = 0x1021,
491491 .initial = 0xffff,
492pub const Crc10Gsm = Crc(u10, crc_10_gsm);492 .reflect_input = true,
493493 .reflect_output = true,
494test "CRC-10/GSM" {494 .xor_output = 0xffff,
495 try testing.expectEqual(crc_10_gsm.check, Crc10Gsm.hash("123456789"));495});
496496
497 var c = Crc10Gsm.init();497pub const Crc16IsoIec144433A = Crc(u16, .{
498 c.update("1234");498 .polynomial = 0x1021,
499 c.update("56789");499 .initial = 0xc6c6,
500 try testing.expectEqual(crc_10_gsm.check, c.final());500 .reflect_input = true,
501}501 .reflect_output = true,
502502 .xor_output = 0x0000,
503const crc_11_flexray: Algorithm(u11) = .{ .poly = 0x385, .init = 0x01a, .refin = false, .refout = false, .xorout = 0x000, .check = 0x5a3, .residue = 0x000 };503});
504504
505pub const Crc11Flexray = Crc(u11, crc_11_flexray);505pub const Crc16Kermit = Crc(u16, .{
506506 .polynomial = 0x1021,
507test "CRC-11/FLEXRAY" {507 .initial = 0x0000,
508 try testing.expectEqual(crc_11_flexray.check, Crc11Flexray.hash("123456789"));508 .reflect_input = true,
509509 .reflect_output = true,
510 var c = Crc11Flexray.init();510 .xor_output = 0x0000,
511 c.update("1234");511});
512 c.update("56789");512
513 try testing.expectEqual(crc_11_flexray.check, c.final());513pub const Crc16Lj1200 = Crc(u16, .{
514}514 .polynomial = 0x6f63,
515515 .initial = 0x0000,
516const crc_11_umts: Algorithm(u11) = .{ .poly = 0x307, .init = 0x000, .refin = false, .refout = false, .xorout = 0x000, .check = 0x061, .residue = 0x000 };516 .reflect_input = false,
517517 .reflect_output = false,
518pub const Crc11Umts = Crc(u11, crc_11_umts);518 .xor_output = 0x0000,
519519});
520test "CRC-11/UMTS" {520
521 try testing.expectEqual(crc_11_umts.check, Crc11Umts.hash("123456789"));521pub const Crc16M17 = Crc(u16, .{
522522 .polynomial = 0x5935,
523 var c = Crc11Umts.init();523 .initial = 0xffff,
524 c.update("1234");524 .reflect_input = false,
525 c.update("56789");525 .reflect_output = false,
526 try testing.expectEqual(crc_11_umts.check, c.final());526 .xor_output = 0x0000,
527}527});
528528
529const crc_12_cdma2000: Algorithm(u12) = .{ .poly = 0xf13, .init = 0xfff, .refin = false, .refout = false, .xorout = 0x000, .check = 0xd4d, .residue = 0x000 };529pub const Crc16MaximDow = Crc(u16, .{
530530 .polynomial = 0x8005,
531pub const Crc12Cdma2000 = Crc(u12, crc_12_cdma2000);531 .initial = 0x0000,
532532 .reflect_input = true,
533test "CRC-12/CDMA2000" {533 .reflect_output = true,
534 try testing.expectEqual(crc_12_cdma2000.check, Crc12Cdma2000.hash("123456789"));534 .xor_output = 0xffff,
535535});
536 var c = Crc12Cdma2000.init();536
537 c.update("1234");537pub const Crc16Mcrf4xx = Crc(u16, .{
538 c.update("56789");538 .polynomial = 0x1021,
539 try testing.expectEqual(crc_12_cdma2000.check, c.final());539 .initial = 0xffff,
540}540 .reflect_input = true,
541541 .reflect_output = true,
542const crc_12_dect: Algorithm(u12) = .{ .poly = 0x80f, .init = 0x000, .refin = false, .refout = false, .xorout = 0x000, .check = 0xf5b, .residue = 0x000 };542 .xor_output = 0x0000,
543543});
544pub const Crc12Dect = Crc(u12, crc_12_dect);544
545545pub const Crc16Modbus = Crc(u16, .{
546test "CRC-12/DECT" {546 .polynomial = 0x8005,
547 try testing.expectEqual(crc_12_dect.check, Crc12Dect.hash("123456789"));547 .initial = 0xffff,
548548 .reflect_input = true,
549 var c = Crc12Dect.init();549 .reflect_output = true,
550 c.update("1234");550 .xor_output = 0x0000,
551 c.update("56789");551});
552 try testing.expectEqual(crc_12_dect.check, c.final());552
553}553pub const Crc16Nrsc5 = Crc(u16, .{
554554 .polynomial = 0x080b,
555const crc_12_gsm: Algorithm(u12) = .{ .poly = 0xd31, .init = 0x000, .refin = false, .refout = false, .xorout = 0xfff, .check = 0xb34, .residue = 0x178 };555 .initial = 0xffff,
556556 .reflect_input = true,
557pub const Crc12Gsm = Crc(u12, crc_12_gsm);557 .reflect_output = true,
558558 .xor_output = 0x0000,
559test "CRC-12/GSM" {559});
560 try testing.expectEqual(crc_12_gsm.check, Crc12Gsm.hash("123456789"));560
561561pub const Crc16OpensafetyA = Crc(u16, .{
562 var c = Crc12Gsm.init();562 .polynomial = 0x5935,
563 c.update("1234");563 .initial = 0x0000,
564 c.update("56789");564 .reflect_input = false,
565 try testing.expectEqual(crc_12_gsm.check, c.final());565 .reflect_output = false,
566}566 .xor_output = 0x0000,
567567});
568const crc_12_umts: Algorithm(u12) = .{ .poly = 0x80f, .init = 0x000, .refin = false, .refout = true, .xorout = 0x000, .check = 0xdaf, .residue = 0x000 };568
569569pub const Crc16OpensafetyB = Crc(u16, .{
570pub const Crc12Umts = Crc(u12, crc_12_umts);570 .polynomial = 0x755b,
571571 .initial = 0x0000,
572test "CRC-12/UMTS" {572 .reflect_input = false,
573 try testing.expectEqual(crc_12_umts.check, Crc12Umts.hash("123456789"));573 .reflect_output = false,
574574 .xor_output = 0x0000,
575 var c = Crc12Umts.init();575});
576 c.update("1234");576
577 c.update("56789");577pub const Crc16Profibus = Crc(u16, .{
578 try testing.expectEqual(crc_12_umts.check, c.final());578 .polynomial = 0x1dcf,
579}579 .initial = 0xffff,
580580 .reflect_input = false,
581const crc_13_bbc: Algorithm(u13) = .{ .poly = 0x1cf5, .init = 0x0000, .refin = false, .refout = false, .xorout = 0x0000, .check = 0x04fa, .residue = 0x0000 };581 .reflect_output = false,
582582 .xor_output = 0xffff,
583pub const Crc13Bbc = Crc(u13, crc_13_bbc);583});
584584
585test "CRC-13/BBC" {585pub const Crc16Riello = Crc(u16, .{
586 try testing.expectEqual(crc_13_bbc.check, Crc13Bbc.hash("123456789"));586 .polynomial = 0x1021,
587587 .initial = 0xb2aa,
588 var c = Crc13Bbc.init();588 .reflect_input = true,
589 c.update("1234");589 .reflect_output = true,
590 c.update("56789");590 .xor_output = 0x0000,
591 try testing.expectEqual(crc_13_bbc.check, c.final());591});
592}592
593593pub const Crc16SpiFujitsu = Crc(u16, .{
594const crc_14_darc: Algorithm(u14) = .{ .poly = 0x0805, .init = 0x0000, .refin = true, .refout = true, .xorout = 0x0000, .check = 0x082d, .residue = 0x0000 };594 .polynomial = 0x1021,
595595 .initial = 0x1d0f,
596pub const Crc14Darc = Crc(u14, crc_14_darc);596 .reflect_input = false,
597597 .reflect_output = false,
598test "CRC-14/DARC" {598 .xor_output = 0x0000,
599 try testing.expectEqual(crc_14_darc.check, Crc14Darc.hash("123456789"));599});
600600
601 var c = Crc14Darc.init();601pub const Crc16T10Dif = Crc(u16, .{
602 c.update("1234");602 .polynomial = 0x8bb7,
603 c.update("56789");603 .initial = 0x0000,
604 try testing.expectEqual(crc_14_darc.check, c.final());604 .reflect_input = false,
605}605 .reflect_output = false,
606606 .xor_output = 0x0000,
607const crc_14_gsm: Algorithm(u14) = .{ .poly = 0x202d, .init = 0x0000, .refin = false, .refout = false, .xorout = 0x3fff, .check = 0x30ae, .residue = 0x031e };607});
608608
609pub const Crc14Gsm = Crc(u14, crc_14_gsm);609pub const Crc16Teledisk = Crc(u16, .{
610610 .polynomial = 0xa097,
611test "CRC-14/GSM" {611 .initial = 0x0000,
612 try testing.expectEqual(crc_14_gsm.check, Crc14Gsm.hash("123456789"));612 .reflect_input = false,
613613 .reflect_output = false,
614 var c = Crc14Gsm.init();614 .xor_output = 0x0000,
615 c.update("1234");615});
616 c.update("56789");616
617 try testing.expectEqual(crc_14_gsm.check, c.final());617pub const Crc16Tms37157 = Crc(u16, .{
618}618 .polynomial = 0x1021,
619619 .initial = 0x89ec,
620const crc_15_can: Algorithm(u15) = .{ .poly = 0x4599, .init = 0x0000, .refin = false, .refout = false, .xorout = 0x0000, .check = 0x059e, .residue = 0x0000 };620 .reflect_input = true,
621621 .reflect_output = true,
622pub const Crc15Can = Crc(u15, crc_15_can);622 .xor_output = 0x0000,
623623});
624test "CRC-15/CAN" {624
625 try testing.expectEqual(crc_15_can.check, Crc15Can.hash("123456789"));625pub const Crc16Umts = Crc(u16, .{
626626 .polynomial = 0x8005,
627 var c = Crc15Can.init();627 .initial = 0x0000,
628 c.update("1234");628 .reflect_input = false,
629 c.update("56789");629 .reflect_output = false,
630 try testing.expectEqual(crc_15_can.check, c.final());630 .xor_output = 0x0000,
631}631});
632632
633const crc_15_mpt1327: Algorithm(u15) = .{ .poly = 0x6815, .init = 0x0000, .refin = false, .refout = false, .xorout = 0x0001, .check = 0x2566, .residue = 0x6815 };633pub const Crc16Usb = Crc(u16, .{
634634 .polynomial = 0x8005,
635pub const Crc15Mpt1327 = Crc(u15, crc_15_mpt1327);635 .initial = 0xffff,
636636 .reflect_input = true,
637test "CRC-15/MPT1327" {637 .reflect_output = true,
638 try testing.expectEqual(crc_15_mpt1327.check, Crc15Mpt1327.hash("123456789"));638 .xor_output = 0xffff,
639639});
640 var c = Crc15Mpt1327.init();640
641 c.update("1234");641pub const Crc16Xmodem = Crc(u16, .{
642 c.update("56789");642 .polynomial = 0x1021,
643 try testing.expectEqual(crc_15_mpt1327.check, c.final());643 .initial = 0x0000,
644}644 .reflect_input = false,
645645 .reflect_output = false,
646const crc_16_arc: Algorithm(u16) = .{ .poly = 0x8005, .init = 0x0000, .refin = true, .refout = true, .xorout = 0x0000, .check = 0xbb3d, .residue = 0x0000 };646 .xor_output = 0x0000,
647647});
648pub const Crc16Arc = Crc(u16, crc_16_arc);648
649649pub const Crc17CanFd = Crc(u17, .{
650test "CRC-16/ARC" {650 .polynomial = 0x1685b,
651 try testing.expectEqual(crc_16_arc.check, Crc16Arc.hash("123456789"));651 .initial = 0x00000,
652652 .reflect_input = false,
653 var c = Crc16Arc.init();653 .reflect_output = false,
654 c.update("1234");654 .xor_output = 0x00000,
655 c.update("56789");655});
656 try testing.expectEqual(crc_16_arc.check, c.final());656
657}657pub const Crc21CanFd = Crc(u21, .{
658658 .polynomial = 0x102899,
659const crc_16_cdma2000: Algorithm(u16) = .{ .poly = 0xc867, .init = 0xffff, .refin = false, .refout = false, .xorout = 0x0000, .check = 0x4c06, .residue = 0x0000 };659 .initial = 0x000000,
660660 .reflect_input = false,
661pub const Crc16Cdma2000 = Crc(u16, crc_16_cdma2000);661 .reflect_output = false,
662662 .xor_output = 0x000000,
663test "CRC-16/CDMA2000" {663});
664 try testing.expectEqual(crc_16_cdma2000.check, Crc16Cdma2000.hash("123456789"));664
665665pub const Crc24Ble = Crc(u24, .{
666 var c = Crc16Cdma2000.init();666 .polynomial = 0x00065b,
667 c.update("1234");667 .initial = 0x555555,
668 c.update("56789");668 .reflect_input = true,
669 try testing.expectEqual(crc_16_cdma2000.check, c.final());669 .reflect_output = true,
670}670 .xor_output = 0x000000,
671671});
672const crc_16_cms: Algorithm(u16) = .{ .poly = 0x8005, .init = 0xffff, .refin = false, .refout = false, .xorout = 0x0000, .check = 0xaee7, .residue = 0x0000 };672
673673pub const Crc24FlexrayA = Crc(u24, .{
674pub const Crc16Cms = Crc(u16, crc_16_cms);674 .polynomial = 0x5d6dcb,
675675 .initial = 0xfedcba,
676test "CRC-16/CMS" {676 .reflect_input = false,
677 try testing.expectEqual(crc_16_cms.check, Crc16Cms.hash("123456789"));677 .reflect_output = false,
678678 .xor_output = 0x000000,
679 var c = Crc16Cms.init();679});
680 c.update("1234");680
681 c.update("56789");681pub const Crc24FlexrayB = Crc(u24, .{
682 try testing.expectEqual(crc_16_cms.check, c.final());682 .polynomial = 0x5d6dcb,
683}683 .initial = 0xabcdef,
684684 .reflect_input = false,
685const crc_16_dds_110: Algorithm(u16) = .{ .poly = 0x8005, .init = 0x800d, .refin = false, .refout = false, .xorout = 0x0000, .check = 0x9ecf, .residue = 0x0000 };685 .reflect_output = false,
686686 .xor_output = 0x000000,
687pub const Crc16Dds110 = Crc(u16, crc_16_dds_110);687});
688688
689test "CRC-16/DDS-110" {689pub const Crc24Interlaken = Crc(u24, .{
690 try testing.expectEqual(crc_16_dds_110.check, Crc16Dds110.hash("123456789"));690 .polynomial = 0x328b63,
691691 .initial = 0xffffff,
692 var c = Crc16Dds110.init();692 .reflect_input = false,
693 c.update("1234");693 .reflect_output = false,
694 c.update("56789");694 .xor_output = 0xffffff,
695 try testing.expectEqual(crc_16_dds_110.check, c.final());695});
696}696
697697pub const Crc24LteA = Crc(u24, .{
698const crc_16_dect_r: Algorithm(u16) = .{ .poly = 0x0589, .init = 0x0000, .refin = false, .refout = false, .xorout = 0x0001, .check = 0x007e, .residue = 0x0589 };698 .polynomial = 0x864cfb,
699699 .initial = 0x000000,
700pub const Crc16DectR = Crc(u16, crc_16_dect_r);700 .reflect_input = false,
701701 .reflect_output = false,
702test "CRC-16/DECT-R" {702 .xor_output = 0x000000,
703 try testing.expectEqual(crc_16_dect_r.check, Crc16DectR.hash("123456789"));703});
704704
705 var c = Crc16DectR.init();705pub const Crc24LteB = Crc(u24, .{
706 c.update("1234");706 .polynomial = 0x800063,
707 c.update("56789");707 .initial = 0x000000,
708 try testing.expectEqual(crc_16_dect_r.check, c.final());708 .reflect_input = false,
709}709 .reflect_output = false,
710710 .xor_output = 0x000000,
711const crc_16_dect_x: Algorithm(u16) = .{ .poly = 0x0589, .init = 0x0000, .refin = false, .refout = false, .xorout = 0x0000, .check = 0x007f, .residue = 0x0000 };711});
712712
713pub const Crc16DectX = Crc(u16, crc_16_dect_x);713pub const Crc24Openpgp = Crc(u24, .{
714714 .polynomial = 0x864cfb,
715test "CRC-16/DECT-X" {715 .initial = 0xb704ce,
716 try testing.expectEqual(crc_16_dect_x.check, Crc16DectX.hash("123456789"));716 .reflect_input = false,
717717 .reflect_output = false,
718 var c = Crc16DectX.init();718 .xor_output = 0x000000,
719 c.update("1234");719});
720 c.update("56789");720
721 try testing.expectEqual(crc_16_dect_x.check, c.final());721pub const Crc24Os9 = Crc(u24, .{
722}722 .polynomial = 0x800063,
723723 .initial = 0xffffff,
724const crc_16_dnp: Algorithm(u16) = .{ .poly = 0x3d65, .init = 0x0000, .refin = true, .refout = true, .xorout = 0xffff, .check = 0xea82, .residue = 0x66c5 };724 .reflect_input = false,
725725 .reflect_output = false,
726pub const Crc16Dnp = Crc(u16, crc_16_dnp);726 .xor_output = 0xffffff,
727727});
728test "CRC-16/DNP" {728
729 try testing.expectEqual(crc_16_dnp.check, Crc16Dnp.hash("123456789"));729pub const Crc30Cdma = Crc(u30, .{
730730 .polynomial = 0x2030b9c7,
731 var c = Crc16Dnp.init();731 .initial = 0x3fffffff,
732 c.update("1234");732 .reflect_input = false,
733 c.update("56789");733 .reflect_output = false,
734 try testing.expectEqual(crc_16_dnp.check, c.final());734 .xor_output = 0x3fffffff,
735}735});
736736
737const crc_16_en_13757: Algorithm(u16) = .{ .poly = 0x3d65, .init = 0x0000, .refin = false, .refout = false, .xorout = 0xffff, .check = 0xc2b7, .residue = 0xa366 };737pub const Crc31Philips = Crc(u31, .{
738738 .polynomial = 0x04c11db7,
739pub const Crc16En13757 = Crc(u16, crc_16_en_13757);739 .initial = 0x7fffffff,
740740 .reflect_input = false,
741test "CRC-16/EN-13757" {741 .reflect_output = false,
742 try testing.expectEqual(crc_16_en_13757.check, Crc16En13757.hash("123456789"));742 .xor_output = 0x7fffffff,
743743});
744 var c = Crc16En13757.init();744
745 c.update("1234");745pub const Crc32Aixm = Crc(u32, .{
746 c.update("56789");746 .polynomial = 0x814141ab,
747 try testing.expectEqual(crc_16_en_13757.check, c.final());747 .initial = 0x00000000,
748}748 .reflect_input = false,
749749 .reflect_output = false,
750const crc_16_genibus: Algorithm(u16) = .{ .poly = 0x1021, .init = 0xffff, .refin = false, .refout = false, .xorout = 0xffff, .check = 0xd64e, .residue = 0x1d0f };750 .xor_output = 0x00000000,
751751});
752pub const Crc16Genibus = Crc(u16, crc_16_genibus);752
753753pub const Crc32Autosar = Crc(u32, .{
754test "CRC-16/GENIBUS" {754 .polynomial = 0xf4acfb13,
755 try testing.expectEqual(crc_16_genibus.check, Crc16Genibus.hash("123456789"));755 .initial = 0xffffffff,
756756 .reflect_input = true,
757 var c = Crc16Genibus.init();757 .reflect_output = true,
758 c.update("1234");758 .xor_output = 0xffffffff,
759 c.update("56789");759});
760 try testing.expectEqual(crc_16_genibus.check, c.final());760
761}761pub const Crc32Base91D = Crc(u32, .{
762762 .polynomial = 0xa833982b,
763const crc_16_gsm: Algorithm(u16) = .{ .poly = 0x1021, .init = 0x0000, .refin = false, .refout = false, .xorout = 0xffff, .check = 0xce3c, .residue = 0x1d0f };763 .initial = 0xffffffff,
764764 .reflect_input = true,
765pub const Crc16Gsm = Crc(u16, crc_16_gsm);765 .reflect_output = true,
766766 .xor_output = 0xffffffff,
767test "CRC-16/GSM" {767});
768 try testing.expectEqual(crc_16_gsm.check, Crc16Gsm.hash("123456789"));768
769769pub const Crc32Bzip2 = Crc(u32, .{
770 var c = Crc16Gsm.init();770 .polynomial = 0x04c11db7,
771 c.update("1234");771 .initial = 0xffffffff,
772 c.update("56789");772 .reflect_input = false,
773 try testing.expectEqual(crc_16_gsm.check, c.final());773 .reflect_output = false,
774}774 .xor_output = 0xffffffff,
775775});
776const crc_16_ibm_3740: Algorithm(u16) = .{ .poly = 0x1021, .init = 0xffff, .refin = false, .refout = false, .xorout = 0x0000, .check = 0x29b1, .residue = 0x0000 };776
777777pub const Crc32CdRomEdc = Crc(u32, .{
778pub const Crc16Ibm3740 = Crc(u16, crc_16_ibm_3740);778 .polynomial = 0x8001801b,
779779 .initial = 0x00000000,
780test "CRC-16/IBM-3740" {780 .reflect_input = true,
781 try testing.expectEqual(crc_16_ibm_3740.check, Crc16Ibm3740.hash("123456789"));781 .reflect_output = true,
782782 .xor_output = 0x00000000,
783 var c = Crc16Ibm3740.init();783});
784 c.update("1234");784
785 c.update("56789");785pub const Crc32Cksum = Crc(u32, .{
786 try testing.expectEqual(crc_16_ibm_3740.check, c.final());786 .polynomial = 0x04c11db7,
787}787 .initial = 0x00000000,
788788 .reflect_input = false,
789const crc_16_ibm_sdlc: Algorithm(u16) = .{ .poly = 0x1021, .init = 0xffff, .refin = true, .refout = true, .xorout = 0xffff, .check = 0x906e, .residue = 0xf0b8 };789 .reflect_output = false,
790790 .xor_output = 0xffffffff,
791pub const Crc16IbmSdlc = Crc(u16, crc_16_ibm_sdlc);791});
792792
793test "CRC-16/IBM-SDLC" {793pub const Crc32Iscsi = Crc(u32, .{
794 try testing.expectEqual(crc_16_ibm_sdlc.check, Crc16IbmSdlc.hash("123456789"));794 .polynomial = 0x1edc6f41,
795795 .initial = 0xffffffff,
796 var c = Crc16IbmSdlc.init();796 .reflect_input = true,
797 c.update("1234");797 .reflect_output = true,
798 c.update("56789");798 .xor_output = 0xffffffff,
799 try testing.expectEqual(crc_16_ibm_sdlc.check, c.final());799});
800}800
801801pub const Crc32IsoHdlc = Crc(u32, .{
802const crc_16_iso_iec_14443_3_a: Algorithm(u16) = .{ .poly = 0x1021, .init = 0xc6c6, .refin = true, .refout = true, .xorout = 0x0000, .check = 0xbf05, .residue = 0x0000 };802 .polynomial = 0x04c11db7,
803803 .initial = 0xffffffff,
804pub const Crc16IsoIec144433A = Crc(u16, crc_16_iso_iec_14443_3_a);804 .reflect_input = true,
805805 .reflect_output = true,
806test "CRC-16/ISO-IEC-14443-3-A" {806 .xor_output = 0xffffffff,
807 try testing.expectEqual(crc_16_iso_iec_14443_3_a.check, Crc16IsoIec144433A.hash("123456789"));807});
808808
809 var c = Crc16IsoIec144433A.init();809pub const Crc32Jamcrc = Crc(u32, .{
810 c.update("1234");810 .polynomial = 0x04c11db7,
811 c.update("56789");811 .initial = 0xffffffff,
812 try testing.expectEqual(crc_16_iso_iec_14443_3_a.check, c.final());812 .reflect_input = true,
813}813 .reflect_output = true,
814814 .xor_output = 0x00000000,
815const crc_16_kermit: Algorithm(u16) = .{ .poly = 0x1021, .init = 0x0000, .refin = true, .refout = true, .xorout = 0x0000, .check = 0x2189, .residue = 0x0000 };815});
816816
817pub const Crc16Kermit = Crc(u16, crc_16_kermit);817pub const Crc32Mef = Crc(u32, .{
818818 .polynomial = 0x741b8cd7,
819test "CRC-16/KERMIT" {819 .initial = 0xffffffff,
820 try testing.expectEqual(crc_16_kermit.check, Crc16Kermit.hash("123456789"));820 .reflect_input = true,
821821 .reflect_output = true,
822 var c = Crc16Kermit.init();822 .xor_output = 0x00000000,
823 c.update("1234");823});
824 c.update("56789");824
825 try testing.expectEqual(crc_16_kermit.check, c.final());825pub const Crc32Mpeg2 = Crc(u32, .{
826}826 .polynomial = 0x04c11db7,
827827 .initial = 0xffffffff,
828const crc_16_lj1200: Algorithm(u16) = .{ .poly = 0x6f63, .init = 0x0000, .refin = false, .refout = false, .xorout = 0x0000, .check = 0xbdf4, .residue = 0x0000 };828 .reflect_input = false,
829829 .reflect_output = false,
830pub const Crc16Lj1200 = Crc(u16, crc_16_lj1200);830 .xor_output = 0x00000000,
831831});
832test "CRC-16/LJ1200" {832
833 try testing.expectEqual(crc_16_lj1200.check, Crc16Lj1200.hash("123456789"));833pub const Crc32Xfer = Crc(u32, .{
834834 .polynomial = 0x000000af,
835 var c = Crc16Lj1200.init();835 .initial = 0x00000000,
836 c.update("1234");836 .reflect_input = false,
837 c.update("56789");837 .reflect_output = false,
838 try testing.expectEqual(crc_16_lj1200.check, c.final());838 .xor_output = 0x00000000,
839}839});
840840
841const crc_16_m17: Algorithm(u16) = .{ .poly = 0x5935, .init = 0xffff, .refin = false, .refout = false, .xorout = 0x0000, .check = 0x772b, .residue = 0x0000 };841pub const Crc40Gsm = Crc(u40, .{
842842 .polynomial = 0x0004820009,
843pub const Crc16M17 = Crc(u16, crc_16_m17);843 .initial = 0x0000000000,
844844 .reflect_input = false,
845test "CRC-16/M17" {845 .reflect_output = false,
846 try testing.expectEqual(crc_16_m17.check, Crc16M17.hash("123456789"));846 .xor_output = 0xffffffffff,
847847});
848 var c = Crc16M17.init();848
849 c.update("1234");849pub const Crc64Ecma182 = Crc(u64, .{
850 c.update("56789");850 .polynomial = 0x42f0e1eba9ea3693,
851 try testing.expectEqual(crc_16_m17.check, c.final());851 .initial = 0x0000000000000000,
852}852 .reflect_input = false,
853853 .reflect_output = false,
854const crc_16_maxim_dow: Algorithm(u16) = .{ .poly = 0x8005, .init = 0x0000, .refin = true, .refout = true, .xorout = 0xffff, .check = 0x44c2, .residue = 0xb001 };854 .xor_output = 0x0000000000000000,
855855});
856pub const Crc16MaximDow = Crc(u16, crc_16_maxim_dow);856
857857pub const Crc64GoIso = Crc(u64, .{
858test "CRC-16/MAXIM-DOW" {858 .polynomial = 0x000000000000001b,
859 try testing.expectEqual(crc_16_maxim_dow.check, Crc16MaximDow.hash("123456789"));859 .initial = 0xffffffffffffffff,
860860 .reflect_input = true,
861 var c = Crc16MaximDow.init();861 .reflect_output = true,
862 c.update("1234");862 .xor_output = 0xffffffffffffffff,
863 c.update("56789");863});
864 try testing.expectEqual(crc_16_maxim_dow.check, c.final());864
865}865pub const Crc64Ms = Crc(u64, .{
866866 .polynomial = 0x259c84cba6426349,
867const crc_16_mcrf4xx: Algorithm(u16) = .{ .poly = 0x1021, .init = 0xffff, .refin = true, .refout = true, .xorout = 0x0000, .check = 0x6f91, .residue = 0x0000 };867 .initial = 0xffffffffffffffff,
868868 .reflect_input = true,
869pub const Crc16Mcrf4xx = Crc(u16, crc_16_mcrf4xx);869 .reflect_output = true,
870870 .xor_output = 0x0000000000000000,
871test "CRC-16/MCRF4XX" {871});
872 try testing.expectEqual(crc_16_mcrf4xx.check, Crc16Mcrf4xx.hash("123456789"));872
873873pub const Crc64Redis = Crc(u64, .{
874 var c = Crc16Mcrf4xx.init();874 .polynomial = 0xad93d23594c935a9,
875 c.update("1234");875 .initial = 0x0000000000000000,
876 c.update("56789");876 .reflect_input = true,
877 try testing.expectEqual(crc_16_mcrf4xx.check, c.final());877 .reflect_output = true,
878}878 .xor_output = 0x0000000000000000,
879879});
880const crc_16_modbus: Algorithm(u16) = .{ .poly = 0x8005, .init = 0xffff, .refin = true, .refout = true, .xorout = 0x0000, .check = 0x4b37, .residue = 0x0000 };880
881881pub const Crc64We = Crc(u64, .{
882pub const Crc16Modbus = Crc(u16, crc_16_modbus);882 .polynomial = 0x42f0e1eba9ea3693,
883883 .initial = 0xffffffffffffffff,
884test "CRC-16/MODBUS" {884 .reflect_input = false,
885 try testing.expectEqual(crc_16_modbus.check, Crc16Modbus.hash("123456789"));885 .reflect_output = false,
886886 .xor_output = 0xffffffffffffffff,
887 var c = Crc16Modbus.init();887});
888 c.update("1234");888
889 c.update("56789");889pub const Crc64Xz = Crc(u64, .{
890 try testing.expectEqual(crc_16_modbus.check, c.final());890 .polynomial = 0x42f0e1eba9ea3693,
891}891 .initial = 0xffffffffffffffff,
892892 .reflect_input = true,
893const crc_16_nrsc_5: Algorithm(u16) = .{ .poly = 0x080b, .init = 0xffff, .refin = true, .refout = true, .xorout = 0x0000, .check = 0xa066, .residue = 0x0000 };893 .reflect_output = true,
894894 .xor_output = 0xffffffffffffffff,
895pub const Crc16Nrsc5 = Crc(u16, crc_16_nrsc_5);895});
896896
897test "CRC-16/NRSC-5" {897pub const Crc82Darc = Crc(u82, .{
898 try testing.expectEqual(crc_16_nrsc_5.check, Crc16Nrsc5.hash("123456789"));898 .polynomial = 0x0308c0111011401440411,
899899 .initial = 0x000000000000000000000,
900 var c = Crc16Nrsc5.init();900 .reflect_input = true,
901 c.update("1234");901 .reflect_output = true,
902 c.update("56789");902 .xor_output = 0x000000000000000000000,
903 try testing.expectEqual(crc_16_nrsc_5.check, c.final());903});
904}
905
906const crc_16_opensafety_a: Algorithm(u16) = .{ .poly = 0x5935, .init = 0x0000, .refin = false, .refout = false, .xorout = 0x0000, .check = 0x5d38, .residue = 0x0000 };
907
908pub const Crc16OpensafetyA = Crc(u16, crc_16_opensafety_a);
909
910test "CRC-16/OPENSAFETY-A" {
911 try testing.expectEqual(crc_16_opensafety_a.check, Crc16OpensafetyA.hash("123456789"));
912
913 var c = Crc16OpensafetyA.init();
914 c.update("1234");
915 c.update("56789");
916 try testing.expectEqual(crc_16_opensafety_a.check, c.final());
917}
918
919const crc_16_opensafety_b: Algorithm(u16) = .{ .poly = 0x755b, .init = 0x0000, .refin = false, .refout = false, .xorout = 0x0000, .check = 0x20fe, .residue = 0x0000 };
920
921pub const Crc16OpensafetyB = Crc(u16, crc_16_opensafety_b);
922
923test "CRC-16/OPENSAFETY-B" {
924 try testing.expectEqual(crc_16_opensafety_b.check, Crc16OpensafetyB.hash("123456789"));
925
926 var c = Crc16OpensafetyB.init();
927 c.update("1234");
928 c.update("56789");
929 try testing.expectEqual(crc_16_opensafety_b.check, c.final());
930}
931
932const crc_16_profibus: Algorithm(u16) = .{ .poly = 0x1dcf, .init = 0xffff, .refin = false, .refout = false, .xorout = 0xffff, .check = 0xa819, .residue = 0xe394 };
933
934pub const Crc16Profibus = Crc(u16, crc_16_profibus);
935
936test "CRC-16/PROFIBUS" {
937 try testing.expectEqual(crc_16_profibus.check, Crc16Profibus.hash("123456789"));
938
939 var c = Crc16Profibus.init();
940 c.update("1234");
941 c.update("56789");
942 try testing.expectEqual(crc_16_profibus.check, c.final());
943}
944
945const crc_16_riello: Algorithm(u16) = .{ .poly = 0x1021, .init = 0xb2aa, .refin = true, .refout = true, .xorout = 0x0000, .check = 0x63d0, .residue = 0x0000 };
946
947pub const Crc16Riello = Crc(u16, crc_16_riello);
948
949test "CRC-16/RIELLO" {
950 try testing.expectEqual(crc_16_riello.check, Crc16Riello.hash("123456789"));
951
952 var c = Crc16Riello.init();
953 c.update("1234");
954 c.update("56789");
955 try testing.expectEqual(crc_16_riello.check, c.final());
956}
957
958const crc_16_spi_fujitsu: Algorithm(u16) = .{ .poly = 0x1021, .init = 0x1d0f, .refin = false, .refout = false, .xorout = 0x0000, .check = 0xe5cc, .residue = 0x0000 };
959
960pub const Crc16SpiFujitsu = Crc(u16, crc_16_spi_fujitsu);
961
962test "CRC-16/SPI-FUJITSU" {
963 try testing.expectEqual(crc_16_spi_fujitsu.check, Crc16SpiFujitsu.hash("123456789"));
964
965 var c = Crc16SpiFujitsu.init();
966 c.update("1234");
967 c.update("56789");
968 try testing.expectEqual(crc_16_spi_fujitsu.check, c.final());
969}
970
971const crc_16_t10_dif: Algorithm(u16) = .{ .poly = 0x8bb7, .init = 0x0000, .refin = false, .refout = false, .xorout = 0x0000, .check = 0xd0db, .residue = 0x0000 };
972
973pub const Crc16T10Dif = Crc(u16, crc_16_t10_dif);
974
975test "CRC-16/T10-DIF" {
976 try testing.expectEqual(crc_16_t10_dif.check, Crc16T10Dif.hash("123456789"));
977
978 var c = Crc16T10Dif.init();
979 c.update("1234");
980 c.update("56789");
981 try testing.expectEqual(crc_16_t10_dif.check, c.final());
982}
983
984const crc_16_teledisk: Algorithm(u16) = .{ .poly = 0xa097, .init = 0x0000, .refin = false, .refout = false, .xorout = 0x0000, .check = 0x0fb3, .residue = 0x0000 };
985
986pub const Crc16Teledisk = Crc(u16, crc_16_teledisk);
987
988test "CRC-16/TELEDISK" {
989 try testing.expectEqual(crc_16_teledisk.check, Crc16Teledisk.hash("123456789"));
990
991 var c = Crc16Teledisk.init();
992 c.update("1234");
993 c.update("56789");
994 try testing.expectEqual(crc_16_teledisk.check, c.final());
995}
996
997const crc_16_tms37157: Algorithm(u16) = .{ .poly = 0x1021, .init = 0x89ec, .refin = true, .refout = true, .xorout = 0x0000, .check = 0x26b1, .residue = 0x0000 };
998
999pub const Crc16Tms37157 = Crc(u16, crc_16_tms37157);
1000
1001test "CRC-16/TMS37157" {
1002 try testing.expectEqual(crc_16_tms37157.check, Crc16Tms37157.hash("123456789"));
1003
1004 var c = Crc16Tms37157.init();
1005 c.update("1234");
1006 c.update("56789");
1007 try testing.expectEqual(crc_16_tms37157.check, c.final());
1008}
1009
1010const crc_16_umts: Algorithm(u16) = .{ .poly = 0x8005, .init = 0x0000, .refin = false, .refout = false, .xorout = 0x0000, .check = 0xfee8, .residue = 0x0000 };
1011
1012pub const Crc16Umts = Crc(u16, crc_16_umts);
1013
1014test "CRC-16/UMTS" {
1015 try testing.expectEqual(crc_16_umts.check, Crc16Umts.hash("123456789"));
1016
1017 var c = Crc16Umts.init();
1018 c.update("1234");
1019 c.update("56789");
1020 try testing.expectEqual(crc_16_umts.check, c.final());
1021}
1022
1023const crc_16_usb: Algorithm(u16) = .{ .poly = 0x8005, .init = 0xffff, .refin = true, .refout = true, .xorout = 0xffff, .check = 0xb4c8, .residue = 0xb001 };
1024
1025pub const Crc16Usb = Crc(u16, crc_16_usb);
1026
1027test "CRC-16/USB" {
1028 try testing.expectEqual(crc_16_usb.check, Crc16Usb.hash("123456789"));
1029
1030 var c = Crc16Usb.init();
1031 c.update("1234");
1032 c.update("56789");
1033 try testing.expectEqual(crc_16_usb.check, c.final());
1034}
1035
1036const crc_16_xmodem: Algorithm(u16) = .{ .poly = 0x1021, .init = 0x0000, .refin = false, .refout = false, .xorout = 0x0000, .check = 0x31c3, .residue = 0x0000 };
1037
1038pub const Crc16Xmodem = Crc(u16, crc_16_xmodem);
1039
1040test "CRC-16/XMODEM" {
1041 try testing.expectEqual(crc_16_xmodem.check, Crc16Xmodem.hash("123456789"));
1042
1043 var c = Crc16Xmodem.init();
1044 c.update("1234");
1045 c.update("56789");
1046 try testing.expectEqual(crc_16_xmodem.check, c.final());
1047}
1048
1049const crc_17_can_fd: Algorithm(u17) = .{ .poly = 0x1685b, .init = 0x00000, .refin = false, .refout = false, .xorout = 0x00000, .check = 0x04f03, .residue = 0x00000 };
1050
1051pub const Crc17CanFd = Crc(u17, crc_17_can_fd);
1052
1053test "CRC-17/CAN-FD" {
1054 try testing.expectEqual(crc_17_can_fd.check, Crc17CanFd.hash("123456789"));
1055
1056 var c = Crc17CanFd.init();
1057 c.update("1234");
1058 c.update("56789");
1059 try testing.expectEqual(crc_17_can_fd.check, c.final());
1060}
1061
1062const crc_21_can_fd: Algorithm(u21) = .{ .poly = 0x102899, .init = 0x000000, .refin = false, .refout = false, .xorout = 0x000000, .check = 0x0ed841, .residue = 0x000000 };
1063
1064pub const Crc21CanFd = Crc(u21, crc_21_can_fd);
1065
1066test "CRC-21/CAN-FD" {
1067 try testing.expectEqual(crc_21_can_fd.check, Crc21CanFd.hash("123456789"));
1068
1069 var c = Crc21CanFd.init();
1070 c.update("1234");
1071 c.update("56789");
1072 try testing.expectEqual(crc_21_can_fd.check, c.final());
1073}
1074
1075const crc_24_ble: Algorithm(u24) = .{ .poly = 0x00065b, .init = 0x555555, .refin = true, .refout = true, .xorout = 0x000000, .check = 0xc25a56, .residue = 0x000000 };
1076
1077pub const Crc24Ble = Crc(u24, crc_24_ble);
1078
1079test "CRC-24/BLE" {
1080 try testing.expectEqual(crc_24_ble.check, Crc24Ble.hash("123456789"));
1081
1082 var c = Crc24Ble.init();
1083 c.update("1234");
1084 c.update("56789");
1085 try testing.expectEqual(crc_24_ble.check, c.final());
1086}
1087
1088const crc_24_flexray_a: Algorithm(u24) = .{ .poly = 0x5d6dcb, .init = 0xfedcba, .refin = false, .refout = false, .xorout = 0x000000, .check = 0x7979bd, .residue = 0x000000 };
1089
1090pub const Crc24FlexrayA = Crc(u24, crc_24_flexray_a);
1091
1092test "CRC-24/FLEXRAY-A" {
1093 try testing.expectEqual(crc_24_flexray_a.check, Crc24FlexrayA.hash("123456789"));
1094
1095 var c = Crc24FlexrayA.init();
1096 c.update("1234");
1097 c.update("56789");
1098 try testing.expectEqual(crc_24_flexray_a.check, c.final());
1099}
1100
1101const crc_24_flexray_b: Algorithm(u24) = .{ .poly = 0x5d6dcb, .init = 0xabcdef, .refin = false, .refout = false, .xorout = 0x000000, .check = 0x1f23b8, .residue = 0x000000 };
1102
1103pub const Crc24FlexrayB = Crc(u24, crc_24_flexray_b);
1104
1105test "CRC-24/FLEXRAY-B" {
1106 try testing.expectEqual(crc_24_flexray_b.check, Crc24FlexrayB.hash("123456789"));
1107
1108 var c = Crc24FlexrayB.init();
1109 c.update("1234");
1110 c.update("56789");
1111 try testing.expectEqual(crc_24_flexray_b.check, c.final());
1112}
1113
1114const crc_24_interlaken: Algorithm(u24) = .{ .poly = 0x328b63, .init = 0xffffff, .refin = false, .refout = false, .xorout = 0xffffff, .check = 0xb4f3e6, .residue = 0x144e63 };
1115
1116pub const Crc24Interlaken = Crc(u24, crc_24_interlaken);
1117
1118test "CRC-24/INTERLAKEN" {
1119 try testing.expectEqual(crc_24_interlaken.check, Crc24Interlaken.hash("123456789"));
1120
1121 var c = Crc24Interlaken.init();
1122 c.update("1234");
1123 c.update("56789");
1124 try testing.expectEqual(crc_24_interlaken.check, c.final());
1125}
1126
1127const crc_24_lte_a: Algorithm(u24) = .{ .poly = 0x864cfb, .init = 0x000000, .refin = false, .refout = false, .xorout = 0x000000, .check = 0xcde703, .residue = 0x000000 };
1128
1129pub const Crc24LteA = Crc(u24, crc_24_lte_a);
1130
1131test "CRC-24/LTE-A" {
1132 try testing.expectEqual(crc_24_lte_a.check, Crc24LteA.hash("123456789"));
1133
1134 var c = Crc24LteA.init();
1135 c.update("1234");
1136 c.update("56789");
1137 try testing.expectEqual(crc_24_lte_a.check, c.final());
1138}
1139
1140const crc_24_lte_b: Algorithm(u24) = .{ .poly = 0x800063, .init = 0x000000, .refin = false, .refout = false, .xorout = 0x000000, .check = 0x23ef52, .residue = 0x000000 };
1141
1142pub const Crc24LteB = Crc(u24, crc_24_lte_b);
1143
1144test "CRC-24/LTE-B" {
1145 try testing.expectEqual(crc_24_lte_b.check, Crc24LteB.hash("123456789"));
1146
1147 var c = Crc24LteB.init();
1148 c.update("1234");
1149 c.update("56789");
1150 try testing.expectEqual(crc_24_lte_b.check, c.final());
1151}
1152
1153const crc_24_openpgp: Algorithm(u24) = .{ .poly = 0x864cfb, .init = 0xb704ce, .refin = false, .refout = false, .xorout = 0x000000, .check = 0x21cf02, .residue = 0x000000 };
1154
1155pub const Crc24Openpgp = Crc(u24, crc_24_openpgp);
1156
1157test "CRC-24/OPENPGP" {
1158 try testing.expectEqual(crc_24_openpgp.check, Crc24Openpgp.hash("123456789"));
1159
1160 var c = Crc24Openpgp.init();
1161 c.update("1234");
1162 c.update("56789");
1163 try testing.expectEqual(crc_24_openpgp.check, c.final());
1164}
1165
1166const crc_24_os_9: Algorithm(u24) = .{ .poly = 0x800063, .init = 0xffffff, .refin = false, .refout = false, .xorout = 0xffffff, .check = 0x200fa5, .residue = 0x800fe3 };
1167
1168pub const Crc24Os9 = Crc(u24, crc_24_os_9);
1169
1170test "CRC-24/OS-9" {
1171 try testing.expectEqual(crc_24_os_9.check, Crc24Os9.hash("123456789"));
1172
1173 var c = Crc24Os9.init();
1174 c.update("1234");
1175 c.update("56789");
1176 try testing.expectEqual(crc_24_os_9.check, c.final());
1177}
1178
1179const crc_30_cdma: Algorithm(u30) = .{ .poly = 0x2030b9c7, .init = 0x3fffffff, .refin = false, .refout = false, .xorout = 0x3fffffff, .check = 0x04c34abf, .residue = 0x34efa55a };
1180
1181pub const Crc30Cdma = Crc(u30, crc_30_cdma);
1182
1183test "CRC-30/CDMA" {
1184 try testing.expectEqual(crc_30_cdma.check, Crc30Cdma.hash("123456789"));
1185
1186 var c = Crc30Cdma.init();
1187 c.update("1234");
1188 c.update("56789");
1189 try testing.expectEqual(crc_30_cdma.check, c.final());
1190}
1191
1192const crc_31_philips: Algorithm(u31) = .{ .poly = 0x04c11db7, .init = 0x7fffffff, .refin = false, .refout = false, .xorout = 0x7fffffff, .check = 0x0ce9e46c, .residue = 0x4eaf26f1 };
1193
1194pub const Crc31Philips = Crc(u31, crc_31_philips);
1195
1196test "CRC-31/PHILIPS" {
1197 try testing.expectEqual(crc_31_philips.check, Crc31Philips.hash("123456789"));
1198
1199 var c = Crc31Philips.init();
1200 c.update("1234");
1201 c.update("56789");
1202 try testing.expectEqual(crc_31_philips.check, c.final());
1203}
1204
1205const crc_32_aixm: Algorithm(u32) = .{ .poly = 0x814141ab, .init = 0x00000000, .refin = false, .refout = false, .xorout = 0x00000000, .check = 0x3010bf7f, .residue = 0x00000000 };
1206
1207pub const Crc32Aixm = Crc(u32, crc_32_aixm);
1208
1209test "CRC-32/AIXM" {
1210 try testing.expectEqual(crc_32_aixm.check, Crc32Aixm.hash("123456789"));
1211
1212 var c = Crc32Aixm.init();
1213 c.update("1234");
1214 c.update("56789");
1215 try testing.expectEqual(crc_32_aixm.check, c.final());
1216}
1217
1218const crc_32_autosar: Algorithm(u32) = .{ .poly = 0xf4acfb13, .init = 0xffffffff, .refin = true, .refout = true, .xorout = 0xffffffff, .check = 0x1697d06a, .residue = 0x904cddbf };
1219
1220pub const Crc32Autosar = Crc(u32, crc_32_autosar);
1221
1222test "CRC-32/AUTOSAR" {
1223 try testing.expectEqual(crc_32_autosar.check, Crc32Autosar.hash("123456789"));
1224
1225 var c = Crc32Autosar.init();
1226 c.update("1234");
1227 c.update("56789");
1228 try testing.expectEqual(crc_32_autosar.check, c.final());
1229}
1230
1231const crc_32_base91_d: Algorithm(u32) = .{ .poly = 0xa833982b, .init = 0xffffffff, .refin = true, .refout = true, .xorout = 0xffffffff, .check = 0x87315576, .residue = 0x45270551 };
1232
1233pub const Crc32Base91D = Crc(u32, crc_32_base91_d);
1234
1235test "CRC-32/BASE91-D" {
1236 try testing.expectEqual(crc_32_base91_d.check, Crc32Base91D.hash("123456789"));
1237
1238 var c = Crc32Base91D.init();
1239 c.update("1234");
1240 c.update("56789");
1241 try testing.expectEqual(crc_32_base91_d.check, c.final());
1242}
1243
1244const crc_32_bzip2: Algorithm(u32) = .{ .poly = 0x04c11db7, .init = 0xffffffff, .refin = false, .refout = false, .xorout = 0xffffffff, .check = 0xfc891918, .residue = 0xc704dd7b };
1245
1246pub const Crc32Bzip2 = Crc(u32, crc_32_bzip2);
1247
1248test "CRC-32/BZIP2" {
1249 try testing.expectEqual(crc_32_bzip2.check, Crc32Bzip2.hash("123456789"));
1250
1251 var c = Crc32Bzip2.init();
1252 c.update("1234");
1253 c.update("56789");
1254 try testing.expectEqual(crc_32_bzip2.check, c.final());
1255}
1256
1257const crc_32_cd_rom_edc: Algorithm(u32) = .{ .poly = 0x8001801b, .init = 0x00000000, .refin = true, .refout = true, .xorout = 0x00000000, .check = 0x6ec2edc4, .residue = 0x00000000 };
1258
1259pub const Crc32CdRomEdc = Crc(u32, crc_32_cd_rom_edc);
1260
1261test "CRC-32/CD-ROM-EDC" {
1262 try testing.expectEqual(crc_32_cd_rom_edc.check, Crc32CdRomEdc.hash("123456789"));
1263
1264 var c = Crc32CdRomEdc.init();
1265 c.update("1234");
1266 c.update("56789");
1267 try testing.expectEqual(crc_32_cd_rom_edc.check, c.final());
1268}
1269
1270const crc_32_cksum: Algorithm(u32) = .{ .poly = 0x04c11db7, .init = 0x00000000, .refin = false, .refout = false, .xorout = 0xffffffff, .check = 0x765e7680, .residue = 0xc704dd7b };
1271
1272pub const Crc32Cksum = Crc(u32, crc_32_cksum);
1273
1274test "CRC-32/CKSUM" {
1275 try testing.expectEqual(crc_32_cksum.check, Crc32Cksum.hash("123456789"));
1276
1277 var c = Crc32Cksum.init();
1278 c.update("1234");
1279 c.update("56789");
1280 try testing.expectEqual(crc_32_cksum.check, c.final());
1281}
1282
1283const crc_32_iscsi: Algorithm(u32) = .{ .poly = 0x1edc6f41, .init = 0xffffffff, .refin = true, .refout = true, .xorout = 0xffffffff, .check = 0xe3069283, .residue = 0xb798b438 };
1284
1285pub const Crc32Iscsi = Crc(u32, crc_32_iscsi);
1286
1287test "CRC-32/ISCSI" {
1288 try testing.expectEqual(crc_32_iscsi.check, Crc32Iscsi.hash("123456789"));
1289
1290 var c = Crc32Iscsi.init();
1291 c.update("1234");
1292 c.update("56789");
1293 try testing.expectEqual(crc_32_iscsi.check, c.final());
1294}
1295
1296const crc_32_iso_hdlc: Algorithm(u32) = .{ .poly = 0x04c11db7, .init = 0xffffffff, .refin = true, .refout = true, .xorout = 0xffffffff, .check = 0xcbf43926, .residue = 0xdebb20e3 };
1297
1298pub const Crc32IsoHdlc = Crc(u32, crc_32_iso_hdlc);
1299
1300test "CRC-32/ISO-HDLC" {
1301 try testing.expectEqual(crc_32_iso_hdlc.check, Crc32IsoHdlc.hash("123456789"));
1302
1303 var c = Crc32IsoHdlc.init();
1304 c.update("1234");
1305 c.update("56789");
1306 try testing.expectEqual(crc_32_iso_hdlc.check, c.final());
1307}
1308
1309const crc_32_jamcrc: Algorithm(u32) = .{ .poly = 0x04c11db7, .init = 0xffffffff, .refin = true, .refout = true, .xorout = 0x00000000, .check = 0x340bc6d9, .residue = 0x00000000 };
1310
1311pub const Crc32Jamcrc = Crc(u32, crc_32_jamcrc);
1312
1313test "CRC-32/JAMCRC" {
1314 try testing.expectEqual(crc_32_jamcrc.check, Crc32Jamcrc.hash("123456789"));
1315
1316 var c = Crc32Jamcrc.init();
1317 c.update("1234");
1318 c.update("56789");
1319 try testing.expectEqual(crc_32_jamcrc.check, c.final());
1320}
1321
1322const crc_32_mef: Algorithm(u32) = .{ .poly = 0x741b8cd7, .init = 0xffffffff, .refin = true, .refout = true, .xorout = 0x00000000, .check = 0xd2c22f51, .residue = 0x00000000 };
1323
1324pub const Crc32Mef = Crc(u32, crc_32_mef);
1325
1326test "CRC-32/MEF" {
1327 try testing.expectEqual(crc_32_mef.check, Crc32Mef.hash("123456789"));
1328
1329 var c = Crc32Mef.init();
1330 c.update("1234");
1331 c.update("56789");
1332 try testing.expectEqual(crc_32_mef.check, c.final());
1333}
1334
1335const crc_32_mpeg_2: Algorithm(u32) = .{ .poly = 0x04c11db7, .init = 0xffffffff, .refin = false, .refout = false, .xorout = 0x00000000, .check = 0x0376e6e7, .residue = 0x00000000 };
1336
1337pub const Crc32Mpeg2 = Crc(u32, crc_32_mpeg_2);
1338
1339test "CRC-32/MPEG-2" {
1340 try testing.expectEqual(crc_32_mpeg_2.check, Crc32Mpeg2.hash("123456789"));
1341
1342 var c = Crc32Mpeg2.init();
1343 c.update("1234");
1344 c.update("56789");
1345 try testing.expectEqual(crc_32_mpeg_2.check, c.final());
1346}
1347
1348const crc_32_xfer: Algorithm(u32) = .{ .poly = 0x000000af, .init = 0x00000000, .refin = false, .refout = false, .xorout = 0x00000000, .check = 0xbd0be338, .residue = 0x00000000 };
1349
1350pub const Crc32Xfer = Crc(u32, crc_32_xfer);
1351
1352test "CRC-32/XFER" {
1353 try testing.expectEqual(crc_32_xfer.check, Crc32Xfer.hash("123456789"));
1354
1355 var c = Crc32Xfer.init();
1356 c.update("1234");
1357 c.update("56789");
1358 try testing.expectEqual(crc_32_xfer.check, c.final());
1359}
1360
1361const crc_40_gsm: Algorithm(u40) = .{ .poly = 0x0004820009, .init = 0x0000000000, .refin = false, .refout = false, .xorout = 0xffffffffff, .check = 0xd4164fc646, .residue = 0xc4ff8071ff };
1362
1363pub const Crc40Gsm = Crc(u40, crc_40_gsm);
1364
1365test "CRC-40/GSM" {
1366 try testing.expectEqual(crc_40_gsm.check, Crc40Gsm.hash("123456789"));
1367
1368 var c = Crc40Gsm.init();
1369 c.update("1234");
1370 c.update("56789");
1371 try testing.expectEqual(crc_40_gsm.check, c.final());
1372}
1373
1374const crc_64_ecma_182: Algorithm(u64) = .{ .poly = 0x42f0e1eba9ea3693, .init = 0x0000000000000000, .refin = false, .refout = false, .xorout = 0x0000000000000000, .check = 0x6c40df5f0b497347, .residue = 0x0000000000000000 };
1375
1376pub const Crc64Ecma182 = Crc(u64, crc_64_ecma_182);
1377
1378test "CRC-64/ECMA-182" {
1379 try testing.expectEqual(crc_64_ecma_182.check, Crc64Ecma182.hash("123456789"));
1380
1381 var c = Crc64Ecma182.init();
1382 c.update("1234");
1383 c.update("56789");
1384 try testing.expectEqual(crc_64_ecma_182.check, c.final());
1385}
1386
1387const crc_64_go_iso: Algorithm(u64) = .{ .poly = 0x000000000000001b, .init = 0xffffffffffffffff, .refin = true, .refout = true, .xorout = 0xffffffffffffffff, .check = 0xb90956c775a41001, .residue = 0x5300000000000000 };
1388
1389pub const Crc64GoIso = Crc(u64, crc_64_go_iso);
1390
1391test "CRC-64/GO-ISO" {
1392 try testing.expectEqual(crc_64_go_iso.check, Crc64GoIso.hash("123456789"));
1393
1394 var c = Crc64GoIso.init();
1395 c.update("1234");
1396 c.update("56789");
1397 try testing.expectEqual(crc_64_go_iso.check, c.final());
1398}
1399
1400const crc_64_ms: Algorithm(u64) = .{ .poly = 0x259c84cba6426349, .init = 0xffffffffffffffff, .refin = true, .refout = true, .xorout = 0x0000000000000000, .check = 0x75d4b74f024eceea, .residue = 0x0000000000000000 };
1401
1402pub const Crc64Ms = Crc(u64, crc_64_ms);
1403
1404test "CRC-64/MS" {
1405 try testing.expectEqual(crc_64_ms.check, Crc64Ms.hash("123456789"));
1406
1407 var c = Crc64Ms.init();
1408 c.update("1234");
1409 c.update("56789");
1410 try testing.expectEqual(crc_64_ms.check, c.final());
1411}
1412
1413const crc_64_redis: Algorithm(u64) = .{ .poly = 0xad93d23594c935a9, .init = 0x0000000000000000, .refin = true, .refout = true, .xorout = 0x0000000000000000, .check = 0xe9c6d914c4b8d9ca, .residue = 0x0000000000000000 };
1414
1415pub const Crc64Redis = Crc(u64, crc_64_redis);
1416
1417test "CRC-64/REDIS" {
1418 try testing.expectEqual(crc_64_redis.check, Crc64Redis.hash("123456789"));
1419
1420 var c = Crc64Redis.init();
1421 c.update("1234");
1422 c.update("56789");
1423 try testing.expectEqual(crc_64_redis.check, c.final());
1424}
1425
1426const crc_64_we: Algorithm(u64) = .{ .poly = 0x42f0e1eba9ea3693, .init = 0xffffffffffffffff, .refin = false, .refout = false, .xorout = 0xffffffffffffffff, .check = 0x62ec59e3f1a4f00a, .residue = 0xfcacbebd5931a992 };
1427
1428pub const Crc64We = Crc(u64, crc_64_we);
1429
1430test "CRC-64/WE" {
1431 try testing.expectEqual(crc_64_we.check, Crc64We.hash("123456789"));
1432
1433 var c = Crc64We.init();
1434 c.update("1234");
1435 c.update("56789");
1436 try testing.expectEqual(crc_64_we.check, c.final());
1437}
1438
1439const crc_64_xz: Algorithm(u64) = .{ .poly = 0x42f0e1eba9ea3693, .init = 0xffffffffffffffff, .refin = true, .refout = true, .xorout = 0xffffffffffffffff, .check = 0x995dc9bbdf1939fa, .residue = 0x49958c9abd7d353f };
1440
1441pub const Crc64Xz = Crc(u64, crc_64_xz);
1442
1443test "CRC-64/XZ" {
1444 try testing.expectEqual(crc_64_xz.check, Crc64Xz.hash("123456789"));
1445
1446 var c = Crc64Xz.init();
1447 c.update("1234");
1448 c.update("56789");
1449 try testing.expectEqual(crc_64_xz.check, c.final());
1450}
1451
1452const crc_82_darc: Algorithm(u82) = .{ .poly = 0x0308c0111011401440411, .init = 0x000000000000000000000, .refin = true, .refout = true, .xorout = 0x000000000000000000000, .check = 0x09ea83f625023801fd612, .residue = 0x000000000000000000000 };
1453
1454pub const Crc82Darc = Crc(u82, crc_82_darc);
1455
1456test "CRC-82/DARC" {
1457 try testing.expectEqual(crc_82_darc.check, Crc82Darc.hash("123456789"));
1458
1459 var c = Crc82Darc.init();
1460 c.update("1234");
1461 c.update("56789");
1462 try testing.expectEqual(crc_82_darc.check, c.final());
1463}
lib/std/hash/crc/catalog_test.zig created+1237
...@@ -0,0 +1,1237 @@
1//! This file is auto-generated by tools/update_crc_catalog.zig.
2
3const std = @import("../../std.zig");
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}
tools/crc/catalog.txt created+113
...@@ -0,0 +1,113 @@
1# https://reveng.sourceforge.io/crc-catalogue/all.htm
2width=3 poly=0x3 init=0x0 refin=false refout=false xorout=0x7 check=0x4 residue=0x2 name="CRC-3/GSM"
3width=3 poly=0x3 init=0x7 refin=true refout=true xorout=0x0 check=0x6 residue=0x0 name="CRC-3/ROHC"
4width=4 poly=0x3 init=0x0 refin=true refout=true xorout=0x0 check=0x7 residue=0x0 name="CRC-4/G-704"
5width=4 poly=0x3 init=0xf refin=false refout=false xorout=0xf check=0xb residue=0x2 name="CRC-4/INTERLAKEN"
6width=5 poly=0x09 init=0x09 refin=false refout=false xorout=0x00 check=0x00 residue=0x00 name="CRC-5/EPC-C1G2"
7width=5 poly=0x15 init=0x00 refin=true refout=true xorout=0x00 check=0x07 residue=0x00 name="CRC-5/G-704"
8width=5 poly=0x05 init=0x1f refin=true refout=true xorout=0x1f check=0x19 residue=0x06 name="CRC-5/USB"
9width=6 poly=0x27 init=0x3f refin=false refout=false xorout=0x00 check=0x0d residue=0x00 name="CRC-6/CDMA2000-A"
10width=6 poly=0x07 init=0x3f refin=false refout=false xorout=0x00 check=0x3b residue=0x00 name="CRC-6/CDMA2000-B"
11width=6 poly=0x19 init=0x00 refin=true refout=true xorout=0x00 check=0x26 residue=0x00 name="CRC-6/DARC"
12width=6 poly=0x03 init=0x00 refin=true refout=true xorout=0x00 check=0x06 residue=0x00 name="CRC-6/G-704"
13width=6 poly=0x2f init=0x00 refin=false refout=false xorout=0x3f check=0x13 residue=0x3a name="CRC-6/GSM"
14width=7 poly=0x09 init=0x00 refin=false refout=false xorout=0x00 check=0x75 residue=0x00 name="CRC-7/MMC"
15width=7 poly=0x4f init=0x7f refin=true refout=true xorout=0x00 check=0x53 residue=0x00 name="CRC-7/ROHC"
16width=7 poly=0x45 init=0x00 refin=false refout=false xorout=0x00 check=0x61 residue=0x00 name="CRC-7/UMTS"
17width=8 poly=0x2f init=0xff refin=false refout=false xorout=0xff check=0xdf residue=0x42 name="CRC-8/AUTOSAR"
18width=8 poly=0xa7 init=0x00 refin=true refout=true xorout=0x00 check=0x26 residue=0x00 name="CRC-8/BLUETOOTH"
19width=8 poly=0x9b init=0xff refin=false refout=false xorout=0x00 check=0xda residue=0x00 name="CRC-8/CDMA2000"
20width=8 poly=0x39 init=0x00 refin=true refout=true xorout=0x00 check=0x15 residue=0x00 name="CRC-8/DARC"
21width=8 poly=0xd5 init=0x00 refin=false refout=false xorout=0x00 check=0xbc residue=0x00 name="CRC-8/DVB-S2"
22width=8 poly=0x1d init=0x00 refin=false refout=false xorout=0x00 check=0x37 residue=0x00 name="CRC-8/GSM-A"
23width=8 poly=0x49 init=0x00 refin=false refout=false xorout=0xff check=0x94 residue=0x53 name="CRC-8/GSM-B"
24width=8 poly=0x1d init=0xff refin=false refout=false xorout=0x00 check=0xb4 residue=0x00 name="CRC-8/HITAG"
25width=8 poly=0x07 init=0x00 refin=false refout=false xorout=0x55 check=0xa1 residue=0xac name="CRC-8/I-432-1"
26width=8 poly=0x1d init=0xfd refin=false refout=false xorout=0x00 check=0x7e residue=0x00 name="CRC-8/I-CODE"
27width=8 poly=0x9b init=0x00 refin=false refout=false xorout=0x00 check=0xea residue=0x00 name="CRC-8/LTE"
28width=8 poly=0x31 init=0x00 refin=true refout=true xorout=0x00 check=0xa1 residue=0x00 name="CRC-8/MAXIM-DOW"
29width=8 poly=0x1d init=0xc7 refin=false refout=false xorout=0x00 check=0x99 residue=0x00 name="CRC-8/MIFARE-MAD"
30width=8 poly=0x31 init=0xff refin=false refout=false xorout=0x00 check=0xf7 residue=0x00 name="CRC-8/NRSC-5"
31width=8 poly=0x2f init=0x00 refin=false refout=false xorout=0x00 check=0x3e residue=0x00 name="CRC-8/OPENSAFETY"
32width=8 poly=0x07 init=0xff refin=true refout=true xorout=0x00 check=0xd0 residue=0x00 name="CRC-8/ROHC"
33width=8 poly=0x1d init=0xff refin=false refout=false xorout=0xff check=0x4b residue=0xc4 name="CRC-8/SAE-J1850"
34width=8 poly=0x07 init=0x00 refin=false refout=false xorout=0x00 check=0xf4 residue=0x00 name="CRC-8/SMBUS"
35width=8 poly=0x1d init=0xff refin=true refout=true xorout=0x00 check=0x97 residue=0x00 name="CRC-8/TECH-3250"
36width=8 poly=0x9b init=0x00 refin=true refout=true xorout=0x00 check=0x25 residue=0x00 name="CRC-8/WCDMA"
37width=10 poly=0x233 init=0x000 refin=false refout=false xorout=0x000 check=0x199 residue=0x000 name="CRC-10/ATM"
38width=10 poly=0x3d9 init=0x3ff refin=false refout=false xorout=0x000 check=0x233 residue=0x000 name="CRC-10/CDMA2000"
39width=10 poly=0x175 init=0x000 refin=false refout=false xorout=0x3ff check=0x12a residue=0x0c6 name="CRC-10/GSM"
40width=11 poly=0x385 init=0x01a refin=false refout=false xorout=0x000 check=0x5a3 residue=0x000 name="CRC-11/FLEXRAY"
41width=11 poly=0x307 init=0x000 refin=false refout=false xorout=0x000 check=0x061 residue=0x000 name="CRC-11/UMTS"
42width=12 poly=0xf13 init=0xfff refin=false refout=false xorout=0x000 check=0xd4d residue=0x000 name="CRC-12/CDMA2000"
43width=12 poly=0x80f init=0x000 refin=false refout=false xorout=0x000 check=0xf5b residue=0x000 name="CRC-12/DECT"
44width=12 poly=0xd31 init=0x000 refin=false refout=false xorout=0xfff check=0xb34 residue=0x178 name="CRC-12/GSM"
45width=12 poly=0x80f init=0x000 refin=false refout=true xorout=0x000 check=0xdaf residue=0x000 name="CRC-12/UMTS"
46width=13 poly=0x1cf5 init=0x0000 refin=false refout=false xorout=0x0000 check=0x04fa residue=0x0000 name="CRC-13/BBC"
47width=14 poly=0x0805 init=0x0000 refin=true refout=true xorout=0x0000 check=0x082d residue=0x0000 name="CRC-14/DARC"
48width=14 poly=0x202d init=0x0000 refin=false refout=false xorout=0x3fff check=0x30ae residue=0x031e name="CRC-14/GSM"
49width=15 poly=0x4599 init=0x0000 refin=false refout=false xorout=0x0000 check=0x059e residue=0x0000 name="CRC-15/CAN"
50width=15 poly=0x6815 init=0x0000 refin=false refout=false xorout=0x0001 check=0x2566 residue=0x6815 name="CRC-15/MPT1327"
51width=16 poly=0x8005 init=0x0000 refin=true refout=true xorout=0x0000 check=0xbb3d residue=0x0000 name="CRC-16/ARC"
52width=16 poly=0xc867 init=0xffff refin=false refout=false xorout=0x0000 check=0x4c06 residue=0x0000 name="CRC-16/CDMA2000"
53width=16 poly=0x8005 init=0xffff refin=false refout=false xorout=0x0000 check=0xaee7 residue=0x0000 name="CRC-16/CMS"
54width=16 poly=0x8005 init=0x800d refin=false refout=false xorout=0x0000 check=0x9ecf residue=0x0000 name="CRC-16/DDS-110"
55width=16 poly=0x0589 init=0x0000 refin=false refout=false xorout=0x0001 check=0x007e residue=0x0589 name="CRC-16/DECT-R"
56width=16 poly=0x0589 init=0x0000 refin=false refout=false xorout=0x0000 check=0x007f residue=0x0000 name="CRC-16/DECT-X"
57width=16 poly=0x3d65 init=0x0000 refin=true refout=true xorout=0xffff check=0xea82 residue=0x66c5 name="CRC-16/DNP"
58width=16 poly=0x3d65 init=0x0000 refin=false refout=false xorout=0xffff check=0xc2b7 residue=0xa366 name="CRC-16/EN-13757"
59width=16 poly=0x1021 init=0xffff refin=false refout=false xorout=0xffff check=0xd64e residue=0x1d0f name="CRC-16/GENIBUS"
60width=16 poly=0x1021 init=0x0000 refin=false refout=false xorout=0xffff check=0xce3c residue=0x1d0f name="CRC-16/GSM"
61width=16 poly=0x1021 init=0xffff refin=false refout=false xorout=0x0000 check=0x29b1 residue=0x0000 name="CRC-16/IBM-3740"
62width=16 poly=0x1021 init=0xffff refin=true refout=true xorout=0xffff check=0x906e residue=0xf0b8 name="CRC-16/IBM-SDLC"
63width=16 poly=0x1021 init=0xc6c6 refin=true refout=true xorout=0x0000 check=0xbf05 residue=0x0000 name="CRC-16/ISO-IEC-14443-3-A"
64width=16 poly=0x1021 init=0x0000 refin=true refout=true xorout=0x0000 check=0x2189 residue=0x0000 name="CRC-16/KERMIT"
65width=16 poly=0x6f63 init=0x0000 refin=false refout=false xorout=0x0000 check=0xbdf4 residue=0x0000 name="CRC-16/LJ1200"
66width=16 poly=0x5935 init=0xffff refin=false refout=false xorout=0x0000 check=0x772b residue=0x0000 name="CRC-16/M17"
67width=16 poly=0x8005 init=0x0000 refin=true refout=true xorout=0xffff check=0x44c2 residue=0xb001 name="CRC-16/MAXIM-DOW"
68width=16 poly=0x1021 init=0xffff refin=true refout=true xorout=0x0000 check=0x6f91 residue=0x0000 name="CRC-16/MCRF4XX"
69width=16 poly=0x8005 init=0xffff refin=true refout=true xorout=0x0000 check=0x4b37 residue=0x0000 name="CRC-16/MODBUS"
70width=16 poly=0x080b init=0xffff refin=true refout=true xorout=0x0000 check=0xa066 residue=0x0000 name="CRC-16/NRSC-5"
71width=16 poly=0x5935 init=0x0000 refin=false refout=false xorout=0x0000 check=0x5d38 residue=0x0000 name="CRC-16/OPENSAFETY-A"
72width=16 poly=0x755b init=0x0000 refin=false refout=false xorout=0x0000 check=0x20fe residue=0x0000 name="CRC-16/OPENSAFETY-B"
73width=16 poly=0x1dcf init=0xffff refin=false refout=false xorout=0xffff check=0xa819 residue=0xe394 name="CRC-16/PROFIBUS"
74width=16 poly=0x1021 init=0xb2aa refin=true refout=true xorout=0x0000 check=0x63d0 residue=0x0000 name="CRC-16/RIELLO"
75width=16 poly=0x1021 init=0x1d0f refin=false refout=false xorout=0x0000 check=0xe5cc residue=0x0000 name="CRC-16/SPI-FUJITSU"
76width=16 poly=0x8bb7 init=0x0000 refin=false refout=false xorout=0x0000 check=0xd0db residue=0x0000 name="CRC-16/T10-DIF"
77width=16 poly=0xa097 init=0x0000 refin=false refout=false xorout=0x0000 check=0x0fb3 residue=0x0000 name="CRC-16/TELEDISK"
78width=16 poly=0x1021 init=0x89ec refin=true refout=true xorout=0x0000 check=0x26b1 residue=0x0000 name="CRC-16/TMS37157"
79width=16 poly=0x8005 init=0x0000 refin=false refout=false xorout=0x0000 check=0xfee8 residue=0x0000 name="CRC-16/UMTS"
80width=16 poly=0x8005 init=0xffff refin=true refout=true xorout=0xffff check=0xb4c8 residue=0xb001 name="CRC-16/USB"
81width=16 poly=0x1021 init=0x0000 refin=false refout=false xorout=0x0000 check=0x31c3 residue=0x0000 name="CRC-16/XMODEM"
82width=17 poly=0x1685b init=0x00000 refin=false refout=false xorout=0x00000 check=0x04f03 residue=0x00000 name="CRC-17/CAN-FD"
83width=21 poly=0x102899 init=0x000000 refin=false refout=false xorout=0x000000 check=0x0ed841 residue=0x000000 name="CRC-21/CAN-FD"
84width=24 poly=0x00065b init=0x555555 refin=true refout=true xorout=0x000000 check=0xc25a56 residue=0x000000 name="CRC-24/BLE"
85width=24 poly=0x5d6dcb init=0xfedcba refin=false refout=false xorout=0x000000 check=0x7979bd residue=0x000000 name="CRC-24/FLEXRAY-A"
86width=24 poly=0x5d6dcb init=0xabcdef refin=false refout=false xorout=0x000000 check=0x1f23b8 residue=0x000000 name="CRC-24/FLEXRAY-B"
87width=24 poly=0x328b63 init=0xffffff refin=false refout=false xorout=0xffffff check=0xb4f3e6 residue=0x144e63 name="CRC-24/INTERLAKEN"
88width=24 poly=0x864cfb init=0x000000 refin=false refout=false xorout=0x000000 check=0xcde703 residue=0x000000 name="CRC-24/LTE-A"
89width=24 poly=0x800063 init=0x000000 refin=false refout=false xorout=0x000000 check=0x23ef52 residue=0x000000 name="CRC-24/LTE-B"
90width=24 poly=0x864cfb init=0xb704ce refin=false refout=false xorout=0x000000 check=0x21cf02 residue=0x000000 name="CRC-24/OPENPGP"
91width=24 poly=0x800063 init=0xffffff refin=false refout=false xorout=0xffffff check=0x200fa5 residue=0x800fe3 name="CRC-24/OS-9"
92width=30 poly=0x2030b9c7 init=0x3fffffff refin=false refout=false xorout=0x3fffffff check=0x04c34abf residue=0x34efa55a name="CRC-30/CDMA"
93width=31 poly=0x04c11db7 init=0x7fffffff refin=false refout=false xorout=0x7fffffff check=0x0ce9e46c residue=0x4eaf26f1 name="CRC-31/PHILIPS"
94width=32 poly=0x814141ab init=0x00000000 refin=false refout=false xorout=0x00000000 check=0x3010bf7f residue=0x00000000 name="CRC-32/AIXM"
95width=32 poly=0xf4acfb13 init=0xffffffff refin=true refout=true xorout=0xffffffff check=0x1697d06a residue=0x904cddbf name="CRC-32/AUTOSAR"
96width=32 poly=0xa833982b init=0xffffffff refin=true refout=true xorout=0xffffffff check=0x87315576 residue=0x45270551 name="CRC-32/BASE91-D"
97width=32 poly=0x04c11db7 init=0xffffffff refin=false refout=false xorout=0xffffffff check=0xfc891918 residue=0xc704dd7b name="CRC-32/BZIP2"
98width=32 poly=0x8001801b init=0x00000000 refin=true refout=true xorout=0x00000000 check=0x6ec2edc4 residue=0x00000000 name="CRC-32/CD-ROM-EDC"
99width=32 poly=0x04c11db7 init=0x00000000 refin=false refout=false xorout=0xffffffff check=0x765e7680 residue=0xc704dd7b name="CRC-32/CKSUM"
100width=32 poly=0x1edc6f41 init=0xffffffff refin=true refout=true xorout=0xffffffff check=0xe3069283 residue=0xb798b438 name="CRC-32/ISCSI"
101width=32 poly=0x04c11db7 init=0xffffffff refin=true refout=true xorout=0xffffffff check=0xcbf43926 residue=0xdebb20e3 name="CRC-32/ISO-HDLC"
102width=32 poly=0x04c11db7 init=0xffffffff refin=true refout=true xorout=0x00000000 check=0x340bc6d9 residue=0x00000000 name="CRC-32/JAMCRC"
103width=32 poly=0x741b8cd7 init=0xffffffff refin=true refout=true xorout=0x00000000 check=0xd2c22f51 residue=0x00000000 name="CRC-32/MEF"
104width=32 poly=0x04c11db7 init=0xffffffff refin=false refout=false xorout=0x00000000 check=0x0376e6e7 residue=0x00000000 name="CRC-32/MPEG-2"
105width=32 poly=0x000000af init=0x00000000 refin=false refout=false xorout=0x00000000 check=0xbd0be338 residue=0x00000000 name="CRC-32/XFER"
106width=40 poly=0x0004820009 init=0x0000000000 refin=false refout=false xorout=0xffffffffff check=0xd4164fc646 residue=0xc4ff8071ff name="CRC-40/GSM"
107width=64 poly=0x42f0e1eba9ea3693 init=0x0000000000000000 refin=false refout=false xorout=0x0000000000000000 check=0x6c40df5f0b497347 residue=0x0000000000000000 name="CRC-64/ECMA-182"
108width=64 poly=0x000000000000001b init=0xffffffffffffffff refin=true refout=true xorout=0xffffffffffffffff check=0xb90956c775a41001 residue=0x5300000000000000 name="CRC-64/GO-ISO"
109width=64 poly=0x259c84cba6426349 init=0xffffffffffffffff refin=true refout=true xorout=0x0000000000000000 check=0x75d4b74f024eceea residue=0x0000000000000000 name="CRC-64/MS"
110width=64 poly=0xad93d23594c935a9 init=0x0000000000000000 refin=true refout=true xorout=0x0000000000000000 check=0xe9c6d914c4b8d9ca residue=0x0000000000000000 name="CRC-64/REDIS"
111width=64 poly=0x42f0e1eba9ea3693 init=0xffffffffffffffff refin=false refout=false xorout=0xffffffffffffffff check=0x62ec59e3f1a4f00a residue=0xfcacbebd5931a992 name="CRC-64/WE"
112width=64 poly=0x42f0e1eba9ea3693 init=0xffffffffffffffff refin=true refout=true xorout=0xffffffffffffffff check=0x995dc9bbdf1939fa residue=0x49958c9abd7d353f name="CRC-64/XZ"
113width=82 poly=0x0308c0111011401440411 init=0x000000000000000000000 refin=true refout=true xorout=0x000000000000000000000 check=0x09ea83f625023801fd612 residue=0x000000000000000000000 name="CRC-82/DARC"
tools/update_crc_catalog.sh deleted-40
...@@ -1,40 +0,0 @@
1if [ $# -lt 1 ]; then
2 echo "Usage: $0 /path/git/zig"
3 exit 1
4fi
5
6filepath=$1/lib/std/hash/crc/catalog.zig
7
8cat <<EOS >$filepath
9//! This file is auto-generated by tools/update_crc_catalog.sh.
10
11const std = @import("../../std.zig");
12const testing = std.testing;
13const crc = @import("../crc.zig");
14const Algorithm = crc.Algorithm;
15const Crc = crc.Crc;
16EOS
17
18curl -s https://reveng.sourceforge.io/crc-catalogue/all.htm | grep -o 'width.*name.*"' | while read -r line; do
19 width=$(echo $line | sed 's/width=\([0-9]*\) \(.*\) name="\(.*\)"/\1/')
20 params=$(echo $line | sed 's/width=\([0-9]*\) \(.*\) name="\(.*\)"/\2/' | sed 's/ /, ./g' | sed 's/=/ = /g')
21 name=$(echo $line | sed 's/width=\([0-9]*\) \(.*\) name="\(.*\)"/\3/')
22 snakecase=$(echo $name | sed 's/[-\/]/_/g' | tr '[:upper:]' '[:lower:]')
23 camelcase=$(echo $snakecase | perl -pe 's/(^|_)(\w)/\U$2/g')
24
25 cat <<EOS >>$filepath
26
27const $snakecase: Algorithm(u$width) = .{ .$params };
28
29pub const $camelcase = Crc(u$width, $snakecase);
30
31test "$name" {
32 try testing.expectEqual($snakecase.check, $camelcase.hash("123456789"));
33
34 var c = $camelcase.init();
35 c.update("1234");
36 c.update("56789");
37 try testing.expectEqual($snakecase.check, c.final());
38}
39EOS
40done
tools/update_crc_catalog.zig created+169
...@@ -0,0 +1,169 @@
1const std = @import("std");
2const fs = std.fs;
3const mem = std.mem;
4const ascii = std.ascii;
5
6const catalog_txt = @embedFile("crc/catalog.txt");
7
8pub fn main() anyerror!void {
9 var arena_state = std.heap.ArenaAllocator.init(std.heap.page_allocator);
10 defer arena_state.deinit();
11 const arena = arena_state.allocator();
12
13 const args = try std.process.argsAlloc(arena);
14 if (args.len <= 1) {
15 usageAndExit(std.io.getStdErr(), args[0], 1);
16 }
17
18 const zig_src_root = args[1];
19 if (mem.startsWith(u8, zig_src_root, "-")) {
20 usageAndExit(std.io.getStdErr(), args[0], 1);
21 }
22
23 var zig_src_dir = try fs.cwd().openDir(zig_src_root, .{});
24 defer zig_src_dir.close();
25
26 const target_sub_path = try fs.path.join(arena, &.{ "lib", "std", "hash", "crc" });
27 var target_dir = try zig_src_dir.makeOpenPath(target_sub_path, .{});
28 defer target_dir.close();
29
30 var zig_code_file = try target_dir.createFile("catalog.zig", .{});
31 defer zig_code_file.close();
32
33 var cbw = std.io.bufferedWriter(zig_code_file.writer());
34 defer cbw.flush() catch unreachable;
35 const code_writer = cbw.writer();
36
37 try code_writer.writeAll(
38 \\//! This file is auto-generated by tools/update_crc_catalog.zig.
39 \\
40 \\const Crc = @import("../crc.zig").Crc;
41 \\
42 \\test {
43 \\ _ = @import("catalog_test.zig");
44 \\}
45 \\
46 );
47
48 var zig_test_file = try target_dir.createFile("catalog_test.zig", .{});
49 defer zig_test_file.close();
50
51 var tbw = std.io.bufferedWriter(zig_test_file.writer());
52 defer tbw.flush() catch unreachable;
53 const test_writer = tbw.writer();
54
55 try test_writer.writeAll(
56 \\//! This file is auto-generated by tools/update_crc_catalog.zig.
57 \\
58 \\const std = @import("../../std.zig");
59 \\const testing = std.testing;
60 \\const catalog = @import("catalog.zig");
61 \\
62 );
63
64 var stream = std.io.fixedBufferStream(catalog_txt);
65 const reader = stream.reader();
66
67 while (try reader.readUntilDelimiterOrEofAlloc(arena, '\n', std.math.maxInt(usize))) |line| {
68 if (line.len == 0 or line[0] == '#')
69 continue;
70
71 var width: []const u8 = undefined;
72 var poly: []const u8 = undefined;
73 var init: []const u8 = undefined;
74 var refin: []const u8 = undefined;
75 var refout: []const u8 = undefined;
76 var xorout: []const u8 = undefined;
77 var check: []const u8 = undefined;
78 var residue: []const u8 = undefined;
79 var name: []const u8 = undefined;
80
81 var it = mem.split(u8, line, " ");
82 while (it.next()) |property| {
83 const i = mem.indexOf(u8, property, "=").?;
84 const key = property[0..i];
85 const value = property[i + 1 ..];
86 if (mem.eql(u8, key, "width")) {
87 width = value;
88 } else if (mem.eql(u8, key, "poly")) {
89 poly = value;
90 } else if (mem.eql(u8, key, "init")) {
91 init = value;
92 } else if (mem.eql(u8, key, "refin")) {
93 refin = value;
94 } else if (mem.eql(u8, key, "refout")) {
95 refout = value;
96 } else if (mem.eql(u8, key, "xorout")) {
97 xorout = value;
98 } else if (mem.eql(u8, key, "check")) {
99 check = value;
100 } else if (mem.eql(u8, key, "residue")) {
101 residue = value;
102 } else if (mem.eql(u8, key, "name")) {
103 name = mem.trim(u8, value, "\"");
104 } else {
105 unreachable;
106 }
107 }
108
109 const snakecase = try ascii.allocLowerString(arena, name);
110 defer arena.free(snakecase);
111
112 _ = mem.replace(u8, snakecase, "-", "_", snakecase);
113 _ = mem.replace(u8, snakecase, "/", "_", snakecase);
114
115 var buf = try std.ArrayList(u8).initCapacity(arena, snakecase.len);
116 defer buf.deinit();
117
118 var prev: u8 = 0;
119 for (snakecase) |c, i| {
120 if (c == '_') {
121 // do nothing
122 } else if (i == 0) {
123 buf.appendAssumeCapacity(ascii.toUpper(c));
124 } else if (prev == '_') {
125 buf.appendAssumeCapacity(ascii.toUpper(c));
126 } else {
127 buf.appendAssumeCapacity(c);
128 }
129 prev = c;
130 }
131
132 const camelcase = buf.items;
133
134 try code_writer.writeAll(try std.fmt.allocPrint(arena,
135 \\
136 \\pub const {s} = Crc(u{s}, .{{
137 \\ .polynomial = {s},
138 \\ .initial = {s},
139 \\ .reflect_input = {s},
140 \\ .reflect_output = {s},
141 \\ .xor_output = {s},
142 \\}});
143 \\
144 , .{ camelcase, width, poly, init, refin, refout, xorout }));
145
146 try test_writer.writeAll(try std.fmt.allocPrint(arena,
147 \\
148 \\test "{0s}" {{
149 \\ const {1s} = catalog.{1s};
150 \\
151 \\ try testing.expectEqual(@as(u{2s}, {3s}), {1s}.hash("123456789"));
152 \\
153 \\ var c = {1s}.init();
154 \\ c.update("1234");
155 \\ c.update("56789");
156 \\ try testing.expectEqual(@as(u{2s}, {3s}), c.final());
157 \\}}
158 \\
159 , .{ name, camelcase, width, check }));
160 }
161}
162
163fn usageAndExit(file: fs.File, arg0: []const u8, code: u8) noreturn {
164 file.writer().print(
165 \\Usage: {s} /path/git/zig
166 \\
167 , .{arg0}) catch std.process.exit(1);
168 std.process.exit(code);
169}