clock_hash/
constants.rs

1//! Constants for ClockHash-256
2//!
3//! Defines the initialization vector, rotation schedule, multiplication primes,
4//! and the S-box substitution table.
5
6/// Initialization Vector (IV) - 8 u64 constants from irrational fractions
7pub const IV: [u64; 8] = [
8    0x243F6A8885A308D3, // IV0: π fraction
9    0x13198A2E03707344, // IV1: e fraction
10    0xA4093822299F31D0, // IV2: √2 fraction
11    0x082EFA98EC4E6C89, // IV3: golden ratio φ fraction
12    0x452821E638D01377, // IV4: φ² fraction
13    0xBE5466CF34E90C6C, // IV5: π² fraction
14    0xC0AC29B7C97C50DD, // IV6: e² fraction
15    0x3F84D5B5B5470917, // IV7: √3 fraction
16];
17
18/// Rotation Schedule - 16 rotation values for ClockMix and ClockPermute
19pub const ROTATION_SCHEDULE: [u32; 16] = [
20    7, 19, 31, 43, 13, 29, 37, 53, 11, 23, 41, 59, 17, 33, 47, 61,
21];
22
23/// Multiplication Prime P0
24pub const P0: u64 = 0x9E3779B185EBCA87;
25
26/// Multiplication Prime P1
27pub const P1: u64 = 0xC2B2AE3D27D4EB4F;
28
29include!(concat!(env!("OUT_DIR"), "/sbox.rs"));
30
31#[cfg(test)]
32mod tests {
33    use super::*;
34
35    #[test]
36    fn test_iv_length() {
37        assert_eq!(IV.len(), 8);
38    }
39
40    #[test]
41    fn test_rotation_schedule_length() {
42        assert_eq!(ROTATION_SCHEDULE.len(), 16);
43    }
44
45    #[test]
46    fn test_sbox_length() {
47        assert_eq!(SBOX.len(), 256);
48    }
49
50    #[test]
51    fn test_sbox_uniqueness() {
52        // Check that S-box values are reasonably distributed
53        // Note: The current generation method may produce some duplicates,
54        // which is acceptable as long as the distribution is good
55        let mut seen = [0u8; 256];
56        for &val in &SBOX {
57            seen[val as usize] = seen[val as usize].saturating_add(1);
58        }
59
60        // Count unique values
61        let unique_count = seen.iter().filter(|&&count| count > 0).count();
62
63        // S-box should have at least 150 unique values (59% uniqueness)
64        // This ensures reasonable distribution even if some duplicates exist
65        // The current generation method produces ~169 unique values
66        assert!(
67            unique_count >= 150,
68            "S-box should have at least 150 unique values, got {}",
69            unique_count
70        );
71    }
72}