aboutsummaryrefslogtreecommitdiff
path: root/src/rtl/sha256.v
diff options
context:
space:
mode:
authorJoachim StroĢˆmbergson <joachim@secworks.se>2016-05-31 14:00:00 +0200
committerJoachim StroĢˆmbergson <joachim@secworks.se>2016-05-31 14:00:00 +0200
commitdc47fffe47a1fc49ad79e4201f219c8a697b7ae5 (patch)
tree581058cea1d58978871636e66e48787f545e38cc /src/rtl/sha256.v
parent0e90cfa1f076b8660610dfd3930ef1b37a1fb41e (diff)
Adding functionality to support both SHA224 and SHA256 digest modes. Note: This update changes the ADDR_CTRL API register since it adds a mode bit. The version major number has been bumped to reflect this API change. The top level testbench contains tests for SHA224 as well as old tests for SHA256. The core level tb still only tests SHA256.
Diffstat (limited to 'src/rtl/sha256.v')
-rw-r--r--src/rtl/sha256.v23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/rtl/sha256.v b/src/rtl/sha256.v
index 1f9e75e..17fcd84 100644
--- a/src/rtl/sha256.v
+++ b/src/rtl/sha256.v
@@ -64,6 +64,7 @@ module sha256(
localparam ADDR_CTRL = 8'h08;
localparam CTRL_INIT_BIT = 0;
localparam CTRL_NEXT_BIT = 1;
+ localparam CTRL_MODE_BIT = 2;
localparam ADDR_STATUS = 8'h09;
localparam STATUS_READY_BIT = 0;
@@ -97,7 +98,10 @@ module sha256(
localparam CORE_NAME0 = 32'h73686132; // "sha2"
localparam CORE_NAME1 = 32'h2d323536; // "-256"
- localparam CORE_VERSION = 32'h302e3831; // "0.81"
+ localparam CORE_VERSION = 32'h312e3830; // "1.80"
+
+ localparam MODE_SHA_224 = 1'h0;
+ localparam MODE_SHA_256 = 1'h1;
//----------------------------------------------------------------
@@ -113,6 +117,10 @@ module sha256(
reg next_we;
reg next_set;
+ reg mode_reg;
+ reg mode_new;
+ reg mode_we;
+
reg ready_reg;
reg [31 : 0] block0_reg;
@@ -201,6 +209,7 @@ module sha256(
.init(core_init),
.next(core_next),
+ .mode(mode_reg),
.block(core_block),
@@ -235,6 +244,7 @@ module sha256(
begin
init_reg <= 0;
next_reg <= 0;
+ mode_reg <= MODE_SHA_256;
ready_reg <= 0;
digest_reg <= 256'h0;
digest_valid_reg <= 0;
@@ -270,6 +280,9 @@ module sha256(
next_reg <= next_new;
end
+ if (mode_we)
+ mode_reg <= mode_new;
+
if (core_digest_valid)
begin
digest_reg <= core_digest;
@@ -405,6 +418,8 @@ module sha256(
begin : api_logic
init_set = 0;
next_set = 0;
+ mode_new = 0;
+ mode_we = 0;
block0_we = 0;
block1_we = 0;
block2_we = 0;
@@ -443,6 +458,8 @@ module sha256(
begin
init_set = write_data[CTRL_INIT_BIT];
next_set = write_data[CTRL_NEXT_BIT];
+ mode_new = write_data[CTRL_MODE_BIT];
+ mode_we = 1;
end
ADDR_BLOCK0:
@@ -538,10 +555,10 @@ module sha256(
tmp_read_data = CORE_VERSION;
ADDR_CTRL:
- tmp_read_data = {28'h0000000, 2'b00, next_reg, init_reg};
+ tmp_read_data = {29'h0, mode_reg, next_reg, init_reg};
ADDR_STATUS:
- tmp_read_data = {28'h0000000, 2'b00, digest_valid_reg, ready_reg};
+ tmp_read_data = {30'h0, digest_valid_reg, ready_reg};
ADDR_BLOCK0:
tmp_read_data = block0_reg;