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
//! WireGuard Next-Generation Secure Network Tunnel (`Noise_IKpsk2`) Layer 3 wire builder.
//!
//! Serializes a [`WireguardSpec`] into a WireGuard protocol packet carried over UDP destination
//! port `51820`. All integer fields in WireGuard headers are encoded in little-endian byte order:
//! - `INITIATION` (`Type = 1`, 148 bytes): 3-byte zeroed Reserved, 32-bit LE `sender_index` (`SENDER`),
//! 32-byte unencrypted ephemeral Curve25519 public key, 48-byte encrypted static key, 28-byte
//! encrypted TAI64N timestamp, 16-byte `mac1`, and 16-byte `mac2`.
//! - `RESPONSE` (`Type = 2`, 92 bytes): 32-bit LE `sender_index`, 32-bit LE `receiver_index` (`RECEIVER`),
//! 32-byte ephemeral key, 16-byte encrypted empty payload, and two 16-byte MAC tags.
//! - `COOKIE` (`Type = 3`, 64 bytes): 32-bit LE `receiver_index`, 24-byte nonce, and 32-byte cookie.
//! - `DATA` (`Type = 4`, `16 + payload` bytes): 32-bit LE `receiver_index` and 64-bit LE `counter` (`COUNTER`).
//!
//! Canonical `.fasm` syntax:
//! `a -> b WIREGUARD [TYPE <INITIATION|RESPONSE|COOKIE|DATA> | INITIATION | COOKIE | DATA] [SENDER <u32>] [RECEIVER <u32>] [COUNTER <u64>] [PAYLOAD "<str>" | HEXPAYLOAD "<hex>"]`
use crate*;
use Vec;
/// Builds a WireGuard packet payload and returns `(bytes, 51820)` for UDP encapsulation.