diff options
| author | fn ⌃ ⌥ <70830482+FnControlOption@users.noreply.github.com> | 2023-01-21 07:04:09 -0800 |
|---|---|---|
| committer | fn ⌃ ⌥ <70830482+FnControlOption@users.noreply.github.com> | 2023-01-21 07:04:09 -0800 |
| commit | be4468be371de34e90a86346b0f6da6f2d85bef4 (patch) | |
| tree | 8514e0141c6f3a06c3de37f24bbb1b8da531c1bc /lib/std | |
| parent | 38eebf3c4d68239e1d29118234a3165355a3a5fc (diff) | |
| download | zig-be4468be371de34e90a86346b0f6da6f2d85bef4.tar.gz zig-be4468be371de34e90a86346b0f6da6f2d85bef4.zip | |
std.hash.crc: implement algorithms listed in CRC RevEng catalog
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/hash/crc.zig | 98 | ||||
| -rw-r--r-- | lib/std/hash/crc/catalog.zig | 1463 |
2 files changed, 1561 insertions, 0 deletions
diff --git a/lib/std/hash/crc.zig b/lib/std/hash/crc.zig index ad2e0018c9..288ce2c8ca 100644 --- a/lib/std/hash/crc.zig +++ b/lib/std/hash/crc.zig @@ -10,6 +10,104 @@ const builtin = @import("builtin"); const debug = std.debug; const testing = std.testing; +pub usingnamespace @import("crc/catalog.zig"); + +pub fn Algorithm(comptime W: type) type { + return struct { + poly: W, + init: W, + refin: bool, + refout: bool, + xorout: W, + check: W, + residue: W, + }; +} + +pub fn Crc(comptime W: type, comptime algorithm: Algorithm(W)) type { + return struct { + const Self = @This(); + const I = if (@bitSizeOf(W) < 8) u8 else W; + const lookup_table = blk: { + @setEvalBranchQuota(2500); + + const poly = if (algorithm.refin) + @bitReverse(@as(I, algorithm.poly)) >> (@bitSizeOf(I) - @bitSizeOf(W)) + else + @as(I, algorithm.poly) << (@bitSizeOf(I) - @bitSizeOf(W)); + + var table: [256]I = undefined; + for (table) |*e, i| { + var crc: I = i; + if (algorithm.refin) { + var j: usize = 0; + while (j < 8) : (j += 1) { + crc = (crc >> 1) ^ ((crc & 1) * poly); + } + } else { + crc <<= @bitSizeOf(I) - 8; + var j: usize = 0; + while (j < 8) : (j += 1) { + crc = (crc << 1) ^ (((crc >> (@bitSizeOf(I) - 1)) & 1) * poly); + } + } + e.* = crc; + } + break :blk table; + }; + + crc: I, + + pub fn init() Self { + const initial = if (algorithm.refin) + @bitReverse(@as(I, algorithm.init)) >> (@bitSizeOf(I) - @bitSizeOf(W)) + else + @as(I, algorithm.init) << (@bitSizeOf(I) - @bitSizeOf(W)); + return Self{ .crc = initial }; + } + + inline fn tableEntry(index: I) I { + return lookup_table[@intCast(u8, index & 0xFF)]; + } + + pub fn update(self: *Self, bytes: []const u8) void { + var i: usize = 0; + if (@bitSizeOf(I) <= 8) { + while (i < bytes.len) : (i += 1) { + self.crc = tableEntry(self.crc ^ bytes[i]); + } + } else if (algorithm.refin) { + while (i < bytes.len) : (i += 1) { + const table_index = self.crc ^ bytes[i]; + self.crc = tableEntry(table_index) ^ (self.crc >> 8); + } + } else { + while (i < bytes.len) : (i += 1) { + const table_index = (self.crc >> (@bitSizeOf(I) - 8)) ^ bytes[i]; + self.crc = tableEntry(table_index) ^ (self.crc << 8); + } + } + } + + pub fn final(self: Self) W { + var c = self.crc; + if (algorithm.refin != algorithm.refout) { + c = @bitReverse(c); + } + if (!algorithm.refout) { + c >>= @bitSizeOf(I) - @bitSizeOf(W); + } + return @intCast(W, c ^ algorithm.xorout); + } + + pub fn hash(bytes: []const u8) W { + var c = Self.init(); + c.update(bytes); + return c.final(); + } + }; +} + pub const Polynomial = enum(u32) { IEEE = 0xedb88320, Castagnoli = 0x82f63b78, diff --git a/lib/std/hash/crc/catalog.zig b/lib/std/hash/crc/catalog.zig new file mode 100644 index 0000000000..a6e2e1c6f1 --- /dev/null +++ b/lib/std/hash/crc/catalog.zig @@ -0,0 +1,1463 @@ +//! This file is auto-generated by tools/update_crc_catalog.sh. + +const std = @import("../../std.zig"); +const testing = std.testing; +const crc = @import("../crc.zig"); +const Algorithm = crc.Algorithm; +const Crc = crc.Crc; + +const crc_3_gsm: Algorithm(u3) = .{ .poly = 0x3, .init = 0x0, .refin = false, .refout = false, .xorout = 0x7, .check = 0x4, .residue = 0x2 }; + +pub const Crc3Gsm = Crc(u3, crc_3_gsm); + +test "CRC-3/GSM" { + try testing.expectEqual(crc_3_gsm.check, Crc3Gsm.hash("123456789")); + + var c = Crc3Gsm.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_3_gsm.check, c.final()); +} + +const crc_3_rohc: Algorithm(u3) = .{ .poly = 0x3, .init = 0x7, .refin = true, .refout = true, .xorout = 0x0, .check = 0x6, .residue = 0x0 }; + +pub const Crc3Rohc = Crc(u3, crc_3_rohc); + +test "CRC-3/ROHC" { + try testing.expectEqual(crc_3_rohc.check, Crc3Rohc.hash("123456789")); + + var c = Crc3Rohc.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_3_rohc.check, c.final()); +} + +const crc_4_g_704: Algorithm(u4) = .{ .poly = 0x3, .init = 0x0, .refin = true, .refout = true, .xorout = 0x0, .check = 0x7, .residue = 0x0 }; + +pub const Crc4G704 = Crc(u4, crc_4_g_704); + +test "CRC-4/G-704" { + try testing.expectEqual(crc_4_g_704.check, Crc4G704.hash("123456789")); + + var c = Crc4G704.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_4_g_704.check, c.final()); +} + +const crc_4_interlaken: Algorithm(u4) = .{ .poly = 0x3, .init = 0xf, .refin = false, .refout = false, .xorout = 0xf, .check = 0xb, .residue = 0x2 }; + +pub const Crc4Interlaken = Crc(u4, crc_4_interlaken); + +test "CRC-4/INTERLAKEN" { + try testing.expectEqual(crc_4_interlaken.check, Crc4Interlaken.hash("123456789")); + + var c = Crc4Interlaken.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_4_interlaken.check, c.final()); +} + +const crc_5_epc_c1g2: Algorithm(u5) = .{ .poly = 0x09, .init = 0x09, .refin = false, .refout = false, .xorout = 0x00, .check = 0x00, .residue = 0x00 }; + +pub const Crc5EpcC1g2 = Crc(u5, crc_5_epc_c1g2); + +test "CRC-5/EPC-C1G2" { + try testing.expectEqual(crc_5_epc_c1g2.check, Crc5EpcC1g2.hash("123456789")); + + var c = Crc5EpcC1g2.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_5_epc_c1g2.check, c.final()); +} + +const crc_5_g_704: Algorithm(u5) = .{ .poly = 0x15, .init = 0x00, .refin = true, .refout = true, .xorout = 0x00, .check = 0x07, .residue = 0x00 }; + +pub const Crc5G704 = Crc(u5, crc_5_g_704); + +test "CRC-5/G-704" { + try testing.expectEqual(crc_5_g_704.check, Crc5G704.hash("123456789")); + + var c = Crc5G704.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_5_g_704.check, c.final()); +} + +const crc_5_usb: Algorithm(u5) = .{ .poly = 0x05, .init = 0x1f, .refin = true, .refout = true, .xorout = 0x1f, .check = 0x19, .residue = 0x06 }; + +pub const Crc5Usb = Crc(u5, crc_5_usb); + +test "CRC-5/USB" { + try testing.expectEqual(crc_5_usb.check, Crc5Usb.hash("123456789")); + + var c = Crc5Usb.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_5_usb.check, c.final()); +} + +const crc_6_cdma2000_a: Algorithm(u6) = .{ .poly = 0x27, .init = 0x3f, .refin = false, .refout = false, .xorout = 0x00, .check = 0x0d, .residue = 0x00 }; + +pub const Crc6Cdma2000A = Crc(u6, crc_6_cdma2000_a); + +test "CRC-6/CDMA2000-A" { + try testing.expectEqual(crc_6_cdma2000_a.check, Crc6Cdma2000A.hash("123456789")); + + var c = Crc6Cdma2000A.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_6_cdma2000_a.check, c.final()); +} + +const crc_6_cdma2000_b: Algorithm(u6) = .{ .poly = 0x07, .init = 0x3f, .refin = false, .refout = false, .xorout = 0x00, .check = 0x3b, .residue = 0x00 }; + +pub const Crc6Cdma2000B = Crc(u6, crc_6_cdma2000_b); + +test "CRC-6/CDMA2000-B" { + try testing.expectEqual(crc_6_cdma2000_b.check, Crc6Cdma2000B.hash("123456789")); + + var c = Crc6Cdma2000B.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_6_cdma2000_b.check, c.final()); +} + +const crc_6_darc: Algorithm(u6) = .{ .poly = 0x19, .init = 0x00, .refin = true, .refout = true, .xorout = 0x00, .check = 0x26, .residue = 0x00 }; + +pub const Crc6Darc = Crc(u6, crc_6_darc); + +test "CRC-6/DARC" { + try testing.expectEqual(crc_6_darc.check, Crc6Darc.hash("123456789")); + + var c = Crc6Darc.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_6_darc.check, c.final()); +} + +const crc_6_g_704: Algorithm(u6) = .{ .poly = 0x03, .init = 0x00, .refin = true, .refout = true, .xorout = 0x00, .check = 0x06, .residue = 0x00 }; + +pub const Crc6G704 = Crc(u6, crc_6_g_704); + +test "CRC-6/G-704" { + try testing.expectEqual(crc_6_g_704.check, Crc6G704.hash("123456789")); + + var c = Crc6G704.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_6_g_704.check, c.final()); +} + +const crc_6_gsm: Algorithm(u6) = .{ .poly = 0x2f, .init = 0x00, .refin = false, .refout = false, .xorout = 0x3f, .check = 0x13, .residue = 0x3a }; + +pub const Crc6Gsm = Crc(u6, crc_6_gsm); + +test "CRC-6/GSM" { + try testing.expectEqual(crc_6_gsm.check, Crc6Gsm.hash("123456789")); + + var c = Crc6Gsm.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_6_gsm.check, c.final()); +} + +const crc_7_mmc: Algorithm(u7) = .{ .poly = 0x09, .init = 0x00, .refin = false, .refout = false, .xorout = 0x00, .check = 0x75, .residue = 0x00 }; + +pub const Crc7Mmc = Crc(u7, crc_7_mmc); + +test "CRC-7/MMC" { + try testing.expectEqual(crc_7_mmc.check, Crc7Mmc.hash("123456789")); + + var c = Crc7Mmc.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_7_mmc.check, c.final()); +} + +const crc_7_rohc: Algorithm(u7) = .{ .poly = 0x4f, .init = 0x7f, .refin = true, .refout = true, .xorout = 0x00, .check = 0x53, .residue = 0x00 }; + +pub const Crc7Rohc = Crc(u7, crc_7_rohc); + +test "CRC-7/ROHC" { + try testing.expectEqual(crc_7_rohc.check, Crc7Rohc.hash("123456789")); + + var c = Crc7Rohc.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_7_rohc.check, c.final()); +} + +const crc_7_umts: Algorithm(u7) = .{ .poly = 0x45, .init = 0x00, .refin = false, .refout = false, .xorout = 0x00, .check = 0x61, .residue = 0x00 }; + +pub const Crc7Umts = Crc(u7, crc_7_umts); + +test "CRC-7/UMTS" { + try testing.expectEqual(crc_7_umts.check, Crc7Umts.hash("123456789")); + + var c = Crc7Umts.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_7_umts.check, c.final()); +} + +const crc_8_autosar: Algorithm(u8) = .{ .poly = 0x2f, .init = 0xff, .refin = false, .refout = false, .xorout = 0xff, .check = 0xdf, .residue = 0x42 }; + +pub const Crc8Autosar = Crc(u8, crc_8_autosar); + +test "CRC-8/AUTOSAR" { + try testing.expectEqual(crc_8_autosar.check, Crc8Autosar.hash("123456789")); + + var c = Crc8Autosar.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_8_autosar.check, c.final()); +} + +const crc_8_bluetooth: Algorithm(u8) = .{ .poly = 0xa7, .init = 0x00, .refin = true, .refout = true, .xorout = 0x00, .check = 0x26, .residue = 0x00 }; + +pub const Crc8Bluetooth = Crc(u8, crc_8_bluetooth); + +test "CRC-8/BLUETOOTH" { + try testing.expectEqual(crc_8_bluetooth.check, Crc8Bluetooth.hash("123456789")); + + var c = Crc8Bluetooth.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_8_bluetooth.check, c.final()); +} + +const crc_8_cdma2000: Algorithm(u8) = .{ .poly = 0x9b, .init = 0xff, .refin = false, .refout = false, .xorout = 0x00, .check = 0xda, .residue = 0x00 }; + +pub const Crc8Cdma2000 = Crc(u8, crc_8_cdma2000); + +test "CRC-8/CDMA2000" { + try testing.expectEqual(crc_8_cdma2000.check, Crc8Cdma2000.hash("123456789")); + + var c = Crc8Cdma2000.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_8_cdma2000.check, c.final()); +} + +const crc_8_darc: Algorithm(u8) = .{ .poly = 0x39, .init = 0x00, .refin = true, .refout = true, .xorout = 0x00, .check = 0x15, .residue = 0x00 }; + +pub const Crc8Darc = Crc(u8, crc_8_darc); + +test "CRC-8/DARC" { + try testing.expectEqual(crc_8_darc.check, Crc8Darc.hash("123456789")); + + var c = Crc8Darc.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_8_darc.check, c.final()); +} + +const crc_8_dvb_s2: Algorithm(u8) = .{ .poly = 0xd5, .init = 0x00, .refin = false, .refout = false, .xorout = 0x00, .check = 0xbc, .residue = 0x00 }; + +pub const Crc8DvbS2 = Crc(u8, crc_8_dvb_s2); + +test "CRC-8/DVB-S2" { + try testing.expectEqual(crc_8_dvb_s2.check, Crc8DvbS2.hash("123456789")); + + var c = Crc8DvbS2.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_8_dvb_s2.check, c.final()); +} + +const crc_8_gsm_a: Algorithm(u8) = .{ .poly = 0x1d, .init = 0x00, .refin = false, .refout = false, .xorout = 0x00, .check = 0x37, .residue = 0x00 }; + +pub const Crc8GsmA = Crc(u8, crc_8_gsm_a); + +test "CRC-8/GSM-A" { + try testing.expectEqual(crc_8_gsm_a.check, Crc8GsmA.hash("123456789")); + + var c = Crc8GsmA.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_8_gsm_a.check, c.final()); +} + +const crc_8_gsm_b: Algorithm(u8) = .{ .poly = 0x49, .init = 0x00, .refin = false, .refout = false, .xorout = 0xff, .check = 0x94, .residue = 0x53 }; + +pub const Crc8GsmB = Crc(u8, crc_8_gsm_b); + +test "CRC-8/GSM-B" { + try testing.expectEqual(crc_8_gsm_b.check, Crc8GsmB.hash("123456789")); + + var c = Crc8GsmB.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_8_gsm_b.check, c.final()); +} + +const crc_8_hitag: Algorithm(u8) = .{ .poly = 0x1d, .init = 0xff, .refin = false, .refout = false, .xorout = 0x00, .check = 0xb4, .residue = 0x00 }; + +pub const Crc8Hitag = Crc(u8, crc_8_hitag); + +test "CRC-8/HITAG" { + try testing.expectEqual(crc_8_hitag.check, Crc8Hitag.hash("123456789")); + + var c = Crc8Hitag.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_8_hitag.check, c.final()); +} + +const crc_8_i_432_1: Algorithm(u8) = .{ .poly = 0x07, .init = 0x00, .refin = false, .refout = false, .xorout = 0x55, .check = 0xa1, .residue = 0xac }; + +pub const Crc8I4321 = Crc(u8, crc_8_i_432_1); + +test "CRC-8/I-432-1" { + try testing.expectEqual(crc_8_i_432_1.check, Crc8I4321.hash("123456789")); + + var c = Crc8I4321.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_8_i_432_1.check, c.final()); +} + +const crc_8_i_code: Algorithm(u8) = .{ .poly = 0x1d, .init = 0xfd, .refin = false, .refout = false, .xorout = 0x00, .check = 0x7e, .residue = 0x00 }; + +pub const Crc8ICode = Crc(u8, crc_8_i_code); + +test "CRC-8/I-CODE" { + try testing.expectEqual(crc_8_i_code.check, Crc8ICode.hash("123456789")); + + var c = Crc8ICode.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_8_i_code.check, c.final()); +} + +const crc_8_lte: Algorithm(u8) = .{ .poly = 0x9b, .init = 0x00, .refin = false, .refout = false, .xorout = 0x00, .check = 0xea, .residue = 0x00 }; + +pub const Crc8Lte = Crc(u8, crc_8_lte); + +test "CRC-8/LTE" { + try testing.expectEqual(crc_8_lte.check, Crc8Lte.hash("123456789")); + + var c = Crc8Lte.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_8_lte.check, c.final()); +} + +const crc_8_maxim_dow: Algorithm(u8) = .{ .poly = 0x31, .init = 0x00, .refin = true, .refout = true, .xorout = 0x00, .check = 0xa1, .residue = 0x00 }; + +pub const Crc8MaximDow = Crc(u8, crc_8_maxim_dow); + +test "CRC-8/MAXIM-DOW" { + try testing.expectEqual(crc_8_maxim_dow.check, Crc8MaximDow.hash("123456789")); + + var c = Crc8MaximDow.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_8_maxim_dow.check, c.final()); +} + +const crc_8_mifare_mad: Algorithm(u8) = .{ .poly = 0x1d, .init = 0xc7, .refin = false, .refout = false, .xorout = 0x00, .check = 0x99, .residue = 0x00 }; + +pub const Crc8MifareMad = Crc(u8, crc_8_mifare_mad); + +test "CRC-8/MIFARE-MAD" { + try testing.expectEqual(crc_8_mifare_mad.check, Crc8MifareMad.hash("123456789")); + + var c = Crc8MifareMad.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_8_mifare_mad.check, c.final()); +} + +const crc_8_nrsc_5: Algorithm(u8) = .{ .poly = 0x31, .init = 0xff, .refin = false, .refout = false, .xorout = 0x00, .check = 0xf7, .residue = 0x00 }; + +pub const Crc8Nrsc5 = Crc(u8, crc_8_nrsc_5); + +test "CRC-8/NRSC-5" { + try testing.expectEqual(crc_8_nrsc_5.check, Crc8Nrsc5.hash("123456789")); + + var c = Crc8Nrsc5.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_8_nrsc_5.check, c.final()); +} + +const crc_8_opensafety: Algorithm(u8) = .{ .poly = 0x2f, .init = 0x00, .refin = false, .refout = false, .xorout = 0x00, .check = 0x3e, .residue = 0x00 }; + +pub const Crc8Opensafety = Crc(u8, crc_8_opensafety); + +test "CRC-8/OPENSAFETY" { + try testing.expectEqual(crc_8_opensafety.check, Crc8Opensafety.hash("123456789")); + + var c = Crc8Opensafety.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_8_opensafety.check, c.final()); +} + +const crc_8_rohc: Algorithm(u8) = .{ .poly = 0x07, .init = 0xff, .refin = true, .refout = true, .xorout = 0x00, .check = 0xd0, .residue = 0x00 }; + +pub const Crc8Rohc = Crc(u8, crc_8_rohc); + +test "CRC-8/ROHC" { + try testing.expectEqual(crc_8_rohc.check, Crc8Rohc.hash("123456789")); + + var c = Crc8Rohc.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_8_rohc.check, c.final()); +} + +const crc_8_sae_j1850: Algorithm(u8) = .{ .poly = 0x1d, .init = 0xff, .refin = false, .refout = false, .xorout = 0xff, .check = 0x4b, .residue = 0xc4 }; + +pub const Crc8SaeJ1850 = Crc(u8, crc_8_sae_j1850); + +test "CRC-8/SAE-J1850" { + try testing.expectEqual(crc_8_sae_j1850.check, Crc8SaeJ1850.hash("123456789")); + + var c = Crc8SaeJ1850.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_8_sae_j1850.check, c.final()); +} + +const crc_8_smbus: Algorithm(u8) = .{ .poly = 0x07, .init = 0x00, .refin = false, .refout = false, .xorout = 0x00, .check = 0xf4, .residue = 0x00 }; + +pub const Crc8Smbus = Crc(u8, crc_8_smbus); + +test "CRC-8/SMBUS" { + try testing.expectEqual(crc_8_smbus.check, Crc8Smbus.hash("123456789")); + + var c = Crc8Smbus.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_8_smbus.check, c.final()); +} + +const crc_8_tech_3250: Algorithm(u8) = .{ .poly = 0x1d, .init = 0xff, .refin = true, .refout = true, .xorout = 0x00, .check = 0x97, .residue = 0x00 }; + +pub const Crc8Tech3250 = Crc(u8, crc_8_tech_3250); + +test "CRC-8/TECH-3250" { + try testing.expectEqual(crc_8_tech_3250.check, Crc8Tech3250.hash("123456789")); + + var c = Crc8Tech3250.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_8_tech_3250.check, c.final()); +} + +const crc_8_wcdma: Algorithm(u8) = .{ .poly = 0x9b, .init = 0x00, .refin = true, .refout = true, .xorout = 0x00, .check = 0x25, .residue = 0x00 }; + +pub const Crc8Wcdma = Crc(u8, crc_8_wcdma); + +test "CRC-8/WCDMA" { + try testing.expectEqual(crc_8_wcdma.check, Crc8Wcdma.hash("123456789")); + + var c = Crc8Wcdma.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_8_wcdma.check, c.final()); +} + +const crc_10_atm: Algorithm(u10) = .{ .poly = 0x233, .init = 0x000, .refin = false, .refout = false, .xorout = 0x000, .check = 0x199, .residue = 0x000 }; + +pub const Crc10Atm = Crc(u10, crc_10_atm); + +test "CRC-10/ATM" { + try testing.expectEqual(crc_10_atm.check, Crc10Atm.hash("123456789")); + + var c = Crc10Atm.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_10_atm.check, c.final()); +} + +const crc_10_cdma2000: Algorithm(u10) = .{ .poly = 0x3d9, .init = 0x3ff, .refin = false, .refout = false, .xorout = 0x000, .check = 0x233, .residue = 0x000 }; + +pub const Crc10Cdma2000 = Crc(u10, crc_10_cdma2000); + +test "CRC-10/CDMA2000" { + try testing.expectEqual(crc_10_cdma2000.check, Crc10Cdma2000.hash("123456789")); + + var c = Crc10Cdma2000.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_10_cdma2000.check, c.final()); +} + +const crc_10_gsm: Algorithm(u10) = .{ .poly = 0x175, .init = 0x000, .refin = false, .refout = false, .xorout = 0x3ff, .check = 0x12a, .residue = 0x0c6 }; + +pub const Crc10Gsm = Crc(u10, crc_10_gsm); + +test "CRC-10/GSM" { + try testing.expectEqual(crc_10_gsm.check, Crc10Gsm.hash("123456789")); + + var c = Crc10Gsm.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_10_gsm.check, c.final()); +} + +const crc_11_flexray: Algorithm(u11) = .{ .poly = 0x385, .init = 0x01a, .refin = false, .refout = false, .xorout = 0x000, .check = 0x5a3, .residue = 0x000 }; + +pub const Crc11Flexray = Crc(u11, crc_11_flexray); + +test "CRC-11/FLEXRAY" { + try testing.expectEqual(crc_11_flexray.check, Crc11Flexray.hash("123456789")); + + var c = Crc11Flexray.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_11_flexray.check, c.final()); +} + +const crc_11_umts: Algorithm(u11) = .{ .poly = 0x307, .init = 0x000, .refin = false, .refout = false, .xorout = 0x000, .check = 0x061, .residue = 0x000 }; + +pub const Crc11Umts = Crc(u11, crc_11_umts); + +test "CRC-11/UMTS" { + try testing.expectEqual(crc_11_umts.check, Crc11Umts.hash("123456789")); + + var c = Crc11Umts.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_11_umts.check, c.final()); +} + +const crc_12_cdma2000: Algorithm(u12) = .{ .poly = 0xf13, .init = 0xfff, .refin = false, .refout = false, .xorout = 0x000, .check = 0xd4d, .residue = 0x000 }; + +pub const Crc12Cdma2000 = Crc(u12, crc_12_cdma2000); + +test "CRC-12/CDMA2000" { + try testing.expectEqual(crc_12_cdma2000.check, Crc12Cdma2000.hash("123456789")); + + var c = Crc12Cdma2000.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_12_cdma2000.check, c.final()); +} + +const crc_12_dect: Algorithm(u12) = .{ .poly = 0x80f, .init = 0x000, .refin = false, .refout = false, .xorout = 0x000, .check = 0xf5b, .residue = 0x000 }; + +pub const Crc12Dect = Crc(u12, crc_12_dect); + +test "CRC-12/DECT" { + try testing.expectEqual(crc_12_dect.check, Crc12Dect.hash("123456789")); + + var c = Crc12Dect.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_12_dect.check, c.final()); +} + +const crc_12_gsm: Algorithm(u12) = .{ .poly = 0xd31, .init = 0x000, .refin = false, .refout = false, .xorout = 0xfff, .check = 0xb34, .residue = 0x178 }; + +pub const Crc12Gsm = Crc(u12, crc_12_gsm); + +test "CRC-12/GSM" { + try testing.expectEqual(crc_12_gsm.check, Crc12Gsm.hash("123456789")); + + var c = Crc12Gsm.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_12_gsm.check, c.final()); +} + +const crc_12_umts: Algorithm(u12) = .{ .poly = 0x80f, .init = 0x000, .refin = false, .refout = true, .xorout = 0x000, .check = 0xdaf, .residue = 0x000 }; + +pub const Crc12Umts = Crc(u12, crc_12_umts); + +test "CRC-12/UMTS" { + try testing.expectEqual(crc_12_umts.check, Crc12Umts.hash("123456789")); + + var c = Crc12Umts.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_12_umts.check, c.final()); +} + +const crc_13_bbc: Algorithm(u13) = .{ .poly = 0x1cf5, .init = 0x0000, .refin = false, .refout = false, .xorout = 0x0000, .check = 0x04fa, .residue = 0x0000 }; + +pub const Crc13Bbc = Crc(u13, crc_13_bbc); + +test "CRC-13/BBC" { + try testing.expectEqual(crc_13_bbc.check, Crc13Bbc.hash("123456789")); + + var c = Crc13Bbc.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_13_bbc.check, c.final()); +} + +const crc_14_darc: Algorithm(u14) = .{ .poly = 0x0805, .init = 0x0000, .refin = true, .refout = true, .xorout = 0x0000, .check = 0x082d, .residue = 0x0000 }; + +pub const Crc14Darc = Crc(u14, crc_14_darc); + +test "CRC-14/DARC" { + try testing.expectEqual(crc_14_darc.check, Crc14Darc.hash("123456789")); + + var c = Crc14Darc.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_14_darc.check, c.final()); +} + +const crc_14_gsm: Algorithm(u14) = .{ .poly = 0x202d, .init = 0x0000, .refin = false, .refout = false, .xorout = 0x3fff, .check = 0x30ae, .residue = 0x031e }; + +pub const Crc14Gsm = Crc(u14, crc_14_gsm); + +test "CRC-14/GSM" { + try testing.expectEqual(crc_14_gsm.check, Crc14Gsm.hash("123456789")); + + var c = Crc14Gsm.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_14_gsm.check, c.final()); +} + +const crc_15_can: Algorithm(u15) = .{ .poly = 0x4599, .init = 0x0000, .refin = false, .refout = false, .xorout = 0x0000, .check = 0x059e, .residue = 0x0000 }; + +pub const Crc15Can = Crc(u15, crc_15_can); + +test "CRC-15/CAN" { + try testing.expectEqual(crc_15_can.check, Crc15Can.hash("123456789")); + + var c = Crc15Can.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_15_can.check, c.final()); +} + +const crc_15_mpt1327: Algorithm(u15) = .{ .poly = 0x6815, .init = 0x0000, .refin = false, .refout = false, .xorout = 0x0001, .check = 0x2566, .residue = 0x6815 }; + +pub const Crc15Mpt1327 = Crc(u15, crc_15_mpt1327); + +test "CRC-15/MPT1327" { + try testing.expectEqual(crc_15_mpt1327.check, Crc15Mpt1327.hash("123456789")); + + var c = Crc15Mpt1327.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_15_mpt1327.check, c.final()); +} + +const crc_16_arc: Algorithm(u16) = .{ .poly = 0x8005, .init = 0x0000, .refin = true, .refout = true, .xorout = 0x0000, .check = 0xbb3d, .residue = 0x0000 }; + +pub const Crc16Arc = Crc(u16, crc_16_arc); + +test "CRC-16/ARC" { + try testing.expectEqual(crc_16_arc.check, Crc16Arc.hash("123456789")); + + var c = Crc16Arc.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_arc.check, c.final()); +} + +const crc_16_cdma2000: Algorithm(u16) = .{ .poly = 0xc867, .init = 0xffff, .refin = false, .refout = false, .xorout = 0x0000, .check = 0x4c06, .residue = 0x0000 }; + +pub const Crc16Cdma2000 = Crc(u16, crc_16_cdma2000); + +test "CRC-16/CDMA2000" { + try testing.expectEqual(crc_16_cdma2000.check, Crc16Cdma2000.hash("123456789")); + + var c = Crc16Cdma2000.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_cdma2000.check, c.final()); +} + +const crc_16_cms: Algorithm(u16) = .{ .poly = 0x8005, .init = 0xffff, .refin = false, .refout = false, .xorout = 0x0000, .check = 0xaee7, .residue = 0x0000 }; + +pub const Crc16Cms = Crc(u16, crc_16_cms); + +test "CRC-16/CMS" { + try testing.expectEqual(crc_16_cms.check, Crc16Cms.hash("123456789")); + + var c = Crc16Cms.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_cms.check, c.final()); +} + +const crc_16_dds_110: Algorithm(u16) = .{ .poly = 0x8005, .init = 0x800d, .refin = false, .refout = false, .xorout = 0x0000, .check = 0x9ecf, .residue = 0x0000 }; + +pub const Crc16Dds110 = Crc(u16, crc_16_dds_110); + +test "CRC-16/DDS-110" { + try testing.expectEqual(crc_16_dds_110.check, Crc16Dds110.hash("123456789")); + + var c = Crc16Dds110.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_dds_110.check, c.final()); +} + +const crc_16_dect_r: Algorithm(u16) = .{ .poly = 0x0589, .init = 0x0000, .refin = false, .refout = false, .xorout = 0x0001, .check = 0x007e, .residue = 0x0589 }; + +pub const Crc16DectR = Crc(u16, crc_16_dect_r); + +test "CRC-16/DECT-R" { + try testing.expectEqual(crc_16_dect_r.check, Crc16DectR.hash("123456789")); + + var c = Crc16DectR.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_dect_r.check, c.final()); +} + +const crc_16_dect_x: Algorithm(u16) = .{ .poly = 0x0589, .init = 0x0000, .refin = false, .refout = false, .xorout = 0x0000, .check = 0x007f, .residue = 0x0000 }; + +pub const Crc16DectX = Crc(u16, crc_16_dect_x); + +test "CRC-16/DECT-X" { + try testing.expectEqual(crc_16_dect_x.check, Crc16DectX.hash("123456789")); + + var c = Crc16DectX.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_dect_x.check, c.final()); +} + +const crc_16_dnp: Algorithm(u16) = .{ .poly = 0x3d65, .init = 0x0000, .refin = true, .refout = true, .xorout = 0xffff, .check = 0xea82, .residue = 0x66c5 }; + +pub const Crc16Dnp = Crc(u16, crc_16_dnp); + +test "CRC-16/DNP" { + try testing.expectEqual(crc_16_dnp.check, Crc16Dnp.hash("123456789")); + + var c = Crc16Dnp.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_dnp.check, c.final()); +} + +const crc_16_en_13757: Algorithm(u16) = .{ .poly = 0x3d65, .init = 0x0000, .refin = false, .refout = false, .xorout = 0xffff, .check = 0xc2b7, .residue = 0xa366 }; + +pub const Crc16En13757 = Crc(u16, crc_16_en_13757); + +test "CRC-16/EN-13757" { + try testing.expectEqual(crc_16_en_13757.check, Crc16En13757.hash("123456789")); + + var c = Crc16En13757.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_en_13757.check, c.final()); +} + +const crc_16_genibus: Algorithm(u16) = .{ .poly = 0x1021, .init = 0xffff, .refin = false, .refout = false, .xorout = 0xffff, .check = 0xd64e, .residue = 0x1d0f }; + +pub const Crc16Genibus = Crc(u16, crc_16_genibus); + +test "CRC-16/GENIBUS" { + try testing.expectEqual(crc_16_genibus.check, Crc16Genibus.hash("123456789")); + + var c = Crc16Genibus.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_genibus.check, c.final()); +} + +const crc_16_gsm: Algorithm(u16) = .{ .poly = 0x1021, .init = 0x0000, .refin = false, .refout = false, .xorout = 0xffff, .check = 0xce3c, .residue = 0x1d0f }; + +pub const Crc16Gsm = Crc(u16, crc_16_gsm); + +test "CRC-16/GSM" { + try testing.expectEqual(crc_16_gsm.check, Crc16Gsm.hash("123456789")); + + var c = Crc16Gsm.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_gsm.check, c.final()); +} + +const crc_16_ibm_3740: Algorithm(u16) = .{ .poly = 0x1021, .init = 0xffff, .refin = false, .refout = false, .xorout = 0x0000, .check = 0x29b1, .residue = 0x0000 }; + +pub const Crc16Ibm3740 = Crc(u16, crc_16_ibm_3740); + +test "CRC-16/IBM-3740" { + try testing.expectEqual(crc_16_ibm_3740.check, Crc16Ibm3740.hash("123456789")); + + var c = Crc16Ibm3740.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_ibm_3740.check, c.final()); +} + +const crc_16_ibm_sdlc: Algorithm(u16) = .{ .poly = 0x1021, .init = 0xffff, .refin = true, .refout = true, .xorout = 0xffff, .check = 0x906e, .residue = 0xf0b8 }; + +pub const Crc16IbmSdlc = Crc(u16, crc_16_ibm_sdlc); + +test "CRC-16/IBM-SDLC" { + try testing.expectEqual(crc_16_ibm_sdlc.check, Crc16IbmSdlc.hash("123456789")); + + var c = Crc16IbmSdlc.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_ibm_sdlc.check, c.final()); +} + +const crc_16_iso_iec_14443_3_a: Algorithm(u16) = .{ .poly = 0x1021, .init = 0xc6c6, .refin = true, .refout = true, .xorout = 0x0000, .check = 0xbf05, .residue = 0x0000 }; + +pub const Crc16IsoIec144433A = Crc(u16, crc_16_iso_iec_14443_3_a); + +test "CRC-16/ISO-IEC-14443-3-A" { + try testing.expectEqual(crc_16_iso_iec_14443_3_a.check, Crc16IsoIec144433A.hash("123456789")); + + var c = Crc16IsoIec144433A.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_iso_iec_14443_3_a.check, c.final()); +} + +const crc_16_kermit: Algorithm(u16) = .{ .poly = 0x1021, .init = 0x0000, .refin = true, .refout = true, .xorout = 0x0000, .check = 0x2189, .residue = 0x0000 }; + +pub const Crc16Kermit = Crc(u16, crc_16_kermit); + +test "CRC-16/KERMIT" { + try testing.expectEqual(crc_16_kermit.check, Crc16Kermit.hash("123456789")); + + var c = Crc16Kermit.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_kermit.check, c.final()); +} + +const crc_16_lj1200: Algorithm(u16) = .{ .poly = 0x6f63, .init = 0x0000, .refin = false, .refout = false, .xorout = 0x0000, .check = 0xbdf4, .residue = 0x0000 }; + +pub const Crc16Lj1200 = Crc(u16, crc_16_lj1200); + +test "CRC-16/LJ1200" { + try testing.expectEqual(crc_16_lj1200.check, Crc16Lj1200.hash("123456789")); + + var c = Crc16Lj1200.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_lj1200.check, c.final()); +} + +const crc_16_m17: Algorithm(u16) = .{ .poly = 0x5935, .init = 0xffff, .refin = false, .refout = false, .xorout = 0x0000, .check = 0x772b, .residue = 0x0000 }; + +pub const Crc16M17 = Crc(u16, crc_16_m17); + +test "CRC-16/M17" { + try testing.expectEqual(crc_16_m17.check, Crc16M17.hash("123456789")); + + var c = Crc16M17.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_m17.check, c.final()); +} + +const crc_16_maxim_dow: Algorithm(u16) = .{ .poly = 0x8005, .init = 0x0000, .refin = true, .refout = true, .xorout = 0xffff, .check = 0x44c2, .residue = 0xb001 }; + +pub const Crc16MaximDow = Crc(u16, crc_16_maxim_dow); + +test "CRC-16/MAXIM-DOW" { + try testing.expectEqual(crc_16_maxim_dow.check, Crc16MaximDow.hash("123456789")); + + var c = Crc16MaximDow.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_maxim_dow.check, c.final()); +} + +const crc_16_mcrf4xx: Algorithm(u16) = .{ .poly = 0x1021, .init = 0xffff, .refin = true, .refout = true, .xorout = 0x0000, .check = 0x6f91, .residue = 0x0000 }; + +pub const Crc16Mcrf4xx = Crc(u16, crc_16_mcrf4xx); + +test "CRC-16/MCRF4XX" { + try testing.expectEqual(crc_16_mcrf4xx.check, Crc16Mcrf4xx.hash("123456789")); + + var c = Crc16Mcrf4xx.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_mcrf4xx.check, c.final()); +} + +const crc_16_modbus: Algorithm(u16) = .{ .poly = 0x8005, .init = 0xffff, .refin = true, .refout = true, .xorout = 0x0000, .check = 0x4b37, .residue = 0x0000 }; + +pub const Crc16Modbus = Crc(u16, crc_16_modbus); + +test "CRC-16/MODBUS" { + try testing.expectEqual(crc_16_modbus.check, Crc16Modbus.hash("123456789")); + + var c = Crc16Modbus.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_modbus.check, c.final()); +} + +const crc_16_nrsc_5: Algorithm(u16) = .{ .poly = 0x080b, .init = 0xffff, .refin = true, .refout = true, .xorout = 0x0000, .check = 0xa066, .residue = 0x0000 }; + +pub const Crc16Nrsc5 = Crc(u16, crc_16_nrsc_5); + +test "CRC-16/NRSC-5" { + try testing.expectEqual(crc_16_nrsc_5.check, Crc16Nrsc5.hash("123456789")); + + var c = Crc16Nrsc5.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_nrsc_5.check, c.final()); +} + +const crc_16_opensafety_a: Algorithm(u16) = .{ .poly = 0x5935, .init = 0x0000, .refin = false, .refout = false, .xorout = 0x0000, .check = 0x5d38, .residue = 0x0000 }; + +pub const Crc16OpensafetyA = Crc(u16, crc_16_opensafety_a); + +test "CRC-16/OPENSAFETY-A" { + try testing.expectEqual(crc_16_opensafety_a.check, Crc16OpensafetyA.hash("123456789")); + + var c = Crc16OpensafetyA.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_opensafety_a.check, c.final()); +} + +const crc_16_opensafety_b: Algorithm(u16) = .{ .poly = 0x755b, .init = 0x0000, .refin = false, .refout = false, .xorout = 0x0000, .check = 0x20fe, .residue = 0x0000 }; + +pub const Crc16OpensafetyB = Crc(u16, crc_16_opensafety_b); + +test "CRC-16/OPENSAFETY-B" { + try testing.expectEqual(crc_16_opensafety_b.check, Crc16OpensafetyB.hash("123456789")); + + var c = Crc16OpensafetyB.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_opensafety_b.check, c.final()); +} + +const crc_16_profibus: Algorithm(u16) = .{ .poly = 0x1dcf, .init = 0xffff, .refin = false, .refout = false, .xorout = 0xffff, .check = 0xa819, .residue = 0xe394 }; + +pub const Crc16Profibus = Crc(u16, crc_16_profibus); + +test "CRC-16/PROFIBUS" { + try testing.expectEqual(crc_16_profibus.check, Crc16Profibus.hash("123456789")); + + var c = Crc16Profibus.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_profibus.check, c.final()); +} + +const crc_16_riello: Algorithm(u16) = .{ .poly = 0x1021, .init = 0xb2aa, .refin = true, .refout = true, .xorout = 0x0000, .check = 0x63d0, .residue = 0x0000 }; + +pub const Crc16Riello = Crc(u16, crc_16_riello); + +test "CRC-16/RIELLO" { + try testing.expectEqual(crc_16_riello.check, Crc16Riello.hash("123456789")); + + var c = Crc16Riello.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_riello.check, c.final()); +} + +const crc_16_spi_fujitsu: Algorithm(u16) = .{ .poly = 0x1021, .init = 0x1d0f, .refin = false, .refout = false, .xorout = 0x0000, .check = 0xe5cc, .residue = 0x0000 }; + +pub const Crc16SpiFujitsu = Crc(u16, crc_16_spi_fujitsu); + +test "CRC-16/SPI-FUJITSU" { + try testing.expectEqual(crc_16_spi_fujitsu.check, Crc16SpiFujitsu.hash("123456789")); + + var c = Crc16SpiFujitsu.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_spi_fujitsu.check, c.final()); +} + +const crc_16_t10_dif: Algorithm(u16) = .{ .poly = 0x8bb7, .init = 0x0000, .refin = false, .refout = false, .xorout = 0x0000, .check = 0xd0db, .residue = 0x0000 }; + +pub const Crc16T10Dif = Crc(u16, crc_16_t10_dif); + +test "CRC-16/T10-DIF" { + try testing.expectEqual(crc_16_t10_dif.check, Crc16T10Dif.hash("123456789")); + + var c = Crc16T10Dif.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_t10_dif.check, c.final()); +} + +const crc_16_teledisk: Algorithm(u16) = .{ .poly = 0xa097, .init = 0x0000, .refin = false, .refout = false, .xorout = 0x0000, .check = 0x0fb3, .residue = 0x0000 }; + +pub const Crc16Teledisk = Crc(u16, crc_16_teledisk); + +test "CRC-16/TELEDISK" { + try testing.expectEqual(crc_16_teledisk.check, Crc16Teledisk.hash("123456789")); + + var c = Crc16Teledisk.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_teledisk.check, c.final()); +} + +const crc_16_tms37157: Algorithm(u16) = .{ .poly = 0x1021, .init = 0x89ec, .refin = true, .refout = true, .xorout = 0x0000, .check = 0x26b1, .residue = 0x0000 }; + +pub const Crc16Tms37157 = Crc(u16, crc_16_tms37157); + +test "CRC-16/TMS37157" { + try testing.expectEqual(crc_16_tms37157.check, Crc16Tms37157.hash("123456789")); + + var c = Crc16Tms37157.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_tms37157.check, c.final()); +} + +const crc_16_umts: Algorithm(u16) = .{ .poly = 0x8005, .init = 0x0000, .refin = false, .refout = false, .xorout = 0x0000, .check = 0xfee8, .residue = 0x0000 }; + +pub const Crc16Umts = Crc(u16, crc_16_umts); + +test "CRC-16/UMTS" { + try testing.expectEqual(crc_16_umts.check, Crc16Umts.hash("123456789")); + + var c = Crc16Umts.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_umts.check, c.final()); +} + +const crc_16_usb: Algorithm(u16) = .{ .poly = 0x8005, .init = 0xffff, .refin = true, .refout = true, .xorout = 0xffff, .check = 0xb4c8, .residue = 0xb001 }; + +pub const Crc16Usb = Crc(u16, crc_16_usb); + +test "CRC-16/USB" { + try testing.expectEqual(crc_16_usb.check, Crc16Usb.hash("123456789")); + + var c = Crc16Usb.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_usb.check, c.final()); +} + +const crc_16_xmodem: Algorithm(u16) = .{ .poly = 0x1021, .init = 0x0000, .refin = false, .refout = false, .xorout = 0x0000, .check = 0x31c3, .residue = 0x0000 }; + +pub const Crc16Xmodem = Crc(u16, crc_16_xmodem); + +test "CRC-16/XMODEM" { + try testing.expectEqual(crc_16_xmodem.check, Crc16Xmodem.hash("123456789")); + + var c = Crc16Xmodem.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_16_xmodem.check, c.final()); +} + +const crc_17_can_fd: Algorithm(u17) = .{ .poly = 0x1685b, .init = 0x00000, .refin = false, .refout = false, .xorout = 0x00000, .check = 0x04f03, .residue = 0x00000 }; + +pub const Crc17CanFd = Crc(u17, crc_17_can_fd); + +test "CRC-17/CAN-FD" { + try testing.expectEqual(crc_17_can_fd.check, Crc17CanFd.hash("123456789")); + + var c = Crc17CanFd.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_17_can_fd.check, c.final()); +} + +const crc_21_can_fd: Algorithm(u21) = .{ .poly = 0x102899, .init = 0x000000, .refin = false, .refout = false, .xorout = 0x000000, .check = 0x0ed841, .residue = 0x000000 }; + +pub const Crc21CanFd = Crc(u21, crc_21_can_fd); + +test "CRC-21/CAN-FD" { + try testing.expectEqual(crc_21_can_fd.check, Crc21CanFd.hash("123456789")); + + var c = Crc21CanFd.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_21_can_fd.check, c.final()); +} + +const crc_24_ble: Algorithm(u24) = .{ .poly = 0x00065b, .init = 0x555555, .refin = true, .refout = true, .xorout = 0x000000, .check = 0xc25a56, .residue = 0x000000 }; + +pub const Crc24Ble = Crc(u24, crc_24_ble); + +test "CRC-24/BLE" { + try testing.expectEqual(crc_24_ble.check, Crc24Ble.hash("123456789")); + + var c = Crc24Ble.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_24_ble.check, c.final()); +} + +const crc_24_flexray_a: Algorithm(u24) = .{ .poly = 0x5d6dcb, .init = 0xfedcba, .refin = false, .refout = false, .xorout = 0x000000, .check = 0x7979bd, .residue = 0x000000 }; + +pub const Crc24FlexrayA = Crc(u24, crc_24_flexray_a); + +test "CRC-24/FLEXRAY-A" { + try testing.expectEqual(crc_24_flexray_a.check, Crc24FlexrayA.hash("123456789")); + + var c = Crc24FlexrayA.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_24_flexray_a.check, c.final()); +} + +const crc_24_flexray_b: Algorithm(u24) = .{ .poly = 0x5d6dcb, .init = 0xabcdef, .refin = false, .refout = false, .xorout = 0x000000, .check = 0x1f23b8, .residue = 0x000000 }; + +pub const Crc24FlexrayB = Crc(u24, crc_24_flexray_b); + +test "CRC-24/FLEXRAY-B" { + try testing.expectEqual(crc_24_flexray_b.check, Crc24FlexrayB.hash("123456789")); + + var c = Crc24FlexrayB.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_24_flexray_b.check, c.final()); +} + +const crc_24_interlaken: Algorithm(u24) = .{ .poly = 0x328b63, .init = 0xffffff, .refin = false, .refout = false, .xorout = 0xffffff, .check = 0xb4f3e6, .residue = 0x144e63 }; + +pub const Crc24Interlaken = Crc(u24, crc_24_interlaken); + +test "CRC-24/INTERLAKEN" { + try testing.expectEqual(crc_24_interlaken.check, Crc24Interlaken.hash("123456789")); + + var c = Crc24Interlaken.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_24_interlaken.check, c.final()); +} + +const crc_24_lte_a: Algorithm(u24) = .{ .poly = 0x864cfb, .init = 0x000000, .refin = false, .refout = false, .xorout = 0x000000, .check = 0xcde703, .residue = 0x000000 }; + +pub const Crc24LteA = Crc(u24, crc_24_lte_a); + +test "CRC-24/LTE-A" { + try testing.expectEqual(crc_24_lte_a.check, Crc24LteA.hash("123456789")); + + var c = Crc24LteA.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_24_lte_a.check, c.final()); +} + +const crc_24_lte_b: Algorithm(u24) = .{ .poly = 0x800063, .init = 0x000000, .refin = false, .refout = false, .xorout = 0x000000, .check = 0x23ef52, .residue = 0x000000 }; + +pub const Crc24LteB = Crc(u24, crc_24_lte_b); + +test "CRC-24/LTE-B" { + try testing.expectEqual(crc_24_lte_b.check, Crc24LteB.hash("123456789")); + + var c = Crc24LteB.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_24_lte_b.check, c.final()); +} + +const crc_24_openpgp: Algorithm(u24) = .{ .poly = 0x864cfb, .init = 0xb704ce, .refin = false, .refout = false, .xorout = 0x000000, .check = 0x21cf02, .residue = 0x000000 }; + +pub const Crc24Openpgp = Crc(u24, crc_24_openpgp); + +test "CRC-24/OPENPGP" { + try testing.expectEqual(crc_24_openpgp.check, Crc24Openpgp.hash("123456789")); + + var c = Crc24Openpgp.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_24_openpgp.check, c.final()); +} + +const crc_24_os_9: Algorithm(u24) = .{ .poly = 0x800063, .init = 0xffffff, .refin = false, .refout = false, .xorout = 0xffffff, .check = 0x200fa5, .residue = 0x800fe3 }; + +pub const Crc24Os9 = Crc(u24, crc_24_os_9); + +test "CRC-24/OS-9" { + try testing.expectEqual(crc_24_os_9.check, Crc24Os9.hash("123456789")); + + var c = Crc24Os9.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_24_os_9.check, c.final()); +} + +const crc_30_cdma: Algorithm(u30) = .{ .poly = 0x2030b9c7, .init = 0x3fffffff, .refin = false, .refout = false, .xorout = 0x3fffffff, .check = 0x04c34abf, .residue = 0x34efa55a }; + +pub const Crc30Cdma = Crc(u30, crc_30_cdma); + +test "CRC-30/CDMA" { + try testing.expectEqual(crc_30_cdma.check, Crc30Cdma.hash("123456789")); + + var c = Crc30Cdma.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_30_cdma.check, c.final()); +} + +const crc_31_philips: Algorithm(u31) = .{ .poly = 0x04c11db7, .init = 0x7fffffff, .refin = false, .refout = false, .xorout = 0x7fffffff, .check = 0x0ce9e46c, .residue = 0x4eaf26f1 }; + +pub const Crc31Philips = Crc(u31, crc_31_philips); + +test "CRC-31/PHILIPS" { + try testing.expectEqual(crc_31_philips.check, Crc31Philips.hash("123456789")); + + var c = Crc31Philips.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_31_philips.check, c.final()); +} + +const crc_32_aixm: Algorithm(u32) = .{ .poly = 0x814141ab, .init = 0x00000000, .refin = false, .refout = false, .xorout = 0x00000000, .check = 0x3010bf7f, .residue = 0x00000000 }; + +pub const Crc32Aixm = Crc(u32, crc_32_aixm); + +test "CRC-32/AIXM" { + try testing.expectEqual(crc_32_aixm.check, Crc32Aixm.hash("123456789")); + + var c = Crc32Aixm.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_32_aixm.check, c.final()); +} + +const crc_32_autosar: Algorithm(u32) = .{ .poly = 0xf4acfb13, .init = 0xffffffff, .refin = true, .refout = true, .xorout = 0xffffffff, .check = 0x1697d06a, .residue = 0x904cddbf }; + +pub const Crc32Autosar = Crc(u32, crc_32_autosar); + +test "CRC-32/AUTOSAR" { + try testing.expectEqual(crc_32_autosar.check, Crc32Autosar.hash("123456789")); + + var c = Crc32Autosar.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_32_autosar.check, c.final()); +} + +const crc_32_base91_d: Algorithm(u32) = .{ .poly = 0xa833982b, .init = 0xffffffff, .refin = true, .refout = true, .xorout = 0xffffffff, .check = 0x87315576, .residue = 0x45270551 }; + +pub const Crc32Base91D = Crc(u32, crc_32_base91_d); + +test "CRC-32/BASE91-D" { + try testing.expectEqual(crc_32_base91_d.check, Crc32Base91D.hash("123456789")); + + var c = Crc32Base91D.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_32_base91_d.check, c.final()); +} + +const crc_32_bzip2: Algorithm(u32) = .{ .poly = 0x04c11db7, .init = 0xffffffff, .refin = false, .refout = false, .xorout = 0xffffffff, .check = 0xfc891918, .residue = 0xc704dd7b }; + +pub const Crc32Bzip2 = Crc(u32, crc_32_bzip2); + +test "CRC-32/BZIP2" { + try testing.expectEqual(crc_32_bzip2.check, Crc32Bzip2.hash("123456789")); + + var c = Crc32Bzip2.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_32_bzip2.check, c.final()); +} + +const crc_32_cd_rom_edc: Algorithm(u32) = .{ .poly = 0x8001801b, .init = 0x00000000, .refin = true, .refout = true, .xorout = 0x00000000, .check = 0x6ec2edc4, .residue = 0x00000000 }; + +pub const Crc32CdRomEdc = Crc(u32, crc_32_cd_rom_edc); + +test "CRC-32/CD-ROM-EDC" { + try testing.expectEqual(crc_32_cd_rom_edc.check, Crc32CdRomEdc.hash("123456789")); + + var c = Crc32CdRomEdc.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_32_cd_rom_edc.check, c.final()); +} + +const crc_32_cksum: Algorithm(u32) = .{ .poly = 0x04c11db7, .init = 0x00000000, .refin = false, .refout = false, .xorout = 0xffffffff, .check = 0x765e7680, .residue = 0xc704dd7b }; + +pub const Crc32Cksum = Crc(u32, crc_32_cksum); + +test "CRC-32/CKSUM" { + try testing.expectEqual(crc_32_cksum.check, Crc32Cksum.hash("123456789")); + + var c = Crc32Cksum.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_32_cksum.check, c.final()); +} + +const crc_32_iscsi: Algorithm(u32) = .{ .poly = 0x1edc6f41, .init = 0xffffffff, .refin = true, .refout = true, .xorout = 0xffffffff, .check = 0xe3069283, .residue = 0xb798b438 }; + +pub const Crc32Iscsi = Crc(u32, crc_32_iscsi); + +test "CRC-32/ISCSI" { + try testing.expectEqual(crc_32_iscsi.check, Crc32Iscsi.hash("123456789")); + + var c = Crc32Iscsi.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_32_iscsi.check, c.final()); +} + +const crc_32_iso_hdlc: Algorithm(u32) = .{ .poly = 0x04c11db7, .init = 0xffffffff, .refin = true, .refout = true, .xorout = 0xffffffff, .check = 0xcbf43926, .residue = 0xdebb20e3 }; + +pub const Crc32IsoHdlc = Crc(u32, crc_32_iso_hdlc); + +test "CRC-32/ISO-HDLC" { + try testing.expectEqual(crc_32_iso_hdlc.check, Crc32IsoHdlc.hash("123456789")); + + var c = Crc32IsoHdlc.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_32_iso_hdlc.check, c.final()); +} + +const crc_32_jamcrc: Algorithm(u32) = .{ .poly = 0x04c11db7, .init = 0xffffffff, .refin = true, .refout = true, .xorout = 0x00000000, .check = 0x340bc6d9, .residue = 0x00000000 }; + +pub const Crc32Jamcrc = Crc(u32, crc_32_jamcrc); + +test "CRC-32/JAMCRC" { + try testing.expectEqual(crc_32_jamcrc.check, Crc32Jamcrc.hash("123456789")); + + var c = Crc32Jamcrc.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_32_jamcrc.check, c.final()); +} + +const crc_32_mef: Algorithm(u32) = .{ .poly = 0x741b8cd7, .init = 0xffffffff, .refin = true, .refout = true, .xorout = 0x00000000, .check = 0xd2c22f51, .residue = 0x00000000 }; + +pub const Crc32Mef = Crc(u32, crc_32_mef); + +test "CRC-32/MEF" { + try testing.expectEqual(crc_32_mef.check, Crc32Mef.hash("123456789")); + + var c = Crc32Mef.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_32_mef.check, c.final()); +} + +const crc_32_mpeg_2: Algorithm(u32) = .{ .poly = 0x04c11db7, .init = 0xffffffff, .refin = false, .refout = false, .xorout = 0x00000000, .check = 0x0376e6e7, .residue = 0x00000000 }; + +pub const Crc32Mpeg2 = Crc(u32, crc_32_mpeg_2); + +test "CRC-32/MPEG-2" { + try testing.expectEqual(crc_32_mpeg_2.check, Crc32Mpeg2.hash("123456789")); + + var c = Crc32Mpeg2.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_32_mpeg_2.check, c.final()); +} + +const crc_32_xfer: Algorithm(u32) = .{ .poly = 0x000000af, .init = 0x00000000, .refin = false, .refout = false, .xorout = 0x00000000, .check = 0xbd0be338, .residue = 0x00000000 }; + +pub const Crc32Xfer = Crc(u32, crc_32_xfer); + +test "CRC-32/XFER" { + try testing.expectEqual(crc_32_xfer.check, Crc32Xfer.hash("123456789")); + + var c = Crc32Xfer.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_32_xfer.check, c.final()); +} + +const crc_40_gsm: Algorithm(u40) = .{ .poly = 0x0004820009, .init = 0x0000000000, .refin = false, .refout = false, .xorout = 0xffffffffff, .check = 0xd4164fc646, .residue = 0xc4ff8071ff }; + +pub const Crc40Gsm = Crc(u40, crc_40_gsm); + +test "CRC-40/GSM" { + try testing.expectEqual(crc_40_gsm.check, Crc40Gsm.hash("123456789")); + + var c = Crc40Gsm.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_40_gsm.check, c.final()); +} + +const crc_64_ecma_182: Algorithm(u64) = .{ .poly = 0x42f0e1eba9ea3693, .init = 0x0000000000000000, .refin = false, .refout = false, .xorout = 0x0000000000000000, .check = 0x6c40df5f0b497347, .residue = 0x0000000000000000 }; + +pub const Crc64Ecma182 = Crc(u64, crc_64_ecma_182); + +test "CRC-64/ECMA-182" { + try testing.expectEqual(crc_64_ecma_182.check, Crc64Ecma182.hash("123456789")); + + var c = Crc64Ecma182.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_64_ecma_182.check, c.final()); +} + +const crc_64_go_iso: Algorithm(u64) = .{ .poly = 0x000000000000001b, .init = 0xffffffffffffffff, .refin = true, .refout = true, .xorout = 0xffffffffffffffff, .check = 0xb90956c775a41001, .residue = 0x5300000000000000 }; + +pub const Crc64GoIso = Crc(u64, crc_64_go_iso); + +test "CRC-64/GO-ISO" { + try testing.expectEqual(crc_64_go_iso.check, Crc64GoIso.hash("123456789")); + + var c = Crc64GoIso.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_64_go_iso.check, c.final()); +} + +const crc_64_ms: Algorithm(u64) = .{ .poly = 0x259c84cba6426349, .init = 0xffffffffffffffff, .refin = true, .refout = true, .xorout = 0x0000000000000000, .check = 0x75d4b74f024eceea, .residue = 0x0000000000000000 }; + +pub const Crc64Ms = Crc(u64, crc_64_ms); + +test "CRC-64/MS" { + try testing.expectEqual(crc_64_ms.check, Crc64Ms.hash("123456789")); + + var c = Crc64Ms.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_64_ms.check, c.final()); +} + +const crc_64_redis: Algorithm(u64) = .{ .poly = 0xad93d23594c935a9, .init = 0x0000000000000000, .refin = true, .refout = true, .xorout = 0x0000000000000000, .check = 0xe9c6d914c4b8d9ca, .residue = 0x0000000000000000 }; + +pub const Crc64Redis = Crc(u64, crc_64_redis); + +test "CRC-64/REDIS" { + try testing.expectEqual(crc_64_redis.check, Crc64Redis.hash("123456789")); + + var c = Crc64Redis.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_64_redis.check, c.final()); +} + +const crc_64_we: Algorithm(u64) = .{ .poly = 0x42f0e1eba9ea3693, .init = 0xffffffffffffffff, .refin = false, .refout = false, .xorout = 0xffffffffffffffff, .check = 0x62ec59e3f1a4f00a, .residue = 0xfcacbebd5931a992 }; + +pub const Crc64We = Crc(u64, crc_64_we); + +test "CRC-64/WE" { + try testing.expectEqual(crc_64_we.check, Crc64We.hash("123456789")); + + var c = Crc64We.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_64_we.check, c.final()); +} + +const crc_64_xz: Algorithm(u64) = .{ .poly = 0x42f0e1eba9ea3693, .init = 0xffffffffffffffff, .refin = true, .refout = true, .xorout = 0xffffffffffffffff, .check = 0x995dc9bbdf1939fa, .residue = 0x49958c9abd7d353f }; + +pub const Crc64Xz = Crc(u64, crc_64_xz); + +test "CRC-64/XZ" { + try testing.expectEqual(crc_64_xz.check, Crc64Xz.hash("123456789")); + + var c = Crc64Xz.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_64_xz.check, c.final()); +} + +const crc_82_darc: Algorithm(u82) = .{ .poly = 0x0308c0111011401440411, .init = 0x000000000000000000000, .refin = true, .refout = true, .xorout = 0x000000000000000000000, .check = 0x09ea83f625023801fd612, .residue = 0x000000000000000000000 }; + +pub const Crc82Darc = Crc(u82, crc_82_darc); + +test "CRC-82/DARC" { + try testing.expectEqual(crc_82_darc.check, Crc82Darc.hash("123456789")); + + var c = Crc82Darc.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(crc_82_darc.check, c.final()); +} |
