]> Cypherpunks.ru repositories - govpn.git/blob - doc/handshake.texi
Merge branch 'develop'
[govpn.git] / doc / handshake.texi
1 @node Handshake
2 @section Handshake protocol
3
4 @verbatiminclude handshake.utxt
5
6 Each handshake message ends with so called @code{IDtag}: it is
7 BLAKE2b-MAC of the first 64 bits of the handshake message, with client's
8 @ref{Identity} used as a key. It is used to transmit identity and to
9 mark packet as handshake message.
10
11 If @ref{Noise, noise} is enabled, then data is padded to fill up packet
12 to MTU's size.
13
14 @strong{Preparation stage}:
15
16 @enumerate
17 @item
18 Client knows only his identity and passphrase written somewhere in the
19 human readable form. Server knows his identity and
20 @ref{Verifier structure, verifier}: @code{DSAPub}.
21 @item
22 Client computes verifier which produces @code{DSAPriv} and
23 @code{DSAPub}. @code{H()} is @emph{BLAKE2b-256} hash function.
24 @item
25 Client generates DH keypair: @code{CDHPub} and @code{CDHPriv}.
26 Also it generates random 64-bit @code{R} that is used as a nonce for
27 symmetric encryption. @code{El()} is Elligator point encoding (and vice
28 versa) algorithm.
29 @end enumerate
30
31 @strong{Interaction stage}:
32
33 @enumerate
34 @item
35 @verb{|R + enc(H(DSAPub), R, El(CDHPub)) + IDtag -> Server|} [48 bytes]
36
37 @item
38 @itemize
39 @item Server remembers client address.
40 @item Decrypts @code{El(CDHPub)}.
41 @item Inverts @code{El()} encoding and gets @code{CDHPub}.
42 @item Generates DH keypair: @code{SDHPriv}/@code{SDHPub}.
43 @item Computes common shared key @code{K = H(DH(SDHPriv, CDHPub))}.
44 @item Generates 64-bit random number @code{RS}.
45 @item Generates 256-bit pre-master secret @code{SS}.
46 @end itemize
47
48 @item
49 @verb{|enc(H(DSAPub), R+1, El(SDHPub)) + enc(K, R, RS + SS) + IDtag -> Client|} [80 bytes]
50
51 @item
52 @itemize
53 @item Client decrypts @code{El(SDHPub)}.
54 @item Inverts @code{El()} encoding and gets @code{SDHPub}.
55 @item Computes @code{K}.
56 @item Decrypts @code{RS} and @code{SS}.
57 @item Remembers @code{SS}.
58 @item Generates 64-bit random number @code{RC}.
59 @item Generates 256-bit pre-master secret @code{SC}.
60 @item Signs with @code{DSAPriv} key @code{K}.
61 @end itemize
62
63 @item
64 @verb{|enc(K, R+1, RS + RC + SC + Sign(DSAPriv, K)) + IDtag -> Server|} [120 bytes]
65
66 @item
67 @itemize
68     @item Server decrypts @code{RS}, @code{RC}, @code{SC},
69     @code{Sign(DSAPriv, K)}.
70
71     @item Compares @code{RS} with its own one sent before. Server
72     decrypts @code{RS}, @code{RC}, @code{SC} with key @code{K}, compares
73     @code{RS} with its own one sent before.
74
75     @item Verifies @code{K} signature with verifier @code{DSAPub}.
76
77     @item Computes final session encryption key:
78     @code{MasterKey=SS XOR SC}.
79 @end itemize
80
81 @item
82 @verb{|ENC(K, R+2, RC) + IDtag -> Client|} [16 bytes]
83
84 @item
85 @itemize
86 @item Client decrypts @code{RC}
87 @item Compares with its own one sent before.
88 @item Computes final session encryption key as server did.
89 @end itemize
90
91 @end enumerate
92
93 @code{MasterKey} is high entropy 256-bit key. @code{K} DH-derived one
94 has 128-bit security margin and that is why are not in use except in
95 handshake process. @code{R*} are required for handshake randomization
96 and two-way authentication.
97
98 In @ref{Encless, encryptionless mode} each @code{enc()} is replaced with
99 AONT and chaffing function over the noised data.