aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoachim StroĢˆmbergson <joachim@secworks.se>2015-08-20 15:20:54 +0200
committerJoachim StroĢˆmbergson <joachim@secworks.se>2015-08-20 15:20:54 +0200
commit173d61b457da53a4dec607113df76ebd35a56d40 (patch)
treead2e88f084ca493638be9c0df52778f43c85bd21
parent5557b9dd7f660bddd36b2713ebfe5aa5b4417904 (diff)
Adding a stat counter for number of CSPRNG reseeds.
-rw-r--r--src/rtl/trng_csprng.v46
1 files changed, 41 insertions, 5 deletions
diff --git a/src/rtl/trng_csprng.v b/src/rtl/trng_csprng.v
index ce5c89c..208feb1 100644
--- a/src/rtl/trng_csprng.v
+++ b/src/rtl/trng_csprng.v
@@ -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;
@@ -153,6 +154,11 @@ module trng_csprng(
reg [63 : 0] block_stat_ctr_reg;
reg [63 : 0] block_stat_ctr_new;
+ 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;
reg ready_we;
@@ -279,6 +285,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;
@@ -316,6 +323,9 @@ module trng_csprng(
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 +431,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 +466,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
@@ -488,6 +501,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 +546,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 +632,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