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 17

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 14 ortegaalfr
        password[0] = 8'h01; // Testvectors http://tools.ietf.org/html/draft-josefsson-rc4-test-vectors-02#page-4
74
        password[1] = 8'h02; //
75
        password[2] = 8'h03; // 
76
        password[3] = 8'h04; // 
77
        password[4] = 8'h05; // 
78
        password[5] = 8'h06; // 
79
        password[6] = 8'h07; // 
80
 
81
//       Key length: 56 bits.
82
// key: 0x01020304050607
83
// DEC    0 HEX    0:  29 3f 02 d4  7f 37 c9 b6   33 f2 af 52  85 fe b4 6b
84
 
85 2 ortegaalfr
        $display ("Start...");
86 3 ortegaalfr
        clk = 0;
87
        rst = 1;
88
        clkcount =0;
89
        password_input=password[clkcount];
90 2 ortegaalfr
        #(1*tck)
91 3 ortegaalfr
        rst = 0;
92 14 ortegaalfr
        #(program_cycles*tck+100000)
93 2 ortegaalfr
        $display ("Finish.");
94
        $finish;
95
end
96
 
97
 
98
endmodule

powered by: WebSVN 2.1.0

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