mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-04 14:22:26 +08:00
协议密钥动态随机生成
This commit is contained in:
@@ -13,7 +13,7 @@ type Ec2b struct {
|
||||
temp []byte
|
||||
}
|
||||
|
||||
func LoadKey(b []byte) (*Ec2b, error) {
|
||||
func LoadEc2bKey(b []byte) (*Ec2b, error) {
|
||||
if len(b) < 4+4+16+4+2048 {
|
||||
return nil, fmt.Errorf("invalid ec2b key")
|
||||
}
|
||||
@@ -88,10 +88,8 @@ func (e *Ec2b) Key() []byte {
|
||||
return b
|
||||
}
|
||||
|
||||
func (e *Ec2b) Xor(data []byte) {
|
||||
for i := 0; i < len(data); i++ {
|
||||
data[i] ^= e.temp[i%4096]
|
||||
}
|
||||
func (e *Ec2b) XorKey() []byte {
|
||||
return e.temp
|
||||
}
|
||||
|
||||
func keyScramble(key []byte) {
|
||||
|
||||
@@ -84,8 +84,6 @@ func (b *KeyBlock) Seed() uint64 {
|
||||
return b.seed
|
||||
}
|
||||
|
||||
func (b *KeyBlock) Xor(data []byte) {
|
||||
for i := 0; i < len(data); i++ {
|
||||
data[i] ^= b.data[i%4096]
|
||||
}
|
||||
func (b *KeyBlock) XorKey() [4096]byte {
|
||||
return b.data
|
||||
}
|
||||
|
||||
@@ -2,38 +2,24 @@ package random
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestKey(t *testing.T) {
|
||||
fmt.Println("hw")
|
||||
dispatchEc2b := NewEc2b()
|
||||
dispatchEc2bData := dispatchEc2b.Bytes()
|
||||
dispatchEc2bSeed := dispatchEc2b.Seed()
|
||||
_ = dispatchEc2bData
|
||||
|
||||
//dispatchEc2b := NewEc2b()
|
||||
keyBin, err := os.ReadFile("./static/dispatchSeed.bin")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
dispatchEc2b, err := LoadKey(keyBin)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
dispatchBin := dispatchEc2b.Bytes()
|
||||
dispatchSeed := dispatchEc2b.Seed()
|
||||
_ = dispatchBin
|
||||
dispatchXorKey := dispatchEc2b.XorKey()
|
||||
|
||||
gateDispatchEc2b := NewEc2b()
|
||||
gateDispatchEc2b.SetSeed(dispatchSeed)
|
||||
gateDispatchEc2b.SetSeed(dispatchEc2bSeed)
|
||||
|
||||
dispatchKey := make([]byte, 4096)
|
||||
dispatchEc2b.Xor(dispatchKey)
|
||||
gateDispatchXorKey := gateDispatchEc2b.XorKey()
|
||||
|
||||
gateDispatchKey := make([]byte, 4096)
|
||||
gateDispatchEc2b.Xor(gateDispatchKey)
|
||||
|
||||
gateXorKey := make([]byte, 4096)
|
||||
keyBlock := NewKeyBlock(uint64(11468049314633205968))
|
||||
keyBlock.Xor(gateXorKey)
|
||||
gateXorKey := keyBlock.XorKey()
|
||||
|
||||
fmt.Println("end")
|
||||
fmt.Println(dispatchXorKey, gateDispatchXorKey, gateXorKey)
|
||||
}
|
||||
|
||||
@@ -10,6 +10,10 @@ func init() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
func GetTimeRand() *rand.Rand {
|
||||
return rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
}
|
||||
|
||||
func GetRandomStr(strLen int) (str string) {
|
||||
baseStr := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
||||
for i := 0; i < strLen; i++ {
|
||||
|
||||
Reference in New Issue
Block a user