Source

sha3 / stream_test.go

Full commit
package sha3

import "testing"

func TestStreamRoundtrip(t *testing.T) {
	key := []byte("key")
	b := make([]byte, 41<<10)
	enc := NewCipher(key)
	for i := 0; i < len(b); i += 41 {
		enc.XORKeyStream(b[i:i+41], b[i:i+41])
	}

	allZero := true
	for _, c := range b {
		if c != 0 {
			allZero = false
			break
		}
	}
	if allZero {
		t.Fatalf("Nothing got ciphered.")
	}

	dec := NewCipher(key)
	dec.XORKeyStream(b, b)

	for i, c := range b {
		if c != 0 {
			t.Fatalf("Cipher roundtrip mismatch at byte %d", i)
		}
	}
}