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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
//! # SHA-384 Hash
//!
//! This module provides the SHA-384 cryptographic hash function as specified
//! in FIPS 180-4. SHA-384 is a variant of SHA-512 that uses a different
//! initialization vector and truncates the final digest to 48 bytes.
//!
//! ## Design rationale
//!
//! SHA-384 shares the same compression function and message schedule as
//! SHA-512. Instead of duplicating the core algorithm, this module wraps
//! [`crate::sha512::Hash`] and overrides only the initialization vector and
//! output length. This reduces code size, simplifies auditing, and guarantees
//! consistency between the two hash functions.
//!
//! ## How it works
//!
//! The [`Hash`] struct holds an internal [`crate::sha512::Hash`] instance with
//! a custom state. During finalization, the full 64-byte SHA-512 digest is
//! computed and then truncated to the first 48 bytes.
//!
//! The module also invokes the [`impl_hmac!`] and [`impl_hkdf!`] macros to
//! generate HMAC-SHA-384 and HKDF-SHA-384 implementations.
use crate;
use crateload_be;
/// Creates a SHA-384 initialization vector.
///
/// This internal helper constructs a [`State`] from the SHA-384 initial
/// hash values defined in FIPS 180-4. It returns a state that will be used
/// as the starting point for SHA-384 compression.
/// SHA-384 hash context.
///
/// This struct represents an incremental SHA-384 computation. It wraps
/// [`crate::sha512::Hash`] with a SHA-384-specific initialization vector and
/// truncates the final digest to 48 bytes.
///
/// # Why this struct exists
///
/// SHA-384 is defined as a truncated SHA-512 with a different IV. By
/// embedding the SHA-512 core, this struct avoids code duplication and
/// ensures the two algorithms stay synchronized.
///
/// # How it works
///
/// The internal SHA-512 state is initialized with [`new_state`]. Updates
/// are forwarded to the inner hash. Finalization computes the full 64-byte
/// SHA-512 digest and returns only the first 48 bytes.
///
/// # Examples
///
/// Incremental hashing:
///
/// ```
/// # use libvctrl_sha512::sha384::Hash;
/// let mut h = Hash::new();
/// h.update(b"hello ");
/// h.update(b"world");
/// let digest = h.finalize();
/// assert_eq!(digest.len(), 48);
/// ```
///
/// One-shot hashing:
///
/// ```
/// # use libvctrl_sha512::sha384::Hash;
/// let digest = Hash::hash(b"abc");
/// assert_eq!(digest.len(), 48);
/// ```
;
impl_hmac!;
impl_hkdf!;