From e08b46f30d8834d77a99d211eb0f47f1ea047786 Mon Sep 17 00:00:00 2001 From: bsdevlin Date: Thu, 28 Feb 2019 18:33:03 -0500 Subject: [PATCH] Bugfix for SHA256 core --- ip_cores/sha256/src/rtl/sha256_top.sv | 8 +++++--- ip_cores/sha256/src/tb/sha256_top_tb.sv | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/ip_cores/sha256/src/rtl/sha256_top.sv b/ip_cores/sha256/src/rtl/sha256_top.sv index 520e136..83966b2 100644 --- a/ip_cores/sha256/src/rtl/sha256_top.sv +++ b/ip_cores/sha256/src/rtl/sha256_top.sv @@ -80,7 +80,8 @@ always_ff @ (posedge i_clk) begin i_block.rdy <= 1; // As soon as we have one write on the input we can start if (i_block.rdy && i_block.val && i_block.sop) begin - W <= i_block.dat; + for (int i = 0; i < 16; i++) + W[i] <= sha256_pkg::bs32(i_block.dat[i*32 +: 32]); bit_len <= DAT_BITS; i_block.rdy <= 0; if (i_block.eop) @@ -113,12 +114,13 @@ always_ff @ (posedge i_clk) begin W[0] <= sha256_pkg::bs32(32'd1); sha_state <= SHA_ROUNDS; end else if (i_block.rdy && i_block.val) begin - W <= i_block.dat; + for (int i = 0; i < 16; i++) + W[i] <= sha256_pkg::bs32(i_block.dat[i*32 +: 32]); bit_len <= bit_len + DAT_BITS; if (i_block.eop) begin msg_eop(); - i_block.rdy <= 0; end + i_block.rdy <= 0; sha_state <= SHA_ROUNDS; end end diff --git a/ip_cores/sha256/src/tb/sha256_top_tb.sv b/ip_cores/sha256/src/tb/sha256_top_tb.sv index 7eef046..1e28f6d 100644 --- a/ip_cores/sha256/src/tb/sha256_top_tb.sv +++ b/ip_cores/sha256/src/tb/sha256_top_tb.sv @@ -73,6 +73,23 @@ task nist_double_block_test(); end endtask +// Test with 1487 bytes (size of equihash header + sol + len) +task large_test(); + begin + integer signed get_len; + logic [common_pkg::MAX_SIM_BYTS*8-1:0] get_dat, in_dat; + $display("Running large_test...\n"); + for (int i = 0; i < 23; i++) + in_dat[i*512 +: 512] = 'h0ff00ff0aa55aa55efbeadde55aa55aa0ff00ff0aa55aa55efbeadde55aa55aa0ff00ff0aa55aa55efbeadde55aa55aa0ff00ff0aa55aa55efbeadde55aa55aa; + in_dat[23*512 +: 512] = 'h636261aa55aa55efbeadde55aa55aa; + expected = 'ha09e5cbc1a770a777f20888ebb0efbaf5ba25767f10b52e6f3676c671760945a; // Both in little endian + i_block.put_stream(in_dat, 1487); + out_hash.get_stream(get_dat, get_len); + common_pkg::compare_and_print(get_dat, expected); + $display("large_test PASSED"); + end +endtask + // Main testbench calls initial begin @@ -83,6 +100,7 @@ initial begin nist_single_block_test(); nist_double_block_test(); + large_test(); #10us $finish();