From 0361065e15bfa903aaee988b8757419a120735c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Thu, 14 Dec 2017 16:31:52 +0100 Subject: Synced the AES core rtl and testbench to github. The updates does not add or modify any functionality, but silence a lot of warnings, reduce code size. --- src/rtl/aes_decipher_block.v | 166 +++++++++++++++++++------------------------ 1 file changed, 74 insertions(+), 92 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 75da9fb..82bdffb 100644 --- a/src/rtl/aes_decipher_block.v +++ b/src/rtl/aes_decipher_block.v @@ -58,23 +58,23 @@ module aes_decipher_block( //---------------------------------------------------------------- // Internal constant and parameter definitions. //---------------------------------------------------------------- - parameter AES_128_BIT_KEY = 1'h0; - parameter AES_256_BIT_KEY = 1'h1; + localparam AES_128_BIT_KEY = 1'h0; + localparam AES_256_BIT_KEY = 1'h1; - parameter AES128_ROUNDS = 4'ha; - parameter AES256_ROUNDS = 4'he; + localparam AES128_ROUNDS = 4'ha; + localparam AES256_ROUNDS = 4'he; - parameter NO_UPDATE = 3'h0; - parameter INIT_UPDATE = 3'h1; - parameter SBOX_UPDATE = 3'h2; - parameter MAIN_UPDATE = 3'h3; - parameter FINAL_UPDATE = 3'h4; + localparam NO_UPDATE = 3'h0; + localparam INIT_UPDATE = 3'h1; + localparam SBOX_UPDATE = 3'h2; + localparam MAIN_UPDATE = 3'h3; + localparam FINAL_UPDATE = 3'h4; - parameter CTRL_IDLE = 3'h0; - parameter CTRL_INIT = 3'h1; - parameter CTRL_SBOX = 3'h2; - parameter CTRL_MAIN = 3'h3; - parameter CTRL_FINAL = 3'h4; + localparam CTRL_IDLE = 3'h0; + localparam CTRL_INIT = 3'h1; + localparam CTRL_SBOX = 3'h2; + localparam CTRL_MAIN = 3'h3; + localparam CTRL_FINAL = 3'h4; //---------------------------------------------------------------- @@ -229,13 +229,12 @@ module aes_decipher_block( reg [31 : 0] tmp_sboxw; wire [31 : 0] new_sboxw; reg [2 : 0] update_type; - reg [3 : 0] num_rounds; //---------------------------------------------------------------- // Instantiations. //---------------------------------------------------------------- - aes_inv_sbox inv_sbox(.sword(tmp_sboxw), .new_sword(new_sboxw)); + aes_inv_sbox inv_sbox_inst(.sword(tmp_sboxw), .new_sword(new_sboxw)); //---------------------------------------------------------------- @@ -257,56 +256,40 @@ module aes_decipher_block( begin: reg_update if (!reset_n) begin - block_w0_reg <= 32'h00000000; - block_w1_reg <= 32'h00000000; - block_w2_reg <= 32'h00000000; - block_w3_reg <= 32'h00000000; + block_w0_reg <= 32'h0; + 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; + ready_reg <= 1'b1; dec_ctrl_reg <= CTRL_IDLE; end else begin if (block_w0_we) - begin - block_w0_reg <= block_new[127 : 096]; - end + block_w0_reg <= block_new[127 : 096]; if (block_w1_we) - begin - block_w1_reg <= block_new[095 : 064]; - end + block_w1_reg <= block_new[095 : 064]; if (block_w2_we) - begin - block_w2_reg <= block_new[063 : 032]; - end + block_w2_reg <= block_new[063 : 032]; if (block_w3_we) - begin - block_w3_reg <= block_new[031 : 000]; - end + block_w3_reg <= block_new[031 : 000]; if (sword_ctr_we) - begin - sword_ctr_reg <= sword_ctr_new; - end + sword_ctr_reg <= sword_ctr_new; if (round_ctr_we) - begin - round_ctr_reg <= round_ctr_new; - end + round_ctr_reg <= round_ctr_new; if (ready_we) - begin - ready_reg <= ready_new; - end + ready_reg <= ready_new; if (dec_ctrl_we) - begin - dec_ctrl_reg <= dec_ctrl_new; - end + dec_ctrl_reg <= dec_ctrl_new; end end // reg_update @@ -321,15 +304,15 @@ module aes_decipher_block( reg [127 : 0] old_block, inv_shiftrows_block, inv_mixcolumns_block; reg [127 : 0] addkey_block; - inv_shiftrows_block = 128'h00000000000000000000000000000000; - inv_mixcolumns_block = 128'h00000000000000000000000000000000; - addkey_block = 128'h00000000000000000000000000000000; - block_new = 128'h00000000000000000000000000000000; - tmp_sboxw = 32'h00000000; - block_w0_we = 0; - block_w1_we = 0; - block_w2_we = 0; - block_w3_we = 0; + inv_shiftrows_block = 128'h0; + 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}; @@ -342,10 +325,10 @@ module aes_decipher_block( addkey_block = addroundkey(old_block, round_key); inv_shiftrows_block = inv_shiftrows(addkey_block); block_new = inv_shiftrows_block; - block_w0_we = 1; - block_w1_we = 1; - block_w2_we = 1; - block_w3_we = 1; + block_w0_we = 1'b1; + block_w1_we = 1'b1; + block_w2_we = 1'b1; + block_w3_we = 1'b1; end SBOX_UPDATE: @@ -356,25 +339,25 @@ module aes_decipher_block( 2'h0: begin tmp_sboxw = block_w0_reg; - block_w0_we = 1; + block_w0_we = 1'b1; end 2'h1: begin tmp_sboxw = block_w1_reg; - block_w1_we = 1; + block_w1_we = 1'b1; end 2'h2: begin tmp_sboxw = block_w2_reg; - block_w2_we = 1; + block_w2_we = 1'b1; end 2'h3: begin tmp_sboxw = block_w3_reg; - block_w3_we = 1; + block_w3_we = 1'b1; end endcase // case (sbox_mux_ctrl_reg) end @@ -385,19 +368,19 @@ module aes_decipher_block( inv_mixcolumns_block = inv_mixcolumns(addkey_block); inv_shiftrows_block = inv_shiftrows(inv_mixcolumns_block); block_new = inv_shiftrows_block; - block_w0_we = 1; - block_w1_we = 1; - block_w2_we = 1; - block_w3_we = 1; + block_w0_we = 1'b1; + block_w1_we = 1'b1; + block_w2_we = 1'b1; + block_w3_we = 1'b1; end FINAL_UPDATE: begin block_new = addroundkey(old_block, round_key); - block_w0_we = 1; - block_w1_we = 1; - block_w2_we = 1; - block_w3_we = 1; + block_w0_we = 1'b1; + block_w1_we = 1'b1; + block_w2_we = 1'b1; + block_w3_we = 1'b1; end default: @@ -467,65 +450,65 @@ module aes_decipher_block( //---------------------------------------------------------------- always @* begin: decipher_ctrl - sword_ctr_inc = 0; - sword_ctr_rst = 0; - round_ctr_dec = 0; - round_ctr_set = 0; - ready_new = 0; - ready_we = 0; + sword_ctr_inc = 1'b0; + sword_ctr_rst = 1'b0; + round_ctr_dec = 1'b0; + round_ctr_set = 1'b0; + ready_new = 1'b0; + ready_we = 1'b0; update_type = NO_UPDATE; dec_ctrl_new = CTRL_IDLE; - dec_ctrl_we = 0; + dec_ctrl_we = 1'b0; case(dec_ctrl_reg) CTRL_IDLE: begin if (next) begin - round_ctr_set = 1; - ready_new = 0; - ready_we = 1; + round_ctr_set = 1'b1; + ready_new = 1'b0; + ready_we = 1'b1; dec_ctrl_new = CTRL_INIT; - dec_ctrl_we = 1; + dec_ctrl_we = 1'b1; end end CTRL_INIT: begin - sword_ctr_rst = 1; + sword_ctr_rst = 1'b1; update_type = INIT_UPDATE; dec_ctrl_new = CTRL_SBOX; - dec_ctrl_we = 1; + dec_ctrl_we = 1'b1; end CTRL_SBOX: begin - sword_ctr_inc = 1; + sword_ctr_inc = 1'b1; update_type = SBOX_UPDATE; if (sword_ctr_reg == 2'h3) begin - round_ctr_dec = 1; + round_ctr_dec = 1'b1; dec_ctrl_new = CTRL_MAIN; - dec_ctrl_we = 1; + dec_ctrl_we = 1'b1; end end CTRL_MAIN: begin - sword_ctr_rst = 1; + sword_ctr_rst = 1'b1; if (round_ctr_reg > 0) begin update_type = MAIN_UPDATE; dec_ctrl_new = CTRL_SBOX; - dec_ctrl_we = 1; + dec_ctrl_we = 1'b1; end else begin update_type = FINAL_UPDATE; - ready_new = 1; - ready_we = 1; + ready_new = 1'b1; + ready_we = 1'b1; dec_ctrl_new = CTRL_IDLE; - dec_ctrl_we = 1; + dec_ctrl_we = 1'b1; end end @@ -535,7 +518,6 @@ module aes_decipher_block( end endcase // case (dec_ctrl_reg) end // decipher_ctrl - endmodule // aes_decipher_block //====================================================================== -- cgit v1.2.3