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_mctester.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_mctester.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 Monte-Carlo 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
library ieee;
49
use ieee.std_logic_1164.all;
50
use ieee.std_logic_arith.all;
51
use ieee.math_real.all;
52
use std.textio.all;
53
use ieee.std_logic_textio.all;
54
library std_developerskit;
55
use std_developerskit.std_iopak.all;
56
 
57
entity aes_fips_mctester is end aes_fips_mctester;
58
 
59
architecture behavioral of aes_fips_mctester is
60
 
61
component aes128_fast
62
port(
63
      clk       : in std_logic;
64
      reset     : in std_logic;
65
      start     : in std_logic;
66
      mode      : in std_logic;
67
      load      : in std_logic;
68
      key       : in std_logic_vector(63 downto 0);
69
      data_in   : in std_logic_vector(63 downto 0);
70
      data_out  : out std_logic_vector(127 downto 0);
71
      done      : out std_logic
72
     );
73
 
74
end component;
75
 
76
signal clock_tb: std_logic:='0';
77
signal reset_tb: std_logic:='0';
78
signal start_tb: std_logic:='0';
79
signal load_tb: std_logic:='0';
80
signal done_tb: std_logic;
81
--#############################
82
signal mode_tb: std_logic:='1'; -- 1-> encode; 0-> decode
83
--#############################
84
signal data_in_tb: std_logic_vector(63 downto 0):=X"0000000000000000";
85
signal data_out_tb: std_logic_vector(127 downto 0);
86
signal key_tb: std_logic_vector(63 downto 0):=X"0000000000000000";
87
signal chk: integer:=0;
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 infile : text open read_mode is "ecb_e_m.txt";
109
file outfile: text open write_mode is "ecb_e_m_results.txt";
110
variable inline       : line;
111
variable outline      : line;
112
variable itr_numline  : string(1 to 2);
113
variable key_line     : string(1 to 4);
114
variable pt_line      : string(1 to 3);
115
variable ct_line      : string(1 to 3);
116
variable iteration_num: integer;
117
variable hex_key_str  : string(1 to 32);
118
variable pt_str       : string(1 to 32);
119
variable ct_str       : string(1 to 32);
120
variable exp_cipher   : std_logic_vector(127 downto 0);
121
variable next_round_data: std_logic_vector(127 downto 0):=X"00000000000000000000000000000000";
122
begin
123
  wait for 1 ns;
124
  wait until reset_tb = '0';
125
  write(outline,string'("Monte-Carlo Encryption Tests"));
126
  writeline(outfile,outline);
127
  write(outline,string'("----------------------------"));
128
  writeline(outfile,outline);
129
  while(not endfile(infile)) loop
130
    wait until rising_edge(clock_tb);
131
    wait until rising_edge(clock_tb);
132
    readline(infile,inline);
133
    read(inline,itr_numline);
134
    read(inline,iteration_num);
135
    readline(infile,inline);
136
    read(inline,key_line);
137
    read(inline,hex_key_str);
138
    readline(infile,inline);
139
    read(inline,pt_line);
140
    read(inline,pt_str);
141
    readline(infile,inline);
142
    read(inline,ct_line);
143
    read(inline,ct_str);
144
    exp_cipher := to_StdLogicVector(From_HexString(ct_str));
145
    for j in 0 to 9999 loop
146
      chk <= j;
147
      if(j = 0) then
148
        wait until rising_edge(clock_tb);
149
        load_tb <= '1';
150
        key_tb <= to_StdLogicVector(From_HexString(hex_key_str(1 to 16)));
151
        data_in_tb <= to_StdLogicVector(From_HexString(pt_str(1 to 16)));
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
      else
157
        wait until rising_edge(clock_tb);
158
        load_tb <= '1';
159
        key_tb <= to_StdLogicVector(From_HexString(hex_key_str(1 to 16)));
160
        data_in_tb <= next_round_data(127 downto 64);
161
        wait until rising_edge(clock_tb);
162
        load_tb <= '0';
163
        key_tb <= to_StdLogicVector(From_HexString(hex_key_str(17 to 32)));
164
        data_in_tb <= next_round_data(63 downto 0);
165
      end if;
166
      wait until rising_edge(clock_tb);
167
      wait until rising_edge(clock_tb);
168
      start_tb <= '1';
169
      wait until rising_edge(clock_tb);
170
      start_tb <= '0';
171
      wait until done_tb = '1';
172
      wait until rising_edge(clock_tb);
173
      next_round_data := data_out_tb;
174
      wait until rising_edge(clock_tb);
175
    end loop;
176
    write(outline,string'("Round Number - "));
177
    write(outline,iteration_num);
178
    writeline(outfile,outline);
179
    write(outline,string'("Result: "));
180
    if(data_out_tb = exp_cipher) then
181
      write(outline,string'("OK"));
182
    else
183
      write(outline,string'("Error"));
184
    end if;
185
    writeline(outfile,outline);
186
  end loop;
187
end process;
188
 
189
end behavioral;
190
 
191
 

powered by: WebSVN 2.1.0

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