prepend hash

pull/215/head v1.20
v2ray 2016-07-17 23:11:05 +02:00
parent 1931820c4c
commit 85d6e1ad13
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
3 changed files with 9 additions and 6 deletions

View File

@ -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

View File

@ -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()))
}

View File

@ -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