]> Cypherpunks.ru repositories - govpn.git/blob - doc/transport.texi
Merge branch 'develop'
[govpn.git] / doc / transport.texi
1 @node Transport protocol
2 @section Transport protocol
3
4 @verbatim
5 ENCn(SERIAL) + ENC(KEY, ENCn(SERIAL), DATA_SIZE+DATA+NOISE) +
6     AUTH(ENCn(SERIAL) + ENC(KEY, ENCn(SERIAL), DATA_SIZE+DATA+NOISE))
7 @end verbatim
8
9 All transport and handshake messages are indistinguishable from
10 pseudo random noise.
11
12 @code{SERIAL} is message's serial number. Odds are reserved for
13 client(→server) messages, evens for server(→client) messages.
14
15 @code{ENCn} is XTEA block cipher algorithm used here as PRP (pseudo
16 random permutation) to randomize, obfuscate @code{SERIAL}. Plaintext
17 @code{SERIAL} state is kept in peers internal state, but encrypted
18 before transmission. XTEA is compact and fast enough. Salsa20 is PRF
19 function and requires much more code to create PRP from it. XTEA's
20 encryption key is the first 128-bit of Salsa20's output with established
21 common key and zero nonce (message nonces start from 1).
22
23 Encrypted @code{SERIAL} is used as a nonce for @code{DATA} encryption:
24 encryption key is different during each handshake, so (key, nonce) pair
25 is always used only once. @code{ENC} is Salsa20 cipher, with established
26 session @code{KEY} and encrypted @code{SERIAL} used as a nonce.
27 @code{DATA_SIZE} is @emph{uint16} storing length of the @code{DATA}.
28
29 @code{NOISE} is optional. It is just some junk data, intended to fill up
30 packet to MTU size. This is useful for concealing payload packets length.
31
32 @code{AUTH} is Poly1305 authentication function. First 256 bits of
33 Salsa20 output are used as a one-time key for @code{AUTH}. Next 256 bits
34 of Salsa20 are ignored. All remaining output is XORed with the data,
35 encrypting it.
36
37 To prevent replay attacks we remember latest @code{SERIAL} from the
38 remote peer. If received message's @code{SERIAL} is not greater that the
39 saved one, then drop it. Optionally, because some UDP packets can be
40 reordered during transmission, we can allow some window for valid
41 serials with the @code{-noncediff} option. @code{-noncediff 10} with
42 current saved serial state equals to 78 allows messages with 68…78
43 serials. That time window can be used by attacker to replay packets, so
44 by default it equals to 1. However it can improve performance because of
45 rearranged UDP packets.