add mutex for thread-safe XORKeyStream in CFB8

This commit is contained in:
adman
2026-05-11 23:27:14 +02:00
parent 021b8ddc1a
commit 2fb290572a
2 changed files with 6 additions and 0 deletions
+2
View File
@@ -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
+4
View File
@@ -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
} }