-
Notifications
You must be signed in to change notification settings - Fork 1
/
AES_MAIN_TB.v
164 lines (123 loc) · 2.49 KB
/
AES_MAIN_TB.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
`timescale 1ns/1ps
`include "aes_main.v"
`include "clk16.v"
module AES_MAIN_TB();
reg clk_base;
wire clk;
reg rst1;
reg rst2;
reg data_in_stb;
reg data_out_stb;
reg [127:0] data_in;
reg [7:0] password;
wire usr_long_key_valid;
wire usr_long_key_change_rq;
reg usr_long_key_ch;
wire ready;
wire ready_for_transmit;
wire [127:0] data_out;
wire data_valid;
reg [7:0] data_count;
reg flag;
integer r, f;
initial
begin
data_in_stb = 0;
data_out_stb = 0;
f = $fopen("C:/intelFPGA/18.1/AES_cryptography/AES_main/data.txt", "r");
if(~f)
begin
$display("Could not open file");
end
flag = 1'b0;
clk_base = 0;
rst2 = 0;
rst1 = 0;
#32
rst2 = 1;
#32
rst2 = 0;
#960
rst1 = 1;
#960
rst1 = 0;
end
always @(posedge clk)
begin
if(rst1)
data_count <= 0;
else if (ready & data_count < 16 & data_in_stb)
data_count <= data_count + 1;
else
data_count <= data_count;
end
always @(posedge clk)
begin
if(rst1)
data_in_stb <= 0;
else if (data_in_stb && ready)
data_in_stb <= 1'b0;
else if(ready & data_count < 16)
data_in_stb <= 1;
end
always @(posedge clk)
begin
if(rst1)
data_out_stb <= 0;
else if(data_valid)
data_out_stb <= 1;
end
always @(posedge clk)
if (rst1)
flag <= 1'b1;
always @(posedge clk)
begin
if(rst1 & ~flag)
r <= $fscanf(f, "%h", data_in);
else if(ready & data_in_stb & data_count < 16 & ~usr_long_key_change_rq)
r <= $fscanf(f, "%h", data_in);
end
always @(posedge clk)
begin
if(rst1)
password <= 8'b10101010;
end
always @(posedge clk)
begin
if(rst1)
usr_long_key_ch <= 0;
else if (usr_long_key_ch)
usr_long_key_ch <= 1'b0;
else if(usr_long_key_change_rq)
usr_long_key_ch <= 1;
end
aes_main main(
.clk_in(clk_base),
.reset(rst1),
.reset_clk(rst2),
//data_in
.data_in_stb(data_in_stb), //val input data
.data_out_stb(data_out_stb), //val of outpat taken
.data_in(data_in),
.password(password),
.usr_long_key_valid(usr_long_key_valid),
.usr_long_key_change_rq(usr_long_key_change_rq),
.usr_long_key_ch(usr_long_key_ch), //accept
.ready(ready), //ready take data
.ready_for_transmit(ready_for_transmit), //not busy can give transmit_req
//data_out
.data_out(data_out),
.data_valid(data_valid)
);
always
begin
#1
clk_base <= ~clk_base;
end
clk16 clk161
(
.reset(rst2),
.clk50(clk_base),
.clk16(clk)
);
endmodule