]> 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) +
6     AUTH(ENCn(SERIAL) + ENC(KEY, ENCn(SERIAL), DATA))
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
28 @code{AUTH} is Poly1305 authentication function. First 256 bits of
29 Salsa20 output are used as a one-time key for @code{AUTH}. Next 256 bits
30 of Salsa20 are ignored. All remaining output is XORed with the data,
31 encrypting it.
32
33 To prevent replay attacks we remember latest @code{SERIAL} from the
34 remote peer. If received message's @code{SERIAL} is not greater that the
35 saved one, then drop it. Optionally, because some UDP packets can be
36 reordered during transmission, we can allow some window for valid
37 serials with the @code{-noncediff} option. @code{-noncediff 10} with
38 current saved serial state equals to 78 allows messages with 68…78
39 serials. That time window can be used by attacker to replay packets, so
40 by default it equals to 1. However it can improve performance because of
41 rearranged UDP packets.