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

Subversion Repositories aes-encryption

[/] [aes-encryption/] [trunk/] [aes_1cycle_1stage/] [aes_cipher_top.v] - Blame information for rev 2

Go to most recent revision | 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 1 cycle 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
module aes_cipher_top(clk, rst, ld, done, key, text_in, text_out,aes_en);
49
 
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
input aes_en;
58
 
59
reg     [127:0]  text_in_r;
60
reg     [127:0]  text_out;
61
 
62
////////////////////////////////////////////////////////////////////
63
//
64
// Local Wires
65
//
66
 
67
wire    [31:0]   w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14, w15, w16, w17, w18, w19, w20, w21, w22,
68
               w23, w24, w25, w26, w27, w28, w29, w30, w31, w32, w33, w34, w35, w36, w37, w38, w39, w40, w41, w42, w43;
69
 
70
reg     [127:0]  text_out_temp;
71
 
72
//round 1 wires
73
reg     [7:0]    sa00, sa01, sa02, sa03;
74
reg     [7:0]    sa10, sa11, sa12, sa13;
75
reg     [7:0]    sa20, sa21, sa22, sa23;
76
reg     [7:0]    sa30, sa31, sa32, sa33;
77
 
78
wire    [7:0]    sa00_next, sa01_next, sa02_next, sa03_next;
79
wire    [7:0]    sa10_next, sa11_next, sa12_next, sa13_next;
80
wire    [7:0]    sa20_next, sa21_next, sa22_next, sa23_next;
81
wire    [7:0]    sa30_next, sa31_next, sa32_next, sa33_next;
82
 
83
wire    [7:0]    sa00_sub, sa01_sub, sa02_sub, sa03_sub;
84
wire    [7:0]    sa10_sub, sa11_sub, sa12_sub, sa13_sub;
85
wire  [7:0]      sa20_sub, sa21_sub, sa22_sub, sa23_sub;
86
wire    [7:0]    sa30_sub, sa31_sub, sa32_sub, sa33_sub;
87
 
88
wire    [7:0]    sa00_sr, sa01_sr, sa02_sr, sa03_sr;
89
wire    [7:0]    sa10_sr, sa11_sr, sa12_sr, sa13_sr;
90
wire    [7:0]    sa20_sr, sa21_sr, sa22_sr, sa23_sr;
91
wire    [7:0]    sa30_sr, sa31_sr, sa32_sr, sa33_sr;
92
 
93
wire    [7:0]    sa00_mc, sa01_mc, sa02_mc, sa03_mc;
94
wire    [7:0]    sa10_mc, sa11_mc, sa12_mc, sa13_mc;
95
wire    [7:0]    sa20_mc, sa21_mc, sa22_mc, sa23_mc;
96
wire    [7:0]    sa30_mc, sa31_mc, sa32_mc, sa33_mc;
97
 
98
 
99
//round2 wires
100
wire    [7:0]    sa00_next_round2, sa01_next_round2, sa02_next_round2, sa03_next_round2;
101
wire    [7:0]    sa10_next_round2, sa11_next_round2, sa12_next_round2, sa13_next_round2;
102
wire    [7:0]    sa20_next_round2, sa21_next_round2, sa22_next_round2, sa23_next_round2;
103
wire    [7:0]    sa30_next_round2, sa31_next_round2, sa32_next_round2, sa33_next_round2;
104
 
105
wire    [7:0]    sa00_sub_round2, sa01_sub_round2, sa02_sub_round2, sa03_sub_round2;
106
wire    [7:0]    sa10_sub_round2, sa11_sub_round2, sa12_sub_round2, sa13_sub_round2;
107
wire  [7:0]      sa20_sub_round2, sa21_sub_round2, sa22_sub_round2, sa23_sub_round2;
108
wire    [7:0]    sa30_sub_round2, sa31_sub_round2, sa32_sub_round2, sa33_sub_round2;
109
 
110
wire    [7:0]    sa00_sr_round2, sa01_sr_round2, sa02_sr_round2, sa03_sr_round2;
111
wire    [7:0]    sa10_sr_round2, sa11_sr_round2, sa12_sr_round2, sa13_sr_round2;
112
wire    [7:0]    sa20_sr_round2, sa21_sr_round2, sa22_sr_round2, sa23_sr_round2;
113
wire    [7:0]    sa30_sr_round2, sa31_sr_round2, sa32_sr_round2, sa33_sr_round2;
114
 
115
wire    [7:0]    sa00_mc_round2, sa01_mc_round2, sa02_mc_round2, sa03_mc_round2;
116
wire    [7:0]    sa10_mc_round2, sa11_mc_round2, sa12_mc_round2, sa13_mc_round2;
117
wire    [7:0]    sa20_mc_round2, sa21_mc_round2, sa22_mc_round2, sa23_mc_round2;
118
wire    [7:0]    sa30_mc_round2, sa31_mc_round2, sa32_mc_round2, sa33_mc_round2;
119
 
120
 
121
//round3 wires
122
wire    [7:0]    sa00_next_round3, sa01_next_round3, sa02_next_round3, sa03_next_round3;
123
wire    [7:0]    sa10_next_round3, sa11_next_round3, sa12_next_round3, sa13_next_round3;
124
wire    [7:0]    sa20_next_round3, sa21_next_round3, sa22_next_round3, sa23_next_round3;
125
wire    [7:0]    sa30_next_round3, sa31_next_round3, sa32_next_round3, sa33_next_round3;
126
 
127
wire    [7:0]    sa00_sub_round3, sa01_sub_round3, sa02_sub_round3, sa03_sub_round3;
128
wire    [7:0]    sa10_sub_round3, sa11_sub_round3, sa12_sub_round3, sa13_sub_round3;
129
wire  [7:0]      sa20_sub_round3, sa21_sub_round3, sa22_sub_round3, sa23_sub_round3;
130
wire    [7:0]    sa30_sub_round3, sa31_sub_round3, sa32_sub_round3, sa33_sub_round3;
131
 
132
wire    [7:0]    sa00_sr_round3, sa01_sr_round3, sa02_sr_round3, sa03_sr_round3;
133
wire    [7:0]    sa10_sr_round3, sa11_sr_round3, sa12_sr_round3, sa13_sr_round3;
134
wire    [7:0]    sa20_sr_round3, sa21_sr_round3, sa22_sr_round3, sa23_sr_round3;
135
wire    [7:0]    sa30_sr_round3, sa31_sr_round3, sa32_sr_round3, sa33_sr_round3;
136
 
137
wire    [7:0]    sa00_mc_round3, sa01_mc_round3, sa02_mc_round3, sa03_mc_round3;
138
wire    [7:0]    sa10_mc_round3, sa11_mc_round3, sa12_mc_round3, sa13_mc_round3;
139
wire    [7:0]    sa20_mc_round3, sa21_mc_round3, sa22_mc_round3, sa23_mc_round3;
140
wire    [7:0]    sa30_mc_round3, sa31_mc_round3, sa32_mc_round3, sa33_mc_round3;
141
 
142
 
143
 
144
//round4 wires
145
wire    [7:0]    sa00_next_round4, sa01_next_round4, sa02_next_round4, sa03_next_round4;
146
wire    [7:0]    sa10_next_round4, sa11_next_round4, sa12_next_round4, sa13_next_round4;
147
wire    [7:0]    sa20_next_round4, sa21_next_round4, sa22_next_round4, sa23_next_round4;
148
wire    [7:0]    sa30_next_round4, sa31_next_round4, sa32_next_round4, sa33_next_round4;
149
 
150
wire    [7:0]    sa00_sub_round4, sa01_sub_round4, sa02_sub_round4, sa03_sub_round4;
151
wire    [7:0]    sa10_sub_round4, sa11_sub_round4, sa12_sub_round4, sa13_sub_round4;
152
wire  [7:0]      sa20_sub_round4, sa21_sub_round4, sa22_sub_round4, sa23_sub_round4;
153
wire    [7:0]    sa30_sub_round4, sa31_sub_round4, sa32_sub_round4, sa33_sub_round4;
154
 
155
wire    [7:0]    sa00_sr_round4, sa01_sr_round4, sa02_sr_round4, sa03_sr_round4;
156
wire    [7:0]    sa10_sr_round4, sa11_sr_round4, sa12_sr_round4, sa13_sr_round4;
157
wire    [7:0]    sa20_sr_round4, sa21_sr_round4, sa22_sr_round4, sa23_sr_round4;
158
wire    [7:0]    sa30_sr_round4, sa31_sr_round4, sa32_sr_round4, sa33_sr_round4;
159
 
160
wire    [7:0]    sa00_mc_round4, sa01_mc_round4, sa02_mc_round4, sa03_mc_round4;
161
wire    [7:0]    sa10_mc_round4, sa11_mc_round4, sa12_mc_round4, sa13_mc_round4;
162
wire    [7:0]    sa20_mc_round4, sa21_mc_round4, sa22_mc_round4, sa23_mc_round4;
163
wire    [7:0]    sa30_mc_round4, sa31_mc_round4, sa32_mc_round4, sa33_mc_round4;
164
 
165
//round5 wires
166
wire    [7:0]    sa00_next_round5, sa01_next_round5, sa02_next_round5, sa03_next_round5;
167
wire    [7:0]    sa10_next_round5, sa11_next_round5, sa12_next_round5, sa13_next_round5;
168
wire    [7:0]    sa20_next_round5, sa21_next_round5, sa22_next_round5, sa23_next_round5;
169
wire    [7:0]    sa30_next_round5, sa31_next_round5, sa32_next_round5, sa33_next_round5;
170
 
171
wire    [7:0]    sa00_sub_round5, sa01_sub_round5, sa02_sub_round5, sa03_sub_round5;
172
wire    [7:0]    sa10_sub_round5, sa11_sub_round5, sa12_sub_round5, sa13_sub_round5;
173
wire  [7:0]      sa20_sub_round5, sa21_sub_round5, sa22_sub_round5, sa23_sub_round5;
174
wire    [7:0]    sa30_sub_round5, sa31_sub_round5, sa32_sub_round5, sa33_sub_round5;
175
 
176
wire    [7:0]    sa00_sr_round5, sa01_sr_round5, sa02_sr_round5, sa03_sr_round5;
177
wire    [7:0]    sa10_sr_round5, sa11_sr_round5, sa12_sr_round5, sa13_sr_round5;
178
wire    [7:0]    sa20_sr_round5, sa21_sr_round5, sa22_sr_round5, sa23_sr_round5;
179
wire    [7:0]    sa30_sr_round5, sa31_sr_round5, sa32_sr_round5, sa33_sr_round5;
180
 
181
wire    [7:0]    sa00_mc_round5, sa01_mc_round5, sa02_mc_round5, sa03_mc_round5;
182
wire    [7:0]    sa10_mc_round5, sa11_mc_round5, sa12_mc_round5, sa13_mc_round5;
183
wire    [7:0]    sa20_mc_round5, sa21_mc_round5, sa22_mc_round5, sa23_mc_round5;
184
wire    [7:0]    sa30_mc_round5, sa31_mc_round5, sa32_mc_round5, sa33_mc_round5;
185
 
186
 
187
//round6 wires
188
wire    [7:0]    sa00_next_round6, sa01_next_round6, sa02_next_round6, sa03_next_round6;
189
wire    [7:0]    sa10_next_round6, sa11_next_round6, sa12_next_round6, sa13_next_round6;
190
wire    [7:0]    sa20_next_round6, sa21_next_round6, sa22_next_round6, sa23_next_round6;
191
wire    [7:0]    sa30_next_round6, sa31_next_round6, sa32_next_round6, sa33_next_round6;
192
 
193
wire    [7:0]    sa00_sub_round6, sa01_sub_round6, sa02_sub_round6, sa03_sub_round6;
194
wire    [7:0]    sa10_sub_round6, sa11_sub_round6, sa12_sub_round6, sa13_sub_round6;
195
wire  [7:0]      sa20_sub_round6, sa21_sub_round6, sa22_sub_round6, sa23_sub_round6;
196
wire    [7:0]    sa30_sub_round6, sa31_sub_round6, sa32_sub_round6, sa33_sub_round6;
197
 
198
wire    [7:0]    sa00_sr_round6, sa01_sr_round6, sa02_sr_round6, sa03_sr_round6;
199
wire    [7:0]    sa10_sr_round6, sa11_sr_round6, sa12_sr_round6, sa13_sr_round6;
200
wire    [7:0]    sa20_sr_round6, sa21_sr_round6, sa22_sr_round6, sa23_sr_round6;
201
wire    [7:0]    sa30_sr_round6, sa31_sr_round6, sa32_sr_round6, sa33_sr_round6;
202
 
203
wire    [7:0]    sa00_mc_round6, sa01_mc_round6, sa02_mc_round6, sa03_mc_round6;
204
wire    [7:0]    sa10_mc_round6, sa11_mc_round6, sa12_mc_round6, sa13_mc_round6;
205
wire    [7:0]    sa20_mc_round6, sa21_mc_round6, sa22_mc_round6, sa23_mc_round6;
206
wire    [7:0]    sa30_mc_round6, sa31_mc_round6, sa32_mc_round6, sa33_mc_round6;
207
 
208
 
209
//round7 wires
210
wire    [7:0]    sa00_next_round7, sa01_next_round7, sa02_next_round7, sa03_next_round7;
211
wire    [7:0]    sa10_next_round7, sa11_next_round7, sa12_next_round7, sa13_next_round7;
212
wire    [7:0]    sa20_next_round7, sa21_next_round7, sa22_next_round7, sa23_next_round7;
213
wire    [7:0]    sa30_next_round7, sa31_next_round7, sa32_next_round7, sa33_next_round7;
214
 
215
wire    [7:0]    sa00_sub_round7, sa01_sub_round7, sa02_sub_round7, sa03_sub_round7;
216
wire    [7:0]    sa10_sub_round7, sa11_sub_round7, sa12_sub_round7, sa13_sub_round7;
217
wire  [7:0]      sa20_sub_round7, sa21_sub_round7, sa22_sub_round7, sa23_sub_round7;
218
wire    [7:0]    sa30_sub_round7, sa31_sub_round7, sa32_sub_round7, sa33_sub_round7;
219
 
220
wire    [7:0]    sa00_sr_round7, sa01_sr_round7, sa02_sr_round7, sa03_sr_round7;
221
wire    [7:0]    sa10_sr_round7, sa11_sr_round7, sa12_sr_round7, sa13_sr_round7;
222
wire    [7:0]    sa20_sr_round7, sa21_sr_round7, sa22_sr_round7, sa23_sr_round7;
223
wire    [7:0]    sa30_sr_round7, sa31_sr_round7, sa32_sr_round7, sa33_sr_round7;
224
 
225
wire    [7:0]    sa00_mc_round7, sa01_mc_round7, sa02_mc_round7, sa03_mc_round7;
226
wire    [7:0]    sa10_mc_round7, sa11_mc_round7, sa12_mc_round7, sa13_mc_round7;
227
wire    [7:0]    sa20_mc_round7, sa21_mc_round7, sa22_mc_round7, sa23_mc_round7;
228
wire    [7:0]    sa30_mc_round7, sa31_mc_round7, sa32_mc_round7, sa33_mc_round7;
229
 
230
 
231
//round8 wires
232
wire    [7:0]    sa00_next_round8, sa01_next_round8, sa02_next_round8, sa03_next_round8;
233
wire    [7:0]    sa10_next_round8, sa11_next_round8, sa12_next_round8, sa13_next_round8;
234
wire    [7:0]    sa20_next_round8, sa21_next_round8, sa22_next_round8, sa23_next_round8;
235
wire    [7:0]    sa30_next_round8, sa31_next_round8, sa32_next_round8, sa33_next_round8;
236
 
237
wire    [7:0]    sa00_sub_round8, sa01_sub_round8, sa02_sub_round8, sa03_sub_round8;
238
wire    [7:0]    sa10_sub_round8, sa11_sub_round8, sa12_sub_round8, sa13_sub_round8;
239
wire  [7:0]      sa20_sub_round8, sa21_sub_round8, sa22_sub_round8, sa23_sub_round8;
240
wire    [7:0]    sa30_sub_round8, sa31_sub_round8, sa32_sub_round8, sa33_sub_round8;
241
 
242
wire    [7:0]    sa00_sr_round8, sa01_sr_round8, sa02_sr_round8, sa03_sr_round8;
243
wire    [7:0]    sa10_sr_round8, sa11_sr_round8, sa12_sr_round8, sa13_sr_round8;
244
wire    [7:0]    sa20_sr_round8, sa21_sr_round8, sa22_sr_round8, sa23_sr_round8;
245
wire    [7:0]    sa30_sr_round8, sa31_sr_round8, sa32_sr_round8, sa33_sr_round8;
246
 
247
wire    [7:0]    sa00_mc_round8, sa01_mc_round8, sa02_mc_round8, sa03_mc_round8;
248
wire    [7:0]    sa10_mc_round8, sa11_mc_round8, sa12_mc_round8, sa13_mc_round8;
249
wire    [7:0]    sa20_mc_round8, sa21_mc_round8, sa22_mc_round8, sa23_mc_round8;
250
wire    [7:0]    sa30_mc_round8, sa31_mc_round8, sa32_mc_round8, sa33_mc_round8;
251
 
252
 
253
//round9 wires
254
wire    [7:0]    sa00_next_round9, sa01_next_round9, sa02_next_round9, sa03_next_round9;
255
wire    [7:0]    sa10_next_round9, sa11_next_round9, sa12_next_round9, sa13_next_round9;
256
wire    [7:0]    sa20_next_round9, sa21_next_round9, sa22_next_round9, sa23_next_round9;
257
wire    [7:0]    sa30_next_round9, sa31_next_round9, sa32_next_round9, sa33_next_round9;
258
 
259
wire    [7:0]    sa00_sub_round9, sa01_sub_round9, sa02_sub_round9, sa03_sub_round9;
260
wire    [7:0]    sa10_sub_round9, sa11_sub_round9, sa12_sub_round9, sa13_sub_round9;
261
wire  [7:0]      sa20_sub_round9, sa21_sub_round9, sa22_sub_round9, sa23_sub_round9;
262
wire    [7:0]    sa30_sub_round9, sa31_sub_round9, sa32_sub_round9, sa33_sub_round9;
263
 
264
wire    [7:0]    sa00_sr_round9, sa01_sr_round9, sa02_sr_round9, sa03_sr_round9;
265
wire    [7:0]    sa10_sr_round9, sa11_sr_round9, sa12_sr_round9, sa13_sr_round9;
266
wire    [7:0]    sa20_sr_round9, sa21_sr_round9, sa22_sr_round9, sa23_sr_round9;
267
wire    [7:0]    sa30_sr_round9, sa31_sr_round9, sa32_sr_round9, sa33_sr_round9;
268
 
269
wire    [7:0]    sa00_mc_round9, sa01_mc_round9, sa02_mc_round9, sa03_mc_round9;
270
wire    [7:0]    sa10_mc_round9, sa11_mc_round9, sa12_mc_round9, sa13_mc_round9;
271
wire    [7:0]    sa20_mc_round9, sa21_mc_round9, sa22_mc_round9, sa23_mc_round9;
272
wire    [7:0]    sa30_mc_round9, sa31_mc_round9, sa32_mc_round9, sa33_mc_round9;
273
 
274
 
275
//round10 wires
276
wire    [7:0]    sa00_next_round10, sa01_next_round10, sa02_next_round10, sa03_next_round10;
277
wire    [7:0]    sa10_next_round10, sa11_next_round10, sa12_next_round10, sa13_next_round10;
278
wire    [7:0]    sa20_next_round10, sa21_next_round10, sa22_next_round10, sa23_next_round10;
279
wire    [7:0]    sa30_next_round10, sa31_next_round10, sa32_next_round10, sa33_next_round10;
280
 
281
wire    [7:0]    sa00_sub_round10, sa01_sub_round10, sa02_sub_round10, sa03_sub_round10;
282
wire    [7:0]    sa10_sub_round10, sa11_sub_round10, sa12_sub_round10, sa13_sub_round10;
283
wire  [7:0]      sa20_sub_round10, sa21_sub_round10, sa22_sub_round10, sa23_sub_round10;
284
wire    [7:0]    sa30_sub_round10, sa31_sub_round10, sa32_sub_round10, sa33_sub_round10;
285
 
286
wire    [7:0]    sa00_sr_round10, sa01_sr_round10, sa02_sr_round10, sa03_sr_round10;
287
wire    [7:0]    sa10_sr_round10, sa11_sr_round10, sa12_sr_round10, sa13_sr_round10;
288
wire    [7:0]    sa20_sr_round10, sa21_sr_round10, sa22_sr_round10, sa23_sr_round10;
289
wire    [7:0]    sa30_sr_round10, sa31_sr_round10, sa32_sr_round10, sa33_sr_round10;
290
 
291
 
292
 
293
reg             done, ld_r;
294
reg     [3:0]    dcnt;
295
reg             done2;
296
 
297
////////////////////////////////////////////////////////////////////
298
//
299
// Misc Logic
300
//
301
 
302
always @(posedge clk)
303
begin
304
        if(rst) begin dcnt <=  4'h0;     end
305
        else
306
        if(ld)  begin   dcnt <=  4'h2;   end
307
        else
308
        if(|dcnt) begin dcnt <=  dcnt - 4'h1;  end
309
 
310
end
311
 
312
always @(posedge clk) done <=  !(|dcnt[3:1]) & dcnt[0] & !ld;
313
always @(posedge clk) if(ld) text_in_r <=  text_in;
314
always @(posedge clk) ld_r <=  ld;
315
 
316
 
317
 
318
////////////////////////////////////////////////////////////////////
319
// key expansion
320
 
321
 
322
aes_key_expand_128 u0(
323
        .clk(           clk     ),
324
        .key(           key     ),
325
        .w0(            w0      ),
326
        .w1(            w1      ),
327
        .w2(            w2      ),
328
        .w3(            w3      ),
329
        .w4(            w4      ),
330
        .w5(            w5      ),
331
        .w6(            w6      ),
332
        .w7(            w7      ),
333
        .w8(            w8      ),
334
        .w9(            w9      ),
335
        .w10(           w10     ),
336
        .w11(           w11     ),
337
        .w12(           w12     ),
338
        .w13(           w13     ),
339
        .w14(           w14     ),
340
        .w15(           w15     ),
341
        .w16(           w16     ),
342
        .w17(           w17     ),
343
        .w18(           w18     ),
344
        .w19(           w19     ),
345
        .w20(           w20     ),
346
        .w21(           w21     ),
347
        .w22(           w22     ),
348
        .w23(           w23     ),
349
        .w24(           w24     ),
350
        .w25(           w25     ),
351
        .w26(           w26     ),
352
        .w27(           w27     ),
353
        .w28(           w28     ),
354
        .w29(           w29     ),
355
        .w30(           w30     ),
356
        .w31(           w31     ),
357
        .w32(           w32     ),
358
        .w33(           w33     ),
359
        .w34(           w34     ),
360
        .w35(           w35     ),
361
        .w36(           w36     ),
362
        .w37(           w37     ),
363
        .w38(           w38     ),
364
        .w39(           w39     ),
365
        .w40(           w40     ),
366
        .w41(           w41     ),
367
        .w42(           w42     ),
368
        .w43(           w43     )
369
                                        );
370
 
371
always @(posedge clk)
372
begin
373
        sa33 <=   text_in_r[007:000] ^ w3[07:00]; //sa33_mc_round2 ^ w3[07:00];
374
        sa23 <=   text_in_r[015:008] ^ w3[15:08]; //sa23_mc_round2 ^ w3[15:08];
375
        sa13 <=   text_in_r[023:016] ^ w3[23:16]; //sa13_mc_round2 ^ w3[23:16];
376
        sa03 <=   text_in_r[031:024] ^ w3[31:24]; //sa03_mc_round2 ^ w3[31:24];
377
        sa32 <=   text_in_r[039:032] ^ w2[07:00]; //sa32_mc_round2 ^ w2[07:00];
378
        sa22 <=   text_in_r[047:040] ^ w2[15:08]; //sa22_mc_round2 ^ w2[15:08];
379
        sa12 <=   text_in_r[055:048] ^ w2[23:16]; //sa12_mc_round2 ^ w2[23:16];
380
        sa02 <=   text_in_r[063:056] ^ w2[31:24]; //sa02_mc_round2 ^ w2[31:24];
381
        sa31 <=   text_in_r[071:064] ^ w1[07:00]; //sa31_mc_round2 ^ w1[07:00];
382
        sa21 <=   text_in_r[079:072] ^ w1[15:08]; //sa21_mc_round2 ^ w1[15:08];
383
        sa11 <=   text_in_r[087:080] ^ w1[23:16]; //sa11_mc_round2 ^ w1[23:16];
384
        sa01 <=   text_in_r[095:088] ^ w1[31:24]; //sa01_mc_round2 ^ w1[31:24];
385
        sa30 <=   text_in_r[103:096] ^ w0[07:00]; //sa30_mc_round2 ^ w0[07:00];
386
        sa20 <=   text_in_r[111:104] ^ w0[15:08]; //sa20_mc_round2 ^ w0[15:08];
387
        sa10 <=   text_in_r[119:112] ^ w0[23:16]; //sa10_mc_round2 ^ w0[23:16];
388
        sa00 <=   text_in_r[127:120] ^ w0[31:24]; //sa00_mc_round2 ^ w0[31:24];
389
 
390
end
391
 
392
 
393
//sbox lookup
394
aes_sbox us00(  .a(     sa00    ), .d(  sa00_sub        ));
395
aes_sbox us01(  .a(     sa01    ), .d(  sa01_sub        ));
396
aes_sbox us02(  .a(     sa02    ), .d(  sa02_sub        ));
397
aes_sbox us03(  .a(     sa03    ), .d(  sa03_sub        ));
398
aes_sbox us10(  .a(     sa10    ), .d(  sa10_sub        ));
399
aes_sbox us11(  .a(     sa11    ), .d(  sa11_sub        ));
400
aes_sbox us12(  .a(     sa12    ), .d(  sa12_sub        ));
401
aes_sbox us13(  .a(     sa13    ), .d(  sa13_sub        ));
402
aes_sbox us20(  .a(     sa20    ), .d(  sa20_sub        ));
403
aes_sbox us21(  .a(     sa21    ), .d(  sa21_sub        ));
404
aes_sbox us22(  .a(     sa22    ), .d(  sa22_sub        ));
405
aes_sbox us23(  .a(     sa23    ), .d(  sa23_sub        ));
406
aes_sbox us30(  .a(     sa30    ), .d(  sa30_sub        ));
407
aes_sbox us31(  .a(     sa31    ), .d(  sa31_sub        ));
408
aes_sbox us32(  .a(     sa32    ), .d(  sa32_sub        ));
409
aes_sbox us33(  .a(     sa33    ), .d(  sa33_sub        ));
410
 
411
//shift rows
412
 
413
assign sa00_sr = sa00_sub;              //
414
assign sa01_sr = sa01_sub;              //no shift
415
assign sa02_sr = sa02_sub;              //
416
assign sa03_sr = sa03_sub;              //
417
 
418
assign sa10_sr = sa11_sub;              //
419
assign sa11_sr = sa12_sub;              // left shift by 1
420
assign sa12_sr = sa13_sub;              //
421
assign sa13_sr = sa10_sub;              //
422
 
423
assign sa20_sr = sa22_sub;              //
424
assign sa21_sr = sa23_sub;              //      left shift by 2
425
assign sa22_sr = sa20_sub;              //
426
assign sa23_sr = sa21_sub;              //
427
 
428
assign sa30_sr = sa33_sub;              //
429
assign sa31_sr = sa30_sub;              // left shift by 3
430
assign sa32_sr = sa31_sub;              //
431
assign sa33_sr = sa32_sub;              //
432
 
433
// mix column operation
434
assign {sa00_mc, sa10_mc, sa20_mc, sa30_mc}  = mix_col(sa00_sr,sa10_sr,sa20_sr,sa30_sr);
435
assign {sa01_mc, sa11_mc, sa21_mc, sa31_mc}  = mix_col(sa01_sr,sa11_sr,sa21_sr,sa31_sr);
436
assign {sa02_mc, sa12_mc, sa22_mc, sa32_mc}  = mix_col(sa02_sr,sa12_sr,sa22_sr,sa32_sr);
437
assign {sa03_mc, sa13_mc, sa23_mc, sa33_mc}  = mix_col(sa03_sr,sa13_sr,sa23_sr,sa33_sr);
438
 
439
//// add round key
440
assign sa00_next_round2 = sa00_mc ^ w4[31:24];
441
assign sa01_next_round2 = sa01_mc ^ w5[31:24];
442
assign sa02_next_round2 = sa02_mc ^ w6[31:24];
443
assign sa03_next_round2 = sa03_mc ^ w7[31:24];
444
assign sa10_next_round2 = sa10_mc ^ w4[23:16];
445
assign sa11_next_round2 = sa11_mc ^ w5[23:16];
446
assign sa12_next_round2 = sa12_mc ^ w6[23:16];
447
assign sa13_next_round2 = sa13_mc ^ w7[23:16];
448
assign sa20_next_round2 = sa20_mc ^ w4[15:08];
449
assign sa21_next_round2 = sa21_mc ^ w5[15:08];
450
assign sa22_next_round2 = sa22_mc ^ w6[15:08];
451
assign sa23_next_round2 = sa23_mc ^ w7[15:08];
452
assign sa30_next_round2 = sa30_mc ^ w4[07:00];
453
assign sa31_next_round2 = sa31_mc ^ w5[07:00];
454
assign sa32_next_round2 = sa32_mc ^ w6[07:00];
455
assign sa33_next_round2 = sa33_mc ^ w7[07:00];
456
 
457
 
458
 
459
//////////////////////  round 2 //////////////////////////////////
460
 
461
//sbox lookup
462
aes_sbox us00_round2(   .a(     sa00_next_round2        ), .d(  sa00_sub_round2 ));
463
aes_sbox us01_round2(   .a(     sa01_next_round2        ), .d(  sa01_sub_round2 ));
464
aes_sbox us02_round2(   .a(     sa02_next_round2        ), .d(  sa02_sub_round2 ));
465
aes_sbox us03_round2(   .a(     sa03_next_round2        ), .d(  sa03_sub_round2 ));
466
aes_sbox us10_round2(   .a(     sa10_next_round2        ), .d(  sa10_sub_round2 ));
467
aes_sbox us11_round2(   .a(     sa11_next_round2        ), .d(  sa11_sub_round2 ));
468
aes_sbox us12_round2(   .a(     sa12_next_round2        ), .d(  sa12_sub_round2 ));
469
aes_sbox us13_round2(   .a(     sa13_next_round2        ), .d(  sa13_sub_round2 ));
470
aes_sbox us20_round2(   .a(     sa20_next_round2        ), .d(  sa20_sub_round2 ));
471
aes_sbox us21_round2(   .a(     sa21_next_round2        ), .d(  sa21_sub_round2 ));
472
aes_sbox us22_round2(   .a(     sa22_next_round2        ), .d(  sa22_sub_round2 ));
473
aes_sbox us23_round2(   .a(     sa23_next_round2        ), .d(  sa23_sub_round2 ));
474
aes_sbox us30_round2(   .a(     sa30_next_round2        ), .d(  sa30_sub_round2 ));
475
aes_sbox us31_round2(   .a(     sa31_next_round2        ), .d(  sa31_sub_round2 ));
476
aes_sbox us32_round2(   .a(     sa32_next_round2        ), .d(  sa32_sub_round2 ));
477
aes_sbox us33_round2(   .a(     sa33_next_round2        ), .d(  sa33_sub_round2 ));
478
 
479
//shift rows
480
 
481
assign sa00_sr_round2 = sa00_sub_round2;                //
482
assign sa01_sr_round2 = sa01_sub_round2;                //no shift
483
assign sa02_sr_round2 = sa02_sub_round2;                //
484
assign sa03_sr_round2 = sa03_sub_round2;                //
485
 
486
assign sa10_sr_round2 = sa11_sub_round2;                //
487
assign sa11_sr_round2 = sa12_sub_round2;                // left shift by 1
488
assign sa12_sr_round2 = sa13_sub_round2;                //
489
assign sa13_sr_round2 = sa10_sub_round2;                //
490
 
491
assign sa20_sr_round2 = sa22_sub_round2;                //
492
assign sa21_sr_round2 = sa23_sub_round2;                //      left shift by 2
493
assign sa22_sr_round2 = sa20_sub_round2;                //
494
assign sa23_sr_round2 = sa21_sub_round2;                //
495
 
496
assign sa30_sr_round2 = sa33_sub_round2;                //
497
assign sa31_sr_round2 = sa30_sub_round2;                // left shift by 3
498
assign sa32_sr_round2 = sa31_sub_round2;                //
499
assign sa33_sr_round2 = sa32_sub_round2;                //
500
 
501
// mix column operation
502
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);
503
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);
504
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);
505
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);
506
 
507
//add round key
508
assign sa33_next_round3 =                  sa33_mc_round2 ^ w11[07:00];
509
assign sa23_next_round3 =       sa23_mc_round2 ^ w11[15:08];
510
assign sa13_next_round3 =       sa13_mc_round2 ^ w11[23:16];
511
assign sa03_next_round3 =       sa03_mc_round2 ^ w11[31:24];
512
assign sa32_next_round3 =       sa32_mc_round2 ^ w10[07:00];
513
assign sa22_next_round3 =       sa22_mc_round2 ^ w10[15:08];
514
assign sa12_next_round3 =       sa12_mc_round2 ^ w10[23:16];
515
assign sa02_next_round3 =       sa02_mc_round2 ^ w10[31:24];
516
assign sa31_next_round3 =       sa31_mc_round2 ^ w9[07:00];
517
assign sa21_next_round3 =       sa21_mc_round2 ^ w9[15:08];
518
assign sa11_next_round3 =       sa11_mc_round2 ^ w9[23:16];
519
assign sa01_next_round3 =       sa01_mc_round2 ^ w9[31:24];
520
assign sa30_next_round3 =       sa30_mc_round2 ^ w8[07:00];
521
assign sa20_next_round3 =       sa20_mc_round2 ^ w8[15:08];
522
assign sa10_next_round3 =       sa10_mc_round2 ^ w8[23:16];
523
assign sa00_next_round3 =       sa00_mc_round2 ^ w8[31:24];
524
 
525
 
526
/////////////////////////round #3 transformations/////////////////////////////
527
 
528
 
529
//sbox lookup
530
aes_sbox us00_round3(   .a(     sa00_next_round3        ), .d(  sa00_sub_round3 ));
531
aes_sbox us01_round3(   .a(     sa01_next_round3        ), .d(  sa01_sub_round3 ));
532
aes_sbox us02_round3(   .a(     sa02_next_round3        ), .d(  sa02_sub_round3 ));
533
aes_sbox us03_round3(   .a(     sa03_next_round3        ), .d(  sa03_sub_round3 ));
534
aes_sbox us10_round3(   .a(     sa10_next_round3        ), .d(  sa10_sub_round3 ));
535
aes_sbox us11_round3(   .a(     sa11_next_round3        ), .d(  sa11_sub_round3 ));
536
aes_sbox us12_round3(   .a(     sa12_next_round3        ), .d(  sa12_sub_round3 ));
537
aes_sbox us13_round3(   .a(     sa13_next_round3        ), .d(  sa13_sub_round3 ));
538
aes_sbox us20_round3(   .a(     sa20_next_round3        ), .d(  sa20_sub_round3 ));
539
aes_sbox us21_round3(   .a(     sa21_next_round3        ), .d(  sa21_sub_round3 ));
540
aes_sbox us22_round3(   .a(     sa22_next_round3        ), .d(  sa22_sub_round3 ));
541
aes_sbox us23_round3(   .a(     sa23_next_round3        ), .d(  sa23_sub_round3 ));
542
aes_sbox us30_round3(   .a(     sa30_next_round3        ), .d(  sa30_sub_round3 ));
543
aes_sbox us31_round3(   .a(     sa31_next_round3        ), .d(  sa31_sub_round3 ));
544
aes_sbox us32_round3(   .a(     sa32_next_round3        ), .d(  sa32_sub_round3 ));
545
aes_sbox us33_round3(   .a(     sa33_next_round3        ), .d(  sa33_sub_round3 ));
546
 
547
//shift rows
548
 
549
assign sa00_sr_round3 = sa00_sub_round3;                //
550
assign sa01_sr_round3 = sa01_sub_round3;                //no shift
551
assign sa02_sr_round3 = sa02_sub_round3;                //
552
assign sa03_sr_round3 = sa03_sub_round3;                //
553
 
554
assign sa10_sr_round3 = sa11_sub_round3;                //
555
assign sa11_sr_round3 = sa12_sub_round3;                // left shift by 1
556
assign sa12_sr_round3 = sa13_sub_round3;                //
557
assign sa13_sr_round3 = sa10_sub_round3;                //
558
 
559
assign sa20_sr_round3 = sa22_sub_round3;                //
560
assign sa21_sr_round3 = sa23_sub_round3;                //      left shift by 2
561
assign sa22_sr_round3 = sa20_sub_round3;                //
562
assign sa23_sr_round3 = sa21_sub_round3;                //
563
 
564
assign sa30_sr_round3 = sa33_sub_round3;                //
565
assign sa31_sr_round3 = sa30_sub_round3;                // left shift by 3
566
assign sa32_sr_round3 = sa31_sub_round3;                //
567
assign sa33_sr_round3 = sa32_sub_round3;                //
568
 
569
// mix column operation
570
assign {sa00_mc_round3, sa10_mc_round3, sa20_mc_round3, sa30_mc_round3}  = mix_col(sa00_sr_round3,sa10_sr_round3,sa20_sr_round3,sa30_sr_round3);
571
assign {sa01_mc_round3, sa11_mc_round3, sa21_mc_round3, sa31_mc_round3}  = mix_col(sa01_sr_round3,sa11_sr_round3,sa21_sr_round3,sa31_sr_round3);
572
assign {sa02_mc_round3, sa12_mc_round3, sa22_mc_round3, sa32_mc_round3}  = mix_col(sa02_sr_round3,sa12_sr_round3,sa22_sr_round3,sa32_sr_round3);
573
assign {sa03_mc_round3, sa13_mc_round3, sa23_mc_round3, sa33_mc_round3}  = mix_col(sa03_sr_round3,sa13_sr_round3,sa23_sr_round3,sa33_sr_round3);
574
 
575
 
576
//add round key
577
assign sa33_next_round4 =                  sa33_mc_round3 ^ w15[07:00];
578
assign sa23_next_round4 =       sa23_mc_round3 ^ w15[15:08];
579
assign sa13_next_round4 =       sa13_mc_round3 ^ w15[23:16];
580
assign sa03_next_round4 =       sa03_mc_round3 ^ w15[31:24];
581
assign sa32_next_round4 =       sa32_mc_round3 ^ w14[07:00];
582
assign sa22_next_round4 =       sa22_mc_round3 ^ w14[15:08];
583
assign sa12_next_round4 =       sa12_mc_round3 ^ w14[23:16];
584
assign sa02_next_round4 =       sa02_mc_round3 ^ w14[31:24];
585
assign sa31_next_round4 =       sa31_mc_round3 ^ w13[07:00];
586
assign sa21_next_round4 =       sa21_mc_round3 ^ w13[15:08];
587
assign sa11_next_round4 =       sa11_mc_round3 ^ w13[23:16];
588
assign sa01_next_round4 =       sa01_mc_round3 ^ w13[31:24];
589
assign sa30_next_round4 =       sa30_mc_round3 ^ w12[07:00];
590
assign sa20_next_round4 =       sa20_mc_round3 ^ w12[15:08];
591
assign sa10_next_round4 =       sa10_mc_round3 ^ w12[23:16];
592
assign sa00_next_round4 =       sa00_mc_round3 ^ w12[31:24];
593
 
594
/////////////////////////round #4 transformations/////////////////////////////
595
 
596
 
597
//sbox lookup
598
aes_sbox us00_round4(   .a(     sa00_next_round4        ), .d(  sa00_sub_round4 ));
599
aes_sbox us01_round4(   .a(     sa01_next_round4        ), .d(  sa01_sub_round4 ));
600
aes_sbox us02_round4(   .a(     sa02_next_round4        ), .d(  sa02_sub_round4 ));
601
aes_sbox us03_round4(   .a(     sa03_next_round4        ), .d(  sa03_sub_round4 ));
602
aes_sbox us10_round4(   .a(     sa10_next_round4        ), .d(  sa10_sub_round4 ));
603
aes_sbox us11_round4(   .a(     sa11_next_round4        ), .d(  sa11_sub_round4 ));
604
aes_sbox us12_round4(   .a(     sa12_next_round4        ), .d(  sa12_sub_round4 ));
605
aes_sbox us13_round4(   .a(     sa13_next_round4        ), .d(  sa13_sub_round4 ));
606
aes_sbox us20_round4(   .a(     sa20_next_round4        ), .d(  sa20_sub_round4 ));
607
aes_sbox us21_round4(   .a(     sa21_next_round4        ), .d(  sa21_sub_round4 ));
608
aes_sbox us22_round4(   .a(     sa22_next_round4        ), .d(  sa22_sub_round4 ));
609
aes_sbox us23_round4(   .a(     sa23_next_round4        ), .d(  sa23_sub_round4 ));
610
aes_sbox us30_round4(   .a(     sa30_next_round4        ), .d(  sa30_sub_round4 ));
611
aes_sbox us31_round4(   .a(     sa31_next_round4        ), .d(  sa31_sub_round4 ));
612
aes_sbox us32_round4(   .a(     sa32_next_round4        ), .d(  sa32_sub_round4 ));
613
aes_sbox us33_round4(   .a(     sa33_next_round4        ), .d(  sa33_sub_round4 ));
614
 
615
//shift rows
616
 
617
assign sa00_sr_round4 = sa00_sub_round4;                //
618
assign sa01_sr_round4 = sa01_sub_round4;                //no shift
619
assign sa02_sr_round4 = sa02_sub_round4;                //
620
assign sa03_sr_round4 = sa03_sub_round4;                //
621
 
622
assign sa10_sr_round4 = sa11_sub_round4;                //
623
assign sa11_sr_round4 = sa12_sub_round4;                // left shift by 1
624
assign sa12_sr_round4 = sa13_sub_round4;                //
625
assign sa13_sr_round4 = sa10_sub_round4;                //
626
 
627
assign sa20_sr_round4 = sa22_sub_round4;                //
628
assign sa21_sr_round4 = sa23_sub_round4;                //      left shift by 2
629
assign sa22_sr_round4 = sa20_sub_round4;                //
630
assign sa23_sr_round4 = sa21_sub_round4;                //
631
 
632
assign sa30_sr_round4 = sa33_sub_round4;                //
633
assign sa31_sr_round4 = sa30_sub_round4;                // left shift by 3
634
assign sa32_sr_round4 = sa31_sub_round4;                //
635
assign sa33_sr_round4 = sa32_sub_round4;                //
636
 
637
// mix column operation
638
assign {sa00_mc_round4, sa10_mc_round4, sa20_mc_round4, sa30_mc_round4}  = mix_col(sa00_sr_round4,sa10_sr_round4,sa20_sr_round4,sa30_sr_round4);
639
assign {sa01_mc_round4, sa11_mc_round4, sa21_mc_round4, sa31_mc_round4}  = mix_col(sa01_sr_round4,sa11_sr_round4,sa21_sr_round4,sa31_sr_round4);
640
assign {sa02_mc_round4, sa12_mc_round4, sa22_mc_round4, sa32_mc_round4}  = mix_col(sa02_sr_round4,sa12_sr_round4,sa22_sr_round4,sa32_sr_round4);
641
assign {sa03_mc_round4, sa13_mc_round4, sa23_mc_round4, sa33_mc_round4}  = mix_col(sa03_sr_round4,sa13_sr_round4,sa23_sr_round4,sa33_sr_round4);
642
 
643
 
644
//add round key
645
assign sa33_next_round5 =                  sa33_mc_round4 ^ w19[07:00];
646
assign sa23_next_round5 =       sa23_mc_round4 ^ w19[15:08];
647
assign sa13_next_round5 =       sa13_mc_round4 ^ w19[23:16];
648
assign sa03_next_round5 =       sa03_mc_round4 ^ w19[31:24];
649
assign sa32_next_round5 =       sa32_mc_round4 ^ w18[07:00];
650
assign sa22_next_round5 =       sa22_mc_round4 ^ w18[15:08];
651
assign sa12_next_round5 =       sa12_mc_round4 ^ w18[23:16];
652
assign sa02_next_round5 =       sa02_mc_round4 ^ w18[31:24];
653
assign sa31_next_round5 =       sa31_mc_round4 ^ w17[07:00];
654
assign sa21_next_round5 =       sa21_mc_round4 ^ w17[15:08];
655
assign sa11_next_round5 =       sa11_mc_round4 ^ w17[23:16];
656
assign sa01_next_round5 =       sa01_mc_round4 ^ w17[31:24];
657
assign sa30_next_round5 =       sa30_mc_round4 ^ w16[07:00];
658
assign sa20_next_round5 =       sa20_mc_round4 ^ w16[15:08];
659
assign sa10_next_round5 =       sa10_mc_round4 ^ w16[23:16];
660
assign sa00_next_round5 =       sa00_mc_round4 ^ w16[31:24];
661
 
662
 
663
/////////////////////////round #5 transformations/////////////////////////////
664
 
665
 
666
//sbox lookup
667
aes_sbox us00_round5(   .a(     sa00_next_round5        ), .d(  sa00_sub_round5 ));
668
aes_sbox us01_round5(   .a(     sa01_next_round5        ), .d(  sa01_sub_round5 ));
669
aes_sbox us02_round5(   .a(     sa02_next_round5        ), .d(  sa02_sub_round5 ));
670
aes_sbox us03_round5(   .a(     sa03_next_round5        ), .d(  sa03_sub_round5 ));
671
aes_sbox us10_round5(   .a(     sa10_next_round5        ), .d(  sa10_sub_round5 ));
672
aes_sbox us11_round5(   .a(     sa11_next_round5        ), .d(  sa11_sub_round5 ));
673
aes_sbox us12_round5(   .a(     sa12_next_round5        ), .d(  sa12_sub_round5 ));
674
aes_sbox us13_round5(   .a(     sa13_next_round5        ), .d(  sa13_sub_round5 ));
675
aes_sbox us20_round5(   .a(     sa20_next_round5        ), .d(  sa20_sub_round5 ));
676
aes_sbox us21_round5(   .a(     sa21_next_round5        ), .d(  sa21_sub_round5 ));
677
aes_sbox us22_round5(   .a(     sa22_next_round5        ), .d(  sa22_sub_round5 ));
678
aes_sbox us23_round5(   .a(     sa23_next_round5        ), .d(  sa23_sub_round5 ));
679
aes_sbox us30_round5(   .a(     sa30_next_round5        ), .d(  sa30_sub_round5 ));
680
aes_sbox us31_round5(   .a(     sa31_next_round5        ), .d(  sa31_sub_round5 ));
681
aes_sbox us32_round5(   .a(     sa32_next_round5        ), .d(  sa32_sub_round5 ));
682
aes_sbox us33_round5(   .a(     sa33_next_round5        ), .d(  sa33_sub_round5 ));
683
 
684
//shift rows
685
 
686
assign sa00_sr_round5 = sa00_sub_round5;                //
687
assign sa01_sr_round5 = sa01_sub_round5;                //no shift
688
assign sa02_sr_round5 = sa02_sub_round5;                //
689
assign sa03_sr_round5 = sa03_sub_round5;                //
690
 
691
assign sa10_sr_round5 = sa11_sub_round5;                //
692
assign sa11_sr_round5 = sa12_sub_round5;                // left shift by 1
693
assign sa12_sr_round5 = sa13_sub_round5;                //
694
assign sa13_sr_round5 = sa10_sub_round5;                //
695
 
696
assign sa20_sr_round5 = sa22_sub_round5;                //
697
assign sa21_sr_round5 = sa23_sub_round5;                //      left shift by 2
698
assign sa22_sr_round5 = sa20_sub_round5;                //
699
assign sa23_sr_round5 = sa21_sub_round5;                //
700
 
701
assign sa30_sr_round5 = sa33_sub_round5;                //
702
assign sa31_sr_round5 = sa30_sub_round5;                // left shift by 3
703
assign sa32_sr_round5 = sa31_sub_round5;                //
704
assign sa33_sr_round5 = sa32_sub_round5;                //
705
 
706
// mix column operation
707
assign {sa00_mc_round5, sa10_mc_round5, sa20_mc_round5, sa30_mc_round5}  = mix_col(sa00_sr_round5,sa10_sr_round5,sa20_sr_round5,sa30_sr_round5);
708
assign {sa01_mc_round5, sa11_mc_round5, sa21_mc_round5, sa31_mc_round5}  = mix_col(sa01_sr_round5,sa11_sr_round5,sa21_sr_round5,sa31_sr_round5);
709
assign {sa02_mc_round5, sa12_mc_round5, sa22_mc_round5, sa32_mc_round5}  = mix_col(sa02_sr_round5,sa12_sr_round5,sa22_sr_round5,sa32_sr_round5);
710
assign {sa03_mc_round5, sa13_mc_round5, sa23_mc_round5, sa33_mc_round5}  = mix_col(sa03_sr_round5,sa13_sr_round5,sa23_sr_round5,sa33_sr_round5);
711
 
712
 
713
//add round key
714
assign sa33_next_round6 =                  sa33_mc_round5 ^ w23[07:00];
715
assign sa23_next_round6 =       sa23_mc_round5 ^ w23[15:08];
716
assign sa13_next_round6 =       sa13_mc_round5 ^ w23[23:16];
717
assign sa03_next_round6 =       sa03_mc_round5 ^ w23[31:24];
718
assign sa32_next_round6 =       sa32_mc_round5 ^ w22[07:00];
719
assign sa22_next_round6 =       sa22_mc_round5 ^ w22[15:08];
720
assign sa12_next_round6 =       sa12_mc_round5 ^ w22[23:16];
721
assign sa02_next_round6 =       sa02_mc_round5 ^ w22[31:24];
722
assign sa31_next_round6 =       sa31_mc_round5 ^ w21[07:00];
723
assign sa21_next_round6 =       sa21_mc_round5 ^ w21[15:08];
724
assign sa11_next_round6 =       sa11_mc_round5 ^ w21[23:16];
725
assign sa01_next_round6 =       sa01_mc_round5 ^ w21[31:24];
726
assign sa30_next_round6 =       sa30_mc_round5 ^ w20[07:00];
727
assign sa20_next_round6 =       sa20_mc_round5 ^ w20[15:08];
728
assign sa10_next_round6 =       sa10_mc_round5 ^ w20[23:16];
729
assign sa00_next_round6 =       sa00_mc_round5 ^ w20[31:24];
730
 
731
 
732
/////////////////////////round #6 transformations/////////////////////////////
733
 
734
 
735
//sbox lookup
736
aes_sbox us00_round6(   .a(     sa00_next_round6        ), .d(  sa00_sub_round6 ));
737
aes_sbox us01_round6(   .a(     sa01_next_round6        ), .d(  sa01_sub_round6 ));
738
aes_sbox us02_round6(   .a(     sa02_next_round6        ), .d(  sa02_sub_round6 ));
739
aes_sbox us03_round6(   .a(     sa03_next_round6        ), .d(  sa03_sub_round6 ));
740
aes_sbox us10_round6(   .a(     sa10_next_round6        ), .d(  sa10_sub_round6 ));
741
aes_sbox us11_round6(   .a(     sa11_next_round6        ), .d(  sa11_sub_round6 ));
742
aes_sbox us12_round6(   .a(     sa12_next_round6        ), .d(  sa12_sub_round6 ));
743
aes_sbox us13_round6(   .a(     sa13_next_round6        ), .d(  sa13_sub_round6 ));
744
aes_sbox us20_round6(   .a(     sa20_next_round6        ), .d(  sa20_sub_round6 ));
745
aes_sbox us21_round6(   .a(     sa21_next_round6        ), .d(  sa21_sub_round6 ));
746
aes_sbox us22_round6(   .a(     sa22_next_round6        ), .d(  sa22_sub_round6 ));
747
aes_sbox us23_round6(   .a(     sa23_next_round6        ), .d(  sa23_sub_round6 ));
748
aes_sbox us30_round6(   .a(     sa30_next_round6        ), .d(  sa30_sub_round6 ));
749
aes_sbox us31_round6(   .a(     sa31_next_round6        ), .d(  sa31_sub_round6 ));
750
aes_sbox us32_round6(   .a(     sa32_next_round6        ), .d(  sa32_sub_round6 ));
751
aes_sbox us33_round6(   .a(     sa33_next_round6        ), .d(  sa33_sub_round6 ));
752
 
753
//shift rows
754
 
755
assign sa00_sr_round6 = sa00_sub_round6;                //
756
assign sa01_sr_round6 = sa01_sub_round6;                //no shift
757
assign sa02_sr_round6 = sa02_sub_round6;                //
758
assign sa03_sr_round6 = sa03_sub_round6;                //
759
 
760
assign sa10_sr_round6 = sa11_sub_round6;                //
761
assign sa11_sr_round6 = sa12_sub_round6;                // left shift by 1
762
assign sa12_sr_round6 = sa13_sub_round6;                //
763
assign sa13_sr_round6 = sa10_sub_round6;                //
764
 
765
assign sa20_sr_round6 = sa22_sub_round6;                //
766
assign sa21_sr_round6 = sa23_sub_round6;                //      left shift by 2
767
assign sa22_sr_round6 = sa20_sub_round6;                //
768
assign sa23_sr_round6 = sa21_sub_round6;                //
769
 
770
assign sa30_sr_round6 = sa33_sub_round6;                //
771
assign sa31_sr_round6 = sa30_sub_round6;                // left shift by 3
772
assign sa32_sr_round6 = sa31_sub_round6;                //
773
assign sa33_sr_round6 = sa32_sub_round6;                //
774
 
775
// mix column operation
776
assign {sa00_mc_round6, sa10_mc_round6, sa20_mc_round6, sa30_mc_round6}  = mix_col(sa00_sr_round6,sa10_sr_round6,sa20_sr_round6,sa30_sr_round6);
777
assign {sa01_mc_round6, sa11_mc_round6, sa21_mc_round6, sa31_mc_round6}  = mix_col(sa01_sr_round6,sa11_sr_round6,sa21_sr_round6,sa31_sr_round6);
778
assign {sa02_mc_round6, sa12_mc_round6, sa22_mc_round6, sa32_mc_round6}  = mix_col(sa02_sr_round6,sa12_sr_round6,sa22_sr_round6,sa32_sr_round6);
779
assign {sa03_mc_round6, sa13_mc_round6, sa23_mc_round6, sa33_mc_round6}  = mix_col(sa03_sr_round6,sa13_sr_round6,sa23_sr_round6,sa33_sr_round6);
780
 
781
 
782
//add round key
783
assign sa33_next_round7 =                  sa33_mc_round6 ^ w27[07:00];
784
assign sa23_next_round7 =       sa23_mc_round6 ^ w27[15:08];
785
assign sa13_next_round7 =       sa13_mc_round6 ^ w27[23:16];
786
assign sa03_next_round7 =       sa03_mc_round6 ^ w27[31:24];
787
assign sa32_next_round7 =       sa32_mc_round6 ^ w26[07:00];
788
assign sa22_next_round7 =       sa22_mc_round6 ^ w26[15:08];
789
assign sa12_next_round7 =       sa12_mc_round6 ^ w26[23:16];
790
assign sa02_next_round7 =       sa02_mc_round6 ^ w26[31:24];
791
assign sa31_next_round7 =       sa31_mc_round6 ^ w25[07:00];
792
assign sa21_next_round7 =       sa21_mc_round6 ^ w25[15:08];
793
assign sa11_next_round7 =       sa11_mc_round6 ^ w25[23:16];
794
assign sa01_next_round7 =       sa01_mc_round6 ^ w25[31:24];
795
assign sa30_next_round7 =       sa30_mc_round6 ^ w24[07:00];
796
assign sa20_next_round7 =       sa20_mc_round6 ^ w24[15:08];
797
assign sa10_next_round7 =       sa10_mc_round6 ^ w24[23:16];
798
assign sa00_next_round7 =       sa00_mc_round6 ^ w24[31:24];
799
 
800
 
801
/////////////////////////round #7 transformations/////////////////////////////
802
 
803
 
804
//sbox lookup
805
aes_sbox us00_round7(   .a(     sa00_next_round7        ), .d(  sa00_sub_round7 ));
806
aes_sbox us01_round7(   .a(     sa01_next_round7        ), .d(  sa01_sub_round7 ));
807
aes_sbox us02_round7(   .a(     sa02_next_round7        ), .d(  sa02_sub_round7 ));
808
aes_sbox us03_round7(   .a(     sa03_next_round7        ), .d(  sa03_sub_round7 ));
809
aes_sbox us10_round7(   .a(     sa10_next_round7        ), .d(  sa10_sub_round7 ));
810
aes_sbox us11_round7(   .a(     sa11_next_round7        ), .d(  sa11_sub_round7 ));
811
aes_sbox us12_round7(   .a(     sa12_next_round7        ), .d(  sa12_sub_round7 ));
812
aes_sbox us13_round7(   .a(     sa13_next_round7        ), .d(  sa13_sub_round7 ));
813
aes_sbox us20_round7(   .a(     sa20_next_round7        ), .d(  sa20_sub_round7 ));
814
aes_sbox us21_round7(   .a(     sa21_next_round7        ), .d(  sa21_sub_round7 ));
815
aes_sbox us22_round7(   .a(     sa22_next_round7        ), .d(  sa22_sub_round7 ));
816
aes_sbox us23_round7(   .a(     sa23_next_round7        ), .d(  sa23_sub_round7 ));
817
aes_sbox us30_round7(   .a(     sa30_next_round7        ), .d(  sa30_sub_round7 ));
818
aes_sbox us31_round7(   .a(     sa31_next_round7        ), .d(  sa31_sub_round7 ));
819
aes_sbox us32_round7(   .a(     sa32_next_round7        ), .d(  sa32_sub_round7 ));
820
aes_sbox us33_round7(   .a(     sa33_next_round7        ), .d(  sa33_sub_round7 ));
821
 
822
//shift rows
823
 
824
assign sa00_sr_round7 = sa00_sub_round7;                //
825
assign sa01_sr_round7 = sa01_sub_round7;                //no shift
826
assign sa02_sr_round7 = sa02_sub_round7;                //
827
assign sa03_sr_round7 = sa03_sub_round7;                //
828
 
829
assign sa10_sr_round7 = sa11_sub_round7;                //
830
assign sa11_sr_round7 = sa12_sub_round7;                // left shift by 1
831
assign sa12_sr_round7 = sa13_sub_round7;                //
832
assign sa13_sr_round7 = sa10_sub_round7;                //
833
 
834
assign sa20_sr_round7 = sa22_sub_round7;                //
835
assign sa21_sr_round7 = sa23_sub_round7;                //      left shift by 2
836
assign sa22_sr_round7 = sa20_sub_round7;                //
837
assign sa23_sr_round7 = sa21_sub_round7;                //
838
 
839
assign sa30_sr_round7 = sa33_sub_round7;                //
840
assign sa31_sr_round7 = sa30_sub_round7;                // left shift by 3
841
assign sa32_sr_round7 = sa31_sub_round7;                //
842
assign sa33_sr_round7 = sa32_sub_round7;                //
843
 
844
// mix column operation
845
assign {sa00_mc_round7, sa10_mc_round7, sa20_mc_round7, sa30_mc_round7}  = mix_col(sa00_sr_round7,sa10_sr_round7,sa20_sr_round7,sa30_sr_round7);
846
assign {sa01_mc_round7, sa11_mc_round7, sa21_mc_round7, sa31_mc_round7}  = mix_col(sa01_sr_round7,sa11_sr_round7,sa21_sr_round7,sa31_sr_round7);
847
assign {sa02_mc_round7, sa12_mc_round7, sa22_mc_round7, sa32_mc_round7}  = mix_col(sa02_sr_round7,sa12_sr_round7,sa22_sr_round7,sa32_sr_round7);
848
assign {sa03_mc_round7, sa13_mc_round7, sa23_mc_round7, sa33_mc_round7}  = mix_col(sa03_sr_round7,sa13_sr_round7,sa23_sr_round7,sa33_sr_round7);
849
 
850
 
851
//add round key
852
assign sa33_next_round8 =                  sa33_mc_round7 ^ w31[07:00];
853
assign sa23_next_round8 =       sa23_mc_round7 ^ w31[15:08];
854
assign sa13_next_round8 =       sa13_mc_round7 ^ w31[23:16];
855
assign sa03_next_round8 =       sa03_mc_round7 ^ w31[31:24];
856
assign sa32_next_round8 =       sa32_mc_round7 ^ w30[07:00];
857
assign sa22_next_round8 =       sa22_mc_round7 ^ w30[15:08];
858
assign sa12_next_round8 =       sa12_mc_round7 ^ w30[23:16];
859
assign sa02_next_round8 =       sa02_mc_round7 ^ w30[31:24];
860
assign sa31_next_round8 =       sa31_mc_round7 ^ w29[07:00];
861
assign sa21_next_round8 =       sa21_mc_round7 ^ w29[15:08];
862
assign sa11_next_round8 =       sa11_mc_round7 ^ w29[23:16];
863
assign sa01_next_round8 =       sa01_mc_round7 ^ w29[31:24];
864
assign sa30_next_round8 =       sa30_mc_round7 ^ w28[07:00];
865
assign sa20_next_round8 =       sa20_mc_round7 ^ w28[15:08];
866
assign sa10_next_round8 =       sa10_mc_round7 ^ w28[23:16];
867
assign sa00_next_round8 =       sa00_mc_round7 ^ w28[31:24];
868
 
869
/////////////////////////round #8 transformations/////////////////////////////
870
 
871
 
872
//sbox lookup
873
aes_sbox us00_round8(   .a(     sa00_next_round8        ), .d(  sa00_sub_round8 ));
874
aes_sbox us01_round8(   .a(     sa01_next_round8        ), .d(  sa01_sub_round8 ));
875
aes_sbox us02_round8(   .a(     sa02_next_round8        ), .d(  sa02_sub_round8 ));
876
aes_sbox us03_round8(   .a(     sa03_next_round8        ), .d(  sa03_sub_round8 ));
877
aes_sbox us10_round8(   .a(     sa10_next_round8        ), .d(  sa10_sub_round8 ));
878
aes_sbox us11_round8(   .a(     sa11_next_round8        ), .d(  sa11_sub_round8 ));
879
aes_sbox us12_round8(   .a(     sa12_next_round8        ), .d(  sa12_sub_round8 ));
880
aes_sbox us13_round8(   .a(     sa13_next_round8        ), .d(  sa13_sub_round8 ));
881
aes_sbox us20_round8(   .a(     sa20_next_round8        ), .d(  sa20_sub_round8 ));
882
aes_sbox us21_round8(   .a(     sa21_next_round8        ), .d(  sa21_sub_round8 ));
883
aes_sbox us22_round8(   .a(     sa22_next_round8        ), .d(  sa22_sub_round8 ));
884
aes_sbox us23_round8(   .a(     sa23_next_round8        ), .d(  sa23_sub_round8 ));
885
aes_sbox us30_round8(   .a(     sa30_next_round8        ), .d(  sa30_sub_round8 ));
886
aes_sbox us31_round8(   .a(     sa31_next_round8        ), .d(  sa31_sub_round8 ));
887
aes_sbox us32_round8(   .a(     sa32_next_round8        ), .d(  sa32_sub_round8 ));
888
aes_sbox us33_round8(   .a(     sa33_next_round8        ), .d(  sa33_sub_round8 ));
889
 
890
//shift rows
891
 
892
assign sa00_sr_round8 = sa00_sub_round8;                //
893
assign sa01_sr_round8 = sa01_sub_round8;                //no shift
894
assign sa02_sr_round8 = sa02_sub_round8;                //
895
assign sa03_sr_round8 = sa03_sub_round8;                //
896
 
897
assign sa10_sr_round8 = sa11_sub_round8;                //
898
assign sa11_sr_round8 = sa12_sub_round8;                // left shift by 1
899
assign sa12_sr_round8 = sa13_sub_round8;                //
900
assign sa13_sr_round8 = sa10_sub_round8;                //
901
 
902
assign sa20_sr_round8 = sa22_sub_round8;                //
903
assign sa21_sr_round8 = sa23_sub_round8;                //      left shift by 2
904
assign sa22_sr_round8 = sa20_sub_round8;                //
905
assign sa23_sr_round8 = sa21_sub_round8;                //
906
 
907
assign sa30_sr_round8 = sa33_sub_round8;                //
908
assign sa31_sr_round8 = sa30_sub_round8;                // left shift by 3
909
assign sa32_sr_round8 = sa31_sub_round8;                //
910
assign sa33_sr_round8 = sa32_sub_round8;                //
911
 
912
// mix column operation
913
assign {sa00_mc_round8, sa10_mc_round8, sa20_mc_round8, sa30_mc_round8}  = mix_col(sa00_sr_round8,sa10_sr_round8,sa20_sr_round8,sa30_sr_round8);
914
assign {sa01_mc_round8, sa11_mc_round8, sa21_mc_round8, sa31_mc_round8}  = mix_col(sa01_sr_round8,sa11_sr_round8,sa21_sr_round8,sa31_sr_round8);
915
assign {sa02_mc_round8, sa12_mc_round8, sa22_mc_round8, sa32_mc_round8}  = mix_col(sa02_sr_round8,sa12_sr_round8,sa22_sr_round8,sa32_sr_round8);
916
assign {sa03_mc_round8, sa13_mc_round8, sa23_mc_round8, sa33_mc_round8}  = mix_col(sa03_sr_round8,sa13_sr_round8,sa23_sr_round8,sa33_sr_round8);
917
 
918
 
919
//add round key
920
assign sa33_next_round9 =                  sa33_mc_round8 ^ w35[07:00];
921
assign sa23_next_round9 =       sa23_mc_round8 ^ w35[15:08];
922
assign sa13_next_round9 =       sa13_mc_round8 ^ w35[23:16];
923
assign sa03_next_round9 =       sa03_mc_round8 ^ w35[31:24];
924
assign sa32_next_round9 =       sa32_mc_round8 ^ w34[07:00];
925
assign sa22_next_round9 =       sa22_mc_round8 ^ w34[15:08];
926
assign sa12_next_round9 =       sa12_mc_round8 ^ w34[23:16];
927
assign sa02_next_round9 =       sa02_mc_round8 ^ w34[31:24];
928
assign sa31_next_round9 =       sa31_mc_round8 ^ w33[07:00];
929
assign sa21_next_round9 =       sa21_mc_round8 ^ w33[15:08];
930
assign sa11_next_round9 =       sa11_mc_round8 ^ w33[23:16];
931
assign sa01_next_round9 =       sa01_mc_round8 ^ w33[31:24];
932
assign sa30_next_round9 =       sa30_mc_round8 ^ w32[07:00];
933
assign sa20_next_round9 =       sa20_mc_round8 ^ w32[15:08];
934
assign sa10_next_round9 =       sa10_mc_round8 ^ w32[23:16];
935
assign sa00_next_round9 =       sa00_mc_round8 ^ w32[31:24];
936
 
937
 
938
 
939
/////////////////////////round #9 transformations/////////////////////////////
940
 
941
 
942
//sbox lookup
943
aes_sbox us00_round9(   .a(     sa00_next_round9        ), .d(  sa00_sub_round9 ));
944
aes_sbox us01_round9(   .a(     sa01_next_round9        ), .d(  sa01_sub_round9 ));
945
aes_sbox us02_round9(   .a(     sa02_next_round9        ), .d(  sa02_sub_round9 ));
946
aes_sbox us03_round9(   .a(     sa03_next_round9        ), .d(  sa03_sub_round9 ));
947
aes_sbox us10_round9(   .a(     sa10_next_round9        ), .d(  sa10_sub_round9 ));
948
aes_sbox us11_round9(   .a(     sa11_next_round9        ), .d(  sa11_sub_round9 ));
949
aes_sbox us12_round9(   .a(     sa12_next_round9        ), .d(  sa12_sub_round9 ));
950
aes_sbox us13_round9(   .a(     sa13_next_round9        ), .d(  sa13_sub_round9 ));
951
aes_sbox us20_round9(   .a(     sa20_next_round9        ), .d(  sa20_sub_round9 ));
952
aes_sbox us21_round9(   .a(     sa21_next_round9        ), .d(  sa21_sub_round9 ));
953
aes_sbox us22_round9(   .a(     sa22_next_round9        ), .d(  sa22_sub_round9 ));
954
aes_sbox us23_round9(   .a(     sa23_next_round9        ), .d(  sa23_sub_round9 ));
955
aes_sbox us30_round9(   .a(     sa30_next_round9        ), .d(  sa30_sub_round9 ));
956
aes_sbox us31_round9(   .a(     sa31_next_round9        ), .d(  sa31_sub_round9 ));
957
aes_sbox us32_round9(   .a(     sa32_next_round9        ), .d(  sa32_sub_round9 ));
958
aes_sbox us33_round9(   .a(     sa33_next_round9        ), .d(  sa33_sub_round9 ));
959
 
960
//shift rows
961
 
962
assign sa00_sr_round9 = sa00_sub_round9;                //
963
assign sa01_sr_round9 = sa01_sub_round9;                //no shift
964
assign sa02_sr_round9 = sa02_sub_round9;                //
965
assign sa03_sr_round9 = sa03_sub_round9;                //
966
 
967
assign sa10_sr_round9 = sa11_sub_round9;                //
968
assign sa11_sr_round9 = sa12_sub_round9;                // left shift by 1
969
assign sa12_sr_round9 = sa13_sub_round9;                //
970
assign sa13_sr_round9 = sa10_sub_round9;                //
971
 
972
assign sa20_sr_round9 = sa22_sub_round9;                //
973
assign sa21_sr_round9 = sa23_sub_round9;                //      left shift by 2
974
assign sa22_sr_round9 = sa20_sub_round9;                //
975
assign sa23_sr_round9 = sa21_sub_round9;                //
976
 
977
assign sa30_sr_round9 = sa33_sub_round9;                //
978
assign sa31_sr_round9 = sa30_sub_round9;                // left shift by 3
979
assign sa32_sr_round9 = sa31_sub_round9;                //
980
assign sa33_sr_round9 = sa32_sub_round9;                //
981
 
982
// mix column operation
983
assign {sa00_mc_round9, sa10_mc_round9, sa20_mc_round9, sa30_mc_round9}  = mix_col(sa00_sr_round9,sa10_sr_round9,sa20_sr_round9,sa30_sr_round9);
984
assign {sa01_mc_round9, sa11_mc_round9, sa21_mc_round9, sa31_mc_round9}  = mix_col(sa01_sr_round9,sa11_sr_round9,sa21_sr_round9,sa31_sr_round9);
985
assign {sa02_mc_round9, sa12_mc_round9, sa22_mc_round9, sa32_mc_round9}  = mix_col(sa02_sr_round9,sa12_sr_round9,sa22_sr_round9,sa32_sr_round9);
986
assign {sa03_mc_round9, sa13_mc_round9, sa23_mc_round9, sa33_mc_round9}  = mix_col(sa03_sr_round9,sa13_sr_round9,sa23_sr_round9,sa33_sr_round9);
987
 
988
 
989
//add round key
990
assign sa33_next_round10 =              sa33_mc_round9 ^ w39[07:00];
991
assign sa23_next_round10 =      sa23_mc_round9 ^ w39[15:08];
992
assign sa13_next_round10 =      sa13_mc_round9 ^ w39[23:16];
993
assign sa03_next_round10 =      sa03_mc_round9 ^ w39[31:24];
994
assign sa32_next_round10 =      sa32_mc_round9 ^ w38[07:00];
995
assign sa22_next_round10 =      sa22_mc_round9 ^ w38[15:08];
996
assign sa12_next_round10 =      sa12_mc_round9 ^ w38[23:16];
997
assign sa02_next_round10 =      sa02_mc_round9 ^ w38[31:24];
998
assign sa31_next_round10 =      sa31_mc_round9 ^ w37[07:00];
999
assign sa21_next_round10 =      sa21_mc_round9 ^ w37[15:08];
1000
assign sa11_next_round10 =      sa11_mc_round9 ^ w37[23:16];
1001
assign sa01_next_round10 =      sa01_mc_round9 ^ w37[31:24];
1002
assign sa30_next_round10 =      sa30_mc_round9 ^ w36[07:00];
1003
assign sa20_next_round10 =      sa20_mc_round9 ^ w36[15:08];
1004
assign sa10_next_round10 =      sa10_mc_round9 ^ w36[23:16];
1005
assign sa00_next_round10 =      sa00_mc_round9 ^ w36[31:24];
1006
 
1007
 
1008
/////////////////////////round # 10 transformations/////////////////////////////
1009
 
1010
 
1011
//sbox lookup
1012
aes_sbox us00_round10(  .a(     sa00_next_round10       ), .d(  sa00_sub_round10        ));
1013
aes_sbox us01_round10(  .a(     sa01_next_round10       ), .d(  sa01_sub_round10        ));
1014
aes_sbox us02_round10(  .a(     sa02_next_round10       ), .d(  sa02_sub_round10        ));
1015
aes_sbox us03_round10(  .a(     sa03_next_round10       ), .d(  sa03_sub_round10        ));
1016
aes_sbox us10_round10(  .a(     sa10_next_round10       ), .d(  sa10_sub_round10        ));
1017
aes_sbox us11_round10(  .a(     sa11_next_round10       ), .d(  sa11_sub_round10        ));
1018
aes_sbox us12_round10(  .a(     sa12_next_round10       ), .d(  sa12_sub_round10        ));
1019
aes_sbox us13_round10(  .a(     sa13_next_round10       ), .d(  sa13_sub_round10        ));
1020
aes_sbox us20_round10(  .a(     sa20_next_round10       ), .d(  sa20_sub_round10        ));
1021
aes_sbox us21_round10(  .a(     sa21_next_round10       ), .d(  sa21_sub_round10        ));
1022
aes_sbox us22_round10(  .a(     sa22_next_round10       ), .d(  sa22_sub_round10        ));
1023
aes_sbox us23_round10(  .a(     sa23_next_round10       ), .d(  sa23_sub_round10        ));
1024
aes_sbox us30_round10(  .a(     sa30_next_round10       ), .d(  sa30_sub_round10        ));
1025
aes_sbox us31_round10(  .a(     sa31_next_round10       ), .d(  sa31_sub_round10        ));
1026
aes_sbox us32_round10(  .a(     sa32_next_round10       ), .d(  sa32_sub_round10        ));
1027
aes_sbox us33_round10(  .a(     sa33_next_round10       ), .d(  sa33_sub_round10        ));
1028
 
1029
//shift rows
1030
 
1031
assign sa00_sr_round10 = sa00_sub_round10;              //
1032
assign sa01_sr_round10 = sa01_sub_round10;              //no shift
1033
assign sa02_sr_round10 = sa02_sub_round10;              //
1034
assign sa03_sr_round10 = sa03_sub_round10;              //
1035
 
1036
assign sa10_sr_round10 = sa11_sub_round10;              //
1037
assign sa11_sr_round10 = sa12_sub_round10;              // left shift by 1
1038
assign sa12_sr_round10 = sa13_sub_round10;              //
1039
assign sa13_sr_round10 = sa10_sub_round10;              //
1040
 
1041
assign sa20_sr_round10 = sa22_sub_round10;              //
1042
assign sa21_sr_round10 = sa23_sub_round10;              //      left shift by 2
1043
assign sa22_sr_round10 = sa20_sub_round10;              //
1044
assign sa23_sr_round10 = sa21_sub_round10;              //
1045
 
1046
assign sa30_sr_round10 = sa33_sub_round10;              //
1047
assign sa31_sr_round10 = sa30_sub_round10;              // left shift by 3
1048
assign sa32_sr_round10 = sa31_sub_round10;              //
1049
assign sa33_sr_round10 = sa32_sub_round10;              //
1050
 
1051
 
1052
// Final text output
1053
 
1054
 
1055
always @(posedge clk)
1056
 if(aes_en && ~rst)
1057
 begin
1058
                /*  $strobe($time,": round_key2 is %h\n",{w4,w5,w6,w7});
1059
                  $strobe($time,": roundkeyeven = %h, text_out_even is %h\n",{w4,w5,w6,w7},text_out);*/
1060
                  text_out[127:120] <=  sa00_sr_round10 ^ w40[31:24];
1061
                  text_out[095:088] <=  sa01_sr_round10 ^ w41[31:24];
1062
                  text_out[063:056] <=  sa02_sr_round10 ^ w42[31:24];
1063
                  text_out[031:024] <=  sa03_sr_round10 ^ w43[31:24];
1064
                  text_out[119:112] <=  sa10_sr_round10 ^ w40[23:16];
1065
                  text_out[087:080] <=  sa11_sr_round10 ^ w41[23:16];
1066
                  text_out[055:048] <=  sa12_sr_round10 ^ w42[23:16];
1067
                  text_out[023:016] <=  sa13_sr_round10 ^ w43[23:16];
1068
                  text_out[111:104] <=  sa20_sr_round10 ^ w40[15:08];
1069
                  text_out[079:072] <=  sa21_sr_round10 ^ w41[15:08];
1070
                  text_out[047:040] <=  sa22_sr_round10 ^ w42[15:08];
1071
                  text_out[015:008] <=  sa23_sr_round10 ^ w43[15:08];
1072
                  text_out[103:096] <=  sa30_sr_round10 ^ w40[07:00];
1073
                  text_out[071:064] <=  sa31_sr_round10 ^ w41[07:00];
1074
                  text_out[039:032] <=  sa32_sr_round10 ^ w42[07:00];
1075
                  text_out[007:000] <=  sa33_sr_round10 ^ w43[07:00];
1076
        end
1077
 
1078
        else
1079
                        text_out <= 128'hx;
1080
 
1081
 
1082
always @(posedge clk)
1083
        begin
1084
/*      $strobe($time,": text_out_temp is %h\n",text_out_temp);
1085
 
1086
 
1087
*/      /*
1088
        $strobe($time,": subbytes is %h\n",{sa00_sub, sa01_sub, sa02_sub, sa03_sub,
1089
                                                                                                         sa10_sub, sa11_sub, sa12_sub, sa13_sub,
1090
                                                                                                         sa20_sub, sa21_sub, sa22_sub, sa23_sub,
1091
                                                                                                         sa30_sub, sa31_sub, sa32_sub, sa33_sub});
1092
 
1093
        $strobe($time,": shiftrows is %h\n",{sa00_sr, sa01_sr, sa02_sr, sa03_sr,
1094
                                                                                                          sa10_sr, sa11_sr, sa12_sr, sa13_sr,
1095
                                                                                                          sa20_sr, sa21_sr, sa22_sr, sa23_sr,
1096
                                                                                                          sa30_sr, sa31_sr, sa32_sr, sa33_sr});
1097
 
1098
        $strobe($time,": mixcolumn is %h\n",{sa00_mc, sa01_mc, sa02_mc, sa03_mc,
1099
                                                                                                          sa10_mc, sa11_mc, sa12_mc, sa13_mc,
1100
                                                                                                          sa20_mc, sa21_mc, sa22_mc, sa23_mc,
1101
                                                                                                          sa30_mc, sa31_mc, sa32_mc, sa33_mc});
1102
 
1103
        $strobe($time,": sa_next_into_even is %h\n",{sa00_next_round2, sa01_next_round2, sa02_next_round2, sa03_next_round2,
1104
                                                                                                                                 sa10_next_round2, sa11_next_round2, sa12_next_round2, sa13_next_round2,
1105
                                                                                                                                 sa20_next_round2, sa21_next_round2, sa22_next_round2, sa23_next_round2,
1106
                                                                                                                                 sa30_next_round2, sa31_next_round2, sa32_next_round2, sa33_next_round2});
1107
 
1108
        $strobe($time,": subbytes_e is %h\n",{sa00_sub_round2, sa01_sub_round2, sa02_sub_round2, sa03_sub_round2,
1109
                                                                                                         sa10_sub_round2, sa11_sub_round2, sa12_sub_round2, sa13_sub_round2,
1110
                                                                                                         sa20_sub_round2, sa21_sub_round2, sa22_sub_round2, sa23_sub_round2,
1111
                                                                                                         sa30_sub_round2, sa31_sub_round2, sa32_sub_round2, sa33_sub_round2});
1112
 
1113
        $strobe($time,": shiftrows_e is %h\n",{sa00_sr_round2, sa01_sr_round2, sa02_sr_round2, sa03_sr_round2,
1114
                                                                                                          sa10_sr_round2, sa11_sr_round2, sa12_sr_round2, sa13_sr_round2,
1115
                                                                                                          sa20_sr_round2, sa21_sr_round2, sa22_sr_round2, sa23_sr_round2,
1116
                                                                                                          sa30_sr_round2, sa31_sr_round2, sa32_sr_round2, sa33_sr_round2});
1117
 
1118
        $strobe($time,": mixcolumn_e is %h\n",{sa00_mc_round2, sa01_mc_round2, sa02_mc_round2, sa03_mc_round2,
1119
                                                                                                          sa10_mc_round2, sa11_mc_round2, sa12_mc_round2, sa13_mc_round2,
1120
                                                                                                          sa20_mc_round2, sa21_mc_round2, sa22_mc_round2, sa23_mc_round2,
1121
                                                                                                          sa30_mc_round2, sa31_mc_round2, sa32_mc_round2, sa33_mc_round2});
1122
        */
1123
        end
1124
 
1125
 
1126
/*
1127
always @(posedge clk)
1128
       begin
1129
                                if(done)
1130
                                                begin
1131
                                                        text_out_64 <= text_out[127:64];
1132
//                                                      done2 <= 1;
1133
                                                end
1134
                                else if(~done)
1135
                                                        text_out_64 <= text_out[63:0];
1136
                end
1137
        */
1138
 
1139
/*
1140
always @(posedge clk)
1141
                         begin
1142
                                if(done2)
1143
                                        begin
1144
                                                text_out_64 <= text_out[63:0];
1145
                                        end
1146
                 end
1147
*/
1148
////////////////////////////////////////////////////////////////////
1149
//
1150
// Generic Functions
1151
//
1152
 
1153
function [31:0] mix_col;
1154
input   [7:0]    s0,s1,s2,s3;
1155
//reg   [7:0]   s0_o,s1_o,s2_o,s3_o;
1156
begin
1157
mix_col[31:24]=xtime(s0)^xtime(s1)^s1^s2^s3;
1158
mix_col[23:16]=s0^xtime(s1)^xtime(s2)^s2^s3;
1159
mix_col[15:08]=s0^s1^xtime(s2)^xtime(s3)^s3;
1160
mix_col[07:00]=xtime(s0)^s0^s1^s2^xtime(s3);
1161
end
1162
endfunction
1163
 
1164
function [7:0] xtime;
1165
input [7:0] b; xtime={b[6:0],1'b0}^(8'h1b&{8{b[7]}});
1166
endfunction
1167
 
1168
 
1169
 
1170
endmodule
1171
 
1172
 
1173
 

powered by: WebSVN 2.1.0

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