[Cryptech-Commits] [core/util/keywrap] 37/95: Added test case with vectors from NIST KWP AE. Test fails. But at least it doesn't hang. Now for some bug hunting.

git at cryptech.is git at cryptech.is
Wed Mar 25 17:18:36 UTC 2020


This is an automated email from the git hooks/post-receive script.

paul at psgd.org pushed a commit to branch master
in repository core/util/keywrap.

commit 2d3531979d28f73027587cd7168e33a1b66fe811
Author: Joachim Strömbergson <joachim at secworks.se>
AuthorDate: Tue Jul 3 10:56:35 2018 +0200

    Added test case with vectors from NIST KWP AE. Test fails. But at least it doesn't hang. Now for some bug hunting.
---
 src/tb/tb_keywrap.v | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 82 insertions(+), 2 deletions(-)

diff --git a/src/tb/tb_keywrap.v b/src/tb/tb_keywrap.v
index fee890c..9c6fb56 100644
--- a/src/tb/tb_keywrap.v
+++ b/src/tb/tb_keywrap.v
@@ -66,6 +66,12 @@ module tb_keywrap();
   localparam ADDR_A_MSB       = 8'h0f;
 
   localparam ADDR_KEY0        = 8'h10;
+  localparam ADDR_KEY1        = 8'h11;
+  localparam ADDR_KEY2        = 8'h12;
+  localparam ADDR_KEY3        = 8'h13;
+  localparam ADDR_KEY4        = 8'h14;
+  localparam ADDR_KEY5        = 8'h15;
+  localparam ADDR_KEY6        = 8'h16;
   localparam ADDR_KEY7        = 8'h17;
 
   localparam ADDR_WRITE_DATA  = 8'h20;
@@ -270,7 +276,7 @@ module tb_keywrap();
   //----------------------------------------------------------------
   task reset_dut;
     begin
-      $display("*** Toggling reset.");
+      $display("** Toggling reset.");
       tb_reset_n = 0;
 
       #(2 * CLK_PERIOD);
@@ -280,6 +286,76 @@ module tb_keywrap();
   endtask // reset_dut
 
 
+  //----------------------------------------------------------------
+  // Implements test based on NIST KWP_AE 128 bit key test 4.
+  //----------------------------------------------------------------
+  task test_kwp_ae_128_4;
+    begin : kwp_ae_128_4
+      integer i;
+
+      tc_ctr = tc_ctr + 1;
+
+      $display("** TC kwp_ae_128_4 START.");
+
+
+      // Write key and keylength, we also want to encrypt/wrap.
+      write_word(ADDR_KEY3,   32'hc03db3cc);
+      write_word(ADDR_KEY2,   32'h1416dcd1);
+      write_word(ADDR_KEY1,   32'hc069a195);
+      write_word(ADDR_KEY0,   32'ha8d77e3d);
+      write_word(ADDR_CONFIG, 32'h00000001);
+
+
+      // Write magic words to the A state regs.
+      // Also set the rlen.
+      write_word(ADDR_A_LSB, 32'h0000001f);
+      write_word(ADDR_A_MSB, 32'ha65959a6);
+      write_word(ADDR_RLEN,  32'h00000004);
+
+
+      // Initialize the AES engine and reset counters.
+      // Wait for init to complete.
+      write_word(ADDR_CTRL, 32'h00000001);
+      wait_ready();
+
+
+      // Write the R blocks to be processed.
+      write_word(ADDR_WRITE_DATA, 32'hcdda4200);
+      write_word(ADDR_WRITE_DATA, 32'h46f87f58);
+
+      write_word(ADDR_WRITE_DATA, 32'h2e49bdb7);
+      write_word(ADDR_WRITE_DATA, 32'hf53d99ce);
+
+      write_word(ADDR_WRITE_DATA, 32'he0cd4d0b);
+      write_word(ADDR_WRITE_DATA, 32'h6212511f);
+
+      write_word(ADDR_WRITE_DATA, 32'h45a28800);
+      write_word(ADDR_WRITE_DATA, 32'h5f37a27d);
+
+
+      // Start wrapping and wait for wrap to complete.
+      write_word(ADDR_CTRL, 32'h00000002);
+      wait_ready();
+
+
+      // Read and display the A registers.
+      read_word(ADDR_A_LSB);
+      $display("A LSB after wrap: 0x%08x", read_data);
+      read_word(ADDR_A_MSB);
+      $display("A MSB after wrap: 0x%08x", read_data);
+
+      // Read and display the R blocks that has been processed.
+      for (i = 0 ; i < 8 ; i = i + 1)
+        begin
+          read_word(ADDR_READ_DATA);
+          $display("mem[0x%07x] = 0x%08x", i, read_data);
+        end
+
+      $display("** TC kwp_ae_128_4 END.\n");
+    end
+  endtask // test_kwp_ae_128_4
+
+
   //----------------------------------------------------------------
   // main
   //----------------------------------------------------------------
@@ -290,14 +366,18 @@ module tb_keywrap();
       $display("");
 
       init_sim();
+
       dump_dut_state();
       reset_dut();
       dump_dut_state();
 
+      test_kwp_ae_128_4();
+
       display_test_results();
 
       $display("");
-      $display("*** Keywrap simulation done. ***");
+      $display("   -= Testbench for Keywrap completed =-");
+      $display("    ====================================");
       $finish;
     end // main
 



More information about the Commits mailing list