1 |
4 |
dj1471 |
//////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// XTEA IP Core ////
|
4 |
|
|
//// ////
|
5 |
|
|
//// This file is part of the xtea project ////
|
6 |
|
|
//// http://www.opencores.org/projects.cgi/web/xtea/overview ////
|
7 |
|
|
//// ////
|
8 |
|
|
//// Test-bench for the XTEA encryption algorithm. ////
|
9 |
|
|
//// ////
|
10 |
|
|
//// TODO: ////
|
11 |
|
|
//// * Update for new combined encipher/decipher module ////
|
12 |
|
|
//// * Tidy ////
|
13 |
|
|
//// * Add interconnections ////
|
14 |
|
|
//// ////
|
15 |
|
|
//// Author: David Johnson, dj@david-web.co.uk ////
|
16 |
|
|
//// ////
|
17 |
|
|
//////////////////////////////////////////////////////////////////////
|
18 |
|
|
//// ////
|
19 |
|
|
//// Copyright (C) 2006 David Johnson ////
|
20 |
|
|
//// ////
|
21 |
|
|
//// This source file is free software; you can redistribute it ////
|
22 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
23 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
24 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
25 |
|
|
//// later version. ////
|
26 |
|
|
//// ////
|
27 |
|
|
//// This source is distributed in the hope that it will be ////
|
28 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
29 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
30 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
31 |
|
|
//// details. ////
|
32 |
|
|
//// ////
|
33 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
34 |
|
|
//// Public License along with this source; if not, write to the ////
|
35 |
|
|
//// Free Software Foundation, Inc., 51 Franklin Street, Fifth ////
|
36 |
|
|
//// Floor, Boston, MA 02110-1301 USA ////
|
37 |
|
|
//// ////
|
38 |
|
|
//////////////////////////////////////////////////////////////////////
|
39 |
|
|
//
|
40 |
|
|
// CVS Revision History
|
41 |
|
|
//
|
42 |
|
|
// $Log: not supported by cvs2svn $
|
43 |
|
|
//
|
44 |
|
|
|
45 |
3 |
dj1471 |
module cipher_testbench (clock, reset, all_done_encipher, all_done_decipher, data_out_encipher1, data_out_encipher2, data_out_decipher1, data_out_decipher2, data_in_encipher1, data_in_encipher2, data_in_decipher1, data_in_decipher2, key_out, result, reset_out);
|
46 |
|
|
|
47 |
|
|
input clock, reset, all_done_encipher, all_done_decipher;
|
48 |
|
|
input[31:0] data_in_encipher1, data_in_encipher2, data_in_decipher1, data_in_decipher2;
|
49 |
|
|
output result, reset_out;
|
50 |
|
|
output[31:0] data_out_encipher1, data_out_encipher2, data_out_decipher1, data_out_decipher2;
|
51 |
|
|
output[127:0] key_out;
|
52 |
|
|
|
53 |
|
|
reg result, reset_out, test_ciphertext, test_plaintext;
|
54 |
|
|
reg[7:0] state;
|
55 |
|
|
reg[31:0] data_out_encipher1, data_out_encipher2, data_out_decipher1, data_out_decipher2, tempdata1, tempdata2;
|
56 |
|
|
reg[127:0] key_out;
|
57 |
|
|
|
58 |
|
|
parameter s0 = 0, s1 = 1, s2 = 2, s3 = 3, s4 = 4, s5 = 5, s6 = 6, s7 = 7, s8 = 8, s9 = 9,
|
59 |
|
|
s10 = 10, s11 = 11, s12 = 12, s13 = 13, s14 = 14, s15 = 15, s16 = 16, s17 = 17, s18 = 18, s19 = 19,
|
60 |
|
|
s20 = 20, s21 = 21, s22 = 22, s23 = 23, s24 = 24, s25 = 25, s26 = 26, s27 = 27, s28 = 28, s29 = 29,
|
61 |
|
|
s30 = 30, s31 = 31, s32 = 32, s33 = 33, s34 = 34, s35 = 35, s36 = 36, s37 = 37, s38 = 38, s39 = 39,
|
62 |
|
|
s40 = 40, s41 = 41, s42 = 42, s43 = 43, s44 = 44, s45 = 45, s46 = 46, s47 = 47, s48 = 48, s49 = 49;
|
63 |
|
|
|
64 |
|
|
always @(posedge clock or posedge reset)
|
65 |
|
|
begin
|
66 |
|
|
if (reset)
|
67 |
|
|
state = s0;
|
68 |
|
|
else
|
69 |
|
|
begin
|
70 |
|
|
case (state)
|
71 |
|
|
s0: state = s1;
|
72 |
|
|
s1: state = s2;
|
73 |
|
|
s2: state = all_done_encipher ? s3 : s2;
|
74 |
|
|
s3: state = s4;
|
75 |
|
|
s4: state = s5;
|
76 |
|
|
s5: state = all_done_decipher ? s6 : s5;
|
77 |
|
|
s6: state = s7;
|
78 |
|
|
s7: state = s8;
|
79 |
|
|
s8: state = s9;
|
80 |
|
|
s9: state = all_done_encipher ? s10 : s9;
|
81 |
|
|
s10: state = s11;
|
82 |
|
|
s11: state = s12;
|
83 |
|
|
s12: state = all_done_decipher ? s13 : s12;
|
84 |
|
|
s13: state = s14;
|
85 |
|
|
s14: state = s15;
|
86 |
|
|
s15: state = s16;
|
87 |
|
|
s16: state = all_done_encipher ? s17 : s16;
|
88 |
|
|
s17: state = s18;
|
89 |
|
|
s18: state = s19;
|
90 |
|
|
s19: state = all_done_decipher ? s20 : s19;
|
91 |
|
|
s20: state = s21;
|
92 |
|
|
s21: state = s22;
|
93 |
|
|
s22: state = s23;
|
94 |
|
|
s23: state = all_done_encipher ? s24 : s23;
|
95 |
|
|
s24: state = s25;
|
96 |
|
|
s25: state = s26;
|
97 |
|
|
s26: state = all_done_decipher ? s27 : s26;
|
98 |
|
|
s27: state = s28;
|
99 |
|
|
s28: state = s29;
|
100 |
|
|
s29: state = s30;
|
101 |
|
|
s30: state = all_done_encipher ? s31 : s30;
|
102 |
|
|
s31: state = s32;
|
103 |
|
|
s32: state = s33;
|
104 |
|
|
s33: state = all_done_decipher ? s34 : s33;
|
105 |
|
|
s34: state = s35;
|
106 |
|
|
s35: state = s36;
|
107 |
|
|
s36: state = s37;
|
108 |
|
|
s37: state = all_done_encipher ? s38 : s37;
|
109 |
|
|
s38: state = s39;
|
110 |
|
|
s39: state = s40;
|
111 |
|
|
s40: state = all_done_decipher ? s41 : s40;
|
112 |
|
|
s41: state = s42;
|
113 |
|
|
s42: state = s43;
|
114 |
|
|
s43: state = s44;
|
115 |
|
|
s44: state = all_done_encipher ? s45 : s44;
|
116 |
|
|
s45: state = s46;
|
117 |
|
|
s46: state = s47;
|
118 |
|
|
s47: state = all_done_decipher ? s48 : s47;
|
119 |
|
|
s48: state = s49;
|
120 |
|
|
s49: state = s49;
|
121 |
|
|
default: state = 1'bz;
|
122 |
|
|
endcase
|
123 |
|
|
end
|
124 |
|
|
end
|
125 |
|
|
|
126 |
|
|
always @(posedge clock or posedge reset)
|
127 |
|
|
begin
|
128 |
|
|
if (reset)
|
129 |
|
|
begin
|
130 |
|
|
result = 1'b0;
|
131 |
|
|
reset_out = 1'b0;
|
132 |
|
|
test_ciphertext = 1'b0;
|
133 |
|
|
test_plaintext = 1'b0;
|
134 |
|
|
data_out_encipher1 = 32'bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;
|
135 |
|
|
data_out_encipher2 = 32'bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;
|
136 |
|
|
data_out_decipher1 = 32'bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;
|
137 |
|
|
data_out_decipher2 = 32'bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;
|
138 |
|
|
key_out = 128'bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;
|
139 |
|
|
end
|
140 |
|
|
else begin
|
141 |
|
|
case (state)
|
142 |
|
|
//Test 1
|
143 |
|
|
s1: begin
|
144 |
|
|
reset_out = 1'b1;
|
145 |
|
|
data_out_encipher1 = 32'h00000000;
|
146 |
|
|
data_out_encipher2 = 32'h00000000;
|
147 |
|
|
key_out = 128'h00000000000000000000000000000000;
|
148 |
|
|
end
|
149 |
|
|
s2: reset_out = 1'b0;
|
150 |
|
|
s3: begin
|
151 |
|
|
test_ciphertext = ((data_in_encipher1 == 32'hdee9d4d8) && (data_in_encipher2 == 32'hf7131ed9));
|
152 |
|
|
tempdata1 = data_in_encipher1;
|
153 |
|
|
tempdata2 = data_in_encipher2;
|
154 |
|
|
end
|
155 |
|
|
s4: begin
|
156 |
|
|
reset_out = 1'b1;
|
157 |
|
|
data_out_decipher1 = tempdata1;
|
158 |
|
|
data_out_decipher2 = tempdata2;
|
159 |
|
|
end
|
160 |
|
|
s5: reset_out = 1'b0;
|
161 |
|
|
s6: test_plaintext = ((data_in_decipher1 == 32'h00000000) && (data_in_decipher2 == 32'h00000000));
|
162 |
|
|
s7: result = (test_ciphertext && test_plaintext);
|
163 |
|
|
//Test 2
|
164 |
|
|
s8: begin
|
165 |
|
|
result = 1'b0;
|
166 |
|
|
reset_out = 1'b1;
|
167 |
|
|
data_out_encipher1 = 32'h00000000;
|
168 |
|
|
data_out_encipher2 = 32'h00000000;
|
169 |
|
|
key_out = 128'h11111111222222223333333344444444;
|
170 |
|
|
end
|
171 |
|
|
s9: reset_out = 1'b0;
|
172 |
|
|
s10: begin
|
173 |
|
|
test_ciphertext = ((data_in_encipher1 == 32'hf07ac290) && (data_in_encipher2 == 32'h23c92672));
|
174 |
|
|
tempdata1 = data_in_encipher1;
|
175 |
|
|
tempdata2 = data_in_encipher2;
|
176 |
|
|
end
|
177 |
|
|
s11: begin
|
178 |
|
|
reset_out = 1'b1;
|
179 |
|
|
data_out_decipher1 = tempdata1;
|
180 |
|
|
data_out_decipher2 = tempdata2;
|
181 |
|
|
end
|
182 |
|
|
s12: reset_out = 1'b0;
|
183 |
|
|
s13: test_plaintext = ((data_in_decipher1 == 32'h00000000) && (data_in_decipher2 == 32'h00000000));
|
184 |
|
|
s14: result = (test_ciphertext && test_plaintext);
|
185 |
|
|
//Test 3
|
186 |
|
|
s15: begin
|
187 |
|
|
result = 1'b0;
|
188 |
|
|
reset_out = 1'b1;
|
189 |
|
|
data_out_encipher1 = 32'h12345678;
|
190 |
|
|
data_out_encipher2 = 32'h9abcdeff;
|
191 |
|
|
key_out = 128'h6a1d78c88c86d67f2a65bfbeb4bd6e46;
|
192 |
|
|
end
|
193 |
|
|
s16: reset_out = 1'b0;
|
194 |
|
|
s17: begin
|
195 |
|
|
test_ciphertext = ((data_in_encipher1 == 32'h99bbb92b) && (data_in_encipher2 == 32'h3ebd1644));
|
196 |
|
|
tempdata1 = data_in_encipher1;
|
197 |
|
|
tempdata2 = data_in_encipher2;
|
198 |
|
|
end
|
199 |
|
|
s18: begin
|
200 |
|
|
reset_out = 1'b1;
|
201 |
|
|
data_out_decipher1 = tempdata1;
|
202 |
|
|
data_out_decipher2 = tempdata2;
|
203 |
|
|
end
|
204 |
|
|
s19: reset_out = 1'b0;
|
205 |
|
|
s20: test_plaintext = ((data_in_decipher1 == 32'h12345678) && (data_in_decipher2 == 32'h9abcdeff));
|
206 |
|
|
s21: result = (test_ciphertext && test_plaintext);
|
207 |
|
|
//Test 4
|
208 |
|
|
s22: begin
|
209 |
|
|
result = 1'b0;
|
210 |
|
|
reset_out = 1'b1;
|
211 |
|
|
data_out_encipher1 = 32'h00000001;
|
212 |
|
|
data_out_encipher2 = 32'h00000001;
|
213 |
|
|
key_out = 128'h62ee209f69b7afce376a8936cdc9e923;
|
214 |
|
|
end
|
215 |
|
|
s23: reset_out = 1'b0;
|
216 |
|
|
s24: begin
|
217 |
|
|
test_ciphertext = ((data_in_encipher1 == 32'he57220dd) && (data_in_encipher2 == 32'h2622745b));
|
218 |
|
|
tempdata1 = data_in_encipher1;
|
219 |
|
|
tempdata2 = data_in_encipher2;
|
220 |
|
|
end
|
221 |
|
|
s25: begin
|
222 |
|
|
reset_out = 1'b1;
|
223 |
|
|
data_out_decipher1 = tempdata1;
|
224 |
|
|
data_out_decipher2 = tempdata2;
|
225 |
|
|
end
|
226 |
|
|
s26: reset_out = 1'b0;
|
227 |
|
|
s27: test_plaintext = ((data_in_decipher1 == 32'h00000001) && (data_in_decipher2 == 32'h00000001));
|
228 |
|
|
s28: result = (test_ciphertext && test_plaintext);
|
229 |
|
|
//Test 5
|
230 |
|
|
s29: begin
|
231 |
|
|
result = 1'b0;
|
232 |
|
|
reset_out = 1'b1;
|
233 |
|
|
data_out_encipher1 = 32'h77777777;
|
234 |
|
|
data_out_encipher2 = 32'h98765432;
|
235 |
|
|
key_out = 128'hbc3a7de2845846cf2794a1276b8ea8b8;
|
236 |
|
|
end
|
237 |
|
|
s30: reset_out = 1'b0;
|
238 |
|
|
s31: begin
|
239 |
|
|
test_ciphertext = ((data_in_encipher1 == 32'hda6b0b0a) && (data_in_encipher2 == 32'ha15e9758));
|
240 |
|
|
tempdata1 = data_in_encipher1;
|
241 |
|
|
tempdata2 = data_in_encipher2;
|
242 |
|
|
end
|
243 |
|
|
s32: begin
|
244 |
|
|
reset_out = 1'b1;
|
245 |
|
|
data_out_decipher1 = tempdata1;
|
246 |
|
|
data_out_decipher2 = tempdata2;
|
247 |
|
|
end
|
248 |
|
|
s33: reset_out = 1'b0;
|
249 |
|
|
s34: test_plaintext = ((data_in_decipher1 == 32'h77777777) && (data_in_decipher2 == 32'h98765432));
|
250 |
|
|
s35: result = (test_ciphertext && test_plaintext);
|
251 |
|
|
//Test 6
|
252 |
|
|
s36: begin
|
253 |
|
|
result = 1'b0;
|
254 |
|
|
reset_out = 1'b1;
|
255 |
|
|
data_out_encipher1 = 32'hffffffff;
|
256 |
|
|
data_out_encipher2 = 32'hffffffff;
|
257 |
|
|
key_out = 128'h6a1d78c88c86d6712a65bfbeb4bd6e46;
|
258 |
|
|
end
|
259 |
|
|
s37: reset_out = 1'b0;
|
260 |
|
|
s38: begin
|
261 |
|
|
test_ciphertext = ((data_in_encipher1 == 32'h674e0539) && (data_in_encipher2 == 32'h5ad31ab8));
|
262 |
|
|
tempdata1 = data_in_encipher1;
|
263 |
|
|
tempdata2 = data_in_encipher2;
|
264 |
|
|
end
|
265 |
|
|
s39: begin
|
266 |
|
|
reset_out = 1'b1;
|
267 |
|
|
data_out_decipher1 = tempdata1;
|
268 |
|
|
data_out_decipher2 = tempdata2;
|
269 |
|
|
end
|
270 |
|
|
s40: reset_out = 1'b0;
|
271 |
|
|
s41: test_plaintext = ((data_in_decipher1 == 32'hffffffff) && (data_in_decipher2 == 32'hffffffff));
|
272 |
|
|
s42: result = (test_ciphertext && test_plaintext);
|
273 |
|
|
//Test 7
|
274 |
|
|
s43: begin
|
275 |
|
|
result = 1'b0;
|
276 |
|
|
reset_out = 1'b1;
|
277 |
|
|
data_out_encipher1 = 32'hffffffff;
|
278 |
|
|
data_out_encipher2 = 32'hffffffff;
|
279 |
|
|
key_out = 128'hffffffffffffffffffffffffffffffff;
|
280 |
|
|
end
|
281 |
|
|
s44: reset_out = 1'b0;
|
282 |
|
|
s45: begin
|
283 |
|
|
test_ciphertext = ((data_in_encipher1 == 32'h28fc2891) && (data_in_encipher2 == 32'he623566a));
|
284 |
|
|
tempdata1 = data_in_encipher1;
|
285 |
|
|
tempdata2 = data_in_encipher2;
|
286 |
|
|
end
|
287 |
|
|
s46: begin
|
288 |
|
|
reset_out = 1'b1;
|
289 |
|
|
data_out_decipher1 = tempdata1;
|
290 |
|
|
data_out_decipher2 = tempdata2;
|
291 |
|
|
end
|
292 |
|
|
s47: reset_out = 1'b0;
|
293 |
|
|
s48: test_plaintext = ((data_in_decipher1 == 32'hffffffff) && (data_in_decipher2 == 32'hffffffff));
|
294 |
|
|
s49: result = (test_ciphertext && test_plaintext);
|
295 |
|
|
//End tests
|
296 |
|
|
default: begin
|
297 |
|
|
reset_out = 1'b1;
|
298 |
|
|
data_out_encipher1 = 32'bzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz;
|
299 |
|
|
data_out_encipher2 = 32'bzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz;
|
300 |
|
|
data_out_decipher1 = 32'bzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz;
|
301 |
|
|
data_out_decipher2 = 32'bzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz;
|
302 |
|
|
key_out = 128'bzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz;
|
303 |
|
|
result = 1'bz;
|
304 |
|
|
end
|
305 |
|
|
endcase
|
306 |
|
|
end
|
307 |
|
|
end
|
308 |
|
|
|
309 |
|
|
endmodule
|