v2ray hace 9 años
padre
commit
85d6e1ad13
Se han modificado 3 ficheros con 9 adiciones y 6 borrados
  1. 7 0
      common/alloc/buffer.go
  2. 1 3
      proxy/vmess/io/writer.go
  3. 1 3
      transport/internet/kcp/crypt.go

+ 7 - 0
common/alloc/buffer.go

@@ -2,6 +2,7 @@
 package alloc
 
 import (
+	"hash"
 	"io"
 
 	"github.com/v2ray/v2ray-core/common/serial"
@@ -109,6 +110,12 @@ func (b *Buffer) PrependUint32(v uint32) *Buffer {
 	return b
 }
 
+func (b *Buffer) PrependHash(h hash.Hash) *Buffer {
+	b.SliceBack(h.Size())
+	h.Sum(b.Value[:0])
+	return b
+}
+
 // Bytes returns the content bytes of this Buffer.
 func (b *Buffer) Bytes() []byte {
 	return b.Value

+ 1 - 3
proxy/vmess/io/writer.go

@@ -30,9 +30,7 @@ func (this *AuthChunkWriter) Release() {
 func Authenticate(buffer *alloc.Buffer) {
 	fnvHash := fnv.New32a()
 	fnvHash.Write(buffer.Value)
-
-	buffer.SliceBack(4)
-	fnvHash.Sum(buffer.Value[:0])
+	buffer.PrependHash(fnvHash)
 
 	buffer.PrependUint16(uint16(buffer.Len()))
 }

+ 1 - 3
transport/internet/kcp/crypt.go

@@ -32,9 +32,7 @@ func (this *SimpleAuthenticator) Seal(buffer *alloc.Buffer) {
 	buffer.PrependUint16(uint16(buffer.Len()))
 	fnvHash := fnv.New32a()
 	fnvHash.Write(buffer.Value)
-
-	buffer.SliceBack(4)
-	fnvHash.Sum(buffer.Value[:0])
+	buffer.PrependHash(fnvHash)
 
 	len := buffer.Len()
 	xtra := 4 - len%4