From 173d61b457da53a4dec607113df76ebd35a56d40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Thu, 20 Aug 2015 15:20:54 +0200 Subject: Adding a stat counter for number of CSPRNG reseeds. --- src/rtl/trng_csprng.v | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file 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 @@ -487,6 +500,27 @@ module trng_csprng( end // block_ctr + //---------------------------------------------------------------- + // 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 // @@ -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 -- cgit v1.2.3