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

Subversion Repositories aes-encryption

[/] [aes-encryption/] [trunk/] [aes_5cycle_2stage/] [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
 
40
`timescale 1 ns/1 ps
41
 
42
module aes_key_expand_128(clk, kld, key, w0,w1,w2,w3,w4_reg,w5_reg,w6_reg,w7_reg);
43
input           clk;
44
input           kld;
45
input   [127:0]  key;
46
output reg      [31:0]   w0,w1,w2,w3;
47
                 reg [31:0]         w4,w5,w6,w7;
48
 
49
output reg   [31:0]   w4_reg,w5_reg,w6_reg,w7_reg;
50
wire    [31:0]   tmp_w,tmp_w2;
51
wire    [31:0]   subword, subword2;
52
wire    [31:0]   rcon, rcon2;                    //round constant
53
 
54
 
55
 
56
always @(posedge clk)
57
begin
58
        w4_reg <=  w4;
59
        w5_reg <=  w5;
60
        w6_reg <=  w6;
61
        w7_reg <=  w7;
62
/*   $strobe($time,": next round_key is %h\n",{w4_reg,w5_reg,w6_reg,w7_reg});
63
*/end
64
 
65
 
66
always @*
67
begin
68
 
69
w0 =  kld ? key[127:096] :w4_reg^subword2^{rcon[31:24],24'b0};
70
w1 =  kld ? key[095:064] :w5_reg^w4_reg^subword2^{rcon[31:24],24'b0};
71
w2 =  kld ? key[063:032] :w6_reg^w5_reg^w4_reg^subword2^{rcon[31:24],24'b0};
72
w3 =  kld ? key[031:000] :w7_reg^w6_reg^w5_reg^w4_reg^subword2^{rcon[31:24],24'b0};
73
 
74
w4 =  (1'b0)? key[127:096]^subword^{8'h01,24'b0} : w0^subword^{rcon2[31:24],24'b0};
75
w5 =  (1'b0)? key[095:064]^key[127:096]^subword^{8'h01,24'b0} :w1^w0^subword^{rcon2[31:24],24'b0};
76
w6 =  (1'b0)? key[063:032]^key[095:064]^key[127:096]^subword^{8'h01,24'b0} : w2^w1^w0^subword^{rcon2[31:24],24'b0};
77
w7 =  (1'b0)? key[127:096]^key[095:064]^key[063:032]^key[031:000]^subword^{8'h01,24'b0} : w3^w2^w1^w0^subword^{rcon2[31:24],24'b0};
78
 
79
/*$display($time,": rcon is %d, rcon2 is %d\n",rcon[31:24],rcon2[31:24]);*/
80
/*$display($time,": round_key is %h\n",{w0,w1,w2,w3});
81
$display($time,": next_round_key is %h\n",{w4,w5,w6,w7});*/
82
end
83
 
84
 
85
/*assign tmp_w =  w3;  //subword
86
assign tmp_w2 = w7 ;  //subword2
87
*/
88
/*
89
assign subword[31:24]     = aes_sbox(tmp_w[23:16]);
90
assign subword[23:16]     = aes_sbox(tmp_w[15:08]);
91
assign subword[15:08]     = aes_sbox(tmp_w[07:00]);
92
assign subword[07:00]     = aes_sbox(tmp_w[31:24]);
93
*/
94
 
95
aes_sbox inst1( .a(w3[23:16]), .d(subword[31:24]));
96
aes_sbox inst2( .a(w3[15:08]), .d(subword[23:16]));
97
aes_sbox inst3( .a(w3[07:00]), .d(subword[15:08]));
98
aes_sbox inst4( .a(w3[31:24]), .d(subword[07:00]));
99
aes_rcon inst5(.clk(clk), .kld(kld), .out(rcon[31:24]), .out2(rcon2[31:24]));
100
 
101
 
102
aes_sbox u4(    .a(w7_reg[23:16]), .d(subword2[31:24]));
103
aes_sbox u5(    .a(w7_reg[15:08]), .d(subword2[23:16]));
104
aes_sbox u6(    .a(w7_reg[07:00]), .d(subword2[15:08]));
105
aes_sbox u7(    .a(w7_reg[31:24]), .d(subword2[07:00]));
106
 
107
 
108
 
109
endmodule
110
 

powered by: WebSVN 2.1.0

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