diff options
author | Joachim StroĢmbergson <joachim@secworks.se> | 2018-07-05 15:15:14 +0200 |
---|---|---|
committer | Joachim StroĢmbergson <joachim@secworks.se> | 2018-07-05 15:15:14 +0200 |
commit | f7da70916565e8e11a69c9ed845b001acf224635 (patch) | |
tree | dd1989fa3373f80dae763b415975560a7716e9a2 /src/rtl | |
parent | 243474ba221fede6574bf49e4f384b4623825eee (diff) |
Adding state and counter functionality to support unwrap. Changed name of define to something more comprehensible.
Diffstat (limited to 'src/rtl')
-rw-r--r-- | src/rtl/keywrap_core.v | 66 |
1 files changed, 58 insertions, 8 deletions
diff --git a/src/rtl/keywrap_core.v b/src/rtl/keywrap_core.v index 28e8f74..91e5161 100644 --- a/src/rtl/keywrap_core.v +++ b/src/rtl/keywrap_core.v @@ -69,7 +69,7 @@ module keywrap_core ( //---------------------------------------------------------------- // Paramenters and local defines. //---------------------------------------------------------------- - localparam OUTER_LOOP_MAX = 6 - 1; + localparam MAX_ITERATIONS = 6 - 1; localparam CTRL_IDLE = 4'h0; localparam CTRL_INIT_WAIT = 4'h1; @@ -77,8 +77,9 @@ module keywrap_core ( localparam CTRL_NEXT_WAIT0 = 4'h3; localparam CTRL_NEXT_WAIT = 4'h4; localparam CTRL_NEXT_UPDATE = 4'h5; - localparam CTRL_NEXT_CHECK = 4'h6; - localparam CTRL_NEXT_FINALIZE = 4'h7; + localparam CTRL_NEXT_WRAP = 4'h6; + localparam CTRL_NEXT_UNWRAP = 4'h7; + localparam CTRL_NEXT_FINALIZE = 4'h8; //---------------------------------------------------------------- @@ -100,8 +101,10 @@ module keywrap_core ( reg [12 : 0] block_ctr_reg; reg [12 : 0] block_ctr_new; reg block_ctr_we; + reg block_ctr_dec; reg block_ctr_inc; reg block_ctr_rst; + reg block_ctr_set; reg [2 : 0] iteration_ctr_reg; reg [2 : 0] iteration_ctr_new; @@ -264,6 +267,18 @@ module keywrap_core ( block_ctr_we = 1'h1; end + if (block_ctr_set) + begin + block_ctr_new = rlen; + block_ctr_we = 1'h1; + end + + if (block_ctr_dec) + begin + block_ctr_new = block_ctr_reg - 1'h1; + block_ctr_we = 1'h1; + end + if (block_ctr_inc) begin block_ctr_new = block_ctr_reg + 1'h1; @@ -288,7 +303,7 @@ module keywrap_core ( if (iteration_ctr_set) begin - iteration_ctr_new = 3'h5; + iteration_ctr_new = MAX_ITERATIONS; iteration_ctr_we = 1'h1; end @@ -320,8 +335,10 @@ module keywrap_core ( update_state = 1'h0; aes_init = 1'h0; aes_next = 1'h0; + block_ctr_dec = 1'h0; block_ctr_inc = 1'h0; block_ctr_rst = 1'h0; + block_ctr_set = 1'h0; iteration_ctr_inc = 1'h0; iteration_ctr_dec = 1'h0; iteration_ctr_set = 1'h0; @@ -398,12 +415,20 @@ module keywrap_core ( CTRL_NEXT_UPDATE: begin update_state = 1'h1; - keywrap_core_ctrl_new = CTRL_NEXT_CHECK; - keywrap_core_ctrl_we = 1'h1; + if (encdec) + begin + keywrap_core_ctrl_new = CTRL_NEXT_WRAP; + keywrap_core_ctrl_we = 1'h1; + end + else + begin + keywrap_core_ctrl_new = CTRL_NEXT_UNWRAP; + keywrap_core_ctrl_we = 1'h1; + end end - CTRL_NEXT_CHECK: + CTRL_NEXT_WRAP: begin if (block_ctr_reg < rlen) begin @@ -412,7 +437,7 @@ module keywrap_core ( keywrap_core_ctrl_we = 1'h1; end - else if (iteration_ctr_reg < OUTER_LOOP_MAX) + else if (iteration_ctr_reg < MAX_ITERATIONS) begin block_ctr_rst = 1'h1; iteration_ctr_inc = 1'h1; @@ -428,6 +453,31 @@ module keywrap_core ( end + CTRL_NEXT_UNWRAP: + begin + if (block_ctr_reg > 0) + begin + block_ctr_dec = 1'h1; + keywrap_core_ctrl_new = CTRL_NEXT_LOOP; + keywrap_core_ctrl_we = 1'h1; + end + + else if (iteration_ctr_reg > 0) + begin + block_ctr_set = 1'h1; + iteration_ctr_dec = 1'h1; + keywrap_core_ctrl_new = CTRL_NEXT_LOOP; + keywrap_core_ctrl_we = 1'h1; + end + + else + begin + keywrap_core_ctrl_new = CTRL_NEXT_FINALIZE; + keywrap_core_ctrl_we = 1'h1; + end + end + + CTRL_NEXT_FINALIZE: begin ready_new = 1'h1; |