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