1 |
7 |
arif_endro |
-- $Id: input.vhdl,v 1.2 2005-12-23 04:27:00 arif_endro Exp $
|
2 |
2 |
arif_endro |
-------------------------------------------------------------------------------
|
3 |
|
|
-- Title : Input
|
4 |
|
|
-- Project : Mini AES 128
|
5 |
|
|
-------------------------------------------------------------------------------
|
6 |
|
|
-- File : input.vhdl
|
7 |
|
|
-- Author : "Arif E. Nugroho" <arif_endro@yahoo.com>
|
8 |
|
|
-- Created : 2005/12/03
|
9 |
|
|
-- Last update :
|
10 |
|
|
-- Simulators : ModelSim SE PLUS 6.0
|
11 |
|
|
-- Synthesizers: ISE Xilinx 6.3i
|
12 |
|
|
-- Target :
|
13 |
|
|
-------------------------------------------------------------------------------
|
14 |
|
|
-- Description : Input stimuli file for test bench.
|
15 |
|
|
-------------------------------------------------------------------------------
|
16 |
|
|
-- Copyright (C) 2005 Arif E. Nugroho
|
17 |
|
|
-- This VHDL design file is an open design; you can redistribute it and/or
|
18 |
|
|
-- modify it and/or implement it after contacting the author
|
19 |
|
|
-------------------------------------------------------------------------------
|
20 |
|
|
-------------------------------------------------------------------------------
|
21 |
|
|
--
|
22 |
|
|
-- THIS SOURCE FILE MAY BE USED AND DISTRIBUTED WITHOUT RESTRICTION
|
23 |
|
|
-- PROVIDED THAT THIS COPYRIGHT STATEMENT IS NOT REMOVED FROM THE FILE AND THAT
|
24 |
|
|
-- ANY DERIVATIVE WORK CONTAINS THE ORIGINAL COPYRIGHT NOTICE AND THE
|
25 |
|
|
-- ASSOCIATED DISCLAIMER.
|
26 |
|
|
--
|
27 |
|
|
-------------------------------------------------------------------------------
|
28 |
|
|
--
|
29 |
|
|
-- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
30 |
|
|
-- IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
31 |
|
|
-- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
32 |
|
|
-- EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
33 |
|
|
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
34 |
|
|
-- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
35 |
|
|
-- OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
36 |
|
|
-- WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
37 |
|
|
-- OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
38 |
|
|
-- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
39 |
|
|
--
|
40 |
|
|
-------------------------------------------------------------------------------
|
41 |
|
|
|
42 |
|
|
library ieee;
|
43 |
|
|
use ieee.std_logic_1164.all;
|
44 |
|
|
use ieee.std_logic_arith.all;
|
45 |
|
|
use ieee.std_logic_unsigned.all;
|
46 |
|
|
use ieee.std_logic_textio.all;
|
47 |
|
|
use std.textio.all;
|
48 |
|
|
|
49 |
|
|
library std_developerskit;
|
50 |
|
|
use std_developerskit.std_iopak.all; -- Function From_HexString
|
51 |
|
|
|
52 |
|
|
entity input is
|
53 |
|
|
port (
|
54 |
|
|
clock : out std_logic;
|
55 |
7 |
arif_endro |
load : out std_logic;
|
56 |
2 |
arif_endro |
done : in std_logic;
|
57 |
|
|
test_iteration : out integer;
|
58 |
7 |
arif_endro |
key_i_byte : out std_logic_vector (007 downto 000);
|
59 |
|
|
data_i_byte : out std_logic_vector (007 downto 000);
|
60 |
|
|
cipher_o_byte : out std_logic_vector (007 downto 000)
|
61 |
2 |
arif_endro |
);
|
62 |
|
|
end input;
|
63 |
|
|
|
64 |
|
|
architecture test_bench of input is
|
65 |
|
|
|
66 |
|
|
--
|
67 |
|
|
file in_file_ptr : text open read_mode is "../data/ecb_tbl.txt";
|
68 |
|
|
--
|
69 |
|
|
signal clock_int : std_logic := '0';
|
70 |
7 |
arif_endro |
signal ct : std_logic_vector (127 downto 000);
|
71 |
|
|
signal pt : std_logic_vector (127 downto 000);
|
72 |
|
|
signal ky : std_logic_vector (127 downto 000);
|
73 |
2 |
arif_endro |
--
|
74 |
|
|
begin
|
75 |
|
|
--
|
76 |
7 |
arif_endro |
clock_int <= not(clock_int) after 1 ns;
|
77 |
|
|
clock <= clock_int;
|
78 |
2 |
arif_endro |
--
|
79 |
|
|
process
|
80 |
|
|
--
|
81 |
|
|
variable delay : time := 1 ns;
|
82 |
|
|
variable in_line : line;
|
83 |
|
|
variable cipher_text : string ( 01 to 32 );
|
84 |
|
|
variable plain_text : string ( 01 to 32 );
|
85 |
|
|
variable key : string ( 01 to 32 );
|
86 |
|
|
variable test : integer;
|
87 |
|
|
variable junk_test : string ( 01 to 02 );
|
88 |
|
|
variable junk_plain_text : string ( 01 to 03 );
|
89 |
|
|
variable junk_cipher_text : string (01 to 03 );
|
90 |
|
|
variable junk_key : string ( 01 to 04 );
|
91 |
|
|
--
|
92 |
|
|
begin
|
93 |
|
|
--
|
94 |
|
|
while not (endfile(in_file_ptr)) loop
|
95 |
|
|
--
|
96 |
|
|
readline(in_file_ptr, in_line); -- blank lines
|
97 |
|
|
--
|
98 |
|
|
readline(in_file_ptr, in_line);
|
99 |
|
|
read(in_line, junk_test);
|
100 |
|
|
read(in_line, test);
|
101 |
|
|
readline(in_file_ptr, in_line);
|
102 |
|
|
read(in_line, junk_key);
|
103 |
|
|
read(in_line, key);
|
104 |
|
|
readline(in_file_ptr, in_line);
|
105 |
|
|
read(in_line, junk_plain_text);
|
106 |
|
|
read(in_line, plain_text);
|
107 |
|
|
readline(in_file_ptr, in_line);
|
108 |
|
|
read(in_line, junk_cipher_text);
|
109 |
|
|
read(in_line, cipher_text);
|
110 |
|
|
--
|
111 |
7 |
arif_endro |
ky <= to_StdLogicVector(From_HexString(key( 01 to 32)));
|
112 |
|
|
pt <= to_StdLogicVector(From_HexString(plain_text( 01 to 32 )));
|
113 |
|
|
ct <= to_StdLogicVector(From_HexString(cipher_text( 01 to 32 )));
|
114 |
|
|
--
|
115 |
|
|
for a in 1 to key'length/2 loop
|
116 |
|
|
wait until rising_edge(clock_int);
|
117 |
|
|
key_i_byte <= to_StdLogicVector(From_HexString(key(2*a-1 to 2*a)));
|
118 |
|
|
data_i_byte <= to_StdLogicVector(From_HexString(plain_text(2*a-1 to 2*a)));
|
119 |
|
|
cipher_o_byte <= to_StdLogicVector(From_HexString(cipher_text(2*a-1 to 2*a)));
|
120 |
|
|
load <= '1';
|
121 |
|
|
test_iteration <= test;
|
122 |
|
|
end loop;
|
123 |
|
|
--
|
124 |
2 |
arif_endro |
wait until rising_edge(clock_int);
|
125 |
7 |
arif_endro |
load <= '0';
|
126 |
2 |
arif_endro |
--
|
127 |
7 |
arif_endro |
wait until falling_edge(done);
|
128 |
2 |
arif_endro |
wait until rising_edge(clock_int);
|
129 |
|
|
--
|
130 |
|
|
end loop;
|
131 |
|
|
wait;
|
132 |
|
|
end process;
|
133 |
|
|
--
|
134 |
|
|
end test_bench;
|