diff options
Diffstat (limited to 'src/tb')
-rw-r--r-- | src/tb/tb_chacha.v | 258 | ||||
-rw-r--r-- | src/tb/tb_chacha_core.v | 137 |
2 files changed, 200 insertions, 195 deletions
diff --git a/src/tb/tb_chacha.v b/src/tb/tb_chacha.v index ac2d3b0..fab2ad7 100644 --- a/src/tb/tb_chacha.v +++ b/src/tb/tb_chacha.v @@ -36,19 +36,15 @@ // //====================================================================== -//------------------------------------------------------------------ -// Simulator directives. -//------------------------------------------------------------------ -`timescale 1ns/100ps - module tb_chacha(); //---------------------------------------------------------------- // Internal constant and parameter definitions. //---------------------------------------------------------------- - localparam DEBUG = 0; + localparam DEBUG = 1; - localparam CLK_HALF_PERIOD = 2; + localparam CLK_HALF_PERIOD = 1; + localparam CLK_PERIOD = 2 * CLK_HALF_PERIOD; localparam TC1 = 1; localparam TC2 = 2; @@ -111,20 +107,6 @@ module tb_chacha(); localparam ADDR_IV1 = 8'h21; localparam ADDR_DATA_IN0 = 8'h40; - localparam ADDR_DATA_IN1 = 8'h41; - localparam ADDR_DATA_IN2 = 8'h42; - localparam ADDR_DATA_IN3 = 8'h43; - localparam ADDR_DATA_IN4 = 8'h44; - localparam ADDR_DATA_IN5 = 8'h45; - localparam ADDR_DATA_IN6 = 8'h46; - localparam ADDR_DATA_IN7 = 8'h47; - localparam ADDR_DATA_IN8 = 8'h48; - localparam ADDR_DATA_IN9 = 8'h49; - localparam ADDR_DATA_IN10 = 8'h4a; - localparam ADDR_DATA_IN11 = 8'h4b; - localparam ADDR_DATA_IN12 = 8'h4c; - localparam ADDR_DATA_IN13 = 8'h4d; - localparam ADDR_DATA_IN14 = 8'h4e; localparam ADDR_DATA_IN15 = 8'h4f; localparam ADDR_DATA_OUT0 = 8'h80; @@ -170,25 +152,20 @@ module tb_chacha(); reg display_cycle_ctr; reg display_read_write; + reg display_core_state; //---------------------------------------------------------------- // Chacha device under test. //---------------------------------------------------------------- chacha dut( - // Clock and reset. .clk(tb_clk), .reset_n(tb_reset_n), - - // Control. .cs(tb_cs), .we(tb_write_read), - - // Data ports. .address(tb_address), .write_data(tb_data_in), - .read_data(tb_data_out), - .error(tb_error) + .read_data(tb_data_out) ); @@ -218,6 +195,24 @@ module tb_chacha(); $display("cycle = %016x:", cycle_ctr); end + if (display_core_state) + begin + $display("core ctrl: 0x%02x, core_qr_ctr: 0x%02x, core_dr_ctr: 0x%02x, init: 0x%01x, next: 0x%01x, core_ready: 0x%02x", + dut.core.chacha_ctrl_reg, dut.core.qr_ctr_reg, + dut.core.dr_ctr_reg, dut.core.init, + dut.core.next, dut.core.ready_reg); + + $display("state0_reg = 0x%08x, state1_reg = 0x%08x, state2_reg = 0x%08x, state3_reg = 0x%08x", + dut.core.state_reg[00], dut.core.state_reg[01], dut.core.state_reg[02], dut.core.state_reg[03]); + $display("state4_reg = 0x%08x, state5_reg = 0x%08x, state6_reg = 0x%08x, state7_reg = 0x%08x", + dut.core.state_reg[04], dut.core.state_reg[05], dut.core.state_reg[06], dut.core.state_reg[07]); + $display("state8_reg = 0x%08x, state9_reg = 0x%08x, state10_reg = 0x%08x, state11_reg = 0x%08x", + dut.core.state_reg[08], dut.core.state_reg[09], dut.core.state_reg[10], dut.core.state_reg[11]); + $display("state12_reg = 0x%08x, state13_reg = 0x%08x, state14_reg = 0x%08x, state15_reg = 0x%08x", + dut.core.state_reg[12], dut.core.state_reg[13], dut.core.state_reg[14], dut.core.state_reg[15]); + $display(""); + end + if (display_read_write) begin @@ -238,31 +233,39 @@ module tb_chacha(); //---------------------------------------------------------------- - // set_display_prefs() - // - // Set the different monitor displays we want to see during - // simulation. + // reset_dut //---------------------------------------------------------------- - task set_display_prefs( - input cycles, - input read_write); + task reset_dut; begin - display_cycle_ctr = cycles; - display_read_write = read_write; + tb_reset_n = 0; + #(2 * CLK_PERIOD); + tb_reset_n = 1; end - endtask // set_display_prefs + endtask // reset_dut //---------------------------------------------------------------- - // reset_dut + // init_sim() + // + // Set the input to the DUT to defined values. //---------------------------------------------------------------- - task reset_dut(); + task init_sim; begin - tb_reset_n = 0; - #(4 * CLK_HALF_PERIOD); - tb_reset_n = 1; + cycle_ctr = 0; + error_ctr = 0; + tc_ctr = 0; + tb_clk = 0; + tb_reset_n = 0; + tb_cs = 0; + tb_write_read = 0; + tb_address = 8'h0; + tb_data_in = 32'h0; + + display_cycle_ctr = 0; + display_read_write = 0; + display_core_state = 0; end - endtask // reset_dut + endtask // init_sim //---------------------------------------------------------------- @@ -276,11 +279,11 @@ module tb_chacha(); tb_cs = 1; tb_write_read = 0; tb_address = addr; - #(2 * CLK_HALF_PERIOD); + #(CLK_PERIOD); tb_cs = 0; tb_write_read = 0; - tb_address = 8'h00; - tb_data_in = 32'h00000000; + tb_address = 8'h0; + tb_data_in = 32'h0; end endtask // read_reg @@ -296,11 +299,11 @@ module tb_chacha(); tb_write_read = 1; tb_address = addr; tb_data_in = data; - #(2 * CLK_HALF_PERIOD); + #(CLK_PERIOD); tb_cs = 0; tb_write_read = 0; - tb_address = 8'h00; - tb_data_in = 32'h00000000; + tb_address = 8'h0; + tb_data_in = 32'h0; end endtask // write_reg @@ -310,36 +313,49 @@ module tb_chacha(); // // Dump the internal state of the top to std out. //---------------------------------------------------------------- - task dump_top_state(); + task dump_top_state; begin $display(""); $display("Top internal state"); $display("------------------"); $display("init_reg = %01x", dut.init_reg); $display("next_reg = %01x", dut.next_reg); - $display("ready_reg = %01x", dut.ready_reg); $display("keylen_reg = %01x", dut.keylen_reg); $display("rounds_reg = %01x", dut.rounds_reg); $display(""); - $display("key0_reg = %08x, key1_reg = %08x, key2_reg = %08x, key3_reg = %08x", dut.key0_reg, dut.key1_reg, dut.key2_reg, dut.key3_reg); - $display("key4_reg = %08x, key5_reg = %08x, key6_reg = %08x, key7_reg = %08x", dut.key4_reg, dut.key5_reg, dut.key6_reg, dut.key7_reg); + $display("key0_reg = %08x, key1_reg = %08x, key2_reg = %08x, key3_reg = %08x", + dut.key_reg[0], dut.key_reg[1], dut.key_reg[2], dut.key_reg[3]); + $display("key4_reg = %08x, key5_reg = %08x, key6_reg = %08x, key7_reg = %08x", + dut.key_reg[4], dut.key_reg[5], dut.key_reg[6], dut.key_reg[7]); $display(""); - $display("iv0_reg = %08x, iv1_reg = %08x", dut.iv0_reg, dut.iv1_reg); + $display("iv0_reg = %08x, iv1_reg = %08x", dut.iv_reg[0], dut.iv_reg[1]); $display(""); - $display("data_in0_reg = %08x, data_in1_reg = %08x, data_in2_reg = %08x, data_in3_reg = %08x", dut.data_in0_reg, dut.data_in1_reg, dut.data_in2_reg, dut.data_in3_reg); - $display("data_in4_reg = %08x, data_in5_reg = %08x, data_in6_reg = %08x, data_in7_reg = %08x", dut.data_in4_reg, dut.data_in5_reg, dut.data_in6_reg, dut.data_in7_reg); - $display("data_in8_reg = %08x, data_in9_reg = %08x, data_in10_reg = %08x, data_in11_reg = %08x", dut.data_in8_reg, dut.data_in9_reg, dut.data_in10_reg, dut.data_in11_reg); - $display("data_in12_reg = %08x, data_in13_reg = %08x, data_in14_reg = %08x, data_in15_reg = %08x", dut.data_in12_reg, dut.data_in13_reg, dut.data_in14_reg, dut.data_in15_reg); + $display("data_in0_reg = %08x, data_in1_reg = %08x, data_in2_reg = %08x, data_in3_reg = %08x", + dut.data_in_reg[00], dut.data_in_reg[01], dut.data_in_reg[02], dut.data_in_reg[03]); + $display("data_in4_reg = %08x, data_in5_reg = %08x, data_in6_reg = %08x, data_in7_reg = %08x", + dut.data_in_reg[04], dut.data_in_reg[05], dut.data_in_reg[06], dut.data_in_reg[07]); + $display("data_in8_reg = %08x, data_in9_reg = %08x, data_in10_reg = %08x, data_in11_reg = %08x", + dut.data_in_reg[08], dut.data_in_reg[09], dut.data_in_reg[10], dut.data_in_reg[11]); + $display("data_in12_reg = %08x, data_in13_reg = %08x, data_in14_reg = %08x, data_in15_reg = %08x", + dut.data_in_reg[12], dut.data_in_reg[13], dut.data_in_reg[14], dut.data_in_reg[15]); $display(""); - $display("data_out_valid_reg = %01x", dut.data_out_valid_reg); - $display("data_out0_reg = %08x, data_out1_reg = %08x, data_out2_reg = %08x, data_out3_reg = %08x", dut.data_out0_reg, dut.data_out1_reg, dut.data_out2_reg, dut.data_out3_reg); - $display("data_out4_reg = %08x, data_out5_reg = %08x, data_out6_reg = %08x, data_out7_reg = %08x", dut.data_out4_reg, dut.data_out5_reg, dut.data_out6_reg, dut.data_out7_reg); - $display("data_out8_reg = %08x, data_out9_reg = %08x, data_out10_reg = %08x, data_out11_reg = %08x", dut.data_out8_reg, dut.data_out9_reg, dut.data_out10_reg, dut.data_out11_reg); - $display("data_out12_reg = %08x, data_out13_reg = %08x, data_out14_reg = %08x, data_out15_reg = %08x", dut.data_out12_reg, dut.data_out13_reg, dut.data_out14_reg, dut.data_out15_reg); + $display("ready = 0x%01x, data_out_valid = %01x", dut.core_ready, dut.core_data_out_valid); + $display("data_out00 = %08x, data_out01 = %08x, data_out02 = %08x, data_out03 = %08x", + dut.core_data_out[511 : 480], dut.core_data_out[479 : 448], + dut.core_data_out[447 : 416], dut.core_data_out[415 : 384]); + $display("data_out04 = %08x, data_out05 = %08x, data_out06 = %08x, data_out07 = %08x", + dut.core_data_out[383 : 352], dut.core_data_out[351 : 320], + dut.core_data_out[319 : 288], dut.core_data_out[287 : 256]); + $display("data_out08 = %08x, data_out09 = %08x, data_out10 = %08x, data_out11 = %08x", + dut.core_data_out[255 : 224], dut.core_data_out[223 : 192], + dut.core_data_out[191 : 160], dut.core_data_out[159 : 128]); + $display("data_out12 = %08x, data_out13 = %08x, data_out14 = %08x, data_out15 = %08x", + dut.core_data_out[127 : 96], dut.core_data_out[95 : 64], + dut.core_data_out[63 : 32], dut.core_data_out[31 : 0]); $display(""); end endtask // dump_top_state @@ -350,27 +366,23 @@ module tb_chacha(); // // Dump the internal state of the core to std out. //---------------------------------------------------------------- - task dump_core_state(); + task dump_core_state; begin $display(""); $display("Core internal state"); $display("-------------------"); -// $display("Internal data state vector:"); -// $display("0x%064x", dut.core.state_reg); - $display(""); - - $display("Round state X:"); - $display("x0_reg = %08x, x1_reg = %08x", dut.core.x0_reg, dut.core.x1_reg); - $display("x2_reg = %08x, x3_reg = %08x", dut.core.x2_reg, dut.core.x3_reg); - $display("x4_reg = %08x, x5_reg = %08x", dut.core.x4_reg, dut.core.x5_reg); - $display("x6_reg = %08x, x7_reg = %08x", dut.core.x6_reg, dut.core.x7_reg); - $display("x8_reg = %08x, x9_reg = %08x", dut.core.x8_reg, dut.core.x9_reg); - $display("x10_reg = %08x, x11_reg = %08x", dut.core.x10_reg, dut.core.x11_reg); - $display("x12_reg = %08x, x13_reg = %08x", dut.core.x12_reg, dut.core.x13_reg); - $display("x14_reg = %08x, x15_reg = %08x", dut.core.x14_reg, dut.core.x15_reg); + $display("Round state:"); + $display("state0_reg = 0x%08x, state1_reg = 0x%08x, state2_reg = 0x%08x, state3_reg = 0x%08x", + dut.core.state_reg[00], dut.core.state_reg[01], dut.core.state_reg[02], dut.core.state_reg[03]); + $display("state4_reg = 0x%08x, state5_reg = 0x%08x, state6_reg = 0x%08x, state7_reg = 0x%08x", + dut.core.state_reg[04], dut.core.state_reg[05], dut.core.state_reg[06], dut.core.state_reg[07]); + $display("state8_reg = 0x%08x, state9_reg = 0x%08x, state10_reg = 0x%08x, state11_reg = 0x%08x", + dut.core.state_reg[08], dut.core.state_reg[09], dut.core.state_reg[10], dut.core.state_reg[11]); + $display("state12_reg = 0x%08x, state13_reg = 0x%08x, state14_reg = 0x%08x, state15_reg = 0x%08x", + dut.core.state_reg[12], dut.core.state_reg[13], dut.core.state_reg[14], dut.core.state_reg[15]); $display(""); - $display("rounds_reg = %01x", dut.core.rounds_reg); + $display("rounds = %01x", dut.core.rounds); $display("qr_ctr_reg = %01x, dr_ctr_reg = %01x", dut.core.qr_ctr_reg, dut.core.dr_ctr_reg); $display("block0_ctr_reg = %08x, block1_ctr_reg = %08x", dut.core.block0_ctr_reg, dut.core.block1_ctr_reg); @@ -379,7 +391,7 @@ module tb_chacha(); $display("chacha_ctrl_reg = %02x", dut.core.chacha_ctrl_reg); $display(""); - $display("data_in_reg = %064x", dut.core.data_in_reg); + $display("data_in = %064x", dut.core.data_in); $display("data_out_valid_reg = %01x", dut.core.data_out_valid_reg); $display(""); @@ -395,7 +407,7 @@ module tb_chacha(); // // Display the accumulated test results. //---------------------------------------------------------------- - task display_test_result(); + task display_test_result; begin if (error_ctr == 0) begin @@ -410,28 +422,6 @@ module tb_chacha(); //---------------------------------------------------------------- - // init_dut() - // - // Set the input to the DUT to defined values. - //---------------------------------------------------------------- - task init_dut(); - begin - // Set clock, reset and DUT input signals to - // defined values at simulation start. - cycle_ctr = 0; - error_ctr = 0; - tc_ctr = 0; - tb_clk = 0; - tb_reset_n = 0; - tb_cs = 0; - tb_write_read = 0; - tb_address = 8'h00; - tb_data_in = 32'h00000000; - end - endtask // init_dut - - - //---------------------------------------------------------------- // read_write_test() // // Simple test case that tries to read and write to the @@ -439,7 +429,7 @@ module tb_chacha(); // // Note: Currently not self testing. No expected values. //---------------------------------------------------------------- - task read_write_test(); + task read_write_test; begin tc_ctr = tc_ctr + 1; @@ -484,8 +474,8 @@ module tb_chacha(); write_reg(ADDR_KEY7, key[31 : 0]); write_reg(ADDR_IV0, iv[63 : 32]); write_reg(ADDR_IV1, iv[31 : 0]); - write_reg(ADDR_KEYLEN, {{31'b0000000000000000000000000000000}, key_length}); - write_reg(ADDR_ROUNDS, {{27'b000000000000000000000000000}, rounds}); + write_reg(ADDR_KEYLEN, {{31'h0}, key_length}); + write_reg(ADDR_ROUNDS, {{27'h0}, rounds}); end endtask // write_parameters @@ -499,10 +489,10 @@ module tb_chacha(); // Note: It is the callers responsibility to call the function // when the dut is ready to react on the init signal. //---------------------------------------------------------------- - task start_init_block(); + task start_init_block; begin write_reg(ADDR_CTRL, 32'h00000001); - #(4 * CLK_HALF_PERIOD); + #(2 * CLK_PERIOD); write_reg(ADDR_CTRL, 32'h00000000); end endtask // start_init_block @@ -517,17 +507,17 @@ module tb_chacha(); // Note: It is the callers responsibility to call the function // when the dut is ready to react on the next signal. //---------------------------------------------------------------- - task start_next_block(); + task start_next_block; begin write_reg(ADDR_CTRL, 32'h00000002); - #(4 * CLK_HALF_PERIOD); + #(2 * CLK_PERIOD); write_reg(ADDR_CTRL, 32'h00000000); if (DEBUG) begin $display("Debug of next state."); dump_core_state(); - #(4 * CLK_HALF_PERIOD); + #(2 * CLK_PERIOD); dump_core_state(); end end @@ -543,7 +533,7 @@ module tb_chacha(); // when the dut is actively processing and will in fact at some // point set the flag. //---------------------------------------------------------------- - task wait_ready(); + task wait_ready; begin while (!tb_data_out[STATUS_READY_BIT]) begin @@ -559,7 +549,7 @@ module tb_chacha(); // Extracts all 16 data out words and combine them into the // global extracted_data. //---------------------------------------------------------------- - task extract_data(); + task extract_data; begin read_reg(ADDR_DATA_OUT0); extracted_data[511 : 480] = tb_data_out; @@ -598,6 +588,34 @@ module tb_chacha(); //---------------------------------------------------------------- + // check_name_version() + // + // Read the name and version from the DUT. + //---------------------------------------------------------------- + task check_name_version; + reg [31 : 0] name0; + reg [31 : 0] name1; + reg [31 : 0] version; + begin + $display("*** Trying to read name and version from core."); + read_reg(ADDR_NAME0); + name0 = tb_data_out; + read_reg(ADDR_NAME1); + name1 = tb_data_out; + read_reg(ADDR_VERSION); + version = tb_data_out; + + $display("DUT name: %c%c%c%c%c%c%c%c", + name0[31 : 24], name0[23 : 16], name0[15 : 8], name0[7 : 0], + name1[31 : 24], name1[23 : 16], name1[15 : 8], name1[7 : 0]); + $display("DUT version: %c%c%c%c", + version[31 : 24], version[23 : 16], version[15 : 8], version[7 : 0]); + $display(""); + end + endtask // check_name_version + + + //---------------------------------------------------------------- // run_two_blocks_test_vector() // // Runs a test case with two blocks based on the given @@ -616,7 +634,6 @@ module tb_chacha(); $display("***TC%2d-%2d started", major, minor); $display("***-----------------"); write_parameters(key, key_length, iv, rounds); - start_init_block(); wait_ready(); extract_data(); @@ -690,7 +707,10 @@ module tb_chacha(); write_parameters(key, key_length, iv, rounds); start_init_block(); + $display("*** Started."); wait_ready(); + $display("*** Ready seen."); + dump_top_state(); extract_data(); if (extracted_data != expected) @@ -720,18 +740,20 @@ module tb_chacha(); initial begin : chacha_test $display(" -- Testbench for chacha started --"); - init_dut(); - set_display_prefs(0, 0); + init_sim(); reset_dut(); $display("State at init after reset:"); dump_top_state(); + // Check name and version. + check_name_version(); + $display("TC1-1: All zero inputs. 128 bit key, 8 rounds."); run_test_vector(TC1, ONE, - 256'h0000000000000000000000000000000000000000000000000000000000000000, + 256'h0, KEY_128_BITS, - 64'h0000000000000000, + 64'h0, EIGHT_ROUNDS, 512'he28a5fa4a67f8c5defed3e6fb7303486aa8427d31419a729572d777953491120b64ab8e72b8deb85cd6aea7cb6089a101824beeb08814a428aab1fa2c816081b); diff --git a/src/tb/tb_chacha_core.v b/src/tb/tb_chacha_core.v index a1ddfdc..a36899f 100644 --- a/src/tb/tb_chacha_core.v +++ b/src/tb/tb_chacha_core.v @@ -36,17 +36,13 @@ // //====================================================================== -//------------------------------------------------------------------ -// Simulator directives. -//------------------------------------------------------------------ -`timescale 1ns/100ps - module tb_chacha_core(); //---------------------------------------------------------------- // Internal constant and parameter definitions. //---------------------------------------------------------------- parameter CLK_HALF_PERIOD = 2; + parameter CLK_PERIOD = 2 * CLK_HALF_PERIOD; parameter TC1 = 1; parameter TC2 = 2; @@ -78,7 +74,7 @@ module tb_chacha_core(); parameter DISABLE = 0; parameter ENABLE = 1; - parameter DEFAULT_CTR_INIT = 64'h0000000000000000; + localparam DEFAULT_CTR_INIT = 64'h0; //---------------------------------------------------------------- @@ -105,7 +101,6 @@ module tb_chacha_core(); reg display_ctrl_and_ctrs; reg display_qround; reg display_state; - reg display_x_state; //---------------------------------------------------------------- @@ -180,31 +175,24 @@ module tb_chacha_core(); // Display the internal state register. if (display_state) begin -// $display("Internal state:"); -// $display("0x%064x", dut.state_reg); -// $display(""); - end - - // Display the round processing state register X. - if (display_x_state) - begin - $display("Round state X:"); - $display("x0_reg = 0x%08x, x0_new = 0x%08x, x0_we = 0x%01x", dut.x0_reg, dut.x0_new, dut.x0_we); - $display("x1_reg = 0x%08x, x1_new = 0x%08x, x1_we = 0x%01x", dut.x1_reg, dut.x1_new, dut.x1_we); - $display("x2_reg = 0x%08x, x2_new = 0x%08x, x2_we = 0x%01x", dut.x2_reg, dut.x2_new, dut.x2_we); - $display("x3_reg = 0x%08x, x3_new = 0x%08x, x3_we = 0x%01x", dut.x3_reg, dut.x3_new, dut.x3_we); - $display("x4_reg = 0x%08x, x4_new = 0x%08x, x4_we = 0x%01x", dut.x4_reg, dut.x4_new, dut.x4_we); - $display("x5_reg = 0x%08x, x5_new = 0x%08x, x5_we = 0x%01x", dut.x5_reg, dut.x5_new, dut.x5_we); - $display("x6_reg = 0x%08x, x6_new = 0x%08x, x6_we = 0x%01x", dut.x6_reg, dut.x6_new, dut.x6_we); - $display("x7_reg = 0x%08x, x7_new = 0x%08x, x7_we = 0x%01x", dut.x7_reg, dut.x7_new, dut.x7_we); - $display("x8_reg = 0x%08x, x8_new = 0x%08x, x8_we = 0x%01x", dut.x8_reg, dut.x8_new, dut.x8_we); - $display("x9_reg = 0x%08x, x9_new = 0x%08x, x9_we = 0x%01x", dut.x9_reg, dut.x9_new, dut.x9_we); - $display("x10_reg = 0x%08x, x10_new = 0x%08x, x10_we = 0x%01x", dut.x10_reg, dut.x10_new, dut.x10_we); - $display("x11_reg = 0x%08x, x11_new = 0x%08x, x11_we = 0x%01x", dut.x11_reg, dut.x11_new, dut.x11_we); - $display("x12_reg = 0x%08x, x12_new = 0x%08x, x12_we = 0x%01x", dut.x12_reg, dut.x12_new, dut.x12_we); - $display("x13_reg = 0x%08x, x13_new = 0x%08x, x13_we = 0x%01x", dut.x13_reg, dut.x13_new, dut.x13_we); - $display("x14_reg = 0x%08x, x14_new = 0x%08x, x14_we = 0x%01x", dut.x14_reg, dut.x14_new, dut.x14_we); - $display("x15_reg = 0x%08x, x15_new = 0x%08x, x15_we = 0x%01x", dut.x15_reg, dut.x15_new, dut.x15_we); + $display("Round state:"); + $display("state0_reg = 0x%08x, state0_new = 0x%08x", dut.state_reg[00], dut.state_new[00]); + $display("state1_reg = 0x%08x, state1_new = 0x%08x", dut.state_reg[01], dut.state_new[01]); + $display("state2_reg = 0x%08x, state2_new = 0x%08x", dut.state_reg[02], dut.state_new[02]); + $display("state3_reg = 0x%08x, state3_new = 0x%08x", dut.state_reg[03], dut.state_new[03]); + $display("state4_reg = 0x%08x, state4_new = 0x%08x", dut.state_reg[04], dut.state_new[04]); + $display("state5_reg = 0x%08x, state5_new = 0x%08x", dut.state_reg[05], dut.state_new[05]); + $display("state6_reg = 0x%08x, state6_new = 0x%08x", dut.state_reg[06], dut.state_new[06]); + $display("state7_reg = 0x%08x, state7_new = 0x%08x", dut.state_reg[07], dut.state_new[07]); + $display("state8_reg = 0x%08x, state8_new = 0x%08x", dut.state_reg[08], dut.state_new[08]); + $display("state9_reg = 0x%08x, state9_new = 0x%08x", dut.state_reg[09], dut.state_new[09]); + $display("state10_reg = 0x%08x, state10_new = 0x%08x", dut.state_reg[10], dut.state_new[10]); + $display("state11_reg = 0x%08x, state11_new = 0x%08x", dut.state_reg[11], dut.state_new[11]); + $display("state12_reg = 0x%08x, state12_new = 0x%08x", dut.state_reg[12], dut.state_new[12]); + $display("state13_reg = 0x%08x, state13_new = 0x%08x", dut.state_reg[13], dut.state_new[13]); + $display("state14_reg = 0x%08x, state14_new = 0x%08x", dut.state_reg[14], dut.state_new[14]); + $display("state15_reg = 0x%08x, state15_new = 0x%08x", dut.state_reg[15], dut.state_new[15]); + $display("state_we = 0x%01x", dut.state_we); $display(""); end @@ -215,7 +203,6 @@ module tb_chacha_core(); $display("qr0_a_prim = %08x, qr0_b_prim = %08x, qr0_c_prim = %08x, qr0_d_prim = %08x", dut.qr0_a_prim, dut.qr0_b_prim, dut.qr0_c_prim, dut.qr0_d_prim); $display(""); end - end // dut_monitor @@ -223,26 +210,23 @@ module tb_chacha_core(); // dump_state() // Dump the internal CHACHA state to std out. //---------------------------------------------------------------- - task dump_state(); + task dump_state; begin $display(""); $display("Internal state:"); $display("---------------"); -// $display("0x%064x", dut.state_reg); -// $display(""); - - $display("Round state X::"); - $display("x0_reg = %08x, x1_reg = %08x", dut.x0_reg, dut.x1_reg); - $display("x2_reg = %08x, x3_reg = %08x", dut.x2_reg, dut.x3_reg); - $display("x4_reg = %08x, x5_reg = %08x", dut.x4_reg, dut.x5_reg); - $display("x6_reg = %08x, x7_reg = %08x", dut.x6_reg, dut.x7_reg); - $display("x8_reg = %08x, x9_reg = %08x", dut.x8_reg, dut.x9_reg); - $display("x10_reg = %08x, x11_reg = %08x", dut.x10_reg, dut.x11_reg); - $display("x12_reg = %08x, x13_reg = %08x", dut.x12_reg, dut.x13_reg); - $display("x14_reg = %08x, x15_reg = %08x", dut.x14_reg, dut.x15_reg); + $display("Round state:"); + $display("state0_reg = %08x, state1_reg = %08x, state2_reg = %08x, state3_reg = %08x", + dut.state_reg[00], dut.state_reg[01], dut.state_reg[02], dut.state_reg[03]); + $display("state4_reg = %08x, state5_reg = %08x, state6_reg = %08x, state7_reg = %08x", + dut.state_reg[04], dut.state_reg[05], dut.state_reg[06], dut.state_reg[07]); + $display("state8_reg = %08x, state9_reg = %08x, state10_reg = %08x, state11_reg = %08x", + dut.state_reg[08], dut.state_reg[09], dut.state_reg[10], dut.state_reg[11]); + $display("state12_reg = %08x, state13_reg = %08x, state14_reg = %08x, state15_reg = %08x", + dut.state_reg[12], dut.state_reg[13], dut.state_reg[14], dut.state_reg[15]); $display(""); - $display("rounds_reg = %01x", dut.rounds_reg); + $display("rounds = %01x", dut.rounds); $display("qr_ctr_reg = %01x, dr_ctr_reg = %01x", dut.qr_ctr_reg, dut.dr_ctr_reg); $display("block0_ctr_reg = %08x, block1_ctr_reg = %08x", dut.block0_ctr_reg, dut.block1_ctr_reg); @@ -251,7 +235,7 @@ module tb_chacha_core(); $display("chacha_ctrl_reg = %02x", dut.chacha_ctrl_reg); $display(""); - $display("data_in_reg = %064x", dut.data_in_reg); + $display("data_in = %064x", dut.data_in); $display("data_out_valid_reg = %01x", dut.data_out_valid_reg); $display(""); @@ -266,7 +250,7 @@ module tb_chacha_core(); // dump_inout() // Dump the status for input and output ports. //---------------------------------------------------------------- - task dump_inout(); + task dump_inout; begin $display(""); $display("State for input and output ports:"); @@ -308,7 +292,7 @@ module tb_chacha_core(); dut.qr0_b = b; dut.qr0_c = c; dut.qr0_d = d; - #(2 * CLK_HALF_PERIOD); + #(CLK_PERIOD); $display("a0 = 0x%08x, a1 = 0x%08x", dut.qr0.qr.a0, dut.qr0.qr.a1); $display("b0 = 0x%08x, b1 = 0x%08x", dut.qr0.qr.b0, dut.qr0.qr.b1); @@ -331,7 +315,7 @@ module tb_chacha_core(); // Run some simple test on the qr logic. // Note: Not self testing. No expected value used. //---------------------------------------------------------------- - task qr_tests(); + task qr_tests; begin $display("*** Test of Quarterround:"); $display(""); @@ -389,15 +373,15 @@ module tb_chacha_core(); // // Cycles the reset signal on the dut. //---------------------------------------------------------------- - task cycle_reset(); + task cycle_reset; begin tb_reset_n = 0; - #(2 * CLK_HALF_PERIOD); + #(CLK_PERIOD); @(negedge tb_clk) tb_reset_n = 1; - #(2 * CLK_HALF_PERIOD); + #(CLK_PERIOD); end endtask // cycle_reset @@ -425,7 +409,7 @@ module tb_chacha_core(); set_core_key_iv_rounds(key, key_length, iv, rounds); set_core_init(1); - #(2 * CLK_HALF_PERIOD); + #(CLK_PERIOD); set_core_init(0); dump_state(); @@ -456,11 +440,11 @@ module tb_chacha_core(); // // Display the accumulated test results. //---------------------------------------------------------------- - task display_test_result(); + task display_test_result; begin if (error_ctr == 0) begin - $display("*** All %d test cases completed successfully", tc_ctr); + $display("*** All test cases completed successfully"); end else begin @@ -475,7 +459,7 @@ module tb_chacha_core(); // // Set the input to the DUT to defined values. //---------------------------------------------------------------- - task init_dut(); + task init_dut; begin cycle_ctr = 0; tb_clk = 0; @@ -489,7 +473,7 @@ module tb_chacha_core(); tb_core_init = 0; tb_core_next = 0; - tb_core_data_in = 512'h00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000; + tb_core_data_in = 512'h0; end endtask // init_dut @@ -510,7 +494,6 @@ module tb_chacha_core(); display_cycle_ctr = cycles; display_ctrl_and_ctrs = ctrl_ctr; display_state = state; - display_x_state = x_state; display_qround = qround; end endtask // set_display_prefs @@ -533,64 +516,64 @@ module tb_chacha_core(); $display(""); dump_state(); - #(4 * CLK_HALF_PERIOD); + #(2 * CLK_PERIOD); @(negedge tb_clk) tb_reset_n = 1; - #(2 * CLK_HALF_PERIOD); + #(CLK_PERIOD); $display("*** State after release of reset:"); $display(""); dump_state(); $display("TC1-1: All zero inputs. 128 bit key, 8 rounds."); run_test_case(TC1, ONE, - 256'h0000000000000000000000000000000000000000000000000000000000000000, + 256'h0, KEY_128_BITS, - 64'h0000000000000000, + 64'h0, EIGHT_ROUNDS, 512'he28a5fa4a67f8c5defed3e6fb7303486aa8427d31419a729572d777953491120b64ab8e72b8deb85cd6aea7cb6089a101824beeb08814a428aab1fa2c816081b); $display("TC1-2: All zero inputs. 128 bit key, 12 rounds."); run_test_case(TC1, TWO, - 256'h0000000000000000000000000000000000000000000000000000000000000000, + 256'h0, KEY_128_BITS, - 64'h0000000000000000, + 64'h0, TWELWE_ROUNDS, 512'he1047ba9476bf8ff312c01b4345a7d8ca5792b0ad467313f1dc412b5fdce32410dea8b68bd774c36a920f092a04d3f95274fbeff97bc8491fcef37f85970b450); $display("TC1-3: All zero inputs. 128 bit key, 20 rounds."); run_test_case(TC1, THREE, - 256'h0000000000000000000000000000000000000000000000000000000000000000, + 256'h0, KEY_128_BITS, - 64'h0000000000000000, + 64'h0, TWENTY_ROUNDS, 512'h89670952608364fd00b2f90936f031c8e756e15dba04b8493d00429259b20f46cc04f111246b6c2ce066be3bfb32d9aa0fddfbc12123d4b9e44f34dca05a103f); $display("TC1-4: All zero inputs. 256 bit key, 8 rounds."); run_test_case(TC1, FOUR, - 256'h0000000000000000000000000000000000000000000000000000000000000000, + 256'h0, KEY_256_BITS, - 64'h0000000000000000, + 64'h0, EIGHT_ROUNDS, 512'h3e00ef2f895f40d67f5bb8e81f09a5a12c840ec3ce9a7f3b181be188ef711a1e984ce172b9216f419f445367456d5619314a42a3da86b001387bfdb80e0cfe42); $display("TC1-5: All zero inputs. 256 bit key, 12 rounds."); run_test_case(TC1, FIVE, - 256'h0000000000000000000000000000000000000000000000000000000000000000, + 256'h0, KEY_256_BITS, - 64'h0000000000000000, + 64'h0, TWELWE_ROUNDS, 512'h9bf49a6a0755f953811fce125f2683d50429c3bb49e074147e0089a52eae155f0564f879d27ae3c02ce82834acfa8c793a629f2ca0de6919610be82f411326be); $display("TC1-6: All zero inputs. 256 bit key, 20 rounds."); run_test_case(TC1, SIX, - 256'h0000000000000000000000000000000000000000000000000000000000000000, + 256'h0, KEY_256_BITS, - 64'h0000000000000000, + 64'h0, TWENTY_ROUNDS, 512'h76b8e0ada0f13d90405d6ae55386bd28bdd219b8a08ded1aa836efcc8b770dc7da41597c5157488d7724e03fb8d84a376a43b8f41518a11cc387b669b2ee6586); @@ -599,7 +582,7 @@ module tb_chacha_core(); run_test_case(TC2, ONE, 256'h0100000000000000000000000000000000000000000000000000000000000000, KEY_128_BITS, - 64'h0000000000000000, + 64'h0, EIGHT_ROUNDS, 512'h03a7669888605a0765e8357475e58673f94fc8161da76c2a3aa2f3caf9fe5449e0fcf38eb882656af83d430d410927d55c972ac4c92ab9da3713e19f761eaa14); @@ -608,14 +591,14 @@ module tb_chacha_core(); run_test_case(TC2, ONE, 256'h0100000000000000000000000000000000000000000000000000000000000000, KEY_256_BITS, - 64'h0000000000000000, + 64'h0, EIGHT_ROUNDS, 512'hcf5ee9a0494aa9613e05d5ed725b804b12f4a465ee635acc3a311de8740489ea289d04f43c7518db56eb4433e498a1238cd8464d3763ddbb9222ee3bd8fae3c8); $display("TC3-1: All zero key, one bit in IV set. 128 bit key, 8 rounds."); run_test_case(TC3, ONE, - 256'h0000000000000000000000000000000000000000000000000000000000000000, + 256'h0, KEY_128_BITS, 64'h0100000000000000, EIGHT_ROUNDS, |