]> Cypherpunks.ru repositories - govpn.git/blobdiff - handshake.go
Well, performance is not so high actually
[govpn.git] / handshake.go
index 2d27e55f3117c7befb462a68edaa8d9d44743b79..6f948b5b440178e3cda5108723a273e5ad7713b0 100644 (file)
@@ -1,5 +1,5 @@
 /*
-govpn -- high-performance secure virtual private network daemon
+govpn -- Simple secure virtual private network daemon
 Copyright (C) 2014 Sergey Matveev <stargrave@stargrave.org>
 
 This program is free software: you can redistribute it and/or modify
@@ -15,6 +15,7 @@ GNU General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
+
 package main
 
 import (
@@ -25,10 +26,10 @@ import (
        "net"
        "time"
 
-       "code.google.com/p/go.crypto/curve25519"
-       "code.google.com/p/go.crypto/poly1305"
-       "code.google.com/p/go.crypto/salsa20"
-       "code.google.com/p/go.crypto/salsa20/salsa"
+       "golang.org/x/crypto/curve25519"
+       "golang.org/x/crypto/poly1305"
+       "golang.org/x/crypto/salsa20"
+       "golang.org/x/crypto/salsa20/salsa"
 )
 
 type Handshake struct {
@@ -111,7 +112,7 @@ func HandshakeStart(conn *net.UDPConn, addr *net.UDPAddr, key *[32]byte) *Handsh
        return &state
 }
 
-func (h *Handshake) Server(conn *net.UDPConn, key *[32]byte, data []byte) *Peer {
+func (h *Handshake) Server(noncediff uint64, conn *net.UDPConn, key *[32]byte, data []byte) *Peer {
        switch len(data) {
        case 56: // R + ENC(PSK, dh_client_pub) + NULLs
                fmt.Print("[HS1]")
@@ -179,7 +180,11 @@ func (h *Handshake) Server(conn *net.UDPConn, key *[32]byte, data []byte) *Peer
                }
 
                // Switch peer
-               peer := Peer{addr: h.addr, nonceOur: 0, nonceRecv: 0}
+               peer := Peer{
+                       addr: h.addr,
+                       nonceOur: noncediff + 0,
+                       nonceRecv: noncediff + 0,
+               }
                peer.key = KeyFromSecrets(h.sServer[:], decRs[8+8:])
                fmt.Print("[OK]")
                return &peer
@@ -189,7 +194,7 @@ func (h *Handshake) Server(conn *net.UDPConn, key *[32]byte, data []byte) *Peer
        return nil
 }
 
-func (h *Handshake) Client(conn *net.UDPConn, key *[32]byte, data []byte) *Peer {
+func (h *Handshake) Client(noncediff uint64, conn *net.UDPConn, key *[32]byte, data []byte) *Peer {
        switch len(data) {
        case 88: // ENC(PSK, dh_server_pub) + ENC(K, RS + SS) + NULLs
                fmt.Print("[HS2]")
@@ -246,7 +251,11 @@ func (h *Handshake) Client(conn *net.UDPConn, key *[32]byte, data []byte) *Peer
                }
 
                // Switch peer
-               peer := Peer{addr: h.addr, nonceOur: 1, nonceRecv: 0}
+               peer := Peer{
+                       addr: h.addr,
+                       nonceOur: noncediff + 1,
+                       nonceRecv: noncediff + 0,
+               }
                peer.key = KeyFromSecrets(h.sServer[:], h.sClient[:])
                fmt.Print("[OK]")
                return &peer