-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkeyall.v
66 lines (57 loc) · 1.14 KB
/
keyall.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
module keyall# (parameter size=128)(input clk,input enable,input reset,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);
always@(posedge clk)
begin
if(reset==1)
begin
Nr=1;
flag=0;
mode=1;
count=1;
finish=0;
kall='h0;
end
else if(enable) begin
if(kall[maxsize-:128]==key[size-1-:128])begin
finish=1;
end
if(Nr<=nr)
begin
if(Nr==1)begin
keytemp[255-:size]=key[size-1:0];
end
else begin
keytemp[255-:size]=keyround[255-:size];
end
Nr=Nr+1;
if((Nr-1)%2==0)begin
flag=1;
end
else begin
flag=0;
end
if(count!=3)begin
count=count+1;
end
else begin
count=1;
end
kall[(maxsize-128*(Nr-2))-:128]=kout[127:0];//kall[(maxsize-(128*Nr)+1)-:128 ]
end
if(Nr>nr)begin
kall[127:0]=kout[127:0];
kall[maxsize-:128]=key[size-1-:128];
end
end
end
//assign kall[size*(size/32 +7)-1 -:128]=128'h2b7e151628aed2a6abf7158809cf4f3c;
endmodule