-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAES_Encrypt.v
62 lines (56 loc) · 1.23 KB
/
AES_Encrypt.v
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
module AES_Encrypt#(parameter N,parameter Nr,parameter Nk)(datain,key,state,reset,clk,start);
input [127:0] datain;
input [N-1:0] key;
output reg [127:0] state;
input reset;
input clk;
output reg start;
wire [(128*(Nr+1))-1:0] keys;
reg [127:0] a1;
wire [127:0] a2;
wire [127:0] a3;
reg [127:0] a4;
wire [127:0] b1;
wire [127:0] b2;
wire [127:0] b3;
integer j = 0;
always @(posedge clk or posedge reset)begin
if(reset) begin
j = 0;
state<=128'hx;
a1 <= 128'hx;
a4 <= 128'hx;
start <= 0;
end
else begin
if( j == 0)begin
a1 <= a3;
state<=a3;
j = j + 1;
start <= 1;
end
else if(j>0 && j < Nr - 1) begin
a1 <= a2;
state<=a2;
j = j + 1;
start <= 1;
end
else if(j == Nr - 1) begin
a4<=a2;
state<=a2;
j = j + 1;
start <= 1;
end
else if(j >= Nr) begin
state<=b3;
start <= 1;
end
end
end
KeyExpansion #(N,Nr,Nk) ke (key, keys);
Addroundkey ark1(datain, keys[128*(Nr)+:128], a3);
round r(a1, a2, keys[128 * (Nr-j) +: 128]);
subBytes sb(a4,b1);
ShiftBytes shb(b1,b2);
Addroundkey ark2(b2,keys[128 * 0 +: 128],b3);
endmodule