1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-06-11 12:10:26 +08:00
Files
WireGold/gold/link/crypto_test.go
源文雨 8163c38884 fix: xor
2023-08-04 16:07:35 +08:00

31 lines
556 B
Go

package link
import (
"bytes"
"crypto/rand"
"io"
"testing"
)
func TestXOR(t *testing.T) {
m := Me{
mask: 0x12345678_90abcdef,
}
buf := make([]byte, 4096)
buf2 := make([]byte, 4096)
for i := 1; i < 4096; i++ {
data := buf[:i]
orgdata := buf2[:i]
r1 := bytes.NewBuffer(data[:0])
r2 := bytes.NewBuffer(orgdata[:0])
w := io.MultiWriter(r1, r2)
_, err := io.CopyN(w, rand.Reader, int64(i))
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(m.xordec(m.xorenc(r1.Bytes())), r2.Bytes()) {
t.Fatal("unexpected xor at", i)
}
}
}