OpenCores
URL https://opencores.org/ocsvn/aes-encryption/aes-encryption/trunk

Subversion Repositories aes-encryption

[/] [aes-encryption/] [trunk/] [aes_5cycle_2stage/] [aes_cipher_top.v] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 tariq786
/////////////////////////////////////////////////////////////////////
2
////                                                             ////
3
////  AES Cipher Top Level                                       ////
4
////                                                             ////
5
////                                                             ////
6
////  Author: Rudolf Usselmann                                   ////
7
////          rudi@asics.ws                                      ////
8
////                                                             ////
9
////                                                             ////
10
////  Downloaded from: http://www.opencores.org/cores/aes_core/  ////
11
////                                                             ////
12
/////////////////////////////////////////////////////////////////////
13
////                                                             ////
14
//// Copyright (C) 2000-2002 Rudolf Usselmann                    ////
15
////                         www.asics.ws                        ////
16
////                         rudi@asics.ws                       ////
17
////                                                             ////
18
//// This source file may be used and distributed without        ////
19
//// restriction provided that this copyright statement is not   ////
20
//// removed from the file and that any derivative work contains ////
21
//// the original copyright notice and the associated disclaimer.////
22
////                                                             ////
23
////     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ////
24
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ////
25
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ////
26
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ////
27
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ////
28
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ////
29
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ////
30
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ////
31
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ////
32
//// LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ////
33
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ////
34
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ////
35
//// POSSIBILITY OF SUCH DAMAGE.                                 ////
36
////                                                             ////
37
/////////////////////////////////////////////////////////////////////
38
 
39
//// Modified to achieve 5 cycles - stage  functionality             ////
40
//// By Tariq Bashir Ahmad                                                                       ////   
41
////  tariq.bashir@gmail.com                                                             ////
42
////  http://www.ecs.umass.edu/~tbashir                                          ////
43
 
44
 
45
 
46
`timescale 1 ns/1 ps
47
 
48 3 tariq786
module aes_cipher_top(clk, rst, ld, done, key, text_in, text_out);
49 2 tariq786
 
50
input           clk, rst;
51
input           ld;
52
output          done;
53
input   [127:0]  key;
54
input   [127:0]  text_in;
55
output  [127:0]  text_out;
56
 
57 3 tariq786
 
58 2 tariq786
////////////////////////////////////////////////////////////////////
59
//
60
// Local Wires
61
//
62
 
63
wire    [31:0]   w0, w1, w2, w3, w4, w5, w6, w7;
64
/*wire  [127:0] key_odd,key_even;
65
*/
66
reg     [127:0]  text_in_r;
67
reg     [127:0]  text_out;
68
 
69
reg     [127:0]  text_out_temp;
70
 
71
reg     [7:0]    sa00, sa01, sa02, sa03;
72
reg     [7:0]    sa10, sa11, sa12, sa13;
73
reg     [7:0]    sa20, sa21, sa22, sa23;
74
reg     [7:0]    sa30, sa31, sa32, sa33;
75
 
76
wire    [7:0]    sa00_next, sa01_next, sa02_next, sa03_next;
77
wire    [7:0]    sa10_next, sa11_next, sa12_next, sa13_next;
78
wire    [7:0]    sa20_next, sa21_next, sa22_next, sa23_next;
79
wire    [7:0]    sa30_next, sa31_next, sa32_next, sa33_next;
80
 
81
wire    [7:0]    sa00_sub, sa01_sub, sa02_sub, sa03_sub;
82
wire    [7:0]    sa10_sub, sa11_sub, sa12_sub, sa13_sub;
83
wire  [7:0]      sa20_sub, sa21_sub, sa22_sub, sa23_sub;
84
wire    [7:0]    sa30_sub, sa31_sub, sa32_sub, sa33_sub;
85
 
86
wire    [7:0]    sa00_sr, sa01_sr, sa02_sr, sa03_sr;
87
wire    [7:0]    sa10_sr, sa11_sr, sa12_sr, sa13_sr;
88
wire    [7:0]    sa20_sr, sa21_sr, sa22_sr, sa23_sr;
89
wire    [7:0]    sa30_sr, sa31_sr, sa32_sr, sa33_sr;
90
 
91
wire    [7:0]    sa00_mc, sa01_mc, sa02_mc, sa03_mc;
92
wire    [7:0]    sa10_mc, sa11_mc, sa12_mc, sa13_mc;
93
wire    [7:0]    sa20_mc, sa21_mc, sa22_mc, sa23_mc;
94
wire    [7:0]    sa30_mc, sa31_mc, sa32_mc, sa33_mc;
95
 
96
 
97
wire    [7:0]    sa00_next_round2, sa01_next_round2, sa02_next_round2, sa03_next_round2;
98
wire    [7:0]    sa10_next_round2, sa11_next_round2, sa12_next_round2, sa13_next_round2;
99
wire    [7:0]    sa20_next_round2, sa21_next_round2, sa22_next_round2, sa23_next_round2;
100
wire    [7:0]    sa30_next_round2, sa31_next_round2, sa32_next_round2, sa33_next_round2;
101
 
102
wire    [7:0]    sa00_sub_round2, sa01_sub_round2, sa02_sub_round2, sa03_sub_round2;
103
wire    [7:0]    sa10_sub_round2, sa11_sub_round2, sa12_sub_round2, sa13_sub_round2;
104
wire  [7:0]      sa20_sub_round2, sa21_sub_round2, sa22_sub_round2, sa23_sub_round2;
105
wire    [7:0]    sa30_sub_round2, sa31_sub_round2, sa32_sub_round2, sa33_sub_round2;
106
 
107
wire    [7:0]    sa00_sr_round2, sa01_sr_round2, sa02_sr_round2, sa03_sr_round2;
108
wire    [7:0]    sa10_sr_round2, sa11_sr_round2, sa12_sr_round2, sa13_sr_round2;
109
wire    [7:0]    sa20_sr_round2, sa21_sr_round2, sa22_sr_round2, sa23_sr_round2;
110
wire    [7:0]    sa30_sr_round2, sa31_sr_round2, sa32_sr_round2, sa33_sr_round2;
111
 
112
wire    [7:0]    sa00_mc_round2, sa01_mc_round2, sa02_mc_round2, sa03_mc_round2;
113
wire    [7:0]    sa10_mc_round2, sa11_mc_round2, sa12_mc_round2, sa13_mc_round2;
114
wire    [7:0]    sa20_mc_round2, sa21_mc_round2, sa22_mc_round2, sa23_mc_round2;
115
wire    [7:0]    sa30_mc_round2, sa31_mc_round2, sa32_mc_round2, sa33_mc_round2;
116
 
117
 
118
 
119
 
120
reg             done, ld_r;
121
reg     [3:0]    dcnt;
122
reg             done2;
123
 
124
////////////////////////////////////////////////////////////////////
125
//
126
// Misc Logic
127
//
128
 
129
always @(posedge clk)
130
begin
131 3 tariq786
        if(~rst)        begin dcnt <=  4'h0;     end
132 2 tariq786
        else
133
        if(ld)  begin   dcnt <=  4'h6;   end
134
        else
135
        if(|dcnt) begin dcnt <=  dcnt - 4'h1;  end
136
 
137
end
138
 
139
always @(posedge clk) done <=  !(|dcnt[3:1]) & dcnt[0] & !ld;
140
always @(posedge clk) if(ld) text_in_r <=  text_in;
141
always @(posedge clk) ld_r <=  ld;
142
 
143
 
144
 
145
////////////////////////////////////////////////////////////////////
146
// key expansion
147
 
148
 
149
aes_key_expand_128 u0(
150
        .clk(           clk     ),
151
        .kld(           ld_r    ),
152
        .key(           key     ),
153
        .w0(            w0      ),
154
        .w1(            w1      ),
155
        .w2(            w2      ),
156
        .w3(            w3      ),
157
        .w4_reg(                w4      ),
158
        .w5_reg(                w5      ),
159
        .w6_reg(                w6      ),
160
        .w7_reg(                w7      )
161
                                                        );
162
/*assign key_odd  = {w0,w1,w2,w3};
163
assign key_even = {w4,w5,w6,w7};
164
*/
165
 
166
/*assign {w0,w1,w2,w3} = 128'h0;
167
 
168
assign {w4,w5,w6,w7} = 128'h62636363626363636263636362636363;
169
*/
170
// Initial Permutation (AddRoundKey)
171
//
172
/*
173
always @(posedge clk)
174
begin
175
  w0 <= w0_net;
176
  w1 <= w1_net;
177
  w2 <= w2_net;
178
  w3 <= w3_net;
179
  w4 <= w4_net;
180
  w5 <= w5_net;
181
  w6 <= w6_net;
182
  w7 <= w7_net;
183
end
184
*/
185
always @(posedge clk)
186
begin
187
        sa33 <=  ld_r ? text_in_r[007:000] ^ w3[07:00] : sa33_mc_round2 ^ w3[07:00];
188
        sa23 <=  ld_r ? text_in_r[015:008] ^ w3[15:08] : sa23_mc_round2 ^ w3[15:08];
189
        sa13 <=  ld_r ? text_in_r[023:016] ^ w3[23:16] : sa13_mc_round2 ^ w3[23:16];
190
        sa03 <=  ld_r ? text_in_r[031:024] ^ w3[31:24] : sa03_mc_round2 ^ w3[31:24];
191
        sa32 <=  ld_r ? text_in_r[039:032] ^ w2[07:00] : sa32_mc_round2 ^ w2[07:00];
192
        sa22 <=  ld_r ? text_in_r[047:040] ^ w2[15:08] : sa22_mc_round2 ^ w2[15:08];
193
        sa12 <=  ld_r ? text_in_r[055:048] ^ w2[23:16] : sa12_mc_round2 ^ w2[23:16];
194
        sa02 <=  ld_r ? text_in_r[063:056] ^ w2[31:24] : sa02_mc_round2 ^ w2[31:24];
195
        sa31 <=  ld_r ? text_in_r[071:064] ^ w1[07:00] : sa31_mc_round2 ^ w1[07:00];
196
        sa21 <=  ld_r ? text_in_r[079:072] ^ w1[15:08] : sa21_mc_round2 ^ w1[15:08];
197
        sa11 <=  ld_r ? text_in_r[087:080] ^ w1[23:16] : sa11_mc_round2 ^ w1[23:16];
198
        sa01 <=  ld_r ? text_in_r[095:088] ^ w1[31:24] : sa01_mc_round2 ^ w1[31:24];
199
        sa30 <=  ld_r ? text_in_r[103:096] ^ w0[07:00] : sa30_mc_round2 ^ w0[07:00];
200
        sa20 <=  ld_r ? text_in_r[111:104] ^ w0[15:08] : sa20_mc_round2 ^ w0[15:08];
201
        sa10 <=  ld_r ? text_in_r[119:112] ^ w0[23:16] : sa10_mc_round2 ^ w0[23:16];
202
        sa00 <=  ld_r ? text_in_r[127:120] ^ w0[31:24] : sa00_mc_round2 ^ w0[31:24];
203
 
204
                /*$strobe($time,": roundkeyodd = %h\n",{w0,w1,w2,w3});
205
                $strobe($time,": state is %h\n",{sa00, sa01, sa02, sa03,
206
                                                                                                         sa10, sa11, sa12, sa13,
207
                                                                                                         sa20, sa21, sa22, sa23,
208
                                                                                                         sa30, sa31, sa32, sa33});*/
209
 
210
end
211
 
212
////////////////////////////////////////////////////////////////////
213
//
214
// Modules instantiation
215
//
216
 
217
//sbox lookup
218
aes_sbox us00(  .a(     sa00    ), .d(  sa00_sub        ));
219
aes_sbox us01(  .a(     sa01    ), .d(  sa01_sub        ));
220
aes_sbox us02(  .a(     sa02    ), .d(  sa02_sub        ));
221
aes_sbox us03(  .a(     sa03    ), .d(  sa03_sub        ));
222
aes_sbox us10(  .a(     sa10    ), .d(  sa10_sub        ));
223
aes_sbox us11(  .a(     sa11    ), .d(  sa11_sub        ));
224
aes_sbox us12(  .a(     sa12    ), .d(  sa12_sub        ));
225
aes_sbox us13(  .a(     sa13    ), .d(  sa13_sub        ));
226
aes_sbox us20(  .a(     sa20    ), .d(  sa20_sub        ));
227
aes_sbox us21(  .a(     sa21    ), .d(  sa21_sub        ));
228
aes_sbox us22(  .a(     sa22    ), .d(  sa22_sub        ));
229
aes_sbox us23(  .a(     sa23    ), .d(  sa23_sub        ));
230
aes_sbox us30(  .a(     sa30    ), .d(  sa30_sub        ));
231
aes_sbox us31(  .a(     sa31    ), .d(  sa31_sub        ));
232
aes_sbox us32(  .a(     sa32    ), .d(  sa32_sub        ));
233
aes_sbox us33(  .a(     sa33    ), .d(  sa33_sub        ));
234
 
235
////////////////////////////////////////////////////////////////////
236
//
237
// Round Permutations
238
//
239
 
240
assign sa00_sr = sa00_sub;              //
241
assign sa01_sr = sa01_sub;              //no shift
242
assign sa02_sr = sa02_sub;              //
243
assign sa03_sr = sa03_sub;              //
244
 
245
assign sa10_sr = sa11_sub;              //
246
assign sa11_sr = sa12_sub;              // left shift by 1
247
assign sa12_sr = sa13_sub;              //
248
assign sa13_sr = sa10_sub;              //
249
 
250
assign sa20_sr = sa22_sub;              //
251
assign sa21_sr = sa23_sub;              //      left shift by 2
252
assign sa22_sr = sa20_sub;              //
253
assign sa23_sr = sa21_sub;              //
254
 
255
assign sa30_sr = sa33_sub;              //
256
assign sa31_sr = sa30_sub;              // left shift by 3
257
assign sa32_sr = sa31_sub;              //
258
assign sa33_sr = sa32_sub;              //
259
 
260
// mix column operation
261
assign {sa00_mc, sa10_mc, sa20_mc, sa30_mc}  = mix_col(sa00_sr,sa10_sr,sa20_sr,sa30_sr);
262
assign {sa01_mc, sa11_mc, sa21_mc, sa31_mc}  = mix_col(sa01_sr,sa11_sr,sa21_sr,sa31_sr);
263
assign {sa02_mc, sa12_mc, sa22_mc, sa32_mc}  = mix_col(sa02_sr,sa12_sr,sa22_sr,sa32_sr);
264
assign {sa03_mc, sa13_mc, sa23_mc, sa33_mc}  = mix_col(sa03_sr,sa13_sr,sa23_sr,sa33_sr);
265
 
266
//// add round key
267
assign sa00_next_round2 = sa00_mc ^ w4[31:24];
268
assign sa01_next_round2 = sa01_mc ^ w5[31:24];
269
assign sa02_next_round2 = sa02_mc ^ w6[31:24];
270
assign sa03_next_round2 = sa03_mc ^ w7[31:24];
271
assign sa10_next_round2 = sa10_mc ^ w4[23:16];
272
assign sa11_next_round2 = sa11_mc ^ w5[23:16];
273
assign sa12_next_round2 = sa12_mc ^ w6[23:16];
274
assign sa13_next_round2 = sa13_mc ^ w7[23:16];
275
assign sa20_next_round2 = sa20_mc ^ w4[15:08];
276
assign sa21_next_round2 = sa21_mc ^ w5[15:08];
277
assign sa22_next_round2 = sa22_mc ^ w6[15:08];
278
assign sa23_next_round2 = sa23_mc ^ w7[15:08];
279
assign sa30_next_round2 = sa30_mc ^ w4[07:00];
280
assign sa31_next_round2 = sa31_mc ^ w5[07:00];
281
assign sa32_next_round2 = sa32_mc ^ w6[07:00];
282
assign sa33_next_round2 = sa33_mc ^ w7[07:00];
283
 
284
 
285
always @(posedge clk)
286
begin
287
 
288
         /* $strobe($time,": roundkeyodd = %h, text_out_odd is %h\n",{w0,w1,w2,w3},text_out_temp);
289
          $strobe($time,": roundkeyeven is %h\n",{w4,w5,w6,w7});        */
290
          text_out_temp[127:120] <=  sa00_sr ^ w4[31:24];
291
          text_out_temp[095:088] <=  sa01_sr ^ w5[31:24];
292 3 tariq786
          text_out_temp[063:056] <=  sa02_sr ^ w6[31:24];
293 2 tariq786
          text_out_temp[031:024] <=  sa03_sr ^ w7[31:24];
294
          text_out_temp[119:112] <=  sa10_sr ^ w4[23:16];
295
          text_out_temp[087:080] <=  sa11_sr ^ w5[23:16];
296
          text_out_temp[055:048] <=  sa12_sr ^ w6[23:16];
297
          text_out_temp[023:016] <=  sa13_sr ^ w7[23:16];
298
          text_out_temp[111:104] <=  sa20_sr ^ w4[15:08];
299
          text_out_temp[079:072] <=  sa21_sr ^ w5[15:08];
300
          text_out_temp[047:040] <=  sa22_sr ^ w6[15:08];
301
          text_out_temp[015:008] <=  sa23_sr ^ w7[15:08];
302
          text_out_temp[103:096] <=  sa30_sr ^ w4[07:00];
303
          text_out_temp[071:064] <=  sa31_sr ^ w5[07:00];
304
          text_out_temp[039:032] <=  sa32_sr ^ w6[07:00];
305
          text_out_temp[007:000] <=  sa33_sr ^ w7[07:00];
306
end
307
 
308
 
309
 
310
 
311
//////////////////////  round i + 1 //////////////////////////////////
312
//sbox lookup
313
aes_sbox us00_round2(   .a(     sa00_next_round2        ), .d(  sa00_sub_round2 ));
314
aes_sbox us01_round2(   .a(     sa01_next_round2        ), .d(  sa01_sub_round2 ));
315
aes_sbox us02_round2(   .a(     sa02_next_round2        ), .d(  sa02_sub_round2 ));
316
aes_sbox us03_round2(   .a(     sa03_next_round2        ), .d(  sa03_sub_round2 ));
317
aes_sbox us10_round2(   .a(     sa10_next_round2        ), .d(  sa10_sub_round2 ));
318
aes_sbox us11_round2(   .a(     sa11_next_round2        ), .d(  sa11_sub_round2 ));
319
aes_sbox us12_round2(   .a(     sa12_next_round2        ), .d(  sa12_sub_round2 ));
320
aes_sbox us13_round2(   .a(     sa13_next_round2        ), .d(  sa13_sub_round2 ));
321
aes_sbox us20_round2(   .a(     sa20_next_round2        ), .d(  sa20_sub_round2 ));
322
aes_sbox us21_round2(   .a(     sa21_next_round2        ), .d(  sa21_sub_round2 ));
323
aes_sbox us22_round2(   .a(     sa22_next_round2        ), .d(  sa22_sub_round2 ));
324
aes_sbox us23_round2(   .a(     sa23_next_round2        ), .d(  sa23_sub_round2 ));
325
aes_sbox us30_round2(   .a(     sa30_next_round2        ), .d(  sa30_sub_round2 ));
326
aes_sbox us31_round2(   .a(     sa31_next_round2        ), .d(  sa31_sub_round2 ));
327
aes_sbox us32_round2(   .a(     sa32_next_round2        ), .d(  sa32_sub_round2 ));
328
aes_sbox us33_round2(   .a(     sa33_next_round2        ), .d(  sa33_sub_round2 ));
329
 
330
 
331
// Round Permutations
332
//
333
 
334
assign sa00_sr_round2 = sa00_sub_round2;                //
335
assign sa01_sr_round2 = sa01_sub_round2;                //no shift
336
assign sa02_sr_round2 = sa02_sub_round2;                //
337
assign sa03_sr_round2 = sa03_sub_round2;                //
338
 
339
assign sa10_sr_round2 = sa11_sub_round2;                //
340
assign sa11_sr_round2 = sa12_sub_round2;                // left shift by 1
341
assign sa12_sr_round2 = sa13_sub_round2;                //
342
assign sa13_sr_round2 = sa10_sub_round2;                //
343
 
344
assign sa20_sr_round2 = sa22_sub_round2;                //
345
assign sa21_sr_round2 = sa23_sub_round2;                //      left shift by 2
346
assign sa22_sr_round2 = sa20_sub_round2;                //
347
assign sa23_sr_round2 = sa21_sub_round2;                //
348
 
349
assign sa30_sr_round2 = sa33_sub_round2;                //
350
assign sa31_sr_round2 = sa30_sub_round2;                // left shift by 3
351
assign sa32_sr_round2 = sa31_sub_round2;                //
352
assign sa33_sr_round2 = sa32_sub_round2;                //
353
 
354
// mix column operation
355
assign {sa00_mc_round2, sa10_mc_round2, sa20_mc_round2, sa30_mc_round2}  = mix_col(sa00_sr_round2,sa10_sr_round2,sa20_sr_round2,sa30_sr_round2);
356
assign {sa01_mc_round2, sa11_mc_round2, sa21_mc_round2, sa31_mc_round2}  = mix_col(sa01_sr_round2,sa11_sr_round2,sa21_sr_round2,sa31_sr_round2);
357
assign {sa02_mc_round2, sa12_mc_round2, sa22_mc_round2, sa32_mc_round2}  = mix_col(sa02_sr_round2,sa12_sr_round2,sa22_sr_round2,sa32_sr_round2);
358
assign {sa03_mc_round2, sa13_mc_round2, sa23_mc_round2, sa33_mc_round2}  = mix_col(sa03_sr_round2,sa13_sr_round2,sa23_sr_round2,sa33_sr_round2);
359
 
360
////////////////////////////////////////////////////////////////////
361
//
362
// Final text output
363
//
364
 
365
 
366
always @(posedge clk)
367
 begin
368
                /*  $strobe($time,": round_key2 is %h\n",{w4,w5,w6,w7});
369
                  $strobe($time,": roundkeyeven = %h, text_out_even is %h\n",{w4,w5,w6,w7},text_out);*/
370
                  text_out[127:120] <=  sa00_sr_round2 ^ w0[31:24];
371
                  text_out[095:088] <=  sa01_sr_round2 ^ w1[31:24];
372
                  text_out[063:056] <=  sa02_sr_round2 ^ w2[31:24];
373
                  text_out[031:024] <=  sa03_sr_round2 ^ w3[31:24];
374
                  text_out[119:112] <=  sa10_sr_round2 ^ w0[23:16];
375
                  text_out[087:080] <=  sa11_sr_round2 ^ w1[23:16];
376
                  text_out[055:048] <=  sa12_sr_round2 ^ w2[23:16];
377
                  text_out[023:016] <=  sa13_sr_round2 ^ w3[23:16];
378
                  text_out[111:104] <=  sa20_sr_round2 ^ w0[15:08];
379
                  text_out[079:072] <=  sa21_sr_round2 ^ w1[15:08];
380
                  text_out[047:040] <=  sa22_sr_round2 ^ w2[15:08];
381
                  text_out[015:008] <=  sa23_sr_round2 ^ w3[15:08];
382
                  text_out[103:096] <=  sa30_sr_round2 ^ w0[07:00];
383
                  text_out[071:064] <=  sa31_sr_round2 ^ w1[07:00];
384
                  text_out[039:032] <=  sa32_sr_round2 ^ w2[07:00];
385
                  text_out[007:000] <=  sa33_sr_round2 ^ w3[07:00];
386
        end
387
 
388
 
389 3 tariq786
/* -----\/----- EXCLUDED -----\/-----
390 2 tariq786
always @(posedge clk)
391
        begin
392 3 tariq786
/-*     $strobe($time,": text_out_temp is %h\n",text_out_temp);
393 2 tariq786
 
394
 
395 3 tariq786
*-/     /-*
396 2 tariq786
        $strobe($time,": subbytes is %h\n",{sa00_sub, sa01_sub, sa02_sub, sa03_sub,
397
                                                                                                         sa10_sub, sa11_sub, sa12_sub, sa13_sub,
398
                                                                                                         sa20_sub, sa21_sub, sa22_sub, sa23_sub,
399
                                                                                                         sa30_sub, sa31_sub, sa32_sub, sa33_sub});
400
 
401
        $strobe($time,": shiftrows is %h\n",{sa00_sr, sa01_sr, sa02_sr, sa03_sr,
402
                                                                                                          sa10_sr, sa11_sr, sa12_sr, sa13_sr,
403
                                                                                                          sa20_sr, sa21_sr, sa22_sr, sa23_sr,
404
                                                                                                          sa30_sr, sa31_sr, sa32_sr, sa33_sr});
405
 
406
        $strobe($time,": mixcolumn is %h\n",{sa00_mc, sa01_mc, sa02_mc, sa03_mc,
407
                                                                                                          sa10_mc, sa11_mc, sa12_mc, sa13_mc,
408
                                                                                                          sa20_mc, sa21_mc, sa22_mc, sa23_mc,
409
                                                                                                          sa30_mc, sa31_mc, sa32_mc, sa33_mc});
410
 
411
        $strobe($time,": sa_next_into_even is %h\n",{sa00_next_round2, sa01_next_round2, sa02_next_round2, sa03_next_round2,
412
                                                                                                                                 sa10_next_round2, sa11_next_round2, sa12_next_round2, sa13_next_round2,
413
                                                                                                                                 sa20_next_round2, sa21_next_round2, sa22_next_round2, sa23_next_round2,
414
                                                                                                                                 sa30_next_round2, sa31_next_round2, sa32_next_round2, sa33_next_round2});
415
 
416
        $strobe($time,": subbytes_e is %h\n",{sa00_sub_round2, sa01_sub_round2, sa02_sub_round2, sa03_sub_round2,
417
                                                                                                         sa10_sub_round2, sa11_sub_round2, sa12_sub_round2, sa13_sub_round2,
418
                                                                                                         sa20_sub_round2, sa21_sub_round2, sa22_sub_round2, sa23_sub_round2,
419
                                                                                                         sa30_sub_round2, sa31_sub_round2, sa32_sub_round2, sa33_sub_round2});
420
 
421
        $strobe($time,": shiftrows_e is %h\n",{sa00_sr_round2, sa01_sr_round2, sa02_sr_round2, sa03_sr_round2,
422
                                                                                                          sa10_sr_round2, sa11_sr_round2, sa12_sr_round2, sa13_sr_round2,
423
                                                                                                          sa20_sr_round2, sa21_sr_round2, sa22_sr_round2, sa23_sr_round2,
424
                                                                                                          sa30_sr_round2, sa31_sr_round2, sa32_sr_round2, sa33_sr_round2});
425
 
426
        $strobe($time,": mixcolumn_e is %h\n",{sa00_mc_round2, sa01_mc_round2, sa02_mc_round2, sa03_mc_round2,
427
                                                                                                          sa10_mc_round2, sa11_mc_round2, sa12_mc_round2, sa13_mc_round2,
428
                                                                                                          sa20_mc_round2, sa21_mc_round2, sa22_mc_round2, sa23_mc_round2,
429
                                                                                                          sa30_mc_round2, sa31_mc_round2, sa32_mc_round2, sa33_mc_round2});
430 3 tariq786
        *-/
431 2 tariq786
        end
432
 
433
 
434 3 tariq786
/-*
435 2 tariq786
always @(posedge clk)
436
       begin
437
                                if(done)
438
                                                begin
439
                                                        text_out_64 <= text_out[127:64];
440
//                                                      done2 <= 1;
441
                                                end
442
                                else if(~done)
443
                                                        text_out_64 <= text_out[63:0];
444
                end
445 3 tariq786
        *-/
446 2 tariq786
 
447 3 tariq786
/-*
448 2 tariq786
always @(posedge clk)
449
                         begin
450
                                if(done2)
451
                                        begin
452
                                                text_out_64 <= text_out[63:0];
453
                                        end
454
                 end
455 3 tariq786
*-/
456
 -----/\----- EXCLUDED -----/\----- */
457 2 tariq786
////////////////////////////////////////////////////////////////////
458
//
459
// Generic Functions
460
//
461
 
462
function [31:0] mix_col;
463
input   [7:0]    s0,s1,s2,s3;
464
//reg   [7:0]   s0_o,s1_o,s2_o,s3_o;
465
begin
466
mix_col[31:24]=xtime(s0)^xtime(s1)^s1^s2^s3;
467
mix_col[23:16]=s0^xtime(s1)^xtime(s2)^s2^s3;
468
mix_col[15:08]=s0^s1^xtime(s2)^xtime(s3)^s3;
469
mix_col[07:00]=xtime(s0)^s0^s1^s2^xtime(s3);
470
end
471
endfunction
472
 
473
function [7:0] xtime;
474
input [7:0] b; xtime={b[6:0],1'b0}^(8'h1b&{8{b[7]}});
475
endfunction
476
 
477
 
478
 
479
endmodule
480
 
481
 
482
 

powered by: WebSVN 2.1.0

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