MCPcopy Create free account
hub / github.com/encodeous/nylon / CheckMAC2

Method CheckMAC2

polyamide/device/cookie.go:86–115  ·  view source on GitHub ↗
(msg, src []byte)

Source from the content-addressed store, hash-verified

84}
85
86func (st *CookieChecker) CheckMAC2(msg, src []byte) bool {
87 st.RLock()
88 defer st.RUnlock()
89
90 if time.Since(st.mac2.secretSet) > CookieRefreshTime {
91 return false
92 }
93
94 // derive cookie key
95
96 var cookie [blake2s.Size128]byte
97 func() {
98 mac, _ := blake2s.New128(st.mac2.secret[:])
99 mac.Write(src)
100 mac.Sum(cookie[:0])
101 }()
102
103 // calculate mac of packet (including mac1)
104
105 smac2 := len(msg) - blake2s.Size128
106
107 var mac2 [blake2s.Size128]byte
108 func() {
109 mac, _ := blake2s.New128(cookie[:])
110 mac.Write(msg[:smac2])
111 mac.Sum(mac2[:0])
112 }()
113
114 return hmac.Equal(mac2[:], msg[smac2:])
115}
116
117func (st *CookieChecker) CreateReply(
118 msg []byte,

Callers 2

RoutineHandshakeMethod · 0.80
TestCookieMAC1Function · 0.80

Calls 1

WriteMethod · 0.65

Tested by 1

TestCookieMAC1Function · 0.64