| 1 |
// Copyright 2025 Don MacAskill. Licensed under MIT or Apache-2.0. |
| 2 |
|
| 3 |
#![allow(dead_code)] |
| 4 |
|
| 5 |
use crc::Algorithm; |
| 6 |
|
| 7 |
// Constants for common values with semantic meaning |
| 8 |
pub(crate) const CRC_CHUNK_SIZE: usize = 16; |
| 9 |
pub(crate) const CRC_HALF_CHUNK_SIZE: usize = 8; |
| 10 |
pub(crate) const CRC_LARGE_CHUNK_THRESHOLD: usize = 256; |
| 11 |
|
| 12 |
pub const NAME_CRC16_ARC: &str = "CRC-16/ARC"; |
| 13 |
pub const NAME_CRC16_CDMA2000: &str = "CRC-16/CDMA2000"; |
| 14 |
pub const NAME_CRC16_CMS: &str = "CRC-16/CMS"; |
| 15 |
pub const NAME_CRC16_DDS_110: &str = "CRC-16/DDS-110"; |
| 16 |
pub const NAME_CRC16_DECT_R: &str = "CRC-16/DECT-R"; |
| 17 |
pub const NAME_CRC16_DECT_X: &str = "CRC-16/DECT-X"; |
| 18 |
pub const NAME_CRC16_DNP: &str = "CRC-16/DNP"; |
| 19 |
pub const NAME_CRC16_EN_13757: &str = "CRC-16/EN-13757"; |
| 20 |
pub const NAME_CRC16_GENIBUS: &str = "CRC-16/GENIBUS"; |
| 21 |
pub const NAME_CRC16_GSM: &str = "CRC-16/GSM"; |
| 22 |
pub const NAME_CRC16_IBM_3740: &str = "CRC-16/IBM-3740"; |
| 23 |
pub const NAME_CRC16_IBM_SDLC: &str = "CRC-16/IBM-SDLC"; |
| 24 |
pub const NAME_CRC16_ISO_IEC_14443_3_A: &str = "CRC-16/ISO-IEC-14443-3-A"; |
| 25 |
pub const NAME_CRC16_KERMIT: &str = "CRC-16/KERMIT"; |
| 26 |
pub const NAME_CRC16_LJ1200: &str = "CRC-16/LJ1200"; |
| 27 |
pub const NAME_CRC16_M17: &str = "CRC-16/M17"; |
| 28 |
pub const NAME_CRC16_MAXIM_DOW: &str = "CRC-16/MAXIM-DOW"; |
| 29 |
pub const NAME_CRC16_MCRF4XX: &str = "CRC-16/MCRF4XX"; |
| 30 |
pub const NAME_CRC16_MODBUS: &str = "CRC-16/MODBUS"; |
| 31 |
pub const NAME_CRC16_NRSC_5: &str = "CRC-16/NRSC-5"; |
| 32 |
pub const NAME_CRC16_OPENSAFETY_A: &str = "CRC-16/OPENSAFETY-A"; |
| 33 |
pub const NAME_CRC16_OPENSAFETY_B: &str = "CRC-16/OPENSAFETY-B"; |
| 34 |
pub const NAME_CRC16_PROFIBUS: &str = "CRC-16/PROFIBUS"; |
| 35 |
pub const NAME_CRC16_RIELLO: &str = "CRC-16/RIELLO"; |
| 36 |
pub const NAME_CRC16_SPI_FUJITSU: &str = "CRC-16/SPI-FUJITSU"; |
| 37 |
pub const NAME_CRC16_T10_DIF: &str = "CRC-16/T10-DIF"; |
| 38 |
pub const NAME_CRC16_TELEDISK: &str = "CRC-16/TELEDISK"; |
| 39 |
pub const NAME_CRC16_TMS37157: &str = "CRC-16/TMS37157"; |
| 40 |
pub const NAME_CRC16_UMTS: &str = "CRC-16/UMTS"; |
| 41 |
pub const NAME_CRC16_USB: &str = "CRC-16/USB"; |
| 42 |
pub const NAME_CRC16_X25: &str = "CRC-16/X-25"; |
| 43 |
pub const NAME_CRC16_XMODEM: &str = "CRC-16/XMODEM"; |
| 44 |
|
| 45 |
pub const NAME_CRC32_AIXM: &str = "CRC-32/AIXM"; |
| 46 |
pub const NAME_CRC32_AUTOSAR: &str = "CRC-32/AUTOSAR"; |
| 47 |
pub const NAME_CRC32_BASE91_D: &str = "CRC-32/BASE91-D"; |
| 48 |
pub const NAME_CRC32_BZIP2: &str = "CRC-32/BZIP2"; |
| 49 |
pub const NAME_CRC32_CD_ROM_EDC: &str = "CRC-32/CD-ROM-EDC"; |
| 50 |
pub const NAME_CRC32_CKSUM: &str = "CRC-32/CKSUM"; |
| 51 |
pub const NAME_CRC32_ISCSI: &str = "CRC-32/ISCSI"; |
| 52 |
pub const NAME_CRC32_ISO_HDLC: &str = "CRC-32/ISO-HDLC"; |
| 53 |
pub const NAME_CRC32_JAMCRC: &str = "CRC-32/JAMCRC"; |
| 54 |
pub const NAME_CRC32_MEF: &str = "CRC-32/MEF"; |
| 55 |
pub const NAME_CRC32_MPEG_2: &str = "CRC-32/MPEG-2"; |
| 56 |
pub const NAME_CRC32_XFER: &str = "CRC-32/XFER"; |
| 57 |
|
| 58 |
pub const NAME_CRC64_ECMA_182: &str = "CRC-64/ECMA-182"; |
| 59 |
pub const NAME_CRC64_GO_ISO: &str = "CRC-64/GO-ISO"; |
| 60 |
pub const NAME_CRC64_MS: &str = "CRC-64/MS"; |
| 61 |
pub const NAME_CRC64_NVME: &str = "CRC-64/NVME"; |
| 62 |
pub const NAME_CRC64_REDIS: &str = "CRC-64/REDIS"; |
| 63 |
pub const NAME_CRC64_WE: &str = "CRC-64/WE"; |
| 64 |
pub const NAME_CRC64_XZ: &str = "CRC-64/XZ"; |
| 65 |
|
| 66 |
// https://reveng.sourceforge.io/crc-catalogue/all.htm#crc.cat.crc-64-nvme |
| 67 |
// width=64 poly=0xad93d23594c93659 init=0xffffffffffffffff refin=true refout=true xorout=0xffffffffffffffff check=0xae8b14860a799888 residue=0xf310303b2b6f6e42 name="CRC-64/NVME" |
| 68 |
pub const CRC_64_NVME: Algorithm<u64> = Algorithm { |
| 69 |
width: 64, |
| 70 |
poly: 0xad93d23594c93659, |
| 71 |
init: 0xFFFFFFFFFFFFFFFF, |
| 72 |
refin: true, |
| 73 |
refout: true, |
| 74 |
xorout: 0xFFFFFFFFFFFFFFFF, |
| 75 |
check: 0xae8b14860a799888, |
| 76 |
residue: 0xf310303b2b6f6e42, |
| 77 |
}; |
| 78 |
|
| 79 |
// for software fallbacks and testing |
| 80 |
pub(crate) const RUST_CRC32_AIXM: crc::Crc<u32> = crc::Crc::<u32>::new(&crc::CRC_32_AIXM); |
| 81 |
|
| 82 |
pub(crate) const RUST_CRC32_AUTOSAR: crc::Crc<u32> = crc::Crc::<u32>::new(&crc::CRC_32_AUTOSAR); |
| 83 |
|
| 84 |
pub(crate) const RUST_CRC32_BASE91_D: crc::Crc<u32> = crc::Crc::<u32>::new(&crc::CRC_32_BASE91_D); |
| 85 |
|
| 86 |
pub(crate) const RUST_CRC32_BZIP2: crc::Crc<u32> = crc::Crc::<u32>::new(&crc::CRC_32_BZIP2); |
| 87 |
|
| 88 |
pub(crate) const RUST_CRC32_CD_ROM_EDC: crc::Crc<u32> = |
| 89 |
crc::Crc::<u32>::new(&crc::CRC_32_CD_ROM_EDC); |
| 90 |
|
| 91 |
pub(crate) const RUST_CRC32_CKSUM: crc::Crc<u32> = crc::Crc::<u32>::new(&crc::CRC_32_CKSUM); |
| 92 |
|
| 93 |
pub(crate) const RUST_CRC32_ISCSI: crc::Crc<u32> = crc::Crc::<u32>::new(&crc::CRC_32_ISCSI); |
| 94 |
|
| 95 |
pub(crate) const RUST_CRC32_ISO_HDLC: crc::Crc<u32> = crc::Crc::<u32>::new(&crc::CRC_32_ISO_HDLC); |
| 96 |
|
| 97 |
pub(crate) const RUST_CRC32_JAMCRC: crc::Crc<u32> = crc::Crc::<u32>::new(&crc::CRC_32_JAMCRC); |
| 98 |
|
| 99 |
pub(crate) const RUST_CRC32_MEF: crc::Crc<u32> = crc::Crc::<u32>::new(&crc::CRC_32_MEF); |
| 100 |
|
| 101 |
pub(crate) const RUST_CRC32_MPEG_2: crc::Crc<u32> = crc::Crc::<u32>::new(&crc::CRC_32_MPEG_2); |
| 102 |
|
| 103 |
pub(crate) const RUST_CRC32_XFER: crc::Crc<u32> = crc::Crc::<u32>::new(&crc::CRC_32_XFER); |
| 104 |
|
| 105 |
pub(crate) const RUST_CRC64_ECMA_182: crc::Crc<u64> = crc::Crc::<u64>::new(&crc::CRC_64_ECMA_182); |
| 106 |
|
| 107 |
pub(crate) const RUST_CRC64_GO_ISO: crc::Crc<u64> = crc::Crc::<u64>::new(&crc::CRC_64_GO_ISO); |
| 108 |
|
| 109 |
pub(crate) const RUST_CRC64_MS: crc::Crc<u64> = crc::Crc::<u64>::new(&crc::CRC_64_MS); |
| 110 |
|
| 111 |
pub(crate) const RUST_CRC64_NVME: crc::Crc<u64> = crc::Crc::<u64>::new(&CRC_64_NVME); |
| 112 |
|
| 113 |
pub(crate) const RUST_CRC64_REDIS: crc::Crc<u64> = crc::Crc::<u64>::new(&crc::CRC_64_REDIS); |
| 114 |
|
| 115 |
pub(crate) const RUST_CRC64_WE: crc::Crc<u64> = crc::Crc::<u64>::new(&crc::CRC_64_WE); |
| 116 |
|
| 117 |
pub(crate) const RUST_CRC64_XZ: crc::Crc<u64> = crc::Crc::<u64>::new(&crc::CRC_64_XZ); |