2 @section Transport protocol
5 TAG || ENCRYPTED || NONCE --> PACKET
12 +--< AUTH(AUTH_KEY, ENCRYPTED || NONCE)
15 +------------------------+ |
19 +--< ENCRYPT(KEY, NONCE, PAYLOAD)
22 | +--< DATA || PAD [|| ZEROS]
24 +--< MAC(MAC_KEY, SERIAL)
27 @code{SERIAL} is message's serial number. Odds are reserved for
28 client (to server) messages, evens for server (to client) messages.
30 @code{MAC} is BLAKE2b-MAC used to obfuscate @code{SERIAL}. MAC's key
31 @code{MAC_KEY} is the first 256-bit of Salsa20's output with established
32 common key and zero nonce (message nonces start from 1).
35 MAC_KEY = 256bit(ENCRYPT(KEY, 0))
38 @code{ENCRYPT} is Salsa20 stream cipher, with established session
39 @code{KEY} and obfuscated @code{SERIAL} used as a nonce. 512 bit of
40 Salsa20's output is ignored and only remaining is XORed with ther data,
43 @code{DATA} is padded with @code{PAD} (0x80 byte). Optional @code{ZEROS}
44 may follow, to fill up packet to conceal payload packet length.
46 @code{AUTH} is Poly1305 authentication function. First 256 bits of
47 Salsa20's output are used as a one-time key for @code{AUTH}.
50 AUTH_KEY = 256bit(ENCRYPT(KEY, NONCE))
53 To prevent replay attacks we must remember received @code{SERIAL}s and
54 drop when receiving duplicate ones.
56 In @ref{Encless, encryptionless mode} this scheme is slightly different:
59 PACKET = ENCODED || NONCE
60 ENCODED = ENCLESS(DATA || PAD || ZEROS)
61 NONCE = MAC(MAC_KEY, SERIAL)
64 @code{ENCLESS} is AONT and chaffing function. There is no need in
65 explicit separate authentication.