| 1 |
// Copyright 2025 Don MacAskill. Licensed under MIT or Apache-2.0. |
| 2 |
|
| 3 |
#![allow(dead_code)] |
| 4 |
|
| 5 |
use crate::consts::*; |
| 6 |
use crate::CrcAlgorithm; |
| 7 |
use crate::CrcParams; |
| 8 |
use crc::{CRC_64_ECMA_182, CRC_64_GO_ISO, CRC_64_MS, CRC_64_REDIS, CRC_64_WE, CRC_64_XZ}; |
| 9 |
|
| 10 |
// width=64 poly=0x42f0e1eba9ea3693 init=0x0000000000000000 refin=false refout=false xorout=0x0000000000000000 check=0x6c40df5f0b497347 residue=0x0000000000000000 name="CRC-64/ECMA-182" |
| 11 |
pub const CRC64_ECMA_182: CrcParams = CrcParams { |
| 12 |
algorithm: CrcAlgorithm::Crc64Ecma182, |
| 13 |
name: NAME_CRC64_ECMA_182, |
| 14 |
width: CRC_64_ECMA_182.width, |
| 15 |
poly: CRC_64_ECMA_182.poly, |
| 16 |
init: CRC_64_ECMA_182.init, |
| 17 |
init_algorithm: CRC_64_ECMA_182.init, |
| 18 |
refin: CRC_64_ECMA_182.refin, // false |
| 19 |
refout: CRC_64_ECMA_182.refout, // false |
| 20 |
xorout: CRC_64_ECMA_182.xorout, |
| 21 |
check: CRC_64_ECMA_182.check, |
| 22 |
keys: crate::CrcKeysStorage::from_keys_fold_256(KEYS_42F0E1EBA9EA3693_FORWARD), |
| 23 |
}; |
| 24 |
|
| 25 |
// width=64 poly=0x000000000000001b init=0xffffffffffffffff refin=true refout=true xorout=0xffffffffffffffff check=0xb90956c775a41001 residue=0x5300000000000000 name="CRC-64/GO-ISO" |
| 26 |
pub const CRC64_GO_ISO: CrcParams = CrcParams { |
| 27 |
algorithm: CrcAlgorithm::Crc64GoIso, |
| 28 |
name: NAME_CRC64_GO_ISO, |
| 29 |
width: CRC_64_GO_ISO.width, |
| 30 |
poly: CRC_64_GO_ISO.poly, |
| 31 |
init: CRC_64_GO_ISO.init, |
| 32 |
init_algorithm: CRC_64_GO_ISO.init, |
| 33 |
refin: CRC_64_GO_ISO.refin, // true |
| 34 |
refout: CRC_64_GO_ISO.refout, // true |
| 35 |
xorout: CRC_64_GO_ISO.xorout, |
| 36 |
check: CRC_64_GO_ISO.check, |
| 37 |
keys: crate::CrcKeysStorage::from_keys_fold_256(KEYS_000000000000001B_REFLECTED), |
| 38 |
}; |
| 39 |
|
| 40 |
// width=64 poly=0x259c84cba6426349 init=0xffffffffffffffff refin=true refout=true xorout=0x0000000000000000 check=0x75d4b74f024eceea residue=0x0000000000000000 name="CRC-64/MS" |
| 41 |
pub const CRC64_MS: CrcParams = CrcParams { |
| 42 |
algorithm: CrcAlgorithm::Crc64Ms, |
| 43 |
name: NAME_CRC64_MS, |
| 44 |
width: 64, |
| 45 |
poly: CRC_64_MS.poly, |
| 46 |
init: CRC_64_MS.init, |
| 47 |
init_algorithm: CRC_64_MS.init, |
| 48 |
refin: CRC_64_MS.refin, // true |
| 49 |
refout: CRC_64_MS.refout, // true |
| 50 |
xorout: CRC_64_MS.xorout, |
| 51 |
check: CRC_64_MS.check, |
| 52 |
keys: crate::CrcKeysStorage::from_keys_fold_256(KEYS_259C84CBA6426349_REFLECTED), |
| 53 |
}; |
| 54 |
|
| 55 |
// https://reveng.sourceforge.io/crc-catalogue/all.htm#crc.cat.crc-64-nvme |
| 56 |
// width=64 poly=0xad93d23594c93659 init=0xffffffffffffffff refin=true refout=true xorout=0xffffffffffffffff check=0xae8b14860a799888 residue=0xf310303b2b6f6e42 name="CRC-64/NVME" |
| 57 |
pub const CRC64_NVME: CrcParams = CrcParams { |
| 58 |
algorithm: CrcAlgorithm::Crc64Nvme, |
| 59 |
name: NAME_CRC64_NVME, |
| 60 |
width: CRC_64_NVME.width, |
| 61 |
poly: CRC_64_NVME.poly, |
| 62 |
init: CRC_64_NVME.init, |
| 63 |
init_algorithm: CRC_64_NVME.init, |
| 64 |
refin: CRC_64_NVME.refin, // true |
| 65 |
refout: CRC_64_NVME.refout, // true |
| 66 |
xorout: CRC_64_NVME.xorout, |
| 67 |
check: CRC_64_NVME.check, |
| 68 |
keys: crate::CrcKeysStorage::from_keys_fold_256(KEYS_AD93D23594C93659_REFLECTED), |
| 69 |
}; |
| 70 |
|
| 71 |
// width=64 poly=0xad93d23594c935a9 init=0x0000000000000000 refin=true refout=true xorout=0x0000000000000000 check=0xe9c6d914c4b8d9ca residue=0x0000000000000000 name="CRC-64/REDIS" |
| 72 |
pub const CRC64_REDIS: CrcParams = CrcParams { |
| 73 |
algorithm: CrcAlgorithm::Crc64Redis, |
| 74 |
name: NAME_CRC64_REDIS, |
| 75 |
width: CRC_64_REDIS.width, |
| 76 |
poly: CRC_64_REDIS.poly, |
| 77 |
init: CRC_64_REDIS.init, |
| 78 |
init_algorithm: CRC_64_REDIS.init, |
| 79 |
refin: CRC_64_REDIS.refin, // true |
| 80 |
refout: CRC_64_REDIS.refout, // true |
| 81 |
xorout: CRC_64_REDIS.xorout, |
| 82 |
check: CRC_64_REDIS.check, |
| 83 |
keys: crate::CrcKeysStorage::from_keys_fold_256(KEYS_AD93D23594C935A9_REFLECTED), |
| 84 |
}; |
| 85 |
|
| 86 |
// width=64 poly=0x42f0e1eba9ea3693 init=0xffffffffffffffff refin=false refout=false xorout=0xffffffffffffffff check=0x62ec59e3f1a4f00a residue=0xfcacbebd5931a992 name="CRC-64/WE" |
| 87 |
pub const CRC64_WE: CrcParams = CrcParams { |
| 88 |
algorithm: CrcAlgorithm::Crc64We, |
| 89 |
name: NAME_CRC64_WE, |
| 90 |
width: CRC_64_WE.width, |
| 91 |
poly: CRC_64_WE.poly, |
| 92 |
init: CRC_64_WE.init, |
| 93 |
init_algorithm: CRC_64_WE.init, |
| 94 |
refin: CRC_64_WE.refin, // false |
| 95 |
refout: CRC_64_WE.refout, // false |
| 96 |
xorout: CRC_64_WE.xorout, |
| 97 |
check: CRC_64_WE.check, |
| 98 |
keys: crate::CrcKeysStorage::from_keys_fold_256(KEYS_42F0E1EBA9EA3693_FORWARD), |
| 99 |
}; |
| 100 |
|
| 101 |
// width=64 poly=0x42f0e1eba9ea3693 init=0xffffffffffffffff refin=true refout=true xorout=0xffffffffffffffff check=0x995dc9bbdf1939fa residue=0x49958c9abd7d353f name="CRC-64/XZ" |
| 102 |
pub const CRC64_XZ: CrcParams = CrcParams { |
| 103 |
algorithm: CrcAlgorithm::Crc64Xz, |
| 104 |
name: NAME_CRC64_XZ, |
| 105 |
width: CRC_64_XZ.width, |
| 106 |
poly: CRC_64_XZ.poly, |
| 107 |
init: CRC_64_XZ.init, |
| 108 |
init_algorithm: CRC_64_XZ.init, |
| 109 |
refin: CRC_64_XZ.refin, // true |
| 110 |
refout: CRC_64_XZ.refout, // true |
| 111 |
xorout: CRC_64_XZ.xorout, |
| 112 |
check: CRC_64_XZ.check, |
| 113 |
keys: crate::CrcKeysStorage::from_keys_fold_256(KEYS_42F0E1EBA9EA3693_REFLECTED), |
| 114 |
}; |
| 115 |
|
| 116 |
// CRC-64/MS |
| 117 |
const KEYS_259C84CBA6426349_REFLECTED: [u64; 23] = [ |
| 118 |
0x0000000000000000, |
| 119 |
0xcef05cca14bbf4df, |
| 120 |
0xfd5d7a0700b5ba38, |
| 121 |
0xafde70a30ebb4286, |
| 122 |
0xe7a651bf12fbb17b, |
| 123 |
0xcef05cca14bbf4df, |
| 124 |
0x0000000000000000, |
| 125 |
0xd7eb06822197a109, |
| 126 |
0x258c84cba6427349, |
| 127 |
0x9f5bbc2a0e2e4c6f, |
| 128 |
0x50e15bfbd337753a, |
| 129 |
0x064a94c5212d44f4, |
| 130 |
0x4aaa0531d46f3c70, |
| 131 |
0xebd4e5a2eb6d83a1, |
| 132 |
0x295b872fea8473f0, |
| 133 |
0xa62bc2d50bf03c03, |
| 134 |
0xd3e2dc3a51dacee1, |
| 135 |
0x4aa4564b4042092b, |
| 136 |
0x717984ed338c465f, |
| 137 |
0x70bd522114faceb8, |
| 138 |
0x2188097f5687b43c, |
| 139 |
0xb7c2f9fa47c4fe55, |
| 140 |
0x8dccaf9d6169d0fa, |
| 141 |
]; |
| 142 |
|
| 143 |
// CRC-64/REDIS |
| 144 |
const KEYS_AD93D23594C935A9_REFLECTED: [u64; 23] = [ |
| 145 |
0x0000000000000000, |
| 146 |
0x381d0015c96f4444, |
| 147 |
0xd9d7be7d505da32c, |
| 148 |
0x768361524d29ed0b, |
| 149 |
0xcc26fa7c57f8054c, |
| 150 |
0x381d0015c96f4444, |
| 151 |
0x0000000000000000, |
| 152 |
0x3e6cfa329aef9f77, |
| 153 |
0x2b5926535897936b, |
| 154 |
0x5bc94ba8e2087636, |
| 155 |
0x6cf09c8f37710b75, |
| 156 |
0x3885fd59e440d95a, |
| 157 |
0xbccba3936411fb7e, |
| 158 |
0xe4dd0d81cbfce585, |
| 159 |
0xb715e37b96ed8633, |
| 160 |
0xf49784a634f014e4, |
| 161 |
0xaf86efb16d9ab4fb, |
| 162 |
0x7b3211a760160db8, |
| 163 |
0xa062b2319d66692f, |
| 164 |
0xef3d1d18ed889ed2, |
| 165 |
0x6ba4d760ab38201e, |
| 166 |
0x9471a5389095fe44, |
| 167 |
0x9a8908341a6d6d52, |
| 168 |
]; |
| 169 |
|
| 170 |
// CRC-64/ECMA-182, CRC-64/WE |
| 171 |
const KEYS_42F0E1EBA9EA3693_FORWARD: [u64; 23] = [ |
| 172 |
0x0000000000000000, // unused placeholder to match 1-based indexing |
| 173 |
0x05f5c3c7eb52fab6, // 2^(64* 2) mod P(x) |
| 174 |
0x4eb938a7d257740e, // 2^(64* 3) mod P(x) |
| 175 |
0x05cf79dea9ac37d6, // 2^(64*16) mod P(x) |
| 176 |
0x001067e571d7d5c2, // 2^(64*17) mod P(x) |
| 177 |
0x05f5c3c7eb52fab6, // 2^(64* 2) mod P(x) |
| 178 |
0x0000000000000000, // 2^(64* 1) mod P(x) |
| 179 |
0x578d29d06cc4f872, // floor(2^128/P(x)) - 2^64, mu |
| 180 |
0x42f0e1eba9ea3693, // P(x) - 2^64, poly_simd |
| 181 |
0xe464f4df5fb60ac1, // 2^(64*14) mod P(x) |
| 182 |
0xb649c5b35a759cf2, // 2^(64*15) mod P(x) |
| 183 |
0x9af04e1eff82d0dd, // 2^(64*12) mod P(x) |
| 184 |
0x6e82e609297f8fe8, // 2^(64*13) mod P(x) |
| 185 |
0x097c516e98bd2e73, // 2^(64*10) mod P(x) |
| 186 |
0x0b76477b31e22e7b, // 2^(64*11) mod P(x) |
| 187 |
0x5f6843ca540df020, // 2^(64* 8) mod P(x) |
| 188 |
0xddf4b6981205b83f, // 2^(64* 9) mod P(x) |
| 189 |
0x54819d8713758b2c, // 2^(64* 6) mod P(x) |
| 190 |
0x4a6b90073eb0af5a, // 2^(64* 7) mod P(x) |
| 191 |
0x571bee0a227ef92b, // 2^(64* 4) mod P(x) |
| 192 |
0x44bef2a201b5200c, // 2^(64* 5) mod P(x) |
| 193 |
0x7f52691a60ddc70d, |
| 194 |
0x7036b0389f6a0c82, |
| 195 |
]; |
| 196 |
|
| 197 |
// CRC-64/XZ |
| 198 |
const KEYS_42F0E1EBA9EA3693_REFLECTED: [u64; 23] = [ |
| 199 |
0x0000000000000000, // unused placeholder to match 1-based indexing |
| 200 |
0xdabe95afc7875f40, // 2^((64* 2)-1) mod P(x) |
| 201 |
0xe05dd497ca393ae4, // 2^((64* 3)-1) mod P(x) |
| 202 |
0xd7d86b2af73de740, // 2^((64*16)-1) mod P(x) |
| 203 |
0x8757d71d4fcc1000, // 2^((64*17)-1) mod P(x) |
| 204 |
0xdabe95afc7875f40, // 2^((64* 2)-1) mod P(x) |
| 205 |
0x0000000000000000, // 2^((64* 1)-1) mod P(x) |
| 206 |
0x9c3e466c172963d5, // floor((2^127)/(P(x)), mu |
| 207 |
0x92d8af2baf0e1e85, // P(x) - 1, poly_simd |
| 208 |
0x947874de595052cb, // 2^((64*14)-1) mod P(x) |
| 209 |
0x9e735cb59b4724da, // 2^((64*15)-1) mod P(x) |
| 210 |
0xe4ce2cd55fea0037, // 2^((64*12)-1) mod P(x) |
| 211 |
0x2fe3fd2920ce82ec, // 2^((64*13)-1) mod P(x) |
| 212 |
0x0e31d519421a63a5, // 2^((64*10)-1) mod P(x) |
| 213 |
0x2e30203212cac325, // 2^((64*11)-1) mod P(x) |
| 214 |
0x081f6054a7842df4, // 2^((64* 8)-1) mod P(x) |
| 215 |
0x6ae3efbb9dd441f3, // 2^((64* 9)-1) mod P(x) |
| 216 |
0x69a35d91c3730254, // 2^((64* 6)-1) mod P(x) |
| 217 |
0xb5ea1af9c013aca4, // 2^((64* 7)-1) mod P(x) |
| 218 |
0x3be653a30fe1af51, // 2^((64* 4)-1) mod P(x) |
| 219 |
0x60095b008a9efa44, // 2^((64* 5)-1) mod P(x) |
| 220 |
0xf31fd9271e228b79, |
| 221 |
0x8260adf2381ad81c, |
| 222 |
]; |
| 223 |
|
| 224 |
// CRC-64/GO-ISO |
| 225 |
const KEYS_000000000000001B_REFLECTED: [u64; 23] = [ |
| 226 |
0x0000000000000000, // unused placeholder to match 1-based indexing |
| 227 |
0xf500000000000001, // 2^((64* 2)-1) mod P(x) |
| 228 |
0x6b70000000000001, // 2^((64* 3)-1) mod P(x) |
| 229 |
0xb001000000010000, // 2^((64*16)-1) mod P(x) |
| 230 |
0xf501b0000001b000, // 2^((64*17)-1) mod P(x) |
| 231 |
0xf500000000000001, // 2^((64* 2)-1) mod P(x) |
| 232 |
0x0000000000000000, // 2^((64* 1)-1) mod P(x) |
| 233 |
0xb000000000000001, // floor((2^127)/(P(x)), mu |
| 234 |
0xb000000000000001, // P(x) - 1, poly_simd |
| 235 |
0xe014514514501501, // 2^((64*14)-1) mod P(x) |
| 236 |
0x771db6db6db71c71, // 2^((64*15)-1) mod P(x) |
| 237 |
0xa101101101110001, // 2^((64*12)-1) mod P(x) |
| 238 |
0x1ab1ab1ab1aab001, // 2^((64*13)-1) mod P(x) |
| 239 |
0xf445014445000001, // 2^((64*10)-1) mod P(x) |
| 240 |
0x6aab71daab700001, // 2^((64*11)-1) mod P(x) |
| 241 |
0xb100010100000001, // 2^((64* 8)-1) mod P(x) |
| 242 |
0x01b001b1b0000001, // 2^((64* 9)-1) mod P(x) |
| 243 |
0xe145150000000001, // 2^((64* 6)-1) mod P(x) |
| 244 |
0x76db6c7000000001, // 2^((64* 7)-1) mod P(x) |
| 245 |
0xa011000000000001, // 2^((64* 4)-1) mod P(x) |
| 246 |
0x1b1ab00000000001, // 2^((64* 5)-1) mod P(x) |
| 247 |
0x45000000b0000000, |
| 248 |
0x6b700000f5000000, |
| 249 |
]; |
| 250 |
|
| 251 |
// CRC-64/NVME |
| 252 |
const KEYS_AD93D23594C93659_REFLECTED: [u64; 23] = [ |
| 253 |
0x0000000000000000, // unused placeholder to match 1-based indexing |
| 254 |
0x21e9_761e_2526_21ac, |
| 255 |
0xeadc_41fd_2ba3_d420, |
| 256 |
0x5f85_2fb6_1e8d_92dc, |
| 257 |
0xa1ca_681e_733f_9c40, |
| 258 |
0x21e9_761e_2526_21ac, |
| 259 |
0x0000000000000000, |
| 260 |
0x27ec_fa32_9aef_9f77, // mu |
| 261 |
0x34d9_2653_5897_936b, // poly |
| 262 |
0x9465_8840_3d4a_dcbc, |
| 263 |
0xd083_dd59_4d96_319d, |
| 264 |
0x34f5_a24e_22d6_6e90, |
| 265 |
0x3c25_5f5e_bc41_4423, |
| 266 |
0x0336_3823_e6e7_91e5, |
| 267 |
0x7b0a_b10d_d0f8_09fe, |
| 268 |
0x6224_2240_ace5_045a, |
| 269 |
0x0c32_cdb3_1e18_a84a, |
| 270 |
0xa3ff_dc1f_e8e8_2a8b, |
| 271 |
0xbdd7_ac0e_e1a4_a0f0, |
| 272 |
0xe1e0_bb9d_45d7_a44c, |
| 273 |
0xb0bc_2e58_9204_f500, |
| 274 |
0xa043_808c_0f78_2663, |
| 275 |
0x37cc_d3e1_4069_cabc, |
| 276 |
]; |
| 277 |
|
| 278 |
pub const SIMD_CONSTANTS: [[u64; 2]; 4] = [ |
| 279 |
[0x08090a0b0c0d0e0f, 0x0001020304050607], // smask |
| 280 |
[0x8080808080808080, 0x8080808080808080], // mask1 |
| 281 |
[0xffffffffffffffff, 0x00000000ffffffff], // mask2 |
| 282 |
[0x0000000000000000, 0xffffffffffffffff], // mask3 |
| 283 |
]; |
| 284 |
|
| 285 |
/// Lookup tables for byte reflection and other operations |
| 286 |
#[repr(C, align(16))] |
| 287 |
pub struct AlignedTableReverse { |
| 288 |
row1: [u8; 16], |
| 289 |
row2: [u8; 16], |
| 290 |
} |
| 291 |
|
| 292 |
pub const PSBTBL_REVERSE: AlignedTableReverse = AlignedTableReverse { |
| 293 |
row1: [ |
| 294 |
// First row (quadwords 1&2): 08786858483828100h, 08f8e8d8c8b8a8988h |
| 295 |
0x00, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, |
| 296 |
0x8f, |
| 297 |
], |
| 298 |
row2: [ |
| 299 |
// Second row (quadwords 3&4): 00706050403020100h, 0000e0d0c0b0a0908h |
| 300 |
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, |
| 301 |
0x00, |
| 302 |
], |
| 303 |
}; |
| 304 |
|
| 305 |
#[repr(C, align(16))] |
| 306 |
pub struct AlignedTableForward { |
| 307 |
row1: [u8; 16], |
| 308 |
row2: [u8; 16], |
| 309 |
row3: [u8; 16], |
| 310 |
row4: [u8; 16], |
| 311 |
} |
| 312 |
|
| 313 |
pub const PSBTBL_FORWARD: AlignedTableForward = AlignedTableForward { |
| 314 |
// First row: 08786858483828100h, 08f8e8d8c8b8a8988h |
| 315 |
row1: [ |
| 316 |
0x00, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, |
| 317 |
0x8f, |
| 318 |
], |
| 319 |
// Second row: 00706050403020100h, 00f0e0d0c0b0a0908h |
| 320 |
row2: [ |
| 321 |
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, |
| 322 |
0x0f, |
| 323 |
], |
| 324 |
// Third row: 08080808080808080h, 00f0e0d0c0b0a0908h |
| 325 |
row3: [ |
| 326 |
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, |
| 327 |
0x0f, |
| 328 |
], |
| 329 |
// Fourth row: 08080808080808080h, 08080808080808080h |
| 330 |
row4: [ |
| 331 |
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, |
| 332 |
0x80, |
| 333 |
], |
| 334 |
}; |