[Cryptech-Commits] [core/cipher/aes] 09/21: Increased number of inverse S-boxes to 16 and removed S-box scheduling.

git at cryptech.is git at cryptech.is
Thu Jan 10 11:53:57 UTC 2019


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

sra at hactrn.net pushed a commit to branch master
in repository core/cipher/aes.

commit 61f2ceb69c96c3d1edd1c70d1f50016d947cfdb9
Author: Joachim Strömbergson <joachim at secworks.se>
AuthorDate: Mon May 21 19:03:36 2018 +0200

    Increased number of inverse S-boxes to 16 and removed S-box scheduling.
---
 src/rtl/aes_decipher_block.v   | 104 +++++++++++------------------------------
 src/tb/tb_aes_decipher_block.v |   5 +-
 2 files changed, 29 insertions(+), 80 deletions(-)

diff --git a/src/rtl/aes_decipher_block.v b/src/rtl/aes_decipher_block.v
index 82bdffb..c2304d6 100644
--- a/src/rtl/aes_decipher_block.v
+++ b/src/rtl/aes_decipher_block.v
@@ -192,12 +192,6 @@ module aes_decipher_block(
   //----------------------------------------------------------------
   // Registers including update variables and write enable.
   //----------------------------------------------------------------
-  reg [1 : 0]   sword_ctr_reg;
-  reg [1 : 0]   sword_ctr_new;
-  reg           sword_ctr_we;
-  reg           sword_ctr_inc;
-  reg           sword_ctr_rst;
-
   reg [3 : 0]   round_ctr_reg;
   reg [3 : 0]   round_ctr_new;
   reg           round_ctr_we;
@@ -226,15 +220,24 @@ module aes_decipher_block(
   //----------------------------------------------------------------
   // Wires.
   //----------------------------------------------------------------
-  reg [31 : 0]  tmp_sboxw;
-  wire [31 : 0] new_sboxw;
+  reg [31 : 0]  sboxw0;
+  reg [31 : 0]  sboxw1;
+  reg [31 : 0]  sboxw2;
+  reg [31 : 0]  sboxw3;
+  wire [31 : 0] new_sboxw0;
+  wire [31 : 0] new_sboxw1;
+  wire [31 : 0] new_sboxw2;
+  wire [31 : 0] new_sboxw3;
   reg [2 : 0]   update_type;
 
 
   //----------------------------------------------------------------
-  // Instantiations.
+  // Inverse S-boxes.
   //----------------------------------------------------------------
-  aes_inv_sbox inv_sbox_inst(.sword(tmp_sboxw), .new_sword(new_sboxw));
+  aes_inv_sbox inv_sbox_inst0(.sword(sboxw0), .new_sword(new_sboxw0));
+  aes_inv_sbox inv_sbox_inst1(.sword(sboxw1), .new_sword(new_sboxw1));
+  aes_inv_sbox inv_sbox_inst2(.sword(sboxw2), .new_sword(new_sboxw2));
+  aes_inv_sbox inv_sbox_inst3(.sword(sboxw3), .new_sword(new_sboxw3));
 
 
   //----------------------------------------------------------------
@@ -260,7 +263,6 @@ module aes_decipher_block(
           block_w1_reg  <= 32'h0;
           block_w2_reg  <= 32'h0;
           block_w3_reg  <= 32'h0;
-          sword_ctr_reg <= 2'h0;
           round_ctr_reg <= 4'h0;
           ready_reg     <= 1'b1;
           dec_ctrl_reg  <= CTRL_IDLE;
@@ -279,9 +281,6 @@ module aes_decipher_block(
           if (block_w3_we)
             block_w3_reg <= block_new[031 : 000];
 
-          if (sword_ctr_we)
-            sword_ctr_reg <= sword_ctr_new;
-
           if (round_ctr_we)
             round_ctr_reg <= round_ctr_new;
 
@@ -308,13 +307,17 @@ module aes_decipher_block(
       inv_mixcolumns_block = 128'h0;
       addkey_block         = 128'h0;
       block_new            = 128'h0;
-      tmp_sboxw            = 32'h0;
       block_w0_we          = 1'b0;
       block_w1_we          = 1'b0;
       block_w2_we          = 1'b0;
       block_w3_we          = 1'b0;
 
-      old_block            = {block_w0_reg, block_w1_reg, block_w2_reg, block_w3_reg};
+      sboxw0 = block_w0_reg;
+      sboxw1 = block_w1_reg;
+      sboxw2 = block_w2_reg;
+      sboxw3 = block_w3_reg;
+
+      old_block = {block_w0_reg, block_w1_reg, block_w2_reg, block_w3_reg};
 
       // Update based on update type.
       case (update_type)
@@ -333,33 +336,11 @@ module aes_decipher_block(
 
         SBOX_UPDATE:
           begin
-            block_new = {new_sboxw, new_sboxw, new_sboxw, new_sboxw};
-
-            case (sword_ctr_reg)
-              2'h0:
-                begin
-                  tmp_sboxw   = block_w0_reg;
-                  block_w0_we = 1'b1;
-                end
-
-              2'h1:
-                begin
-                  tmp_sboxw   = block_w1_reg;
-                  block_w1_we = 1'b1;
-                end
-
-              2'h2:
-                begin
-                  tmp_sboxw   = block_w2_reg;
-                  block_w2_we = 1'b1;
-                end
-
-              2'h3:
-                begin
-                  tmp_sboxw   = block_w3_reg;
-                  block_w3_we = 1'b1;
-                end
-            endcase // case (sbox_mux_ctrl_reg)
+            block_new = {new_sboxw0, new_sboxw1, new_sboxw2, new_sboxw3};
+            block_w0_we = 1'b1;
+            block_w1_we = 1'b1;
+            block_w2_we = 1'b1;
+            block_w3_we = 1'b1;
           end
 
         MAIN_UPDATE:
@@ -390,29 +371,6 @@ module aes_decipher_block(
     end // round_logic
 
 
-  //----------------------------------------------------------------
-  // sword_ctr
-  //
-  // The subbytes word counter with reset and increase logic.
-  //----------------------------------------------------------------
-  always @*
-    begin : sword_ctr
-      sword_ctr_new = 2'h0;
-      sword_ctr_we  = 1'b0;
-
-      if (sword_ctr_rst)
-        begin
-          sword_ctr_new = 2'h0;
-          sword_ctr_we  = 1'b1;
-        end
-      else if (sword_ctr_inc)
-        begin
-          sword_ctr_new = sword_ctr_reg + 1'b1;
-          sword_ctr_we  = 1'b1;
-        end
-    end // sword_ctr
-
-
   //----------------------------------------------------------------
   // round_ctr
   //
@@ -450,8 +408,6 @@ module aes_decipher_block(
   //----------------------------------------------------------------
   always @*
     begin: decipher_ctrl
-      sword_ctr_inc = 1'b0;
-      sword_ctr_rst = 1'b0;
       round_ctr_dec = 1'b0;
       round_ctr_set = 1'b0;
       ready_new     = 1'b0;
@@ -475,7 +431,6 @@ module aes_decipher_block(
 
         CTRL_INIT:
           begin
-            sword_ctr_rst = 1'b1;
             update_type   = INIT_UPDATE;
             dec_ctrl_new  = CTRL_SBOX;
             dec_ctrl_we   = 1'b1;
@@ -483,19 +438,14 @@ module aes_decipher_block(
 
         CTRL_SBOX:
           begin
-            sword_ctr_inc = 1'b1;
             update_type   = SBOX_UPDATE;
-            if (sword_ctr_reg == 2'h3)
-              begin
-                round_ctr_dec = 1'b1;
-                dec_ctrl_new  = CTRL_MAIN;
-                dec_ctrl_we   = 1'b1;
-              end
+            round_ctr_dec = 1'b1;
+            dec_ctrl_new  = CTRL_MAIN;
+            dec_ctrl_we   = 1'b1;
           end
 
         CTRL_MAIN:
           begin
-            sword_ctr_rst = 1'b1;
             if (round_ctr_reg > 0)
               begin
                 update_type   = MAIN_UPDATE;
diff --git a/src/tb/tb_aes_decipher_block.v b/src/tb/tb_aes_decipher_block.v
index ec228c0..0475cf5 100644
--- a/src/tb/tb_aes_decipher_block.v
+++ b/src/tb/tb_aes_decipher_block.v
@@ -152,13 +152,12 @@ module tb_aes_decipher_block();
 
       $display("Control states");
       $display("round = 0x%01x", dut.round);
-      $display("dec_ctrl = 0x%01x, update_type = 0x%01x, sword_ctr = 0x%01x, round_ctr = 0x%01x",
-               dut.dec_ctrl_reg, dut.update_type, dut.sword_ctr_reg, dut.round_ctr_reg);
+      $display("dec_ctrl = 0x%01x, update_type = 0x%01x, round_ctr = 0x%01x",
+               dut.dec_ctrl_reg, dut.update_type, dut.round_ctr_reg);
       $display("");
 
       $display("Internal data values");
       $display("round_key = 0x%016x", dut.round_key);
-      $display("sboxw = 0x%08x, new_sboxw = 0x%08x", dut.tmp_sboxw, dut.new_sboxw);
       $display("block_w0_reg = 0x%08x, block_w1_reg = 0x%08x, block_w2_reg = 0x%08x, block_w3_reg = 0x%08x",
                dut.block_w0_reg, dut.block_w1_reg, dut.block_w2_reg, dut.block_w3_reg);
       $display("");



More information about the Commits mailing list