mirror of
https://github.com/cedar2025/hysteria.git
synced 2025-09-12 03:14:33 +00:00
Adjustable saltLen
This commit is contained in:
@@ -7,7 +7,9 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// [salt(16)][obfuscated payload]
|
// [salt][obfuscated payload]
|
||||||
|
|
||||||
|
const saltLen = 16
|
||||||
|
|
||||||
type XPlusObfuscator struct {
|
type XPlusObfuscator struct {
|
||||||
Key []byte
|
Key []byte
|
||||||
@@ -24,14 +26,14 @@ func NewXPlusObfuscator(key []byte) *XPlusObfuscator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *XPlusObfuscator) Deobfuscate(in []byte, out []byte) int {
|
func (x *XPlusObfuscator) Deobfuscate(in []byte, out []byte) int {
|
||||||
pLen := len(in) - 16
|
pLen := len(in) - saltLen
|
||||||
if pLen <= 0 || len(out) < pLen {
|
if pLen <= 0 || len(out) < pLen {
|
||||||
// Invalid
|
// Invalid
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
key := sha256.Sum256(append(x.Key, in[:16]...))
|
key := sha256.Sum256(append(x.Key, in[:saltLen]...))
|
||||||
// Deobfuscate the payload
|
// Deobfuscate the payload
|
||||||
for i, c := range in[16:] {
|
for i, c := range in[saltLen:] {
|
||||||
out[i] = c ^ key[i%sha256.Size]
|
out[i] = c ^ key[i%sha256.Size]
|
||||||
}
|
}
|
||||||
return pLen
|
return pLen
|
||||||
@@ -39,14 +41,14 @@ func (x *XPlusObfuscator) Deobfuscate(in []byte, out []byte) int {
|
|||||||
|
|
||||||
func (x *XPlusObfuscator) Obfuscate(p []byte) []byte {
|
func (x *XPlusObfuscator) Obfuscate(p []byte) []byte {
|
||||||
pLen := len(p)
|
pLen := len(p)
|
||||||
buf := make([]byte, 16+pLen)
|
buf := make([]byte, saltLen+pLen)
|
||||||
x.lk.Lock()
|
x.lk.Lock()
|
||||||
_, _ = x.RandSrc.Read(buf[:16]) // salt
|
_, _ = x.RandSrc.Read(buf[:saltLen]) // salt
|
||||||
x.lk.Unlock()
|
x.lk.Unlock()
|
||||||
// Obfuscate the payload
|
// Obfuscate the payload
|
||||||
key := sha256.Sum256(append(x.Key, buf[:16]...))
|
key := sha256.Sum256(append(x.Key, buf[:saltLen]...))
|
||||||
for i, c := range p {
|
for i, c := range p {
|
||||||
buf[i+16] = c ^ key[i%sha256.Size]
|
buf[i+saltLen] = c ^ key[i%sha256.Size]
|
||||||
}
|
}
|
||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user