2 GoVPN -- simple secure free software virtual private network daemon
3 Copyright (C) 2014-2019 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, version 3 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
29 testKey = new([16]byte)
33 io.ReadFull(rand.Reader, testKey[:])
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)
83 io.ReadFull(rand.Reader, data)
85 for i := 0; i < b.N; i++ {
90 func BenchmarkDecode(b *testing.B) {
91 data := make([]byte, 128)
92 io.ReadFull(rand.Reader, data)
93 encoded, _ := Encode(testKey, data)
95 for i := 0; i < b.N; i++ {