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

Subversion Repositories aes-encryption

[/] [aes-encryption/] [trunk/] [aes_10cycle_10stage/] [aes_key_expand_128.v] - Blame information for rev 2

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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