2 GoVPN -- simple secure free software virtual private network daemon
3 Copyright (C) 2014-2017 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 = new([32]byte)
34 io.ReadFull(Rand, testKey[:])
37 func TestEnclessSymmetric(t *testing.T) {
38 nonce := new([16]byte)
39 f := func(pktNum uint64, in []byte) bool {
40 binary.BigEndian.PutUint64(nonce[8:], pktNum)
41 encoded, err := EnclessEncode(testKey, nonce, in)
45 decoded, err := EnclessDecode(testKey, nonce, encoded)
49 return bytes.Compare(decoded, in) == 0
51 if err := quick.Check(f, nil); err != nil {
56 func BenchmarkEnclessEncode(b *testing.B) {
57 nonce := new([16]byte)
58 data := make([]byte, 128)
59 io.ReadFull(Rand, nonce[8:])
60 io.ReadFull(Rand, data)
62 for i := 0; i < b.N; i++ {
63 EnclessEncode(testKey, nonce, data)
67 func BenchmarkEnclessDecode(b *testing.B) {
68 nonce := new([16]byte)
69 data := make([]byte, 128)
70 io.ReadFull(Rand, nonce[8:])
71 io.ReadFull(Rand, data)
72 encoded, _ := EnclessEncode(testKey, nonce, data)
74 for i := 0; i < b.N; i++ {
75 EnclessDecode(testKey, nonce, encoded)