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 10

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

powered by: WebSVN 2.1.0

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