1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-06-30 15:50:24 +08:00

fix(crypto): xchacha20poly1305 encode

This commit is contained in:
源文雨
2024-07-12 23:01:29 +09:00
parent 9336ab61e8
commit 677b11f440
2 changed files with 21 additions and 13 deletions

View File

@@ -43,14 +43,18 @@ func TestXChacha20(t *testing.T) {
if err != nil {
t.Fatal(err)
}
data := []byte("12345678")
for i := uint64(0); i < 100000; i++ {
db, err := decode(aead, uint16(i), encode(aead, uint16(i), data))
data := make([]byte, 4096)
_, err = rand.Read(data)
if err != nil {
t.Fatal(err)
}
for i := 0; i < 4096; i++ {
db, err := decode(aead, uint16(i), encode(aead, uint16(i), data[:i]))
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(db, data) {
t.Fatal("unexpected preshared at", i, "addt", uint16(i))
if !bytes.Equal(db, data[:i]) {
t.Fatal("unexpected preshared at idx(len)", i, "addt", uint16(i))
}
}
}