summaryrefslogtreecommitdiffhomepage
path: root/src/cookie.go
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2017-10-08 22:03:32 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2017-10-08 22:03:32 +0200
commita72b0f7ae5dda27d839bb317b7c01d11b215e77a (patch)
treebd70e6fc71574b300e6e928b7887d69c7cf4ddef /src/cookie.go
parent2d856045a0dbfc15d38d738e2a9d159ba2a49a47 (diff)
Added new UDPBind interface
Diffstat (limited to 'src/cookie.go')
-rw-r--r--src/cookie.go12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/cookie.go b/src/cookie.go
index a81819b..a13ad49 100644
--- a/src/cookie.go
+++ b/src/cookie.go
@@ -5,10 +5,8 @@ import (
"crypto/rand"
"golang.org/x/crypto/blake2s"
"golang.org/x/crypto/chacha20poly1305"
- "net"
"sync"
"time"
- "unsafe"
)
type CookieChecker struct {
@@ -76,7 +74,7 @@ func (st *CookieChecker) CheckMAC1(msg []byte) bool {
return hmac.Equal(mac1[:], msg[smac1:smac2])
}
-func (st *CookieChecker) CheckMAC2(msg []byte, src *net.UDPAddr) bool {
+func (st *CookieChecker) CheckMAC2(msg []byte, src []byte) bool {
st.mutex.RLock()
defer st.mutex.RUnlock()
@@ -89,8 +87,7 @@ func (st *CookieChecker) CheckMAC2(msg []byte, src *net.UDPAddr) bool {
var cookie [blake2s.Size128]byte
func() {
mac, _ := blake2s.New128(st.mac2.secret[:])
- mac.Write(src.IP)
- mac.Write((*[unsafe.Sizeof(src.Port)]byte)(unsafe.Pointer(&src.Port))[:])
+ mac.Write(src)
mac.Sum(cookie[:0])
}()
@@ -111,7 +108,7 @@ func (st *CookieChecker) CheckMAC2(msg []byte, src *net.UDPAddr) bool {
func (st *CookieChecker) CreateReply(
msg []byte,
recv uint32,
- src *net.UDPAddr,
+ src []byte,
) (*MessageCookieReply, error) {
st.mutex.RLock()
@@ -136,8 +133,7 @@ func (st *CookieChecker) CreateReply(
var cookie [blake2s.Size128]byte
func() {
mac, _ := blake2s.New128(st.mac2.secret[:])
- mac.Write(src.IP)
- mac.Write((*[unsafe.Sizeof(src.Port)]byte)(unsafe.Pointer(&src.Port))[:])
+ mac.Write(src)
mac.Sum(cookie[:0])
}()