]> Cypherpunks.ru repositories - govpn.git/blob - doc/transport.texi
Merge branch 'develop'
[govpn.git] / doc / transport.texi
1 @node Transport
2 @cindex Transport
3 @cindex Transport protocol
4 @cindex Salsa20
5 @cindex PRP
6 @cindex Nonce
7 @cindex Poly1305
8 @cindex XTEA
9 @cindex Serial
10 @section Transport protocol
11
12 @verbatim
13 TAG || ENCRYPTED || NONCE --> PACKET
14  ^         ^          ^
15  |         |          |
16  |         |          +-------------+
17  |         |                        |
18  |         +-------------+          |
19  |                       |          |
20  +--< AUTH(AUTH_KEY, ENCRYPTED || NONCE)
21                          ^          ^
22                          |          |
23 +------------------------+          |
24 |                                   |
25 |                   +---------------+
26 |                   |
27 +--< ENCRYPT(KEY, NONCE, PAYLOAD)
28                     ^       ^
29                     |       |
30                     |       +--< DATA || PAD [|| ZEROS]
31                     |
32                     +--< PRP(PRP_KEY, SERIAL)
33 @end verbatim
34
35 @code{SERIAL} is message's serial number. Odds are reserved for
36 client (to server) messages, evens for server (to client) messages.
37
38 @code{PRP} is XTEA block cipher algorithm used here as PRP (pseudo
39 random permutation function) to obfuscate @code{SERIAL}. Plaintext
40 @code{SERIAL} state is kept in peers internal state, but encrypted
41 before transmission.
42
43 XTEA's encryption key @code{PRP_KEY} is the first 128-bit of Salsa20's
44 output with established common key and zero nonce (message nonces start
45 from 1).
46
47 @verbatim
48 PRP_KEY = 128bit(ENCRYPT(KEY, 0))
49 @end verbatim
50
51 @code{ENCRYPT} is Salsa20 stream cipher, with established session
52 @code{KEY} and obfuscated @code{SERIAL} used as a nonce. 512 bit of
53 Salsa20's output is ignored and only remaining is XORed with ther data,
54 encrypting it.
55
56 @code{DATA} is padded with @code{PAD} (0x80 byte). Optional @code{ZEROS}
57 may follow, to fill up packet to conceal payload packet length.
58
59 @code{AUTH} is Poly1305 authentication function. First 256 bits of
60 Salsa20's output are used as a one-time key for @code{AUTH}.
61
62 @verbatim
63 AUTH_KEY = 256bit(ENCRYPT(KEY, NONCE))
64 @end verbatim
65
66 To prevent replay attacks we must remember received @code{SERIAL}s and
67 drop when receiving duplicate ones.
68
69 In @ref{Encless, encryptionless mode} this scheme is slightly different:
70
71 @verbatim
72  PACKET = ENCODED || NONCE
73 ENCODED = ENCLESS(DATA || PAD || ZEROS)
74   NONCE = PRP(PRP_KEY, SERIAL)
75 @end verbatim
76
77 @code{ENCLESS} is AONT and chaffing function. There is no need in
78 explicit separate authentication.