]> Cypherpunks.ru repositories - govpn.git/blob - src/govpn/peer_test.go
Use Argon2d PHC winner instead of PBKDF2
[govpn.git] / src / govpn / peer_test.go
1 package govpn
2
3 import (
4         "testing"
5         "time"
6 )
7
8 var (
9         peer       *Peer
10         plaintext  []byte
11         ciphertext []byte
12         peerId     *PeerId
13         conf       *PeerConf
14 )
15
16 type Dummy struct {
17         dst *[]byte
18 }
19
20 func (d Dummy) Write(b []byte) (int, error) {
21         if d.dst != nil {
22                 *d.dst = b
23         }
24         return len(b), nil
25 }
26
27 func init() {
28         MTU = 1500
29         id := new([IDSize]byte)
30         peerId := PeerId(*id)
31         conf = &PeerConf{
32                 Id:      &peerId,
33                 Timeout: time.Second * time.Duration(TimeoutDefault),
34                 Noise:   false,
35                 CPR:     0,
36         }
37         peer = newPeer(true, "foo", Dummy{&ciphertext}, conf, new([SSize]byte))
38         plaintext = make([]byte, 789)
39 }
40
41 func BenchmarkEnc(b *testing.B) {
42         b.ResetTimer()
43         for i := 0; i < b.N; i++ {
44                 peer.EthProcess(plaintext)
45         }
46 }
47
48 func BenchmarkDec(b *testing.B) {
49         peer = newPeer(true, "foo", Dummy{&ciphertext}, conf, new([SSize]byte))
50         peer.EthProcess(plaintext)
51         peer = newPeer(true, "foo", Dummy{nil}, conf, new([SSize]byte))
52         orig := make([]byte, len(ciphertext))
53         copy(orig, ciphertext)
54         b.ResetTimer()
55         for i := 0; i < b.N; i++ {
56                 peer.nonceBucket0 = make(map[uint64]struct{}, 1)
57                 peer.nonceBucket1 = make(map[uint64]struct{}, 1)
58                 copy(ciphertext, orig)
59                 if !peer.PktProcess(ciphertext, Dummy{nil}, true) {
60                         b.Fail()
61                 }
62         }
63 }