1 |
21 |
arif_endro |
-- ------------------------------------------------------------------------
|
2 |
16 |
arif_endro |
-- Copyright (C) 2005 Arif Endro Nugroho
|
3 |
21 |
arif_endro |
-- All rights reserved.
|
4 |
2 |
arif_endro |
--
|
5 |
21 |
arif_endro |
-- Redistribution and use in source and binary forms, with or without
|
6 |
|
|
-- modification, are permitted provided that the following conditions
|
7 |
|
|
-- are met:
|
8 |
2 |
arif_endro |
--
|
9 |
21 |
arif_endro |
-- 1. Redistributions of source code must retain the above copyright
|
10 |
|
|
-- notice, this list of conditions and the following disclaimer.
|
11 |
|
|
-- 2. Redistributions in binary form must reproduce the above copyright
|
12 |
|
|
-- notice, this list of conditions and the following disclaimer in the
|
13 |
|
|
-- documentation and/or other materials provided with the distribution.
|
14 |
|
|
-- 3. The name of Arif Endro Nugroho may not be used to endorse or promote
|
15 |
|
|
-- products derived from this software without specific prior written
|
16 |
|
|
-- permission.
|
17 |
2 |
arif_endro |
--
|
18 |
21 |
arif_endro |
-- THIS SOFTWARE IS PROVIDED BY ARIF ENDRO NUGROHO "AS IS" AND ANY EXPRESS
|
19 |
|
|
-- OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
20 |
|
|
-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
21 |
|
|
-- DISCLAIMED. IN NO EVENT SHALL ARIF ENDRO NUGROHO BE LIABLE FOR ANY
|
22 |
|
|
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
23 |
|
|
-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
24 |
|
|
-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
25 |
|
|
-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
26 |
|
|
-- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
27 |
|
|
-- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 |
|
|
-- POSSIBILITY OF SUCH DAMAGE.
|
29 |
2 |
arif_endro |
--
|
30 |
21 |
arif_endro |
-- End Of License.
|
31 |
|
|
-- ------------------------------------------------------------------------
|
32 |
2 |
arif_endro |
|
33 |
|
|
library ieee;
|
34 |
|
|
use ieee.std_logic_1164.all;
|
35 |
|
|
use ieee.std_logic_arith.all;
|
36 |
|
|
use ieee.std_logic_unsigned.all;
|
37 |
|
|
use ieee.std_logic_textio.all;
|
38 |
|
|
use std.textio.all;
|
39 |
|
|
|
40 |
|
|
library std_developerskit;
|
41 |
|
|
use std_developerskit.std_iopak.all; -- Function From_HexString
|
42 |
|
|
|
43 |
|
|
entity input is
|
44 |
|
|
port (
|
45 |
|
|
clock : out std_logic;
|
46 |
7 |
arif_endro |
load : out std_logic;
|
47 |
2 |
arif_endro |
done : in std_logic;
|
48 |
|
|
test_iteration : out integer;
|
49 |
7 |
arif_endro |
key_i_byte : out std_logic_vector (007 downto 000);
|
50 |
|
|
data_i_byte : out std_logic_vector (007 downto 000);
|
51 |
|
|
cipher_o_byte : out std_logic_vector (007 downto 000)
|
52 |
2 |
arif_endro |
);
|
53 |
|
|
end input;
|
54 |
|
|
|
55 |
|
|
architecture test_bench of input is
|
56 |
|
|
|
57 |
|
|
--
|
58 |
|
|
file in_file_ptr : text open read_mode is "../data/ecb_tbl.txt";
|
59 |
|
|
--
|
60 |
|
|
signal clock_int : std_logic := '0';
|
61 |
7 |
arif_endro |
signal ct : std_logic_vector (127 downto 000);
|
62 |
|
|
signal pt : std_logic_vector (127 downto 000);
|
63 |
|
|
signal ky : std_logic_vector (127 downto 000);
|
64 |
2 |
arif_endro |
--
|
65 |
|
|
begin
|
66 |
|
|
--
|
67 |
7 |
arif_endro |
clock_int <= not(clock_int) after 1 ns;
|
68 |
|
|
clock <= clock_int;
|
69 |
2 |
arif_endro |
--
|
70 |
|
|
process
|
71 |
|
|
--
|
72 |
|
|
variable delay : time := 1 ns;
|
73 |
|
|
variable in_line : line;
|
74 |
|
|
variable cipher_text : string ( 01 to 32 );
|
75 |
|
|
variable plain_text : string ( 01 to 32 );
|
76 |
|
|
variable key : string ( 01 to 32 );
|
77 |
|
|
variable test : integer;
|
78 |
|
|
variable junk_test : string ( 01 to 02 );
|
79 |
|
|
variable junk_plain_text : string ( 01 to 03 );
|
80 |
|
|
variable junk_cipher_text : string (01 to 03 );
|
81 |
|
|
variable junk_key : string ( 01 to 04 );
|
82 |
|
|
--
|
83 |
|
|
begin
|
84 |
|
|
--
|
85 |
|
|
while not (endfile(in_file_ptr)) loop
|
86 |
|
|
--
|
87 |
|
|
readline(in_file_ptr, in_line); -- blank lines
|
88 |
|
|
--
|
89 |
|
|
readline(in_file_ptr, in_line);
|
90 |
|
|
read(in_line, junk_test);
|
91 |
|
|
read(in_line, test);
|
92 |
|
|
readline(in_file_ptr, in_line);
|
93 |
|
|
read(in_line, junk_key);
|
94 |
|
|
read(in_line, key);
|
95 |
|
|
readline(in_file_ptr, in_line);
|
96 |
|
|
read(in_line, junk_plain_text);
|
97 |
|
|
read(in_line, plain_text);
|
98 |
|
|
readline(in_file_ptr, in_line);
|
99 |
|
|
read(in_line, junk_cipher_text);
|
100 |
|
|
read(in_line, cipher_text);
|
101 |
|
|
--
|
102 |
7 |
arif_endro |
ky <= to_StdLogicVector(From_HexString(key( 01 to 32)));
|
103 |
|
|
pt <= to_StdLogicVector(From_HexString(plain_text( 01 to 32 )));
|
104 |
|
|
ct <= to_StdLogicVector(From_HexString(cipher_text( 01 to 32 )));
|
105 |
|
|
--
|
106 |
|
|
for a in 1 to key'length/2 loop
|
107 |
|
|
wait until rising_edge(clock_int);
|
108 |
|
|
key_i_byte <= to_StdLogicVector(From_HexString(key(2*a-1 to 2*a)));
|
109 |
|
|
data_i_byte <= to_StdLogicVector(From_HexString(plain_text(2*a-1 to 2*a)));
|
110 |
|
|
cipher_o_byte <= to_StdLogicVector(From_HexString(cipher_text(2*a-1 to 2*a)));
|
111 |
|
|
load <= '1';
|
112 |
|
|
test_iteration <= test;
|
113 |
|
|
end loop;
|
114 |
|
|
--
|
115 |
2 |
arif_endro |
wait until rising_edge(clock_int);
|
116 |
7 |
arif_endro |
load <= '0';
|
117 |
2 |
arif_endro |
--
|
118 |
7 |
arif_endro |
wait until falling_edge(done);
|
119 |
2 |
arif_endro |
wait until rising_edge(clock_int);
|
120 |
|
|
--
|
121 |
|
|
end loop;
|
122 |
|
|
wait;
|
123 |
|
|
end process;
|
124 |
|
|
--
|
125 |
|
|
end test_bench;
|