aes_ctrl.v
3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// This confidential and propriety software may be used
// only as authorized by a licensing agreement from
// Ocean Logic Pty Ltd http://www.ocean-logic.com
//
// In the event of publication, the following notice is
// applicable
//
// (C) COPYRIGHT 2001 Ocean Logic Pty Ltd
// ALL RIGHTS RESERVED
//
// the entire notice must be reproduced on all
// authorized copies
//
// File : ctrl.vhd
// Author : Vincenzo Liguori
// Date : 01-03-02
// Version 1.0
// Abstract :
// This implements the AES controller
//
// Modification history :
// Date by Version Change description
// -------------------------------------------------
// 01-03-02 VL 1.0 Original
// 08-07-02 frank name change to avoid vcs module name conflict
module aes_ctrl(
clk,
rstn,
en,
go,
ksize,
dinit,
ibypass,
final,
raddr0,
raddr1,
raddr2,
raddr3,
waddr0,
waddr1,
waddr2,
waddr3,
dout_vld
);
// Inputs
input clk, rstn;
input en, go;
input[1:0] ksize;
// Outputs
output dinit, ibypass;
output final;
output[1:0] raddr0, raddr1, raddr2, raddr3;
output[1:0] waddr0, waddr1, waddr2, waddr3;
output dout_vld;
wire clk;
wire rstn;
wire en;
wire go;
wire [1:0] ksize;
reg dinit;
wire ibypass;
reg final;
reg [1:0] raddr0;
wire [1:0] raddr1;
wire [1:0] raddr2;
wire [1:0] raddr3;
reg [1:0] waddr0;
reg [1:0] waddr1;
reg [1:0] waddr2;
reg [1:0] waddr3;
wire dout_vld;
wire [1:0] inc1;
wire [1:0] inc2;
wire [1:0] inc3;
wire finali;
wire endround;
wire byps;
reg [3:0] round;
reg [3:0] maxround;
always @(ksize) begin
// Select the number of rounds
case(ksize)
2'b 00 : begin
maxround <= 4'b 1010;
end
2'b 01 : begin
maxround <= 4'b 1100;
end
default : begin
maxround <= 4'b 1110;
end
endcase
end
assign byps = raddr0 == 2'b 00 ? 1'b 1 : 1'b 0;
assign ibypass = byps;
assign endround = raddr0 == 2'b 11 ? 1'b 1 : 1'b 0;
assign finali = round == maxround ? 1'b 1 : 1'b 0;
assign dout_vld = final;
always @(posedge clk or negedge rstn) begin
if(rstn == 1'b 0) begin
round <= {4{1'b0}};
raddr0 <= {2{1'b0}};
waddr0 <= {2{1'b0}};
waddr1 <= {2{1'b0}};
waddr2 <= {2{1'b0}};
waddr3 <= {2{1'b0}};
dinit <= 1'b 0;
final <= 1'b 0;
end else begin
if(en == 1'b 1) begin
final <= finali;
if(go == 1'b 0) begin
dinit <= 1'b 0;
round <= {4{1'b0}};
raddr0 <= {2{1'b0}};
end
else begin
if(round == 4'b 0000) begin
dinit <= 1'b 1;
end
else begin
dinit <= 1'b 0;
end
if(endround == 1'b 1) begin
raddr0 <= {2{1'b0}};
if(finali == 1'b 1) begin
round <= {4{1'b0}};
end
else begin
round <= round + 1'b 1;
end
end
else begin
raddr0 <= raddr0 + 1'b 1;
end
end
waddr0 <= raddr0;
waddr1 <= raddr1;
waddr2 <= raddr2;
waddr3 <= raddr3;
end
end
end
assign inc1 = 2'b 00;
addmod ad1(
// Inputs
.clk(clk),
.rstn(rstn),
.en(en),
.clrn(go),
.endround(endround),
.inc(inc1),
// Outputs
.raddr(raddr1));
assign inc2 = 2'b 11;
addmod ad2(
// Inputs
.clk(clk),
.rstn(rstn),
.en(en),
.clrn(go),
.endround(endround),
.inc(inc2),
// Outputs
.raddr(raddr2));
assign inc3 = 2'b 10;
addmod ad3(
// Inputs
.clk(clk),
.rstn(rstn),
.en(en),
.clrn(go),
.endround(endround),
.inc(inc3),
// Outputs
.raddr(raddr3));
endmodule