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

Subversion Repositories cryptopan_core

[/] [cryptopan_core/] [trunk/] [tb/] [cryptopan_unit_tb.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 tonyb33
--
2
-- This file is part of the Crypto-PAn core (www.opencores.org).
3
--
4
-- Copyright (c) 2007 The University of Waikato, Hamilton, New Zealand.
5
-- Authors: Anthony Blake (tonyb33@opencores.org)
6
--          
7
-- All rights reserved.
8
--
9
-- This code has been developed by the University of Waikato WAND 
10
-- research group. For further information please see http://www.wand.net.nz/
11
--
12
-- This source file is free software; you can redistribute it and/or modify
13
-- it under the terms of the GNU General Public License as published by
14
-- the Free Software Foundation; either version 2 of the License, or
15
-- (at your option) any later version.
16
--
17
-- This source is distributed in the hope that it will be useful,
18
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-- GNU General Public License for more details.
21
--
22
-- You should have received a copy of the GNU General Public License
23
-- along with libtrace; if not, write to the Free Software
24
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
--
26
 
27
library ieee;
28
use ieee.std_logic_1164.all;
29
use ieee.std_logic_unsigned.all;
30
use ieee.std_logic_arith.all;
31
use ieee.numeric_std.all;
32
 
33
 
34
entity cryptopan_unit_tb is
35
 
36
end cryptopan_unit_tb;
37
 
38
architecture tb of cryptopan_unit_tb is
39
 
40
  component cryptopan_unit
41
    port (
42
      clk      : in  std_logic;
43
      reset    : in  std_logic;
44
      ready    : out std_logic;
45
      key      : in  std_logic_vector(255 downto 0);
46
      key_wren : in  std_logic;
47
      ip_in    : in  std_logic_vector(31 downto 0);
48
      ip_wren  : in  std_logic;
49
      ip_out   : out std_logic_vector(31 downto 0);
50
      ip_dv    : out std_logic);
51
  end component;
52
 
53
  signal clk   : std_logic;
54
  signal reset : std_logic;
55
 
56
  signal key            : std_logic_vector(255 downto 0);
57
  signal key_wren       : std_logic;
58
  signal ready          : std_logic;
59
  signal ip_in, ip_out  : std_logic_vector(31 downto 0);
60
  signal ip_wren, ip_dv : std_logic;
61
 
62
  type char_file is file of character;
63
  file bin_file_raw  : char_file is in "sim/trace_bin_raw";
64
  file bin_file_anon : char_file is in "sim/trace_bin_anon";
65
 
66
  signal ip_in_int  : std_logic_vector(31 downto 0);
67
  signal ip_out_int : std_logic_vector(31 downto 0);
68
 
69
begin
70
 
71
  CLKGEN : process
72
  begin
73
    clk <= '1';
74
    wait for 5 ns;
75
    clk <= '0';
76
    wait for 5 ns;
77
  end process CLKGEN;
78
 
79
  DUT : cryptopan_unit
80
    port map (
81
      clk      => clk,
82
      reset    => reset,
83
      ready    => ready,
84
      key      => key,
85
      key_wren => key_wren,
86
      ip_in    => ip_in,
87
      ip_wren  => ip_wren,
88
      ip_out   => ip_out,
89
      ip_dv    => ip_dv);
90
 
91
  GEN_IPS            : process
92
    variable my_char : character;
93
  begin  -- process GEN_IPS
94
    -- file_open(bin_file_raw, "sim/trace_bin_raw", read_mode);
95
 
96
    ip_in_int <= (others => '0');
97
    ip_wren   <= '0';
98
    wait until ready = '1';
99
    wait for 50 ns;
100
 
101
    while not endfile(bin_file_raw) loop
102
 
103
 
104
      read(bin_file_raw, my_char);
105
      ip_in_int(31 downto 24) <= conv_std_logic_vector(character'pos(my_char), 8);
106
      read(bin_file_raw, my_char);
107
      ip_in_int(23 downto 16) <= conv_std_logic_vector(character'pos(my_char), 8);
108
      read(bin_file_raw, my_char);
109
      ip_in_int(15 downto 8)  <= conv_std_logic_vector(character'pos(my_char), 8);
110
      read(bin_file_raw, my_char);
111
      ip_in_int(7 downto 0)   <= conv_std_logic_vector(character'pos(my_char), 8);
112
      wait for 10 ns;
113
      ip_wren                 <= '1';
114
 
115
      wait for 10 ns;
116
 
117
      ip_wren <= '0';
118
 
119
      wait until ready = '1';
120
    end loop;
121
    report "TEST COMPLETED" severity note;
122
 
123
  end process GEN_IPS;
124
 
125
  IP_OUT_INT_LOGIC : process
126
    variable my_char : character;
127
  begin  -- process IP_OUT_INT_LOGIC
128
    --ip_out_int <= (others => '0');
129
    wait until ip_dv = '1';
130
    read(bin_file_anon, my_char);
131
    ip_out_int(31 downto 24) <= conv_std_logic_vector(character'pos(my_char), 8);
132
    read(bin_file_anon, my_char);
133
    ip_out_int(23 downto 16) <= conv_std_logic_vector(character'pos(my_char), 8);
134
    read(bin_file_anon, my_char);
135
    ip_out_int(15 downto 8)  <= conv_std_logic_vector(character'pos(my_char), 8);
136
    read(bin_file_anon, my_char);
137
    ip_out_int(7 downto 0)   <= conv_std_logic_vector(character'pos(my_char), 8);
138
 
139
  end process IP_OUT_INT_LOGIC;
140
 
141
  DV_LOGIC           : process(clk)
142
    variable my_char : character;
143
  begin  -- process DV_LOGIC
144
    if clk'event and clk = '1' then
145
      if ip_dv = '1' then
146
        assert ip_out_int = ip_out report "TEST FAILED" severity error;
147
      end if;
148
    end if;
149
  end process DV_LOGIC;
150
 
151
 
152
  ip_in <= ip_in_int;
153
 
154
  TESTBENCH : process
155
  begin
156
    reset    <= '1';
157
-- ip_in <= (others => '0');
158
    key      <= (others => '0');
159
-- ip_wren <= '0';
160
    key_wren <= '0';
161
    wait for 50 ns;
162
    reset    <= '0';
163
    wait for 20 ns;
164
    key      <= X"d8988f837979652762574c2d2a8422021522178d33a4cf80130a5b1649907d10";
165
    key_wren <= '1';
166
    wait for 10 ns;
167
    key_wren <= '0';
168
-- wait until ready='1';
169
-- wait for 40 ns;
170
-- ip_in <= X"18050050";
171
-- ip_wren <= '1';
172
-- wait for 10 ns;
173
-- ip_wren <= '0';
174
-- wait until ready='1';
175
    wait;
176
  end process TESTBENCH;
177
 
178
 
179
 
180
end tb;

powered by: WebSVN 2.1.0

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