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