2 @unnumbered Packet format
5 @url{https://tools.ietf.org/html/rfc4506, XDR}-encoded structures.
9 * Encrypted packet: Encrypted.
15 Plain packet contains either the whole file, or file request (freq), or
16 transition packet or email message. It is called "plain", because it
17 contains plaintext, but plain packets would never be stored on your hard
22 +-------------------------------+--...---+
23 | MAGIC | TYPE | PATHLEN | PATH | PAYLOAD|
24 +-------------------------------+--...---+
27 @multitable @columnfractions 0.2 0.3 0.5
28 @headitem @tab XDR type @tab Value
29 @item Magic number @tab
30 8-byte, fixed length opaque data @tab
31 @verb{|N N C P P 0x00 0x00 0x01|}
32 @item Payload type @tab
34 0 (file), 1 (freq), 2 (mail), 3 (transition)
35 @item Path length @tab
37 actual length of @emph{path} field's payload
39 255 byte, fixed length opaque data @tab
41 @item UTF-8 encoded destination path for file transfer
42 @item UTF-8 encoded source path for file request
43 @item UTF-8 encoded, space separated, email recipients list
44 @item Node's id the transition packet must be relayed on
48 Path has fixed size because of hiding its actual length -- it is
49 valuable metadata. Payload is appended to the header -- it is not stored
50 as XDR field, because most XDR libraries will store all that data in the
53 Depending on the packet's type, payload could store:
57 @item Destination path for freq
58 @item @url{http://zlib.net/, zlib} compressed email
59 @item Whole encrypted packet we need to relay on
63 @section Encrypted packet
65 Encrypted packets are the only files found in spools, in exchangeable
66 storages and that are synchronized between TCP daemons.
68 Each encrypted packet has the following header:
71 +------------ HEADER --------------------+ +-------- ENCRYPTED --------+
73 +--------------------------------------------+------------+----...-----------+------+
74 | MAGIC | NICE | SENDER | RCPT | EPUB | SIGN | SIZE | MAC | CIPHERTEXT | MAC | JUNK |
75 +-------------------------------------/------\------------+----...-----------+------+
77 +-------------------------------------+
78 | MAGIC | NICE | SENDER | RCPT | EPUB |
79 +-------------------------------------+
82 @multitable @columnfractions 0.2 0.3 0.5
83 @headitem @tab XDR type @tab Value
84 @item Magic number @tab
85 8-byte, fixed length opaque data @tab
86 @verb{|N N C P E 0x00 0x00 0x03|}
89 1-255, packet @ref{Niceness, niceness} level
91 32-byte, fixed length opaque data @tab
94 32-byte, fixed length opaque data @tab
96 @item Exchange public key @tab
97 32-byte, fixed length opaque data @tab
98 Ephemeral curve25519 public key
100 64-byte, fixed length opaque data @tab
101 ed25519 signature for that packet's header
104 Signature is calculated over all previous fields.
106 All following encryption is done using @url{https://cr.yp.to/chacha.html,
107 ChaCha20} algorithm. Data is splitted on 128 KiB blocks. Each block is
108 encrypted with increasing nonce counter. @url{https://blake2.net/,
109 BLAKE2b-256} MAC is appended to the ciphertext.
111 After the headers comes an encrypted payload size and MAC of that size.
113 @multitable @columnfractions 0.2 0.3 0.5
114 @headitem @tab XDR type @tab Value
116 unsigned hyper integer @tab
120 Next comes the actual encrypted payload with corresponding MAC.
122 Each node has static @strong{exchange} and @strong{signature} keypairs.
123 When node A want to send encrypted packet to node B, it:
126 @item generates ephemeral @url{http://cr.yp.to/ecdh.html, curve25519} keypair
127 @item prepares structure for signing
128 @item signs that structure using private
129 @url{http://ed25519.cr.yp.to/, ed25519} signature key
130 @item takes remote node's exchange public key and performs
131 Diffie-Hellman computation on this remote static public key and
132 private ephemeral one
133 @item derive the keys:
135 @item initialize @url{https://blake2.net/, BLAKE2Xb} XOF with
136 derived ephemeral key and 224-byte output length
137 @item feed @verb{|N N C P E 0x00 0x00 0x03|} magic number to XOF
138 @item read 32-bytes of "size" encryption key (for ChaCha20)
139 @item read 64-bytes of "size" authentication key (for BLAKE2b-MAC)
140 @item read 32-bytes of payload encryption key
141 @item read 64-bytes of payload authentication key
142 @item optionally read 32-bytes pad generation key (for ChaCha20)
144 @item encrypts size, appends its ciphertext to the header
145 @item appends MAC tag over that ciphertext
146 @item encrypts and appends payload ciphertext
147 @item appends MAC tag over that payload ciphertext
148 @item possibly appends any kind of "junk" noise data to hide real
149 payload's size from the adversary