OpenCores
URL https://opencores.org/ocsvn/csa/csa/trunk

Subversion Repositories csa

[/] [csa/] [trunk/] [bench/] [decrypt_tb.v] - Blame information for rev 35

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 18 simon111
 
2
// this is the test bench for decrypt module
3
 
4 22 simon111
 
5
`define TEST_DECRYPT
6
 
7 18 simon111
`timescale 10ns/1ns
8 20 simon111
module decrypt_tb;
9 18 simon111
 
10 22 simon111
reg clk;
11
reg rst;
12
 
13
`ifdef TEST_DECRYPT
14
 
15
 
16
integer bytes;
17
integer out_bytes;
18
 
19
reg      [204*8-1 : 0]  tt;
20
reg      [8*8-1   : 0]  even_cw;
21
reg      [8*8-1   : 0]  odd_cw;
22
reg      [8-1     : 0]  encrypted [188:1];
23
reg      [8-1     : 0]  decrypted [188:1];
24
 
25
reg      [8*8-1:0]    ck;
26
reg                   even_odd;
27
reg                   en;
28
reg                   key_en;
29
reg      [  8-1:0]    enc;
30
wire     [  8-1:0]    dec;
31
wire                  invalid;
32
 
33 18 simon111
initial
34
begin
35
        $read_data(
36 22 simon111
                                "../test_dat/decrypt.in"
37 18 simon111
                               ,tt
38
                  );
39
 
40 35 simon111
        even_cw   = tt [ 8*8-1  : 0*8  ] ;
41
        odd_cw    = tt [16*8-1  : 8*8  ] ;
42 22 simon111
        out_bytes = 1;
43 18 simon111
 
44 35 simon111
        encrypted[188] = tt [204*8-1 :203*8 ] ;
45
        encrypted[187] = tt [203*8-1 :202*8 ] ;
46
        encrypted[186] = tt [202*8-1 :201*8 ] ;
47
        encrypted[185] = tt [201*8-1 :200*8 ] ;
48
        encrypted[184] = tt [200*8-1 :199*8 ] ;
49
        encrypted[183] = tt [199*8-1 :198*8 ] ;
50
        encrypted[182] = tt [198*8-1 :197*8 ] ;
51
        encrypted[181] = tt [197*8-1 :196*8 ] ;
52
        encrypted[180] = tt [196*8-1 :195*8 ] ;
53
        encrypted[179] = tt [195*8-1 :194*8 ] ;
54
        encrypted[178] = tt [194*8-1 :193*8 ] ;
55
        encrypted[177] = tt [193*8-1 :192*8 ] ;
56
        encrypted[176] = tt [192*8-1 :191*8 ] ;
57
        encrypted[175] = tt [191*8-1 :190*8 ] ;
58
        encrypted[174] = tt [190*8-1 :189*8 ] ;
59
        encrypted[173] = tt [189*8-1 :188*8 ] ;
60
        encrypted[172] = tt [188*8-1 :187*8 ] ;
61
        encrypted[171] = tt [187*8-1 :186*8 ] ;
62
        encrypted[170] = tt [186*8-1 :185*8 ] ;
63
        encrypted[169] = tt [185*8-1 :184*8 ] ;
64
        encrypted[168] = tt [184*8-1 :183*8 ] ;
65
        encrypted[167] = tt [183*8-1 :182*8 ] ;
66
        encrypted[166] = tt [182*8-1 :181*8 ] ;
67
        encrypted[165] = tt [181*8-1 :180*8 ] ;
68
        encrypted[164] = tt [180*8-1 :179*8 ] ;
69
        encrypted[163] = tt [179*8-1 :178*8 ] ;
70
        encrypted[162] = tt [178*8-1 :177*8 ] ;
71
        encrypted[161] = tt [177*8-1 :176*8 ] ;
72
        encrypted[160] = tt [176*8-1 :175*8 ] ;
73
        encrypted[159] = tt [175*8-1 :174*8 ] ;
74
        encrypted[158] = tt [174*8-1 :173*8 ] ;
75
        encrypted[157] = tt [173*8-1 :172*8 ] ;
76
        encrypted[156] = tt [172*8-1 :171*8 ] ;
77
        encrypted[155] = tt [171*8-1 :170*8 ] ;
78
        encrypted[154] = tt [170*8-1 :169*8 ] ;
79
        encrypted[153] = tt [169*8-1 :168*8 ] ;
80
        encrypted[152] = tt [168*8-1 :167*8 ] ;
81
        encrypted[151] = tt [167*8-1 :166*8 ] ;
82
        encrypted[150] = tt [166*8-1 :165*8 ] ;
83
        encrypted[149] = tt [165*8-1 :164*8 ] ;
84
        encrypted[148] = tt [164*8-1 :163*8 ] ;
85
        encrypted[147] = tt [163*8-1 :162*8 ] ;
86
        encrypted[146] = tt [162*8-1 :161*8 ] ;
87
        encrypted[145] = tt [161*8-1 :160*8 ] ;
88
        encrypted[144] = tt [160*8-1 :159*8 ] ;
89
        encrypted[143] = tt [159*8-1 :158*8 ] ;
90
        encrypted[142] = tt [158*8-1 :157*8 ] ;
91
        encrypted[141] = tt [157*8-1 :156*8 ] ;
92
        encrypted[140] = tt [156*8-1 :155*8 ] ;
93
        encrypted[139] = tt [155*8-1 :154*8 ] ;
94
        encrypted[138] = tt [154*8-1 :153*8 ] ;
95
        encrypted[137] = tt [153*8-1 :152*8 ] ;
96
        encrypted[136] = tt [152*8-1 :151*8 ] ;
97
        encrypted[135] = tt [151*8-1 :150*8 ] ;
98
        encrypted[134] = tt [150*8-1 :149*8 ] ;
99
        encrypted[133] = tt [149*8-1 :148*8 ] ;
100
        encrypted[132] = tt [148*8-1 :147*8 ] ;
101
        encrypted[131] = tt [147*8-1 :146*8 ] ;
102
        encrypted[130] = tt [146*8-1 :145*8 ] ;
103
        encrypted[129] = tt [145*8-1 :144*8 ] ;
104
        encrypted[128] = tt [144*8-1 :143*8 ] ;
105
        encrypted[127] = tt [143*8-1 :142*8 ] ;
106
        encrypted[126] = tt [142*8-1 :141*8 ] ;
107
        encrypted[125] = tt [141*8-1 :140*8 ] ;
108
        encrypted[124] = tt [140*8-1 :139*8 ] ;
109
        encrypted[123] = tt [139*8-1 :138*8 ] ;
110
        encrypted[122] = tt [138*8-1 :137*8 ] ;
111
        encrypted[121] = tt [137*8-1 :136*8 ] ;
112
        encrypted[120] = tt [136*8-1 :135*8 ] ;
113
        encrypted[119] = tt [135*8-1 :134*8 ] ;
114
        encrypted[118] = tt [134*8-1 :133*8 ] ;
115
        encrypted[117] = tt [133*8-1 :132*8 ] ;
116
        encrypted[116] = tt [132*8-1 :131*8 ] ;
117
        encrypted[115] = tt [131*8-1 :130*8 ] ;
118
        encrypted[114] = tt [130*8-1 :129*8 ] ;
119
        encrypted[113] = tt [129*8-1 :128*8 ] ;
120
        encrypted[112] = tt [128*8-1 :127*8 ] ;
121
        encrypted[111] = tt [127*8-1 :126*8 ] ;
122
        encrypted[110] = tt [126*8-1 :125*8 ] ;
123
        encrypted[109] = tt [125*8-1 :124*8 ] ;
124
        encrypted[108] = tt [124*8-1 :123*8 ] ;
125
        encrypted[107] = tt [123*8-1 :122*8 ] ;
126
        encrypted[106] = tt [122*8-1 :121*8 ] ;
127
        encrypted[105] = tt [121*8-1 :120*8 ] ;
128
        encrypted[104] = tt [120*8-1 :119*8 ] ;
129
        encrypted[103] = tt [119*8-1 :118*8 ] ;
130
        encrypted[102] = tt [118*8-1 :117*8 ] ;
131
        encrypted[101] = tt [117*8-1 :116*8 ] ;
132
        encrypted[100] = tt [116*8-1 :115*8 ] ;
133
        encrypted[ 99] = tt [115*8-1 :114*8 ] ;
134
        encrypted[ 98] = tt [114*8-1 :113*8 ] ;
135
        encrypted[ 97] = tt [113*8-1 :112*8 ] ;
136
        encrypted[ 96] = tt [112*8-1 :111*8 ] ;
137
        encrypted[ 95] = tt [111*8-1 :110*8 ] ;
138
        encrypted[ 94] = tt [110*8-1 :109*8 ] ;
139
        encrypted[ 93] = tt [109*8-1 :108*8 ] ;
140
        encrypted[ 92] = tt [108*8-1 :107*8 ] ;
141
        encrypted[ 91] = tt [107*8-1 :106*8 ] ;
142
        encrypted[ 90] = tt [106*8-1 :105*8 ] ;
143
        encrypted[ 89] = tt [105*8-1 :104*8 ] ;
144
        encrypted[ 88] = tt [104*8-1 :103*8 ] ;
145
        encrypted[ 87] = tt [103*8-1 :102*8 ] ;
146
        encrypted[ 86] = tt [102*8-1 :101*8 ] ;
147
        encrypted[ 85] = tt [101*8-1 :100*8 ] ;
148
        encrypted[ 84] = tt [100*8-1 : 99*8 ] ;
149
        encrypted[ 83] = tt [ 99*8-1 : 98*8 ] ;
150
        encrypted[ 82] = tt [ 98*8-1 : 97*8 ] ;
151
        encrypted[ 81] = tt [ 97*8-1 : 96*8 ] ;
152
        encrypted[ 80] = tt [ 96*8-1 : 95*8 ] ;
153
        encrypted[ 79] = tt [ 95*8-1 : 94*8 ] ;
154
        encrypted[ 78] = tt [ 94*8-1 : 93*8 ] ;
155
        encrypted[ 77] = tt [ 93*8-1 : 92*8 ] ;
156
        encrypted[ 76] = tt [ 92*8-1 : 91*8 ] ;
157
        encrypted[ 75] = tt [ 91*8-1 : 90*8 ] ;
158
        encrypted[ 74] = tt [ 90*8-1 : 89*8 ] ;
159
        encrypted[ 73] = tt [ 89*8-1 : 88*8 ] ;
160
        encrypted[ 72] = tt [ 88*8-1 : 87*8 ] ;
161
        encrypted[ 71] = tt [ 87*8-1 : 86*8 ] ;
162
        encrypted[ 70] = tt [ 86*8-1 : 85*8 ] ;
163
        encrypted[ 69] = tt [ 85*8-1 : 84*8 ] ;
164
        encrypted[ 68] = tt [ 84*8-1 : 83*8 ] ;
165
        encrypted[ 67] = tt [ 83*8-1 : 82*8 ] ;
166
        encrypted[ 66] = tt [ 82*8-1 : 81*8 ] ;
167
        encrypted[ 65] = tt [ 81*8-1 : 80*8 ] ;
168
        encrypted[ 64] = tt [ 80*8-1 : 79*8 ] ;
169
        encrypted[ 63] = tt [ 79*8-1 : 78*8 ] ;
170
        encrypted[ 62] = tt [ 78*8-1 : 77*8 ] ;
171
        encrypted[ 61] = tt [ 77*8-1 : 76*8 ] ;
172
        encrypted[ 60] = tt [ 76*8-1 : 75*8 ] ;
173
        encrypted[ 59] = tt [ 75*8-1 : 74*8 ] ;
174
        encrypted[ 58] = tt [ 74*8-1 : 73*8 ] ;
175
        encrypted[ 57] = tt [ 73*8-1 : 72*8 ] ;
176
        encrypted[ 56] = tt [ 72*8-1 : 71*8 ] ;
177
        encrypted[ 55] = tt [ 71*8-1 : 70*8 ] ;
178
        encrypted[ 54] = tt [ 70*8-1 : 69*8 ] ;
179
        encrypted[ 53] = tt [ 69*8-1 : 68*8 ] ;
180
        encrypted[ 52] = tt [ 68*8-1 : 67*8 ] ;
181
        encrypted[ 51] = tt [ 67*8-1 : 66*8 ] ;
182
        encrypted[ 50] = tt [ 66*8-1 : 65*8 ] ;
183
        encrypted[ 49] = tt [ 65*8-1 : 64*8 ] ;
184
        encrypted[ 48] = tt [ 64*8-1 : 63*8 ] ;
185
        encrypted[ 47] = tt [ 63*8-1 : 62*8 ] ;
186
        encrypted[ 46] = tt [ 62*8-1 : 61*8 ] ;
187
        encrypted[ 45] = tt [ 61*8-1 : 60*8 ] ;
188
        encrypted[ 44] = tt [ 60*8-1 : 59*8 ] ;
189
        encrypted[ 43] = tt [ 59*8-1 : 58*8 ] ;
190
        encrypted[ 42] = tt [ 58*8-1 : 57*8 ] ;
191
        encrypted[ 41] = tt [ 57*8-1 : 56*8 ] ;
192
        encrypted[ 40] = tt [ 56*8-1 : 55*8 ] ;
193
        encrypted[ 39] = tt [ 55*8-1 : 54*8 ] ;
194
        encrypted[ 38] = tt [ 54*8-1 : 53*8 ] ;
195
        encrypted[ 37] = tt [ 53*8-1 : 52*8 ] ;
196
        encrypted[ 36] = tt [ 52*8-1 : 51*8 ] ;
197
        encrypted[ 35] = tt [ 51*8-1 : 50*8 ] ;
198
        encrypted[ 34] = tt [ 50*8-1 : 49*8 ] ;
199
        encrypted[ 33] = tt [ 49*8-1 : 48*8 ] ;
200
        encrypted[ 32] = tt [ 48*8-1 : 47*8 ] ;
201
        encrypted[ 31] = tt [ 47*8-1 : 46*8 ] ;
202
        encrypted[ 30] = tt [ 46*8-1 : 45*8 ] ;
203
        encrypted[ 29] = tt [ 45*8-1 : 44*8 ] ;
204
        encrypted[ 28] = tt [ 44*8-1 : 43*8 ] ;
205
        encrypted[ 27] = tt [ 43*8-1 : 42*8 ] ;
206
        encrypted[ 26] = tt [ 42*8-1 : 41*8 ] ;
207
        encrypted[ 25] = tt [ 41*8-1 : 40*8 ] ;
208
        encrypted[ 24] = tt [ 40*8-1 : 39*8 ] ;
209
        encrypted[ 23] = tt [ 39*8-1 : 38*8 ] ;
210
        encrypted[ 22] = tt [ 38*8-1 : 37*8 ] ;
211
        encrypted[ 21] = tt [ 37*8-1 : 36*8 ] ;
212
        encrypted[ 20] = tt [ 36*8-1 : 35*8 ] ;
213
        encrypted[ 19] = tt [ 35*8-1 : 34*8 ] ;
214
        encrypted[ 18] = tt [ 34*8-1 : 33*8 ] ;
215
        encrypted[ 17] = tt [ 33*8-1 : 32*8 ] ;
216
        encrypted[ 16] = tt [ 32*8-1 : 31*8 ] ;
217
        encrypted[ 15] = tt [ 31*8-1 : 30*8 ] ;
218
        encrypted[ 14] = tt [ 30*8-1 : 29*8 ] ;
219
        encrypted[ 13] = tt [ 29*8-1 : 28*8 ] ;
220
        encrypted[ 12] = tt [ 28*8-1 : 27*8 ] ;
221
        encrypted[ 11] = tt [ 27*8-1 : 26*8 ] ;
222
        encrypted[ 10] = tt [ 26*8-1 : 25*8 ] ;
223
        encrypted[  9] = tt [ 25*8-1 : 24*8 ] ;
224
        encrypted[  8] = tt [ 24*8-1 : 23*8 ] ;
225
        encrypted[  7] = tt [ 23*8-1 : 22*8 ] ;
226
        encrypted[  6] = tt [ 22*8-1 : 21*8 ] ;
227
        encrypted[  5] = tt [ 21*8-1 : 20*8 ] ;
228
        encrypted[  4] = tt [ 20*8-1 : 19*8 ] ;
229
        encrypted[  3] = tt [ 19*8-1 : 18*8 ] ;
230
        encrypted[  2] = tt [ 18*8-1 : 17*8 ] ;
231
        encrypted[  1] = tt [ 17*8-1 : 16*8 ] ;
232 22 simon111
        en=0;
233
        key_en=0;
234
 
235 23 simon111
        repeat(14)@(posedge clk);
236 22 simon111
 
237
        // set even cw 
238
        @(posedge clk);
239
        ck=even_cw;
240
        en=0;
241
        even_odd=0;
242
        @(posedge clk);
243
        key_en=1;
244
        @(posedge clk);
245
        key_en=0;
246
        repeat (11) @(posedge clk);
247
 
248
        // set odd key
249
        @(posedge clk);
250
        ck=odd_cw;
251
        key_en=1;
252
        en=0;
253
        even_odd=1;
254
        @(posedge clk);
255
        key_en=0;
256
        repeat (11)@(posedge clk);
257
        repeat(4)@(posedge clk);
258
 
259
        // decrypt
260
        for(bytes=1;bytes<=188;bytes=bytes+1)
261
        begin
262
                en=1;
263
                enc=encrypted[bytes];
264
                @(posedge clk);
265
                en=0;
266
                @(posedge clk);
267
        end
268
 
269
        repeat(44) @(posedge clk);
270
 
271
        // output result
272 18 simon111
        $write_data(
273 22 simon111
                                 "../test_dat/decrypt.out.v"
274 18 simon111
                                ,"w"
275 22 simon111
                                ,decrypted[1]
276 18 simon111
                   );
277 22 simon111
        for(out_bytes=2;out_bytes<=188;out_bytes=out_bytes+1)
278
        begin
279
        $write_data(
280
                                 "../test_dat/decrypt.out.v"
281
                                ,"a"
282
                                ,decrypted[out_bytes]
283
                   );
284
        end
285
 
286
 
287
        $stop;
288 18 simon111
 
289
end
290
 
291 22 simon111
always @(posedge clk)
292
        if(invalid)
293
        begin
294
                decrypted[out_bytes]=dec;
295
                out_bytes=out_bytes+1;
296
        end
297
 
298
 
299 20 simon111
decrypt b(
300 22 simon111
                  .clk        (clk)
301
                , .rst        (rst)
302
                , .ck         (ck)
303
                , .key_en     (key_en)
304
                , .even_odd   (even_odd)
305
                , .en         (en)
306
                , .encrypted  (enc)
307
                , .decrypted  (dec)
308
                , .invalid    (invalid)
309 18 simon111
                );
310 22 simon111
 
311
 
312
 
313
`else
314
 
315
reg en;
316
reg init;
317
reg [8*8-1:0] ck;
318
reg [8*8-1:0] sb;
319
wire [8*8-1:0] cb;
320
 
321
initial
322
begin
323
        repeat (12)@(posedge clk);
324
        init=1'h1;
325
        en=1'h1;
326
        ck=64'hffffffffffffffff;
327
        sb=64'hffffffffffffffff;
328
        @(posedge clk);
329
        en=1'h0;
330
        @(posedge clk);
331
        en=1'h1;
332
        init=1'h0;
333
        @(posedge clk);
334
        en=1'h0;
335
        @(posedge clk);
336
        repeat(10)@(posedge clk);
337
        en=1'h1;
338
        @(posedge clk);
339
        en=1'h0;
340
        repeat(10)@(posedge clk);
341
 
342
        $stop;
343
 
344
end
345
 
346
stream_cypher sc(
347
                    .clk   (clk)
348
                  , .rst   (rst)
349
                  , .en    (en)
350
                  , .init  (init)
351
                  , .ck    (ck)
352
                  , .sb    (sb)
353
                  , .cb    (cb)
354
                  );
355
 
356
`endif
357
 
358
initial
359
begin
360
        clk<=1'b0;
361
        forever #5 clk=~clk;
362
end
363
 
364
initial
365
begin
366
        rst<=1'b1;
367
        @(posedge clk);
368
        @(posedge clk);
369
        rst=1'h0;
370
end
371 18 simon111
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.