OXYGENHUB
◆ v0.4.3 oxygen / vendor / crc-fast / src / crc64 / mod.rs
2.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
//! This module provides CRC-64 support.
4
5
pub mod algorithm;
6
pub mod consts;
7
pub mod utils;
8
9
#[cfg(test)]
10
mod property_tests {
11
    use crate::test::miri_compatible_proptest_config;
12
    use crate::{checksum, CrcAlgorithm};
13
    use proptest::prelude::*;
14
15
    proptest! {
16
        #![proptest_config(miri_compatible_proptest_config())]
17
18
        /// Feature: crc16-hardware-acceleration, Property 4: CRC-32 and CRC-64 backwards compatibility
19
        /// *For any* existing CRC-32 or CRC-64 configuration and any input byte sequence, the
20
        /// computed checksum SHALL match the result from the `crc` crate reference implementation,
21
        /// ensuring no regression from CRC-16 changes.
22
        /// **Validates: Requirements 3.1, 3.2, 3.4**
23
        #[test]
24
        fn prop_crc64_compatibility(data in proptest::collection::vec(any::<u8>(), 0..1024)) {
25
            use crate::test::consts::{RUST_CRC64_NVME, RUST_CRC64_XZ, RUST_CRC64_ECMA_182, RUST_CRC64_GO_ISO};
26
27
            // Test CRC-64/NVME (reflected)
28
            let our_nvme = checksum(CrcAlgorithm::Crc64Nvme, &data);
29
            let ref_nvme = RUST_CRC64_NVME.checksum(&data);
30
            prop_assert_eq!(
31
                our_nvme, ref_nvme,
32
                "CRC-64/NVME mismatch for {} bytes: our=0x{:016X}, ref=0x{:016X}",
33
                data.len(), our_nvme, ref_nvme
34
            );
35
36
            // Test CRC-64/XZ (reflected)
37
            let our_xz = checksum(CrcAlgorithm::Crc64Xz, &data);
38
            let ref_xz = RUST_CRC64_XZ.checksum(&data);
39
            prop_assert_eq!(
40
                our_xz, ref_xz,
41
                "CRC-64/XZ mismatch for {} bytes: our=0x{:016X}, ref=0x{:016X}",
42
                data.len(), our_xz, ref_xz
43
            );
44
45
            // Test CRC-64/ECMA-182 (forward/non-reflected)
46
            let our_ecma = checksum(CrcAlgorithm::Crc64Ecma182, &data);
47
            let ref_ecma = RUST_CRC64_ECMA_182.checksum(&data);
48
            prop_assert_eq!(
49
                our_ecma, ref_ecma,
50
                "CRC-64/ECMA-182 mismatch for {} bytes: our=0x{:016X}, ref=0x{:016X}",
51
                data.len(), our_ecma, ref_ecma
52
            );
53
54
            // Test CRC-64/GO-ISO (reflected)
55
            let our_go_iso = checksum(CrcAlgorithm::Crc64GoIso, &data);
56
            let ref_go_iso = RUST_CRC64_GO_ISO.checksum(&data);
57
            prop_assert_eq!(
58
                our_go_iso, ref_go_iso,
59
                "CRC-64/GO-ISO mismatch for {} bytes: our=0x{:016X}, ref=0x{:016X}",
60
                data.len(), our_go_iso, ref_go_iso
61
            );
62
        }
63
    }
64
}