]> Cypherpunks.ru repositories - govpn.git/blob - doc/transport.texi
[DOC] Refactoring and some info on russian
[govpn.git] / doc / transport.texi
1 @node Transport
2 @section Transport protocol
3
4 @verbatim
5 [PktLen] + 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, except when using TCP connections.
11
12 @code{PktLen} is used only with TCP connections. It is big-endian
13 @emph{uint16} length of the whole packet (except @code{PktLen} itself).
14
15 @code{SERIAL} is message's serial number. Odds are reserved for
16 client(->server) messages, evens for server(->client) messages.
17
18 @code{ENCn} is XTEA block cipher algorithm used here as PRP (pseudo
19 random permutation function) to obfuscate @code{SERIAL}. Plaintext
20 @code{SERIAL} state is kept in peers internal state, but encrypted
21 before transmission. XTEA is compact and fast enough. Salsa20 is PRF
22 function and requires much more code to create PRP from it.
23
24 XTEA's encryption key is the first 128-bit of Salsa20's output with
25 established common key and zero nonce (message nonces start from 1).
26
27 @code{ENC} is Salsa20 stream cipher, with established session @code{KEY}
28 and obfuscated @code{SERIAL} used as a nonce. First 256 bits of
29 Salsa20's output is used as Poly1305 authentication key, next 256 bits
30 are ignored. All remaining output is XORed with the data, encrypting it.
31
32 @code{DATA_SIZE} is big-endian @emph{uint16} storing length of the
33 @code{DATA}.
34
35 @code{NOISE} is optional. It is just some junk data, intended to fill up
36 packet to MTU size. This is useful for concealing payload packets length.
37
38 @code{AUTH} is Poly1305 authentication function. First 256 bits of
39 Salsa20 output are used as a one-time key for @code{AUTH}.
40
41 To prevent replay attacks we must remember received @code{SERIAL}s and
42 if meet one, then drop it. Basically we could just store latest number
43 and check if received one is greater, but because of UDP packets
44 reordering this can lead to valid packets dropping and overall
45 performance degradation. We store up to 256 seen nonces in hash
46 structure, in two swapping buckets.