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