From 0ab3199f5aaa792a577fb3ec8b7310c3c4213eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Mon, 21 May 2018 19:03:36 +0200 Subject: Increased number of inverse S-boxes to 16 and removed S-box scheduling. --- src/rtl/aes_decipher_block.v | 104 +++++++++++-------------------------------- 1 file changed, 27 insertions(+), 77 deletions(-) (limited to 'src/rtl/aes_decipher_block.v') 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; -- cgit v1.2.3