1 |
4 |
gajos |
-----------------------------------------------------------------------
|
2 |
|
|
---- ----
|
3 |
|
|
---- Present - a lightweight block cipher project ----
|
4 |
|
|
---- ----
|
5 |
|
|
---- This file is part of the Present - a lightweight block ----
|
6 |
|
|
---- cipher project ----
|
7 |
|
|
---- http://www.http://opencores.org/project,present ----
|
8 |
|
|
---- ----
|
9 |
|
|
---- Description: ----
|
10 |
|
|
---- Present decoder test bench. Test signals were taken from ----
|
11 |
|
|
---- 'pure' Presnet encoder simulation (it is proper work, because ----
|
12 |
|
|
---- it was good implementation). ----
|
13 |
|
|
---- To Do: ----
|
14 |
|
|
---- ----
|
15 |
|
|
---- Author(s): ----
|
16 |
|
|
---- - Krzysztof Gajewski, gajos@opencores.org ----
|
17 |
|
|
---- k.gajewski@gmail.com ----
|
18 |
|
|
---- ----
|
19 |
|
|
-----------------------------------------------------------------------
|
20 |
|
|
---- ----
|
21 |
|
|
---- Copyright (C) 2013 Authors and OPENCORES.ORG ----
|
22 |
|
|
---- ----
|
23 |
|
|
---- This source file may be used and distributed without ----
|
24 |
|
|
---- restriction provided that this copyright statement is not ----
|
25 |
|
|
---- removed from the file and that any derivative work contains ----
|
26 |
|
|
---- the original copyright notice and the associated disclaimer. ----
|
27 |
|
|
---- ----
|
28 |
|
|
---- This source file is free software; you can redistribute it ----
|
29 |
|
|
---- and-or modify it under the terms of the GNU Lesser General ----
|
30 |
|
|
---- Public License as published by the Free Software Foundation; ----
|
31 |
|
|
---- either version 2.1 of the License, or (at your option) any ----
|
32 |
|
|
---- later version. ----
|
33 |
|
|
---- ----
|
34 |
|
|
---- This source is distributed in the hope that it will be ----
|
35 |
|
|
---- useful, but WITHOUT ANY WARRANTY; without even the implied ----
|
36 |
|
|
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ----
|
37 |
|
|
---- PURPOSE. See the GNU Lesser General Public License for more ----
|
38 |
|
|
---- details. ----
|
39 |
|
|
---- ----
|
40 |
|
|
---- You should have received a copy of the GNU Lesser General ----
|
41 |
|
|
---- Public License along with this source; if not, download it ----
|
42 |
|
|
---- from http://www.opencores.org/lgpl.shtml ----
|
43 |
|
|
---- ----
|
44 |
|
|
-----------------------------------------------------------------------
|
45 |
3 |
gajos |
LIBRARY ieee;
|
46 |
|
|
USE ieee.std_logic_1164.ALL;
|
47 |
|
|
|
48 |
|
|
-- Uncomment the following library declaration if using
|
49 |
|
|
-- arithmetic functions with Signed or Unsigned values
|
50 |
|
|
--USE ieee.numeric_std.ALL;
|
51 |
|
|
|
52 |
|
|
ENTITY PresentDecTB IS
|
53 |
|
|
END PresentDecTB;
|
54 |
|
|
|
55 |
|
|
ARCHITECTURE behavior OF PresentDecTB IS
|
56 |
|
|
|
57 |
|
|
-- Component Declaration for the Unit Under Test (UUT)
|
58 |
|
|
|
59 |
|
|
COMPONENT PresentDec
|
60 |
|
|
PORT(
|
61 |
|
|
plaintext : IN std_logic_vector(63 downto 0);
|
62 |
|
|
key : IN std_logic_vector(79 downto 0);
|
63 |
|
|
ciphertext : OUT std_logic_vector(63 downto 0);
|
64 |
|
|
start : IN std_logic;
|
65 |
|
|
clk : IN std_logic;
|
66 |
|
|
reset : IN std_logic;
|
67 |
|
|
ready : OUT std_logic
|
68 |
|
|
);
|
69 |
|
|
END COMPONENT;
|
70 |
|
|
|
71 |
|
|
|
72 |
|
|
--Inputs
|
73 |
|
|
signal plaintext : std_logic_vector(63 downto 0) := (others => '0');
|
74 |
|
|
signal key : std_logic_vector(79 downto 0) := (others => '0');
|
75 |
|
|
signal start : std_logic := '0';
|
76 |
|
|
signal clk : std_logic := '0';
|
77 |
|
|
signal reset : std_logic := '0';
|
78 |
|
|
|
79 |
|
|
--Outputs
|
80 |
|
|
signal ciphertext : std_logic_vector(63 downto 0);
|
81 |
|
|
signal ready : std_logic;
|
82 |
|
|
|
83 |
|
|
-- Clock period definitions
|
84 |
|
|
constant clk_period : time := 10 ns;
|
85 |
|
|
|
86 |
|
|
BEGIN
|
87 |
|
|
|
88 |
|
|
-- Instantiate the Unit Under Test (UUT)
|
89 |
|
|
uut: PresentDec PORT MAP (
|
90 |
|
|
plaintext => plaintext,
|
91 |
|
|
key => key,
|
92 |
|
|
ciphertext => ciphertext,
|
93 |
|
|
start => start,
|
94 |
|
|
clk => clk,
|
95 |
|
|
reset => reset,
|
96 |
|
|
ready => ready
|
97 |
|
|
);
|
98 |
|
|
|
99 |
|
|
-- Clock process definitions
|
100 |
|
|
clk_process :process
|
101 |
|
|
begin
|
102 |
|
|
clk <= '0';
|
103 |
|
|
wait for clk_period/2;
|
104 |
|
|
clk <= '1';
|
105 |
|
|
wait for clk_period/2;
|
106 |
|
|
end process;
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
-- Stimulus process
|
110 |
|
|
stim_proc: process
|
111 |
|
|
begin
|
112 |
|
|
|
113 |
11 |
gajos |
---- Preparation for test case 1 -----------------
|
114 |
|
|
-- plaintext <= x"5579c1387b228445";
|
115 |
|
|
-- key <= x"6dab31744f41d7008759";
|
116 |
|
|
-- expected_ciphertext <= x"0000000000000000";
|
117 |
|
|
--------------------------------------------------
|
118 |
|
|
|
119 |
3 |
gajos |
reset <= '1';
|
120 |
|
|
start <= '0';
|
121 |
|
|
plaintext <= x"5579c1387b228445";
|
122 |
|
|
key <= x"6dab31744f41d7008759";
|
123 |
|
|
wait for 100 ns;
|
124 |
|
|
reset <= '0';
|
125 |
|
|
|
126 |
|
|
plaintext <= x"5579c1387b228445";
|
127 |
|
|
key <= x"6dab31744f41d7008759";
|
128 |
|
|
start <= '1';
|
129 |
11 |
gajos |
wait until ready = '1';
|
130 |
|
|
|
131 |
|
|
if ciphertext /= x"0000000000000000" then
|
132 |
|
|
report "RESULT MISMATCH! Test case 1 failed" severity ERROR;
|
133 |
|
|
assert false severity failure;
|
134 |
|
|
else
|
135 |
|
|
report "Test case 1 successful" severity note;
|
136 |
|
|
end if;
|
137 |
|
|
|
138 |
|
|
---- Preparation for test case 2 -----------------
|
139 |
|
|
-- plaintext <= x"e72c46c0f5945049";
|
140 |
|
|
-- key <= x"fe7a548fb60eb167c511";
|
141 |
|
|
-- expected_ciphertext <= x"0000000000000000";
|
142 |
|
|
--------------------------------------------------
|
143 |
|
|
|
144 |
3 |
gajos |
start <= '0';
|
145 |
|
|
wait for clk_period;
|
146 |
|
|
|
147 |
|
|
plaintext <= x"e72c46c0f5945049";
|
148 |
|
|
key <= x"fe7a548fb60eb167c511";
|
149 |
|
|
start <= '1';
|
150 |
11 |
gajos |
wait until ready = '1';
|
151 |
|
|
|
152 |
|
|
if ciphertext /= x"0000000000000000" then
|
153 |
|
|
report "RESULT MISMATCH! Test case 2 failed" severity ERROR;
|
154 |
|
|
assert false severity failure;
|
155 |
|
|
else
|
156 |
|
|
report "Test case 2 successful" severity note;
|
157 |
|
|
end if;
|
158 |
|
|
|
159 |
|
|
---- Preparation for test case 3 -----------------
|
160 |
|
|
-- plaintext <= x"a112ffc72f68417b";
|
161 |
|
|
-- key <= x"6dab31744f41d7008759";
|
162 |
|
|
-- expected_ciphertext <= x"ffffffffffffffff";
|
163 |
|
|
--------------------------------------------------
|
164 |
|
|
|
165 |
3 |
gajos |
start <= '0';
|
166 |
|
|
wait for clk_period;
|
167 |
|
|
|
168 |
|
|
plaintext <= x"a112ffc72f68417b";
|
169 |
|
|
key <= x"6dab31744f41d7008759";
|
170 |
|
|
start <= '1';
|
171 |
11 |
gajos |
wait until ready = '1';
|
172 |
|
|
|
173 |
|
|
if ciphertext /= x"ffffffffffffffff" then
|
174 |
|
|
report "RESULT MISMATCH! Test case 3 failed" severity ERROR;
|
175 |
|
|
assert false severity failure;
|
176 |
|
|
else
|
177 |
|
|
report "Test case 3 successful" severity note;
|
178 |
|
|
end if;
|
179 |
|
|
|
180 |
|
|
---- Preparation for test case 4 -----------------
|
181 |
|
|
-- plaintext <= x"3333dcd3213210d2";
|
182 |
|
|
-- key <= x"fe7a548fb60eb167c511";
|
183 |
|
|
-- expected_ciphertext <= x"ffffffffffffffff";
|
184 |
|
|
--------------------------------------------------
|
185 |
|
|
|
186 |
3 |
gajos |
start <= '0';
|
187 |
|
|
wait for clk_period;
|
188 |
|
|
|
189 |
|
|
plaintext <= x"3333dcd3213210d2";
|
190 |
|
|
key <= x"fe7a548fb60eb167c511";
|
191 |
|
|
start <= '1';
|
192 |
11 |
gajos |
wait until ready = '1';
|
193 |
3 |
gajos |
|
194 |
11 |
gajos |
if ciphertext /= x"ffffffffffffffff" then
|
195 |
|
|
report "RESULT MISMATCH! Test case 4 failed" severity ERROR;
|
196 |
|
|
assert false severity failure;
|
197 |
|
|
else
|
198 |
|
|
report "Test case 4 successful" severity note;
|
199 |
|
|
end if;
|
200 |
|
|
|
201 |
3 |
gajos |
assert false severity failure;
|
202 |
|
|
|
203 |
|
|
end process;
|
204 |
|
|
|
205 |
|
|
END;
|