forked from Sara-Gamal1/ADVANCED-ENCRYPTION-STANDARD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
encryption.v.bak
46 lines (25 loc) · 835 Bytes
/
encryption.v.bak
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
module encryption#( parameter Nk=4,parameter Nr=10)(in, out, key);
input wire [127:0] in;
output wire [127:0] out;
input [Nk*4*8-1:0] key;
wire [127:0] state[14:0];
wire [127:0] state_out1[14:0];
wire [127:0] state_out2[14:0];
wire [127:0] state_out3[14:0];
wire [128*(Nr+1)-1:0]all_key;
General_KeyExpansion #(Nk*4*8,Nr) g(key,all_key);
genvar i;
generate
assign state[Nr-1]=in^all_key[128*(Nr+1)-1-:128];
for(i=Nr-1;i>0;i=i-1)
begin :f
Sub_Bytes s(state[i],state_out1[i]) ;
ShiftRows r(state_out1[i],state_out2[i]) ;
MixCloumns m(state_out2[i],state_out3[i]);
assign state[i-1]=state_out3[i]^all_key[(128*(i+1)-1)-:128];
end //end for
Sub_Bytes c(state[0],state_out1[0]);
ShiftRows w(state_out1[0],state_out2[0]);
assign out = state_out2[0]^all_key[127:0];
endgenerate //end genvar
endmodule