1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-06-19 01:30:26 +08:00

feat(head): use uniform head extract & crc64 -> md5

This commit is contained in:
源文雨
2024-08-08 12:42:04 +08:00
parent e018aee705
commit d5d7a9412f
5 changed files with 63 additions and 39 deletions

22
gold/head/raw.go Normal file
View File

@@ -0,0 +1,22 @@
package head
import (
"crypto/md5"
"encoding/binary"
)
// CRC64 extract packet header checksum
func CRC64(data []byte) uint64 {
return binary.LittleEndian.Uint64(data[52:PacketHeadLen])
}
// CalcCRC64 calculate packet header checksum
func CalcCRC64(data []byte) uint64 {
m := md5.Sum(data[:52])
return binary.LittleEndian.Uint64(m[:8])
}
// Hash extract 32 bytes blake2b hash from raw bytes
func Hash(data []byte) []byte {
return data[20:52]
}