]> Cypherpunks.ru repositories - govpn.git/commitdiff
Move nonce expectation calculation to common function
authorSergey Matveev <stargrave@stargrave.org>
Fri, 18 Sep 2015 12:01:22 +0000 (15:01 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 18 Sep 2015 12:01:22 +0000 (15:01 +0300)
Signed-off-by: Sergey Matveev <stargrave@stargrave.org>
src/govpn/cmd/govpn-client/tcp.go
src/govpn/cmd/govpn-server/tcp.go
src/govpn/peer.go

index 6265eeb6087e8f8b80dedf4f2450ede422ea5726..1dd11ec39eb4c62789062e5cfb39eec8a5ca8653 100644 (file)
@@ -20,7 +20,6 @@ package main
 
 import (
        "bytes"
-       "encoding/binary"
        "log"
        "net"
        "sync/atomic"
@@ -116,8 +115,7 @@ HandshakeCycle:
        }
 
        nonceExpectation := make([]byte, govpn.NonceSize)
-       binary.BigEndian.PutUint64(nonceExpectation, peer.NonceExpect)
-       peer.NonceCipher.Encrypt(nonceExpectation, nonceExpectation)
+       peer.NonceExpectation(nonceExpectation)
        prev = 0
        var i int
 TransportCycle:
@@ -158,8 +156,7 @@ TransportCycle:
                        rehandshaking <- struct{}{}
                        break TransportCycle
                }
-               binary.BigEndian.PutUint64(nonceExpectation, peer.NonceExpect)
-               peer.NonceCipher.Encrypt(nonceExpectation, nonceExpectation)
+               peer.NonceExpectation(nonceExpectation)
                copy(buf, buf[i+govpn.NonceSize:prev])
                prev = prev - i - govpn.NonceSize
                goto CheckMore
index 59ee55965e96e03b0ee617511de233a8da647e4f..437b5005aa8ca11b085419e484bf218108941c3a 100644 (file)
@@ -20,7 +20,6 @@ package main
 
 import (
        "bytes"
-       "encoding/binary"
        "log"
        "net"
        "time"
@@ -152,8 +151,7 @@ func handleTCP(conn net.Conn) {
        }
 
        nonceExpectation := make([]byte, govpn.NonceSize)
-       binary.BigEndian.PutUint64(nonceExpectation, peer.NonceExpect)
-       peer.NonceCipher.Encrypt(nonceExpectation, nonceExpectation)
+       peer.NonceExpectation(nonceExpectation)
        prev = 0
        var i int
        for {
@@ -182,8 +180,7 @@ func handleTCP(conn net.Conn) {
                        )
                        break
                }
-               binary.BigEndian.PutUint64(nonceExpectation, peer.NonceExpect)
-               peer.NonceCipher.Encrypt(nonceExpectation, nonceExpectation)
+               peer.NonceExpectation(nonceExpectation)
                copy(buf, buf[i+govpn.NonceSize:prev])
                prev = prev - i - govpn.NonceSize
                goto CheckMore
index 7366ffd642da84cec01a7ec76dc361667286855a..1076e74bea38300f1e0531e3e9ebf52f94e58340 100644 (file)
@@ -118,6 +118,11 @@ func (p *Peer) Zero() {
        p.BusyR.Unlock()
 }
 
+func (p *Peer) NonceExpectation(buf []byte) {
+       binary.BigEndian.PutUint64(buf, p.NonceExpect)
+       p.NonceCipher.Encrypt(buf, buf)
+}
+
 func newPeer(isClient bool, addr string, conn io.Writer, conf *PeerConf, key *[SSize]byte) *Peer {
        now := time.Now()
        timeout := conf.Timeout