From f762c8d4e4ae3335c3340ac24ecc9c58606f7163 Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Sun, 6 Jun 2021 22:04:55 -0400 Subject: The SHA-3 algorithm really wants everything to be little-endian, which is at odds with everything else in our system (including the register interface to sha3_wrapper). Rather than trying to rewrite Bernd's beautiful code, I'll isolate it in its own little-endian universe by byte-swapping all reads and writes. --- src/tb/tb_sha3.v | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'src/tb') diff --git a/src/tb/tb_sha3.v b/src/tb/tb_sha3.v index 28d06a3..5dd93c4 100644 --- a/src/tb/tb_sha3.v +++ b/src/tb/tb_sha3.v @@ -239,8 +239,8 @@ module tb_sha3(); for (i=0; i<50; i=i+1) begin case (i) - 0: tb_wr_data = 32'h00000006; // ...0001 | 10 - block_words-1: tb_wr_data = 32'h80000000; // 1000... + 0: tb_wr_data = 32'h06000000; // ...0001 | 10 + block_words-1: tb_wr_data = 32'h00000080; // 1000... default: tb_wr_data = 32'h00000000; endcase tb_addr = {1'b0, i[5:0]}; // increment address @@ -266,9 +266,7 @@ module tb_sha3(); tb_addr = {1'b1, i[5:0]}; #(CLK_PERIOD); - // swap bytes in the read value - for (j=31; j>0; j=j-8) - hash_word[j-:8] = tb_rd_data[31-j+:8]; + hash_word = tb_rd_data; $display(" *** hash_word[%0d]: reference = %08x, calculated = %08x", i, hash_shreg[511-:32], hash_word); @@ -323,8 +321,8 @@ module tb_sha3(); for (i=0; i<50; i=i+1) begin case (i) - 0: tb_wr_data = 32'h06636261; // ...0001 | 10 | 'cba' - block_words-1: tb_wr_data = 32'h80000000; // 1000... + 0: tb_wr_data = 32'h61626306; // ...0001 | 10 | 'cba' + block_words-1: tb_wr_data = 32'h00000080; // 1000... default: tb_wr_data = 32'h00000000; endcase tb_addr = {1'b0, i[5:0]}; // increment address @@ -350,9 +348,7 @@ module tb_sha3(); tb_addr = {1'b1, i[5:0]}; #(CLK_PERIOD); - // swap bytes in the read value - for (j=31; j>0; j=j-8) - hash_word[j-:8] = tb_rd_data[31-j+:8]; + hash_word = tb_rd_data; $display(" *** hash_word[%0d]: reference = %08x, calculated = %08x", i, hash_shreg[511-:32], hash_word); @@ -440,14 +436,14 @@ module tb_sha3(); total_bits = total_bits - 32; end else if (total_bits == 0) begin // padding - tb_wr_data = 32'h00000006; + tb_wr_data = 32'h06000000; tb_addr = {1'b0, i[5:0]}; tb_we = 1; #(CLK_PERIOD); total_bits = total_bits - 32; end else if (i == (block_words-1)) begin // more padding - tb_wr_data = 32'h80000000; + tb_wr_data = 32'h00000080; tb_addr = {1'b0, i[5:0]}; tb_we = 1; #(CLK_PERIOD); @@ -482,9 +478,7 @@ module tb_sha3(); tb_addr = {1'b1, i[5:0]}; #(CLK_PERIOD); - // swap bytes in the read value - for (j=31; j>0; j=j-8) - hash_word[j-:8] = tb_rd_data[31-j+:8]; + hash_word = tb_rd_data; $display(" *** hash_word[%0d]: reference = %08x, calculated = %08x", i, hash_shreg[511-:32], hash_word); -- cgit v1.2.3