This repository has been archived on 2026-10-31. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Ananta-ps/pkg/crypto/chacha8/chacha8_test.go
T

42 lines
792 B
Go

package chacha8
import (
"bytes"
"testing"
)
func TestChaCha8Roundtrip(t *testing.T) {
key := make([]byte, 32)
for i := range key {
key[i] = byte(i + 1)
}
nonce := make([]byte, 12)
for i := range nonce {
nonce[i] = byte(i + 0x10)
}
c1, err := New(key, nonce)
if err != nil {
t.Fatalf("New failed: %v", err)
}
c2, err := New(key, nonce)
if err != nil {
t.Fatalf("New failed: %v", err)
}
original := []byte("Hello, Ananta NetEase UXChaCha8 stream cipher verification!")
data := make([]byte, len(original))
copy(data, original)
c1.XorInPlace(data)
if bytes.Equal(data, original) {
t.Errorf("Ciphertext equals plaintext")
}
c2.XorInPlace(data)
if !bytes.Equal(data, original) {
t.Errorf("Decrypted data != original: got %q, want %q", data, original)
}
}