-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathaesffx_test.go
More file actions
143 lines (119 loc) · 2.96 KB
/
aesffx_test.go
File metadata and controls
143 lines (119 loc) · 2.96 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package aesffx
import (
"encoding/hex"
"testing"
)
// Test vectors taken from:
// * http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/ffx/aes-ffx-vectors.txt
func TestVector1(t *testing.T) {
key, err := hex.DecodeString("2b7e151628aed2a6abf7158809cf4f3c")
if err != nil {
t.Fatalf("Unable to decode hex key: %v", key)
}
tweak := []byte("9876543210")
plainString := "0123456789"
aes, err := NewCipher(10, key, tweak)
if err != nil {
t.Fatalf("Unable to create cipher: %v", err)
}
cipher, err := aes.Encrypt(plainString)
if err != nil {
t.Fatalf("%v", err)
}
if cipher != "6124200773" {
t.Fatalf("Encryption was incorrect. Need %v, got %v",
"6124200773", cipher)
}
plain, err := aes.Decrypt(cipher)
if err != nil {
t.Fatalf("%v", err)
}
if plain != plainString {
t.Fatalf("Decryption unsuccessful. Need %v, got %v",
plainString, plain)
}
}
func TestVector2(t *testing.T) {
key, err := hex.DecodeString("2b7e151628aed2a6abf7158809cf4f3c")
if err != nil {
t.Fatalf("Unable to decode hex key: %v", key)
}
var tweak []byte
plainString := "0123456789"
aes, err := NewCipher(10, key, tweak)
if err != nil {
t.Fatalf("Unable to create cipher: %v", err)
}
cipher, err := aes.Encrypt(plainString)
if err != nil {
t.Fatalf("%v", err)
}
if cipher != "2433477484" {
t.Fatalf("Encryption was incorrect. Need %v, got %v",
"2433477484", cipher)
}
plain, err := aes.Decrypt(cipher)
if err != nil {
t.Fatalf("%v", err)
}
if plain != plainString {
t.Fatalf("Decryption unsuccessful. Need %v, got %v",
plainString, plain)
}
}
func TestVector3(t *testing.T) {
key, err := hex.DecodeString("2b7e151628aed2a6abf7158809cf4f3c")
if err != nil {
t.Fatalf("Unable to decode hex key: %v", key)
}
tweak := []byte("2718281828")
plainString := "314159"
aes, err := NewCipher(10, key, tweak)
if err != nil {
t.Fatalf("Unable to create cipher: %v", err)
}
cipher, err := aes.Encrypt(plainString)
if err != nil {
t.Fatalf("%v", err)
}
if cipher != "535005" {
t.Fatalf("Encryption was incorrect. Need %v, got %v",
"535005", cipher)
}
plain, err := aes.Decrypt(cipher)
if err != nil {
t.Fatalf("%v", err)
}
if plain != plainString {
t.Fatalf("Decryption unsuccessful. Need %v, got %v",
plainString, plain)
}
}
func TestVector4(t *testing.T) {
key, err := hex.DecodeString("2b7e151628aed2a6abf7158809cf4f3c")
if err != nil {
t.Fatalf("Unable to decode hex key: %v", key)
}
tweak := []byte("7777777")
plainString := "999999999"
aes, err := NewCipher(10, key, tweak)
if err != nil {
t.Fatalf("Unable to create cipher: %v", err)
}
cipher, err := aes.Encrypt(plainString)
if err != nil {
t.Fatalf("%v", err)
}
if cipher != "658229573" {
t.Fatalf("Encryption was incorrect. Need %v, got %v",
"658229573", cipher)
}
plain, err := aes.Decrypt(cipher)
if err != nil {
t.Fatalf("%v", err)
}
if plain != plainString {
t.Fatalf("Decryption unsuccessful. Need %v, got %v",
plainString, plain)
}
}