1 |
7 |
rudi |
/////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// DES TEST BENCH ////
|
4 |
|
|
//// ////
|
5 |
|
|
//// Author: Rudolf Usselmann ////
|
6 |
|
|
//// rudi@asics.ws ////
|
7 |
|
|
//// ////
|
8 |
|
|
/////////////////////////////////////////////////////////////////////
|
9 |
|
|
//// ////
|
10 |
|
|
//// Copyright (C) 2001 Rudolf Usselmann ////
|
11 |
|
|
//// rudi@asics.ws ////
|
12 |
|
|
//// ////
|
13 |
|
|
//// This source file may be used and distributed without ////
|
14 |
|
|
//// restriction provided that this copyright statement is not ////
|
15 |
|
|
//// removed from the file and that any derivative work contains ////
|
16 |
|
|
//// the original copyright notice and the associated disclaimer.////
|
17 |
|
|
//// ////
|
18 |
|
|
//// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY ////
|
19 |
|
|
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED ////
|
20 |
|
|
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ////
|
21 |
|
|
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR ////
|
22 |
|
|
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, ////
|
23 |
|
|
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ////
|
24 |
|
|
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ////
|
25 |
|
|
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR ////
|
26 |
|
|
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ////
|
27 |
|
|
//// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ////
|
28 |
|
|
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ////
|
29 |
|
|
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ////
|
30 |
|
|
//// POSSIBILITY OF SUCH DAMAGE. ////
|
31 |
|
|
//// ////
|
32 |
|
|
/////////////////////////////////////////////////////////////////////
|
33 |
|
|
|
34 |
|
|
module test;
|
35 |
|
|
|
36 |
|
|
reg clk;
|
37 |
|
|
reg [319:0] x[512:0];
|
38 |
|
|
|
39 |
|
|
reg [319:0] tmp;
|
40 |
|
|
|
41 |
|
|
reg [5:0] cnt;
|
42 |
|
|
integer select;
|
43 |
|
|
integer decrypt;
|
44 |
|
|
wire [63:0] desOut;
|
45 |
|
|
wire [63:0] des_in;
|
46 |
|
|
wire [63:0] exp_out;
|
47 |
|
|
wire [55:0] key1;
|
48 |
|
|
wire [55:0] key2;
|
49 |
|
|
wire [55:0] key3;
|
50 |
|
|
integer ZZZ;
|
51 |
|
|
|
52 |
|
|
initial
|
53 |
|
|
begin
|
54 |
|
|
$display("\n\n");
|
55 |
|
|
$display("*********************************************************");
|
56 |
|
|
$display("* Area Optimized DES core simulation started ... *");
|
57 |
|
|
$display("*********************************************************");
|
58 |
|
|
$display("\n");
|
59 |
|
|
|
60 |
|
|
`ifdef WAVES
|
61 |
|
|
$shm_open("waves");
|
62 |
|
|
$shm_probe("AS",test,"AS");
|
63 |
|
|
$display("INFO: Signal dump enabled ...\n\n");
|
64 |
|
|
`endif
|
65 |
|
|
|
66 |
|
|
clk=0;
|
67 |
|
|
|
68 |
|
|
ZZZ=0;
|
69 |
|
|
|
70 |
|
|
// key1 key2 key3 Test data Out data
|
71 |
|
|
x[0]=320'h0101010101010101_0101010101010101_0101010101010101_95F8A5E5DD31D900_8000000000000000;
|
72 |
|
|
x[1]=320'h0101010101010101_0101010101010101_0101010101010101_9D64555A9A10B852_0000001000000000;
|
73 |
|
|
x[2]=320'h3849674C2602319E_3849674C2602319E_3849674C2602319E_51454B582DDF440A_7178876E01F19B2A;
|
74 |
|
|
x[3]=320'h04B915BA43FEB5B6_04B915BA43FEB5B6_04B915BA43FEB5B6_42FD443059577FA2_AF37FB421F8C4095;
|
75 |
|
|
x[4]=320'h0123456789ABCDEF_0123456789ABCDEF_0123456789ABCDEF_736F6D6564617461_3D124FE2198BA318;
|
76 |
|
|
x[5]=320'h0123456789ABCDEF_5555555555555555_0123456789ABCDEF_736F6D6564617461_FBABA1FF9D05E9B1;
|
77 |
|
|
x[6]=320'h0123456789ABCDEF_5555555555555555_FEDCBA9876543210_736F6D6564617461_18d748e563620572;
|
78 |
|
|
x[7]=320'h0352020767208217_8602876659082198_64056ABDFEA93457_7371756967676C65_c07d2a0fa566fa30;
|
79 |
|
|
x[8]=320'h0101010101010101_8001010101010101_0101010101010102_0000000000000000_e6e6dd5b7e722974;
|
80 |
|
|
x[9]=320'h1046103489988020_9107D01589190101_19079210981A0101_0000000000000000_e1ef62c332fe825b;
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
decrypt = 0;
|
84 |
|
|
@(posedge clk);
|
85 |
|
|
|
86 |
|
|
$display("");
|
87 |
|
|
$display("**************************************");
|
88 |
|
|
$display("* Starting DES Test ... *");
|
89 |
|
|
$display("**************************************");
|
90 |
|
|
$display("");
|
91 |
|
|
|
92 |
|
|
for(decrypt=0;decrypt<2;decrypt=decrypt+1)
|
93 |
|
|
begin
|
94 |
|
|
if(decrypt) $display("Running Encrypt test ...\n");
|
95 |
|
|
else $display("Running Decrypt test ...\n");
|
96 |
|
|
|
97 |
|
|
for(select=0;select<16;select=select+1)
|
98 |
|
|
begin
|
99 |
|
|
tmp=x[select];
|
100 |
|
|
for(cnt=0;cnt<47;cnt=cnt+1) @(posedge clk);
|
101 |
|
|
|
102 |
|
|
#10;
|
103 |
|
|
if((exp_out !== desOut) | (^exp_out===1'bx) | (^desOut===1'bx))
|
104 |
|
|
|
105 |
|
|
$display("ERROR: (%0d) Expected %x Got %x", select, exp_out, desOut);
|
106 |
|
|
else
|
107 |
|
|
$display("PASS : (%0d) Expected %x Got %x", select, exp_out, desOut);
|
108 |
|
|
|
109 |
|
|
//#2 $display("%h %h %h %h %h", key3, key2, key1, des_in, exp_out);
|
110 |
|
|
@(posedge clk);
|
111 |
|
|
end
|
112 |
|
|
end
|
113 |
|
|
|
114 |
|
|
$display("");
|
115 |
|
|
$display("**************************************");
|
116 |
|
|
$display("* DES Test done ... *");
|
117 |
|
|
$display("**************************************");
|
118 |
|
|
$display("");
|
119 |
|
|
|
120 |
|
|
$finish;
|
121 |
|
|
end // end of innitial
|
122 |
|
|
|
123 |
|
|
always #100 clk=~clk;
|
124 |
|
|
|
125 |
|
|
assign #1 key1 = {tmp[319:313],tmp[311:305],tmp[303:297],tmp[295:289],
|
126 |
|
|
tmp[287:281],tmp[279:273],tmp[271:265],tmp[263:257]};
|
127 |
|
|
|
128 |
|
|
assign #1 key2 = {tmp[255:249],tmp[247:241],tmp[239:233],tmp[231:225],
|
129 |
|
|
tmp[223:217],tmp[215:209],tmp[207:201],tmp[199:193]};
|
130 |
|
|
|
131 |
|
|
assign #1 key3 = {tmp[191:185],tmp[183:177],tmp[175:169],tmp[167:161],
|
132 |
|
|
tmp[159:153],tmp[151:145],tmp[143:137],tmp[135:129]};
|
133 |
|
|
|
134 |
|
|
|
135 |
|
|
assign #1 des_in = decrypt[0] ? tmp[63:0] : tmp[127:64];
|
136 |
|
|
assign exp_out = decrypt[0] ? tmp[127:64] : tmp[63:0];
|
137 |
|
|
|
138 |
|
|
des3 u0( .clk( clk ),
|
139 |
|
|
.desOut( desOut ),
|
140 |
|
|
.desIn( des_in ),
|
141 |
|
|
.key1( key1 ),
|
142 |
|
|
.key2( key2 ),
|
143 |
|
|
.key3( key3 ),
|
144 |
|
|
.roundSel( cnt ),
|
145 |
|
|
.decrypt( decrypt[0] )
|
146 |
|
|
);
|
147 |
|
|
|
148 |
|
|
endmodule
|