]> Cypherpunks.ru repositories - govpn.git/blobdiff - src/cypherpunks.ru/govpn/identity.go
Do not allocate memory in each iteration
[govpn.git] / src / cypherpunks.ru / govpn / identity.go
index d738c5563e091179bd1e1fa287fb1bbcbd6ef1d9..89b12ab5cb118687415ef05c0cbbed79cbd10a9c 100644 (file)
@@ -106,6 +106,7 @@ func (mc *MACCache) Find(data []byte) *PeerId {
                return nil
        }
        buf := make([]byte, 8)
+       sum := make([]byte, 32)
        mc.l.RLock()
        for pid, mt := range mc.cache {
                copy(buf, data)
@@ -113,7 +114,7 @@ func (mc *MACCache) Find(data []byte) *PeerId {
                mt.l.Lock()
                mt.mac.Reset()
                mt.mac.Write(buf)
-               sum := mt.mac.Sum(nil)
+               mt.mac.Sum(sum[:0])
                mt.l.Unlock()
                if subtle.ConstantTimeCompare(sum[len(sum)-8:], data[len(data)-8:]) == 1 {
                        ppid := PeerId(pid)