mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-04-21 04:59:10 -04:00
re-enable vmess test
This commit is contained in:
51
hash/id.go
Normal file
51
hash/id.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package hash
|
||||
|
||||
import (
|
||||
"crypto/hmac"
|
||||
"crypto/md5"
|
||||
)
|
||||
|
||||
type CounterHash interface {
|
||||
Hash(key []byte, counter int64) []byte
|
||||
}
|
||||
|
||||
type StringHash interface {
|
||||
Hash(key []byte, data []byte) []byte
|
||||
}
|
||||
|
||||
type TimeHash struct {
|
||||
baseHash StringHash
|
||||
}
|
||||
|
||||
func NewTimeHash(baseHash StringHash) CounterHash {
|
||||
return TimeHash{
|
||||
baseHash: baseHash,
|
||||
}
|
||||
}
|
||||
|
||||
func (h TimeHash) Hash(key []byte, counter int64) []byte {
|
||||
counterBytes := int64ToBytes(counter)
|
||||
return h.baseHash.Hash(key, counterBytes)
|
||||
}
|
||||
|
||||
type HMACHash struct {
|
||||
}
|
||||
|
||||
func (h HMACHash) Hash(key []byte, data []byte) []byte {
|
||||
hash := hmac.New(md5.New, key)
|
||||
hash.Write(data)
|
||||
return hash.Sum(nil)
|
||||
}
|
||||
|
||||
func int64ToBytes(value int64) []byte {
|
||||
return []byte{
|
||||
byte(value >> 56),
|
||||
byte(value >> 48),
|
||||
byte(value >> 40),
|
||||
byte(value >> 32),
|
||||
byte(value >> 24),
|
||||
byte(value >> 16),
|
||||
byte(value >> 8),
|
||||
byte(value),
|
||||
}
|
||||
}
|
||||
15
hash/int.go
Normal file
15
hash/int.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package hash
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
)
|
||||
|
||||
func Int64Hash(value int64) []byte {
|
||||
md5hash := md5.New()
|
||||
buffer := int64ToBytes(value)
|
||||
md5hash.Write(buffer)
|
||||
md5hash.Write(buffer)
|
||||
md5hash.Write(buffer)
|
||||
md5hash.Write(buffer)
|
||||
return md5hash.Sum(nil)
|
||||
}
|
||||
Reference in New Issue
Block a user