Bugfix for SHA256 core

This commit is contained in:
bsdevlin 2019-02-28 18:33:03 -05:00
parent 2251338f1d
commit e08b46f30d
2 changed files with 23 additions and 3 deletions

View File

@ -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

View File

@ -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();