1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
use ;
use ;
/// Hash data using the provided hasher type.
///
/// This is a generic function that works with any type implementing the
/// `Digest` trait from the `sha2` or `sha3` crates.
///
/// # Type Parameters
///
/// * `D` - A hasher type implementing `Digest` (e.g., `Sha256`, `Sha3_512`)
///
/// # Arguments
///
/// * `data` - The data to hash
///
/// # Returns
///
/// The hash output as a byte vector
///
/// # Example
///
/// ```rust
/// use rust_bottle::hash::hash;
/// use sha2::Sha256;
///
/// let data = b"Hello, world!";
/// let hash = hash::<Sha256>(data);
/// ```
/// Multi-level hash (hash of hash).
///
/// This function applies hashing multiple times, hashing the result of the
/// previous hash. This can be useful for certain cryptographic constructions.
///
/// # Type Parameters
///
/// * `D` - A hasher type implementing `Digest`
///
/// # Arguments
///
/// * `data` - The data to hash
/// * `levels` - The number of times to hash (0 means no hashing, 1 means hash once, etc.)
///
/// # Returns
///
/// The final hash output after applying hashing `levels` times
///
/// # Example
///
/// ```rust
/// use rust_bottle::hash::multi_hash;
/// use sha2::Sha256;
///
/// let data = b"Hello, world!";
/// let hash = multi_hash::<Sha256>(data, 3); // Hash 3 times
/// ```
/// Hash data using SHA-256.
///
/// SHA-256 is a widely-used cryptographic hash function producing 256-bit
/// (32-byte) outputs. It's used throughout rust-bottle for key fingerprinting.
///
/// # Arguments
///
/// * `data` - The data to hash
///
/// # Returns
///
/// SHA-256 hash as a 32-byte vector
///
/// # Example
///
/// ```rust
/// use rust_bottle::hash::sha256;
///
/// let data = b"Hello, world!";
/// let hash = sha256(data);
/// assert_eq!(hash.len(), 32);
/// ```
/// Hash data using SHA-384.
///
/// SHA-384 is a cryptographic hash function producing 384-bit (48-byte) outputs.
///
/// # Arguments
///
/// * `data` - The data to hash
///
/// # Returns
///
/// SHA-384 hash as a 48-byte vector
/// Hash data using SHA-512.
///
/// SHA-512 is a cryptographic hash function producing 512-bit (64-byte) outputs.
///
/// # Arguments
///
/// * `data` - The data to hash
///
/// # Returns
///
/// SHA-512 hash as a 64-byte vector
/// Hash data using SHA3-256.
///
/// SHA3-256 is a SHA-3 variant producing 256-bit (32-byte) outputs.
///
/// # Arguments
///
/// * `data` - The data to hash
///
/// # Returns
///
/// SHA3-256 hash as a 32-byte vector
/// Hash data using SHA3-384.
///
/// SHA3-384 is a SHA-3 variant producing 384-bit (48-byte) outputs.
///
/// # Arguments
///
/// * `data` - The data to hash
///
/// # Returns
///
/// SHA3-384 hash as a 48-byte vector
/// Hash data using SHA3-512.
///
/// SHA3-512 is a SHA-3 variant producing 512-bit (64-byte) outputs.
///
/// # Arguments
///
/// * `data` - The data to hash
///
/// # Returns
///
/// SHA3-512 hash as a 64-byte vector