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([32]byte)
33 io.ReadFull(Rand, testKey[:])
36 func TestEnclessSymmetric(t *testing.T) {
37 nonce := new([16]byte)
38 f := func(pktNum uint64, in []byte) bool {
39 binary.BigEndian.PutUint64(nonce[8:], pktNum)
40 encoded, err := EnclessEncode(testKey, nonce, in)
44 decoded, err := EnclessDecode(testKey, nonce, encoded)
48 return bytes.Compare(decoded, in) == 0
50 if err := quick.Check(f, nil); err != nil {
55 func BenchmarkEnclessEncode(b *testing.B) {
56 nonce := new([16]byte)
57 data := make([]byte, 128)
58 io.ReadFull(Rand, nonce[8:])
59 io.ReadFull(Rand, data)
61 for i := 0; i < b.N; i++ {
62 EnclessEncode(testKey, nonce, data)
66 func BenchmarkEnclessDecode(b *testing.B) {
67 nonce := new([16]byte)
68 data := make([]byte, 128)
69 io.ReadFull(Rand, nonce[8:])
70 io.ReadFull(Rand, data)
71 encoded, _ := EnclessEncode(testKey, nonce, data)
73 for i := 0; i < b.N; i++ {
74 EnclessDecode(testKey, nonce, encoded)