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 +--< PRP(PRP_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{PRP} is XTEA block cipher algorithm used here as PRP (pseudo
31 random permutation function) to obfuscate @code{SERIAL}. Plaintext
32 @code{SERIAL} state is kept in peers internal state, but encrypted
35 XTEA's encryption key @code{PRP_KEY} is the first 128-bit of Salsa20's
36 output with established common key and zero nonce (message nonces start
40 PRP_KEY = 128bit(ENCRYPT(KEY, 0))
43 @code{ENCRYPT} is Salsa20 stream cipher, with established session
44 @code{KEY} and obfuscated @code{SERIAL} used as a nonce. 512 bit of
45 Salsa20's output is ignored and only remaining is XORed with ther data,
48 @code{DATA} is padded with @code{PAD} (0x80 byte). Optional @code{ZEROS}
49 may follow, to fill up packet to conceal payload packet length.
51 @code{AUTH} is Poly1305 authentication function. First 256 bits of
52 Salsa20's output are used as a one-time key for @code{AUTH}.
55 AUTH_KEY = 256bit(ENCRYPT(KEY, NONCE))
58 To prevent replay attacks we must remember received @code{SERIAL}s and
59 drop when receiving duplicate ones.
61 In @ref{Encless, encryptionless mode} this scheme is slightly different:
64 PACKET = ENCODED || NONCE
65 ENCODED = ENCLESS(DATA || PAD || ZEROS)
66 NONCE = PRP(PRP_KEY, SERIAL)
69 @code{ENCLESS} is AONT and chaffing function. There is no need in
70 explicit separate authentication.