add mutex for thread-safe XORKeyStream in CFB8
This commit is contained in:
@@ -27,6 +27,8 @@ var (
|
|||||||
StateFlag = cmd.String("state", "login", "Initial state: login, config, play")
|
StateFlag = cmd.String("state", "login", "Initial state: login, config, play")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO: maybe use the proto replay api
|
||||||
|
|
||||||
//go:embed failed_packet.go.tmpl
|
//go:embed failed_packet.go.tmpl
|
||||||
var TestSrcF string
|
var TestSrcF string
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ package crypto
|
|||||||
import (
|
import (
|
||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
"crypto/subtle"
|
"crypto/subtle"
|
||||||
|
"sync"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -37,6 +38,7 @@ type CFB8 struct {
|
|||||||
ivPos int
|
ivPos int
|
||||||
iv []byte
|
iv []byte
|
||||||
de bool
|
de bool
|
||||||
|
mutex sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCFB8Decrypt(c cipher.Block, iv []byte) *CFB8 {
|
func NewCFB8Decrypt(c cipher.Block, iv []byte) *CFB8 {
|
||||||
@@ -59,6 +61,8 @@ func newCFB8(c cipher.Block, iv []byte, de bool) *CFB8 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cf *CFB8) XORKeyStream(dst, src []byte) {
|
func (cf *CFB8) XORKeyStream(dst, src []byte) {
|
||||||
|
cf.mutex.Lock()
|
||||||
|
defer cf.mutex.Unlock()
|
||||||
if len(src) == 0 {
|
if len(src) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user