aboutsummaryrefslogtreecommitdiff
path: root/src/tb
diff options
context:
space:
mode:
authorJoachim StroĢˆmbergson <joachim@secworks.se>2015-05-24 21:51:06 +0200
committerJoachim StroĢˆmbergson <joachim@secworks.se>2015-05-24 21:51:06 +0200
commit033f6292ad4ec8c299f8765d2d3184566734de31 (patch)
tree4237193a8453600b9edf69429aa7788960514669 /src/tb
parent7bb2e93583ad67c1f9beb37742116c4903d32677 (diff)
Adding two more signing test cases with e=65537 and explicit lengths for exponent and modulus, message.
Diffstat (limited to 'src/tb')
-rw-r--r--src/tb/tb_modexp.v174
1 files 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()
//
@@ -835,6 +833,169 @@ module tb_modexp();
//----------------------------------------------------------------
+ // 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
//
// The main test functionality.
@@ -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();