From e3930e4fe34638f06f404286894ab49a8de964e7 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Fri, 5 Jul 2024 08:59:46 +0800 Subject: [PATCH] Fix AEAD multi-user service not working with packet --- shadowaead/service_multi.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/shadowaead/service_multi.go b/shadowaead/service_multi.go index 0a12377..cb73b7f 100644 --- a/shadowaead/service_multi.go +++ b/shadowaead/service_multi.go @@ -159,6 +159,7 @@ func (s *MultiService[U]) newPacket(ctx context.Context, conn N.PacketConn, buff } var readCipher cipher.AEAD var err error + decrypted := make([]byte, 0, buffer.Len()) for u, m := range s.methodMap { key := buf.NewSize(m.keySaltLength) Kdf(m.key, buffer.To(m.keySaltLength), key) @@ -168,13 +169,14 @@ func (s *MultiService[U]) newPacket(ctx context.Context, conn N.PacketConn, buff return err } var packet []byte - packet, err = readCipher.Open(buffer.Index(m.keySaltLength), rw.ZeroBytes[:readCipher.NonceSize()], buffer.From(m.keySaltLength), nil) + packet, err = readCipher.Open(decrypted, rw.ZeroBytes[:readCipher.NonceSize()], buffer.From(m.keySaltLength), nil) if err != nil { continue } buffer.Advance(m.keySaltLength) buffer.Truncate(len(packet)) + copy(buffer.Bytes(), packet) user, method = u, m break