-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcipher.v
78 lines (56 loc) · 1 KB
/
cipher.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
72
73
74
75
76
77
78
module Cipher# (parameter size=128)
(
input [127:0]plaintext,
input[size-1:0]key,
input clk,
input reset,
input enable,
output reg [127:0]out
);
localparam nr=size/32 +6;
wire finish;
wire [127:0] block2;
wire [127:0] block3;
wire [127:0] block4;
wire [127:0]tempout;
wire [128*(size/(32)+7)-1:0] keys;
reg set;
reg [127:0]tempblock;
integer i;
keyall #(size) k(clk,enable,reset,key,keys,finish);
subbytes c1(tempblock,block2);
ShiftRows c2(block2,block3);
MixColumns c3(block3, block4);
AddRoundKey c5(block4,keys[128*(nr+1)-128*(i)-1-:128] ,tempout);
always@(posedge clk)
begin//a
if(reset==1)
begin//0
i=0;
set=0;
end//0
else if(enable)
begin //1
if(finish ==1)
begin //2
if(i<=nr)
begin //3
if(i==0)
begin//4
tempblock=plaintext^key[size-1-:128];
end//4
if(i>0&&i<=nr)
begin//5
tempblock=tempout;
end//5
i=i+1;
end//3
if(i==nr+1&&set!=1)
begin//6
out=block3^keys[127:0];
set=1;
end//6
end//2
end//1
end//a
endmodule