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