aboutsummaryrefslogtreecommitdiff
path: root/src/rtl
diff options
context:
space:
mode:
Diffstat (limited to 'src/rtl')
-rw-r--r--src/rtl/sha256.v23
-rw-r--r--src/rtl/sha256_core.v101
2 files changed, 89 insertions, 35 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;
diff --git a/src/rtl/sha256_core.v b/src/rtl/sha256_core.v
index 448dfe6..6553aab 100644
--- a/src/rtl/sha256_core.v
+++ b/src/rtl/sha256_core.v
@@ -44,6 +44,7 @@ module sha256_core(
input wire init,
input wire next,
+ input wire mode,
input wire [511 : 0] block,
@@ -68,20 +69,29 @@ module sha256_core(
//----------------------------------------------------------------
// Internal constant and parameter definitions.
//----------------------------------------------------------------
- parameter H0_0 = 32'h6a09e667;
- parameter H0_1 = 32'hbb67ae85;
- parameter H0_2 = 32'h3c6ef372;
- parameter H0_3 = 32'ha54ff53a;
- parameter H0_4 = 32'h510e527f;
- parameter H0_5 = 32'h9b05688c;
- parameter H0_6 = 32'h1f83d9ab;
- parameter H0_7 = 32'h5be0cd19;
-
- parameter SHA256_ROUNDS = 63;
-
- parameter CTRL_IDLE = 0;
- parameter CTRL_ROUNDS = 1;
- parameter CTRL_DONE = 2;
+ localparam SHA224_H0_0 = 32'hc1059ed8;
+ localparam SHA224_H0_1 = 32'h367cd507;
+ localparam SHA224_H0_2 = 32'h3070dd17;
+ localparam SHA224_H0_3 = 32'hf70e5939;
+ localparam SHA224_H0_4 = 32'hffc00b31;
+ localparam SHA224_H0_5 = 32'h68581511;
+ localparam SHA224_H0_6 = 32'h64f98fa7;
+ localparam SHA224_H0_7 = 32'hbefa4fa4;
+
+ localparam SHA256_H0_0 = 32'h6a09e667;
+ localparam SHA256_H0_1 = 32'hbb67ae85;
+ localparam SHA256_H0_2 = 32'h3c6ef372;
+ localparam SHA256_H0_3 = 32'ha54ff53a;
+ localparam SHA256_H0_4 = 32'h510e527f;
+ localparam SHA256_H0_5 = 32'h9b05688c;
+ localparam SHA256_H0_6 = 32'h1f83d9ab;
+ localparam SHA256_H0_7 = 32'h5be0cd19;
+
+ localparam SHA256_ROUNDS = 63;
+
+ localparam CTRL_IDLE = 0;
+ localparam CTRL_ROUNDS = 1;
+ localparam CTRL_DONE = 2;
//----------------------------------------------------------------
@@ -311,15 +321,29 @@ module sha256_core(
if (digest_init)
begin
- H0_new = H0_0;
- H1_new = H0_1;
- H2_new = H0_2;
- H3_new = H0_3;
- H4_new = H0_4;
- H5_new = H0_5;
- H6_new = H0_6;
- H7_new = H0_7;
H_we = 1;
+ if (mode)
+ begin
+ H0_new = SHA256_H0_0;
+ H1_new = SHA256_H0_1;
+ H2_new = SHA256_H0_2;
+ H3_new = SHA256_H0_3;
+ H4_new = SHA256_H0_4;
+ H5_new = SHA256_H0_5;
+ H6_new = SHA256_H0_6;
+ H7_new = SHA256_H0_7;
+ end
+ else
+ begin
+ H0_new = SHA224_H0_0;
+ H1_new = SHA224_H0_1;
+ H2_new = SHA224_H0_2;
+ H3_new = SHA224_H0_3;
+ H4_new = SHA224_H0_4;
+ H5_new = SHA224_H0_5;
+ H6_new = SHA224_H0_6;
+ H7_new = SHA224_H0_7;
+ end
end
if (digest_update)
@@ -397,17 +421,31 @@ module sha256_core(
if (state_init)
begin
+ a_h_we = 1;
if (first_block)
begin
- a_new = H0_0;
- b_new = H0_1;
- c_new = H0_2;
- d_new = H0_3;
- e_new = H0_4;
- f_new = H0_5;
- g_new = H0_6;
- h_new = H0_7;
- a_h_we = 1;
+ if (mode)
+ begin
+ a_new = SHA256_H0_0;
+ b_new = SHA256_H0_1;
+ c_new = SHA256_H0_2;
+ d_new = SHA256_H0_3;
+ e_new = SHA256_H0_4;
+ f_new = SHA256_H0_5;
+ g_new = SHA256_H0_6;
+ h_new = SHA256_H0_7;
+ end
+ else
+ begin
+ a_new = SHA224_H0_0;
+ b_new = SHA224_H0_1;
+ c_new = SHA224_H0_2;
+ d_new = SHA224_H0_3;
+ e_new = SHA224_H0_4;
+ f_new = SHA224_H0_5;
+ g_new = SHA224_H0_6;
+ h_new = SHA224_H0_7;
+ end
end
else
begin
@@ -419,7 +457,6 @@ module sha256_core(
f_new = H5_reg;
g_new = H6_reg;
h_new = H7_reg;
- a_h_we = 1;
end
end