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

Subversion Repositories sha256_hash_core

[/] [sha256_hash_core/] [trunk/] [syn/] [sha256/] [sha256_test.vhd] - Blame information for rev 6

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jdoin
-----------------------------------------------------------------------------------------------------------------------
2 6 jdoin
-- Author:          Jonny Doin, jdoin@opencores.org, jonnydoin@gmail.com, jonnydoin@gridvortex.com
3 2 jdoin
-- 
4
-- Create Date:     09:56:30 05/22/2016  
5
-- Module Name:     sha256_test.vhd
6
-- Project Name:    sha256 engine
7
-- Target Devices:  Spartan-6
8
-- Tool versions:   ISE 14.7
9
-- Description: 
10
--
11
--      Testbench for the GV_SHA256 engine.
12
--      This is the testbench for the GV_SHA256 engine. It exercises all the input control signals and error generation,
13
--      and tests the GV_SHA256 engine with the NIST SHA256 test vectors, including the additional NIST test vectors up to the 
14
--      1 million chars.
15
--
16
--      The following waveforms describe the operation of the engine control signals for message start, update and end.
17
--
18
--      BEGIN BLOCK (1st block)
19
--      ======================
20
--
21
--      The hash operation starts with a 'begin' sync pulse, which causes the RESET of the processor. The processor comes out of RESET only after 'begin' is
22
--      released. 
23
--      The DATA_INPUT state is signalled by the data request signal 'di_req' going HIGH. The processor will latch 16 words from the 'di' port, at every 
24
--      rising edge of the system clock. At the end of the block input, the 'di_req' signal goes LOW. 
25
--      The input data can be held by bringing the 'ack' input LOW. When the 'ack' input is held LOW, it includes a wait state in the whole processor, to
26
--      cope with slow inputs or to allow periodic fetches of input data from multiple data sources. 
27
--
28
--      state              |reset| data                                    |wait |                                                     | process                  
29
--                    __   |__   |__    __    __    __    __    __    __   |__   |__    __    __    __    __    __    __    __    __   |__    __    __ 
30
--      clk_i      __/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \...     -- system clock
31
--                        _____                                                                                                                                      
32
--      start_i    ______/   \_\_______________________________________________________________________________________________________________________...     -- 'start_i' resets the processor and starts a new hash
33
--                                                                                                                                                       
34
--      end_i      ____________________________________________________________________________________________________________________________________...     -- 'end_i' marks end of last block data input
35
--                 __ _ _ _       _____________________________________________________________________________________________________                  
36
--      di_req_o   __ _ _ _\_____/                                                                                                     \_______________...     -- 'di_req_o' asserted during data input
37
--                            ___________________________________________       _________________________________________________________                
38
--      ack_i      __________/____/                                      \_____/                                                         \_____________...     -- 'ack_i' can hold the core for slow data
39
--                 __________ _________ _____ _____ _____ _____ _____ ___________ _____ _____ _____ _____ _____ _____ _____ _____ ______ ______________...
40
--      di_i       __________\___\_W0__\__W1_\__W2_\__W3_\__W4_\__W5_\\\\\\\__W6_\__W7_\__W8_\__W9_\_W10_\_W11_\_W12_\_W13_\_W14_\_W15__\______X_______...     -- user words on 'di_i' are latched on 'clk_i' rising edge
41
--                 ____________________ _____ _____ _____ _____ _____ ___________ _____ _____ _____ _____ _____ _____ _____ _____ _____________________...
42
--      st_cnt_reg ________/__0__/__0__/__1__/__2__/__3__/__4__/__5__/___6_______/__7__/__8__/__9__/__10_/__11_/__12_/__13_/__14_/__15_/__16_/__17_/_18...     -- internal state counter value
43
--                 __________ ___ _____ _____ _____ _____ _____ _____ ___________ _____ _____ _____ _____ _____ _____ _____ _____ _____________________...
44
--      Wt_i@core  __________\___\__W0_\__W1_\__W2_\__W3_\__W4_\__W5_\\\\\\\__W6_\__W7_\__W8_\__W9_\_W10_\_W11_\_W12_\_W13_\_W14_\_W15_________________...     -- msg scheduler lookahead output for Wt_i at core
45
--                 ______________ _____ _____ _____ _____ _____ _____ ___________ _____ _____ _____ _____ _____ _____ _____ _____ _____________________...
46
--      Kt_i@core  ______________/__K0_/__K1_/__K2_/__K3_/__K4_/__K5_/__K6_______/__K7_/__K8_/__K9_/_K10_/_K11_/_K12_/_K13_/_K14_/_K15_________________...     -- Kt rom synchronous with scheduler for Kt_i at core
47
--                 __ _ _ _                                                                                                                                            
48
--      error_o    __ _ _ _\___________________________________________________________________________________________________________________________...     -- 'start_i' clears any error condition
49
--                 __ _ _ _                                                                                                                                            
50
--      do_valid_o __ _ _ _\___________________________________________________________________________________________________________________________...     -- 'start_i' invalidates any previous results
51
--
52
--
53
--      UPDATE BLOCK (preload)
54
--      =====================
55
--
56
--      At the start of each block, the 'di_req' signal is raised to request new data.
57
--
58
--      state       ... process  |next | data                                    |wait |                                                     | process                    
59
--                    __    __    __    __    __    __    __    __    __    __   |__   |__    __    __    __    __    __    __    __    __    __ 
60
--      clk_i      __/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \...        -- system clock
61
--                                                                                                                                                  
62
--      end_i      ______________________________________________________________________________________________________________________________...        -- 'end_i' marks end of last block data input
63
--                                      _____________________________________________________________________________________________________       
64
--      di_req_o   ____________________/                                                                                                     \___...        -- 'di_req_o' asserted during data input
65
--                          ___________________________________________________       _________________________________________________________     
66
--      ack_i      ________/__________/                                        \_____/                                                         \_...        -- 'ack_i' can hold the core for slow data
67
--                 _________________ _ ______ _____ _____ _____ _____ _____ ___________ _____ _____ _____ _____ _____ _____ _____ _____ _____ ____...
68
--      di_i       _________________\\\___W0_\__W1_\__W2_\__W3_\__W4_\__W5_\\\\\\\\_W6_\__W7_\__W8_\__W9_\_W10_\_W11_\_W12_\_W13_\_W14_\_W15_\\_X_...       -- user words on 'di_i' are latched on 'clk_i' rising edge
69
--                 
70
--
71
--      UPDATE BLOCK (delayed start)
72
--      ===========================
73
--
74
--      The data for the new block can be delayed, by keeping the 'ack' signal low until the data is present at the data input port. 
75
--
76
--      state      ..|next | data                                                                  |wait |                                         | process                    
77
--                    __    __    __    __    __    __    __    __    __    __    __    __    __   |__   |__    __    __    __    __    __    __    __ 
78
--      clk_i      __/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \...     -- system clock
79
--                                                                                                                                                       
80
--      end_i      ____________________________________________________________________________________________________________________________________...     -- 'end_i' marks end of last block data input
81
--                          _______ _ _ ___________________________________________________________________________________________________________      
82
--      di_req_o   ________/                                                                                                                       \___...     -- 'di_req_o' asserted during data input
83
--                                             __________________________________________________       _____________________________________________    
84
--      ack_i      ________________ _ _ ______/                                                  \_____/                                             \_...     -- 'ack_i' valid on rising edge of 'clk_i'
85
--                 ________________ _ _ ___________ _____ _____ _____ _____ _____ _____ _____ ___________ _____ _____ _____ _____ _____ _____ _____ ____...
86
--      di_i       ________________ _ _ ______\_W0_\__W1_\__W2_\__W3_\__W4_\__W5_\__W6_\__W7_\\\\_____W8_\__W9_\_W10_\_W11_\_W12_\_W13_\_W14_\_W15_\__Z_...     -- user words on 'di_i' are latched on 'clk_i' rising edge
87
--                 
88
--
89
--      END BLOCK (success)
90
--      ==================
91
--
92
--      At the end of the last block the signal 'end' must be raised for at least one clock cycle. 
93
--      The 'bytes' input marks the number of valid bytes in the last word. 
94
--      A PADDING state completes the last data block and a BLK_PROCESS finishes the hash computation.
95
--      The 'do_valid' remains HIGH until the next RESET.
96
--
97
--      state      ..|next | data                              | padding         | process                     |next | valid     |reset| data     
98
--                    __    __    __    __    __    __    __    __    __          __    __    __          __    __    __    __    __    __    __  
99
--      clk_i      __/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \__/  \_ _ _ __/  \__/  \__/  \_ _ _ __/  \__/  \__/  \__/  \__/  \__/  \__/  \_...     -- system clock
100
--                                                                                                                              ______                    
101
--      start_i    ____________________________________________________________________________________________________________/   \__\___________...     -- 'start_i' resets the processor and starts a new hash
102
--                                                           ______                                                                               
103
--      end_i      _________________________________________/      \______ _ _ ___________________ _ _ ___________________________________________...     -- 'end_i' marks end of last block data input
104
--                          ___________________________________                                                                         __________  
105
--      di_req_o   ________/                                   \__________ _ _ ___________________ _ _ ________________________________/          ...     -- 'di_req_o' asserted during data input
106
--                           ______________________________________                                                                      _________  
107
--      ack_i      _________/                                    \\\______ _ _ ___________________ _ _ _________________________________/         ...     -- 'ack_i' can hold the core for slow data
108
--                 ______________ _____ _____ _____ _____ _____ __________ _ _ ___________________ _ _ ______________________________________ ____...
109
--      di_i       _________\_W0_\__W1_\__W2_\__W3_\__W4_\__W5_\__________ _ _ ___________________ _ _ _________________________________\_W0_\__W1...     -- words after the end_i assertion are ignored
110
--                 __ _____ _____ _____ _____ _____ _____ _____ _____ ____ _ ____ _____ _____ ____ _ _ ______________________________________ ____
111
--      st_cnt_reg __/_64__/__0__/__1__/__2__/__3__/__4__/__5__/__6__/__7_ _ _15_/__16_/__17_/__18 _ _ __/__63_/__64_/______0__________/__0__/__1_...     -- internal state counter value
112
--                          _____ _____ _____ _____ _____ _____                                                                         _____ ____
113
--      bytes_i    --------<__0__\__0__\__0__\__0__\__0__\__3__>-----------------------------------------------------------------------<__0__\__0_...     -- bytes_i mark number of valid bytes in each word
114
--                                                                                                                                                   
115
--      error_o    _______________________________________________________ _ _ ___________________ _ _ ___________________________________________...     -- 'error_o' goes high on an invalid computation
116
--                                                                                                                    ___________                 
117
--      do_valid_o _______________________________________________________ _ _ ___________________ _ _ ______________/           \________________...     -- 'do_valid_o' goes high at the end of a computation
118
--                                                                                                                    ___________                 
119
--      H0_o       _______________________________________________________ _ _ ___________________ _ _ ______________/___H0______\________________...     -- H0 holds the bytes 0..3 of the output
120
--                                                                                                                    ___________                                 
121
--      H1_o       _______________________________________________________ _ _ ___________________ _ _ ______________/___H1______\________________...     -- H1 holds the bytes 4..7 of the output
122
--                                                                                                                    ___________                            
123
--      H2_o       _______________________________________________________ _ _ ___________________ _ _ ______________/___H2______\________________...     -- H2 holds the bytes 8..11 of the output
124
--                                                                                                                    ___________                            
125
--      H3_o       _______________________________________________________ _ _ ___________________ _ _ ______________/___H3______\________________...     -- H3 holds the bytes 12..15 of the output
126
--                                                                                                                    ___________                            
127
--      H4_o       _______________________________________________________ _ _ ___________________ _ _ ______________/___H4______\________________...     -- H4 holds the bytes 16..19 of the output
128
--                                                                                                                    ___________                            
129
--      H5_o       _______________________________________________________ _ _ ___________________ _ _ ______________/___H5______\________________...     -- H5 holds the bytes 20..23 of the output
130
--                                                                                                                    ___________                            
131
--      H6_o       _______________________________________________________ _ _ ___________________ _ _ ______________/___H6______\________________...     -- H6 holds the bytes 24..27 of the output
132
--                                                                                                                    ___________                            
133
--      H7_o       _______________________________________________________ _ _ ___________________ _ _ ______________/___H7______\________________...     -- H7 holds the bytes 28..31 of the output
134
--
135
--
136
--      END BLOCK (full last block)
137
--      ==================
138
--
139
--      If the last block has exactly 16 full words, the controller inserts a dummy PADDING cycle, processes the input block, and inserts a
140
--      last PADDING block followed by a last BLK_PROCESS block.
141
--
142
--      state      ... data         |pad  | process   |next | pad                   | process   |next | valid     |reset| data
143
--                 __    __    __    __    __          __    __    __          __    __          __    __    __    __    __    __     
144
--      clk_i        \__/  \__/  \__/  \__/  \_ _ _ __/  \__/  \__/  \_ _ _ __/  \__/  \_ _ _ __/  \__/  \__/  \__/  \__/  \__/  \_...     -- system clock
145
--                                                                                                               ______                  
146
--      start_i    _____________________________________________________________________________________________/   \__\___________...     -- 'start_i' resets the processor and starts a new hash
147
--                                ______                                                                                                      
148
--      end_i      ______________/      \______ _ _ ___________________ _ _ _____________ _ _ _____________________________________...     -- 'end_i' marks end of last block data input
149
--                 _________________                                                                                     __________  
150
--      di_req_o                    \__________ _ _ ___________________ _ _ _____________ _ _ __________________________/          ...     -- 'di_req_o' asserted on rising edge of 'clk_i'
151
--                 ____________________                                                                                   _________  
152
--      ack_i                        \\\_______ _ _ ___________________ _ _ _____________ _ _ ___________________________/         ...     -- 'ack_i' valid on rising edge of 'clk_i'
153
--                 _____ _____ _____ __________ _ _ ___________________ _ _ _____________ _ _ ________________________________ ____...
154
--      di_i       _W13_\_W14_\_W15_\__________ _ _ ___________________ _ _ _____________ _ _ ___________________________\_W0_\__W1...     -- words after the end_i assertion are ignored
155
--                 _____ _____ _____ _____ ____ _ ____ _____ _____ ____ _ _ ________ ____ _ ____ _____ _______________________ ____
156
--      st_cnt_reg _13__/_14__/_15__/_16__/_16_ _ _63_/__64_/__0__/__1_ _ _ __/_15__/_16_ _ _63_/__64_/_____0_____/__0__/__0__/__1_...     -- internal state counter value
157
--                 _____ _____ _____                                                                                     _____ ____
158
--      bytes_i    __0__/__0__/__0__>-----------------------------------------------------------------------------------<__0__/__0_...     -- bytes_i mark number of valid bytes in each word
159
--                                                                                                     ___________                 
160
--      do_valid_o ____________________________ _ _ ___________________ _ _ __________________________/           \________________...     -- 'do_valid_o' goes high at the end of a computation
161
--
162
------------------------------ COPYRIGHT NOTICE -----------------------------------------------------------------------
163 6 jdoin
--                                                                   
164
--      This file is part of the SHA256 HASH CORE project http://opencores.org/project,sha256_hash_core
165
--                                                                   
166
--      Author(s):      Jonny Doin, jdoin@opencores.org, jonnydoin@gridvortex.com, jonnydoin@gmail.com
167
--                                                                   
168
--      Copyright (C) 2016 Jonny Doin
169
--      -----------------------------
170
--                                                                   
171
--      This source file may be used and distributed without restriction provided that this copyright statement is not    
172
--      removed from the file and that any derivative work contains the original copyright notice and the associated 
173
--      disclaimer. 
174
--                                                                   
175
--      This source file is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser 
176
--      General Public License as published by the Free Software Foundation; either version 2.1 of the License, or 
177
--      (at your option) any later version.
178
--                                                                   
179
--      This source is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
180
--      warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more  
181
--      details.
182
--
183
--      You should have received a copy of the GNU Lesser General Public License along with this source; if not, download 
184
--      it from http://www.gnu.org/licenses/lgpl.txt
185
--                                                                   
186 2 jdoin
------------------------------ REVISION HISTORY -----------------------------------------------------------------------
187
--
188
-- 2016/05/22   v0.01.0010  [JD]    started development. design of blocks and port interfaces.
189
-- 2016/06/05   v0.01.0090  [JD]    all modules integrated. testbench for basic test vectors verification.
190
-- 2016/06/05   v0.01.0095  [JD]    verification failed. misalignment of words in the datapath. 
191
-- 2016/06/06   v0.01.0100  [JD]    first simulation verification against NIST-FIPS-180-4 test vectors "abc" passed.
192
-- 2016/06/07   v0.01.0101  [JD]    failed 2-block test for "abcdbcdecd..." vector. Fixed padding control logic.
193
-- 2016/06/07   v0.01.0105  [JD]    sha256 verification against all NIST-FIPS-180-4 test vectors passed.
194
-- 2016/06/11   v0.01.0105  [JD]    verification against NIST-SHA2_Additional test vectors #1 to #10 passed.
195
-- 2016/06/11   v0.01.0110  [JD]    optimized controller states, reduced 2 clocks per block. 
196
-- 2016/06/18   v0.01.0120  [JD]    implemented error detection on 'bytes_i' input.
197
--
198
-----------------------------------------------------------------------------------------------------------------------
199
--  TODO
200
--  ====
201
--
202
--
203
-----------------------------------------------------------------------------------------------------------------------
204
library ieee;
205
use ieee.std_logic_1164.all;
206
use ieee.numeric_std.all;
207
 
208
entity testbench is
209
    Generic (
210
        CLK_PERIOD : time := 10 ns;                     -- clock period for pclk_i (default 100MHz)
211
        START_DELAY : time := 200 ns                    -- start delay between each run
212
    );
213
end testbench;
214
 
215
architecture behavior of testbench is
216
 
217
    --=============================================================================================
218
    -- Constants
219
    --=============================================================================================
220
    -- clock period
221
    constant PCLK_PERIOD : time := CLK_PERIOD;          -- parallel high-speed clock
222
 
223
    --=============================================================================================
224
    -- Signals for state machine control
225
    --=============================================================================================
226
 
227
    --=============================================================================================
228
    -- Signals for internal operation
229
    --=============================================================================================
230
    --- clock signals ---
231
    signal pclk             : std_logic := '1';                 -- 100MHz clock
232
    signal dut_ce           : std_logic;
233
    -- input data
234
    signal dut_di           : std_logic_vector (31 downto 0);   -- big endian input message words
235
    signal dut_bytes        : std_logic_vector (1 downto 0);    -- valid bytes in input word
236
    -- start/end commands
237
    signal dut_start        : std_logic;                        -- reset the processor and start a new hash
238
    signal dut_end          : std_logic;                        -- marks end of last block data input
239
    -- handshake
240
    signal dut_di_req       : std_logic;                        -- requests data input for next word
241
    signal dut_di_ack       : std_logic;                        -- high for di_i valid, low for hold
242
    signal dut_error        : std_logic;                        -- signalizes error. output data is invalid
243
    signal dut_do_valid     : std_logic;                        -- when high, the output is valid
244
    -- 256bit output registers
245
    signal dut_H0           : std_logic_vector (31 downto 0);
246
    signal dut_H1           : std_logic_vector (31 downto 0);
247
    signal dut_H2           : std_logic_vector (31 downto 0);
248
    signal dut_H3           : std_logic_vector (31 downto 0);
249
    signal dut_H4           : std_logic_vector (31 downto 0);
250
    signal dut_H5           : std_logic_vector (31 downto 0);
251
    signal dut_H6           : std_logic_vector (31 downto 0);
252
    signal dut_H7           : std_logic_vector (31 downto 0);
253
 
254
    -- testbench control signals
255
    signal words            : natural;
256
    signal blocks           : natural;
257
    signal test_case        : natural;
258
begin
259
 
260
    --=============================================================================================
261
    -- INSTANTIATION FOR THE DEVICE UNDER TEST
262
    --=============================================================================================
263
        Inst_sha_256_dut: entity work.gv_sha256(rtl)
264
        port map(
265
            -- clock and core enable
266
            clk_i => pclk,
267
            ce_i => dut_ce,
268
            -- input data
269
            di_i => dut_di,
270
            bytes_i => dut_bytes,
271
            -- start/end commands
272
            start_i => dut_start,
273
            end_i => dut_end,
274
            -- handshake
275
            di_req_o => dut_di_req,
276
            di_ack_i => dut_di_ack,
277
            error_o => dut_error,
278
            do_valid_o => dut_do_valid,
279
            -- 256bit output registers 
280
            H0_o => dut_H0,
281
            H1_o => dut_H1,
282
            H2_o => dut_H2,
283
            H3_o => dut_H3,
284
            H4_o => dut_H4,
285
            H5_o => dut_H5,
286
            H6_o => dut_H6,
287
            H7_o => dut_H7
288
        );
289
 
290
    --=============================================================================================
291
    -- CLOCK GENERATION
292
    --=============================================================================================
293
    pclk_proc: process is
294
    begin
295
        loop
296
            pclk <= not pclk;
297
            wait for PCLK_PERIOD / 2;
298
        end loop;
299
    end process pclk_proc;
300
    --=============================================================================================
301
    -- TEST BENCH STIMULI
302
    --=============================================================================================
303
    -- This testbench exercises the SHA256 toplevel with the NIST-FIPS-180-4 test vectors.
304
    --
305
    tb1 : process is
306
        variable count_words  : natural := 0;
307
        variable count_blocks : natural := 0;
308
        variable temp_di      : unsigned (31 downto 0) := (others => '0');
309
    begin
310
        wait for START_DELAY; -- wait until global set/reset completes
311
        -------------------------------------------------------------------------------------------
312
        -- test vector 1
313
        -- src: NIST-FIPS-180-4 
314
        -- msg := "abc" 
315
        -- hash:= BA7816BF 8F01CFEA 414140DE 5DAE2223 B00361A3 96177A9C B410FF61 F20015AD
316
        test_case <= 1;
317
        dut_ce <= '0';
318
        dut_di <= (others => '0');
319
        dut_bytes <= b"00";
320
        dut_start <= '0';
321
        dut_end <= '0';
322
        dut_di_ack <= '0';
323
        wait until pclk'event and pclk = '1';
324
        dut_ce <= '1';
325
        dut_start <= '1';
326 6 jdoin
        dut_di <= x"61626300";
327
        dut_bytes <= b"11";
328 2 jdoin
        wait until pclk'event and pclk = '1';
329
        dut_start <= '0';
330
        wait until dut_di_req = '1';
331
        dut_di_ack <= '1';
332
        dut_end <= '1';
333
        wait until pclk'event and pclk = '1';
334
        dut_end <= '0';
335
        if dut_error /= '1' and dut_do_valid /= '1' then
336
            while dut_error /= '1' and dut_do_valid /= '1' loop
337
                wait until pclk'event and pclk = '1';
338
            end loop;
339
        end if;
340
        wait for CLK_PERIOD*20;
341
 
342
        -- expected: BA7816BF 8F01CFEA 414140DE 5DAE2223 B00361A3 96177A9C B410FF61 F20015AD
343
        assert dut_H0 = x"BA7816BF" report "test #1 failed on H0" severity error;
344
        assert dut_H1 = x"8F01CFEA" report "test #1 failed on H1" severity error;
345
        assert dut_H2 = x"414140DE" report "test #1 failed on H2" severity error;
346
        assert dut_H3 = x"5DAE2223" report "test #1 failed on H3" severity error;
347
        assert dut_H4 = x"B00361A3" report "test #1 failed on H4" severity error;
348
        assert dut_H5 = x"96177A9C" report "test #1 failed on H5" severity error;
349
        assert dut_H6 = x"B410FF61" report "test #1 failed on H6" severity error;
350
        assert dut_H7 = x"F20015AD" report "test #1 failed on H7" severity error;
351
 
352
        -------------------------------------------------------------------------------------------
353
        -- test vector 2
354
        -- src: NIST-FIPS-180-4 
355
        -- msg := "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
356
        -- hash:= 248D6A61 D20638B8 E5C02693 0C3E6039 A33CE459 64FF2167 F6ECEDD4 19DB06C1
357
        test_case <= 2;
358
        dut_ce <= '0';
359
        dut_di <= (others => '0');
360
        dut_bytes <= b"00";
361
        dut_start <= '0';
362
        dut_end <= '0';
363
        dut_di_ack <= '0';
364
        wait until pclk'event and pclk = '1';
365
        dut_ce <= '1';
366
        dut_start <= '1';
367
        wait until pclk'event and pclk = '1';   -- 'begin' pulse minimum width is one clock
368
        wait for 25 ns;                         -- TEST: stretch 'begin' pulse
369
        dut_start <= '0';
370
        wait until dut_di_req = '1';
371
        wait until pclk'event and pclk = '1';
372
        dut_di_ack <= '1';
373
        dut_bytes <= b"00";
374
        dut_di <= x"61626364";
375
        wait until pclk'event and pclk = '1';
376
        dut_di <= x"62636465";
377
        wait until pclk'event and pclk = '1';
378
        dut_di <= x"63646566";
379
        wait until pclk'event and pclk = '1';
380
        dut_di <= x"64656667";
381
        wait until pclk'event and pclk = '1';
382
        dut_di <= x"65666768";
383
        wait until pclk'event and pclk = '1';
384
        dut_di <= x"66676869";
385
        wait until pclk'event and pclk = '1';
386
        dut_di <= x"6768696A";
387
        dut_di_ack <= '0';
388
        wait until pclk'event and pclk = '1';
389
        wait until pclk'event and pclk = '1';
390
        wait until pclk'event and pclk = '1';
391
        dut_di_ack <= '1';                      -- TEST: slow inputs with 'ack' handshake
392
        wait until pclk'event and pclk = '1';
393
        dut_di <= x"68696A6B";
394
        wait until pclk'event and pclk = '1';
395
        dut_di <= x"696A6B6C";
396
        wait until pclk'event and pclk = '1';
397
        dut_di <= x"6A6B6C6D";
398
        dut_bytes <= b"01";                     -- induce ERROR
399
        wait until pclk'event and pclk = '1';
400
        dut_di <= x"6B6C6D6E";
401
        wait until pclk'event and pclk = '1';
402
        dut_di <= x"6C6D6E6F";
403
        wait until pclk'event and pclk = '1';
404
        dut_di <= x"6D6E6F70";
405
        wait until pclk'event and pclk = '1';
406
        dut_di <= x"6E6F7071";
407
        dut_end <= '1';
408
        wait until pclk'event and pclk = '1';   -- 'end' pulse minimum width is one clock
409
        dut_bytes <= b"01";                     -- TEST: change 'bytes' value after END
410
        wait for 75 ns;                         -- TEST: stretch 'end' pulse
411
        dut_end <= '0';
412
        if dut_error /= '1' and dut_do_valid /= '1' then
413
            while dut_error /= '1' and dut_do_valid /= '1' loop
414
                wait until pclk'event and pclk = '1';
415
            end loop;
416
        end if;
417
        wait for CLK_PERIOD*20;
418
        -------------------------------------------------------------------------
419
        -- restart test #2
420
        test_case <= 0;
421
        wait until pclk'event and pclk = '1';
422
        test_case <= 2;
423
        dut_ce <= '0';
424
        dut_di <= (others => '0');
425
        dut_bytes <= b"00";
426
        dut_start <= '0';
427
        dut_end <= '0';
428
        dut_di_ack <= '0';
429
        wait until pclk'event and pclk = '1';
430
        dut_ce <= '1';
431
        dut_start <= '1';
432 6 jdoin
        dut_di <= x"61626364";
433
        dut_bytes <= b"00";
434
        dut_di_ack <= '1';
435 2 jdoin
        wait until pclk'event and pclk = '1';   -- 'begin' pulse minimum width is one clock
436
        dut_start <= '0';
437
        wait until dut_di_req = '1';
438
        wait until pclk'event and pclk = '1';
439
        dut_di <= x"62636465";
440
        wait until pclk'event and pclk = '1';
441
        dut_di <= x"63646566";
442
        wait until pclk'event and pclk = '1';
443
        dut_di <= x"64656667";
444
        wait until pclk'event and pclk = '1';
445
        dut_di <= x"65666768";
446
        wait until pclk'event and pclk = '1';
447
        dut_di <= x"66676869";
448
        wait until pclk'event and pclk = '1';
449
        dut_di <= x"6768696A";
450
        wait until pclk'event and pclk = '1';
451
        dut_di <= x"68696A6B";
452
        wait until pclk'event and pclk = '1';
453
        dut_di <= x"696A6B6C";
454
        wait until pclk'event and pclk = '1';
455
        dut_di <= x"6A6B6C6D";
456
        wait until pclk'event and pclk = '1';
457
        dut_di <= x"6B6C6D6E";
458
        wait until pclk'event and pclk = '1';
459
        dut_di <= x"6C6D6E6F";
460
        wait until pclk'event and pclk = '1';
461
        dut_di <= x"6D6E6F70";
462
        wait until pclk'event and pclk = '1';
463
        dut_di <= x"6E6F7071";
464
        dut_end <= '1';
465
        wait until pclk'event and pclk = '1';   -- 'end' pulse minimum width is one clock
466
        dut_end <= '0';
467
        if dut_error /= '1' and dut_do_valid /= '1' then
468
            while dut_error /= '1' and dut_do_valid /= '1' loop
469
                wait until pclk'event and pclk = '1';
470
            end loop;
471
        end if;
472
        wait for CLK_PERIOD*20;
473
 
474
        -- expected: 248D6A61 D20638B8 E5C02693 0C3E6039 A33CE459 64FF2167 F6ECEDD4 19DB06C1
475
        assert dut_H0 = x"248D6A61" report "test #2 failed on H0" severity error;
476
        assert dut_H1 = x"D20638B8" report "test #2 failed on H1" severity error;
477
        assert dut_H2 = x"E5C02693" report "test #2 failed on H2" severity error;
478
        assert dut_H3 = x"0C3E6039" report "test #2 failed on H3" severity error;
479
        assert dut_H4 = x"A33CE459" report "test #2 failed on H4" severity error;
480
        assert dut_H5 = x"64FF2167" report "test #2 failed on H5" severity error;
481
        assert dut_H6 = x"F6ECEDD4" report "test #2 failed on H6" severity error;
482
        assert dut_H7 = x"19DB06C1" report "test #2 failed on H7" severity error;
483
 
484
        -------------------------------------------------------------------------------------------
485
        -- test vector 3
486
        -- src: NIST-ADDITIONAL-SHA256
487
        -- #1) 1 byte 0xbd
488
        -- msg := x"bd"
489
        -- hash:= 68325720 aabd7c82 f30f554b 313d0570 c95accbb 7dc4b5aa e11204c0 8ffe732b
490
        test_case <= 3;
491
        dut_ce <= '0';
492
        dut_di <= (others => '0');
493
        dut_bytes <= b"00";
494
        dut_start <= '0';
495
        dut_end <= '0';
496
        dut_di_ack <= '0';
497
        wait until pclk'event and pclk = '1';
498
        dut_ce <= '1';
499
        dut_start <= '1';
500 6 jdoin
        dut_di <= x"bd000000";
501
        dut_bytes <= b"01";
502 2 jdoin
        wait until pclk'event and pclk = '1';
503
        dut_start <= '0';
504
        wait until dut_di_req = '1';
505
        dut_di_ack <= '1';
506
        dut_end <= '1';
507
        wait until pclk'event and pclk = '1';
508
        dut_end <= '0';
509
        if dut_error /= '1' and dut_do_valid /= '1' then
510
            while dut_error /= '1' and dut_do_valid /= '1' loop
511
                wait until pclk'event and pclk = '1';
512
            end loop;
513
        end if;
514
        wait for CLK_PERIOD*20;
515
 
516
        -- expected: 68325720 aabd7c82 f30f554b 313d0570 c95accbb 7dc4b5aa e11204c0 8ffe732b
517
        assert dut_H0 = x"68325720" report "test #3 failed on H0" severity error;
518
        assert dut_H1 = x"aabd7c82" report "test #3 failed on H1" severity error;
519
        assert dut_H2 = x"f30f554b" report "test #3 failed on H2" severity error;
520
        assert dut_H3 = x"313d0570" report "test #3 failed on H3" severity error;
521
        assert dut_H4 = x"c95accbb" report "test #3 failed on H4" severity error;
522
        assert dut_H5 = x"7dc4b5aa" report "test #3 failed on H5" severity error;
523
        assert dut_H6 = x"e11204c0" report "test #3 failed on H6" severity error;
524
        assert dut_H7 = x"8ffe732b" report "test #3 failed on H7" severity error;
525
 
526
        -------------------------------------------------------------------------------------------
527
        -- test vector 4
528
        -- src: NIST-ADDITIONAL-SHA256
529
        -- #2) 4 bytes 0xc98c8e55
530
        -- msg := x"c98c8e55"
531
        -- hash:= 7abc22c0 ae5af26c e93dbb94 433a0e0b 2e119d01 4f8e7f65 bd56c61c cccd9504
532
        test_case <= 4;
533
        dut_ce <= '0';
534
        dut_di <= (others => '0');
535
        dut_bytes <= b"00";
536
        dut_start <= '0';
537
        dut_end <= '0';
538
        dut_di_ack <= '0';
539
        wait until pclk'event and pclk = '1';
540
        dut_ce <= '1';
541
        dut_start <= '1';
542 6 jdoin
        dut_di <= x"c98c8e55";
543
        dut_bytes <= b"00";
544 2 jdoin
        wait until pclk'event and pclk = '1';
545
        dut_start <= '0';
546
        wait until dut_di_req = '1';
547
        dut_di_ack <= '1';
548
        dut_end <= '1';
549
        wait until pclk'event and pclk = '1';
550
        dut_end <= '0';
551
        if dut_error /= '1' and dut_do_valid /= '1' then
552
            while dut_error /= '1' and dut_do_valid /= '1' loop
553
                wait until pclk'event and pclk = '1';
554
            end loop;
555
        end if;
556
        wait for CLK_PERIOD*20;
557
 
558
        -- expected: 7abc22c0 ae5af26c e93dbb94 433a0e0b 2e119d01 4f8e7f65 bd56c61c cccd9504 
559
        assert dut_H0 = x"7abc22c0" report "test #4 failed on H0" severity error;
560
        assert dut_H1 = x"ae5af26c" report "test #4 failed on H1" severity error;
561
        assert dut_H2 = x"e93dbb94" report "test #4 failed on H2" severity error;
562
        assert dut_H3 = x"433a0e0b" report "test #4 failed on H3" severity error;
563
        assert dut_H4 = x"2e119d01" report "test #4 failed on H4" severity error;
564
        assert dut_H5 = x"4f8e7f65" report "test #4 failed on H5" severity error;
565
        assert dut_H6 = x"bd56c61c" report "test #4 failed on H6" severity error;
566
        assert dut_H7 = x"cccd9504" report "test #4 failed on H7" severity error;
567
 
568
        -------------------------------------------------------------------------------------------
569
        -- test vector 5
570
        -- src: NIST-ADDITIONAL-SHA256
571
        -- #3) 55 bytes of zeros
572
        -- msg := 55 x"00"
573
        -- hash:= 02779466 cdec1638 11d07881 5c633f21 90141308 1449002f 24aa3e80 f0b88ef7
574
        test_case <= 5;
575
        dut_ce <= '0';
576
        dut_di <= (others => '0');
577
        dut_bytes <= b"00";
578
        dut_start <= '0';
579
        dut_end <= '0';
580
        dut_di_ack <= '0';
581
        wait until pclk'event and pclk = '1';
582
        dut_ce <= '1';
583
        dut_start <= '1';
584 6 jdoin
        dut_di <= x"00000000";
585
        dut_bytes <= b"00";
586
        dut_di_ack <= '1';
587 2 jdoin
        wait until pclk'event and pclk = '1';
588
        dut_start <= '0';
589
        wait until dut_di_req = '1';
590
        wait until pclk'event and pclk = '1';
591
        wait until pclk'event and pclk = '1';
592
        wait until pclk'event and pclk = '1';
593
        wait until pclk'event and pclk = '1';
594
        wait until pclk'event and pclk = '1';
595
        wait until pclk'event and pclk = '1';
596
        wait until pclk'event and pclk = '1';
597
        wait until pclk'event and pclk = '1';
598
        wait until pclk'event and pclk = '1';
599
        wait until pclk'event and pclk = '1';
600
        wait until pclk'event and pclk = '1';
601
        wait until pclk'event and pclk = '1';
602
        wait until pclk'event and pclk = '1';
603
        dut_end <= '1';
604
        dut_bytes <= b"11";
605
        wait until pclk'event and pclk = '1';
606
        dut_end <= '0';
607
        if dut_error /= '1' and dut_do_valid /= '1' then
608
            while dut_error /= '1' and dut_do_valid /= '1' loop
609
                wait until pclk'event and pclk = '1';
610
            end loop;
611
        end if;
612
        wait for CLK_PERIOD*20;
613
 
614
        -- expected: 02779466 cdec1638 11d07881 5c633f21 90141308 1449002f 24aa3e80 f0b88ef7
615
        assert dut_H0 = x"02779466" report "test #5 failed on H0" severity error;
616
        assert dut_H1 = x"cdec1638" report "test #5 failed on H1" severity error;
617
        assert dut_H2 = x"11d07881" report "test #5 failed on H2" severity error;
618
        assert dut_H3 = x"5c633f21" report "test #5 failed on H3" severity error;
619
        assert dut_H4 = x"90141308" report "test #5 failed on H4" severity error;
620
        assert dut_H5 = x"1449002f" report "test #5 failed on H5" severity error;
621
        assert dut_H6 = x"24aa3e80" report "test #5 failed on H6" severity error;
622
        assert dut_H7 = x"f0b88ef7" report "test #5 failed on H7" severity error;
623
 
624
        -------------------------------------------------------------------------------------------
625
        -- test vector 6
626
        -- src: NIST-ADDITIONAL-SHA256
627
        -- #4) 56 bytes of zeros
628
        -- msg := 56 x"00"
629
        -- hash:= d4817aa5 497628e7 c77e6b60 6107042b bba31308 88c5f47a 375e6179 be789fbb
630
        test_case <= 6;
631
        dut_ce <= '0';
632
        dut_di <= (others => '0');
633
        dut_bytes <= b"00";
634
        dut_start <= '0';
635
        dut_end <= '0';
636
        dut_di_ack <= '0';
637
        wait until pclk'event and pclk = '1';
638
        dut_ce <= '1';
639
        dut_start <= '1';
640 6 jdoin
        dut_di <= x"00000000";
641
        dut_bytes <= b"00";
642
        dut_di_ack <= '1';
643 2 jdoin
        wait until pclk'event and pclk = '1';
644
        dut_start <= '0';
645
        wait until dut_di_req = '1';
646
        wait until pclk'event and pclk = '1';
647
        wait until pclk'event and pclk = '1';
648
        wait until pclk'event and pclk = '1';
649
        wait until pclk'event and pclk = '1';
650
        wait until pclk'event and pclk = '1';
651
        wait until pclk'event and pclk = '1';
652
        wait until pclk'event and pclk = '1';
653
        wait until pclk'event and pclk = '1';
654
        wait until pclk'event and pclk = '1';
655
        wait until pclk'event and pclk = '1';
656
        wait until pclk'event and pclk = '1';
657
        wait until pclk'event and pclk = '1';
658
        wait until pclk'event and pclk = '1';
659
        dut_end <= '1';
660
        wait until pclk'event and pclk = '1';
661
        dut_end <= '0';
662
        if dut_error /= '1' and dut_do_valid /= '1' then
663
            while dut_error /= '1' and dut_do_valid /= '1' loop
664
                wait until pclk'event and pclk = '1';
665
            end loop;
666
        end if;
667
        wait for CLK_PERIOD*20;
668
 
669
        -- expected: d4817aa5 497628e7 c77e6b60 6107042b bba31308 88c5f47a 375e6179 be789fbb
670
        assert dut_H0 = x"d4817aa5" report "test #6 failed on H0" severity error;
671
        assert dut_H1 = x"497628e7" report "test #6 failed on H1" severity error;
672
        assert dut_H2 = x"c77e6b60" report "test #6 failed on H2" severity error;
673
        assert dut_H3 = x"6107042b" report "test #6 failed on H3" severity error;
674
        assert dut_H4 = x"bba31308" report "test #6 failed on H4" severity error;
675
        assert dut_H5 = x"88c5f47a" report "test #6 failed on H5" severity error;
676
        assert dut_H6 = x"375e6179" report "test #6 failed on H6" severity error;
677
        assert dut_H7 = x"be789fbb" report "test #6 failed on H7" severity error;
678
 
679
        -------------------------------------------------------------------------------------------
680
        -- test vector 7
681
        -- src: NIST-ADDITIONAL-SHA256
682
        -- #5) 57 bytes of zeros
683
        -- msg := 57 x"00"
684
        -- hash:= 65a16cb7 861335d5 ace3c607 18b5052e 44660726 da4cd13b b745381b 235a1785
685
        test_case <= 7;
686
        dut_ce <= '0';
687
        dut_di <= (others => '0');
688
        dut_bytes <= b"00";
689
        dut_start <= '0';
690
        dut_end <= '0';
691
        dut_di_ack <= '0';
692
        wait until pclk'event and pclk = '1';
693
        dut_ce <= '1';
694
        dut_start <= '1';
695 6 jdoin
        dut_di <= x"00000000";
696
        dut_bytes <= b"00";
697
        dut_di_ack <= '1';
698 2 jdoin
        wait until pclk'event and pclk = '1';
699
        dut_start <= '0';
700
        wait until dut_di_req = '1';
701
        wait until pclk'event and pclk = '1';
702
        wait until pclk'event and pclk = '1';
703
        wait until pclk'event and pclk = '1';
704
        wait until pclk'event and pclk = '1';
705
        wait until pclk'event and pclk = '1';
706
        wait until pclk'event and pclk = '1';
707
        wait until pclk'event and pclk = '1';
708
        wait until pclk'event and pclk = '1';
709
        wait until pclk'event and pclk = '1';
710
        wait until pclk'event and pclk = '1';
711
        wait until pclk'event and pclk = '1';
712
        wait until pclk'event and pclk = '1';
713
        wait until pclk'event and pclk = '1';
714
        wait until pclk'event and pclk = '1';
715
        dut_end <= '1';
716
        dut_bytes <= b"01";
717
        wait until pclk'event and pclk = '1';
718
        dut_end <= '0';
719
        if dut_error /= '1' and dut_do_valid /= '1' then
720
            while dut_error /= '1' and dut_do_valid /= '1' loop
721
                wait until pclk'event and pclk = '1';
722
            end loop;
723
        end if;
724
        wait for CLK_PERIOD*20;
725
 
726
        -- expected: 65a16cb7 861335d5 ace3c607 18b5052e 44660726 da4cd13b b745381b 235a1785
727
        assert dut_H0 = x"65a16cb7" report "test #7 failed on H0" severity error;
728
        assert dut_H1 = x"861335d5" report "test #7 failed on H1" severity error;
729
        assert dut_H2 = x"ace3c607" report "test #7 failed on H2" severity error;
730
        assert dut_H3 = x"18b5052e" report "test #7 failed on H3" severity error;
731
        assert dut_H4 = x"44660726" report "test #7 failed on H4" severity error;
732
        assert dut_H5 = x"da4cd13b" report "test #7 failed on H5" severity error;
733
        assert dut_H6 = x"b745381b" report "test #7 failed on H6" severity error;
734
        assert dut_H7 = x"235a1785" report "test #7 failed on H7" severity error;
735
 
736
        -------------------------------------------------------------------------------------------
737
        -- test vector 8
738
        -- src: NIST-ADDITIONAL-SHA256
739
        -- #6) 64 bytes of zeros
740
        -- msg := 64 x"00"
741
        -- hash:= f5a5fd42 d16a2030 2798ef6e d309979b 43003d23 20d9f0e8 ea9831a9 2759fb4b
742
        test_case <= 8;
743
        dut_ce <= '0';
744
        dut_di <= (others => '0');
745
        dut_bytes <= b"00";
746
        dut_start <= '0';
747
        dut_end <= '0';
748
        dut_di_ack <= '0';
749
        wait until pclk'event and pclk = '1';
750
        dut_ce <= '1';
751
        dut_start <= '1';
752 6 jdoin
        dut_di <= x"00000000";
753
        dut_bytes <= b"00";
754
        dut_di_ack <= '1';
755 2 jdoin
        wait until pclk'event and pclk = '1';
756
        dut_start <= '0';
757
        wait until dut_di_req = '1';
758
        wait until pclk'event and pclk = '1';
759
        wait until pclk'event and pclk = '1';
760
        wait until pclk'event and pclk = '1';
761
        wait until pclk'event and pclk = '1';
762
        wait until pclk'event and pclk = '1';
763
        wait until pclk'event and pclk = '1';
764
        wait until pclk'event and pclk = '1';
765
        wait until pclk'event and pclk = '1';
766
        wait until pclk'event and pclk = '1';
767
        wait until pclk'event and pclk = '1';
768
        wait until pclk'event and pclk = '1';
769
        wait until pclk'event and pclk = '1';
770
        wait until pclk'event and pclk = '1';
771
        wait until pclk'event and pclk = '1';
772
        wait until pclk'event and pclk = '1';
773
        dut_end <= '1';
774
        wait until pclk'event and pclk = '1';
775
        dut_end <= '0';
776
        if dut_error /= '1' and dut_do_valid /= '1' then
777
            while dut_error /= '1' and dut_do_valid /= '1' loop
778
                wait until pclk'event and pclk = '1';
779
            end loop;
780
        end if;
781
        wait for CLK_PERIOD*20;
782
 
783
        -- expected: f5a5fd42 d16a2030 2798ef6e d309979b 43003d23 20d9f0e8 ea9831a9 2759fb4b
784
        assert dut_H0 = x"f5a5fd42" report "test #8 failed on H0" severity error;
785
        assert dut_H1 = x"d16a2030" report "test #8 failed on H1" severity error;
786
        assert dut_H2 = x"2798ef6e" report "test #8 failed on H2" severity error;
787
        assert dut_H3 = x"d309979b" report "test #8 failed on H3" severity error;
788
        assert dut_H4 = x"43003d23" report "test #8 failed on H4" severity error;
789
        assert dut_H5 = x"20d9f0e8" report "test #8 failed on H5" severity error;
790
        assert dut_H6 = x"ea9831a9" report "test #8 failed on H6" severity error;
791
        assert dut_H7 = x"2759fb4b" report "test #8 failed on H7" severity error;
792
 
793
        -------------------------------------------------------------------------------------------
794
        -- test vector 9
795
        -- src: NIST-ADDITIONAL-SHA256
796
        -- #7) 1000 bytes of zeros
797
        -- msg := 1000 x"00"
798
        -- hash:= 541b3e9d aa09b20b f85fa273 e5cbd3e8 0185aa4e c298e765 db87742b 70138a53
799
        test_case <= 9;
800
        dut_ce <= '0';
801
        dut_di <= (others => '0');
802
        dut_bytes <= b"00";
803
        dut_start <= '0';
804
        dut_end <= '0';
805
        dut_di_ack <= '0';
806
        wait until pclk'event and pclk = '1';
807
        dut_ce <= '1';
808
        dut_start <= '1';
809
        wait until pclk'event and pclk = '1';
810
        dut_start <= '0';
811
        dut_di_ack <= '1';
812
        dut_bytes <= b"00";
813
        dut_di <= x"00000000";
814
        count_words := 0;
815
        words <= count_words;
816
        count_blocks := 0;
817
        blocks <= count_blocks;
818
        loop
819
            wait until dut_di_req = '1';
820
            loop
821
                wait until pclk'event and pclk = '1';
822
                count_words := count_words + 1;
823
                words <= count_words;
824
                exit when words = 15;
825
            end loop;
826
            count_words := 0;
827
            words <= count_words;
828
            count_blocks := count_blocks + 1;
829
            blocks <= count_blocks;
830
            exit when blocks = 14;
831
        end loop;
832
        count_words := 0;
833
        words <= count_words;
834
        wait until dut_di_req = '1';
835
        loop
836
            wait until pclk'event and pclk = '1';
837
            count_words := count_words + 1;
838
            words <= count_words;
839
            exit when words = 8;
840
        end loop;
841
        dut_end <= '1';
842
        wait until pclk'event and pclk = '1';
843
        dut_end <= '0';
844
        if dut_error /= '1' and dut_do_valid /= '1' then
845
            while dut_error /= '1' and dut_do_valid /= '1' loop
846
                wait until pclk'event and pclk = '1';
847
            end loop;
848
        end if;
849
        wait for CLK_PERIOD*20;
850
 
851
        -- expected: 541b3e9d aa09b20b f85fa273 e5cbd3e8 0185aa4e c298e765 db87742b 70138a53
852
        assert dut_H0 = x"541b3e9d" report "test #9 failed on H0" severity error;
853
        assert dut_H1 = x"aa09b20b" report "test #9 failed on H1" severity error;
854
        assert dut_H2 = x"f85fa273" report "test #9 failed on H2" severity error;
855
        assert dut_H3 = x"e5cbd3e8" report "test #9 failed on H3" severity error;
856
        assert dut_H4 = x"0185aa4e" report "test #9 failed on H4" severity error;
857
        assert dut_H5 = x"c298e765" report "test #9 failed on H5" severity error;
858
        assert dut_H6 = x"db87742b" report "test #9 failed on H6" severity error;
859
        assert dut_H7 = x"70138a53" report "test #9 failed on H7" severity error;
860
 
861
        -------------------------------------------------------------------------------------------
862
        -- test vector 10
863
        -- src: NIST-ADDITIONAL-SHA256
864
        -- #8) 1000 bytes of 0x41 'A'
865
        -- msg := 1000 x"41"
866
        -- hash:= c2e68682 3489ced2 017f6059 b8b23931 8b6364f6 dcd835d0 a519105a 1eadd6e4
867
        test_case <= 10;
868
        dut_ce <= '0';
869
        dut_di <= (others => '0');
870
        dut_bytes <= b"00";
871
        dut_start <= '0';
872
        dut_end <= '0';
873
        dut_di_ack <= '0';
874
        wait until pclk'event and pclk = '1';
875
        dut_ce <= '1';
876
        dut_start <= '1';
877
        wait until pclk'event and pclk = '1';
878
        dut_start <= '0';
879
        dut_di_ack <= '1';
880
        dut_bytes <= b"00";
881
        dut_di <= x"41414141";
882
        count_words := 0;
883
        words <= count_words;
884
        count_blocks := 0;
885
        blocks <= count_blocks;
886
        loop
887
            wait until dut_di_req = '1';
888
            loop
889
                wait until pclk'event and pclk = '1';
890
                count_words := count_words + 1;
891
                words <= count_words;
892
                exit when words = 15;
893
            end loop;
894
            count_words := 0;
895
            words <= count_words;
896
            count_blocks := count_blocks + 1;
897
            blocks <= count_blocks;
898
            exit when blocks = 14;
899
        end loop;
900
        count_words := 0;
901
        words <= count_words;
902
        wait until dut_di_req = '1';
903
        loop
904
            wait until pclk'event and pclk = '1';
905
            count_words := count_words + 1;
906
            words <= count_words;
907
            exit when words = 8;
908
        end loop;
909
        dut_end <= '1';
910
        wait until pclk'event and pclk = '1';
911
        dut_end <= '0';
912
        if dut_error /= '1' and dut_do_valid /= '1' then
913
            while dut_error /= '1' and dut_do_valid /= '1' loop
914
                wait until pclk'event and pclk = '1';
915
            end loop;
916
        end if;
917
        wait for CLK_PERIOD*20;
918
 
919
        -- expected: c2e68682 3489ced2 017f6059 b8b23931 8b6364f6 dcd835d0 a519105a 1eadd6e4
920
        assert dut_H0 = x"c2e68682" report "test #10 failed on H0" severity error;
921
        assert dut_H1 = x"3489ced2" report "test #10 failed on H1" severity error;
922
        assert dut_H2 = x"017f6059" report "test #10 failed on H2" severity error;
923
        assert dut_H3 = x"b8b23931" report "test #10 failed on H3" severity error;
924
        assert dut_H4 = x"8b6364f6" report "test #10 failed on H4" severity error;
925
        assert dut_H5 = x"dcd835d0" report "test #10 failed on H5" severity error;
926
        assert dut_H6 = x"a519105a" report "test #10 failed on H6" severity error;
927
        assert dut_H7 = x"1eadd6e4" report "test #10 failed on H7" severity error;
928
 
929
        -------------------------------------------------------------------------------------------
930
        -- test vector 11
931
        -- src: NIST-ADDITIONAL-SHA256
932
        -- #9) 1005 bytes of 0x55 'U'
933
        -- msg := 1000 x"55"
934
        -- hash:= f4d62dde c0f3dd90 ea1380fa 16a5ff8d c4c54b21 740650f2 4afc4120 903552b0
935
        test_case <= 11;
936
        dut_ce <= '0';
937
        dut_di <= (others => '0');
938
        dut_bytes <= b"00";
939
        dut_start <= '0';
940
        dut_end <= '0';
941
        dut_di_ack <= '0';
942
        wait until pclk'event and pclk = '1';
943
        dut_ce <= '1';
944
        dut_start <= '1';
945
        wait until pclk'event and pclk = '1';
946
        dut_start <= '0';
947
        dut_di_ack <= '1';
948
        dut_bytes <= b"00";
949
        dut_di <= x"55555555";
950
        count_words := 0;
951
        words <= count_words;
952
        count_blocks := 0;
953
        blocks <= count_blocks;
954
        loop
955
            wait until dut_di_req = '1';
956
            loop
957
                wait until pclk'event and pclk = '1';
958
                count_words := count_words + 1;
959
                words <= count_words;
960
                exit when words = 15;
961
            end loop;
962
            count_words := 0;
963
            words <= count_words;
964
            count_blocks := count_blocks + 1;
965
            blocks <= count_blocks;
966
            exit when blocks = 14;
967
        end loop;
968
        count_words := 0;
969
        words <= count_words;
970
        wait until dut_di_req = '1';
971
        loop
972
            wait until pclk'event and pclk = '1';
973
            count_words := count_words + 1;
974
            words <= count_words;
975
            exit when words = 9;
976
        end loop;
977
        wait until pclk'event and pclk = '1';
978
        dut_bytes <= b"01";
979
        dut_end <= '1';
980
        wait until pclk'event and pclk = '1';
981
        dut_end <= '0';
982
        if dut_error /= '1' and dut_do_valid /= '1' then
983
            while dut_error /= '1' and dut_do_valid /= '1' loop
984
                wait until pclk'event and pclk = '1';
985
            end loop;
986
        end if;
987
        wait for CLK_PERIOD*20;
988
 
989
        -- expected: f4d62dde c0f3dd90 ea1380fa 16a5ff8d c4c54b21 740650f2 4afc4120 903552b0
990
        assert dut_H0 = x"f4d62dde" report "test #11 failed on H0" severity error;
991
        assert dut_H1 = x"c0f3dd90" report "test #11 failed on H1" severity error;
992
        assert dut_H2 = x"ea1380fa" report "test #11 failed on H2" severity error;
993
        assert dut_H3 = x"16a5ff8d" report "test #11 failed on H3" severity error;
994
        assert dut_H4 = x"c4c54b21" report "test #11 failed on H4" severity error;
995
        assert dut_H5 = x"740650f2" report "test #11 failed on H5" severity error;
996
        assert dut_H6 = x"4afc4120" report "test #11 failed on H6" severity error;
997
        assert dut_H7 = x"903552b0" report "test #11 failed on H7" severity error;
998
 
999
        -------------------------------------------------------------------------------------------
1000
        -- test vector 12
1001
        -- src: NIST-ADDITIONAL-SHA256
1002
        -- #10) 1000000 bytes of zeros
1003
        -- msg := 1000000 x"00"
1004
        -- hash:= d29751f2 649b32ff 572b5e0a 9f541ea6 60a50f94 ff0beedf b0b692b9 24cc8025
1005
        test_case <= 12;
1006
        dut_ce <= '0';
1007
        dut_di <= (others => '0');
1008
        dut_bytes <= b"00";
1009
        dut_start <= '0';
1010
        dut_end <= '0';
1011
        dut_di_ack <= '0';
1012
        wait until pclk'event and pclk = '1';
1013
        dut_ce <= '1';
1014
        dut_start <= '1';
1015
        wait until pclk'event and pclk = '1';
1016
        dut_start <= '0';
1017
        dut_di_ack <= '1';
1018
        dut_bytes <= b"00";
1019
        dut_di <= x"00000000";
1020
        count_words := 0;
1021
        words <= count_words;
1022
        count_blocks := 0;
1023
        blocks <= count_blocks;
1024
        loop
1025
            wait until dut_di_req = '1';
1026
            loop
1027
                wait until pclk'event and pclk = '1';
1028
                count_words := count_words + 1;
1029
                words <= count_words;
1030
                exit when words = 15;
1031
            end loop;
1032
            count_words := 0;
1033
            words <= count_words;
1034
            count_blocks := count_blocks + 1;
1035
            blocks <= count_blocks;
1036
            exit when blocks = 15623;
1037
        end loop;
1038
        count_words := 0;
1039
        words <= count_words;
1040
        wait until dut_di_req = '1';
1041
        loop
1042
            wait until pclk'event and pclk = '1';
1043
            count_words := count_words + 1;
1044
            words <= count_words;
1045
            exit when words = 14;
1046
        end loop;
1047
        dut_end <= '1';
1048
        wait until pclk'event and pclk = '1';
1049
        dut_end <= '0';
1050
        if dut_error /= '1' and dut_do_valid /= '1' then
1051
            while dut_error /= '1' and dut_do_valid /= '1' loop
1052
                wait until pclk'event and pclk = '1';
1053
            end loop;
1054
        end if;
1055
        wait for CLK_PERIOD*20;
1056
 
1057
        -- expected: d29751f2 649b32ff 572b5e0a 9f541ea6 60a50f94 ff0beedf b0b692b9 24cc8025
1058
        assert dut_H0 = x"d29751f2" report "test #12 failed on H0" severity error;
1059
        assert dut_H1 = x"649b32ff" report "test #12 failed on H1" severity error;
1060
        assert dut_H2 = x"572b5e0a" report "test #12 failed on H2" severity error;
1061
        assert dut_H3 = x"9f541ea6" report "test #12 failed on H3" severity error;
1062
        assert dut_H4 = x"60a50f94" report "test #12 failed on H4" severity error;
1063
        assert dut_H5 = x"ff0beedf" report "test #12 failed on H5" severity error;
1064
        assert dut_H6 = x"b0b692b9" report "test #12 failed on H6" severity error;
1065
        assert dut_H7 = x"24cc8025" report "test #12 failed on H7" severity error;
1066
 
1067
 
1068
        assert false report "End Simulation" severity failure; -- stop simulation
1069
    end process tb1;
1070
    --  End Test Bench 
1071
END;

powered by: WebSVN 2.1.0

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