diff --git a/lib/std/hash/crc.zig b/lib/std/hash/crc.zig index 0ac4de761ef9ae8c6a1d7a4a7b927ee75f1cd4f6..732c03e721cfaa273a372f76e159ea81bb255b9b 100644 --- a/lib/std/hash/crc.zig +++ b/lib/std/hash/crc.zig @@ -1,285 +1,911 @@ -// There are two implementations of CRC32 implemented with the following key characteristics: -// -// - Crc32WithPoly uses 8Kb of tables but is ~10x faster than the small method. -// -// - Crc32SmallWithPoly uses only 64 bytes of memory but is slower. Be aware that this is -// still moderately fast just slow relative to the slicing approach. +//! This file is auto-generated by tools/update_crc_catalog.zig. -const std = @import("std"); -const builtin = @import("builtin"); -const debug = std.debug; -const testing = std.testing; +const impl = @import("crc/impl.zig"); -pub usingnamespace @import("crc/catalog.zig"); - -pub fn Algorithm(comptime W: type) type { - return struct { - polynomial: W, - initial: W, - reflect_input: bool, - reflect_output: bool, - xor_output: 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.reflect_input) - @bitReverse(@as(I, algorithm.polynomial)) >> (@bitSizeOf(I) - @bitSizeOf(W)) - else - @as(I, algorithm.polynomial) << (@bitSizeOf(I) - @bitSizeOf(W)); - - var table: [256]I = undefined; - for (&table, 0..) |*e, i| { - var crc: I = i; - if (algorithm.reflect_input) { - 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.reflect_input) - @bitReverse(@as(I, algorithm.initial)) >> (@bitSizeOf(I) - @bitSizeOf(W)) - else - @as(I, algorithm.initial) << (@bitSizeOf(I) - @bitSizeOf(W)); - return Self{ .crc = initial }; - } - - inline fn tableEntry(index: I) I { - return lookup_table[@as(u8, @intCast(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.reflect_input) { - 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.reflect_input != algorithm.reflect_output) { - c = @bitReverse(c); - } - if (!algorithm.reflect_output) { - c >>= @bitSizeOf(I) - @bitSizeOf(W); - } - return @as(W, @intCast(c ^ algorithm.xor_output)); - } - - 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, - Koopman = 0xeb31d82e, - _, -}; +pub const Crc = impl.Crc; +pub const Polynomial = impl.Polynomial; +pub const Crc32WithPoly = impl.Crc32WithPoly; +pub const Crc32SmallWithPoly = impl.Crc32SmallWithPoly; // IEEE is by far the most common CRC and so is aliased by default. pub const Crc32 = Crc32WithPoly(.IEEE); -// slicing-by-8 crc32 implementation. -pub fn Crc32WithPoly(comptime poly: Polynomial) type { - return struct { - const Self = @This(); - const lookup_tables = block: { - @setEvalBranchQuota(20000); - var tables: [8][256]u32 = undefined; - - for (&tables[0], 0..) |*e, i| { - var crc = @as(u32, @intCast(i)); - var j: usize = 0; - while (j < 8) : (j += 1) { - if (crc & 1 == 1) { - crc = (crc >> 1) ^ @intFromEnum(poly); - } else { - crc = (crc >> 1); - } - } - e.* = crc; - } - - var i: usize = 0; - while (i < 256) : (i += 1) { - var crc = tables[0][i]; - var j: usize = 1; - while (j < 8) : (j += 1) { - const index: u8 = @truncate(crc); - crc = tables[0][index] ^ (crc >> 8); - tables[j][i] = crc; - } - } - - break :block tables; - }; - - crc: u32, - - pub fn init() Self { - return Self{ .crc = 0xffffffff }; - } - - pub fn update(self: *Self, input: []const u8) void { - var i: usize = 0; - while (i + 8 <= input.len) : (i += 8) { - const p = input[i..][0..8]; - - // Unrolling this way gives ~50Mb/s increase - self.crc ^= std.mem.readInt(u32, p[0..4], .little); - - self.crc = - lookup_tables[0][p[7]] ^ - lookup_tables[1][p[6]] ^ - lookup_tables[2][p[5]] ^ - lookup_tables[3][p[4]] ^ - lookup_tables[4][@as(u8, @truncate(self.crc >> 24))] ^ - lookup_tables[5][@as(u8, @truncate(self.crc >> 16))] ^ - lookup_tables[6][@as(u8, @truncate(self.crc >> 8))] ^ - lookup_tables[7][@as(u8, @truncate(self.crc >> 0))]; - } - - while (i < input.len) : (i += 1) { - const index = @as(u8, @truncate(self.crc)) ^ input[i]; - self.crc = (self.crc >> 8) ^ lookup_tables[0][index]; - } - } - - pub fn final(self: *Self) u32 { - return ~self.crc; - } - - pub fn hash(input: []const u8) u32 { - var c = Self.init(); - c.update(input); - return c.final(); - } - }; +test { + _ = @import("crc/test.zig"); } -const verify = @import("verify.zig"); +pub const Crc3Gsm = Crc(u3, .{ + .polynomial = 0x3, + .initial = 0x0, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x7, +}); -test "crc32 ieee" { - const Crc32Ieee = Crc32WithPoly(.IEEE); +pub const Crc3Rohc = Crc(u3, .{ + .polynomial = 0x3, + .initial = 0x7, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0x0, +}); - try testing.expect(Crc32Ieee.hash("") == 0x00000000); - try testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43); - try testing.expect(Crc32Ieee.hash("abc") == 0x352441c2); -} +pub const Crc4G704 = Crc(u4, .{ + .polynomial = 0x3, + .initial = 0x0, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0x0, +}); -test "crc32 castagnoli" { - const Crc32Castagnoli = Crc32WithPoly(.Castagnoli); +pub const Crc4Interlaken = Crc(u4, .{ + .polynomial = 0x3, + .initial = 0xf, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0xf, +}); - try testing.expect(Crc32Castagnoli.hash("") == 0x00000000); - try testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330); - try testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7); -} +pub const Crc5EpcC1g2 = Crc(u5, .{ + .polynomial = 0x09, + .initial = 0x09, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x00, +}); -test "crc32 iterative" { - try verify.iterativeApi(Crc32WithPoly(.IEEE)); -} +pub const Crc5G704 = Crc(u5, .{ + .polynomial = 0x15, + .initial = 0x00, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0x00, +}); -// half-byte lookup table implementation. -pub fn Crc32SmallWithPoly(comptime poly: Polynomial) type { - return struct { - const Self = @This(); - const lookup_table = block: { - var table: [16]u32 = undefined; - - for (&table, 0..) |*e, i| { - var crc = @as(u32, @intCast(i * 16)); - var j: usize = 0; - while (j < 8) : (j += 1) { - if (crc & 1 == 1) { - crc = (crc >> 1) ^ @intFromEnum(poly); - } else { - crc = (crc >> 1); - } - } - e.* = crc; - } - - break :block table; - }; - - crc: u32, - - pub fn init() Self { - return Self{ .crc = 0xffffffff }; - } - - pub fn update(self: *Self, input: []const u8) void { - for (input) |b| { - self.crc = lookup_table[@as(u4, @truncate(self.crc ^ (b >> 0)))] ^ (self.crc >> 4); - self.crc = lookup_table[@as(u4, @truncate(self.crc ^ (b >> 4)))] ^ (self.crc >> 4); - } - } - - pub fn final(self: *Self) u32 { - return ~self.crc; - } - - pub fn hash(input: []const u8) u32 { - var c = Self.init(); - c.update(input); - return c.final(); - } - }; -} +pub const Crc5Usb = Crc(u5, .{ + .polynomial = 0x05, + .initial = 0x1f, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0x1f, +}); -test "small crc32 iterative" { - try verify.iterativeApi(Crc32SmallWithPoly(.IEEE)); -} +pub const Crc6Cdma2000A = Crc(u6, .{ + .polynomial = 0x27, + .initial = 0x3f, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x00, +}); -test "small crc32 ieee" { - const Crc32Ieee = Crc32SmallWithPoly(.IEEE); +pub const Crc6Cdma2000B = Crc(u6, .{ + .polynomial = 0x07, + .initial = 0x3f, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x00, +}); - try testing.expect(Crc32Ieee.hash("") == 0x00000000); - try testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43); - try testing.expect(Crc32Ieee.hash("abc") == 0x352441c2); -} +pub const Crc6Darc = Crc(u6, .{ + .polynomial = 0x19, + .initial = 0x00, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0x00, +}); -test "small crc32 castagnoli" { - const Crc32Castagnoli = Crc32SmallWithPoly(.Castagnoli); +pub const Crc6G704 = Crc(u6, .{ + .polynomial = 0x03, + .initial = 0x00, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0x00, +}); - try testing.expect(Crc32Castagnoli.hash("") == 0x00000000); - try testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330); - try testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7); -} +pub const Crc6Gsm = Crc(u6, .{ + .polynomial = 0x2f, + .initial = 0x00, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x3f, +}); + +pub const Crc7Mmc = Crc(u7, .{ + .polynomial = 0x09, + .initial = 0x00, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x00, +}); + +pub const Crc7Rohc = Crc(u7, .{ + .polynomial = 0x4f, + .initial = 0x7f, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0x00, +}); + +pub const Crc7Umts = Crc(u7, .{ + .polynomial = 0x45, + .initial = 0x00, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x00, +}); + +pub const Crc8Autosar = Crc(u8, .{ + .polynomial = 0x2f, + .initial = 0xff, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0xff, +}); + +pub const Crc8Bluetooth = Crc(u8, .{ + .polynomial = 0xa7, + .initial = 0x00, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0x00, +}); + +pub const Crc8Cdma2000 = Crc(u8, .{ + .polynomial = 0x9b, + .initial = 0xff, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x00, +}); + +pub const Crc8Darc = Crc(u8, .{ + .polynomial = 0x39, + .initial = 0x00, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0x00, +}); + +pub const Crc8DvbS2 = Crc(u8, .{ + .polynomial = 0xd5, + .initial = 0x00, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x00, +}); + +pub const Crc8GsmA = Crc(u8, .{ + .polynomial = 0x1d, + .initial = 0x00, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x00, +}); + +pub const Crc8GsmB = Crc(u8, .{ + .polynomial = 0x49, + .initial = 0x00, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0xff, +}); + +pub const Crc8Hitag = Crc(u8, .{ + .polynomial = 0x1d, + .initial = 0xff, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x00, +}); + +pub const Crc8I4321 = Crc(u8, .{ + .polynomial = 0x07, + .initial = 0x00, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x55, +}); + +pub const Crc8ICode = Crc(u8, .{ + .polynomial = 0x1d, + .initial = 0xfd, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x00, +}); + +pub const Crc8Lte = Crc(u8, .{ + .polynomial = 0x9b, + .initial = 0x00, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x00, +}); + +pub const Crc8MaximDow = Crc(u8, .{ + .polynomial = 0x31, + .initial = 0x00, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0x00, +}); + +pub const Crc8MifareMad = Crc(u8, .{ + .polynomial = 0x1d, + .initial = 0xc7, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x00, +}); + +pub const Crc8Nrsc5 = Crc(u8, .{ + .polynomial = 0x31, + .initial = 0xff, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x00, +}); + +pub const Crc8Opensafety = Crc(u8, .{ + .polynomial = 0x2f, + .initial = 0x00, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x00, +}); + +pub const Crc8Rohc = Crc(u8, .{ + .polynomial = 0x07, + .initial = 0xff, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0x00, +}); + +pub const Crc8SaeJ1850 = Crc(u8, .{ + .polynomial = 0x1d, + .initial = 0xff, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0xff, +}); + +pub const Crc8Smbus = Crc(u8, .{ + .polynomial = 0x07, + .initial = 0x00, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x00, +}); + +pub const Crc8Tech3250 = Crc(u8, .{ + .polynomial = 0x1d, + .initial = 0xff, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0x00, +}); + +pub const Crc8Wcdma = Crc(u8, .{ + .polynomial = 0x9b, + .initial = 0x00, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0x00, +}); + +pub const Crc10Atm = Crc(u10, .{ + .polynomial = 0x233, + .initial = 0x000, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x000, +}); + +pub const Crc10Cdma2000 = Crc(u10, .{ + .polynomial = 0x3d9, + .initial = 0x3ff, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x000, +}); + +pub const Crc10Gsm = Crc(u10, .{ + .polynomial = 0x175, + .initial = 0x000, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x3ff, +}); + +pub const Crc11Flexray = Crc(u11, .{ + .polynomial = 0x385, + .initial = 0x01a, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x000, +}); + +pub const Crc11Umts = Crc(u11, .{ + .polynomial = 0x307, + .initial = 0x000, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x000, +}); + +pub const Crc12Cdma2000 = Crc(u12, .{ + .polynomial = 0xf13, + .initial = 0xfff, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x000, +}); + +pub const Crc12Dect = Crc(u12, .{ + .polynomial = 0x80f, + .initial = 0x000, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x000, +}); + +pub const Crc12Gsm = Crc(u12, .{ + .polynomial = 0xd31, + .initial = 0x000, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0xfff, +}); + +pub const Crc12Umts = Crc(u12, .{ + .polynomial = 0x80f, + .initial = 0x000, + .reflect_input = false, + .reflect_output = true, + .xor_output = 0x000, +}); + +pub const Crc13Bbc = Crc(u13, .{ + .polynomial = 0x1cf5, + .initial = 0x0000, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x0000, +}); + +pub const Crc14Darc = Crc(u14, .{ + .polynomial = 0x0805, + .initial = 0x0000, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0x0000, +}); + +pub const Crc14Gsm = Crc(u14, .{ + .polynomial = 0x202d, + .initial = 0x0000, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x3fff, +}); + +pub const Crc15Can = Crc(u15, .{ + .polynomial = 0x4599, + .initial = 0x0000, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x0000, +}); + +pub const Crc15Mpt1327 = Crc(u15, .{ + .polynomial = 0x6815, + .initial = 0x0000, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x0001, +}); + +pub const Crc16Arc = Crc(u16, .{ + .polynomial = 0x8005, + .initial = 0x0000, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0x0000, +}); + +pub const Crc16Cdma2000 = Crc(u16, .{ + .polynomial = 0xc867, + .initial = 0xffff, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x0000, +}); + +pub const Crc16Cms = Crc(u16, .{ + .polynomial = 0x8005, + .initial = 0xffff, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x0000, +}); + +pub const Crc16Dds110 = Crc(u16, .{ + .polynomial = 0x8005, + .initial = 0x800d, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x0000, +}); + +pub const Crc16DectR = Crc(u16, .{ + .polynomial = 0x0589, + .initial = 0x0000, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x0001, +}); + +pub const Crc16DectX = Crc(u16, .{ + .polynomial = 0x0589, + .initial = 0x0000, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x0000, +}); + +pub const Crc16Dnp = Crc(u16, .{ + .polynomial = 0x3d65, + .initial = 0x0000, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0xffff, +}); + +pub const Crc16En13757 = Crc(u16, .{ + .polynomial = 0x3d65, + .initial = 0x0000, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0xffff, +}); + +pub const Crc16Genibus = Crc(u16, .{ + .polynomial = 0x1021, + .initial = 0xffff, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0xffff, +}); + +pub const Crc16Gsm = Crc(u16, .{ + .polynomial = 0x1021, + .initial = 0x0000, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0xffff, +}); + +pub const Crc16Ibm3740 = Crc(u16, .{ + .polynomial = 0x1021, + .initial = 0xffff, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x0000, +}); + +pub const Crc16IbmSdlc = Crc(u16, .{ + .polynomial = 0x1021, + .initial = 0xffff, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0xffff, +}); + +pub const Crc16IsoIec144433A = Crc(u16, .{ + .polynomial = 0x1021, + .initial = 0xc6c6, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0x0000, +}); + +pub const Crc16Kermit = Crc(u16, .{ + .polynomial = 0x1021, + .initial = 0x0000, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0x0000, +}); + +pub const Crc16Lj1200 = Crc(u16, .{ + .polynomial = 0x6f63, + .initial = 0x0000, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x0000, +}); + +pub const Crc16M17 = Crc(u16, .{ + .polynomial = 0x5935, + .initial = 0xffff, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x0000, +}); + +pub const Crc16MaximDow = Crc(u16, .{ + .polynomial = 0x8005, + .initial = 0x0000, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0xffff, +}); + +pub const Crc16Mcrf4xx = Crc(u16, .{ + .polynomial = 0x1021, + .initial = 0xffff, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0x0000, +}); + +pub const Crc16Modbus = Crc(u16, .{ + .polynomial = 0x8005, + .initial = 0xffff, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0x0000, +}); + +pub const Crc16Nrsc5 = Crc(u16, .{ + .polynomial = 0x080b, + .initial = 0xffff, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0x0000, +}); + +pub const Crc16OpensafetyA = Crc(u16, .{ + .polynomial = 0x5935, + .initial = 0x0000, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x0000, +}); + +pub const Crc16OpensafetyB = Crc(u16, .{ + .polynomial = 0x755b, + .initial = 0x0000, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x0000, +}); + +pub const Crc16Profibus = Crc(u16, .{ + .polynomial = 0x1dcf, + .initial = 0xffff, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0xffff, +}); + +pub const Crc16Riello = Crc(u16, .{ + .polynomial = 0x1021, + .initial = 0xb2aa, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0x0000, +}); + +pub const Crc16SpiFujitsu = Crc(u16, .{ + .polynomial = 0x1021, + .initial = 0x1d0f, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x0000, +}); + +pub const Crc16T10Dif = Crc(u16, .{ + .polynomial = 0x8bb7, + .initial = 0x0000, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x0000, +}); + +pub const Crc16Teledisk = Crc(u16, .{ + .polynomial = 0xa097, + .initial = 0x0000, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x0000, +}); + +pub const Crc16Tms37157 = Crc(u16, .{ + .polynomial = 0x1021, + .initial = 0x89ec, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0x0000, +}); + +pub const Crc16Umts = Crc(u16, .{ + .polynomial = 0x8005, + .initial = 0x0000, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x0000, +}); + +pub const Crc16Usb = Crc(u16, .{ + .polynomial = 0x8005, + .initial = 0xffff, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0xffff, +}); + +pub const Crc16Xmodem = Crc(u16, .{ + .polynomial = 0x1021, + .initial = 0x0000, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x0000, +}); + +pub const Crc17CanFd = Crc(u17, .{ + .polynomial = 0x1685b, + .initial = 0x00000, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x00000, +}); + +pub const Crc21CanFd = Crc(u21, .{ + .polynomial = 0x102899, + .initial = 0x000000, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x000000, +}); + +pub const Crc24Ble = Crc(u24, .{ + .polynomial = 0x00065b, + .initial = 0x555555, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0x000000, +}); + +pub const Crc24FlexrayA = Crc(u24, .{ + .polynomial = 0x5d6dcb, + .initial = 0xfedcba, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x000000, +}); + +pub const Crc24FlexrayB = Crc(u24, .{ + .polynomial = 0x5d6dcb, + .initial = 0xabcdef, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x000000, +}); + +pub const Crc24Interlaken = Crc(u24, .{ + .polynomial = 0x328b63, + .initial = 0xffffff, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0xffffff, +}); + +pub const Crc24LteA = Crc(u24, .{ + .polynomial = 0x864cfb, + .initial = 0x000000, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x000000, +}); + +pub const Crc24LteB = Crc(u24, .{ + .polynomial = 0x800063, + .initial = 0x000000, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x000000, +}); + +pub const Crc24Openpgp = Crc(u24, .{ + .polynomial = 0x864cfb, + .initial = 0xb704ce, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x000000, +}); + +pub const Crc24Os9 = Crc(u24, .{ + .polynomial = 0x800063, + .initial = 0xffffff, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0xffffff, +}); + +pub const Crc30Cdma = Crc(u30, .{ + .polynomial = 0x2030b9c7, + .initial = 0x3fffffff, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x3fffffff, +}); + +pub const Crc31Philips = Crc(u31, .{ + .polynomial = 0x04c11db7, + .initial = 0x7fffffff, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x7fffffff, +}); + +pub const Crc32Aixm = Crc(u32, .{ + .polynomial = 0x814141ab, + .initial = 0x00000000, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x00000000, +}); + +pub const Crc32Autosar = Crc(u32, .{ + .polynomial = 0xf4acfb13, + .initial = 0xffffffff, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0xffffffff, +}); + +pub const Crc32Base91D = Crc(u32, .{ + .polynomial = 0xa833982b, + .initial = 0xffffffff, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0xffffffff, +}); + +pub const Crc32Bzip2 = Crc(u32, .{ + .polynomial = 0x04c11db7, + .initial = 0xffffffff, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0xffffffff, +}); + +pub const Crc32CdRomEdc = Crc(u32, .{ + .polynomial = 0x8001801b, + .initial = 0x00000000, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0x00000000, +}); + +pub const Crc32Cksum = Crc(u32, .{ + .polynomial = 0x04c11db7, + .initial = 0x00000000, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0xffffffff, +}); + +pub const Crc32Iscsi = Crc(u32, .{ + .polynomial = 0x1edc6f41, + .initial = 0xffffffff, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0xffffffff, +}); + +pub const Crc32IsoHdlc = Crc(u32, .{ + .polynomial = 0x04c11db7, + .initial = 0xffffffff, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0xffffffff, +}); + +pub const Crc32Jamcrc = Crc(u32, .{ + .polynomial = 0x04c11db7, + .initial = 0xffffffff, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0x00000000, +}); + +pub const Crc32Mef = Crc(u32, .{ + .polynomial = 0x741b8cd7, + .initial = 0xffffffff, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0x00000000, +}); + +pub const Crc32Mpeg2 = Crc(u32, .{ + .polynomial = 0x04c11db7, + .initial = 0xffffffff, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x00000000, +}); + +pub const Crc32Xfer = Crc(u32, .{ + .polynomial = 0x000000af, + .initial = 0x00000000, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x00000000, +}); + +pub const Crc40Gsm = Crc(u40, .{ + .polynomial = 0x0004820009, + .initial = 0x0000000000, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0xffffffffff, +}); + +pub const Crc64Ecma182 = Crc(u64, .{ + .polynomial = 0x42f0e1eba9ea3693, + .initial = 0x0000000000000000, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0x0000000000000000, +}); + +pub const Crc64GoIso = Crc(u64, .{ + .polynomial = 0x000000000000001b, + .initial = 0xffffffffffffffff, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0xffffffffffffffff, +}); + +pub const Crc64Ms = Crc(u64, .{ + .polynomial = 0x259c84cba6426349, + .initial = 0xffffffffffffffff, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0x0000000000000000, +}); + +pub const Crc64Redis = Crc(u64, .{ + .polynomial = 0xad93d23594c935a9, + .initial = 0x0000000000000000, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0x0000000000000000, +}); + +pub const Crc64We = Crc(u64, .{ + .polynomial = 0x42f0e1eba9ea3693, + .initial = 0xffffffffffffffff, + .reflect_input = false, + .reflect_output = false, + .xor_output = 0xffffffffffffffff, +}); + +pub const Crc64Xz = Crc(u64, .{ + .polynomial = 0x42f0e1eba9ea3693, + .initial = 0xffffffffffffffff, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0xffffffffffffffff, +}); + +pub const Crc82Darc = Crc(u82, .{ + .polynomial = 0x0308c0111011401440411, + .initial = 0x000000000000000000000, + .reflect_input = true, + .reflect_output = true, + .xor_output = 0x000000000000000000000, +}); diff --git a/lib/std/hash/crc/catalog.zig b/lib/std/hash/crc/catalog.zig deleted file mode 100644 index ed08accce6431116cb85c6f72e7c9ce07275dcb8..0000000000000000000000000000000000000000 --- a/lib/std/hash/crc/catalog.zig +++ /dev/null @@ -1,903 +0,0 @@ -//! This file is auto-generated by tools/update_crc_catalog.zig. - -const Crc = @import("../crc.zig").Crc; - -test { - _ = @import("catalog_test.zig"); -} - -pub const Crc3Gsm = Crc(u3, .{ - .polynomial = 0x3, - .initial = 0x0, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x7, -}); - -pub const Crc3Rohc = Crc(u3, .{ - .polynomial = 0x3, - .initial = 0x7, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0x0, -}); - -pub const Crc4G704 = Crc(u4, .{ - .polynomial = 0x3, - .initial = 0x0, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0x0, -}); - -pub const Crc4Interlaken = Crc(u4, .{ - .polynomial = 0x3, - .initial = 0xf, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0xf, -}); - -pub const Crc5EpcC1g2 = Crc(u5, .{ - .polynomial = 0x09, - .initial = 0x09, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x00, -}); - -pub const Crc5G704 = Crc(u5, .{ - .polynomial = 0x15, - .initial = 0x00, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0x00, -}); - -pub const Crc5Usb = Crc(u5, .{ - .polynomial = 0x05, - .initial = 0x1f, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0x1f, -}); - -pub const Crc6Cdma2000A = Crc(u6, .{ - .polynomial = 0x27, - .initial = 0x3f, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x00, -}); - -pub const Crc6Cdma2000B = Crc(u6, .{ - .polynomial = 0x07, - .initial = 0x3f, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x00, -}); - -pub const Crc6Darc = Crc(u6, .{ - .polynomial = 0x19, - .initial = 0x00, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0x00, -}); - -pub const Crc6G704 = Crc(u6, .{ - .polynomial = 0x03, - .initial = 0x00, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0x00, -}); - -pub const Crc6Gsm = Crc(u6, .{ - .polynomial = 0x2f, - .initial = 0x00, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x3f, -}); - -pub const Crc7Mmc = Crc(u7, .{ - .polynomial = 0x09, - .initial = 0x00, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x00, -}); - -pub const Crc7Rohc = Crc(u7, .{ - .polynomial = 0x4f, - .initial = 0x7f, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0x00, -}); - -pub const Crc7Umts = Crc(u7, .{ - .polynomial = 0x45, - .initial = 0x00, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x00, -}); - -pub const Crc8Autosar = Crc(u8, .{ - .polynomial = 0x2f, - .initial = 0xff, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0xff, -}); - -pub const Crc8Bluetooth = Crc(u8, .{ - .polynomial = 0xa7, - .initial = 0x00, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0x00, -}); - -pub const Crc8Cdma2000 = Crc(u8, .{ - .polynomial = 0x9b, - .initial = 0xff, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x00, -}); - -pub const Crc8Darc = Crc(u8, .{ - .polynomial = 0x39, - .initial = 0x00, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0x00, -}); - -pub const Crc8DvbS2 = Crc(u8, .{ - .polynomial = 0xd5, - .initial = 0x00, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x00, -}); - -pub const Crc8GsmA = Crc(u8, .{ - .polynomial = 0x1d, - .initial = 0x00, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x00, -}); - -pub const Crc8GsmB = Crc(u8, .{ - .polynomial = 0x49, - .initial = 0x00, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0xff, -}); - -pub const Crc8Hitag = Crc(u8, .{ - .polynomial = 0x1d, - .initial = 0xff, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x00, -}); - -pub const Crc8I4321 = Crc(u8, .{ - .polynomial = 0x07, - .initial = 0x00, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x55, -}); - -pub const Crc8ICode = Crc(u8, .{ - .polynomial = 0x1d, - .initial = 0xfd, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x00, -}); - -pub const Crc8Lte = Crc(u8, .{ - .polynomial = 0x9b, - .initial = 0x00, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x00, -}); - -pub const Crc8MaximDow = Crc(u8, .{ - .polynomial = 0x31, - .initial = 0x00, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0x00, -}); - -pub const Crc8MifareMad = Crc(u8, .{ - .polynomial = 0x1d, - .initial = 0xc7, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x00, -}); - -pub const Crc8Nrsc5 = Crc(u8, .{ - .polynomial = 0x31, - .initial = 0xff, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x00, -}); - -pub const Crc8Opensafety = Crc(u8, .{ - .polynomial = 0x2f, - .initial = 0x00, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x00, -}); - -pub const Crc8Rohc = Crc(u8, .{ - .polynomial = 0x07, - .initial = 0xff, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0x00, -}); - -pub const Crc8SaeJ1850 = Crc(u8, .{ - .polynomial = 0x1d, - .initial = 0xff, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0xff, -}); - -pub const Crc8Smbus = Crc(u8, .{ - .polynomial = 0x07, - .initial = 0x00, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x00, -}); - -pub const Crc8Tech3250 = Crc(u8, .{ - .polynomial = 0x1d, - .initial = 0xff, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0x00, -}); - -pub const Crc8Wcdma = Crc(u8, .{ - .polynomial = 0x9b, - .initial = 0x00, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0x00, -}); - -pub const Crc10Atm = Crc(u10, .{ - .polynomial = 0x233, - .initial = 0x000, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x000, -}); - -pub const Crc10Cdma2000 = Crc(u10, .{ - .polynomial = 0x3d9, - .initial = 0x3ff, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x000, -}); - -pub const Crc10Gsm = Crc(u10, .{ - .polynomial = 0x175, - .initial = 0x000, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x3ff, -}); - -pub const Crc11Flexray = Crc(u11, .{ - .polynomial = 0x385, - .initial = 0x01a, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x000, -}); - -pub const Crc11Umts = Crc(u11, .{ - .polynomial = 0x307, - .initial = 0x000, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x000, -}); - -pub const Crc12Cdma2000 = Crc(u12, .{ - .polynomial = 0xf13, - .initial = 0xfff, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x000, -}); - -pub const Crc12Dect = Crc(u12, .{ - .polynomial = 0x80f, - .initial = 0x000, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x000, -}); - -pub const Crc12Gsm = Crc(u12, .{ - .polynomial = 0xd31, - .initial = 0x000, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0xfff, -}); - -pub const Crc12Umts = Crc(u12, .{ - .polynomial = 0x80f, - .initial = 0x000, - .reflect_input = false, - .reflect_output = true, - .xor_output = 0x000, -}); - -pub const Crc13Bbc = Crc(u13, .{ - .polynomial = 0x1cf5, - .initial = 0x0000, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x0000, -}); - -pub const Crc14Darc = Crc(u14, .{ - .polynomial = 0x0805, - .initial = 0x0000, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0x0000, -}); - -pub const Crc14Gsm = Crc(u14, .{ - .polynomial = 0x202d, - .initial = 0x0000, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x3fff, -}); - -pub const Crc15Can = Crc(u15, .{ - .polynomial = 0x4599, - .initial = 0x0000, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x0000, -}); - -pub const Crc15Mpt1327 = Crc(u15, .{ - .polynomial = 0x6815, - .initial = 0x0000, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x0001, -}); - -pub const Crc16Arc = Crc(u16, .{ - .polynomial = 0x8005, - .initial = 0x0000, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0x0000, -}); - -pub const Crc16Cdma2000 = Crc(u16, .{ - .polynomial = 0xc867, - .initial = 0xffff, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x0000, -}); - -pub const Crc16Cms = Crc(u16, .{ - .polynomial = 0x8005, - .initial = 0xffff, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x0000, -}); - -pub const Crc16Dds110 = Crc(u16, .{ - .polynomial = 0x8005, - .initial = 0x800d, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x0000, -}); - -pub const Crc16DectR = Crc(u16, .{ - .polynomial = 0x0589, - .initial = 0x0000, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x0001, -}); - -pub const Crc16DectX = Crc(u16, .{ - .polynomial = 0x0589, - .initial = 0x0000, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x0000, -}); - -pub const Crc16Dnp = Crc(u16, .{ - .polynomial = 0x3d65, - .initial = 0x0000, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0xffff, -}); - -pub const Crc16En13757 = Crc(u16, .{ - .polynomial = 0x3d65, - .initial = 0x0000, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0xffff, -}); - -pub const Crc16Genibus = Crc(u16, .{ - .polynomial = 0x1021, - .initial = 0xffff, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0xffff, -}); - -pub const Crc16Gsm = Crc(u16, .{ - .polynomial = 0x1021, - .initial = 0x0000, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0xffff, -}); - -pub const Crc16Ibm3740 = Crc(u16, .{ - .polynomial = 0x1021, - .initial = 0xffff, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x0000, -}); - -pub const Crc16IbmSdlc = Crc(u16, .{ - .polynomial = 0x1021, - .initial = 0xffff, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0xffff, -}); - -pub const Crc16IsoIec144433A = Crc(u16, .{ - .polynomial = 0x1021, - .initial = 0xc6c6, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0x0000, -}); - -pub const Crc16Kermit = Crc(u16, .{ - .polynomial = 0x1021, - .initial = 0x0000, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0x0000, -}); - -pub const Crc16Lj1200 = Crc(u16, .{ - .polynomial = 0x6f63, - .initial = 0x0000, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x0000, -}); - -pub const Crc16M17 = Crc(u16, .{ - .polynomial = 0x5935, - .initial = 0xffff, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x0000, -}); - -pub const Crc16MaximDow = Crc(u16, .{ - .polynomial = 0x8005, - .initial = 0x0000, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0xffff, -}); - -pub const Crc16Mcrf4xx = Crc(u16, .{ - .polynomial = 0x1021, - .initial = 0xffff, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0x0000, -}); - -pub const Crc16Modbus = Crc(u16, .{ - .polynomial = 0x8005, - .initial = 0xffff, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0x0000, -}); - -pub const Crc16Nrsc5 = Crc(u16, .{ - .polynomial = 0x080b, - .initial = 0xffff, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0x0000, -}); - -pub const Crc16OpensafetyA = Crc(u16, .{ - .polynomial = 0x5935, - .initial = 0x0000, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x0000, -}); - -pub const Crc16OpensafetyB = Crc(u16, .{ - .polynomial = 0x755b, - .initial = 0x0000, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x0000, -}); - -pub const Crc16Profibus = Crc(u16, .{ - .polynomial = 0x1dcf, - .initial = 0xffff, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0xffff, -}); - -pub const Crc16Riello = Crc(u16, .{ - .polynomial = 0x1021, - .initial = 0xb2aa, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0x0000, -}); - -pub const Crc16SpiFujitsu = Crc(u16, .{ - .polynomial = 0x1021, - .initial = 0x1d0f, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x0000, -}); - -pub const Crc16T10Dif = Crc(u16, .{ - .polynomial = 0x8bb7, - .initial = 0x0000, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x0000, -}); - -pub const Crc16Teledisk = Crc(u16, .{ - .polynomial = 0xa097, - .initial = 0x0000, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x0000, -}); - -pub const Crc16Tms37157 = Crc(u16, .{ - .polynomial = 0x1021, - .initial = 0x89ec, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0x0000, -}); - -pub const Crc16Umts = Crc(u16, .{ - .polynomial = 0x8005, - .initial = 0x0000, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x0000, -}); - -pub const Crc16Usb = Crc(u16, .{ - .polynomial = 0x8005, - .initial = 0xffff, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0xffff, -}); - -pub const Crc16Xmodem = Crc(u16, .{ - .polynomial = 0x1021, - .initial = 0x0000, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x0000, -}); - -pub const Crc17CanFd = Crc(u17, .{ - .polynomial = 0x1685b, - .initial = 0x00000, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x00000, -}); - -pub const Crc21CanFd = Crc(u21, .{ - .polynomial = 0x102899, - .initial = 0x000000, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x000000, -}); - -pub const Crc24Ble = Crc(u24, .{ - .polynomial = 0x00065b, - .initial = 0x555555, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0x000000, -}); - -pub const Crc24FlexrayA = Crc(u24, .{ - .polynomial = 0x5d6dcb, - .initial = 0xfedcba, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x000000, -}); - -pub const Crc24FlexrayB = Crc(u24, .{ - .polynomial = 0x5d6dcb, - .initial = 0xabcdef, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x000000, -}); - -pub const Crc24Interlaken = Crc(u24, .{ - .polynomial = 0x328b63, - .initial = 0xffffff, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0xffffff, -}); - -pub const Crc24LteA = Crc(u24, .{ - .polynomial = 0x864cfb, - .initial = 0x000000, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x000000, -}); - -pub const Crc24LteB = Crc(u24, .{ - .polynomial = 0x800063, - .initial = 0x000000, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x000000, -}); - -pub const Crc24Openpgp = Crc(u24, .{ - .polynomial = 0x864cfb, - .initial = 0xb704ce, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x000000, -}); - -pub const Crc24Os9 = Crc(u24, .{ - .polynomial = 0x800063, - .initial = 0xffffff, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0xffffff, -}); - -pub const Crc30Cdma = Crc(u30, .{ - .polynomial = 0x2030b9c7, - .initial = 0x3fffffff, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x3fffffff, -}); - -pub const Crc31Philips = Crc(u31, .{ - .polynomial = 0x04c11db7, - .initial = 0x7fffffff, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x7fffffff, -}); - -pub const Crc32Aixm = Crc(u32, .{ - .polynomial = 0x814141ab, - .initial = 0x00000000, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x00000000, -}); - -pub const Crc32Autosar = Crc(u32, .{ - .polynomial = 0xf4acfb13, - .initial = 0xffffffff, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0xffffffff, -}); - -pub const Crc32Base91D = Crc(u32, .{ - .polynomial = 0xa833982b, - .initial = 0xffffffff, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0xffffffff, -}); - -pub const Crc32Bzip2 = Crc(u32, .{ - .polynomial = 0x04c11db7, - .initial = 0xffffffff, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0xffffffff, -}); - -pub const Crc32CdRomEdc = Crc(u32, .{ - .polynomial = 0x8001801b, - .initial = 0x00000000, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0x00000000, -}); - -pub const Crc32Cksum = Crc(u32, .{ - .polynomial = 0x04c11db7, - .initial = 0x00000000, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0xffffffff, -}); - -pub const Crc32Iscsi = Crc(u32, .{ - .polynomial = 0x1edc6f41, - .initial = 0xffffffff, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0xffffffff, -}); - -pub const Crc32IsoHdlc = Crc(u32, .{ - .polynomial = 0x04c11db7, - .initial = 0xffffffff, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0xffffffff, -}); - -pub const Crc32Jamcrc = Crc(u32, .{ - .polynomial = 0x04c11db7, - .initial = 0xffffffff, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0x00000000, -}); - -pub const Crc32Mef = Crc(u32, .{ - .polynomial = 0x741b8cd7, - .initial = 0xffffffff, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0x00000000, -}); - -pub const Crc32Mpeg2 = Crc(u32, .{ - .polynomial = 0x04c11db7, - .initial = 0xffffffff, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x00000000, -}); - -pub const Crc32Xfer = Crc(u32, .{ - .polynomial = 0x000000af, - .initial = 0x00000000, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x00000000, -}); - -pub const Crc40Gsm = Crc(u40, .{ - .polynomial = 0x0004820009, - .initial = 0x0000000000, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0xffffffffff, -}); - -pub const Crc64Ecma182 = Crc(u64, .{ - .polynomial = 0x42f0e1eba9ea3693, - .initial = 0x0000000000000000, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0x0000000000000000, -}); - -pub const Crc64GoIso = Crc(u64, .{ - .polynomial = 0x000000000000001b, - .initial = 0xffffffffffffffff, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0xffffffffffffffff, -}); - -pub const Crc64Ms = Crc(u64, .{ - .polynomial = 0x259c84cba6426349, - .initial = 0xffffffffffffffff, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0x0000000000000000, -}); - -pub const Crc64Redis = Crc(u64, .{ - .polynomial = 0xad93d23594c935a9, - .initial = 0x0000000000000000, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0x0000000000000000, -}); - -pub const Crc64We = Crc(u64, .{ - .polynomial = 0x42f0e1eba9ea3693, - .initial = 0xffffffffffffffff, - .reflect_input = false, - .reflect_output = false, - .xor_output = 0xffffffffffffffff, -}); - -pub const Crc64Xz = Crc(u64, .{ - .polynomial = 0x42f0e1eba9ea3693, - .initial = 0xffffffffffffffff, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0xffffffffffffffff, -}); - -pub const Crc82Darc = Crc(u82, .{ - .polynomial = 0x0308c0111011401440411, - .initial = 0x000000000000000000000, - .reflect_input = true, - .reflect_output = true, - .xor_output = 0x000000000000000000000, -}); diff --git a/lib/std/hash/crc/catalog_test.zig b/lib/std/hash/crc/catalog_test.zig deleted file mode 100644 index ab89745ca8479506cd535ef992d0d7746ee0f5d8..0000000000000000000000000000000000000000 --- a/lib/std/hash/crc/catalog_test.zig +++ /dev/null @@ -1,1237 +0,0 @@ -//! This file is auto-generated by tools/update_crc_catalog.zig. - -const std = @import("std"); -const testing = std.testing; -const catalog = @import("catalog.zig"); - -test "CRC-3/GSM" { - const Crc3Gsm = catalog.Crc3Gsm; - - try testing.expectEqual(@as(u3, 0x4), Crc3Gsm.hash("123456789")); - - var c = Crc3Gsm.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u3, 0x4), c.final()); -} - -test "CRC-3/ROHC" { - const Crc3Rohc = catalog.Crc3Rohc; - - try testing.expectEqual(@as(u3, 0x6), Crc3Rohc.hash("123456789")); - - var c = Crc3Rohc.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u3, 0x6), c.final()); -} - -test "CRC-4/G-704" { - const Crc4G704 = catalog.Crc4G704; - - try testing.expectEqual(@as(u4, 0x7), Crc4G704.hash("123456789")); - - var c = Crc4G704.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u4, 0x7), c.final()); -} - -test "CRC-4/INTERLAKEN" { - const Crc4Interlaken = catalog.Crc4Interlaken; - - try testing.expectEqual(@as(u4, 0xb), Crc4Interlaken.hash("123456789")); - - var c = Crc4Interlaken.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u4, 0xb), c.final()); -} - -test "CRC-5/EPC-C1G2" { - const Crc5EpcC1g2 = catalog.Crc5EpcC1g2; - - try testing.expectEqual(@as(u5, 0x00), Crc5EpcC1g2.hash("123456789")); - - var c = Crc5EpcC1g2.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u5, 0x00), c.final()); -} - -test "CRC-5/G-704" { - const Crc5G704 = catalog.Crc5G704; - - try testing.expectEqual(@as(u5, 0x07), Crc5G704.hash("123456789")); - - var c = Crc5G704.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u5, 0x07), c.final()); -} - -test "CRC-5/USB" { - const Crc5Usb = catalog.Crc5Usb; - - try testing.expectEqual(@as(u5, 0x19), Crc5Usb.hash("123456789")); - - var c = Crc5Usb.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u5, 0x19), c.final()); -} - -test "CRC-6/CDMA2000-A" { - const Crc6Cdma2000A = catalog.Crc6Cdma2000A; - - try testing.expectEqual(@as(u6, 0x0d), Crc6Cdma2000A.hash("123456789")); - - var c = Crc6Cdma2000A.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u6, 0x0d), c.final()); -} - -test "CRC-6/CDMA2000-B" { - const Crc6Cdma2000B = catalog.Crc6Cdma2000B; - - try testing.expectEqual(@as(u6, 0x3b), Crc6Cdma2000B.hash("123456789")); - - var c = Crc6Cdma2000B.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u6, 0x3b), c.final()); -} - -test "CRC-6/DARC" { - const Crc6Darc = catalog.Crc6Darc; - - try testing.expectEqual(@as(u6, 0x26), Crc6Darc.hash("123456789")); - - var c = Crc6Darc.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u6, 0x26), c.final()); -} - -test "CRC-6/G-704" { - const Crc6G704 = catalog.Crc6G704; - - try testing.expectEqual(@as(u6, 0x06), Crc6G704.hash("123456789")); - - var c = Crc6G704.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u6, 0x06), c.final()); -} - -test "CRC-6/GSM" { - const Crc6Gsm = catalog.Crc6Gsm; - - try testing.expectEqual(@as(u6, 0x13), Crc6Gsm.hash("123456789")); - - var c = Crc6Gsm.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u6, 0x13), c.final()); -} - -test "CRC-7/MMC" { - const Crc7Mmc = catalog.Crc7Mmc; - - try testing.expectEqual(@as(u7, 0x75), Crc7Mmc.hash("123456789")); - - var c = Crc7Mmc.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u7, 0x75), c.final()); -} - -test "CRC-7/ROHC" { - const Crc7Rohc = catalog.Crc7Rohc; - - try testing.expectEqual(@as(u7, 0x53), Crc7Rohc.hash("123456789")); - - var c = Crc7Rohc.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u7, 0x53), c.final()); -} - -test "CRC-7/UMTS" { - const Crc7Umts = catalog.Crc7Umts; - - try testing.expectEqual(@as(u7, 0x61), Crc7Umts.hash("123456789")); - - var c = Crc7Umts.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u7, 0x61), c.final()); -} - -test "CRC-8/AUTOSAR" { - const Crc8Autosar = catalog.Crc8Autosar; - - try testing.expectEqual(@as(u8, 0xdf), Crc8Autosar.hash("123456789")); - - var c = Crc8Autosar.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u8, 0xdf), c.final()); -} - -test "CRC-8/BLUETOOTH" { - const Crc8Bluetooth = catalog.Crc8Bluetooth; - - try testing.expectEqual(@as(u8, 0x26), Crc8Bluetooth.hash("123456789")); - - var c = Crc8Bluetooth.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u8, 0x26), c.final()); -} - -test "CRC-8/CDMA2000" { - const Crc8Cdma2000 = catalog.Crc8Cdma2000; - - try testing.expectEqual(@as(u8, 0xda), Crc8Cdma2000.hash("123456789")); - - var c = Crc8Cdma2000.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u8, 0xda), c.final()); -} - -test "CRC-8/DARC" { - const Crc8Darc = catalog.Crc8Darc; - - try testing.expectEqual(@as(u8, 0x15), Crc8Darc.hash("123456789")); - - var c = Crc8Darc.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u8, 0x15), c.final()); -} - -test "CRC-8/DVB-S2" { - const Crc8DvbS2 = catalog.Crc8DvbS2; - - try testing.expectEqual(@as(u8, 0xbc), Crc8DvbS2.hash("123456789")); - - var c = Crc8DvbS2.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u8, 0xbc), c.final()); -} - -test "CRC-8/GSM-A" { - const Crc8GsmA = catalog.Crc8GsmA; - - try testing.expectEqual(@as(u8, 0x37), Crc8GsmA.hash("123456789")); - - var c = Crc8GsmA.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u8, 0x37), c.final()); -} - -test "CRC-8/GSM-B" { - const Crc8GsmB = catalog.Crc8GsmB; - - try testing.expectEqual(@as(u8, 0x94), Crc8GsmB.hash("123456789")); - - var c = Crc8GsmB.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u8, 0x94), c.final()); -} - -test "CRC-8/HITAG" { - const Crc8Hitag = catalog.Crc8Hitag; - - try testing.expectEqual(@as(u8, 0xb4), Crc8Hitag.hash("123456789")); - - var c = Crc8Hitag.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u8, 0xb4), c.final()); -} - -test "CRC-8/I-432-1" { - const Crc8I4321 = catalog.Crc8I4321; - - try testing.expectEqual(@as(u8, 0xa1), Crc8I4321.hash("123456789")); - - var c = Crc8I4321.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u8, 0xa1), c.final()); -} - -test "CRC-8/I-CODE" { - const Crc8ICode = catalog.Crc8ICode; - - try testing.expectEqual(@as(u8, 0x7e), Crc8ICode.hash("123456789")); - - var c = Crc8ICode.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u8, 0x7e), c.final()); -} - -test "CRC-8/LTE" { - const Crc8Lte = catalog.Crc8Lte; - - try testing.expectEqual(@as(u8, 0xea), Crc8Lte.hash("123456789")); - - var c = Crc8Lte.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u8, 0xea), c.final()); -} - -test "CRC-8/MAXIM-DOW" { - const Crc8MaximDow = catalog.Crc8MaximDow; - - try testing.expectEqual(@as(u8, 0xa1), Crc8MaximDow.hash("123456789")); - - var c = Crc8MaximDow.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u8, 0xa1), c.final()); -} - -test "CRC-8/MIFARE-MAD" { - const Crc8MifareMad = catalog.Crc8MifareMad; - - try testing.expectEqual(@as(u8, 0x99), Crc8MifareMad.hash("123456789")); - - var c = Crc8MifareMad.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u8, 0x99), c.final()); -} - -test "CRC-8/NRSC-5" { - const Crc8Nrsc5 = catalog.Crc8Nrsc5; - - try testing.expectEqual(@as(u8, 0xf7), Crc8Nrsc5.hash("123456789")); - - var c = Crc8Nrsc5.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u8, 0xf7), c.final()); -} - -test "CRC-8/OPENSAFETY" { - const Crc8Opensafety = catalog.Crc8Opensafety; - - try testing.expectEqual(@as(u8, 0x3e), Crc8Opensafety.hash("123456789")); - - var c = Crc8Opensafety.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u8, 0x3e), c.final()); -} - -test "CRC-8/ROHC" { - const Crc8Rohc = catalog.Crc8Rohc; - - try testing.expectEqual(@as(u8, 0xd0), Crc8Rohc.hash("123456789")); - - var c = Crc8Rohc.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u8, 0xd0), c.final()); -} - -test "CRC-8/SAE-J1850" { - const Crc8SaeJ1850 = catalog.Crc8SaeJ1850; - - try testing.expectEqual(@as(u8, 0x4b), Crc8SaeJ1850.hash("123456789")); - - var c = Crc8SaeJ1850.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u8, 0x4b), c.final()); -} - -test "CRC-8/SMBUS" { - const Crc8Smbus = catalog.Crc8Smbus; - - try testing.expectEqual(@as(u8, 0xf4), Crc8Smbus.hash("123456789")); - - var c = Crc8Smbus.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u8, 0xf4), c.final()); -} - -test "CRC-8/TECH-3250" { - const Crc8Tech3250 = catalog.Crc8Tech3250; - - try testing.expectEqual(@as(u8, 0x97), Crc8Tech3250.hash("123456789")); - - var c = Crc8Tech3250.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u8, 0x97), c.final()); -} - -test "CRC-8/WCDMA" { - const Crc8Wcdma = catalog.Crc8Wcdma; - - try testing.expectEqual(@as(u8, 0x25), Crc8Wcdma.hash("123456789")); - - var c = Crc8Wcdma.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u8, 0x25), c.final()); -} - -test "CRC-10/ATM" { - const Crc10Atm = catalog.Crc10Atm; - - try testing.expectEqual(@as(u10, 0x199), Crc10Atm.hash("123456789")); - - var c = Crc10Atm.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u10, 0x199), c.final()); -} - -test "CRC-10/CDMA2000" { - const Crc10Cdma2000 = catalog.Crc10Cdma2000; - - try testing.expectEqual(@as(u10, 0x233), Crc10Cdma2000.hash("123456789")); - - var c = Crc10Cdma2000.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u10, 0x233), c.final()); -} - -test "CRC-10/GSM" { - const Crc10Gsm = catalog.Crc10Gsm; - - try testing.expectEqual(@as(u10, 0x12a), Crc10Gsm.hash("123456789")); - - var c = Crc10Gsm.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u10, 0x12a), c.final()); -} - -test "CRC-11/FLEXRAY" { - const Crc11Flexray = catalog.Crc11Flexray; - - try testing.expectEqual(@as(u11, 0x5a3), Crc11Flexray.hash("123456789")); - - var c = Crc11Flexray.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u11, 0x5a3), c.final()); -} - -test "CRC-11/UMTS" { - const Crc11Umts = catalog.Crc11Umts; - - try testing.expectEqual(@as(u11, 0x061), Crc11Umts.hash("123456789")); - - var c = Crc11Umts.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u11, 0x061), c.final()); -} - -test "CRC-12/CDMA2000" { - const Crc12Cdma2000 = catalog.Crc12Cdma2000; - - try testing.expectEqual(@as(u12, 0xd4d), Crc12Cdma2000.hash("123456789")); - - var c = Crc12Cdma2000.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u12, 0xd4d), c.final()); -} - -test "CRC-12/DECT" { - const Crc12Dect = catalog.Crc12Dect; - - try testing.expectEqual(@as(u12, 0xf5b), Crc12Dect.hash("123456789")); - - var c = Crc12Dect.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u12, 0xf5b), c.final()); -} - -test "CRC-12/GSM" { - const Crc12Gsm = catalog.Crc12Gsm; - - try testing.expectEqual(@as(u12, 0xb34), Crc12Gsm.hash("123456789")); - - var c = Crc12Gsm.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u12, 0xb34), c.final()); -} - -test "CRC-12/UMTS" { - const Crc12Umts = catalog.Crc12Umts; - - try testing.expectEqual(@as(u12, 0xdaf), Crc12Umts.hash("123456789")); - - var c = Crc12Umts.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u12, 0xdaf), c.final()); -} - -test "CRC-13/BBC" { - const Crc13Bbc = catalog.Crc13Bbc; - - try testing.expectEqual(@as(u13, 0x04fa), Crc13Bbc.hash("123456789")); - - var c = Crc13Bbc.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u13, 0x04fa), c.final()); -} - -test "CRC-14/DARC" { - const Crc14Darc = catalog.Crc14Darc; - - try testing.expectEqual(@as(u14, 0x082d), Crc14Darc.hash("123456789")); - - var c = Crc14Darc.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u14, 0x082d), c.final()); -} - -test "CRC-14/GSM" { - const Crc14Gsm = catalog.Crc14Gsm; - - try testing.expectEqual(@as(u14, 0x30ae), Crc14Gsm.hash("123456789")); - - var c = Crc14Gsm.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u14, 0x30ae), c.final()); -} - -test "CRC-15/CAN" { - const Crc15Can = catalog.Crc15Can; - - try testing.expectEqual(@as(u15, 0x059e), Crc15Can.hash("123456789")); - - var c = Crc15Can.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u15, 0x059e), c.final()); -} - -test "CRC-15/MPT1327" { - const Crc15Mpt1327 = catalog.Crc15Mpt1327; - - try testing.expectEqual(@as(u15, 0x2566), Crc15Mpt1327.hash("123456789")); - - var c = Crc15Mpt1327.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u15, 0x2566), c.final()); -} - -test "CRC-16/ARC" { - const Crc16Arc = catalog.Crc16Arc; - - try testing.expectEqual(@as(u16, 0xbb3d), Crc16Arc.hash("123456789")); - - var c = Crc16Arc.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0xbb3d), c.final()); -} - -test "CRC-16/CDMA2000" { - const Crc16Cdma2000 = catalog.Crc16Cdma2000; - - try testing.expectEqual(@as(u16, 0x4c06), Crc16Cdma2000.hash("123456789")); - - var c = Crc16Cdma2000.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0x4c06), c.final()); -} - -test "CRC-16/CMS" { - const Crc16Cms = catalog.Crc16Cms; - - try testing.expectEqual(@as(u16, 0xaee7), Crc16Cms.hash("123456789")); - - var c = Crc16Cms.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0xaee7), c.final()); -} - -test "CRC-16/DDS-110" { - const Crc16Dds110 = catalog.Crc16Dds110; - - try testing.expectEqual(@as(u16, 0x9ecf), Crc16Dds110.hash("123456789")); - - var c = Crc16Dds110.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0x9ecf), c.final()); -} - -test "CRC-16/DECT-R" { - const Crc16DectR = catalog.Crc16DectR; - - try testing.expectEqual(@as(u16, 0x007e), Crc16DectR.hash("123456789")); - - var c = Crc16DectR.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0x007e), c.final()); -} - -test "CRC-16/DECT-X" { - const Crc16DectX = catalog.Crc16DectX; - - try testing.expectEqual(@as(u16, 0x007f), Crc16DectX.hash("123456789")); - - var c = Crc16DectX.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0x007f), c.final()); -} - -test "CRC-16/DNP" { - const Crc16Dnp = catalog.Crc16Dnp; - - try testing.expectEqual(@as(u16, 0xea82), Crc16Dnp.hash("123456789")); - - var c = Crc16Dnp.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0xea82), c.final()); -} - -test "CRC-16/EN-13757" { - const Crc16En13757 = catalog.Crc16En13757; - - try testing.expectEqual(@as(u16, 0xc2b7), Crc16En13757.hash("123456789")); - - var c = Crc16En13757.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0xc2b7), c.final()); -} - -test "CRC-16/GENIBUS" { - const Crc16Genibus = catalog.Crc16Genibus; - - try testing.expectEqual(@as(u16, 0xd64e), Crc16Genibus.hash("123456789")); - - var c = Crc16Genibus.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0xd64e), c.final()); -} - -test "CRC-16/GSM" { - const Crc16Gsm = catalog.Crc16Gsm; - - try testing.expectEqual(@as(u16, 0xce3c), Crc16Gsm.hash("123456789")); - - var c = Crc16Gsm.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0xce3c), c.final()); -} - -test "CRC-16/IBM-3740" { - const Crc16Ibm3740 = catalog.Crc16Ibm3740; - - try testing.expectEqual(@as(u16, 0x29b1), Crc16Ibm3740.hash("123456789")); - - var c = Crc16Ibm3740.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0x29b1), c.final()); -} - -test "CRC-16/IBM-SDLC" { - const Crc16IbmSdlc = catalog.Crc16IbmSdlc; - - try testing.expectEqual(@as(u16, 0x906e), Crc16IbmSdlc.hash("123456789")); - - var c = Crc16IbmSdlc.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0x906e), c.final()); -} - -test "CRC-16/ISO-IEC-14443-3-A" { - const Crc16IsoIec144433A = catalog.Crc16IsoIec144433A; - - try testing.expectEqual(@as(u16, 0xbf05), Crc16IsoIec144433A.hash("123456789")); - - var c = Crc16IsoIec144433A.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0xbf05), c.final()); -} - -test "CRC-16/KERMIT" { - const Crc16Kermit = catalog.Crc16Kermit; - - try testing.expectEqual(@as(u16, 0x2189), Crc16Kermit.hash("123456789")); - - var c = Crc16Kermit.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0x2189), c.final()); -} - -test "CRC-16/LJ1200" { - const Crc16Lj1200 = catalog.Crc16Lj1200; - - try testing.expectEqual(@as(u16, 0xbdf4), Crc16Lj1200.hash("123456789")); - - var c = Crc16Lj1200.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0xbdf4), c.final()); -} - -test "CRC-16/M17" { - const Crc16M17 = catalog.Crc16M17; - - try testing.expectEqual(@as(u16, 0x772b), Crc16M17.hash("123456789")); - - var c = Crc16M17.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0x772b), c.final()); -} - -test "CRC-16/MAXIM-DOW" { - const Crc16MaximDow = catalog.Crc16MaximDow; - - try testing.expectEqual(@as(u16, 0x44c2), Crc16MaximDow.hash("123456789")); - - var c = Crc16MaximDow.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0x44c2), c.final()); -} - -test "CRC-16/MCRF4XX" { - const Crc16Mcrf4xx = catalog.Crc16Mcrf4xx; - - try testing.expectEqual(@as(u16, 0x6f91), Crc16Mcrf4xx.hash("123456789")); - - var c = Crc16Mcrf4xx.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0x6f91), c.final()); -} - -test "CRC-16/MODBUS" { - const Crc16Modbus = catalog.Crc16Modbus; - - try testing.expectEqual(@as(u16, 0x4b37), Crc16Modbus.hash("123456789")); - - var c = Crc16Modbus.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0x4b37), c.final()); -} - -test "CRC-16/NRSC-5" { - const Crc16Nrsc5 = catalog.Crc16Nrsc5; - - try testing.expectEqual(@as(u16, 0xa066), Crc16Nrsc5.hash("123456789")); - - var c = Crc16Nrsc5.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0xa066), c.final()); -} - -test "CRC-16/OPENSAFETY-A" { - const Crc16OpensafetyA = catalog.Crc16OpensafetyA; - - try testing.expectEqual(@as(u16, 0x5d38), Crc16OpensafetyA.hash("123456789")); - - var c = Crc16OpensafetyA.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0x5d38), c.final()); -} - -test "CRC-16/OPENSAFETY-B" { - const Crc16OpensafetyB = catalog.Crc16OpensafetyB; - - try testing.expectEqual(@as(u16, 0x20fe), Crc16OpensafetyB.hash("123456789")); - - var c = Crc16OpensafetyB.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0x20fe), c.final()); -} - -test "CRC-16/PROFIBUS" { - const Crc16Profibus = catalog.Crc16Profibus; - - try testing.expectEqual(@as(u16, 0xa819), Crc16Profibus.hash("123456789")); - - var c = Crc16Profibus.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0xa819), c.final()); -} - -test "CRC-16/RIELLO" { - const Crc16Riello = catalog.Crc16Riello; - - try testing.expectEqual(@as(u16, 0x63d0), Crc16Riello.hash("123456789")); - - var c = Crc16Riello.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0x63d0), c.final()); -} - -test "CRC-16/SPI-FUJITSU" { - const Crc16SpiFujitsu = catalog.Crc16SpiFujitsu; - - try testing.expectEqual(@as(u16, 0xe5cc), Crc16SpiFujitsu.hash("123456789")); - - var c = Crc16SpiFujitsu.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0xe5cc), c.final()); -} - -test "CRC-16/T10-DIF" { - const Crc16T10Dif = catalog.Crc16T10Dif; - - try testing.expectEqual(@as(u16, 0xd0db), Crc16T10Dif.hash("123456789")); - - var c = Crc16T10Dif.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0xd0db), c.final()); -} - -test "CRC-16/TELEDISK" { - const Crc16Teledisk = catalog.Crc16Teledisk; - - try testing.expectEqual(@as(u16, 0x0fb3), Crc16Teledisk.hash("123456789")); - - var c = Crc16Teledisk.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0x0fb3), c.final()); -} - -test "CRC-16/TMS37157" { - const Crc16Tms37157 = catalog.Crc16Tms37157; - - try testing.expectEqual(@as(u16, 0x26b1), Crc16Tms37157.hash("123456789")); - - var c = Crc16Tms37157.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0x26b1), c.final()); -} - -test "CRC-16/UMTS" { - const Crc16Umts = catalog.Crc16Umts; - - try testing.expectEqual(@as(u16, 0xfee8), Crc16Umts.hash("123456789")); - - var c = Crc16Umts.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0xfee8), c.final()); -} - -test "CRC-16/USB" { - const Crc16Usb = catalog.Crc16Usb; - - try testing.expectEqual(@as(u16, 0xb4c8), Crc16Usb.hash("123456789")); - - var c = Crc16Usb.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0xb4c8), c.final()); -} - -test "CRC-16/XMODEM" { - const Crc16Xmodem = catalog.Crc16Xmodem; - - try testing.expectEqual(@as(u16, 0x31c3), Crc16Xmodem.hash("123456789")); - - var c = Crc16Xmodem.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u16, 0x31c3), c.final()); -} - -test "CRC-17/CAN-FD" { - const Crc17CanFd = catalog.Crc17CanFd; - - try testing.expectEqual(@as(u17, 0x04f03), Crc17CanFd.hash("123456789")); - - var c = Crc17CanFd.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u17, 0x04f03), c.final()); -} - -test "CRC-21/CAN-FD" { - const Crc21CanFd = catalog.Crc21CanFd; - - try testing.expectEqual(@as(u21, 0x0ed841), Crc21CanFd.hash("123456789")); - - var c = Crc21CanFd.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u21, 0x0ed841), c.final()); -} - -test "CRC-24/BLE" { - const Crc24Ble = catalog.Crc24Ble; - - try testing.expectEqual(@as(u24, 0xc25a56), Crc24Ble.hash("123456789")); - - var c = Crc24Ble.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u24, 0xc25a56), c.final()); -} - -test "CRC-24/FLEXRAY-A" { - const Crc24FlexrayA = catalog.Crc24FlexrayA; - - try testing.expectEqual(@as(u24, 0x7979bd), Crc24FlexrayA.hash("123456789")); - - var c = Crc24FlexrayA.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u24, 0x7979bd), c.final()); -} - -test "CRC-24/FLEXRAY-B" { - const Crc24FlexrayB = catalog.Crc24FlexrayB; - - try testing.expectEqual(@as(u24, 0x1f23b8), Crc24FlexrayB.hash("123456789")); - - var c = Crc24FlexrayB.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u24, 0x1f23b8), c.final()); -} - -test "CRC-24/INTERLAKEN" { - const Crc24Interlaken = catalog.Crc24Interlaken; - - try testing.expectEqual(@as(u24, 0xb4f3e6), Crc24Interlaken.hash("123456789")); - - var c = Crc24Interlaken.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u24, 0xb4f3e6), c.final()); -} - -test "CRC-24/LTE-A" { - const Crc24LteA = catalog.Crc24LteA; - - try testing.expectEqual(@as(u24, 0xcde703), Crc24LteA.hash("123456789")); - - var c = Crc24LteA.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u24, 0xcde703), c.final()); -} - -test "CRC-24/LTE-B" { - const Crc24LteB = catalog.Crc24LteB; - - try testing.expectEqual(@as(u24, 0x23ef52), Crc24LteB.hash("123456789")); - - var c = Crc24LteB.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u24, 0x23ef52), c.final()); -} - -test "CRC-24/OPENPGP" { - const Crc24Openpgp = catalog.Crc24Openpgp; - - try testing.expectEqual(@as(u24, 0x21cf02), Crc24Openpgp.hash("123456789")); - - var c = Crc24Openpgp.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u24, 0x21cf02), c.final()); -} - -test "CRC-24/OS-9" { - const Crc24Os9 = catalog.Crc24Os9; - - try testing.expectEqual(@as(u24, 0x200fa5), Crc24Os9.hash("123456789")); - - var c = Crc24Os9.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u24, 0x200fa5), c.final()); -} - -test "CRC-30/CDMA" { - const Crc30Cdma = catalog.Crc30Cdma; - - try testing.expectEqual(@as(u30, 0x04c34abf), Crc30Cdma.hash("123456789")); - - var c = Crc30Cdma.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u30, 0x04c34abf), c.final()); -} - -test "CRC-31/PHILIPS" { - const Crc31Philips = catalog.Crc31Philips; - - try testing.expectEqual(@as(u31, 0x0ce9e46c), Crc31Philips.hash("123456789")); - - var c = Crc31Philips.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u31, 0x0ce9e46c), c.final()); -} - -test "CRC-32/AIXM" { - const Crc32Aixm = catalog.Crc32Aixm; - - try testing.expectEqual(@as(u32, 0x3010bf7f), Crc32Aixm.hash("123456789")); - - var c = Crc32Aixm.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u32, 0x3010bf7f), c.final()); -} - -test "CRC-32/AUTOSAR" { - const Crc32Autosar = catalog.Crc32Autosar; - - try testing.expectEqual(@as(u32, 0x1697d06a), Crc32Autosar.hash("123456789")); - - var c = Crc32Autosar.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u32, 0x1697d06a), c.final()); -} - -test "CRC-32/BASE91-D" { - const Crc32Base91D = catalog.Crc32Base91D; - - try testing.expectEqual(@as(u32, 0x87315576), Crc32Base91D.hash("123456789")); - - var c = Crc32Base91D.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u32, 0x87315576), c.final()); -} - -test "CRC-32/BZIP2" { - const Crc32Bzip2 = catalog.Crc32Bzip2; - - try testing.expectEqual(@as(u32, 0xfc891918), Crc32Bzip2.hash("123456789")); - - var c = Crc32Bzip2.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u32, 0xfc891918), c.final()); -} - -test "CRC-32/CD-ROM-EDC" { - const Crc32CdRomEdc = catalog.Crc32CdRomEdc; - - try testing.expectEqual(@as(u32, 0x6ec2edc4), Crc32CdRomEdc.hash("123456789")); - - var c = Crc32CdRomEdc.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u32, 0x6ec2edc4), c.final()); -} - -test "CRC-32/CKSUM" { - const Crc32Cksum = catalog.Crc32Cksum; - - try testing.expectEqual(@as(u32, 0x765e7680), Crc32Cksum.hash("123456789")); - - var c = Crc32Cksum.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u32, 0x765e7680), c.final()); -} - -test "CRC-32/ISCSI" { - const Crc32Iscsi = catalog.Crc32Iscsi; - - try testing.expectEqual(@as(u32, 0xe3069283), Crc32Iscsi.hash("123456789")); - - var c = Crc32Iscsi.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u32, 0xe3069283), c.final()); -} - -test "CRC-32/ISO-HDLC" { - const Crc32IsoHdlc = catalog.Crc32IsoHdlc; - - try testing.expectEqual(@as(u32, 0xcbf43926), Crc32IsoHdlc.hash("123456789")); - - var c = Crc32IsoHdlc.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u32, 0xcbf43926), c.final()); -} - -test "CRC-32/JAMCRC" { - const Crc32Jamcrc = catalog.Crc32Jamcrc; - - try testing.expectEqual(@as(u32, 0x340bc6d9), Crc32Jamcrc.hash("123456789")); - - var c = Crc32Jamcrc.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u32, 0x340bc6d9), c.final()); -} - -test "CRC-32/MEF" { - const Crc32Mef = catalog.Crc32Mef; - - try testing.expectEqual(@as(u32, 0xd2c22f51), Crc32Mef.hash("123456789")); - - var c = Crc32Mef.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u32, 0xd2c22f51), c.final()); -} - -test "CRC-32/MPEG-2" { - const Crc32Mpeg2 = catalog.Crc32Mpeg2; - - try testing.expectEqual(@as(u32, 0x0376e6e7), Crc32Mpeg2.hash("123456789")); - - var c = Crc32Mpeg2.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u32, 0x0376e6e7), c.final()); -} - -test "CRC-32/XFER" { - const Crc32Xfer = catalog.Crc32Xfer; - - try testing.expectEqual(@as(u32, 0xbd0be338), Crc32Xfer.hash("123456789")); - - var c = Crc32Xfer.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u32, 0xbd0be338), c.final()); -} - -test "CRC-40/GSM" { - const Crc40Gsm = catalog.Crc40Gsm; - - try testing.expectEqual(@as(u40, 0xd4164fc646), Crc40Gsm.hash("123456789")); - - var c = Crc40Gsm.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u40, 0xd4164fc646), c.final()); -} - -test "CRC-64/ECMA-182" { - const Crc64Ecma182 = catalog.Crc64Ecma182; - - try testing.expectEqual(@as(u64, 0x6c40df5f0b497347), Crc64Ecma182.hash("123456789")); - - var c = Crc64Ecma182.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u64, 0x6c40df5f0b497347), c.final()); -} - -test "CRC-64/GO-ISO" { - const Crc64GoIso = catalog.Crc64GoIso; - - try testing.expectEqual(@as(u64, 0xb90956c775a41001), Crc64GoIso.hash("123456789")); - - var c = Crc64GoIso.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u64, 0xb90956c775a41001), c.final()); -} - -test "CRC-64/MS" { - const Crc64Ms = catalog.Crc64Ms; - - try testing.expectEqual(@as(u64, 0x75d4b74f024eceea), Crc64Ms.hash("123456789")); - - var c = Crc64Ms.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u64, 0x75d4b74f024eceea), c.final()); -} - -test "CRC-64/REDIS" { - const Crc64Redis = catalog.Crc64Redis; - - try testing.expectEqual(@as(u64, 0xe9c6d914c4b8d9ca), Crc64Redis.hash("123456789")); - - var c = Crc64Redis.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u64, 0xe9c6d914c4b8d9ca), c.final()); -} - -test "CRC-64/WE" { - const Crc64We = catalog.Crc64We; - - try testing.expectEqual(@as(u64, 0x62ec59e3f1a4f00a), Crc64We.hash("123456789")); - - var c = Crc64We.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u64, 0x62ec59e3f1a4f00a), c.final()); -} - -test "CRC-64/XZ" { - const Crc64Xz = catalog.Crc64Xz; - - try testing.expectEqual(@as(u64, 0x995dc9bbdf1939fa), Crc64Xz.hash("123456789")); - - var c = Crc64Xz.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u64, 0x995dc9bbdf1939fa), c.final()); -} - -test "CRC-82/DARC" { - const Crc82Darc = catalog.Crc82Darc; - - try testing.expectEqual(@as(u82, 0x09ea83f625023801fd612), Crc82Darc.hash("123456789")); - - var c = Crc82Darc.init(); - c.update("1234"); - c.update("56789"); - try testing.expectEqual(@as(u82, 0x09ea83f625023801fd612), c.final()); -} diff --git a/lib/std/hash/crc/impl.zig b/lib/std/hash/crc/impl.zig new file mode 100644 index 0000000000000000000000000000000000000000..f0fd5ac14e74d4548ddac63e5f9a10e4f302b5f5 --- /dev/null +++ b/lib/std/hash/crc/impl.zig @@ -0,0 +1,241 @@ +// There is a generic CRC implementation "Crc()" which can be paramterized via +// the Algorithm struct for a plethora of uses, along with two implementations +// of CRC32 implemented with the following key characteristics: +// +// - Crc32WithPoly uses 8Kb of tables but is ~10x faster than the small method. +// +// - Crc32SmallWithPoly uses only 64 bytes of memory but is slower. Be aware that this is +// still moderately fast just slow relative to the slicing approach. +// +// The primary interface for all of the standard CRC algorithms is the +// generated file "crc.zig", which uses the implementation code here to define +// many standard CRCs. + +const std = @import("std"); + +pub fn Algorithm(comptime W: type) type { + return struct { + polynomial: W, + initial: W, + reflect_input: bool, + reflect_output: bool, + xor_output: 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.reflect_input) + @bitReverse(@as(I, algorithm.polynomial)) >> (@bitSizeOf(I) - @bitSizeOf(W)) + else + @as(I, algorithm.polynomial) << (@bitSizeOf(I) - @bitSizeOf(W)); + + var table: [256]I = undefined; + for (&table, 0..) |*e, i| { + var crc: I = i; + if (algorithm.reflect_input) { + 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.reflect_input) + @bitReverse(@as(I, algorithm.initial)) >> (@bitSizeOf(I) - @bitSizeOf(W)) + else + @as(I, algorithm.initial) << (@bitSizeOf(I) - @bitSizeOf(W)); + return Self{ .crc = initial }; + } + + inline fn tableEntry(index: I) I { + return lookup_table[@as(u8, @intCast(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.reflect_input) { + 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.reflect_input != algorithm.reflect_output) { + c = @bitReverse(c); + } + if (!algorithm.reflect_output) { + c >>= @bitSizeOf(I) - @bitSizeOf(W); + } + return @as(W, @intCast(c ^ algorithm.xor_output)); + } + + 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, + Koopman = 0xeb31d82e, + _, +}; + +// slicing-by-8 crc32 implementation. +pub fn Crc32WithPoly(comptime poly: Polynomial) type { + return struct { + const Self = @This(); + const lookup_tables = block: { + @setEvalBranchQuota(20000); + var tables: [8][256]u32 = undefined; + + for (&tables[0], 0..) |*e, i| { + var crc = @as(u32, @intCast(i)); + var j: usize = 0; + while (j < 8) : (j += 1) { + if (crc & 1 == 1) { + crc = (crc >> 1) ^ @intFromEnum(poly); + } else { + crc = (crc >> 1); + } + } + e.* = crc; + } + + var i: usize = 0; + while (i < 256) : (i += 1) { + var crc = tables[0][i]; + var j: usize = 1; + while (j < 8) : (j += 1) { + const index: u8 = @truncate(crc); + crc = tables[0][index] ^ (crc >> 8); + tables[j][i] = crc; + } + } + + break :block tables; + }; + + crc: u32, + + pub fn init() Self { + return Self{ .crc = 0xffffffff }; + } + + pub fn update(self: *Self, input: []const u8) void { + var i: usize = 0; + while (i + 8 <= input.len) : (i += 8) { + const p = input[i..][0..8]; + + // Unrolling this way gives ~50Mb/s increase + self.crc ^= std.mem.readInt(u32, p[0..4], .little); + + self.crc = + lookup_tables[0][p[7]] ^ + lookup_tables[1][p[6]] ^ + lookup_tables[2][p[5]] ^ + lookup_tables[3][p[4]] ^ + lookup_tables[4][@as(u8, @truncate(self.crc >> 24))] ^ + lookup_tables[5][@as(u8, @truncate(self.crc >> 16))] ^ + lookup_tables[6][@as(u8, @truncate(self.crc >> 8))] ^ + lookup_tables[7][@as(u8, @truncate(self.crc >> 0))]; + } + + while (i < input.len) : (i += 1) { + const index = @as(u8, @truncate(self.crc)) ^ input[i]; + self.crc = (self.crc >> 8) ^ lookup_tables[0][index]; + } + } + + pub fn final(self: *Self) u32 { + return ~self.crc; + } + + pub fn hash(input: []const u8) u32 { + var c = Self.init(); + c.update(input); + return c.final(); + } + }; +} + +// half-byte lookup table implementation. +pub fn Crc32SmallWithPoly(comptime poly: Polynomial) type { + return struct { + const Self = @This(); + const lookup_table = block: { + var table: [16]u32 = undefined; + + for (&table, 0..) |*e, i| { + var crc = @as(u32, @intCast(i * 16)); + var j: usize = 0; + while (j < 8) : (j += 1) { + if (crc & 1 == 1) { + crc = (crc >> 1) ^ @intFromEnum(poly); + } else { + crc = (crc >> 1); + } + } + e.* = crc; + } + + break :block table; + }; + + crc: u32, + + pub fn init() Self { + return Self{ .crc = 0xffffffff }; + } + + pub fn update(self: *Self, input: []const u8) void { + for (input) |b| { + self.crc = lookup_table[@as(u4, @truncate(self.crc ^ (b >> 0)))] ^ (self.crc >> 4); + self.crc = lookup_table[@as(u4, @truncate(self.crc ^ (b >> 4)))] ^ (self.crc >> 4); + } + } + + pub fn final(self: *Self) u32 { + return ~self.crc; + } + + pub fn hash(input: []const u8) u32 { + var c = Self.init(); + c.update(input); + return c.final(); + } + }; +} diff --git a/lib/std/hash/crc/test.zig b/lib/std/hash/crc/test.zig new file mode 100644 index 0000000000000000000000000000000000000000..c9cabf6463e9f30869c6643c64fff4f7569225bd --- /dev/null +++ b/lib/std/hash/crc/test.zig @@ -0,0 +1,1256 @@ +//! This file is auto-generated by tools/update_crc_catalog.zig. + +const std = @import("std"); +const testing = std.testing; +const verify = @import("../verify.zig"); +const crc = @import("../crc.zig"); + +test "crc32 ieee" { + inline for ([2]type{ crc.Crc32WithPoly(.IEEE), crc.Crc32SmallWithPoly(.IEEE) }) |ieee| { + try testing.expect(ieee.hash("") == 0x00000000); + try testing.expect(ieee.hash("a") == 0xe8b7be43); + try testing.expect(ieee.hash("abc") == 0x352441c2); + try verify.iterativeApi(ieee); + } +} + +test "crc32 castagnoli" { + inline for ([2]type{ crc.Crc32WithPoly(.Castagnoli), crc.Crc32SmallWithPoly(.Castagnoli) }) |casta| { + try testing.expect(casta.hash("") == 0x00000000); + try testing.expect(casta.hash("a") == 0xc1d04330); + try testing.expect(casta.hash("abc") == 0x364b3fb7); + try verify.iterativeApi(casta); + } +} + +test "CRC-3/GSM" { + const Crc3Gsm = crc.Crc3Gsm; + + try testing.expectEqual(@as(u3, 0x4), Crc3Gsm.hash("123456789")); + + var c = Crc3Gsm.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u3, 0x4), c.final()); +} + +test "CRC-3/ROHC" { + const Crc3Rohc = crc.Crc3Rohc; + + try testing.expectEqual(@as(u3, 0x6), Crc3Rohc.hash("123456789")); + + var c = Crc3Rohc.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u3, 0x6), c.final()); +} + +test "CRC-4/G-704" { + const Crc4G704 = crc.Crc4G704; + + try testing.expectEqual(@as(u4, 0x7), Crc4G704.hash("123456789")); + + var c = Crc4G704.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u4, 0x7), c.final()); +} + +test "CRC-4/INTERLAKEN" { + const Crc4Interlaken = crc.Crc4Interlaken; + + try testing.expectEqual(@as(u4, 0xb), Crc4Interlaken.hash("123456789")); + + var c = Crc4Interlaken.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u4, 0xb), c.final()); +} + +test "CRC-5/EPC-C1G2" { + const Crc5EpcC1g2 = crc.Crc5EpcC1g2; + + try testing.expectEqual(@as(u5, 0x00), Crc5EpcC1g2.hash("123456789")); + + var c = Crc5EpcC1g2.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u5, 0x00), c.final()); +} + +test "CRC-5/G-704" { + const Crc5G704 = crc.Crc5G704; + + try testing.expectEqual(@as(u5, 0x07), Crc5G704.hash("123456789")); + + var c = Crc5G704.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u5, 0x07), c.final()); +} + +test "CRC-5/USB" { + const Crc5Usb = crc.Crc5Usb; + + try testing.expectEqual(@as(u5, 0x19), Crc5Usb.hash("123456789")); + + var c = Crc5Usb.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u5, 0x19), c.final()); +} + +test "CRC-6/CDMA2000-A" { + const Crc6Cdma2000A = crc.Crc6Cdma2000A; + + try testing.expectEqual(@as(u6, 0x0d), Crc6Cdma2000A.hash("123456789")); + + var c = Crc6Cdma2000A.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u6, 0x0d), c.final()); +} + +test "CRC-6/CDMA2000-B" { + const Crc6Cdma2000B = crc.Crc6Cdma2000B; + + try testing.expectEqual(@as(u6, 0x3b), Crc6Cdma2000B.hash("123456789")); + + var c = Crc6Cdma2000B.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u6, 0x3b), c.final()); +} + +test "CRC-6/DARC" { + const Crc6Darc = crc.Crc6Darc; + + try testing.expectEqual(@as(u6, 0x26), Crc6Darc.hash("123456789")); + + var c = Crc6Darc.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u6, 0x26), c.final()); +} + +test "CRC-6/G-704" { + const Crc6G704 = crc.Crc6G704; + + try testing.expectEqual(@as(u6, 0x06), Crc6G704.hash("123456789")); + + var c = Crc6G704.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u6, 0x06), c.final()); +} + +test "CRC-6/GSM" { + const Crc6Gsm = crc.Crc6Gsm; + + try testing.expectEqual(@as(u6, 0x13), Crc6Gsm.hash("123456789")); + + var c = Crc6Gsm.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u6, 0x13), c.final()); +} + +test "CRC-7/MMC" { + const Crc7Mmc = crc.Crc7Mmc; + + try testing.expectEqual(@as(u7, 0x75), Crc7Mmc.hash("123456789")); + + var c = Crc7Mmc.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u7, 0x75), c.final()); +} + +test "CRC-7/ROHC" { + const Crc7Rohc = crc.Crc7Rohc; + + try testing.expectEqual(@as(u7, 0x53), Crc7Rohc.hash("123456789")); + + var c = Crc7Rohc.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u7, 0x53), c.final()); +} + +test "CRC-7/UMTS" { + const Crc7Umts = crc.Crc7Umts; + + try testing.expectEqual(@as(u7, 0x61), Crc7Umts.hash("123456789")); + + var c = Crc7Umts.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u7, 0x61), c.final()); +} + +test "CRC-8/AUTOSAR" { + const Crc8Autosar = crc.Crc8Autosar; + + try testing.expectEqual(@as(u8, 0xdf), Crc8Autosar.hash("123456789")); + + var c = Crc8Autosar.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u8, 0xdf), c.final()); +} + +test "CRC-8/BLUETOOTH" { + const Crc8Bluetooth = crc.Crc8Bluetooth; + + try testing.expectEqual(@as(u8, 0x26), Crc8Bluetooth.hash("123456789")); + + var c = Crc8Bluetooth.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u8, 0x26), c.final()); +} + +test "CRC-8/CDMA2000" { + const Crc8Cdma2000 = crc.Crc8Cdma2000; + + try testing.expectEqual(@as(u8, 0xda), Crc8Cdma2000.hash("123456789")); + + var c = Crc8Cdma2000.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u8, 0xda), c.final()); +} + +test "CRC-8/DARC" { + const Crc8Darc = crc.Crc8Darc; + + try testing.expectEqual(@as(u8, 0x15), Crc8Darc.hash("123456789")); + + var c = Crc8Darc.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u8, 0x15), c.final()); +} + +test "CRC-8/DVB-S2" { + const Crc8DvbS2 = crc.Crc8DvbS2; + + try testing.expectEqual(@as(u8, 0xbc), Crc8DvbS2.hash("123456789")); + + var c = Crc8DvbS2.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u8, 0xbc), c.final()); +} + +test "CRC-8/GSM-A" { + const Crc8GsmA = crc.Crc8GsmA; + + try testing.expectEqual(@as(u8, 0x37), Crc8GsmA.hash("123456789")); + + var c = Crc8GsmA.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u8, 0x37), c.final()); +} + +test "CRC-8/GSM-B" { + const Crc8GsmB = crc.Crc8GsmB; + + try testing.expectEqual(@as(u8, 0x94), Crc8GsmB.hash("123456789")); + + var c = Crc8GsmB.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u8, 0x94), c.final()); +} + +test "CRC-8/HITAG" { + const Crc8Hitag = crc.Crc8Hitag; + + try testing.expectEqual(@as(u8, 0xb4), Crc8Hitag.hash("123456789")); + + var c = Crc8Hitag.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u8, 0xb4), c.final()); +} + +test "CRC-8/I-432-1" { + const Crc8I4321 = crc.Crc8I4321; + + try testing.expectEqual(@as(u8, 0xa1), Crc8I4321.hash("123456789")); + + var c = Crc8I4321.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u8, 0xa1), c.final()); +} + +test "CRC-8/I-CODE" { + const Crc8ICode = crc.Crc8ICode; + + try testing.expectEqual(@as(u8, 0x7e), Crc8ICode.hash("123456789")); + + var c = Crc8ICode.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u8, 0x7e), c.final()); +} + +test "CRC-8/LTE" { + const Crc8Lte = crc.Crc8Lte; + + try testing.expectEqual(@as(u8, 0xea), Crc8Lte.hash("123456789")); + + var c = Crc8Lte.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u8, 0xea), c.final()); +} + +test "CRC-8/MAXIM-DOW" { + const Crc8MaximDow = crc.Crc8MaximDow; + + try testing.expectEqual(@as(u8, 0xa1), Crc8MaximDow.hash("123456789")); + + var c = Crc8MaximDow.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u8, 0xa1), c.final()); +} + +test "CRC-8/MIFARE-MAD" { + const Crc8MifareMad = crc.Crc8MifareMad; + + try testing.expectEqual(@as(u8, 0x99), Crc8MifareMad.hash("123456789")); + + var c = Crc8MifareMad.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u8, 0x99), c.final()); +} + +test "CRC-8/NRSC-5" { + const Crc8Nrsc5 = crc.Crc8Nrsc5; + + try testing.expectEqual(@as(u8, 0xf7), Crc8Nrsc5.hash("123456789")); + + var c = Crc8Nrsc5.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u8, 0xf7), c.final()); +} + +test "CRC-8/OPENSAFETY" { + const Crc8Opensafety = crc.Crc8Opensafety; + + try testing.expectEqual(@as(u8, 0x3e), Crc8Opensafety.hash("123456789")); + + var c = Crc8Opensafety.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u8, 0x3e), c.final()); +} + +test "CRC-8/ROHC" { + const Crc8Rohc = crc.Crc8Rohc; + + try testing.expectEqual(@as(u8, 0xd0), Crc8Rohc.hash("123456789")); + + var c = Crc8Rohc.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u8, 0xd0), c.final()); +} + +test "CRC-8/SAE-J1850" { + const Crc8SaeJ1850 = crc.Crc8SaeJ1850; + + try testing.expectEqual(@as(u8, 0x4b), Crc8SaeJ1850.hash("123456789")); + + var c = Crc8SaeJ1850.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u8, 0x4b), c.final()); +} + +test "CRC-8/SMBUS" { + const Crc8Smbus = crc.Crc8Smbus; + + try testing.expectEqual(@as(u8, 0xf4), Crc8Smbus.hash("123456789")); + + var c = Crc8Smbus.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u8, 0xf4), c.final()); +} + +test "CRC-8/TECH-3250" { + const Crc8Tech3250 = crc.Crc8Tech3250; + + try testing.expectEqual(@as(u8, 0x97), Crc8Tech3250.hash("123456789")); + + var c = Crc8Tech3250.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u8, 0x97), c.final()); +} + +test "CRC-8/WCDMA" { + const Crc8Wcdma = crc.Crc8Wcdma; + + try testing.expectEqual(@as(u8, 0x25), Crc8Wcdma.hash("123456789")); + + var c = Crc8Wcdma.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u8, 0x25), c.final()); +} + +test "CRC-10/ATM" { + const Crc10Atm = crc.Crc10Atm; + + try testing.expectEqual(@as(u10, 0x199), Crc10Atm.hash("123456789")); + + var c = Crc10Atm.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u10, 0x199), c.final()); +} + +test "CRC-10/CDMA2000" { + const Crc10Cdma2000 = crc.Crc10Cdma2000; + + try testing.expectEqual(@as(u10, 0x233), Crc10Cdma2000.hash("123456789")); + + var c = Crc10Cdma2000.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u10, 0x233), c.final()); +} + +test "CRC-10/GSM" { + const Crc10Gsm = crc.Crc10Gsm; + + try testing.expectEqual(@as(u10, 0x12a), Crc10Gsm.hash("123456789")); + + var c = Crc10Gsm.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u10, 0x12a), c.final()); +} + +test "CRC-11/FLEXRAY" { + const Crc11Flexray = crc.Crc11Flexray; + + try testing.expectEqual(@as(u11, 0x5a3), Crc11Flexray.hash("123456789")); + + var c = Crc11Flexray.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u11, 0x5a3), c.final()); +} + +test "CRC-11/UMTS" { + const Crc11Umts = crc.Crc11Umts; + + try testing.expectEqual(@as(u11, 0x061), Crc11Umts.hash("123456789")); + + var c = Crc11Umts.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u11, 0x061), c.final()); +} + +test "CRC-12/CDMA2000" { + const Crc12Cdma2000 = crc.Crc12Cdma2000; + + try testing.expectEqual(@as(u12, 0xd4d), Crc12Cdma2000.hash("123456789")); + + var c = Crc12Cdma2000.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u12, 0xd4d), c.final()); +} + +test "CRC-12/DECT" { + const Crc12Dect = crc.Crc12Dect; + + try testing.expectEqual(@as(u12, 0xf5b), Crc12Dect.hash("123456789")); + + var c = Crc12Dect.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u12, 0xf5b), c.final()); +} + +test "CRC-12/GSM" { + const Crc12Gsm = crc.Crc12Gsm; + + try testing.expectEqual(@as(u12, 0xb34), Crc12Gsm.hash("123456789")); + + var c = Crc12Gsm.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u12, 0xb34), c.final()); +} + +test "CRC-12/UMTS" { + const Crc12Umts = crc.Crc12Umts; + + try testing.expectEqual(@as(u12, 0xdaf), Crc12Umts.hash("123456789")); + + var c = Crc12Umts.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u12, 0xdaf), c.final()); +} + +test "CRC-13/BBC" { + const Crc13Bbc = crc.Crc13Bbc; + + try testing.expectEqual(@as(u13, 0x04fa), Crc13Bbc.hash("123456789")); + + var c = Crc13Bbc.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u13, 0x04fa), c.final()); +} + +test "CRC-14/DARC" { + const Crc14Darc = crc.Crc14Darc; + + try testing.expectEqual(@as(u14, 0x082d), Crc14Darc.hash("123456789")); + + var c = Crc14Darc.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u14, 0x082d), c.final()); +} + +test "CRC-14/GSM" { + const Crc14Gsm = crc.Crc14Gsm; + + try testing.expectEqual(@as(u14, 0x30ae), Crc14Gsm.hash("123456789")); + + var c = Crc14Gsm.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u14, 0x30ae), c.final()); +} + +test "CRC-15/CAN" { + const Crc15Can = crc.Crc15Can; + + try testing.expectEqual(@as(u15, 0x059e), Crc15Can.hash("123456789")); + + var c = Crc15Can.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u15, 0x059e), c.final()); +} + +test "CRC-15/MPT1327" { + const Crc15Mpt1327 = crc.Crc15Mpt1327; + + try testing.expectEqual(@as(u15, 0x2566), Crc15Mpt1327.hash("123456789")); + + var c = Crc15Mpt1327.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u15, 0x2566), c.final()); +} + +test "CRC-16/ARC" { + const Crc16Arc = crc.Crc16Arc; + + try testing.expectEqual(@as(u16, 0xbb3d), Crc16Arc.hash("123456789")); + + var c = Crc16Arc.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0xbb3d), c.final()); +} + +test "CRC-16/CDMA2000" { + const Crc16Cdma2000 = crc.Crc16Cdma2000; + + try testing.expectEqual(@as(u16, 0x4c06), Crc16Cdma2000.hash("123456789")); + + var c = Crc16Cdma2000.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0x4c06), c.final()); +} + +test "CRC-16/CMS" { + const Crc16Cms = crc.Crc16Cms; + + try testing.expectEqual(@as(u16, 0xaee7), Crc16Cms.hash("123456789")); + + var c = Crc16Cms.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0xaee7), c.final()); +} + +test "CRC-16/DDS-110" { + const Crc16Dds110 = crc.Crc16Dds110; + + try testing.expectEqual(@as(u16, 0x9ecf), Crc16Dds110.hash("123456789")); + + var c = Crc16Dds110.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0x9ecf), c.final()); +} + +test "CRC-16/DECT-R" { + const Crc16DectR = crc.Crc16DectR; + + try testing.expectEqual(@as(u16, 0x007e), Crc16DectR.hash("123456789")); + + var c = Crc16DectR.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0x007e), c.final()); +} + +test "CRC-16/DECT-X" { + const Crc16DectX = crc.Crc16DectX; + + try testing.expectEqual(@as(u16, 0x007f), Crc16DectX.hash("123456789")); + + var c = Crc16DectX.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0x007f), c.final()); +} + +test "CRC-16/DNP" { + const Crc16Dnp = crc.Crc16Dnp; + + try testing.expectEqual(@as(u16, 0xea82), Crc16Dnp.hash("123456789")); + + var c = Crc16Dnp.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0xea82), c.final()); +} + +test "CRC-16/EN-13757" { + const Crc16En13757 = crc.Crc16En13757; + + try testing.expectEqual(@as(u16, 0xc2b7), Crc16En13757.hash("123456789")); + + var c = Crc16En13757.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0xc2b7), c.final()); +} + +test "CRC-16/GENIBUS" { + const Crc16Genibus = crc.Crc16Genibus; + + try testing.expectEqual(@as(u16, 0xd64e), Crc16Genibus.hash("123456789")); + + var c = Crc16Genibus.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0xd64e), c.final()); +} + +test "CRC-16/GSM" { + const Crc16Gsm = crc.Crc16Gsm; + + try testing.expectEqual(@as(u16, 0xce3c), Crc16Gsm.hash("123456789")); + + var c = Crc16Gsm.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0xce3c), c.final()); +} + +test "CRC-16/IBM-3740" { + const Crc16Ibm3740 = crc.Crc16Ibm3740; + + try testing.expectEqual(@as(u16, 0x29b1), Crc16Ibm3740.hash("123456789")); + + var c = Crc16Ibm3740.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0x29b1), c.final()); +} + +test "CRC-16/IBM-SDLC" { + const Crc16IbmSdlc = crc.Crc16IbmSdlc; + + try testing.expectEqual(@as(u16, 0x906e), Crc16IbmSdlc.hash("123456789")); + + var c = Crc16IbmSdlc.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0x906e), c.final()); +} + +test "CRC-16/ISO-IEC-14443-3-A" { + const Crc16IsoIec144433A = crc.Crc16IsoIec144433A; + + try testing.expectEqual(@as(u16, 0xbf05), Crc16IsoIec144433A.hash("123456789")); + + var c = Crc16IsoIec144433A.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0xbf05), c.final()); +} + +test "CRC-16/KERMIT" { + const Crc16Kermit = crc.Crc16Kermit; + + try testing.expectEqual(@as(u16, 0x2189), Crc16Kermit.hash("123456789")); + + var c = Crc16Kermit.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0x2189), c.final()); +} + +test "CRC-16/LJ1200" { + const Crc16Lj1200 = crc.Crc16Lj1200; + + try testing.expectEqual(@as(u16, 0xbdf4), Crc16Lj1200.hash("123456789")); + + var c = Crc16Lj1200.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0xbdf4), c.final()); +} + +test "CRC-16/M17" { + const Crc16M17 = crc.Crc16M17; + + try testing.expectEqual(@as(u16, 0x772b), Crc16M17.hash("123456789")); + + var c = Crc16M17.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0x772b), c.final()); +} + +test "CRC-16/MAXIM-DOW" { + const Crc16MaximDow = crc.Crc16MaximDow; + + try testing.expectEqual(@as(u16, 0x44c2), Crc16MaximDow.hash("123456789")); + + var c = Crc16MaximDow.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0x44c2), c.final()); +} + +test "CRC-16/MCRF4XX" { + const Crc16Mcrf4xx = crc.Crc16Mcrf4xx; + + try testing.expectEqual(@as(u16, 0x6f91), Crc16Mcrf4xx.hash("123456789")); + + var c = Crc16Mcrf4xx.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0x6f91), c.final()); +} + +test "CRC-16/MODBUS" { + const Crc16Modbus = crc.Crc16Modbus; + + try testing.expectEqual(@as(u16, 0x4b37), Crc16Modbus.hash("123456789")); + + var c = Crc16Modbus.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0x4b37), c.final()); +} + +test "CRC-16/NRSC-5" { + const Crc16Nrsc5 = crc.Crc16Nrsc5; + + try testing.expectEqual(@as(u16, 0xa066), Crc16Nrsc5.hash("123456789")); + + var c = Crc16Nrsc5.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0xa066), c.final()); +} + +test "CRC-16/OPENSAFETY-A" { + const Crc16OpensafetyA = crc.Crc16OpensafetyA; + + try testing.expectEqual(@as(u16, 0x5d38), Crc16OpensafetyA.hash("123456789")); + + var c = Crc16OpensafetyA.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0x5d38), c.final()); +} + +test "CRC-16/OPENSAFETY-B" { + const Crc16OpensafetyB = crc.Crc16OpensafetyB; + + try testing.expectEqual(@as(u16, 0x20fe), Crc16OpensafetyB.hash("123456789")); + + var c = Crc16OpensafetyB.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0x20fe), c.final()); +} + +test "CRC-16/PROFIBUS" { + const Crc16Profibus = crc.Crc16Profibus; + + try testing.expectEqual(@as(u16, 0xa819), Crc16Profibus.hash("123456789")); + + var c = Crc16Profibus.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0xa819), c.final()); +} + +test "CRC-16/RIELLO" { + const Crc16Riello = crc.Crc16Riello; + + try testing.expectEqual(@as(u16, 0x63d0), Crc16Riello.hash("123456789")); + + var c = Crc16Riello.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0x63d0), c.final()); +} + +test "CRC-16/SPI-FUJITSU" { + const Crc16SpiFujitsu = crc.Crc16SpiFujitsu; + + try testing.expectEqual(@as(u16, 0xe5cc), Crc16SpiFujitsu.hash("123456789")); + + var c = Crc16SpiFujitsu.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0xe5cc), c.final()); +} + +test "CRC-16/T10-DIF" { + const Crc16T10Dif = crc.Crc16T10Dif; + + try testing.expectEqual(@as(u16, 0xd0db), Crc16T10Dif.hash("123456789")); + + var c = Crc16T10Dif.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0xd0db), c.final()); +} + +test "CRC-16/TELEDISK" { + const Crc16Teledisk = crc.Crc16Teledisk; + + try testing.expectEqual(@as(u16, 0x0fb3), Crc16Teledisk.hash("123456789")); + + var c = Crc16Teledisk.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0x0fb3), c.final()); +} + +test "CRC-16/TMS37157" { + const Crc16Tms37157 = crc.Crc16Tms37157; + + try testing.expectEqual(@as(u16, 0x26b1), Crc16Tms37157.hash("123456789")); + + var c = Crc16Tms37157.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0x26b1), c.final()); +} + +test "CRC-16/UMTS" { + const Crc16Umts = crc.Crc16Umts; + + try testing.expectEqual(@as(u16, 0xfee8), Crc16Umts.hash("123456789")); + + var c = Crc16Umts.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0xfee8), c.final()); +} + +test "CRC-16/USB" { + const Crc16Usb = crc.Crc16Usb; + + try testing.expectEqual(@as(u16, 0xb4c8), Crc16Usb.hash("123456789")); + + var c = Crc16Usb.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0xb4c8), c.final()); +} + +test "CRC-16/XMODEM" { + const Crc16Xmodem = crc.Crc16Xmodem; + + try testing.expectEqual(@as(u16, 0x31c3), Crc16Xmodem.hash("123456789")); + + var c = Crc16Xmodem.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u16, 0x31c3), c.final()); +} + +test "CRC-17/CAN-FD" { + const Crc17CanFd = crc.Crc17CanFd; + + try testing.expectEqual(@as(u17, 0x04f03), Crc17CanFd.hash("123456789")); + + var c = Crc17CanFd.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u17, 0x04f03), c.final()); +} + +test "CRC-21/CAN-FD" { + const Crc21CanFd = crc.Crc21CanFd; + + try testing.expectEqual(@as(u21, 0x0ed841), Crc21CanFd.hash("123456789")); + + var c = Crc21CanFd.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u21, 0x0ed841), c.final()); +} + +test "CRC-24/BLE" { + const Crc24Ble = crc.Crc24Ble; + + try testing.expectEqual(@as(u24, 0xc25a56), Crc24Ble.hash("123456789")); + + var c = Crc24Ble.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u24, 0xc25a56), c.final()); +} + +test "CRC-24/FLEXRAY-A" { + const Crc24FlexrayA = crc.Crc24FlexrayA; + + try testing.expectEqual(@as(u24, 0x7979bd), Crc24FlexrayA.hash("123456789")); + + var c = Crc24FlexrayA.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u24, 0x7979bd), c.final()); +} + +test "CRC-24/FLEXRAY-B" { + const Crc24FlexrayB = crc.Crc24FlexrayB; + + try testing.expectEqual(@as(u24, 0x1f23b8), Crc24FlexrayB.hash("123456789")); + + var c = Crc24FlexrayB.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u24, 0x1f23b8), c.final()); +} + +test "CRC-24/INTERLAKEN" { + const Crc24Interlaken = crc.Crc24Interlaken; + + try testing.expectEqual(@as(u24, 0xb4f3e6), Crc24Interlaken.hash("123456789")); + + var c = Crc24Interlaken.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u24, 0xb4f3e6), c.final()); +} + +test "CRC-24/LTE-A" { + const Crc24LteA = crc.Crc24LteA; + + try testing.expectEqual(@as(u24, 0xcde703), Crc24LteA.hash("123456789")); + + var c = Crc24LteA.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u24, 0xcde703), c.final()); +} + +test "CRC-24/LTE-B" { + const Crc24LteB = crc.Crc24LteB; + + try testing.expectEqual(@as(u24, 0x23ef52), Crc24LteB.hash("123456789")); + + var c = Crc24LteB.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u24, 0x23ef52), c.final()); +} + +test "CRC-24/OPENPGP" { + const Crc24Openpgp = crc.Crc24Openpgp; + + try testing.expectEqual(@as(u24, 0x21cf02), Crc24Openpgp.hash("123456789")); + + var c = Crc24Openpgp.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u24, 0x21cf02), c.final()); +} + +test "CRC-24/OS-9" { + const Crc24Os9 = crc.Crc24Os9; + + try testing.expectEqual(@as(u24, 0x200fa5), Crc24Os9.hash("123456789")); + + var c = Crc24Os9.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u24, 0x200fa5), c.final()); +} + +test "CRC-30/CDMA" { + const Crc30Cdma = crc.Crc30Cdma; + + try testing.expectEqual(@as(u30, 0x04c34abf), Crc30Cdma.hash("123456789")); + + var c = Crc30Cdma.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u30, 0x04c34abf), c.final()); +} + +test "CRC-31/PHILIPS" { + const Crc31Philips = crc.Crc31Philips; + + try testing.expectEqual(@as(u31, 0x0ce9e46c), Crc31Philips.hash("123456789")); + + var c = Crc31Philips.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u31, 0x0ce9e46c), c.final()); +} + +test "CRC-32/AIXM" { + const Crc32Aixm = crc.Crc32Aixm; + + try testing.expectEqual(@as(u32, 0x3010bf7f), Crc32Aixm.hash("123456789")); + + var c = Crc32Aixm.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u32, 0x3010bf7f), c.final()); +} + +test "CRC-32/AUTOSAR" { + const Crc32Autosar = crc.Crc32Autosar; + + try testing.expectEqual(@as(u32, 0x1697d06a), Crc32Autosar.hash("123456789")); + + var c = Crc32Autosar.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u32, 0x1697d06a), c.final()); +} + +test "CRC-32/BASE91-D" { + const Crc32Base91D = crc.Crc32Base91D; + + try testing.expectEqual(@as(u32, 0x87315576), Crc32Base91D.hash("123456789")); + + var c = Crc32Base91D.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u32, 0x87315576), c.final()); +} + +test "CRC-32/BZIP2" { + const Crc32Bzip2 = crc.Crc32Bzip2; + + try testing.expectEqual(@as(u32, 0xfc891918), Crc32Bzip2.hash("123456789")); + + var c = Crc32Bzip2.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u32, 0xfc891918), c.final()); +} + +test "CRC-32/CD-ROM-EDC" { + const Crc32CdRomEdc = crc.Crc32CdRomEdc; + + try testing.expectEqual(@as(u32, 0x6ec2edc4), Crc32CdRomEdc.hash("123456789")); + + var c = Crc32CdRomEdc.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u32, 0x6ec2edc4), c.final()); +} + +test "CRC-32/CKSUM" { + const Crc32Cksum = crc.Crc32Cksum; + + try testing.expectEqual(@as(u32, 0x765e7680), Crc32Cksum.hash("123456789")); + + var c = Crc32Cksum.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u32, 0x765e7680), c.final()); +} + +test "CRC-32/ISCSI" { + const Crc32Iscsi = crc.Crc32Iscsi; + + try testing.expectEqual(@as(u32, 0xe3069283), Crc32Iscsi.hash("123456789")); + + var c = Crc32Iscsi.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u32, 0xe3069283), c.final()); +} + +test "CRC-32/ISO-HDLC" { + const Crc32IsoHdlc = crc.Crc32IsoHdlc; + + try testing.expectEqual(@as(u32, 0xcbf43926), Crc32IsoHdlc.hash("123456789")); + + var c = Crc32IsoHdlc.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u32, 0xcbf43926), c.final()); +} + +test "CRC-32/JAMCRC" { + const Crc32Jamcrc = crc.Crc32Jamcrc; + + try testing.expectEqual(@as(u32, 0x340bc6d9), Crc32Jamcrc.hash("123456789")); + + var c = Crc32Jamcrc.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u32, 0x340bc6d9), c.final()); +} + +test "CRC-32/MEF" { + const Crc32Mef = crc.Crc32Mef; + + try testing.expectEqual(@as(u32, 0xd2c22f51), Crc32Mef.hash("123456789")); + + var c = Crc32Mef.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u32, 0xd2c22f51), c.final()); +} + +test "CRC-32/MPEG-2" { + const Crc32Mpeg2 = crc.Crc32Mpeg2; + + try testing.expectEqual(@as(u32, 0x0376e6e7), Crc32Mpeg2.hash("123456789")); + + var c = Crc32Mpeg2.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u32, 0x0376e6e7), c.final()); +} + +test "CRC-32/XFER" { + const Crc32Xfer = crc.Crc32Xfer; + + try testing.expectEqual(@as(u32, 0xbd0be338), Crc32Xfer.hash("123456789")); + + var c = Crc32Xfer.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u32, 0xbd0be338), c.final()); +} + +test "CRC-40/GSM" { + const Crc40Gsm = crc.Crc40Gsm; + + try testing.expectEqual(@as(u40, 0xd4164fc646), Crc40Gsm.hash("123456789")); + + var c = Crc40Gsm.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u40, 0xd4164fc646), c.final()); +} + +test "CRC-64/ECMA-182" { + const Crc64Ecma182 = crc.Crc64Ecma182; + + try testing.expectEqual(@as(u64, 0x6c40df5f0b497347), Crc64Ecma182.hash("123456789")); + + var c = Crc64Ecma182.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u64, 0x6c40df5f0b497347), c.final()); +} + +test "CRC-64/GO-ISO" { + const Crc64GoIso = crc.Crc64GoIso; + + try testing.expectEqual(@as(u64, 0xb90956c775a41001), Crc64GoIso.hash("123456789")); + + var c = Crc64GoIso.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u64, 0xb90956c775a41001), c.final()); +} + +test "CRC-64/MS" { + const Crc64Ms = crc.Crc64Ms; + + try testing.expectEqual(@as(u64, 0x75d4b74f024eceea), Crc64Ms.hash("123456789")); + + var c = Crc64Ms.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u64, 0x75d4b74f024eceea), c.final()); +} + +test "CRC-64/REDIS" { + const Crc64Redis = crc.Crc64Redis; + + try testing.expectEqual(@as(u64, 0xe9c6d914c4b8d9ca), Crc64Redis.hash("123456789")); + + var c = Crc64Redis.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u64, 0xe9c6d914c4b8d9ca), c.final()); +} + +test "CRC-64/WE" { + const Crc64We = crc.Crc64We; + + try testing.expectEqual(@as(u64, 0x62ec59e3f1a4f00a), Crc64We.hash("123456789")); + + var c = Crc64We.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u64, 0x62ec59e3f1a4f00a), c.final()); +} + +test "CRC-64/XZ" { + const Crc64Xz = crc.Crc64Xz; + + try testing.expectEqual(@as(u64, 0x995dc9bbdf1939fa), Crc64Xz.hash("123456789")); + + var c = Crc64Xz.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u64, 0x995dc9bbdf1939fa), c.final()); +} + +test "CRC-82/DARC" { + const Crc82Darc = crc.Crc82Darc; + + try testing.expectEqual(@as(u82, 0x09ea83f625023801fd612), Crc82Darc.hash("123456789")); + + var c = Crc82Darc.init(); + c.update("1234"); + c.update("56789"); + try testing.expectEqual(@as(u82, 0x09ea83f625023801fd612), c.final()); +} diff --git a/tools/update_crc_catalog.zig b/tools/update_crc_catalog.zig index 0e8d9b3ef81948f52c12fd9ad6602a901e30151c..31d0b55e1b01eed6b38d369296e24ccc716c8796 100644 --- a/tools/update_crc_catalog.zig +++ b/tools/update_crc_catalog.zig @@ -23,11 +23,15 @@ pub fn main() anyerror!void { var zig_src_dir = try fs.cwd().openDir(zig_src_root, .{}); defer zig_src_dir.close(); - const target_sub_path = try fs.path.join(arena, &.{ "lib", "std", "hash", "crc" }); - var target_dir = try zig_src_dir.makeOpenPath(target_sub_path, .{}); - defer target_dir.close(); + const hash_sub_path = try fs.path.join(arena, &.{ "lib", "std", "hash" }); + var hash_target_dir = try zig_src_dir.makeOpenPath(hash_sub_path, .{}); + defer hash_target_dir.close(); - var zig_code_file = try target_dir.createFile("catalog.zig", .{}); + const crc_sub_path = try fs.path.join(arena, &.{ "lib", "std", "hash", "crc" }); + var crc_target_dir = try zig_src_dir.makeOpenPath(crc_sub_path, .{}); + defer crc_target_dir.close(); + + var zig_code_file = try hash_target_dir.createFile("crc.zig", .{}); defer zig_code_file.close(); var cbw = std.io.bufferedWriter(zig_code_file.writer()); @@ -37,15 +41,23 @@ pub fn main() anyerror!void { try code_writer.writeAll( \\//! This file is auto-generated by tools/update_crc_catalog.zig. \\ - \\const Crc = @import("../crc.zig").Crc; + \\const impl = @import("crc/impl.zig"); + \\ + \\pub const Crc = impl.Crc; + \\pub const Polynomial = impl.Polynomial; + \\pub const Crc32WithPoly = impl.Crc32WithPoly; + \\pub const Crc32SmallWithPoly = impl.Crc32SmallWithPoly; + \\ + \\// IEEE is by far the most common CRC and so is aliased by default. + \\pub const Crc32 = Crc32WithPoly(.IEEE); \\ \\test { - \\ _ = @import("catalog_test.zig"); + \\ _ = @import("crc/test.zig"); \\} \\ ); - var zig_test_file = try target_dir.createFile("catalog_test.zig", .{}); + var zig_test_file = try crc_target_dir.createFile("test.zig", .{}); defer zig_test_file.close(); var tbw = std.io.bufferedWriter(zig_test_file.writer()); @@ -57,7 +69,26 @@ pub fn main() anyerror!void { \\ \\const std = @import("std"); \\const testing = std.testing; - \\const catalog = @import("catalog.zig"); + \\const verify = @import("../verify.zig"); + \\const crc = @import("../crc.zig"); + \\ + \\test "crc32 ieee" { + \\ inline for ([2]type{ crc.Crc32WithPoly(.IEEE), crc.Crc32SmallWithPoly(.IEEE) }) |ieee| { + \\ try testing.expect(ieee.hash("") == 0x00000000); + \\ try testing.expect(ieee.hash("a") == 0xe8b7be43); + \\ try testing.expect(ieee.hash("abc") == 0x352441c2); + \\ try verify.iterativeApi(ieee); + \\ } + \\} + \\ + \\test "crc32 castagnoli" { + \\ inline for ([2]type{ crc.Crc32WithPoly(.Castagnoli), crc.Crc32SmallWithPoly(.Castagnoli) }) |casta| { + \\ try testing.expect(casta.hash("") == 0x00000000); + \\ try testing.expect(casta.hash("a") == 0xc1d04330); + \\ try testing.expect(casta.hash("abc") == 0x364b3fb7); + \\ try verify.iterativeApi(casta); + \\ } + \\} \\ ); @@ -146,7 +177,7 @@ pub fn main() anyerror!void { try test_writer.writeAll(try std.fmt.allocPrint(arena, \\ \\test "{0s}" {{ - \\ const {1s} = catalog.{1s}; + \\ const {1s} = crc.{1s}; \\ \\ try testing.expectEqual(@as(u{2s}, {3s}), {1s}.hash("123456789")); \\