mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 13:05:46 +00:00
control/noise: don't cache mixer, just rebuild a BLAKE2s each time.
This should optimize out fine, and readability is preferable to performance here. Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
parent
7e9e72887c
commit
edb33d65c3
@ -284,8 +284,6 @@ type symmetricState struct {
|
|||||||
|
|
||||||
h [blake2s.Size]byte
|
h [blake2s.Size]byte
|
||||||
ck [blake2s.Size]byte
|
ck [blake2s.Size]byte
|
||||||
|
|
||||||
mixer hash.Hash // for updating h
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *symmetricState) checkFinished() {
|
func (s *symmetricState) checkFinished() {
|
||||||
@ -295,25 +293,21 @@ func (s *symmetricState) checkFinished() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize sets s to the initial handshake state, prior to
|
// Initialize sets s to the initial handshake state, prior to
|
||||||
// processing any Noise messages.
|
// processing any handshake messages.
|
||||||
func (s *symmetricState) Initialize() {
|
func (s *symmetricState) Initialize() {
|
||||||
s.checkFinished()
|
s.checkFinished()
|
||||||
if s.mixer != nil {
|
|
||||||
panic("symmetricState cannot be reused")
|
|
||||||
}
|
|
||||||
s.h = blake2s.Sum256([]byte(protocolName))
|
s.h = blake2s.Sum256([]byte(protocolName))
|
||||||
s.ck = s.h
|
s.ck = s.h
|
||||||
s.mixer = newBLAKE2s()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MixHash updates s.h to be BLAKE2s(s.h || data), where || is
|
// MixHash updates s.h to be BLAKE2s(s.h || data), where || is
|
||||||
// concatenation.
|
// concatenation.
|
||||||
func (s *symmetricState) MixHash(data []byte) {
|
func (s *symmetricState) MixHash(data []byte) {
|
||||||
s.checkFinished()
|
s.checkFinished()
|
||||||
s.mixer.Reset()
|
h := newBLAKE2s()
|
||||||
s.mixer.Write(s.h[:])
|
h.Write(s.h[:])
|
||||||
s.mixer.Write(data)
|
h.Write(data)
|
||||||
s.mixer.Sum(s.h[:0])
|
h.Sum(s.h[:0])
|
||||||
}
|
}
|
||||||
|
|
||||||
// MixDH updates s.ck with the result of X25519(priv, pub) and returns
|
// MixDH updates s.ck with the result of X25519(priv, pub) and returns
|
||||||
|
Loading…
Reference in New Issue
Block a user