1 |
2 |
tariq786 |
/////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// AES Key Expand Block (for 128 bit keys) ////
|
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 |
|
|
//// Modified to achieve 1 cycle functionality ////
|
39 |
|
|
//// By Tariq Bashir Ahmad ////
|
40 |
|
|
//// tariq.bashir@gmail.com ////
|
41 |
|
|
//// http://www.ecs.umass.edu/~tbashir ////
|
42 |
|
|
|
43 |
|
|
|
44 |
|
|
`timescale 1 ns/1 ps
|
45 |
|
|
|
46 |
|
|
module aes_key_expand_128(clk, key, w0,w1,w2,w3,w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14, w15, w16, w17,
|
47 |
|
|
w18, w19, w20, w21, w22, w23, w24, w25, w26, w27, w28, w29, w30, w31, w32, w33,
|
48 |
|
|
w34, w35, w36, w37, w38, w39, w40, w41, w42, w43);
|
49 |
|
|
input clk;
|
50 |
|
|
input [127:0] key;
|
51 |
|
|
output reg [31:0] w0,w1,w2,w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14, w15, w16, w17,
|
52 |
|
|
w18, w19, w20, w21, w22, w23, w24, w25, w26, w27, w28, w29, w30, w31, w32, w33,
|
53 |
|
|
w34, w35, w36, w37, w38, w39, w40, w41, w42, w43;
|
54 |
|
|
wire [31:0] subword, subword2,subword3,subword4,subword5, subword6, subword7,subword8,subword9,subword10;
|
55 |
|
|
wire [7:0] rcon, rcon2,rcon3,rcon4,rcon5, rcon6, rcon7,rcon8,rcon9,rcon10;
|
56 |
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
|
|
always @*
|
61 |
|
|
begin
|
62 |
|
|
|
63 |
|
|
w0 = key[127:096];
|
64 |
|
|
w1 = key[095:064];
|
65 |
|
|
w2 = key[063:032];
|
66 |
|
|
w3 = key[031:000];
|
67 |
|
|
|
68 |
|
|
w4 = key[127:096]^subword^{8'h01,24'b0};
|
69 |
|
|
w5 = key[095:064]^key[127:096]^subword^{8'h01,24'b0};
|
70 |
|
|
w6 = key[063:032]^key[095:064]^key[127:096]^subword^{8'h01,24'b0};
|
71 |
|
|
w7 = key[127:096]^key[095:064]^key[063:032]^key[031:000]^subword^{8'h01,24'b0};
|
72 |
|
|
|
73 |
|
|
w8 = w4^subword2^{rcon2,24'b0};
|
74 |
|
|
w9 = w5^w4^subword2^{rcon2,24'b0};
|
75 |
|
|
w10 = w6^w5^w4^subword2^{rcon2,24'b0};
|
76 |
|
|
w11 = w7^w6^w5^w4^subword2^{rcon2,24'b0};
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
w12 = w8^subword3^{rcon3,24'b0};
|
80 |
|
|
w13 = w8^w9^subword3^{rcon3,24'b0};
|
81 |
|
|
w14 = w8^w9^w10^subword3^{rcon3,24'b0};
|
82 |
|
|
w15 = w8^w9^w10^w11^subword3^{rcon3,24'b0};
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
w16 = w12^subword4^{rcon4,24'b0};
|
86 |
|
|
w17 = w12^w13^subword4^{rcon4,24'b0};
|
87 |
|
|
w18 = w12^w13^w14^subword4^{rcon4,24'b0};
|
88 |
|
|
w19 = w12^w13^w14^w15^subword4^{rcon4,24'b0};
|
89 |
|
|
|
90 |
|
|
|
91 |
|
|
w20 = w16^subword5^{rcon5,24'b0};
|
92 |
|
|
w21 = w16^w17^subword5^{rcon5,24'b0};
|
93 |
|
|
w22 = w16^w17^w18^subword5^{rcon5,24'b0};
|
94 |
|
|
w23 = w16^w17^w18^w19^subword5^{rcon5,24'b0};
|
95 |
|
|
|
96 |
|
|
|
97 |
|
|
w24 = w20^subword6^{rcon6,24'b0};
|
98 |
|
|
w25 = w20^w21^subword6^{rcon6,24'b0};
|
99 |
|
|
w26 = w20^w21^w22^subword6^{rcon6,24'b0};
|
100 |
|
|
w27 = w20^w21^w22^w23^subword6^{rcon6,24'b0};
|
101 |
|
|
|
102 |
|
|
w28 = w24^subword7^{rcon7,24'b0};
|
103 |
|
|
w29 = w24^w25^subword7^{rcon7,24'b0};
|
104 |
|
|
w30 = w24^w25^w26^subword7^{rcon7,24'b0};
|
105 |
|
|
w31 = w24^w25^w26^w27^subword7^{rcon7,24'b0};
|
106 |
|
|
|
107 |
|
|
|
108 |
|
|
w32 = w28^subword8^{rcon8,24'b0};
|
109 |
|
|
w33 = w28^w29^subword8^{rcon8,24'b0};
|
110 |
|
|
w34 = w28^w29^w30^subword8^{rcon8,24'b0};
|
111 |
|
|
w35 = w28^w29^w30^w31^subword8^{rcon8,24'b0};
|
112 |
|
|
|
113 |
|
|
w36 = w32^subword9^{rcon9,24'b0};
|
114 |
|
|
w37 = w32^w33^subword9^{rcon9,24'b0};
|
115 |
|
|
w38 = w32^w33^w34^subword9^{rcon9,24'b0};
|
116 |
|
|
w39 = w32^w33^w34^w35^subword9^{rcon9,24'b0};
|
117 |
|
|
|
118 |
|
|
w40 = w36^subword10^{rcon10,24'b0};
|
119 |
|
|
w41 = w36^w37^subword10^{rcon10,24'b0};
|
120 |
|
|
w42 = w36^w37^w38^subword10^{rcon10,24'b0};
|
121 |
|
|
w43 = w36^w37^w38^w39^subword10^{rcon10,24'b0};
|
122 |
|
|
|
123 |
|
|
/*$display($time,": subword5 is %h\n",subword2);
|
124 |
|
|
$display($time,": rcon5 is %h\n",rcon5);
|
125 |
|
|
$display($time,": key5 is %h, key6 is %h\n",{w16,w17,w18,w19},{w20,w21,w22,w23});*/
|
126 |
|
|
|
127 |
|
|
end
|
128 |
|
|
|
129 |
|
|
aes_rcon inst5(.clk(clk), .out(rcon), .out2(rcon2),
|
130 |
|
|
.out3(rcon3), .out4(rcon4),
|
131 |
|
|
.out5(rcon5), .out6(rcon6),
|
132 |
|
|
.out7(rcon7), .out8(rcon8),
|
133 |
|
|
.out9(rcon9), .out10(rcon10));
|
134 |
|
|
|
135 |
|
|
aes_sbox u0( .a(w3[23:16]), .d(subword[31:24]));
|
136 |
|
|
aes_sbox u1( .a(w3[15:08]), .d(subword[23:16]));
|
137 |
|
|
aes_sbox u2( .a(w3[07:00]), .d(subword[15:08]));
|
138 |
|
|
aes_sbox u3( .a(w3[31:24]), .d(subword[07:00]));
|
139 |
|
|
|
140 |
|
|
aes_sbox u4( .a(w7[23:16]), .d(subword2[31:24]));
|
141 |
|
|
aes_sbox u5( .a(w7[15:08]), .d(subword2[23:16]));
|
142 |
|
|
aes_sbox u6( .a(w7[07:00]), .d(subword2[15:08]));
|
143 |
|
|
aes_sbox u7( .a(w7[31:24]), .d(subword2[07:00]));
|
144 |
|
|
|
145 |
|
|
|
146 |
|
|
aes_sbox u8( .a(w11[23:16]), .d(subword3[31:24]));
|
147 |
|
|
aes_sbox u9( .a(w11[15:08]), .d(subword3[23:16]));
|
148 |
|
|
aes_sbox u10( .a(w11[07:00]), .d(subword3[15:08]));
|
149 |
|
|
aes_sbox u11( .a(w11[31:24]), .d(subword3[07:00]));
|
150 |
|
|
|
151 |
|
|
|
152 |
|
|
aes_sbox u12( .a(w15[23:16]), .d(subword4[31:24]));
|
153 |
|
|
aes_sbox u13( .a(w15[15:08]), .d(subword4[23:16]));
|
154 |
|
|
aes_sbox u14( .a(w15[07:00]), .d(subword4[15:08]));
|
155 |
|
|
aes_sbox u15( .a(w15[31:24]), .d(subword4[07:00]));
|
156 |
|
|
|
157 |
|
|
aes_sbox u16( .a(w19[23:16]), .d(subword5[31:24]));
|
158 |
|
|
aes_sbox u17( .a(w19[15:08]), .d(subword5[23:16]));
|
159 |
|
|
aes_sbox u18( .a(w19[07:00]), .d(subword5[15:08]));
|
160 |
|
|
aes_sbox u19( .a(w19[31:24]), .d(subword5[07:00]));
|
161 |
|
|
|
162 |
|
|
aes_sbox u20( .a(w23[23:16]), .d(subword6[31:24]));
|
163 |
|
|
aes_sbox u21( .a(w23[15:08]), .d(subword6[23:16]));
|
164 |
|
|
aes_sbox u22( .a(w23[07:00]), .d(subword6[15:08]));
|
165 |
|
|
aes_sbox u23( .a(w23[31:24]), .d(subword6[07:00]));
|
166 |
|
|
|
167 |
|
|
aes_sbox u24( .a(w27[23:16]), .d(subword7[31:24]));
|
168 |
|
|
aes_sbox u25( .a(w27[15:08]), .d(subword7[23:16]));
|
169 |
|
|
aes_sbox u26( .a(w27[07:00]), .d(subword7[15:08]));
|
170 |
|
|
aes_sbox u27( .a(w27[31:24]), .d(subword7[07:00]));
|
171 |
|
|
|
172 |
|
|
aes_sbox u28( .a(w31[23:16]), .d(subword8[31:24]));
|
173 |
|
|
aes_sbox u29( .a(w31[15:08]), .d(subword8[23:16]));
|
174 |
|
|
aes_sbox u30( .a(w31[07:00]), .d(subword8[15:08]));
|
175 |
|
|
aes_sbox u31( .a(w31[31:24]), .d(subword8[07:00]));
|
176 |
|
|
|
177 |
|
|
aes_sbox u32( .a(w35[23:16]), .d(subword9[31:24]));
|
178 |
|
|
aes_sbox u33( .a(w35[15:08]), .d(subword9[23:16]));
|
179 |
|
|
aes_sbox u34( .a(w35[07:00]), .d(subword9[15:08]));
|
180 |
|
|
aes_sbox u35( .a(w35[31:24]), .d(subword9[07:00]));
|
181 |
|
|
|
182 |
|
|
aes_sbox u36( .a(w39[23:16]), .d(subword10[31:24]));
|
183 |
|
|
aes_sbox u37( .a(w39[15:08]), .d(subword10[23:16]));
|
184 |
|
|
aes_sbox u38( .a(w39[07:00]), .d(subword10[15:08]));
|
185 |
|
|
aes_sbox u39( .a(w39[31:24]), .d(subword10[07:00]));
|
186 |
|
|
|
187 |
|
|
|
188 |
|
|
endmodule
|
189 |
|
|
|