From 70e1598c451c4c1ebf4d52b952b6dd6f4fb7ff66 Mon Sep 17 00:00:00 2001 From: bsdevlin Date: Wed, 13 Feb 2019 16:43:19 -0500 Subject: [PATCH] Bug updates, now working correctly for all test cases --- ip_cores/blake2b/src/rtl/blake2b_pkg.sv | 2 +- ip_cores/blake2b/src/rtl/blake2b_top.sv | 27 +++++++++-------------- ip_cores/blake2b/src/tb/blake2b_top_tb.sv | 3 +++ 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/ip_cores/blake2b/src/rtl/blake2b_pkg.sv b/ip_cores/blake2b/src/rtl/blake2b_pkg.sv index 7837a1d..7a22548 100644 --- a/ip_cores/blake2b/src/rtl/blake2b_pkg.sv +++ b/ip_cores/blake2b/src/rtl/blake2b_pkg.sv @@ -10,7 +10,7 @@ package blake2b_pkg; 64'h3c6ef372fe94f82b, 64'hbb67ae8584caa73b, 64'h6a09e667f3bcc908 - }; + }; // Sigma permutations used for G function blocks and input messages parameter [16*10-1:0][31:0] SIGMA = { diff --git a/ip_cores/blake2b/src/rtl/blake2b_top.sv b/ip_cores/blake2b/src/rtl/blake2b_top.sv index c2204ff..a72a43b 100644 --- a/ip_cores/blake2b/src/rtl/blake2b_top.sv +++ b/ip_cores/blake2b/src/rtl/blake2b_top.sv @@ -1,4 +1,4 @@ -/* Implemented from RFC-7693, The BLAKE2 Cryptographic Hash and Message Authentication Code (MAC) +/* Implemented from RFC-7693, The BLAKE2b Cryptographic Hash and Message Authentication Code (MAC) * Parameters are passed in as an input. Inputs and outputs are AXI stream and respect flow control. * Only only hash is computed at a time, and takes 26 clocks * number of 128 Byte message blocks. */ @@ -36,17 +36,15 @@ logic [7:0] byte_len_l; // Pipelining logic that has no reset always_ff @(posedge i_clk) begin - if (blake2_state == STATE_IDLE && ~i_block.rdy) + if (blake2_state == STATE_IDLE) block_r <= 0; - if (i_block.val && i_block.rdy) begin + if (i_block.val && i_block.rdy) block_r <= i_block.dat; - end - - for (int i = 0; i < 16; i++) - if (g_col == 0) - v_tmp[i] <= g_out[blake2b_pkg::G_MAPPING[i]]; + for (int i = 0; i < 16; i++) begin + v_tmp[blake2b_pkg::G_MAPPING[i]] <= g_out[i]; + end for (int i = 0; i < 8; i++) if (blake2_state == STATE_ROUNDS) @@ -99,28 +97,25 @@ always_ff @(posedge i_clk) begin end end // Here we do the compression over 12 rounds, each round can be done in two clock cycles - // After we do 12 rounds we increment counter t STATE_ROUNDS: begin // Update local work vector with output of G function blocks depending on column or diagonal operation - for (int i = 0; i < 16; i++) begin + for (int i = 0; i < 16; i++) v[i] <= g_out[16 + blake2b_pkg::G_MAPPING_DIAG[i]]; - end - if (g_col) begin + if (g_col) round_cntr <= round_cntr + 1; - end else begin + else round_cntr_msg <= (round_cntr_msg + 1) % 10; - end + if (round_cntr == ROUNDS-1) round_cntr_fin <= 1; if (round_cntr_fin) begin if (block_eop_l) blake2_state <= STATE_FINAL_BLOCK; - else begin + else blake2_state <= STATE_NEXT_BLOCK; - end end end STATE_NEXT_BLOCK: begin diff --git a/ip_cores/blake2b/src/tb/blake2b_top_tb.sv b/ip_cores/blake2b/src/tb/blake2b_top_tb.sv index 8b0ae50..a98bc36 100644 --- a/ip_cores/blake2b/src/tb/blake2b_top_tb.sv +++ b/ip_cores/blake2b/src/tb/blake2b_top_tb.sv @@ -37,6 +37,7 @@ task rfc_test(); begin integer signed get_len; logic [common_pkg::MAX_SIM_BYTS*8-1:0] get_dat; + $display("Running rfc_test...\n"); expected = 'h239900d4ed8623b95a92f1dba88ad31895cc3345ded552c22d79ab2a39c5877dd1a2ffdb6fbb124bb7c45a68142f214ce9f6129fb697276a0d4d1c983fa580ba; i_byte_len = 3; i_block.put_stream("cba", i_byte_len); @@ -51,6 +52,7 @@ task test_128_bytes(); begin integer signed get_len; logic [common_pkg::MAX_SIM_BYTS*8-1:0] get_dat; + $display("Running test_128_bytes..."); expected = 'hd2a56bb7bb1ff1fffcf2f151522455e32969ddfeb409b105f45299b8cbd68eb370fd6d45d63981d23cd2686dfd9a76f5b1d134be076f7d08ecc457522042e34a; i_byte_len = 128; i_block.put_stream("monek14SFMpNgHz12zMfplMfcHkx6JhKhSWTNwzGiq8UiPa4n4Ehq363oHG92GPDVpvQut4ui5e6XxieeKTn1THLWiMZ0iaOFndxcT6FGPgmHXQ5zJU96X71zfWbvUQs", i_byte_len); @@ -65,6 +67,7 @@ task test_140_bytes(); begin integer signed get_len; logic [common_pkg::MAX_SIM_BYTS*8-1:0] get_dat; + $display("Running test_140_bytes..."); expected = 'h2012a869a3b89a69ffc954f6855c7f61a61190553dc487171ec3fe944d04c83cd4c842fff5a8258d5e14b05b7b6f30e8ddcb754d719137ec42fb5cdb562f8c89; i_byte_len = 140; i_block.put_stream("YbEAEzgJ1tgC3t6vDaJFqlWp1PaL482f7iZZzRj3xXpY2PPupwdTKAaBzB6KuN6j0alaoaFQfNboDbkNv5KDs5d7zN9JssrtOjGJdrVLfvb7uAdnVYoIgIv2zbXUQIPpwWdzEzj1CzX5", i_byte_len);