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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
//! §2–§5 — the wire: where bytes acquire meaning.
//!
//! This module holds the suite declaration ([`suite`]), §6.1's handshake
//! ladder as a trait ([`handshake`]), the three packet headers (`header`),
//! mac1 (`mac`), msg1's payload codec (`payload`) and §3.1's pre-AEAD
//! classify/drop gate (`classify`). Everything but the suite and the
//! ladder trait is crate-internal: no §16 surface exposes a header.
//!
//! Nothing here drives a handshake, holds a key, opens a session, or reads
//! a clock. No DH is performed, no index is minted, no timestamp guard is
//! consulted, no frame is parsed. If a file in this module needs to know
//! what a *connection* is, something has gone in the wrong place.
//!
//! [`Handshake`] is the one item that names hiss's state machine, and it
//! names it without stepping it: the trait **declares** the ladder's shape
//! so that a suite-generic `core::Endpoint<I>` can call transitions that
//! `hiss::noise!` emits as *inherent* methods on generated types.
//! [`crate::channel!`] stamps the single `impl`, and that expansion lands
//! in the **caller's** module beside its own `IK`, not here. The driving —
//! when each stage is paid, what is parked between them, what a rejection
//! costs — is §6's, and lives in the endpoint core.
//!
//! # The gate is the crate's only silent-drop tier
//!
//! §3.1: a datagram outside its type's accepted length, longer than
//! [`MAX_DATAGRAM`](crate::constants::MAX_DATAGRAM), or bearing an unknown
//! type or version is **silently dropped before any further work**. A
//! packet that fails here may genuinely be corruption, so nothing is
//! signalled. A packet that passes the AEAD and then fails structurally is
//! a peer bug or an attack, and gets a signalled death (§8.2).
//!
//! "Silently" is complete: no error, no `tracing` event, no counter, no
//! observability of any kind. §18.2's five trace targets are
//! operator-visible contract in which renaming or dropping one is a
//! protocol revision — which makes **adding** one a protocol revision too,
//! and the gate is not among them (ruling 67). A drop counter is exactly
//! the sort of thing that gets added helpfully here and questioned by
//! nobody.
pub
pub
pub
use ;
use crateconstants;
// The wire types are crate-internal: no §16 surface exposes a header, a
// mac1 key or a payload codec. Start closed — widening later is not a
// breaking change and narrowing is.
pub use ;
pub use ;
pub use Handshake;
pub use ;
/// A datagram that survived §3.1's gate.
///
/// Borrowed throughout: every slice points into the caller's datagram, so
/// the gate allocates nothing and copies nothing. It is the cheapest thing
/// in the crate and must stay that way.
///
/// **`ad` and `preimage` are the received bytes, verbatim.** §3.4 makes
/// the 14 header bytes the AEAD associated data "verbatim" and §4.1 makes
/// mac1's preimage "all packet bytes preceding the tag"; both are taken as
/// subslices here rather than rebuilt by re-encoding a decoded header. A
/// re-encode would be correct today and is a place to be wrong forever.
///
/// **Unattested name** — §3.1 describes the gate's behaviour and names no
/// result type.
pub
/// §3.1's pre-AEAD gate: classify a received datagram, or drop it.
///
/// `None` **is** the drop. It is not an error, it is not traced, it is not
/// counted, and it never reaches the application — see the module docs.
/// §18.1's error taxonomy is closed and deliberately has no variant for
/// this: a `DropReason` returned to a caller invites a caller to act on
/// it, and the whole point is that nothing acts on it.
///
/// Generic over the suite because `INIT_PACKET_LEN` and `RESP_PACKET_LEN`
/// are per-suite (§2.3) while the headers and caps are not. The gate never
/// asks "which suite is this" — there is no suite byte to ask with. It
/// asks "is this the length my suite says it is", and a wrong-curve-suite
/// packet dies here or at mac1, the same fate as garbage; a same-curve
/// sibling suite's packet passes both and dies at the first AEAD open on
/// the staged ladder (§2.2, amended by ruling 279).
///
/// **Unattested name** — §3.1 names no function.
///
/// # Order
///
/// Size cap, then the type byte, then the version byte, then the type's
/// length rule. The type must be read before the length is tested, because
/// §3.1's accepted length is a property *of the type*.
pub
/// Decode a fixed-size packtool header out of an exactly-sized slice.
///
/// The `Err` is a length error only, and the gate has already excluded it,
/// so this never fails in practice — it is still written as a drop rather
/// than an `unwrap`, for the same reason as the `_` arm above.