Skip to main content

halftime/
variant.rs

1//! HalftimeHash variant parameters (Section 4).
2
3use universal_hash::array::ArraySize;
4
5/// Parameters shared by each [`HalftimeHash`](crate::hash) variant.
6#[allow(dead_code)]
7pub(crate) trait HalftimeVariant: Copy + 'static {
8    /// Number of `u64` words in the internal hash output.
9    const OUT: usize;
10    /// EHC dimension parameter.
11    const DIM: usize;
12    /// Encoder parameter.
13    const ENC: usize;
14    /// Tag width in bytes.
15    const TAG_BYTES: usize;
16    /// Universal-hash block size for this tag.
17    type TagSize: ArraySize;
18}
19
20/// `HalftimeHash16`: 16-byte tag, distance-2 code.
21pub(crate) mod hh16 {
22    pub(crate) const TAG_BYTES: usize = 16;
23}
24
25/// `HalftimeHash24`: 24-byte tag, distance-3 code.
26pub(crate) mod hh24 {
27    pub(crate) const TAG_BYTES: usize = 24;
28}
29
30/// `HalftimeHash32`: 32-byte tag, distance-4 code.
31pub(crate) mod hh32 {
32    pub(crate) const TAG_BYTES: usize = 32;
33}
34
35/// `HalftimeHash40`: 40-byte tag, distance-5 code.
36pub(crate) mod hh40 {
37    pub(crate) const TAG_BYTES: usize = 40;
38}
39
40/// Marker type for `HalftimeHash16`.
41#[derive(Copy, Clone, Debug)]
42pub enum Hh16 {}
43
44impl HalftimeVariant for Hh16 {
45    const OUT: usize = 2;
46    const DIM: usize = 6;
47    const ENC: usize = 7;
48    const TAG_BYTES: usize = 16;
49    type TagSize = universal_hash::consts::U16;
50}
51
52/// Marker type for `HalftimeHash24`.
53#[derive(Copy, Clone, Debug)]
54pub enum Hh24 {}
55
56impl HalftimeVariant for Hh24 {
57    const OUT: usize = 3;
58    const DIM: usize = 7;
59    const ENC: usize = 9;
60    const TAG_BYTES: usize = 24;
61    type TagSize = universal_hash::consts::U24;
62}
63
64/// Marker type for `HalftimeHash32`.
65#[derive(Copy, Clone, Debug)]
66pub enum Hh32 {}
67
68impl HalftimeVariant for Hh32 {
69    const OUT: usize = 4;
70    const DIM: usize = 7;
71    const ENC: usize = 10;
72    const TAG_BYTES: usize = 32;
73    type TagSize = universal_hash::consts::U32;
74}
75
76/// Marker type for `HalftimeHash40`.
77#[derive(Copy, Clone, Debug)]
78pub enum Hh40 {}
79
80impl HalftimeVariant for Hh40 {
81    const OUT: usize = 5;
82    const DIM: usize = 5;
83    const ENC: usize = 9;
84    const TAG_BYTES: usize = 40;
85    type TagSize = universal_hash::consts::U40;
86}