mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 07:26:24 -05:00
add reduced entropy experiment to shadowsocks
This commit is contained in:
parent
eced27b48b
commit
0746740b10
@ -25,6 +25,8 @@ type MemoryAccount struct {
|
|||||||
Key []byte
|
Key []byte
|
||||||
|
|
||||||
replayFilter antireplay.GeneralizedReplayFilter
|
replayFilter antireplay.GeneralizedReplayFilter
|
||||||
|
|
||||||
|
ReducedIVEntropy bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Equals implements protocol.Account.Equals().
|
// Equals implements protocol.Account.Equals().
|
||||||
@ -101,6 +103,7 @@ func (a *Account) AsAccount() (protocol.Account, error) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}(),
|
}(),
|
||||||
|
ReducedIVEntropy: a.ExperimentReducedInitialIvEntropy,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"hash/crc32"
|
"hash/crc32"
|
||||||
"io"
|
"io"
|
||||||
|
mrand "math/rand"
|
||||||
gonet "net"
|
gonet "net"
|
||||||
|
|
||||||
"github.com/v2fly/v2ray-core/v5/common"
|
"github.com/v2fly/v2ray-core/v5/common"
|
||||||
@ -103,6 +104,9 @@ func WriteTCPRequest(request *protocol.RequestHeader, writer io.Writer) (buf.Wri
|
|||||||
if account.Cipher.IVSize() > 0 {
|
if account.Cipher.IVSize() > 0 {
|
||||||
iv = make([]byte, account.Cipher.IVSize())
|
iv = make([]byte, account.Cipher.IVSize())
|
||||||
common.Must2(rand.Read(iv))
|
common.Must2(rand.Read(iv))
|
||||||
|
if account.ReducedIVEntropy {
|
||||||
|
remapToPrintable(iv[:6])
|
||||||
|
}
|
||||||
if ivError := account.CheckIV(iv); ivError != nil {
|
if ivError := account.CheckIV(iv); ivError != nil {
|
||||||
return nil, newError("failed to mark outgoing iv").Base(ivError)
|
return nil, newError("failed to mark outgoing iv").Base(ivError)
|
||||||
}
|
}
|
||||||
@ -301,3 +305,11 @@ func (w *UDPWriter) WriteTo(payload []byte, addr gonet.Addr) (n int, err error)
|
|||||||
packet.Release()
|
packet.Release()
|
||||||
return len(payload), err
|
return len(payload), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func remapToPrintable(input []byte) {
|
||||||
|
const charSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_`{|}~\\\""
|
||||||
|
seed := mrand.New(mrand.NewSource(int64(crc32.ChecksumIEEE(input))))
|
||||||
|
for i := range input {
|
||||||
|
input[i] = charSet[seed.Intn(len(charSet))]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user