1
2
3
4
5
6
7 package salsa
8
9 import (
10 "bytes"
11 "testing"
12 )
13
14 func TestCounterOverflow(t *testing.T) {
15 in := make([]byte, 4096)
16 key := &[32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5,
17 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2}
18 for n, counter := range []*[16]byte{
19 &[16]byte{0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0},
20 &[16]byte{0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff},
21 &[16]byte{0, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 0xff, 0xff, 0xff, 0xff},
22 } {
23 out := make([]byte, 4096)
24 XORKeyStream(out, in, counter, key)
25 outGeneric := make([]byte, 4096)
26 genericXORKeyStream(outGeneric, in, counter, key)
27 if !bytes.Equal(out, outGeneric) {
28 t.Errorf("%d: assembly and go implementations disagree", n)
29 }
30 }
31 }
32
View as plain text