]> Cypherpunks.ru repositories - govpn.git/blobdiff - src/govpn/peer.go
Use Argon2d PHC winner instead of PBKDF2
[govpn.git] / src / govpn / peer.go
index 7366ffd642da84cec01a7ec76dc361667286855a..45b5dd7d01ac47022220387e90c3b040215b1e3f 100644 (file)
@@ -1,3 +1,21 @@
+/*
+GoVPN -- simple secure free software virtual private network daemon
+Copyright (C) 2014-2015 Sergey Matveev <stargrave@stargrave.org>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+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 govpn
 
 import (
@@ -118,6 +136,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
@@ -237,6 +260,9 @@ func (p *Peer) EthProcess(data []byte) {
 }
 
 func (p *Peer) PktProcess(data []byte, tap io.Writer, reorderable bool) bool {
+       if len(data) < MinPktLength {
+               return false
+       }
        p.BusyR.Lock()
        for i := 0; i < SSize; i++ {
                p.bufR[i] = byte(0)
@@ -304,6 +330,9 @@ func (p *Peer) PktProcess(data []byte, tap io.Writer, reorderable bool) bool {
                p.BusyR.Unlock()
                return true
        }
+       if int(p.pktSizeR) > len(data)-MinPktLength {
+               return false
+       }
        p.BytesPayloadIn += int64(p.pktSizeR)
        tap.Write(p.bufR[S20BS+PktSizeSize : S20BS+PktSizeSize+p.pktSizeR])
        p.BusyR.Unlock()