mirror of
https://github.com/fumiama/WireGold.git
synced 2026-06-04 23:40:26 +08:00
fix: addtional data error
This commit is contained in:
@@ -5,6 +5,8 @@ import (
|
||||
"crypto/rand"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/crypto/chacha20poly1305"
|
||||
)
|
||||
|
||||
func TestXOR(t *testing.T) {
|
||||
@@ -28,3 +30,22 @@ func TestXOR(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestXChacha20(t *testing.T) {
|
||||
l := Link{}
|
||||
k := make([]byte, 32)
|
||||
_, err := rand.Read(k)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
l.aead, err = chacha20poly1305.NewX(k)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data := []byte("12345678")
|
||||
for i := uint64(0); i < 100000; i++ {
|
||||
if !bytes.Equal(l.DecodePreshared(uint16(i), l.EncodePreshared(uint16(i), data)), data) {
|
||||
t.Fatal("unexpected preshared at", i, "addt", uint16(i))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ func (l *Link) encrypt(p *head.Packet, sndcnt uint16, teatype uint8) {
|
||||
logrus.Debugln("[send] data len after zstd:", len(p.Data))
|
||||
}
|
||||
if l.aead != nil {
|
||||
p.Data = l.EncodePreshared(sndcnt, p.Data)
|
||||
p.Data = l.EncodePreshared(sndcnt&0x0fff, p.Data)
|
||||
logrus.Debugln("[send] data len after xchacha20:", len(p.Data))
|
||||
}
|
||||
p.Data = l.Encode(teatype, p.Data)
|
||||
|
||||
Reference in New Issue
Block a user