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

Subversion Repositories sha3

[/] [sha3/] [trunk/] [high_throughput_core/] [testbench/] [test_keccak.v] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 homer.hsin
/*
2
 * Copyright 2013, Homer Hsing <homer.hsing@gmail.com>
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 * http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
 
17
`timescale 1ns / 1ps
18
`define P 20
19
 
20
module test_keccak;
21
 
22
    // Inputs
23
    reg clk;
24
    reg reset;
25
    reg [63:0] in;
26
    reg in_ready;
27
    reg is_last;
28
    reg [2:0] byte_num;
29
 
30
    // Outputs
31
    wire buffer_full;
32
    wire [511:0] out;
33
    wire out_ready;
34
 
35
    // Var
36
    integer i;
37
 
38
    // Instantiate the Unit Under Test (UUT)
39
    keccak uut (
40
        .clk(clk),
41
        .reset(reset),
42
        .in(in),
43
        .in_ready(in_ready),
44
        .is_last(is_last),
45
        .byte_num(byte_num),
46
        .buffer_full(buffer_full),
47
        .out(out),
48
        .out_ready(out_ready)
49
    );
50
 
51
    initial begin
52
        // Initialize Inputs
53
        clk = 0;
54
        reset = 0;
55
        in = 0;
56
        in_ready = 0;
57
        is_last = 0;
58
        byte_num = 0;
59
 
60
        // Wait 100 ns for global reset to finish
61
        #100;
62
 
63
        // Add stimulus here
64
        @ (negedge clk);
65
 
66
        // SHA3-512("The quick brown fox jumps over the lazy dog")
67
        reset = 1; #(`P); reset = 0;
68
        in_ready = 1; is_last = 0;
69
        in = "The quic"; #(`P);
70
        in = "k brown "; #(`P);
71
        in = "fox jump"; #(`P);
72
        in = "s over t"; #(`P);
73
        in = "he lazy "; #(`P);
74
        in = "dog     "; byte_num = 3; is_last = 1; #(`P); /* !!! not in = "dog" */
75
        in_ready = 0; is_last = 0;
76
        while (out_ready !== 1)
77
            #(`P);
78
        check(512'hd135bb84d0439dbac432247ee573a23ea7d3c9deb2a968eb31d47c4fb45f1ef4422d6c531b5b9bd6f449ebcc449ea94d0a8f05f62130fda612da53c79659f609);
79
 
80
        // SHA3-512("The quick brown fox jumps over the lazy dog.")
81
        reset = 1; #(`P); reset = 0;
82
        in_ready = 1; is_last = 0;
83
        in = "The quic"; #(`P);
84
        in = "k brown "; #(`P);
85
        in = "fox jump"; #(`P);
86
        in = "s over t"; #(`P);
87
        in = "he lazy "; #(`P);
88
        in = "dog.    "; byte_num = 4; is_last = 1; #(`P); /* !!! not in = "dog." */
89
        in_ready = 0; is_last = 0;
90
        while (out_ready !== 1)
91
            #(`P);
92
        check(512'hab7192d2b11f51c7dd744e7b3441febf397ca07bf812cceae122ca4ded6387889064f8db9230f173f6d1ab6e24b6e50f065b039f799f5592360a6558eb52d760);
93
 
94
        // hash an string "\xA1\xA2\xA3\xA4\xA5", len == 5
95
        reset = 1; #(`P); reset = 0;
96
        #(7*`P); // wait some cycles
97
        in = 64'hA1A2A3A4A5000000;
98
        byte_num = 5;
99
        in_ready = 1;
100
        is_last = 1;
101
        #(`P);
102
        in = 64'h12345678; // next input
103
        in_ready = 1;
104
        is_last = 1;
105
        #(`P/2);
106
        if (buffer_full === 1) error; // should be 0
107
        #(`P/2);
108
        in_ready = 0;
109
        is_last = 0;
110
 
111
        while (out_ready !== 1)
112
            #(`P);
113
        check(512'h12f4a85b68b091e8836219e79dfff7eb9594a42f5566515423b2aa4c67c454de83a62989e44b5303022bfe8c1a9976781b747a596cdab0458e20d8750df6ddfb);
114
        for(i=0; i<5; i=i+1)
115
          begin
116
            #(`P);
117
            if (buffer_full !== 0) error; // should keep 0
118
          end
119
 
120
        // hash an empty string, should not eat next input
121
        reset = 1; #(`P); reset = 0;
122
        #(7*`P); // wait some cycles
123
        in = 64'h12345678; // should not be eat
124
        byte_num = 0;
125
        in_ready = 1;
126
        is_last = 1;
127
        #(`P);
128
        in = 64'hddddd; // should not be eat
129
        in_ready = 1; // next input
130
        is_last = 1;
131
        #(`P);
132
        in_ready = 0;
133
        is_last = 0;
134
 
135
        while (out_ready !== 1)
136
            #(`P);
137
        check(512'h0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e);
138
        for(i=0; i<5; i=i+1)
139
          begin
140
            #(`P);
141
            if (buffer_full !== 0) error; // should keep 0
142
          end
143
 
144
        // hash an (576-8) bit string
145
        reset = 1; #(`P); reset = 0;
146
        #(4*`P); // wait some cycles
147
        in_ready = 1;
148
        byte_num = 7; /* should have no effect */
149
        is_last = 0;
150
        for (i=0; i<8; i=i+1)
151
          begin
152
            in = 64'hEFCDAB9078563412;
153
            #(`P);
154
          end
155
        is_last = 1;
156
        #(`P);
157
        in_ready = 0;
158
        is_last = 0;
159
        while (out_ready !== 1)
160
            #(`P);
161
        check(512'hf7f6b44069dba8900b6711ffcbe40523d4bb718cc8ed7f0a0bd28a1b18ee9374359f0ca0c9c1e96fcfca29ee2f282b46d5045eff01f7a7549eaa6b652cbf6270);
162
 
163
        // pad an (576-64) bit string
164
        reset = 1; #(`P); reset = 0;
165
        // don't wait any cycle
166
        in_ready = 1;
167
        byte_num = 7; /* should have no effect */
168
        is_last = 0;
169
        for (i=0; i<8; i=i+1)
170
          begin
171
            in = 64'hEFCDAB9078563412;
172
            #(`P);
173
          end
174
        is_last = 1;
175
        byte_num = 0;
176
        #(`P);
177
        in_ready = 0;
178
        is_last = 0;
179
        in = 0;
180
        while (out_ready !== 1)
181
            #(`P);
182
        check(512'hccd91653872c106f6eea1b8b68a4c2901c8d9bed9c180201f8a6144e7e6e6c251afcb6f6da44780b2d9aabff254036664719425469671f7e21fb67e5280a27ed);
183
 
184
        // pad an (576*2-16) bit string
185
        reset = 1; #(`P); reset = 0;
186
        in_ready = 1;
187
        byte_num = 1; /* should have no effect */
188
        is_last = 0;
189
        for (i=0; i<9; i=i+1)
190
          begin
191
            in = 64'hEFCDAB9078563412; #(`P);
192
          end
193
        #(`P/2);
194
        if (buffer_full !== 1) error; // should not eat
195
        #(`P/2);
196
        in = 64'h999; // should not eat this
197
        in_ready = 0;
198
        #(`P/2);
199
        if (buffer_full !== 0) error; // should not eat, but buffer should not be full
200
        #(`P/2);
201
        #(`P);
202
        // feed next (576-16) bit
203
        in_ready = 1;
204
        for (i=0; i<8; i=i+1)
205
          begin
206
            in = 64'hEFCDAB9078563412; #(`P);
207
          end
208
        byte_num = 6;
209
        is_last = 1;
210
        in = 64'hEFCDAB9078563412;
211
        #(`P);
212
        is_last = 0;
213
        in_ready = 0;
214
        while (out_ready !== 1)
215
            #(`P);
216
        check(512'h0f385323604e279251e80f928cfd9ce9492ba5df775063ea106eebe2a2c7785a3e33b4397fca66e90f67470334c66ea12016cb1f06170b9b033f158a7c01933e);
217
 
218
        $display("Good!");
219
        $finish;
220
    end
221
 
222
    always #(`P/2) clk = ~ clk;
223
 
224
    task error;
225
        begin
226
              $display("E");
227
              $finish;
228
        end
229
    endtask
230
 
231
    task check;
232
        input [511:0] wish;
233
        begin
234
          if (out !== wish)
235
            begin
236
              $display("%h %h", out, wish); error;
237
            end
238
        end
239
    endtask
240
endmodule
241
 
242
`undef P

powered by: WebSVN 2.1.0

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