diff options
Diffstat (limited to 'src/tb/tb_csprng.v')
-rw-r--r-- | src/tb/tb_csprng.v | 105 |
1 files changed, 90 insertions, 15 deletions
diff --git a/src/tb/tb_csprng.v b/src/tb/tb_csprng.v index 0404b56..bd84489 100644 --- a/src/tb/tb_csprng.v +++ b/src/tb/tb_csprng.v @@ -50,7 +50,7 @@ module tb_csprng(); //---------------------------------------------------------------- // Internal constant and parameter definitions. //---------------------------------------------------------------- - parameter DEBUG = 1; + parameter DEBUG = 0; parameter CLK_HALF_PERIOD = 1; parameter CLK_PERIOD = 2 * CLK_HALF_PERIOD; @@ -68,6 +68,7 @@ module tb_csprng(); localparam ADDR_STAT_BLOCKS_LOW = 8'h14; localparam ADDR_STAT_BLOCKS_HIGH = 8'h15; + localparam ADDR_STAT_RESEEDS = 8'h16; localparam ADDR_RND_DATA = 8'h20; @@ -109,6 +110,7 @@ module tb_csprng(); reg tb_debug_update; reg [31 : 0] read_data; + reg [7 : 0] pbyte; //---------------------------------------------------------------- @@ -127,10 +129,9 @@ module tb_csprng(); .discard(tb_discard), .test_mode(tb_test_mode), - - .more_seed(tb_more_seed), .security_error(tb_security_error), + .more_seed(tb_more_seed), .seed_data(tb_seed_data), .seed_syn(tb_seed_syn), .seed_ack(tb_seed_ack), @@ -210,11 +211,6 @@ module tb_csprng(); dut.cipher_inst.ready, dut.cipher_inst.data_out_valid); $display("cipher data out: 0x%064x", dut.cipher_inst.data_out); $display(""); - - $display("Outputs:"); - $display("rnd_syn = 0x%01x, rnd_ack = 0x%01x, rnd_data = 0x%08x", - dut.rnd_syn, dut.rnd_ack, tb_read_data); - $display(""); end endtask // dump_dut_state @@ -237,6 +233,7 @@ module tb_csprng(); tb_write_data = word; tb_cs = 1; tb_we = 1; + #(2 * CLK_PERIOD); tb_cs = 0; tb_we = 0; @@ -330,14 +327,68 @@ module tb_csprng(); tb_test_mode = 0; tb_seed_syn = 0; - tb_seed_data = {16{32'h00000000}}; + tb_seed_data = {8{64'h0000000000000000}}; tb_rnd_ack = 0; tb_debug_update = 0; + + pbyte = 8'h00; end endtask // init_sim //---------------------------------------------------------------- + // seed_generator + // + // When a seed_syn is observed this process will provide a new + // seed to the DUT, assert SYN, wait for ACK and then update + // the seed pattern state. + //---------------------------------------------------------------- + always @ (posedge tb_more_seed) + begin : seed_generator + #(CLK_PERIOD); + tb_seed_data = {64{pbyte}}; + tb_seed_syn = 1'b1; + + while (!tb_seed_ack) + #(CLK_PERIOD); + + tb_seed_syn = 1'b0; + pbyte = pbyte + 8'h01; + end + + + //---------------------------------------------------------------- + // read_rng_data() + // + // Support task that reads a given number of data words + // from the DUT via the API. + //---------------------------------------------------------------- + task read_rng_data(input [31 : 0] num_words); + reg [31 : 0] i; + begin + i = 32'h00000000; + + $display("*** Trying to read 0x%08x RNG data words", num_words); + while (i < num_words) + begin + tb_cs = 1'b1; + tb_we = 1'b0; + tb_address = ADDR_RND_DATA; + i = i + 1; + + #CLK_PERIOD; + + if (DEBUG) + $display("*** RNG data word 0x%08x: 0x%08x", i, tb_read_data); + end + + tb_cs = 1'b0; + $display("*** Reading of RNG data words completed."); + end + endtask // read_rng_data + + + //---------------------------------------------------------------- // tc1_init_csprng() // // TC1: Test that the DUT automatically starts initialize when @@ -353,11 +404,8 @@ module tb_csprng(); tb_seed_data = {8{64'haaaaaaaa55555555}}; tb_seed_syn = 1'b1; - tb_cs = 1'b1; - tb_we = 1'b0; - tb_address = ADDR_RND_DATA; - - #(200 * CLK_PERIOD); + // Start pulling data. + read_rng_data(32'h100); $display("*** TC1: Test automatic init of csprng done."); end @@ -365,6 +413,32 @@ module tb_csprng(); //---------------------------------------------------------------- + // tc2_reseed_csprng() + // + // TC2: Test that the CSPRNG is reseeded as expected. + // We set the max block size to a small value and pull data. + //---------------------------------------------------------------- + task tc2_reseed_csprng(); + begin + tc_ctr = tc_ctr + 1; + + $display("*** TC2: Test reseed of CSPRNG started."); + + tb_seed_data = {8{64'h0102030405060708}}; + tb_seed_syn = 1'b1; + + // Set the max number of blocks to a low value + write_word(ADDR_NUM_BLOCKS_HIGH, 32'h00000000); + write_word(ADDR_NUM_BLOCKS_LOW, 32'h00000007); + + read_rng_data(32'h10000); + + $display("*** TC2 done.."); + end + endtask // tc2_reseed_csprng + + + //---------------------------------------------------------------- // csprng_test // // The main test functionality. @@ -381,7 +455,8 @@ module tb_csprng(); reset_dut(); dump_dut_state(); - tc1_init_csprng(); +// tc1_init_csprng(); + tc2_reseed_csprng(); display_test_results(); |