vendor: Move back to upstream KCP (fixes #4407)

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4614
This commit is contained in:
Audrius Butkevicius
2017-12-27 11:33:12 +00:00
parent 5a05d9b867
commit 72172d853c
32 changed files with 4262 additions and 45 deletions

25
vendor/github.com/xtaci/kcp-go/rand.go generated vendored Normal file
View File

@@ -0,0 +1,25 @@
package kcp
import (
"crypto/md5"
"crypto/rand"
"io"
)
// nonceMD5 is a nonce generator for each packet header
// which took the advantages of both MD5 and CSPRNG(like /dev/urandom).
// The benchmark shows it's faster than previous CSPRNG only method.
type nonceMD5 struct {
data [md5.Size]byte
}
// Nonce fills a nonce into the provided slice with no more than md5.Size bytes
// the entropy will be updated whenever a leading 0 appears
func (n *nonceMD5) Fill(nonce []byte) {
if n.data[0] == 0 { // 1/256 chance for entropy update
io.ReadFull(rand.Reader, n.data[:])
}
n.data = md5.Sum(n.data[:])
copy(nonce, n.data[:])
return
}