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

Method AddMacs

polyamide/device/cookie.go:215–248  ·  view source on GitHub ↗
(msg []byte)

Source from the content-addressed store, hash-verified

213}
214
215func (st *CookieGenerator) AddMacs(msg []byte) {
216 size := len(msg)
217
218 smac2 := size - blake2s.Size128
219 smac1 := smac2 - blake2s.Size128
220
221 mac1 := msg[smac1:smac2]
222 mac2 := msg[smac2:]
223
224 st.Lock()
225 defer st.Unlock()
226
227 // set mac1
228
229 func() {
230 mac, _ := blake2s.New128(st.mac1.key[:])
231 mac.Write(msg[:smac1])
232 mac.Sum(mac1[:0])
233 }()
234 copy(st.mac2.lastMAC1[:], mac1)
235 st.mac2.hasLastMAC1 = true
236
237 // set mac2
238
239 if time.Since(st.mac2.cookieSet) > CookieRefreshTime {
240 return
241 }
242
243 func() {
244 mac, _ := blake2s.New128(st.mac2.cookie[:])
245 mac.Write(msg[:smac2])
246 mac.Sum(mac2[:0])
247 }()
248}

Callers 3

TestCookieMAC1Function · 0.80
SendHandshakeResponseMethod · 0.80

Calls 1

WriteMethod · 0.65

Tested by 1

TestCookieMAC1Function · 0.64