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/>.
39 func (d Dummy) Write(b []byte) (int, error) {
47 id := new([IDSize]byte)
52 Timeout: time.Second * time.Duration(TimeoutDefault),
54 peer = newPeer(true, "foo", Dummy{&ciphertext}, conf, new([SSize]byte))
55 plaintext = make([]byte, 789)
58 func TestTransportSymmetric(t *testing.T) {
59 peerd := newPeer(true, "foo", Dummy{nil}, conf, new([SSize]byte))
60 f := func(payload []byte) bool {
61 if len(payload) == 0 {
64 peer.EthProcess(payload)
65 return peerd.PktProcess(ciphertext, Dummy{nil}, true)
67 if err := quick.Check(f, nil); err != nil {
72 func TestTransportSymmetricNoise(t *testing.T) {
73 peerd := newPeer(true, "foo", Dummy{nil}, conf, new([SSize]byte))
74 peer.NoiseEnable = true
75 peerd.NoiseEnable = true
76 f := func(payload []byte) bool {
77 if len(payload) == 0 {
80 peer.EthProcess(payload)
81 return peerd.PktProcess(ciphertext, Dummy{nil}, true)
83 if err := quick.Check(f, nil); err != nil {
86 peer.NoiseEnable = true
89 func TestTransportSymmetricEncless(t *testing.T) {
90 peerd := newPeer(true, "foo", Dummy{nil}, conf, new([SSize]byte))
92 peer.NoiseEnable = true
94 peerd.NoiseEnable = true
95 f := func(payload []byte) bool {
96 if len(payload) == 0 {
99 peer.EthProcess(payload)
100 return peerd.PktProcess(ciphertext, Dummy{nil}, true)
102 if err := quick.Check(f, nil); err != nil {
105 peer.NoiseEnable = false
109 func BenchmarkEnc(b *testing.B) {
111 for i := 0; i < b.N; i++ {
112 peer.EthProcess(plaintext)
116 func BenchmarkDec(b *testing.B) {
117 peer = newPeer(true, "foo", Dummy{&ciphertext}, conf, new([SSize]byte))
118 peer.EthProcess(plaintext)
119 peer = newPeer(true, "foo", Dummy{nil}, conf, new([SSize]byte))
120 orig := make([]byte, len(ciphertext))
121 copy(orig, ciphertext)
123 for i := 0; i < b.N; i++ {
124 peer.nonceBucket0 = make(map[uint64]struct{}, 1)
125 peer.nonceBucket1 = make(map[uint64]struct{}, 1)
126 copy(ciphertext, orig)
127 if !peer.PktProcess(ciphertext, Dummy{nil}, true) {
133 func TestTransportBigger(t *testing.T) {
134 tmp := make([]byte, MTUMax*4)
136 peer.PktProcess(tmp, Dummy{nil}, true)