-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblock_test.go
102 lines (91 loc) · 2.06 KB
/
block_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package ipcipher
import (
"net"
"testing"
)
var c = New(new(Key))
func TestIpCipher_BlockSize(t *testing.T) {
if c.BlockSize() != 0 {
t.Error("Block size is not 0")
}
}
func TestEncryptBlock(t *testing.T) {
for key, ips := range testVectors {
c := New(key)
for in, out := range ips {
o := net.ParseIP(in)
c.Encrypt(o, o)
if !net.ParseIP(out).Equal(o) {
t.Errorf("Invalid IP conversion for key %x, ip %s, expected: %s, got %s", key[:], in, out, o)
}
}
}
}
func TestDecryptBlock(t *testing.T) {
for key, ips := range testVectors {
c := New(key)
for out, in := range ips {
o := net.ParseIP(in)
c.Decrypt(o, o)
if !net.ParseIP(out).Equal(o) {
t.Errorf("Invalid IP conversion for key %x, ip %s, expected: %s, got %s", key[:], in, out, o)
}
}
}
}
func TestEncryptBlockMega(t *testing.T) {
for key, ips := range megaTestVectors {
c := New(key)
for in, out := range ips {
o := net.ParseIP(in)
for i := 0; i < 100000000; i++ {
c.Encrypt(o, o)
}
if !net.ParseIP(out).Equal(o) {
t.Fatalf("Encryption failed for key % x; ip %s; expected %s; got %s", key[:], in, out, o)
}
}
}
}
func TestDecryptBlockMega(t *testing.T) {
for key, ips := range megaTestVectors {
c := New(key)
for out, in := range ips {
o := net.ParseIP(in)
for i := 0; i < 100000000; i++ {
c.Decrypt(o, o)
}
if !net.ParseIP(out).Equal(o) {
t.Fatalf("Encryption failed for key % x; ip %s; expected %s; got %s", key[:], in, out, o)
}
}
}
}
func BenchmarkIpCipher_EncryptForIPv4(b *testing.B) {
ip := net.IPv4zero
c := New(new(Key))
for i := 0; i < b.N; i++ {
c.Encrypt(ip, ip)
}
}
func BenchmarkIpCipher_DecryptForIPv4(b *testing.B) {
ip := net.IPv4zero
c := New(new(Key))
for i := 0; i < b.N; i++ {
c.Decrypt(ip, ip)
}
}
func BenchmarkIpCipher_EncryptForIPv6(b *testing.B) {
ip := net.IPv6zero
c := New(new(Key))
for i := 0; i < b.N; i++ {
c.Encrypt(ip, ip)
}
}
func BenchmarkIpCipher_DecryptForIPv6(b *testing.B) {
ip := net.IPv6zero
c := New(new(Key))
for i := 0; i < b.N; i++ {
c.Decrypt(ip, ip)
}
}