OpenCores
URL https://opencores.org/ocsvn/aes_decrypt_fpga/aes_decrypt_fpga/trunk

Subversion Repositories aes_decrypt_fpga

[/] [aes_decrypt_fpga/] [trunk/] [rtl/] [verilog/] [Sbox.sv] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 schengopen
////////////////////////////////////////////////////////////////// ////
2
////                                                                                                                            ////
3
//// AES Decryption Core for FPGA                                                                       ////
4
////                                                                                                                            ////
5
//// This file is part of the AES Decryption Core for FPGA project      ////
6
//// http://www.opencores.org/cores/xxx/                                                        ////
7
////                                                                                                                            ////
8
//// Description                                                                                                        ////
9
//// Implementation of  AES Decryption Core for FPGA according to       ////
10
//// core specification document.                                                                       ////
11
////                                                                                                                            ////
12
//// To Do:                                                                                                             ////
13
//// -                                                                                                                          ////
14
////                                                                                                                            ////
15
//// Author(s):                                                                                                         ////
16
//// - scheng, schengopencores@opencores.org                                            ////
17
////                                                                                                                            ////
18
//////////////////////////////////////////////////////////////////////
19
////                                                                                                                            ////
20
//// Copyright (C) 2009 Authors and OPENCORES.ORG                                       ////
21
////                                                                                                                            ////
22
//// This source file may be used and distributed without                       ////
23
//// restriction provided that this copyright statement is not          ////
24
//// removed from the file and that any derivative work contains        ////
25
//// the original copyright notice and the associated disclaimer.       ////
26
////                                                                                                                            ////
27
//// This source file is free software; you can redistribute it         ////
28
//// and/or modify it under the terms of the GNU Lesser General         ////
29
//// Public License as published by the Free Software Foundation;       ////
30
//// either version 2.1 of the License, or (at your option) any         ////
31
//// later version.                                                                                             ////
32
////                                                                                                                            ////
33
//// This source is distributed in the hope that it will be             ////
34
//// useful, but WITHOUT ANY WARRANTY; without even the implied         ////
35
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR            ////
36
//// PURPOSE. See the GNU Lesser General Public License for more        ////
37
//// details.                                                                                                           ////
38
////                                                                                                                            ////
39
//// You should have received a copy of the GNU Lesser General          ////
40
//// Public License along with this source; if not, download it         ////
41
//// from http://www.opencores.org/lgpl.shtml                                           ////
42
////                                                                                                                            //// ///
43
///////////////////////////////////////////////////////////////////
44
////                                                                                                                            ////
45
//// This file implements the SBox transform as described in            ////
46
//// section 5.1.1 of the FIPS-197 specification. It is used to         ////
47
//// implement the SubWord() transform in Key Expansion.                        ////
48
////                                                                                                                            ////
49
////////////////////////////////////////////////////////////////////////
50
 
51
module Sbox(
52
    input [7:0] d,
53
    output [7:0] q
54
    );
55
 
56
    wire [7:0] q0, q1, q2, q3;
57
    wire [7:0] r0, r1;
58
 
59
    Sbox_table0 t0(.d(d[5:0]), .q(q0));
60
    Sbox_table1 t1(.d(d[5:0]), .q(q1));
61
    Sbox_table2 t2(.d(d[5:0]), .q(q2));
62
    Sbox_table3 t3(.d(d[5:0]), .q(q3));
63
 
64
    genvar j;
65
    generate
66
        for (j=0; j<8; j++)
67
        begin
68
            MUXF7 muxf7_lo(.O(r0[j]), .I0(q0[j]), .I1(q1[j]), .S(d[6]));
69
            MUXF7 muxf7_hi(.O(r1[j]), .I0(q2[j]), .I1(q3[j]), .S(d[6]));
70
            MUXF8 muxf8_u(.O(q[j]), .I0(r0[j]), .I1(r1[j]), .S(d[7]));
71
        end
72
    endgenerate
73
 
74
endmodule
75
 
76
// The SBox transform is divided into 4 tables, each 64 entries by 8-bit.
77
 
78
// The "keep_hierarchy" attribute is there to prevent the tool from further
79
// optimizing the table, thereby forcing it to infer 8 LUT6 for each table.
80
// This allows the table output to feed the MUXF7 in the same slice, forcing
81
// the tool to pack the LUT6 and MUXFX into the same slice.
82
 
83
(* keep_hierarchy = "yes" *) module Sbox_table0(input [5:0] d, output [7:0] q);
84
        logic [7:0] p0;
85
 
86
        always_comb
87
                case (d)
88
                        6'h00 : p0 <= 8'h63;
89
                        6'h01 : p0 <= 8'h7c;
90
                        6'h02 : p0 <= 8'h77;
91
                        6'h03 : p0 <= 8'h7b;
92
                        6'h04 : p0 <= 8'hf2;
93
                        6'h05 : p0 <= 8'h6b;
94
                        6'h06 : p0 <= 8'h6f;
95
                        6'h07 : p0 <= 8'hc5;
96
                        6'h08 : p0 <= 8'h30;
97
                        6'h09 : p0 <= 8'h01;
98
                        6'h0a : p0 <= 8'h67;
99
                        6'h0b : p0 <= 8'h2b;
100
                        6'h0c : p0 <= 8'hfe;
101
                        6'h0d : p0 <= 8'hd7;
102
                        6'h0e : p0 <= 8'hab;
103
                        6'h0f : p0 <= 8'h76;
104
                        6'h10 : p0 <= 8'hca;
105
                        6'h11 : p0 <= 8'h82;
106
                        6'h12 : p0 <= 8'hc9;
107
                        6'h13 : p0 <= 8'h7d;
108
                        6'h14 : p0 <= 8'hfa;
109
                        6'h15 : p0 <= 8'h59;
110
                        6'h16 : p0 <= 8'h47;
111
                        6'h17 : p0 <= 8'hf0;
112
                        6'h18 : p0 <= 8'had;
113
                        6'h19 : p0 <= 8'hd4;
114
                        6'h1a : p0 <= 8'ha2;
115
                        6'h1b : p0 <= 8'haf;
116
                        6'h1c : p0 <= 8'h9c;
117
                        6'h1d : p0 <= 8'ha4;
118
                        6'h1e : p0 <= 8'h72;
119
                        6'h1f : p0 <= 8'hc0;
120
                        6'h20 : p0 <= 8'hb7;
121
                        6'h21 : p0 <= 8'hfd;
122
                        6'h22 : p0 <= 8'h93;
123
                        6'h23 : p0 <= 8'h26;
124
                        6'h24 : p0 <= 8'h36;
125
                        6'h25 : p0 <= 8'h3f;
126
                        6'h26 : p0 <= 8'hf7;
127
                        6'h27 : p0 <= 8'hcc;
128
                        6'h28 : p0 <= 8'h34;
129
                        6'h29 : p0 <= 8'ha5;
130
                        6'h2a : p0 <= 8'he5;
131
                        6'h2b : p0 <= 8'hf1;
132
                        6'h2c : p0 <= 8'h71;
133
                        6'h2d : p0 <= 8'hd8;
134
                        6'h2e : p0 <= 8'h31;
135
                        6'h2f : p0 <= 8'h15;
136
                        6'h30 : p0 <= 8'h04;
137
                        6'h31 : p0 <= 8'hc7;
138
                        6'h32 : p0 <= 8'h23;
139
                        6'h33 : p0 <= 8'hc3;
140
                        6'h34 : p0 <= 8'h18;
141
                        6'h35 : p0 <= 8'h96;
142
                        6'h36 : p0 <= 8'h05;
143
                        6'h37 : p0 <= 8'h9a;
144
                        6'h38 : p0 <= 8'h07;
145
                        6'h39 : p0 <= 8'h12;
146
                        6'h3a : p0 <= 8'h80;
147
                        6'h3b : p0 <= 8'he2;
148
                        6'h3c : p0 <= 8'heb;
149
                        6'h3d : p0 <= 8'h27;
150
                        6'h3e : p0 <= 8'hb2;
151
                        6'h3f : p0 <= 8'h75;
152
                endcase
153
 
154
        assign q = p0;
155
endmodule
156
 
157
(* keep_hierarchy = "yes" *) module Sbox_table1(input [5:0] d, output [7:0] q);
158
        logic [7:0] p1;
159
 
160
        always_comb
161
                case (d)
162
                        6'h00 : p1 <= 8'h09;
163
                        6'h01 : p1 <= 8'h83;
164
                        6'h02 : p1 <= 8'h2c;
165
                        6'h03 : p1 <= 8'h1a;
166
                        6'h04 : p1 <= 8'h1b;
167
                        6'h05 : p1 <= 8'h6e;
168
                        6'h06 : p1 <= 8'h5a;
169
                        6'h07 : p1 <= 8'ha0;
170
                        6'h08 : p1 <= 8'h52;
171
                        6'h09 : p1 <= 8'h3b;
172
                        6'h0a : p1 <= 8'hd6;
173
                        6'h0b : p1 <= 8'hb3;
174
                        6'h0c : p1 <= 8'h29;
175
                        6'h0d : p1 <= 8'he3;
176
                        6'h0e : p1 <= 8'h2f;
177
                        6'h0f : p1 <= 8'h84;
178
                        6'h10 : p1 <= 8'h53;
179
                        6'h11 : p1 <= 8'hd1;
180
                        6'h12 : p1 <= 8'h00;
181
                        6'h13 : p1 <= 8'hed;
182
                        6'h14 : p1 <= 8'h20;
183
                        6'h15 : p1 <= 8'hfc;
184
                        6'h16 : p1 <= 8'hb1;
185
                        6'h17 : p1 <= 8'h5b;
186
                        6'h18 : p1 <= 8'h6a;
187
                        6'h19 : p1 <= 8'hcb;
188
                        6'h1a : p1 <= 8'hbe;
189
                        6'h1b : p1 <= 8'h39;
190
                        6'h1c : p1 <= 8'h4a;
191
                        6'h1d : p1 <= 8'h4c;
192
                        6'h1e : p1 <= 8'h58;
193
                        6'h1f : p1 <= 8'hcf;
194
                        6'h20 : p1 <= 8'hd0;
195
                        6'h21 : p1 <= 8'hef;
196
                        6'h22 : p1 <= 8'haa;
197
                        6'h23 : p1 <= 8'hfb;
198
                        6'h24 : p1 <= 8'h43;
199
                        6'h25 : p1 <= 8'h4d;
200
                        6'h26 : p1 <= 8'h33;
201
                        6'h27 : p1 <= 8'h85;
202
                        6'h28 : p1 <= 8'h45;
203
                        6'h29 : p1 <= 8'hf9;
204
                        6'h2a : p1 <= 8'h02;
205
                        6'h2b : p1 <= 8'h7f;
206
                        6'h2c : p1 <= 8'h50;
207
                        6'h2d : p1 <= 8'h3c;
208
                        6'h2e : p1 <= 8'h9f;
209
                        6'h2f : p1 <= 8'ha8;
210
                        6'h30 : p1 <= 8'h51;
211
                        6'h31 : p1 <= 8'ha3;
212
                        6'h32 : p1 <= 8'h40;
213
                        6'h33 : p1 <= 8'h8f;
214
                        6'h34 : p1 <= 8'h92;
215
                        6'h35 : p1 <= 8'h9d;
216
                        6'h36 : p1 <= 8'h38;
217
                        6'h37 : p1 <= 8'hf5;
218
                        6'h38 : p1 <= 8'hbc;
219
                        6'h39 : p1 <= 8'hb6;
220
                        6'h3a : p1 <= 8'hda;
221
                        6'h3b : p1 <= 8'h21;
222
                        6'h3c : p1 <= 8'h10;
223
                        6'h3d : p1 <= 8'hff;
224
                        6'h3e : p1 <= 8'hf3;
225
                        6'h3f : p1 <= 8'hd2;
226
                endcase
227
        assign q = p1;
228
endmodule
229
 
230
(* keep_hierarchy = "yes" *) module Sbox_table2(input [5:0] d, output [7:0] q);
231
        logic [7:0] p2;
232
 
233
        always_comb
234
                case (d)
235
                        6'h00 : p2 <= 8'hcd;
236
                        6'h01 : p2 <= 8'h0c;
237
                        6'h02 : p2 <= 8'h13;
238
                        6'h03 : p2 <= 8'hec;
239
                        6'h04 : p2 <= 8'h5f;
240
                        6'h05 : p2 <= 8'h97;
241
                        6'h06 : p2 <= 8'h44;
242
                        6'h07 : p2 <= 8'h17;
243
                        6'h08 : p2 <= 8'hc4;
244
                        6'h09 : p2 <= 8'ha7;
245
                        6'h0a : p2 <= 8'h7e;
246
                        6'h0b : p2 <= 8'h3d;
247
                        6'h0c : p2 <= 8'h64;
248
                        6'h0d : p2 <= 8'h5d;
249
                        6'h0e : p2 <= 8'h19;
250
                        6'h0f : p2 <= 8'h73;
251
                        6'h10 : p2 <= 8'h60;
252
                        6'h11 : p2 <= 8'h81;
253
                        6'h12 : p2 <= 8'h4f;
254
                        6'h13 : p2 <= 8'hdc;
255
                        6'h14 : p2 <= 8'h22;
256
                        6'h15 : p2 <= 8'h2a;
257
                        6'h16 : p2 <= 8'h90;
258
                        6'h17 : p2 <= 8'h88;
259
                        6'h18 : p2 <= 8'h46;
260
                        6'h19 : p2 <= 8'hee;
261
                        6'h1a : p2 <= 8'hb8;
262
                        6'h1b : p2 <= 8'h14;
263
                        6'h1c : p2 <= 8'hde;
264
                        6'h1d : p2 <= 8'h5e;
265
                        6'h1e : p2 <= 8'h0b;
266
                        6'h1f : p2 <= 8'hdb;
267
                        6'h20 : p2 <= 8'he0;
268
                        6'h21 : p2 <= 8'h32;
269
                        6'h22 : p2 <= 8'h3a;
270
                        6'h23 : p2 <= 8'h0a;
271
                        6'h24 : p2 <= 8'h49;
272
                        6'h25 : p2 <= 8'h06;
273
                        6'h26 : p2 <= 8'h24;
274
                        6'h27 : p2 <= 8'h5c;
275
                        6'h28 : p2 <= 8'hc2;
276
                        6'h29 : p2 <= 8'hd3;
277
                        6'h2a : p2 <= 8'hac;
278
                        6'h2b : p2 <= 8'h62;
279
                        6'h2c : p2 <= 8'h91;
280
                        6'h2d : p2 <= 8'h95;
281
                        6'h2e : p2 <= 8'he4;
282
                        6'h2f : p2 <= 8'h79;
283
                        6'h30 : p2 <= 8'he7;
284
                        6'h31 : p2 <= 8'hc8;
285
                        6'h32 : p2 <= 8'h37;
286
                        6'h33 : p2 <= 8'h6d;
287
                        6'h34 : p2 <= 8'h8d;
288
                        6'h35 : p2 <= 8'hd5;
289
                        6'h36 : p2 <= 8'h4e;
290
                        6'h37 : p2 <= 8'ha9;
291
                        6'h38 : p2 <= 8'h6c;
292
                        6'h39 : p2 <= 8'h56;
293
                        6'h3a : p2 <= 8'hf4;
294
                        6'h3b : p2 <= 8'hea;
295
                        6'h3c : p2 <= 8'h65;
296
                        6'h3d : p2 <= 8'h7a;
297
                        6'h3e : p2 <= 8'hae;
298
                        6'h3f : p2 <= 8'h08;
299
                endcase
300
        assign q = p2;
301
endmodule
302
 
303
(* keep_hierarchy = "yes" *) module Sbox_table3(input [5:0] d, output [7:0] q);
304
        logic [7:0] p3;
305
 
306
        always_comb
307
                case (d)
308
                        6'h00 : p3 <= 8'hba;
309
                        6'h01 : p3 <= 8'h78;
310
                        6'h02 : p3 <= 8'h25;
311
                        6'h03 : p3 <= 8'h2e;
312
                        6'h04 : p3 <= 8'h1c;
313
                        6'h05 : p3 <= 8'ha6;
314
                        6'h06 : p3 <= 8'hb4;
315
                        6'h07 : p3 <= 8'hc6;
316
                        6'h08 : p3 <= 8'he8;
317
                        6'h09 : p3 <= 8'hdd;
318
                        6'h0a : p3 <= 8'h74;
319
                        6'h0b : p3 <= 8'h1f;
320
                        6'h0c : p3 <= 8'h4b;
321
                        6'h0d : p3 <= 8'hbd;
322
                        6'h0e : p3 <= 8'h8b;
323
                        6'h0f : p3 <= 8'h8a;
324
                        6'h10 : p3 <= 8'h70;
325
                        6'h11 : p3 <= 8'h3e;
326
                        6'h12 : p3 <= 8'hb5;
327
                        6'h13 : p3 <= 8'h66;
328
                        6'h14 : p3 <= 8'h48;
329
                        6'h15 : p3 <= 8'h03;
330
                        6'h16 : p3 <= 8'hf6;
331
                        6'h17 : p3 <= 8'h0e;
332
                        6'h18 : p3 <= 8'h61;
333
                        6'h19 : p3 <= 8'h35;
334
                        6'h1a : p3 <= 8'h57;
335
                        6'h1b : p3 <= 8'hb9;
336
                        6'h1c : p3 <= 8'h86;
337
                        6'h1d : p3 <= 8'hc1;
338
                        6'h1e : p3 <= 8'h1d;
339
                        6'h1f : p3 <= 8'h9e;
340
                        6'h20 : p3 <= 8'he1;
341
                        6'h21 : p3 <= 8'hf8;
342
                        6'h22 : p3 <= 8'h98;
343
                        6'h23 : p3 <= 8'h11;
344
                        6'h24 : p3 <= 8'h69;
345
                        6'h25 : p3 <= 8'hd9;
346
                        6'h26 : p3 <= 8'h8e;
347
                        6'h27 : p3 <= 8'h94;
348
                        6'h28 : p3 <= 8'h9b;
349
                        6'h29 : p3 <= 8'h1e;
350
                        6'h2a : p3 <= 8'h87;
351
                        6'h2b : p3 <= 8'he9;
352
                        6'h2c : p3 <= 8'hce;
353
                        6'h2d : p3 <= 8'h55;
354
                        6'h2e : p3 <= 8'h28;
355
                        6'h2f : p3 <= 8'hdf;
356
                        6'h30 : p3 <= 8'h8c;
357
                        6'h31 : p3 <= 8'ha1;
358
                        6'h32 : p3 <= 8'h89;
359
                        6'h33 : p3 <= 8'h0d;
360
                        6'h34 : p3 <= 8'hbf;
361
                        6'h35 : p3 <= 8'he6;
362
                        6'h36 : p3 <= 8'h42;
363
                        6'h37 : p3 <= 8'h68;
364
                        6'h38 : p3 <= 8'h41;
365
                        6'h39 : p3 <= 8'h99;
366
                        6'h3a : p3 <= 8'h2d;
367
                        6'h3b : p3 <= 8'h0f;
368
                        6'h3c : p3 <= 8'hb0;
369
                        6'h3d : p3 <= 8'h54;
370
                        6'h3e : p3 <= 8'hbb;
371
                        6'h3f : p3 <= 8'h16;
372
                endcase
373
        assign q = p3;
374
endmodule

powered by: WebSVN 2.1.0

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