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 TestSymmetricEncLess(t *testing.T) {
75 peerd := newPeer(true, "foo", Dummy{nil}, conf, new([SSize]byte))
76 peer.NoiseEnable = true
79 peerd.NoiseEnable = true
80 f := func(payload []byte) bool {
81 if len(payload) == 0 {
84 peer.EthProcess(payload)
85 return peerd.PktProcess(ciphertext, Dummy{nil}, true)
87 if err := quick.Check(f, nil); err != nil {
90 peer.NoiseEnable = false
94 func BenchmarkEnc(b *testing.B) {
96 for i := 0; i < b.N; i++ {
97 peer.EthProcess(plaintext)
101 func BenchmarkDec(b *testing.B) {
102 peer = newPeer(true, "foo", Dummy{&ciphertext}, conf, new([SSize]byte))
103 peer.EthProcess(plaintext)
104 peer = newPeer(true, "foo", Dummy{nil}, conf, new([SSize]byte))
105 orig := make([]byte, len(ciphertext))
106 copy(orig, ciphertext)
108 for i := 0; i < b.N; i++ {
109 peer.nonceBucket0 = make(map[uint64]struct{}, 1)
110 peer.nonceBucket1 = make(map[uint64]struct{}, 1)
111 copy(ciphertext, orig)
112 if !peer.PktProcess(ciphertext, Dummy{nil}, true) {