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

Subversion Repositories aes_crypto_core

[/] [aes_crypto_core/] [tags/] [arelease/] [tb/] [aes_fips_tester.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 hemanth
--*************************************************************************
2
-- Project    : AES128                                                    *
3
--                                                                        *
4
-- Block Name : aes_fips_tester.vhd                                       *
5
--                                                                        *
6
-- Author     : Hemanth Satyanarayana                                     *
7
--                                                                        *
8
-- Email      : hemanth@opencores.org                                     *
9
--                                                                        *
10
-- Description: Test bench module to test the aes implemntation           *
11
--              for KAT based tests.                                      *
12
--                         .                                              *
13
--                                                                        *
14
-- Revision History                                                       *
15
-- |-----------|-------------|---------|---------------------------------|*
16
-- |   Name    |    Date     | Version |          Revision details       |*
17
-- |-----------|-------------|---------|---------------------------------|*
18
-- | Hemanth   | 15-Dec-2004 | 1.1.1.1 |            Uploaded             |*
19
-- |-----------|-------------|---------|---------------------------------|*
20
--                                                                        *
21
--  Refer FIPS-KAT Document for details                                   *
22
--*************************************************************************
23
--                                                                        *
24
-- Copyright (C) 2004 Author                                              *
25
--                                                                        *
26
-- This source file may be used and distributed without                   *
27
-- restriction provided that this copyright statement is not              *
28
-- removed from the file and that any derivative work contains            *
29
-- the original copyright notice and the associated disclaimer.           *
30
--                                                                        *
31
-- This source file is free software; you can redistribute it             *
32
-- and/or modify it under the terms of the GNU Lesser General             *
33
-- Public License as published by the Free Software Foundation;           *
34
-- either version 2.1 of the License, or (at your option) any             *
35
-- later version.                                                         *
36
--                                                                        *
37
-- This source is distributed in the hope that it will be                 *
38
-- useful, but WITHOUT ANY WARRANTY; without even the implied             *
39
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR                *
40
-- PURPOSE.  See the GNU Lesser General Public License for more           *
41
-- details.                                                               *
42
--                                                                        *
43
-- You should have received a copy of the GNU Lesser General              *
44
-- Public License along with this source; if not, download it             *
45
-- from http://www.opencores.org/lgpl.shtml                               *
46
--                                                                        *
47
--*************************************************************************
48
 
49
library ieee;
50
use ieee.std_logic_1164.all;
51
use ieee.std_logic_arith.all;
52
use ieee.math_real.all;
53
use std.textio.all;
54
use ieee.std_logic_textio.all;
55
library std_developerskit;
56
use std_developerskit.std_iopak.all;
57
 
58
entity aes_fips_tester is end aes_fips_tester;
59
 
60
architecture behavioral of aes_fips_tester is
61
 
62
component aes128_fast
63
port(
64
      clk       : in std_logic;
65
      reset     : in std_logic;
66
      start     : in std_logic;
67
      mode      : in std_logic;
68
      load      : in std_logic;
69
      key       : in std_logic_vector(63 downto 0);
70
      data_in   : in std_logic_vector(63 downto 0);
71
      data_out  : out std_logic_vector(127 downto 0);
72
      done      : out std_logic
73
     );
74
 
75
end component;
76
 
77
signal clock_tb: std_logic:='0';
78
signal reset_tb: std_logic:='0';
79
signal start_tb: std_logic:='0';
80
signal load_tb: std_logic:='0';
81
signal done_tb: std_logic;
82
--#############################
83
signal mode_tb: std_logic:='1'; -- 1-> encode; 0-> decode
84
--#############################
85
signal data_in_tb: std_logic_vector(63 downto 0):=X"0000000000000000";
86
signal data_out_tb: std_logic_vector(127 downto 0);
87
signal key_tb: std_logic_vector(63 downto 0):=X"0000000000000000";
88
 
89
begin
90
 
91
clock_tb <= not clock_tb after 50 ns;
92
reset_tb <= '1','0' after 150 ns;
93
 
94
aes_i: aes128_fast
95
       port map(
96
                  clk      => clock_tb,
97
                  reset    => reset_tb,
98
                  start    => start_tb,
99
                  mode     => mode_tb,
100
                  load     => load_tb,
101
                  key      => key_tb,
102
                  data_in  => data_in_tb,
103
                  data_out => data_out_tb,
104
                  done     => done_tb
105
                 );
106
 
107
process
108
file infile1 : text open read_mode is "ecb_tbl.txt";
109
file outfile1: text open write_mode is "ecb_tb_results.txt";
110
file infile2 : text open read_mode is "ecb_vk.txt";
111
file outfile2: text open write_mode is "ecb_vk_results.txt";
112
file infile3 : text open read_mode is "ecb_vt.txt";
113
file outfile3: text open write_mode is "ecb_vt_results.txt";
114
variable inline       : line;
115
variable outline      : line;
116
variable itr_numline  : string(1 to 2);
117
variable key_line     : string(1 to 4);
118
variable pt_line      : string(1 to 3);
119
variable ct_line      : string(1 to 3);
120
variable iteration_num: integer;
121
variable hex_key_str  : string(1 to 32);
122
variable pt_str       : string(1 to 32);
123
variable ct_str       : string(1 to 32);
124
variable exp_cipher   : std_logic_vector(127 downto 0);
125
begin
126
  wait for 1 ns;
127
  wait until reset_tb = '0';
128
  write(outline,string'("Tables Known Answer Tests"));
129
  writeline(outfile1,outline);
130
  write(outline,string'("-------------------------"));
131
  writeline(outfile1,outline);
132
  while(not endfile(infile1)) loop
133
    wait until rising_edge(clock_tb);
134
    wait until rising_edge(clock_tb);
135
    readline(infile1,inline);
136
    read(inline,itr_numline);
137
    read(inline,iteration_num);
138
    readline(infile1,inline);
139
    read(inline,key_line);
140
    read(inline,hex_key_str);
141
    readline(infile1,inline);
142
    read(inline,pt_line);
143
    read(inline,pt_str);
144
    readline(infile1,inline);
145
    read(inline,ct_line);
146
    read(inline,ct_str);
147
    wait until rising_edge(clock_tb);
148
    load_tb <= '1';
149
    key_tb <= to_StdLogicVector(From_HexString(hex_key_str(1 to 16)));
150
    data_in_tb <= to_StdLogicVector(From_HexString(pt_str(1 to 16)));
151
    exp_cipher := to_StdLogicVector(From_HexString(ct_str));
152
    wait until rising_edge(clock_tb);
153
    load_tb <= '0';
154
    key_tb <= to_StdLogicVector(From_HexString(hex_key_str(17 to 32)));
155
    data_in_tb <= to_StdLogicVector(From_HexString(pt_str(17 to 32)));
156
    wait until rising_edge(clock_tb);
157
    wait until rising_edge(clock_tb);
158
    start_tb <= '1';
159
    wait until rising_edge(clock_tb);
160
    start_tb <= '0';
161
    wait until done_tb = '1';
162
    wait until rising_edge(clock_tb);
163
    write(outline,string'("Test Vector Number - "));
164
    write(outline,iteration_num);
165
    writeline(outfile1,outline);
166
    write(outline,string'("Result: "));
167
    if(data_out_tb = exp_cipher) then
168
      write(outline,string'("OK"));
169
    else
170
      write(outline,string'("Error"));
171
    end if;
172
    writeline(outfile1,outline);
173
  end loop;
174
  wait until rising_edge(clock_tb);
175
  write(outline,string'("Variable Key Known Answer Tests"));
176
  writeline(outfile2,outline);
177
  write(outline,string'("-------------------------------"));
178
  writeline(outfile2,outline);
179
  while(not endfile(infile2)) loop
180
    data_in_tb <= X"0000000000000000";
181
    wait until rising_edge(clock_tb);
182
    wait until rising_edge(clock_tb);
183
    readline(infile2,inline);
184
    read(inline,itr_numline);
185
    read(inline,iteration_num);
186
    readline(infile2,inline);
187
    read(inline,key_line);
188
    read(inline,hex_key_str);
189
    readline(infile2,inline);
190
    read(inline,ct_line);
191
    read(inline,ct_str);
192
    wait until rising_edge(clock_tb);
193
    load_tb <= '1';
194
    key_tb <= to_StdLogicVector(From_HexString(hex_key_str(1 to 16)));
195
    exp_cipher := to_StdLogicVector(From_HexString(ct_str));
196
    wait until rising_edge(clock_tb);
197
    load_tb <= '0';
198
    key_tb <= to_StdLogicVector(From_HexString(hex_key_str(17 to 32)));
199
    wait until rising_edge(clock_tb);
200
    wait until rising_edge(clock_tb);
201
    start_tb <= '1';
202
    wait until rising_edge(clock_tb);
203
    start_tb <= '0';
204
    wait until done_tb = '1';
205
    wait until rising_edge(clock_tb);
206
    write(outline,string'("Test Vector Number - "));
207
    write(outline,iteration_num);
208
    writeline(outfile2,outline);
209
    write(outline,string'("Result: "));
210
    if(data_out_tb = exp_cipher) then
211
      write(outline,string'("OK"));
212
    else
213
      write(outline,string'("Error"));
214
    end if;
215
    writeline(outfile2,outline);
216
  end loop;
217
  wait until rising_edge(clock_tb);
218
  write(outline,string'("Variable Text Known Answer Tests"));
219
  writeline(outfile3,outline);
220
  write(outline,string'("--------------------------------"));
221
  writeline(outfile3,outline);
222
  while(not endfile(infile3)) loop
223
    key_tb <= X"0000000000000000";
224
    wait until rising_edge(clock_tb);
225
    wait until rising_edge(clock_tb);
226
    readline(infile3,inline);
227
    read(inline,itr_numline);
228
    read(inline,iteration_num);
229
    readline(infile3,inline);
230
    read(inline,pt_line);
231
    read(inline,pt_str);
232
    readline(infile3,inline);
233
    read(inline,ct_line);
234
    read(inline,ct_str);
235
    wait until rising_edge(clock_tb);
236
    load_tb <= '1';
237
    data_in_tb <= to_StdLogicVector(From_HexString(pt_str(1 to 16)));
238
    exp_cipher := to_StdLogicVector(From_HexString(ct_str));
239
    wait until rising_edge(clock_tb);
240
    load_tb <= '0';
241
    data_in_tb <= to_StdLogicVector(From_HexString(pt_str(17 to 32)));
242
    wait until rising_edge(clock_tb);
243
    wait until rising_edge(clock_tb);
244
    start_tb <= '1';
245
    wait until rising_edge(clock_tb);
246
    start_tb <= '0';
247
    wait until done_tb = '1';
248
    wait until rising_edge(clock_tb);
249
    write(outline,string'("Test Vector Number - "));
250
    write(outline,iteration_num);
251
    writeline(outfile3,outline);
252
    write(outline,string'("Result: "));
253
    if(data_out_tb = exp_cipher) then
254
      write(outline,string'("OK"));
255
    else
256
      write(outline,string'("Error"));
257
    end if;
258
    writeline(outfile3,outline);
259
  end loop;
260
end process;
261
 
262
 
263
end behavioral;
264
 
265
 
266
 
267
 
268
 
269
 
270
 

powered by: WebSVN 2.1.0

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