2 GoVPN -- simple secure free software virtual private network daemon
3 Copyright (C) 2014-2016 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
30 testKey *[16]byte = new([16]byte)
34 io.ReadFull(rand.Reader, testKey[:])
37 func TestSymmetric(t *testing.T) {
38 f := func(data []byte) bool {
39 encoded, err := Encode(testKey, data)
43 if len(encoded) != len(data)+16+32 {
46 decoded, err := Decode(encoded)
50 return bytes.Compare(decoded, data) == 0
52 if err := quick.Check(f, nil); err != nil {
57 func TestSmallSize(t *testing.T) {
58 _, err := Decode([]byte("foobar"))
64 func TestTampered(t *testing.T) {
65 f := func(data []byte, index int) bool {
69 encoded, _ := Encode(testKey, data)
70 encoded[len(data)%index] ^= byte('a')
71 _, err := Decode(encoded)
77 if err := quick.Check(f, nil); err != nil {
82 func BenchmarkEncode(b *testing.B) {
83 data := make([]byte, 128)
84 io.ReadFull(rand.Reader, data)
86 for i := 0; i < b.N; i++ {
91 func BenchmarkDecode(b *testing.B) {
92 data := make([]byte, 128)
93 io.ReadFull(rand.Reader, data)
94 encoded, _ := Encode(testKey, data)
96 for i := 0; i < b.N; i++ {