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 2

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

Line No. Rev Author Line
1 2 jdoin
-----------------------------------------------------------------------------------------------------------------------
2
-- Author:          Jonny Doin, jdoin@opencores.org, jonnydoin@gmail.com
3
-- 
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
--                                                                   
164
--      Author(s):      Jonny Doin, jonnydoin@gridvortex.com, jonnydoin@gmail.com
165
--                                                                   
166
--      Copyright (C) 2016 GridVortex, All Rights Reserved
167
--      --------------------------------------------------
168
--                                                                   
169
------------------------------ REVISION HISTORY -----------------------------------------------------------------------
170
--
171
-- 2016/05/22   v0.01.0010  [JD]    started development. design of blocks and port interfaces.
172
-- 2016/06/05   v0.01.0090  [JD]    all modules integrated. testbench for basic test vectors verification.
173
-- 2016/06/05   v0.01.0095  [JD]    verification failed. misalignment of words in the datapath. 
174
-- 2016/06/06   v0.01.0100  [JD]    first simulation verification against NIST-FIPS-180-4 test vectors "abc" passed.
175
-- 2016/06/07   v0.01.0101  [JD]    failed 2-block test for "abcdbcdecd..." vector. Fixed padding control logic.
176
-- 2016/06/07   v0.01.0105  [JD]    sha256 verification against all NIST-FIPS-180-4 test vectors passed.
177
-- 2016/06/11   v0.01.0105  [JD]    verification against NIST-SHA2_Additional test vectors #1 to #10 passed.
178
-- 2016/06/11   v0.01.0110  [JD]    optimized controller states, reduced 2 clocks per block. 
179
-- 2016/06/18   v0.01.0120  [JD]    implemented error detection on 'bytes_i' input.
180
--
181
-----------------------------------------------------------------------------------------------------------------------
182
--  TODO
183
--  ====
184
--
185
--
186
-----------------------------------------------------------------------------------------------------------------------
187
library ieee;
188
use ieee.std_logic_1164.all;
189
use ieee.numeric_std.all;
190
 
191
entity testbench is
192
    Generic (
193
        CLK_PERIOD : time := 10 ns;                     -- clock period for pclk_i (default 100MHz)
194
        START_DELAY : time := 200 ns                    -- start delay between each run
195
    );
196
end testbench;
197
 
198
architecture behavior of testbench is
199
 
200
    --=============================================================================================
201
    -- Constants
202
    --=============================================================================================
203
    -- clock period
204
    constant PCLK_PERIOD : time := CLK_PERIOD;          -- parallel high-speed clock
205
 
206
    --=============================================================================================
207
    -- Signals for state machine control
208
    --=============================================================================================
209
 
210
    --=============================================================================================
211
    -- Signals for internal operation
212
    --=============================================================================================
213
    --- clock signals ---
214
    signal pclk             : std_logic := '1';                 -- 100MHz clock
215
    signal dut_ce           : std_logic;
216
    -- input data
217
    signal dut_di           : std_logic_vector (31 downto 0);   -- big endian input message words
218
    signal dut_bytes        : std_logic_vector (1 downto 0);    -- valid bytes in input word
219
    -- start/end commands
220
    signal dut_start        : std_logic;                        -- reset the processor and start a new hash
221
    signal dut_end          : std_logic;                        -- marks end of last block data input
222
    -- handshake
223
    signal dut_di_req       : std_logic;                        -- requests data input for next word
224
    signal dut_di_ack       : std_logic;                        -- high for di_i valid, low for hold
225
    signal dut_error        : std_logic;                        -- signalizes error. output data is invalid
226
    signal dut_do_valid     : std_logic;                        -- when high, the output is valid
227
    -- 256bit output registers
228
    signal dut_H0           : std_logic_vector (31 downto 0);
229
    signal dut_H1           : std_logic_vector (31 downto 0);
230
    signal dut_H2           : std_logic_vector (31 downto 0);
231
    signal dut_H3           : std_logic_vector (31 downto 0);
232
    signal dut_H4           : std_logic_vector (31 downto 0);
233
    signal dut_H5           : std_logic_vector (31 downto 0);
234
    signal dut_H6           : std_logic_vector (31 downto 0);
235
    signal dut_H7           : std_logic_vector (31 downto 0);
236
 
237
    -- testbench control signals
238
    signal words            : natural;
239
    signal blocks           : natural;
240
    signal test_case        : natural;
241
begin
242
 
243
    --=============================================================================================
244
    -- INSTANTIATION FOR THE DEVICE UNDER TEST
245
    --=============================================================================================
246
        Inst_sha_256_dut: entity work.gv_sha256(rtl)
247
        port map(
248
            -- clock and core enable
249
            clk_i => pclk,
250
            ce_i => dut_ce,
251
            -- input data
252
            di_i => dut_di,
253
            bytes_i => dut_bytes,
254
            -- start/end commands
255
            start_i => dut_start,
256
            end_i => dut_end,
257
            -- handshake
258
            di_req_o => dut_di_req,
259
            di_ack_i => dut_di_ack,
260
            error_o => dut_error,
261
            do_valid_o => dut_do_valid,
262
            -- 256bit output registers 
263
            H0_o => dut_H0,
264
            H1_o => dut_H1,
265
            H2_o => dut_H2,
266
            H3_o => dut_H3,
267
            H4_o => dut_H4,
268
            H5_o => dut_H5,
269
            H6_o => dut_H6,
270
            H7_o => dut_H7
271
        );
272
 
273
    --=============================================================================================
274
    -- CLOCK GENERATION
275
    --=============================================================================================
276
    pclk_proc: process is
277
    begin
278
        loop
279
            pclk <= not pclk;
280
            wait for PCLK_PERIOD / 2;
281
        end loop;
282
    end process pclk_proc;
283
    --=============================================================================================
284
    -- TEST BENCH STIMULI
285
    --=============================================================================================
286
    -- This testbench exercises the SHA256 toplevel with the NIST-FIPS-180-4 test vectors.
287
    --
288
    tb1 : process is
289
        variable count_words  : natural := 0;
290
        variable count_blocks : natural := 0;
291
        variable temp_di      : unsigned (31 downto 0) := (others => '0');
292
    begin
293
        wait for START_DELAY; -- wait until global set/reset completes
294
        -------------------------------------------------------------------------------------------
295
        -- test vector 1
296
        -- src: NIST-FIPS-180-4 
297
        -- msg := "abc" 
298
        -- hash:= BA7816BF 8F01CFEA 414140DE 5DAE2223 B00361A3 96177A9C B410FF61 F20015AD
299
        test_case <= 1;
300
        dut_ce <= '0';
301
        dut_di <= (others => '0');
302
        dut_bytes <= b"00";
303
        dut_start <= '0';
304
        dut_end <= '0';
305
        dut_di_ack <= '0';
306
        wait until pclk'event and pclk = '1';
307
        dut_ce <= '1';
308
        dut_start <= '1';
309
        wait until pclk'event and pclk = '1';
310
        dut_start <= '0';
311
        wait until dut_di_req = '1';
312
        wait until pclk'event and pclk = '1';
313
        dut_di_ack <= '1';
314
        dut_di <= x"61626300";
315
        dut_bytes <= b"11";
316
        dut_end <= '1';
317
        wait until pclk'event and pclk = '1';
318
        dut_end <= '0';
319
        if dut_error /= '1' and dut_do_valid /= '1' then
320
            while dut_error /= '1' and dut_do_valid /= '1' loop
321
                wait until pclk'event and pclk = '1';
322
            end loop;
323
        end if;
324
        wait for CLK_PERIOD*20;
325
 
326
        -- expected: BA7816BF 8F01CFEA 414140DE 5DAE2223 B00361A3 96177A9C B410FF61 F20015AD
327
        assert dut_H0 = x"BA7816BF" report "test #1 failed on H0" severity error;
328
        assert dut_H1 = x"8F01CFEA" report "test #1 failed on H1" severity error;
329
        assert dut_H2 = x"414140DE" report "test #1 failed on H2" severity error;
330
        assert dut_H3 = x"5DAE2223" report "test #1 failed on H3" severity error;
331
        assert dut_H4 = x"B00361A3" report "test #1 failed on H4" severity error;
332
        assert dut_H5 = x"96177A9C" report "test #1 failed on H5" severity error;
333
        assert dut_H6 = x"B410FF61" report "test #1 failed on H6" severity error;
334
        assert dut_H7 = x"F20015AD" report "test #1 failed on H7" severity error;
335
 
336
        -------------------------------------------------------------------------------------------
337
        -- test vector 2
338
        -- src: NIST-FIPS-180-4 
339
        -- msg := "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
340
        -- hash:= 248D6A61 D20638B8 E5C02693 0C3E6039 A33CE459 64FF2167 F6ECEDD4 19DB06C1
341
        test_case <= 2;
342
        dut_ce <= '0';
343
        dut_di <= (others => '0');
344
        dut_bytes <= b"00";
345
        dut_start <= '0';
346
        dut_end <= '0';
347
        dut_di_ack <= '0';
348
        wait until pclk'event and pclk = '1';
349
        dut_ce <= '1';
350
        dut_start <= '1';
351
        wait until pclk'event and pclk = '1';   -- 'begin' pulse minimum width is one clock
352
        wait for 25 ns;                         -- TEST: stretch 'begin' pulse
353
        dut_start <= '0';
354
        wait until dut_di_req = '1';
355
        wait until pclk'event and pclk = '1';
356
        dut_di_ack <= '1';
357
        dut_bytes <= b"00";
358
        dut_di <= x"61626364";
359
        wait until pclk'event and pclk = '1';
360
        dut_di <= x"62636465";
361
        wait until pclk'event and pclk = '1';
362
        dut_di <= x"63646566";
363
        wait until pclk'event and pclk = '1';
364
        dut_di <= x"64656667";
365
        wait until pclk'event and pclk = '1';
366
        dut_di <= x"65666768";
367
        wait until pclk'event and pclk = '1';
368
        dut_di <= x"66676869";
369
        wait until pclk'event and pclk = '1';
370
        dut_di <= x"6768696A";
371
        dut_di_ack <= '0';
372
        wait until pclk'event and pclk = '1';
373
        wait until pclk'event and pclk = '1';
374
        wait until pclk'event and pclk = '1';
375
        dut_di_ack <= '1';                      -- TEST: slow inputs with 'ack' handshake
376
        wait until pclk'event and pclk = '1';
377
        dut_di <= x"68696A6B";
378
        wait until pclk'event and pclk = '1';
379
        dut_di <= x"696A6B6C";
380
        wait until pclk'event and pclk = '1';
381
        dut_di <= x"6A6B6C6D";
382
        dut_bytes <= b"01";                     -- induce ERROR
383
        wait until pclk'event and pclk = '1';
384
        dut_di <= x"6B6C6D6E";
385
        wait until pclk'event and pclk = '1';
386
        dut_di <= x"6C6D6E6F";
387
        wait until pclk'event and pclk = '1';
388
        dut_di <= x"6D6E6F70";
389
        wait until pclk'event and pclk = '1';
390
        dut_di <= x"6E6F7071";
391
        dut_end <= '1';
392
        wait until pclk'event and pclk = '1';   -- 'end' pulse minimum width is one clock
393
        dut_bytes <= b"01";                     -- TEST: change 'bytes' value after END
394
        wait for 75 ns;                         -- TEST: stretch 'end' pulse
395
        dut_end <= '0';
396
        if dut_error /= '1' and dut_do_valid /= '1' then
397
            while dut_error /= '1' and dut_do_valid /= '1' loop
398
                wait until pclk'event and pclk = '1';
399
            end loop;
400
        end if;
401
        wait for CLK_PERIOD*20;
402
        -------------------------------------------------------------------------
403
        -- restart test #2
404
        test_case <= 0;
405
        wait until pclk'event and pclk = '1';
406
        test_case <= 2;
407
        dut_ce <= '0';
408
        dut_di <= (others => '0');
409
        dut_bytes <= b"00";
410
        dut_start <= '0';
411
        dut_end <= '0';
412
        dut_di_ack <= '0';
413
        wait until pclk'event and pclk = '1';
414
        dut_ce <= '1';
415
        dut_start <= '1';
416
        wait until pclk'event and pclk = '1';   -- 'begin' pulse minimum width is one clock
417
        dut_start <= '0';
418
        wait until dut_di_req = '1';
419
        wait until pclk'event and pclk = '1';
420
        dut_di_ack <= '1';
421
        dut_bytes <= b"00";
422
        dut_di <= x"61626364";
423
        wait until pclk'event and pclk = '1';
424
        dut_di <= x"62636465";
425
        wait until pclk'event and pclk = '1';
426
        dut_di <= x"63646566";
427
        wait until pclk'event and pclk = '1';
428
        dut_di <= x"64656667";
429
        wait until pclk'event and pclk = '1';
430
        dut_di <= x"65666768";
431
        wait until pclk'event and pclk = '1';
432
        dut_di <= x"66676869";
433
        wait until pclk'event and pclk = '1';
434
        dut_di <= x"6768696A";
435
        wait until pclk'event and pclk = '1';
436
        dut_di <= x"68696A6B";
437
        wait until pclk'event and pclk = '1';
438
        dut_di <= x"696A6B6C";
439
        wait until pclk'event and pclk = '1';
440
        dut_di <= x"6A6B6C6D";
441
        wait until pclk'event and pclk = '1';
442
        dut_di <= x"6B6C6D6E";
443
        wait until pclk'event and pclk = '1';
444
        dut_di <= x"6C6D6E6F";
445
        wait until pclk'event and pclk = '1';
446
        dut_di <= x"6D6E6F70";
447
        wait until pclk'event and pclk = '1';
448
        dut_di <= x"6E6F7071";
449
        dut_end <= '1';
450
        wait until pclk'event and pclk = '1';   -- 'end' pulse minimum width is one clock
451
        dut_end <= '0';
452
        if dut_error /= '1' and dut_do_valid /= '1' then
453
            while dut_error /= '1' and dut_do_valid /= '1' loop
454
                wait until pclk'event and pclk = '1';
455
            end loop;
456
        end if;
457
        wait for CLK_PERIOD*20;
458
 
459
        -- expected: 248D6A61 D20638B8 E5C02693 0C3E6039 A33CE459 64FF2167 F6ECEDD4 19DB06C1
460
        assert dut_H0 = x"248D6A61" report "test #2 failed on H0" severity error;
461
        assert dut_H1 = x"D20638B8" report "test #2 failed on H1" severity error;
462
        assert dut_H2 = x"E5C02693" report "test #2 failed on H2" severity error;
463
        assert dut_H3 = x"0C3E6039" report "test #2 failed on H3" severity error;
464
        assert dut_H4 = x"A33CE459" report "test #2 failed on H4" severity error;
465
        assert dut_H5 = x"64FF2167" report "test #2 failed on H5" severity error;
466
        assert dut_H6 = x"F6ECEDD4" report "test #2 failed on H6" severity error;
467
        assert dut_H7 = x"19DB06C1" report "test #2 failed on H7" severity error;
468
 
469
        -------------------------------------------------------------------------------------------
470
        -- test vector 3
471
        -- src: NIST-ADDITIONAL-SHA256
472
        -- #1) 1 byte 0xbd
473
        -- msg := x"bd"
474
        -- hash:= 68325720 aabd7c82 f30f554b 313d0570 c95accbb 7dc4b5aa e11204c0 8ffe732b
475
        test_case <= 3;
476
        dut_ce <= '0';
477
        dut_di <= (others => '0');
478
        dut_bytes <= b"00";
479
        dut_start <= '0';
480
        dut_end <= '0';
481
        dut_di_ack <= '0';
482
        wait until pclk'event and pclk = '1';
483
        dut_ce <= '1';
484
        dut_start <= '1';
485
        wait until pclk'event and pclk = '1';
486
        dut_start <= '0';
487
        wait until dut_di_req = '1';
488
        wait until pclk'event and pclk = '1';
489
        dut_di_ack <= '1';
490
        dut_di <= x"bd000000";
491
        dut_bytes <= b"01";
492
        dut_end <= '1';
493
        wait until pclk'event and pclk = '1';
494
        dut_end <= '0';
495
        if dut_error /= '1' and dut_do_valid /= '1' then
496
            while dut_error /= '1' and dut_do_valid /= '1' loop
497
                wait until pclk'event and pclk = '1';
498
            end loop;
499
        end if;
500
        wait for CLK_PERIOD*20;
501
 
502
        -- expected: 68325720 aabd7c82 f30f554b 313d0570 c95accbb 7dc4b5aa e11204c0 8ffe732b
503
        assert dut_H0 = x"68325720" report "test #3 failed on H0" severity error;
504
        assert dut_H1 = x"aabd7c82" report "test #3 failed on H1" severity error;
505
        assert dut_H2 = x"f30f554b" report "test #3 failed on H2" severity error;
506
        assert dut_H3 = x"313d0570" report "test #3 failed on H3" severity error;
507
        assert dut_H4 = x"c95accbb" report "test #3 failed on H4" severity error;
508
        assert dut_H5 = x"7dc4b5aa" report "test #3 failed on H5" severity error;
509
        assert dut_H6 = x"e11204c0" report "test #3 failed on H6" severity error;
510
        assert dut_H7 = x"8ffe732b" report "test #3 failed on H7" severity error;
511
 
512
        -------------------------------------------------------------------------------------------
513
        -- test vector 4
514
        -- src: NIST-ADDITIONAL-SHA256
515
        -- #2) 4 bytes 0xc98c8e55
516
        -- msg := x"c98c8e55"
517
        -- hash:= 7abc22c0 ae5af26c e93dbb94 433a0e0b 2e119d01 4f8e7f65 bd56c61c cccd9504
518
        test_case <= 4;
519
        dut_ce <= '0';
520
        dut_di <= (others => '0');
521
        dut_bytes <= b"00";
522
        dut_start <= '0';
523
        dut_end <= '0';
524
        dut_di_ack <= '0';
525
        wait until pclk'event and pclk = '1';
526
        dut_ce <= '1';
527
        dut_start <= '1';
528
        wait until pclk'event and pclk = '1';
529
        dut_start <= '0';
530
        wait until dut_di_req = '1';
531
        wait until pclk'event and pclk = '1';
532
        dut_di_ack <= '1';
533
        dut_di <= x"c98c8e55";
534
        dut_bytes <= b"00";
535
        dut_end <= '1';
536
        wait until pclk'event and pclk = '1';
537
        dut_end <= '0';
538
        if dut_error /= '1' and dut_do_valid /= '1' then
539
            while dut_error /= '1' and dut_do_valid /= '1' loop
540
                wait until pclk'event and pclk = '1';
541
            end loop;
542
        end if;
543
        wait for CLK_PERIOD*20;
544
 
545
        -- expected: 7abc22c0 ae5af26c e93dbb94 433a0e0b 2e119d01 4f8e7f65 bd56c61c cccd9504 
546
        assert dut_H0 = x"7abc22c0" report "test #4 failed on H0" severity error;
547
        assert dut_H1 = x"ae5af26c" report "test #4 failed on H1" severity error;
548
        assert dut_H2 = x"e93dbb94" report "test #4 failed on H2" severity error;
549
        assert dut_H3 = x"433a0e0b" report "test #4 failed on H3" severity error;
550
        assert dut_H4 = x"2e119d01" report "test #4 failed on H4" severity error;
551
        assert dut_H5 = x"4f8e7f65" report "test #4 failed on H5" severity error;
552
        assert dut_H6 = x"bd56c61c" report "test #4 failed on H6" severity error;
553
        assert dut_H7 = x"cccd9504" report "test #4 failed on H7" severity error;
554
 
555
        -------------------------------------------------------------------------------------------
556
        -- test vector 5
557
        -- src: NIST-ADDITIONAL-SHA256
558
        -- #3) 55 bytes of zeros
559
        -- msg := 55 x"00"
560
        -- hash:= 02779466 cdec1638 11d07881 5c633f21 90141308 1449002f 24aa3e80 f0b88ef7
561
        test_case <= 5;
562
        dut_ce <= '0';
563
        dut_di <= (others => '0');
564
        dut_bytes <= b"00";
565
        dut_start <= '0';
566
        dut_end <= '0';
567
        dut_di_ack <= '0';
568
        wait until pclk'event and pclk = '1';
569
        dut_ce <= '1';
570
        dut_start <= '1';
571
        wait until pclk'event and pclk = '1';
572
        dut_start <= '0';
573
        wait until dut_di_req = '1';
574
        wait until pclk'event and pclk = '1';
575
        dut_di_ack <= '1';
576
        dut_bytes <= b"00";
577
        dut_di <= x"00000000";
578
        wait until pclk'event and pclk = '1';
579
        wait until pclk'event and pclk = '1';
580
        wait until pclk'event and pclk = '1';
581
        wait until pclk'event and pclk = '1';
582
        wait until pclk'event and pclk = '1';
583
        wait until pclk'event and pclk = '1';
584
        wait until pclk'event and pclk = '1';
585
        wait until pclk'event and pclk = '1';
586
        wait until pclk'event and pclk = '1';
587
        wait until pclk'event and pclk = '1';
588
        wait until pclk'event and pclk = '1';
589
        wait until pclk'event and pclk = '1';
590
        wait until pclk'event and pclk = '1';
591
        dut_end <= '1';
592
        dut_bytes <= b"11";
593
        wait until pclk'event and pclk = '1';
594
        dut_end <= '0';
595
        if dut_error /= '1' and dut_do_valid /= '1' then
596
            while dut_error /= '1' and dut_do_valid /= '1' loop
597
                wait until pclk'event and pclk = '1';
598
            end loop;
599
        end if;
600
        wait for CLK_PERIOD*20;
601
 
602
        -- expected: 02779466 cdec1638 11d07881 5c633f21 90141308 1449002f 24aa3e80 f0b88ef7
603
        assert dut_H0 = x"02779466" report "test #5 failed on H0" severity error;
604
        assert dut_H1 = x"cdec1638" report "test #5 failed on H1" severity error;
605
        assert dut_H2 = x"11d07881" report "test #5 failed on H2" severity error;
606
        assert dut_H3 = x"5c633f21" report "test #5 failed on H3" severity error;
607
        assert dut_H4 = x"90141308" report "test #5 failed on H4" severity error;
608
        assert dut_H5 = x"1449002f" report "test #5 failed on H5" severity error;
609
        assert dut_H6 = x"24aa3e80" report "test #5 failed on H6" severity error;
610
        assert dut_H7 = x"f0b88ef7" report "test #5 failed on H7" severity error;
611
 
612
        -------------------------------------------------------------------------------------------
613
        -- test vector 6
614
        -- src: NIST-ADDITIONAL-SHA256
615
        -- #4) 56 bytes of zeros
616
        -- msg := 56 x"00"
617
        -- hash:= d4817aa5 497628e7 c77e6b60 6107042b bba31308 88c5f47a 375e6179 be789fbb
618
        test_case <= 6;
619
        dut_ce <= '0';
620
        dut_di <= (others => '0');
621
        dut_bytes <= b"00";
622
        dut_start <= '0';
623
        dut_end <= '0';
624
        dut_di_ack <= '0';
625
        wait until pclk'event and pclk = '1';
626
        dut_ce <= '1';
627
        dut_start <= '1';
628
        wait until pclk'event and pclk = '1';
629
        dut_start <= '0';
630
        wait until dut_di_req = '1';
631
        wait until pclk'event and pclk = '1';
632
        dut_di_ack <= '1';
633
        dut_bytes <= b"00";
634
        dut_di <= x"00000000";
635
        wait until pclk'event and pclk = '1';
636
        wait until pclk'event and pclk = '1';
637
        wait until pclk'event and pclk = '1';
638
        wait until pclk'event and pclk = '1';
639
        wait until pclk'event and pclk = '1';
640
        wait until pclk'event and pclk = '1';
641
        wait until pclk'event and pclk = '1';
642
        wait until pclk'event and pclk = '1';
643
        wait until pclk'event and pclk = '1';
644
        wait until pclk'event and pclk = '1';
645
        wait until pclk'event and pclk = '1';
646
        wait until pclk'event and pclk = '1';
647
        wait until pclk'event and pclk = '1';
648
        dut_end <= '1';
649
        wait until pclk'event and pclk = '1';
650
        dut_end <= '0';
651
        if dut_error /= '1' and dut_do_valid /= '1' then
652
            while dut_error /= '1' and dut_do_valid /= '1' loop
653
                wait until pclk'event and pclk = '1';
654
            end loop;
655
        end if;
656
        wait for CLK_PERIOD*20;
657
 
658
        -- expected: d4817aa5 497628e7 c77e6b60 6107042b bba31308 88c5f47a 375e6179 be789fbb
659
        assert dut_H0 = x"d4817aa5" report "test #6 failed on H0" severity error;
660
        assert dut_H1 = x"497628e7" report "test #6 failed on H1" severity error;
661
        assert dut_H2 = x"c77e6b60" report "test #6 failed on H2" severity error;
662
        assert dut_H3 = x"6107042b" report "test #6 failed on H3" severity error;
663
        assert dut_H4 = x"bba31308" report "test #6 failed on H4" severity error;
664
        assert dut_H5 = x"88c5f47a" report "test #6 failed on H5" severity error;
665
        assert dut_H6 = x"375e6179" report "test #6 failed on H6" severity error;
666
        assert dut_H7 = x"be789fbb" report "test #6 failed on H7" severity error;
667
 
668
        -------------------------------------------------------------------------------------------
669
        -- test vector 7
670
        -- src: NIST-ADDITIONAL-SHA256
671
        -- #5) 57 bytes of zeros
672
        -- msg := 57 x"00"
673
        -- hash:= 65a16cb7 861335d5 ace3c607 18b5052e 44660726 da4cd13b b745381b 235a1785
674
        test_case <= 7;
675
        dut_ce <= '0';
676
        dut_di <= (others => '0');
677
        dut_bytes <= b"00";
678
        dut_start <= '0';
679
        dut_end <= '0';
680
        dut_di_ack <= '0';
681
        wait until pclk'event and pclk = '1';
682
        dut_ce <= '1';
683
        dut_start <= '1';
684
        wait until pclk'event and pclk = '1';
685
        dut_start <= '0';
686
        wait until dut_di_req = '1';
687
        wait until pclk'event and pclk = '1';
688
        dut_di_ack <= '1';
689
        dut_bytes <= b"00";
690
        dut_di <= x"00000000";
691
        wait until pclk'event and pclk = '1';
692
        wait until pclk'event and pclk = '1';
693
        wait until pclk'event and pclk = '1';
694
        wait until pclk'event and pclk = '1';
695
        wait until pclk'event and pclk = '1';
696
        wait until pclk'event and pclk = '1';
697
        wait until pclk'event and pclk = '1';
698
        wait until pclk'event and pclk = '1';
699
        wait until pclk'event and pclk = '1';
700
        wait until pclk'event and pclk = '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
        dut_end <= '1';
706
        dut_bytes <= b"01";
707
        wait until pclk'event and pclk = '1';
708
        dut_end <= '0';
709
        if dut_error /= '1' and dut_do_valid /= '1' then
710
            while dut_error /= '1' and dut_do_valid /= '1' loop
711
                wait until pclk'event and pclk = '1';
712
            end loop;
713
        end if;
714
        wait for CLK_PERIOD*20;
715
 
716
        -- expected: 65a16cb7 861335d5 ace3c607 18b5052e 44660726 da4cd13b b745381b 235a1785
717
        assert dut_H0 = x"65a16cb7" report "test #7 failed on H0" severity error;
718
        assert dut_H1 = x"861335d5" report "test #7 failed on H1" severity error;
719
        assert dut_H2 = x"ace3c607" report "test #7 failed on H2" severity error;
720
        assert dut_H3 = x"18b5052e" report "test #7 failed on H3" severity error;
721
        assert dut_H4 = x"44660726" report "test #7 failed on H4" severity error;
722
        assert dut_H5 = x"da4cd13b" report "test #7 failed on H5" severity error;
723
        assert dut_H6 = x"b745381b" report "test #7 failed on H6" severity error;
724
        assert dut_H7 = x"235a1785" report "test #7 failed on H7" severity error;
725
 
726
        -------------------------------------------------------------------------------------------
727
        -- test vector 8
728
        -- src: NIST-ADDITIONAL-SHA256
729
        -- #6) 64 bytes of zeros
730
        -- msg := 64 x"00"
731
        -- hash:= f5a5fd42 d16a2030 2798ef6e d309979b 43003d23 20d9f0e8 ea9831a9 2759fb4b
732
        test_case <= 8;
733
        dut_ce <= '0';
734
        dut_di <= (others => '0');
735
        dut_bytes <= b"00";
736
        dut_start <= '0';
737
        dut_end <= '0';
738
        dut_di_ack <= '0';
739
        wait until pclk'event and pclk = '1';
740
        dut_ce <= '1';
741
        dut_start <= '1';
742
        wait until pclk'event and pclk = '1';
743
        dut_start <= '0';
744
        wait until dut_di_req = '1';
745
        wait until pclk'event and pclk = '1';
746
        dut_di_ack <= '1';
747
        dut_bytes <= b"00";
748
        dut_di <= x"00000000";
749
        wait until pclk'event and pclk = '1';
750
        wait until pclk'event and pclk = '1';
751
        wait until pclk'event and pclk = '1';
752
        wait until pclk'event and pclk = '1';
753
        wait until pclk'event and pclk = '1';
754
        wait until pclk'event and pclk = '1';
755
        wait until pclk'event and pclk = '1';
756
        wait until pclk'event and pclk = '1';
757
        wait until pclk'event and pclk = '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
        dut_end <= '1';
765
        wait until pclk'event and pclk = '1';
766
        dut_end <= '0';
767
        if dut_error /= '1' and dut_do_valid /= '1' then
768
            while dut_error /= '1' and dut_do_valid /= '1' loop
769
                wait until pclk'event and pclk = '1';
770
            end loop;
771
        end if;
772
        wait for CLK_PERIOD*20;
773
 
774
        -- expected: f5a5fd42 d16a2030 2798ef6e d309979b 43003d23 20d9f0e8 ea9831a9 2759fb4b
775
        assert dut_H0 = x"f5a5fd42" report "test #8 failed on H0" severity error;
776
        assert dut_H1 = x"d16a2030" report "test #8 failed on H1" severity error;
777
        assert dut_H2 = x"2798ef6e" report "test #8 failed on H2" severity error;
778
        assert dut_H3 = x"d309979b" report "test #8 failed on H3" severity error;
779
        assert dut_H4 = x"43003d23" report "test #8 failed on H4" severity error;
780
        assert dut_H5 = x"20d9f0e8" report "test #8 failed on H5" severity error;
781
        assert dut_H6 = x"ea9831a9" report "test #8 failed on H6" severity error;
782
        assert dut_H7 = x"2759fb4b" report "test #8 failed on H7" severity error;
783
 
784
        -------------------------------------------------------------------------------------------
785
        -- test vector 9
786
        -- src: NIST-ADDITIONAL-SHA256
787
        -- #7) 1000 bytes of zeros
788
        -- msg := 1000 x"00"
789
        -- hash:= 541b3e9d aa09b20b f85fa273 e5cbd3e8 0185aa4e c298e765 db87742b 70138a53
790
        test_case <= 9;
791
        dut_ce <= '0';
792
        dut_di <= (others => '0');
793
        dut_bytes <= b"00";
794
        dut_start <= '0';
795
        dut_end <= '0';
796
        dut_di_ack <= '0';
797
        wait until pclk'event and pclk = '1';
798
        dut_ce <= '1';
799
        dut_start <= '1';
800
        wait until pclk'event and pclk = '1';
801
        dut_start <= '0';
802
        dut_di_ack <= '1';
803
        dut_bytes <= b"00";
804
        dut_di <= x"00000000";
805
        count_words := 0;
806
        words <= count_words;
807
        count_blocks := 0;
808
        blocks <= count_blocks;
809
        loop
810
            wait until dut_di_req = '1';
811
            loop
812
                wait until pclk'event and pclk = '1';
813
                count_words := count_words + 1;
814
                words <= count_words;
815
                exit when words = 15;
816
            end loop;
817
            count_words := 0;
818
            words <= count_words;
819
            count_blocks := count_blocks + 1;
820
            blocks <= count_blocks;
821
            exit when blocks = 14;
822
        end loop;
823
        count_words := 0;
824
        words <= count_words;
825
        wait until dut_di_req = '1';
826
        loop
827
            wait until pclk'event and pclk = '1';
828
            count_words := count_words + 1;
829
            words <= count_words;
830
            exit when words = 8;
831
        end loop;
832
        dut_end <= '1';
833
        wait until pclk'event and pclk = '1';
834
        dut_end <= '0';
835
        if dut_error /= '1' and dut_do_valid /= '1' then
836
            while dut_error /= '1' and dut_do_valid /= '1' loop
837
                wait until pclk'event and pclk = '1';
838
            end loop;
839
        end if;
840
        wait for CLK_PERIOD*20;
841
 
842
        -- expected: 541b3e9d aa09b20b f85fa273 e5cbd3e8 0185aa4e c298e765 db87742b 70138a53
843
        assert dut_H0 = x"541b3e9d" report "test #9 failed on H0" severity error;
844
        assert dut_H1 = x"aa09b20b" report "test #9 failed on H1" severity error;
845
        assert dut_H2 = x"f85fa273" report "test #9 failed on H2" severity error;
846
        assert dut_H3 = x"e5cbd3e8" report "test #9 failed on H3" severity error;
847
        assert dut_H4 = x"0185aa4e" report "test #9 failed on H4" severity error;
848
        assert dut_H5 = x"c298e765" report "test #9 failed on H5" severity error;
849
        assert dut_H6 = x"db87742b" report "test #9 failed on H6" severity error;
850
        assert dut_H7 = x"70138a53" report "test #9 failed on H7" severity error;
851
 
852
        -------------------------------------------------------------------------------------------
853
        -- test vector 10
854
        -- src: NIST-ADDITIONAL-SHA256
855
        -- #8) 1000 bytes of 0x41 'A'
856
        -- msg := 1000 x"41"
857
        -- hash:= c2e68682 3489ced2 017f6059 b8b23931 8b6364f6 dcd835d0 a519105a 1eadd6e4
858
        test_case <= 10;
859
        dut_ce <= '0';
860
        dut_di <= (others => '0');
861
        dut_bytes <= b"00";
862
        dut_start <= '0';
863
        dut_end <= '0';
864
        dut_di_ack <= '0';
865
        wait until pclk'event and pclk = '1';
866
        dut_ce <= '1';
867
        dut_start <= '1';
868
        wait until pclk'event and pclk = '1';
869
        dut_start <= '0';
870
        dut_di_ack <= '1';
871
        dut_bytes <= b"00";
872
        dut_di <= x"41414141";
873
        count_words := 0;
874
        words <= count_words;
875
        count_blocks := 0;
876
        blocks <= count_blocks;
877
        loop
878
            wait until dut_di_req = '1';
879
            loop
880
                wait until pclk'event and pclk = '1';
881
                count_words := count_words + 1;
882
                words <= count_words;
883
                exit when words = 15;
884
            end loop;
885
            count_words := 0;
886
            words <= count_words;
887
            count_blocks := count_blocks + 1;
888
            blocks <= count_blocks;
889
            exit when blocks = 14;
890
        end loop;
891
        count_words := 0;
892
        words <= count_words;
893
        wait until dut_di_req = '1';
894
        loop
895
            wait until pclk'event and pclk = '1';
896
            count_words := count_words + 1;
897
            words <= count_words;
898
            exit when words = 8;
899
        end loop;
900
        dut_end <= '1';
901
        wait until pclk'event and pclk = '1';
902
        dut_end <= '0';
903
        if dut_error /= '1' and dut_do_valid /= '1' then
904
            while dut_error /= '1' and dut_do_valid /= '1' loop
905
                wait until pclk'event and pclk = '1';
906
            end loop;
907
        end if;
908
        wait for CLK_PERIOD*20;
909
 
910
        -- expected: c2e68682 3489ced2 017f6059 b8b23931 8b6364f6 dcd835d0 a519105a 1eadd6e4
911
        assert dut_H0 = x"c2e68682" report "test #10 failed on H0" severity error;
912
        assert dut_H1 = x"3489ced2" report "test #10 failed on H1" severity error;
913
        assert dut_H2 = x"017f6059" report "test #10 failed on H2" severity error;
914
        assert dut_H3 = x"b8b23931" report "test #10 failed on H3" severity error;
915
        assert dut_H4 = x"8b6364f6" report "test #10 failed on H4" severity error;
916
        assert dut_H5 = x"dcd835d0" report "test #10 failed on H5" severity error;
917
        assert dut_H6 = x"a519105a" report "test #10 failed on H6" severity error;
918
        assert dut_H7 = x"1eadd6e4" report "test #10 failed on H7" severity error;
919
 
920
        -------------------------------------------------------------------------------------------
921
        -- test vector 11
922
        -- src: NIST-ADDITIONAL-SHA256
923
        -- #9) 1005 bytes of 0x55 'U'
924
        -- msg := 1000 x"55"
925
        -- hash:= f4d62dde c0f3dd90 ea1380fa 16a5ff8d c4c54b21 740650f2 4afc4120 903552b0
926
        test_case <= 11;
927
        dut_ce <= '0';
928
        dut_di <= (others => '0');
929
        dut_bytes <= b"00";
930
        dut_start <= '0';
931
        dut_end <= '0';
932
        dut_di_ack <= '0';
933
        wait until pclk'event and pclk = '1';
934
        dut_ce <= '1';
935
        dut_start <= '1';
936
        wait until pclk'event and pclk = '1';
937
        dut_start <= '0';
938
        dut_di_ack <= '1';
939
        dut_bytes <= b"00";
940
        dut_di <= x"55555555";
941
        count_words := 0;
942
        words <= count_words;
943
        count_blocks := 0;
944
        blocks <= count_blocks;
945
        loop
946
            wait until dut_di_req = '1';
947
            loop
948
                wait until pclk'event and pclk = '1';
949
                count_words := count_words + 1;
950
                words <= count_words;
951
                exit when words = 15;
952
            end loop;
953
            count_words := 0;
954
            words <= count_words;
955
            count_blocks := count_blocks + 1;
956
            blocks <= count_blocks;
957
            exit when blocks = 14;
958
        end loop;
959
        count_words := 0;
960
        words <= count_words;
961
        wait until dut_di_req = '1';
962
        loop
963
            wait until pclk'event and pclk = '1';
964
            count_words := count_words + 1;
965
            words <= count_words;
966
            exit when words = 9;
967
        end loop;
968
        wait until pclk'event and pclk = '1';
969
        dut_bytes <= b"01";
970
        dut_end <= '1';
971
        wait until pclk'event and pclk = '1';
972
        dut_end <= '0';
973
        if dut_error /= '1' and dut_do_valid /= '1' then
974
            while dut_error /= '1' and dut_do_valid /= '1' loop
975
                wait until pclk'event and pclk = '1';
976
            end loop;
977
        end if;
978
        wait for CLK_PERIOD*20;
979
 
980
        -- expected: f4d62dde c0f3dd90 ea1380fa 16a5ff8d c4c54b21 740650f2 4afc4120 903552b0
981
        assert dut_H0 = x"f4d62dde" report "test #11 failed on H0" severity error;
982
        assert dut_H1 = x"c0f3dd90" report "test #11 failed on H1" severity error;
983
        assert dut_H2 = x"ea1380fa" report "test #11 failed on H2" severity error;
984
        assert dut_H3 = x"16a5ff8d" report "test #11 failed on H3" severity error;
985
        assert dut_H4 = x"c4c54b21" report "test #11 failed on H4" severity error;
986
        assert dut_H5 = x"740650f2" report "test #11 failed on H5" severity error;
987
        assert dut_H6 = x"4afc4120" report "test #11 failed on H6" severity error;
988
        assert dut_H7 = x"903552b0" report "test #11 failed on H7" severity error;
989
 
990
        -------------------------------------------------------------------------------------------
991
        -- test vector 12
992
        -- src: NIST-ADDITIONAL-SHA256
993
        -- #10) 1000000 bytes of zeros
994
        -- msg := 1000000 x"00"
995
        -- hash:= d29751f2 649b32ff 572b5e0a 9f541ea6 60a50f94 ff0beedf b0b692b9 24cc8025
996
        test_case <= 12;
997
        dut_ce <= '0';
998
        dut_di <= (others => '0');
999
        dut_bytes <= b"00";
1000
        dut_start <= '0';
1001
        dut_end <= '0';
1002
        dut_di_ack <= '0';
1003
        wait until pclk'event and pclk = '1';
1004
        dut_ce <= '1';
1005
        dut_start <= '1';
1006
        wait until pclk'event and pclk = '1';
1007
        dut_start <= '0';
1008
        dut_di_ack <= '1';
1009
        dut_bytes <= b"00";
1010
        dut_di <= x"00000000";
1011
        count_words := 0;
1012
        words <= count_words;
1013
        count_blocks := 0;
1014
        blocks <= count_blocks;
1015
        loop
1016
            wait until dut_di_req = '1';
1017
            loop
1018
                wait until pclk'event and pclk = '1';
1019
                count_words := count_words + 1;
1020
                words <= count_words;
1021
                exit when words = 15;
1022
            end loop;
1023
            count_words := 0;
1024
            words <= count_words;
1025
            count_blocks := count_blocks + 1;
1026
            blocks <= count_blocks;
1027
            exit when blocks = 15623;
1028
        end loop;
1029
        count_words := 0;
1030
        words <= count_words;
1031
        wait until dut_di_req = '1';
1032
        loop
1033
            wait until pclk'event and pclk = '1';
1034
            count_words := count_words + 1;
1035
            words <= count_words;
1036
            exit when words = 14;
1037
        end loop;
1038
        dut_end <= '1';
1039
        wait until pclk'event and pclk = '1';
1040
        dut_end <= '0';
1041
        if dut_error /= '1' and dut_do_valid /= '1' then
1042
            while dut_error /= '1' and dut_do_valid /= '1' loop
1043
                wait until pclk'event and pclk = '1';
1044
            end loop;
1045
        end if;
1046
        wait for CLK_PERIOD*20;
1047
 
1048
        -- expected: d29751f2 649b32ff 572b5e0a 9f541ea6 60a50f94 ff0beedf b0b692b9 24cc8025
1049
        assert dut_H0 = x"d29751f2" report "test #12 failed on H0" severity error;
1050
        assert dut_H1 = x"649b32ff" report "test #12 failed on H1" severity error;
1051
        assert dut_H2 = x"572b5e0a" report "test #12 failed on H2" severity error;
1052
        assert dut_H3 = x"9f541ea6" report "test #12 failed on H3" severity error;
1053
        assert dut_H4 = x"60a50f94" report "test #12 failed on H4" severity error;
1054
        assert dut_H5 = x"ff0beedf" report "test #12 failed on H5" severity error;
1055
        assert dut_H6 = x"b0b692b9" report "test #12 failed on H6" severity error;
1056
        assert dut_H7 = x"24cc8025" report "test #12 failed on H7" severity error;
1057
 
1058
 
1059
        assert false report "End Simulation" severity failure; -- stop simulation
1060
    end process tb1;
1061
    --  End Test Bench 
1062
END;

powered by: WebSVN 2.1.0

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