-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdecrypt_test.go
85 lines (68 loc) · 1.63 KB
/
decrypt_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
package ige
import (
"bytes"
"crypto/aes"
"testing"
)
func TestNewIGEDecrypter(t *testing.T) {
c, err := aes.NewCipher(make([]byte, 16))
if err != nil {
t.Fatal(err)
}
defer func() {
if r := recover(); r == nil {
t.Fatal("NewIGEEncrypter didn't panic with bad iv")
}
}()
_ = NewIGEDecrypter(c, []byte{})
}
func TestDecrypterBlockSize(t *testing.T) {
c, err := aes.NewCipher(make([]byte, 16))
if err != nil {
t.Fatal(err)
}
i := NewIGEDecrypter(c, make([]byte, 32))
if i.BlockSize() != 16 {
t.Fatalf("decrypter.BlockSize() != 16, got %d instead\n", i.BlockSize())
}
}
func TestDecrypterCryptBlocks(t *testing.T) {
for a, v := range TestVectors {
out := make([]byte, len(v.Ciphertext))
c, err := aes.NewCipher(v.Key)
if err != nil {
t.Fatal(err)
}
i := NewIGEDecrypter(c, v.IV)
i.CryptBlocks(out, v.Ciphertext)
if !bytes.Equal(out, v.Plaintext) {
t.Fatalf("test vector %d has wrong ciphertext\n", a+1)
}
}
}
func TestDecryptCryptBlocksPanicSrc(t *testing.T) {
c, err := aes.NewCipher(make([]byte, 16))
if err != nil {
t.Fatal(err)
}
defer func() {
if r := recover(); r == nil {
t.Fatal("decrypt.CryptBlocks() not panicking with bad src")
}
}()
i := NewIGEDecrypter(c, make([]byte, 32))
i.CryptBlocks(make([]byte, 16), make([]byte, 1))
}
func TestDecryptCryptBlocksPanicDst(t *testing.T) {
c, err := aes.NewCipher(make([]byte, 16))
if err != nil {
t.Fatal(err)
}
defer func() {
if r := recover(); r == nil {
t.Fatal("decrypt.CryptBlocks() not panicking with bad dst")
}
}()
i := NewIGEDecrypter(c, make([]byte, 32))
i.CryptBlocks(make([]byte, 1), make([]byte, 16))
}