diff --git a/format.go b/format.go index 8f2a2e2..5062a41 100644 --- a/format.go +++ b/format.go @@ -1,7 +1,7 @@ package shadowsocks //go:generate go install -v mvdan.cc/gofumpt@latest -//go:generate go install -v github.com/daixiang0/gci@latest +//go:generate go install -v github.com/daixiang0/gci@v0.4.0 //go:generate gofumpt -l -w . //go:generate gofmt -s -w . -//go:generate gci write . +//go:generate gci write -s "standard,prefix(github.com/sagernet/),default" . diff --git a/shadowaead/aead.go b/shadowaead/aead.go index 3ecaab4..e29789f 100644 --- a/shadowaead/aead.go +++ b/shadowaead/aead.go @@ -379,18 +379,18 @@ type BufferedWriter struct { } func (w *BufferedWriter) Write(p []byte) (n int, err error) { - var index int for { - cachedN := copy(w.data[w.reversed+w.index:], p[index:]) - if cachedN == len(p[index:]) { - w.index += cachedN - return cachedN, nil + cachedN := copy(w.data[w.reversed+w.index:], p[n:]) + w.index += cachedN + if cachedN == len(p[n:]) { + n += cachedN + return } err = w.Flush() if err != nil { return } - index += cachedN + n += cachedN } } @@ -412,6 +412,7 @@ func (w *BufferedWriter) Flush() error { increaseNonce(w.upstream.nonce) _, err := w.upstream.upstream.Write(w.upstream.buffer[:w.reversed+offset+len(packet)]) w.reversed = 0 + w.index = 0 return err } diff --git a/shadowaead/protocol.go b/shadowaead/protocol.go index ae487ef..3ebb309 100644 --- a/shadowaead/protocol.go +++ b/shadowaead/protocol.go @@ -14,6 +14,7 @@ import ( M "github.com/sagernet/sing/common/metadata" N "github.com/sagernet/sing/common/network" "github.com/sagernet/sing/common/rw" + "golang.org/x/crypto/chacha20poly1305" "golang.org/x/crypto/hkdf" ) diff --git a/shadowaead/service.go b/shadowaead/service.go index a905f53..af58c84 100644 --- a/shadowaead/service.go +++ b/shadowaead/service.go @@ -19,6 +19,7 @@ import ( N "github.com/sagernet/sing/common/network" "github.com/sagernet/sing/common/rw" "github.com/sagernet/sing/common/udpnat" + "golang.org/x/crypto/chacha20poly1305" ) diff --git a/shadowaead_2022/protocol.go b/shadowaead_2022/protocol.go index c7011e2..4cafb9b 100644 --- a/shadowaead_2022/protocol.go +++ b/shadowaead_2022/protocol.go @@ -8,7 +8,6 @@ import ( "crypto/sha256" "encoding/base64" "encoding/binary" - "github.com/sagernet/sing/common/random" "io" "math" mRand "math/rand" @@ -26,7 +25,9 @@ import ( E "github.com/sagernet/sing/common/exceptions" M "github.com/sagernet/sing/common/metadata" N "github.com/sagernet/sing/common/network" + "github.com/sagernet/sing/common/random" "github.com/sagernet/sing/common/rw" + "golang.org/x/crypto/chacha20poly1305" "lukechampine.com/blake3" ) diff --git a/shadowaead_2022/relay.go b/shadowaead_2022/relay.go index 71bb26b..cfdf3fd 100644 --- a/shadowaead_2022/relay.go +++ b/shadowaead_2022/relay.go @@ -18,6 +18,7 @@ import ( M "github.com/sagernet/sing/common/metadata" N "github.com/sagernet/sing/common/network" "github.com/sagernet/sing/common/udpnat" + "lukechampine.com/blake3" ) diff --git a/shadowaead_2022/service.go b/shadowaead_2022/service.go index b23316e..582c0e7 100644 --- a/shadowaead_2022/service.go +++ b/shadowaead_2022/service.go @@ -27,6 +27,7 @@ import ( N "github.com/sagernet/sing/common/network" "github.com/sagernet/sing/common/replay" "github.com/sagernet/sing/common/udpnat" + "golang.org/x/crypto/chacha20poly1305" ) diff --git a/shadowaead_2022/service_multi.go b/shadowaead_2022/service_multi.go index 241313d..980e400 100644 --- a/shadowaead_2022/service_multi.go +++ b/shadowaead_2022/service_multi.go @@ -20,6 +20,7 @@ import ( M "github.com/sagernet/sing/common/metadata" N "github.com/sagernet/sing/common/network" "github.com/sagernet/sing/common/rw" + "lukechampine.com/blake3" ) diff --git a/shadowstream/protocol.go b/shadowstream/protocol.go index 567b785..0af89c4 100644 --- a/shadowstream/protocol.go +++ b/shadowstream/protocol.go @@ -15,6 +15,7 @@ import ( "github.com/sagernet/sing/common/buf" M "github.com/sagernet/sing/common/metadata" N "github.com/sagernet/sing/common/network" + "golang.org/x/crypto/chacha20" )