From 033f6292ad4ec8c299f8765d2d3184566734de31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Sun, 24 May 2015 21:51:06 +0200 Subject: Adding two more signing test cases with e=65537 and explicit lengths for exponent and modulus, message. --- src/tb/tb_modexp.v | 174 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 169 insertions(+), 5 deletions(-) diff --git a/src/tb/tb_modexp.v b/src/tb/tb_modexp.v index 4b3029e..1eb7c13 100644 --- a/src/tb/tb_modexp.v +++ b/src/tb/tb_modexp.v @@ -204,8 +204,7 @@ module tb_modexp(); #(CLK_PERIOD); if (DISPLAY_TEST_CYCLES) - $display("*** Number of cycles performed during test: 0x%016x", - {dut.cycle_ctr_high_reg, dut.cycle_ctr_low_reg}); + $display("*** Number of cycles performed during test: 0x%016x", test_cycle_ctr); end endtask // stop_test_cycle_ctr() @@ -775,7 +774,6 @@ module tb_modexp(); endtask // autogenerated_BASIC_33bit - //---------------------------------------------------------------- // autogenerated_BASIC_128bit() // @@ -834,6 +832,169 @@ module tb_modexp(); endtask // autogenerated_BASIC_128bit + //---------------------------------------------------------------- + // e65537_64bit_modulus() + //---------------------------------------------------------------- + task e65537_64bit_modulus(); + reg [31 : 0] read_data; + begin + success = 32'h1; + tc_ctr = tc_ctr + 1; + $display("Test with e = 65537 and 64 bit modulus."); + + write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); + write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00010001); + + write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); + write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hf077656f); + write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h3bf9e69b); + + write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); + write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hb6684dc3); + write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h79a5824b); + + write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000001); + write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000002); + + start_test_cycle_ctr(); + + // Start processing and wait for ready. + write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); + wait_ready(); + + stop_test_cycle_ctr(); + + write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); + read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h419a024f, read_data); + read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hdddf178e, read_data); + + if (success !== 1) + begin + $display("*** ERROR: e65537_64bit_modulus was NOT successful."); + error_ctr = error_ctr + 1; + end + else + $display("*** e65537_64bit_modulus success."); + end + endtask // e65537_64bit_modulus + + + //---------------------------------------------------------------- + // e65537_128bit_modulus() + //---------------------------------------------------------------- + task e65537_128bit_modulus(); + reg [31 : 0] read_data; + begin + success = 32'h1; + tc_ctr = tc_ctr + 1; + $display("Test with e = 65537 and 128 bit modulus."); + + write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); + write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00010001); + + write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); + write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hf5e8eee0); + write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hc06b048a); + write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h964b2105); + write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h2c36ad6b); + + write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); + write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h956e61b3); + write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h27997bc4); + write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h94e7e5c9); + write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hb53585cf); + + write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000001); + write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000004); + + start_test_cycle_ctr(); + + // Start processing and wait for ready. + write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); + wait_ready(); + + stop_test_cycle_ctr(); + + write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); + read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h1e97bff8, read_data); + read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h60029e6e, read_data); + read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hedaef85e, read_data); + read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hfb0c6562, read_data); + + if (success !== 1) + begin + $display("*** ERROR: e65537_128bit_modulus was NOT successful."); + error_ctr = error_ctr + 1; + end + else + $display("*** e65537_128bit_modulus success."); + end + endtask // e65537_128bit_modulus + + + //---------------------------------------------------------------- + // e65537_256bit_modulus() + // + // Task that tests modexp with small exponent and 256 bit modulus. + //---------------------------------------------------------------- + task e65537_256bit_modulus(); + reg [31 : 0] read_data; + begin + success = 32'h1; + tc_ctr = tc_ctr + 1; + $display("Test with e = 65537 and 256 bit modulus."); + + write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); + write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00010001); + + write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); + write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hf169d36e); + write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hbe2ce61d); + write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hc2e87809); + write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h4fed15c3); + write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h7c70eac5); + write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'ha123e643); + write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h299b36d2); + write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h788e583b); + + write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); + write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hf169d36e); + write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hbe2ce61d); + write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hc2e87809); + write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h4fed15c3); + write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h7c70eac5); + write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'ha123e643); + write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h299b36d2); + write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h788e583b); + + write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000001); + write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000008); + + start_test_cycle_ctr(); + + // Start processing and wait for ready. + write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); + wait_ready(); + + stop_test_cycle_ctr(); + + write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); + read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h0ddc404d, read_data); //TEMPLATE_EXPECTED_VALUES + read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h91600596, read_data); //TEMPLATE_EXPECTED_VALUES + read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h7425a8d8, read_data); //TEMPLATE_EXPECTED_VALUES + read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha066ca56, read_data); //TEMPLATE_EXPECTED_VALUES + + if (success !== 1) + begin + $display("*** ERROR: e65537_256bit_modulus was NOT successful."); + error_ctr = error_ctr + 1; + end + else + $display("*** e65537_256bit_modulus success."); + end + endtask // e65537_256bit_modulus + + //---------------------------------------------------------------- // main // @@ -854,8 +1015,11 @@ module tb_modexp(); tc1(); tc2(); tc3(); - autogenerated_BASIC_33bit(); - autogenerated_BASIC_128bit(); +// autogenerated_BASIC_33bit(); +// autogenerated_BASIC_128bit(); + e65537_64it_modulus(); + e65537_128it_modulus(); + e65537_256bit_modulus(); display_test_results(); // dump_memories(); -- cgit v1.2.3