Skip to content

Commit a65ba6b

Browse files
author
Maximilian Brune
committed
vim retab + go module recreation + mumbleproto/generate_main.go Changed
1 parent 3371eeb commit a65ba6b

34 files changed

+3600
-3488
lines changed

cryptstate/cryptstate.go

Lines changed: 199 additions & 199 deletions
Large diffs are not rendered by default.

cryptstate/cryptstate_test.go

Lines changed: 158 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -5,184 +5,184 @@
55
package cryptstate
66

77
import (
8-
"bytes"
9-
"crypto/aes"
10-
"encoding/hex"
11-
"testing"
8+
"bytes"
9+
"crypto/aes"
10+
"encoding/hex"
11+
"testing"
1212
)
1313

1414
func TestOCB2AES128Encrypt(t *testing.T) {
15-
msg := [15]byte{
16-
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
17-
}
18-
key := [aes.BlockSize]byte{
19-
0x96, 0x8b, 0x1b, 0x0c, 0x53, 0x1e, 0x1f, 0x80, 0xa6, 0x1d, 0xcb, 0x27, 0x94, 0x09, 0x6f, 0x32,
20-
}
21-
eiv := [aes.BlockSize]byte{
22-
0x1e, 0x2a, 0x9b, 0xd0, 0x2d, 0xa6, 0x8e, 0x46, 0x26, 0x85, 0x83, 0xe9, 0x14, 0x2a, 0xff, 0x2a,
23-
}
24-
div := [aes.BlockSize]byte{
25-
0x73, 0x99, 0x9d, 0xa2, 0x03, 0x70, 0x00, 0x96, 0xef, 0x55, 0x06, 0x7a, 0x8b, 0xbe, 0x00, 0x07,
26-
}
27-
expected := [19]byte{
28-
0x1f, 0xfc, 0xdd, 0xb4, 0x68, 0x13, 0x68, 0xb7, 0x92, 0x67, 0xca, 0x2d, 0xba, 0xb7, 0x0d, 0x44, 0xdf, 0x32, 0xd4,
29-
}
30-
expected_eiv := [aes.BlockSize]byte{
31-
0x1f, 0x2a, 0x9b, 0xd0, 0x2d, 0xa6, 0x8e, 0x46, 0x26, 0x85, 0x83, 0xe9, 0x14, 0x2a, 0xff, 0x2a,
32-
}
33-
34-
cs := CryptState{}
35-
out := make([]byte, 19)
36-
cs.SetKey("OCB2-AES128", key[:], eiv[:], div[:])
37-
cs.Encrypt(out, msg[:])
38-
39-
if !bytes.Equal(out[:], expected[:]) {
40-
t.Errorf("Mismatch in output")
41-
}
42-
43-
if !bytes.Equal(cs.EncryptIV[:], expected_eiv[:]) {
44-
t.Errorf("EIV mismatch")
45-
}
15+
msg := [15]byte{
16+
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
17+
}
18+
key := [aes.BlockSize]byte{
19+
0x96, 0x8b, 0x1b, 0x0c, 0x53, 0x1e, 0x1f, 0x80, 0xa6, 0x1d, 0xcb, 0x27, 0x94, 0x09, 0x6f, 0x32,
20+
}
21+
eiv := [aes.BlockSize]byte{
22+
0x1e, 0x2a, 0x9b, 0xd0, 0x2d, 0xa6, 0x8e, 0x46, 0x26, 0x85, 0x83, 0xe9, 0x14, 0x2a, 0xff, 0x2a,
23+
}
24+
div := [aes.BlockSize]byte{
25+
0x73, 0x99, 0x9d, 0xa2, 0x03, 0x70, 0x00, 0x96, 0xef, 0x55, 0x06, 0x7a, 0x8b, 0xbe, 0x00, 0x07,
26+
}
27+
expected := [19]byte{
28+
0x1f, 0xfc, 0xdd, 0xb4, 0x68, 0x13, 0x68, 0xb7, 0x92, 0x67, 0xca, 0x2d, 0xba, 0xb7, 0x0d, 0x44, 0xdf, 0x32, 0xd4,
29+
}
30+
expected_eiv := [aes.BlockSize]byte{
31+
0x1f, 0x2a, 0x9b, 0xd0, 0x2d, 0xa6, 0x8e, 0x46, 0x26, 0x85, 0x83, 0xe9, 0x14, 0x2a, 0xff, 0x2a,
32+
}
33+
34+
cs := CryptState{}
35+
out := make([]byte, 19)
36+
cs.SetKey("OCB2-AES128", key[:], eiv[:], div[:])
37+
cs.Encrypt(out, msg[:])
38+
39+
if !bytes.Equal(out[:], expected[:]) {
40+
t.Errorf("Mismatch in output")
41+
}
42+
43+
if !bytes.Equal(cs.EncryptIV[:], expected_eiv[:]) {
44+
t.Errorf("EIV mismatch")
45+
}
4646
}
4747

4848
func TestOCB2AES128Decrypt(t *testing.T) {
49-
key := [aes.BlockSize]byte{
50-
0x96, 0x8b, 0x1b, 0x0c, 0x53, 0x1e, 0x1f, 0x80, 0xa6, 0x1d, 0xcb, 0x27, 0x94, 0x09, 0x6f, 0x32,
51-
}
52-
eiv := [aes.BlockSize]byte{
53-
0x1e, 0x2a, 0x9b, 0xd0, 0x2d, 0xa6, 0x8e, 0x46, 0x26, 0x85, 0x83, 0xe9, 0x14, 0x2a, 0xff, 0x2a,
54-
}
55-
div := [aes.BlockSize]byte{
56-
0x73, 0x99, 0x9d, 0xa2, 0x03, 0x70, 0x00, 0x96, 0xef, 0x55, 0x06, 0x7a, 0x8b, 0xbe, 0x00, 0x07,
57-
}
58-
crypted := [19]byte{
59-
0x1f, 0xfc, 0xdd, 0xb4, 0x68, 0x13, 0x68, 0xb7, 0x92, 0x67, 0xca, 0x2d, 0xba, 0xb7, 0x0d, 0x44, 0xdf, 0x32, 0xd4,
60-
}
61-
expected := [15]byte{
62-
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
63-
}
64-
post_div := [aes.BlockSize]byte{
65-
0x1f, 0x2a, 0x9b, 0xd0, 0x2d, 0xa6, 0x8e, 0x46, 0x26, 0x85, 0x83, 0xe9, 0x14, 0x2a, 0xff, 0x2a,
66-
}
67-
68-
cs := CryptState{}
69-
out := make([]byte, 15)
70-
cs.SetKey("OCB2-AES128", key[:], div[:], eiv[:])
71-
err := cs.Decrypt(out, crypted[:])
72-
if err != nil {
73-
t.Fatalf("%v", err)
74-
}
75-
76-
if !bytes.Equal(out, expected[:]) {
77-
t.Errorf("Mismatch in output")
78-
}
79-
80-
if !bytes.Equal(cs.DecryptIV, post_div[:]) {
81-
t.Errorf("Mismatch in DIV")
82-
}
49+
key := [aes.BlockSize]byte{
50+
0x96, 0x8b, 0x1b, 0x0c, 0x53, 0x1e, 0x1f, 0x80, 0xa6, 0x1d, 0xcb, 0x27, 0x94, 0x09, 0x6f, 0x32,
51+
}
52+
eiv := [aes.BlockSize]byte{
53+
0x1e, 0x2a, 0x9b, 0xd0, 0x2d, 0xa6, 0x8e, 0x46, 0x26, 0x85, 0x83, 0xe9, 0x14, 0x2a, 0xff, 0x2a,
54+
}
55+
div := [aes.BlockSize]byte{
56+
0x73, 0x99, 0x9d, 0xa2, 0x03, 0x70, 0x00, 0x96, 0xef, 0x55, 0x06, 0x7a, 0x8b, 0xbe, 0x00, 0x07,
57+
}
58+
crypted := [19]byte{
59+
0x1f, 0xfc, 0xdd, 0xb4, 0x68, 0x13, 0x68, 0xb7, 0x92, 0x67, 0xca, 0x2d, 0xba, 0xb7, 0x0d, 0x44, 0xdf, 0x32, 0xd4,
60+
}
61+
expected := [15]byte{
62+
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
63+
}
64+
post_div := [aes.BlockSize]byte{
65+
0x1f, 0x2a, 0x9b, 0xd0, 0x2d, 0xa6, 0x8e, 0x46, 0x26, 0x85, 0x83, 0xe9, 0x14, 0x2a, 0xff, 0x2a,
66+
}
67+
68+
cs := CryptState{}
69+
out := make([]byte, 15)
70+
cs.SetKey("OCB2-AES128", key[:], div[:], eiv[:])
71+
err := cs.Decrypt(out, crypted[:])
72+
if err != nil {
73+
t.Fatalf("%v", err)
74+
}
75+
76+
if !bytes.Equal(out, expected[:]) {
77+
t.Errorf("Mismatch in output")
78+
}
79+
80+
if !bytes.Equal(cs.DecryptIV, post_div[:]) {
81+
t.Errorf("Mismatch in DIV")
82+
}
8383
}
8484

8585
// Test that our wrapped NaCl secretbox cipher
8686
// works. The test data for this test was lifted
8787
// from the secretbox_test.go file.
8888
func TestXSalsa20Poly1305Encrypt(t *testing.T) {
89-
cs := CryptState{}
90-
91-
var key [32]byte
92-
var eiv [24]byte
93-
var div [24]byte
94-
var message [64]byte
95-
96-
for i := range key[:] {
97-
key[i] = 1
98-
}
99-
100-
// Since we pre-increment our EIV,
101-
// this look a bit off compared to
102-
// the secretbox_test.go test case.
103-
for i := range eiv[:] {
104-
eiv[i] = 2
105-
div[i] = 2
106-
}
107-
eiv[0] = 1
108-
div[0] = 1
109-
110-
for i := range message[:] {
111-
message[i] = 3
112-
}
113-
114-
cs.SetKey("XSalsa20-Poly1305", key[:], div[:], eiv[:])
115-
dst := make([]byte, len(message)+cs.Overhead())
116-
cs.Encrypt(dst, message[:])
117-
118-
expected, _ := hex.DecodeString("8442bc313f4626f1359e3b50122b6ce6fe66ddfe7d39d14e637eb4fd5b45beadab55198df6ab5368439792a23c87db70acb6156dc5ef957ac04f6276cf6093b84be77ff0849cc33e34b7254d5a8f65ad")
119-
if !bytes.Equal(dst[1:], expected) {
120-
t.Fatalf("mismatch! got\n%x\n, expected\n%x", dst, expected)
121-
}
89+
cs := CryptState{}
90+
91+
var key [32]byte
92+
var eiv [24]byte
93+
var div [24]byte
94+
var message [64]byte
95+
96+
for i := range key[:] {
97+
key[i] = 1
98+
}
99+
100+
// Since we pre-increment our EIV,
101+
// this look a bit off compared to
102+
// the secretbox_test.go test case.
103+
for i := range eiv[:] {
104+
eiv[i] = 2
105+
div[i] = 2
106+
}
107+
eiv[0] = 1
108+
div[0] = 1
109+
110+
for i := range message[:] {
111+
message[i] = 3
112+
}
113+
114+
cs.SetKey("XSalsa20-Poly1305", key[:], div[:], eiv[:])
115+
dst := make([]byte, len(message)+cs.Overhead())
116+
cs.Encrypt(dst, message[:])
117+
118+
expected, _ := hex.DecodeString("8442bc313f4626f1359e3b50122b6ce6fe66ddfe7d39d14e637eb4fd5b45beadab55198df6ab5368439792a23c87db70acb6156dc5ef957ac04f6276cf6093b84be77ff0849cc33e34b7254d5a8f65ad")
119+
if !bytes.Equal(dst[1:], expected) {
120+
t.Fatalf("mismatch! got\n%x\n, expected\n%x", dst, expected)
121+
}
122122
}
123123

124124
// Test that we can reverse the result of the Encrypt test.
125125
func TestXSalsa20Poly1305Decrypt(t *testing.T) {
126-
cs := CryptState{}
127-
128-
var key [32]byte
129-
var eiv [24]byte
130-
var div [24]byte
131-
var expected [64]byte
132-
133-
for i := range key[:] {
134-
key[i] = 1
135-
}
136-
137-
// Since we pre-increment our EIV,
138-
// this look a bit off compared to
139-
// the secretbox_test.go test case.
140-
for i := range eiv[:] {
141-
eiv[i] = 2
142-
div[i] = 2
143-
}
144-
eiv[0] = 1
145-
div[0] = 1
146-
147-
for i := range expected[:] {
148-
expected[i] = 3
149-
}
150-
151-
message, _ := hex.DecodeString("028442bc313f4626f1359e3b50122b6ce6fe66ddfe7d39d14e637eb4fd5b45beadab55198df6ab5368439792a23c87db70acb6156dc5ef957ac04f6276cf6093b84be77ff0849cc33e34b7254d5a8f65ad")
152-
cs.SetKey("XSalsa20-Poly1305", key[:], eiv[:], div[:])
153-
dst := make([]byte, len(message)-cs.Overhead())
154-
err := cs.Decrypt(dst, message[:])
155-
if err != nil {
156-
t.Fatalf("%v", err)
157-
}
158-
159-
if !bytes.Equal(dst, expected[:]) {
160-
t.Fatalf("mismatch! got\n%x\n, expected\n%x", dst, expected)
161-
}
126+
cs := CryptState{}
127+
128+
var key [32]byte
129+
var eiv [24]byte
130+
var div [24]byte
131+
var expected [64]byte
132+
133+
for i := range key[:] {
134+
key[i] = 1
135+
}
136+
137+
// Since we pre-increment our EIV,
138+
// this look a bit off compared to
139+
// the secretbox_test.go test case.
140+
for i := range eiv[:] {
141+
eiv[i] = 2
142+
div[i] = 2
143+
}
144+
eiv[0] = 1
145+
div[0] = 1
146+
147+
for i := range expected[:] {
148+
expected[i] = 3
149+
}
150+
151+
message, _ := hex.DecodeString("028442bc313f4626f1359e3b50122b6ce6fe66ddfe7d39d14e637eb4fd5b45beadab55198df6ab5368439792a23c87db70acb6156dc5ef957ac04f6276cf6093b84be77ff0849cc33e34b7254d5a8f65ad")
152+
cs.SetKey("XSalsa20-Poly1305", key[:], eiv[:], div[:])
153+
dst := make([]byte, len(message)-cs.Overhead())
154+
err := cs.Decrypt(dst, message[:])
155+
if err != nil {
156+
t.Fatalf("%v", err)
157+
}
158+
159+
if !bytes.Equal(dst, expected[:]) {
160+
t.Fatalf("mismatch! got\n%x\n, expected\n%x", dst, expected)
161+
}
162162
}
163163

164164
func TestNullEncrypt(t *testing.T) {
165-
cs := CryptState{}
166-
cs.SetKey("NULL", []byte{}, []byte{1}, []byte{1})
167-
msg := []byte("HelloWorld")
168-
dst := make([]byte, len(msg)+cs.Overhead())
169-
cs.Encrypt(dst, msg)
170-
if !bytes.Equal(dst[1:], msg) {
171-
t.Fatalf("mismatch! got\n%x\n, expected\n%x", dst, msg)
172-
}
165+
cs := CryptState{}
166+
cs.SetKey("NULL", []byte{}, []byte{1}, []byte{1})
167+
msg := []byte("HelloWorld")
168+
dst := make([]byte, len(msg)+cs.Overhead())
169+
cs.Encrypt(dst, msg)
170+
if !bytes.Equal(dst[1:], msg) {
171+
t.Fatalf("mismatch! got\n%x\n, expected\n%x", dst, msg)
172+
}
173173
}
174174

175175
func TestNullDecrypt(t *testing.T) {
176-
cs := CryptState{}
177-
cs.SetKey("NULL", []byte{}, []byte{1}, []byte{1})
178-
msg := []byte{2}
179-
msg = append(msg, []byte("HelloWorld")...)
180-
dst := make([]byte, len(msg)-cs.Overhead())
181-
err := cs.Decrypt(dst, msg)
182-
if err != nil {
183-
t.Fatalf("%v", err)
184-
}
185-
if !bytes.Equal(dst, msg[1:]) {
186-
t.Fatalf("mismatch! got\n%x\n, expected\n%x", dst, msg)
187-
}
176+
cs := CryptState{}
177+
cs.SetKey("NULL", []byte{}, []byte{1}, []byte{1})
178+
msg := []byte{2}
179+
msg = append(msg, []byte("HelloWorld")...)
180+
dst := make([]byte, len(msg)-cs.Overhead())
181+
err := cs.Decrypt(dst, msg)
182+
if err != nil {
183+
t.Fatalf("%v", err)
184+
}
185+
if !bytes.Equal(dst, msg[1:]) {
186+
t.Fatalf("mismatch! got\n%x\n, expected\n%x", dst, msg)
187+
}
188188
}

cryptstate/mode_null.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ type nullMode struct{}
99

1010
// NonceSize returns the nonce size to be used with NULL.
1111
func (n *nullMode) NonceSize() int {
12-
return 1
12+
return 1
1313
}
1414

1515
// KeySize returns the key size to be used with NULL.
1616
func (n *nullMode) KeySize() int {
17-
return 0
17+
return 0
1818
}
1919

2020
// Overhead returns the overhead that a ciphertext has over a plaintext.
2121
func (n *nullMode) Overhead() int {
22-
return 0
22+
return 0
2323
}
2424

2525
// SetKey sets a new key. The key must have a length equal to KeySize().
@@ -28,11 +28,11 @@ func (n *nullMode) SetKey(key []byte) {
2828

2929
// Encrypt encrypts a message using NULL and outputs it to dst.
3030
func (n *nullMode) Encrypt(dst []byte, src []byte, nonce []byte) {
31-
copy(dst, src)
31+
copy(dst, src)
3232
}
3333

3434
// Decrypt decrypts a message using NULL and outputs it to dst.
3535
func (n *nullMode) Decrypt(dst []byte, src []byte, nonce []byte) bool {
36-
copy(dst, src)
37-
return true
36+
copy(dst, src)
37+
return true
3838
}

0 commit comments

Comments
 (0)