forked from RawanMostafa08/AES-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInvkeyall.v
71 lines (52 loc) · 1.07 KB
/
Invkeyall.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
63
64
65
66
67
68
69
70
71
module Invkeyall# (parameter size=128)(input clk,input[size-1:0] key,output reg [128*(size/32 +7)-1:0] kall,output reg finish );
localparam nr= size/32 +6;
localparam maxsize=128*(nr+1)-1;
reg flag;
reg[1:0] mode;
reg[1:0]count;
reg[3:0] Nr;
wire[255:0] keyround;
reg [255:0] keytemp;
wire[127:0] kout;
keyexpansion#(size) uut(clk,keytemp,Nr-1,keyround,flag,count-1,kout);
initial
begin
Nr=1;
flag=0;
mode=1;
count=1;
finish=0;
end
always@(posedge clk)
begin//a
if(kall[127:0]==key[size-1-:128])begin//0
finish=1;
end//0
else if(Nr<=nr)begin//1
if(Nr==1)begin//2
keytemp[255-:size]=key[size-1:0];
end//2
else begin//3
keytemp[255-:size]=keyround[255-:size];
end//3
Nr=Nr+1;
if((Nr-1)%2==0)begin//4
flag=1;
end//4
else begin//5
flag=0;
end//5
if(count!=3)begin//6
count=count+1;
end//6
else begin//7
count=1;
end//7
kall[(128*(1)-1):(128*(1-1))]=kout[127:0];//kall[(maxsize-(128*Nr)+1)-:128 ]
end//1
else if(Nr>nr)begin//8
kall[maxsize-:128]=kout[127:0];
kall[127:0]=key[size-1-:128];
end//8
end//4
endmodule