]> Cypherpunks.ru repositories - govpn.git/blob - doc/transport.texi
812322528f03019d4b882dab6e925ebdd386afa4
[govpn.git] / doc / transport.texi
1 @node Transport
2 @section Transport protocol
3
4 @verbatim
5      NONCE = 64bit(MAC(MAC_KEY, SERIAL))
6    PAYLOAD = DATA || PAD [|| ZEROS]
7 CIPHERTEXT = ENCRYPT(KEY, NONCE, PAYLOAD)
8        TAG = AUTH(AUTH_KEY, CIPHERTEXT || NONCE)
9    MESSAGE = TAG || CIPHERTEXT || NONCE
10 @end verbatim
11
12 @code{SERIAL} is message's serial number. Odds are reserved for
13 client (to server) messages, evens for server (to client) messages.
14
15 @code{MAC} is BLAKE2b-MAC used to obfuscate @code{SERIAL}. MAC's key
16 @code{MAC_KEY} is the first 256-bit of Salsa20's output with established
17 common key and zero nonce (message nonces start from 1).
18
19 @verbatim
20 MAC_KEY = 256bit(ENCRYPT(KEY, 0))
21 @end verbatim
22
23 @code{ENCRYPT} is Salsa20 stream cipher, with established session
24 @code{KEY} and obfuscated @code{SERIAL} used as a nonce. 512 bit of
25 Salsa20's output is ignored and only remaining is XORed with ther data,
26 encrypting it.
27
28 @code{DATA} is padded using ISO/IEC 7816-4 format (@code{PAD} (0x80
29 byte) with optional @code{ZEROS} following), to fill up packet to
30 conceal payload packet length.
31
32 @code{AUTH} is Poly1305 authentication function. First 256 bits of
33 Salsa20's output are used as a one-time key for @code{AUTH}.
34
35 @verbatim
36 AUTH_KEY = 256bit(ENCRYPT(KEY, NONCE))
37 @end verbatim
38
39 To prevent replay attacks we must remember received @code{SERIAL}s and
40 drop when receiving duplicate ones.
41
42 In @ref{Encless, encryptionless mode} this scheme is slightly different:
43
44 @verbatim
45   NONCE = MAC(MAC_KEY, SERIAL)
46 ENCODED = ENCLESS(DATA || PAD || ZEROS)
47  PACKET = ENCODED || NONCE
48 @end verbatim
49
50 @code{ENCLESS} is AONT and chaffing function. There is no need in
51 explicit separate authentication.