OpenCores
URL https://opencores.org/ocsvn/rc4-prbs/rc4-prbs/trunk

Subversion Repositories rc4-prbs

[/] [rc4-prbs/] [trunk/] [rc4_tb.v] - Blame information for rev 9

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

Line No. Rev Author Line
1 3 ortegaalfr
/*
2
        RC4 PRGA Testbench
3
        Copyright 2012 - Alfredo Ortega
4
        aortega@alu.itba.edu.ar
5 2 ortegaalfr
 
6 3 ortegaalfr
 This library is free software: you can redistribute it and/or
7
 modify it under the terms of the GNU Lesser General Public
8
 License as published by the Free Software Foundation, either
9
 version 3 of the License, or (at your option) any later version.
10
 
11
 This library is distributed in the hope that it will be useful,
12
 but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 Lesser General Public License for more details.
15
 
16
 You should have received a copy of the GNU Lesser General Public
17
 License along with this library.  If not, see <http://www.gnu.org/licenses/>.
18
*/
19
 
20 2 ortegaalfr
`define RC4
21
 
22
 
23
`ifndef TEST_CYCLES
24
`define TEST_CYCLES 2000
25
`endif
26
 
27 3 ortegaalfr
`include "rc4.inc"
28 2 ortegaalfr
 
29
module rc4_tb;
30
 
31 3 ortegaalfr
reg [7:0] password[0:`KEY_SIZE-1];
32 2 ortegaalfr
 
33
parameter tck = 10, program_cycles = `TEST_CYCLES;
34
 
35
 
36
reg clk, rst; // clock, reset
37 3 ortegaalfr
wire output_ready; // output ready (valid)
38
wire [7:0] K; // output
39
reg [7:0] password_input; //input
40 2 ortegaalfr
 
41
/* Clocking device */
42
always #(tck/2)
43
        clk = ~clk;
44
 
45 5 ortegaalfr
 
46
/* Password loader and info display*/
47 3 ortegaalfr
integer clkcount;
48 2 ortegaalfr
always @ (posedge clk)
49
        begin
50 3 ortegaalfr
        clkcount<=clkcount+1;
51
        if (clkcount < `KEY_SIZE)
52 2 ortegaalfr
                begin
53 3 ortegaalfr
                password_input<=password[clkcount];
54
                $display ("--- clk %d --- key[%x] = %08X",clkcount,clkcount,password[clkcount]);
55 2 ortegaalfr
                end
56 7 ortegaalfr
        else $display ("--- clk %d --- K %08X --- valid: ",clkcount,K,output_ready);
57 2 ortegaalfr
        end
58
 
59
 
60 3 ortegaalfr
/* rc4 module implementation */
61
rc4 rc4mod(
62
        .clk(clk),
63
        .rst(rst),
64
        .password_input(password_input),
65
        .output_ready(output_ready),
66
        .K(K)
67
);
68 2 ortegaalfr
 
69 3 ortegaalfr
 
70 2 ortegaalfr
/* Simulation */
71
integer q;
72
initial begin
73 9 ortegaalfr
        password[0] = 8'h53; // 'S'
74
        password[1] = 8'h65; // 'e'
75
        password[2] = 8'h63; // 'c'
76
        password[3] = 8'h72; // 'r'
77
        password[4] = 8'h65; // 'e'
78
        password[5] = 8'h74; // 't'
79
        // Test vector: "Secret" --> "04 d4 6b 05 3c a8 7b 59"
80 2 ortegaalfr
        $display ("Start...");
81 3 ortegaalfr
        clk = 0;
82
        rst = 1;
83
        clkcount =0;
84
        password_input=password[clkcount];
85 2 ortegaalfr
        #(1*tck)
86 3 ortegaalfr
        rst = 0;
87 2 ortegaalfr
        #(program_cycles*tck+100)
88
        $display ("Finish.");
89
        $finish;
90
end
91
 
92
 
93
endmodule

powered by: WebSVN 2.1.0

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