[Cryptech-Commits] [core/util/keywrap] 53/95: Updated keywrap logic to support unwrap. Split state to handle next start in both wrap and unwrap cases.

git at cryptech.is git at cryptech.is
Wed Mar 25 17:18:52 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 732478fb1672a3ee16f10602ae443db7d0e9fd59
Author: Joachim Strömbergson <joachim at secworks.se>
AuthorDate: Thu Jul 5 15:29:45 2018 +0200

    Updated keywrap logic to support unwrap. Split state to handle next start in both wrap and unwrap cases.
---
 src/rtl/keywrap_core.v | 86 +++++++++++++++++++++++++++++++++-----------------
 1 file changed, 57 insertions(+), 29 deletions(-)

diff --git a/src/rtl/keywrap_core.v b/src/rtl/keywrap_core.v
index 91e5161..99736f2 100644
--- a/src/rtl/keywrap_core.v
+++ b/src/rtl/keywrap_core.v
@@ -73,13 +73,15 @@ module keywrap_core (
 
   localparam CTRL_IDLE          = 4'h0;
   localparam CTRL_INIT_WAIT     = 4'h1;
-  localparam CTRL_NEXT_LOOP     = 4'h2;
-  localparam CTRL_NEXT_WAIT0    = 4'h3;
-  localparam CTRL_NEXT_WAIT     = 4'h4;
-  localparam CTRL_NEXT_UPDATE   = 4'h5;
-  localparam CTRL_NEXT_WRAP     = 4'h6;
-  localparam CTRL_NEXT_UNWRAP   = 4'h7;
-  localparam CTRL_NEXT_FINALIZE = 4'h8;
+  localparam CTRL_NEXT_WSTART   = 4'h2;
+  localparam CTRL_NEXT_USTART   = 4'h3;
+  localparam CTRL_NEXT_LOOP     = 4'h4;
+  localparam CTRL_NEXT_WAIT0    = 4'h5;
+  localparam CTRL_NEXT_WAIT     = 4'h6;
+  localparam CTRL_NEXT_UPDATE   = 4'h7;
+  localparam CTRL_NEXT_WCHECK   = 4'h8;
+  localparam CTRL_NEXT_UCHECK   = 4'h9;
+  localparam CTRL_NEXT_FINALIZE = 4'ha;
 
 
   //----------------------------------------------------------------
@@ -221,23 +223,28 @@ module keywrap_core (
 
 
   //----------------------------------------------------------------
-  // keywrap_dp
+  // keywrap_logic
   //
   // Main logic for the key wrap functionality.
   //----------------------------------------------------------------
   always @*
-    begin : keywrap_dp
+    begin : keywrap_logic
       reg [63 : 0] xor_val;
 
       a_new     = 64'h0;
       a_we      = 1'h0;
       core_addr = block_ctr_reg - 1'h1;
-      core_we = 1'h0;
+      core_we   = 1'h0;
 
-      aes_block = {a_reg, core_rd_data};
-      core_wr_data = aes_result[63 : 0];
       xor_val = (rlen * iteration_ctr_reg) + {51'h0, block_ctr_reg};
 
+      if (encdec)
+        aes_block = {a_reg, core_rd_data};
+      else
+        aes_block = {(a_reg ^ xor_val), core_rd_data};
+
+      core_wr_data = aes_result[63 : 0];
+
       if (init_a)
         begin
           a_new = a_init;
@@ -246,9 +253,13 @@ module keywrap_core (
 
       if (update_state)
         begin
-          a_new   = aes_result[127 : 64] ^ xor_val;
-          a_we    = 1'h1;
           core_we = 1'h1;
+
+          if (encdec)
+            a_new   = aes_result[127 : 64] ^ xor_val;
+          else
+            a_new   = aes_result[127 : 64];
+          a_we    = 1'h1;
         end
     end
 
@@ -258,7 +269,7 @@ module keywrap_core (
   //----------------------------------------------------------------
   always @*
     begin : block_ctr
-      block_ctr_new = 13'h1;
+      block_ctr_new = 13'h0;
       block_ctr_we  = 1'h0;
 
       if (block_ctr_rst)
@@ -363,18 +374,21 @@ module keywrap_core (
 
             if (next)
               begin
-                block_ctr_rst         = 1'h1;
-                iteration_ctr_rst     = 1'h1;
                 ready_new             = 1'h0;
                 ready_we              = 1'h1;
                 valid_new             = 1'h0;
                 valid_we              = 1'h1;
                 init_a                = 1'h1;
-                keywrap_core_ctrl_new = CTRL_NEXT_LOOP;
+
+                if (encdec)
+                  keywrap_core_ctrl_new = CTRL_NEXT_WSTART;
+                else
+                  keywrap_core_ctrl_new = CTRL_NEXT_USTART;
                 keywrap_core_ctrl_we  = 1'h1;
               end
           end
 
+
         CTRL_INIT_WAIT:
           begin
             if (aes_ready)
@@ -387,6 +401,24 @@ module keywrap_core (
           end
 
 
+        CTRL_NEXT_WSTART:
+          begin
+            block_ctr_rst         = 1'h1;
+            iteration_ctr_rst     = 1'h1;
+            keywrap_core_ctrl_new = CTRL_NEXT_LOOP;
+            keywrap_core_ctrl_we  = 1'h1;
+          end
+
+
+        CTRL_NEXT_USTART:
+          begin
+            block_ctr_set         = 1'h1;
+            iteration_ctr_set     = 1'h1;
+            keywrap_core_ctrl_new = CTRL_NEXT_LOOP;
+            keywrap_core_ctrl_we  = 1'h1;
+          end
+
+
         CTRL_NEXT_LOOP:
           begin
             aes_next              = 1'h1;
@@ -414,21 +446,17 @@ module keywrap_core (
 
         CTRL_NEXT_UPDATE:
           begin
-            update_state          = 1'h1;
+            update_state = 1'h1;
+
             if (encdec)
-              begin
-                keywrap_core_ctrl_new = CTRL_NEXT_WRAP;
-                keywrap_core_ctrl_we  = 1'h1;
-              end
+              keywrap_core_ctrl_new = CTRL_NEXT_WCHECK;
             else
-              begin
-                keywrap_core_ctrl_new = CTRL_NEXT_UNWRAP;
-                keywrap_core_ctrl_we  = 1'h1;
-              end
+              keywrap_core_ctrl_new = CTRL_NEXT_UCHECK;
+            keywrap_core_ctrl_we  = 1'h1;
           end
 
 
-        CTRL_NEXT_WRAP:
+        CTRL_NEXT_WCHECK:
           begin
             if (block_ctr_reg < rlen)
               begin
@@ -453,7 +481,7 @@ module keywrap_core (
           end
 
 
-        CTRL_NEXT_UNWRAP:
+        CTRL_NEXT_UCHECK:
           begin
             if (block_ctr_reg > 0)
               begin



More information about the Commits mailing list