OpenCores
URL https://opencores.org/ocsvn/aes_pipe/aes_pipe/trunk

Subversion Repositories aes_pipe

[/] [aes_pipe/] [trunk/] [bench/] [vhdl/] [tb_aes.vhdl] - Blame information for rev 9

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 subhasis25
----------------------------------------------------------------------
2
----                                                              ----
3 9 subhasis25
---- Pipelined Aes IP Core                                        ----
4
----                                                              ----
5
---- This file is part of the Pipelined AES project               ----
6
---- http://www.opencores.org/cores/aes_pipe/                     ----
7
----                                                              ----
8
---- Description                                                  ----
9
---- Implementation of AES IP core according to                   ----
10
---- FIPS PUB 197 specification document.                         ----
11
----                                                              ----
12
---- To Do:                                                       ----
13
----   -                                                          ----
14
----                                                              ----
15
---- Author:                                                      ----
16
----      - Subhasis Das, subhasis256@gmail.com                   ----
17
----                                                              ----
18
----------------------------------------------------------------------
19
----                                                              ----
20
---- Copyright (C) 2009 Authors and OPENCORES.ORG                 ----
21
----                                                              ----
22 2 subhasis25
---- This source file may be used and distributed without         ----
23
---- restriction provided that this copyright statement is not    ----
24 9 subhasis25
---- removed from the file and that any derivative work contains ----
25 2 subhasis25
---- the original copyright notice and the associated disclaimer. ----
26
----                                                              ----
27
---- This source file is free software; you can redistribute it   ----
28
---- and/or modify it under the terms of the GNU Lesser General   ----
29
---- Public License as published by the Free Software Foundation; ----
30
---- either version 2.1 of the License, or (at your option) any   ----
31
---- later version.                                               ----
32
----                                                              ----
33
---- This source is distributed in the hope that it will be       ----
34
---- useful, but WITHOUT ANY WARRANTY; without even the implied   ----
35
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ----
36 9 subhasis25
---- PURPOSE. See the GNU Lesser General Public License for more ----
37 2 subhasis25
---- details.                                                     ----
38
----                                                              ----
39
---- You should have received a copy of the GNU Lesser General    ----
40
---- Public License along with this source; if not, download it   ----
41 9 subhasis25
---- from http://www.opencores.org/lgpl.shtml                     ----
42 2 subhasis25
----                                                              ----
43
----------------------------------------------------------------------
44
------------------------------------------------------
45
-- Project: AESFast
46
-- Author: Subhasis
47 9 subhasis25
-- Last Modified: 25/03/10
48 2 subhasis25
-- Email: subhasis256@gmail.com
49
--
50
-- TODO: Test with NIST test vectors
51
------------------------------------------------------
52
--
53
-- Description: Testbench for AESFast
54 9 subhasis25
-- Takes in data and keys from ../src/vectors.dat
55
-- Takes in true output values from ../src/cipher.dat
56
-- Writes all the output to ../log/output.log
57 2 subhasis25
------------------------------------------------------
58
 
59
library IEEE;
60
use IEEE.std_logic_1164.all;
61 9 subhasis25
use IEEE.std_logic_textio.all;
62
use std.textio.all;
63 2 subhasis25
 
64
library work;
65
use work.aes_pkg.all;
66
 
67
entity tb_aes is
68
end tb_aes;
69
 
70
architecture rtl of tb_aes is
71 9 subhasis25
signal clk: std_logic; -- clock
72 2 subhasis25
signal plaintext: datablock;
73
signal key: datablock;
74
signal cipher: datablock;
75 9 subhasis25
signal rst: std_logic; -- reset input
76
signal op_start: std_logic; -- signal that simulation ended
77
constant clk_period: time := 10 ns;
78 2 subhasis25
 
79 5 subhasis25
component aes_top is
80 2 subhasis25
port(
81 5 subhasis25
        clk_i: in std_logic;
82 9 subhasis25
        rst_i: in std_logic;
83 5 subhasis25
        plaintext_i: in datablock;
84
        keyblock_i: in datablock;
85
        ciphertext_o: out datablock
86 2 subhasis25
        );
87
end component;
88
 
89
begin
90 9 subhasis25
        -- The wiring of the top module
91
        DUT: aes_top port map(
92
                                                 clk_i => clk,
93
                                                 rst_i => rst,
94
                                                 plaintext_i => plaintext,
95
                                                 keyblock_i => key,
96
                                                 ciphertext_o => cipher
97
                                                 );
98
        -- Generate clock
99 2 subhasis25
        gen_clk: process
100
        begin
101
                clk <= '1';
102 9 subhasis25
                wait for clk_period/2;
103 2 subhasis25
                clk <= '0';
104 9 subhasis25
                wait for clk_period/2;
105 2 subhasis25
        end process;
106 9 subhasis25
        -- Generate Reset
107
        gen_rst: process
108
        begin
109
                rst <= '1';
110
                wait for clk_period/2; -- generate reset
111
                rst <= '0';
112
                wait;
113
        end process;
114 2 subhasis25
 
115 9 subhasis25
        -- generate the inputs and check against expected output
116 2 subhasis25
        gen_in: process
117 9 subhasis25
        file testfile: text open read_mode is "../src/vectors.dat";
118
        variable line_in: line;
119
        variable plaintext_byte, key_byte: std_logic_vector(7 downto 0);
120 2 subhasis25
        begin
121 9 subhasis25
                if(endfile(testfile)) then
122
                        file_close(testfile);
123
                        wait;
124
                end if;
125
 
126
                readline(testfile, line_in);
127
                for i in 3 downto 0 loop
128
                        for j in 3 downto 0 loop
129
                                hread(line_in, plaintext_byte);
130
                                plaintext(3-j,3-i) <= plaintext_byte;
131
                        end loop;
132
                end loop;
133
                for i in 3 downto 0 loop
134
                        for j in 3 downto 0 loop
135
                                hread(line_in, key_byte);
136
                                key(3-j,3-i) <= key_byte;
137
                        end loop;
138
                end loop;
139
 
140
                wait for clk_period;
141
        end process;
142
 
143
        -- Generate a signal to indicate that valid output has begun
144
        op_begin: process
145
        begin
146
                wait for 30*clk_period;
147
                wait for clk_period/2;
148
                op_start <= '1';
149 2 subhasis25
                wait;
150
        end process;
151 9 subhasis25
 
152
        -- Compare output with actual output file
153
        op_chk: process
154
        file chkfile: text open read_mode is "../src/cipher.dat";
155
        file opfile: text open write_mode is "../log/output.log";
156
        variable line_in, line_out_file, line_out: line;
157
        variable exp_cipher_byte: std_logic_vector(7 downto 0);
158
        variable succeded: boolean;
159
        begin
160
                -- if required cycles have passed
161
                if(op_start = '1') then
162
                        if(endfile(chkfile)) then -- end of simulation
163
                                file_close(chkfile);
164
                                wait;
165
                        end if;
166
                        succeded := true;
167
                        readline(chkfile, line_in); -- read in one expected result
168
                        for i in 3 downto 0 loop
169
                                for j in 3 downto 0 loop
170
                                        hread(line_in, exp_cipher_byte); -- read in one byte
171
                                        if(exp_cipher_byte /= cipher(3-j,3-i)) then
172
                                                succeded := false; -- check failed
173
                                        end if;
174
                                end loop;
175
                        end loop;
176
                        -- writing the output line
177
                        for i in 3 downto 0 loop
178
                                for j in 3 downto 0 loop
179
                                        hwrite(line_out_file, cipher(3-j,3-i));
180
                                        hwrite(line_out, cipher(3-j,3-i));
181
                                end loop;
182
                        end loop;
183
                        write(line_out_file, ' ');
184
                        write(line_out, ' ');
185
                        -- writing the comparison result
186
                        write(line_out_file, succeded);
187
                        write(line_out, succeded);
188
                        writeline(opfile, line_out_file);
189
                        writeline(OUTPUT, line_out);
190
                end if;
191
                wait for clk_period;
192
        end process;
193 2 subhasis25
end rtl;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.