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) {
48 id := new([IDSize]byte)
52 Timeout: time.Second * time.Duration(TimeoutDefault),
56 peer = newPeer(true, "foo", Dummy{&ciphertext}, conf, new([SSize]byte))
57 plaintext = make([]byte, 789)
60 func TestSymmetric(t *testing.T) {
61 peerd := newPeer(true, "foo", Dummy{nil}, conf, new([SSize]byte))
62 f := func(payload []byte) bool {
63 if len(payload) == 0 {
66 peer.EthProcess(payload)
67 return peerd.PktProcess(ciphertext, Dummy{nil}, true)
69 if err := quick.Check(f, nil); err != nil {
74 func TestSymmetricNoise(t *testing.T) {
75 peerd := newPeer(true, "foo", Dummy{nil}, conf, new([SSize]byte))
76 peer.NoiseEnable = true
77 peerd.NoiseEnable = true
78 f := func(payload []byte) bool {
79 if len(payload) == 0 {
82 peer.EthProcess(payload)
83 return peerd.PktProcess(ciphertext, Dummy{nil}, true)
85 if err := quick.Check(f, nil); err != nil {
88 peer.NoiseEnable = true
91 func TestSymmetricEncLess(t *testing.T) {
92 peerd := newPeer(true, "foo", Dummy{nil}, conf, new([SSize]byte))
94 peer.NoiseEnable = true
96 peerd.NoiseEnable = true
97 f := func(payload []byte) bool {
98 if len(payload) == 0 {
101 peer.EthProcess(payload)
102 return peerd.PktProcess(ciphertext, Dummy{nil}, true)
104 if err := quick.Check(f, nil); err != nil {
107 peer.NoiseEnable = false
111 func BenchmarkEnc(b *testing.B) {
113 for i := 0; i < b.N; i++ {
114 peer.EthProcess(plaintext)
118 func BenchmarkDec(b *testing.B) {
119 peer = newPeer(true, "foo", Dummy{&ciphertext}, conf, new([SSize]byte))
120 peer.EthProcess(plaintext)
121 peer = newPeer(true, "foo", Dummy{nil}, conf, new([SSize]byte))
122 orig := make([]byte, len(ciphertext))
123 copy(orig, ciphertext)
125 for i := 0; i < b.N; i++ {
126 peer.nonceBucket0 = make(map[uint64]struct{}, 1)
127 peer.nonceBucket1 = make(map[uint64]struct{}, 1)
128 copy(ciphertext, orig)
129 if !peer.PktProcess(ciphertext, Dummy{nil}, true) {