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/>.
29 testKey *[16]byte = new([16]byte)
36 func TestSymmetric(t *testing.T) {
37 f := func(data []byte) bool {
38 encoded, err := Encode(testKey, data)
42 if len(encoded) != len(data)+16+32 {
45 decoded, err := Decode(encoded)
49 return bytes.Compare(decoded, data) == 0
51 if err := quick.Check(f, nil); err != nil {
56 func TestSmallSize(t *testing.T) {
57 _, err := Decode([]byte("foobar"))
63 func TestTampered(t *testing.T) {
64 f := func(data []byte, index int) bool {
68 encoded, _ := Encode(testKey, data)
69 encoded[len(data)%index] ^= byte('a')
70 _, err := Decode(encoded)
76 if err := quick.Check(f, nil); err != nil {
81 func BenchmarkEncode(b *testing.B) {
82 data := make([]byte, 128)
85 for i := 0; i < b.N; i++ {
90 func BenchmarkDecode(b *testing.B) {
91 data := make([]byte, 128)
93 encoded, _ := Encode(testKey, data)
95 for i := 0; i < b.N; i++ {