aboutsummaryrefslogtreecommitdiff
path: root/src/rtl/trng_csprng.v
diff options
context:
space:
mode:
Diffstat (limited to 'src/rtl/trng_csprng.v')
-rw-r--r--src/rtl/trng_csprng.v61
1 files changed, 52 insertions, 9 deletions
diff --git a/src/rtl/trng_csprng.v b/src/rtl/trng_csprng.v
index ce5c89c..d33e72a 100644
--- a/src/rtl/trng_csprng.v
+++ b/src/rtl/trng_csprng.v
@@ -49,7 +49,7 @@ module trng_csprng(
output wire error,
input wire discard,
- input test_mode,
+ input wire test_mode,
output wire more_seed,
output wire security_error,
@@ -78,6 +78,7 @@ module trng_csprng(
localparam ADDR_STAT_BLOCKS_LOW = 8'h14;
localparam ADDR_STAT_BLOCKS_HIGH = 8'h15;
+ localparam ADDR_STAT_RESEEDS = 8'h16;
localparam ADDR_RND_DATA = 8'h20;
@@ -103,7 +104,7 @@ module trng_csprng(
localparam ADDR_TEST_SEED_W15 = 8'h8f;
localparam CIPHER_KEYLEN256 = 1'b1; // 256 bit key.
- localparam CIPHER_MAX_BLOCKS = 64'h1000000000000000;
+ localparam CIPHER_MAX_BLOCKS = 64'h0000000100000000;
localparam CTRL_IDLE = 4'h0;
localparam CTRL_SEED0 = 4'h1;
@@ -117,7 +118,7 @@ module trng_csprng(
localparam CTRL_CANCEL = 4'hf;
localparam DEFAULT_NUM_ROUNDS = 5'h18;
- localparam DEFAULT_NUM_BLOCKS = 64'h1000000000000000;
+ localparam DEFAULT_NUM_BLOCKS = 64'h0000000001000000;
parameter CORE_NAME0 = 32'h63737072; // "cspr"
parameter CORE_NAME1 = 32'h6e672020; // "ng "
@@ -152,6 +153,12 @@ module trng_csprng(
reg [63 : 0] block_stat_ctr_reg;
reg [63 : 0] block_stat_ctr_new;
+ reg block_stat_ctr_we;
+
+ reg [31 : 0] reseed_stat_ctr_reg;
+ reg [31 : 0] reseed_stat_ctr_new;
+ reg reseed_stat_ctr_inc;
+ reg reseed_stat_ctr_we;
reg ready_reg;
reg ready_new;
@@ -279,6 +286,7 @@ module trng_csprng(
cipher_block_reg <= {16{32'h00000000}};
block_ctr_reg <= {2{32'h00000000}};
block_stat_ctr_reg <= {2{32'h00000000}};
+ reseed_stat_ctr_reg <= 32'h00000000;
more_seed_reg <= 0;
seed_ack_reg <= 0;
ready_reg <= 0;
@@ -313,9 +321,16 @@ module trng_csprng(
if (block_ctr_we)
begin
block_ctr_reg <= block_ctr_new;
+ end
+
+ if (block_stat_ctr_we)
+ begin
block_stat_ctr_reg <= block_stat_ctr_new;
end
+ if (reseed_stat_ctr_we)
+ reseed_stat_ctr_reg <= reseed_stat_ctr_new;
+
if (ready_we)
ready_reg <= ready_new;
@@ -421,6 +436,9 @@ module trng_csprng(
ADDR_STAT_BLOCKS_HIGH:
tmp_read_data = block_stat_ctr_reg[63 : 32];
+ ADDR_STAT_RESEEDS:
+ tmp_read_data = reseed_stat_ctr_reg;
+
ADDR_RND_DATA:
begin
tmp_read_data = rnd_data;
@@ -453,7 +471,7 @@ module trng_csprng(
// ability to detect that maximum allowed number of blocks
// has been reached. Either as defined by the application
// or the hard coded CIPHER_MAX_BLOCKS value.
-
+ //
// The stat counter is a sepatate block counter updated in
// sync with the block counter. It is only used to track the
// number of blocks generated from the cipher as a metric
@@ -465,6 +483,7 @@ module trng_csprng(
block_ctr_we = 1'b0;
block_ctr_max = 1'b0;
block_stat_ctr_new = {2{32'h00000000}};
+ block_stat_ctr_we = 1'b0;
if (block_ctr_rst)
begin
@@ -475,8 +494,9 @@ module trng_csprng(
if (block_ctr_inc)
begin
block_ctr_new = block_ctr_reg + 1'b1;
- block_stat_ctr_new = block_stat_ctr_reg + 1'b1;
block_ctr_we = 1;
+ block_stat_ctr_new = block_stat_ctr_reg + 1'b1;
+ block_stat_ctr_we = 1;
end
if ((block_ctr_reg == {num_blocks_high_reg, num_blocks_low_reg}) ||
@@ -488,6 +508,27 @@ module trng_csprng(
//----------------------------------------------------------------
+ // reseed_ctr
+ //
+ // A simple monotonically increasing counter that counts the
+ // number of times the CSPRNG has been reseeded. is reseeded.
+ // Note that the counter is 32-bit and it is up to SW to handle
+ // wrap around issues.
+ //----------------------------------------------------------------
+ always @*
+ begin : reseed_ctr
+ reseed_stat_ctr_new = 32'h00000000;
+ reseed_stat_ctr_we = 0;
+
+ if (reseed_stat_ctr_inc)
+ begin
+ reseed_stat_ctr_new = reseed_stat_ctr_reg + 1'b1;
+ reseed_stat_ctr_we = 1;
+ end
+ end // reseed_ctr
+
+
+ //----------------------------------------------------------------
// csprng_ctrl_fsm
//
// Control FSM for the CSPRNG.
@@ -512,6 +553,7 @@ module trng_csprng(
more_seed_new = 0;
fifo_discard = 0;
fifo_cipher_data_valid = 0;
+ reseed_stat_ctr_inc = 0;
csprng_ctrl_new = CTRL_IDLE;
csprng_ctrl_we = 0;
@@ -597,10 +639,11 @@ module trng_csprng(
end
else
begin
- cipher_init = 1;
- block_ctr_rst = 1;
- csprng_ctrl_new = CTRL_INIT1;
- csprng_ctrl_we = 1;
+ reseed_stat_ctr_inc = 1;
+ cipher_init = 1;
+ block_ctr_rst = 1;
+ csprng_ctrl_new = CTRL_INIT1;
+ csprng_ctrl_we = 1;
end
end