Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Test Bench Required- Verilog Code for True Random Number Generator

Yukta2007

Junior Member level 3
Joined
Sep 13, 2020
Messages
30
Helped
1
Reputation
2
Reaction score
0
Trophy points
6
Activity points
156
Hello
I have been working on a simulation implementation of ring oscillator based TRNG(True Random Number Generator)
Can someone help me with the test bench of the code and if possible, explain the code.
It would be of immense help
Thank you.
The code is as follows

Code:
module ringosc (clkout);

output clkout;
parameter NUMGATES = 3;

   (* keep="true" *)

wire [NUMGATES-1:0] patch;

generate
genvar i;
for (i = 0; i < NUMGATES-1; i = i + 1)
begin: for_gates
(* keep="true" *)
assign patch[i+1] = ~patch;
end
endgenerate


(* keep="true" *)
   assign patch[0] = ~patch[NUMGATES-1];
   // Plain output

  assign clkout = patch[0];

endmodule

module trng_wrapper (clk, resetn, random_num);
input clk;
input resetn;
output reg [127:0] random_num;
parameter NUMRO_TRNG = 10;

wire random_bit;
wire [NUMRO_TRNG-1:0] ind_ro_output;

always @ (posedge clk or negedge resetn)
if (!resetn)
random_num <= 128'h0;
else
       random_num <= {random_num[126:0], random_bit};


generate
genvar i;
for (i = 0; i < NUMRO_TRNG; i = i + 1)
begin: Ring_Osc
ringosc RO (ind_ro_output);
end
endgenerate

assign random_bit = ^ind_ro_output;
endmodule
 
Last edited by a moderator:

dick_freebird

Advanced Member level 5
Joined
Mar 4, 2008
Messages
7,281
Helped
2,126
Reputation
4,257
Reaction score
1,983
Trophy points
1,393
Location
USA
Activity points
58,399
"True" randomness is difficult to attain and to
prove at test.

A ring oscillator has a good amount of determinism
in its startup and frequency and you might have
to randomize, or assert as a condition some
randomization of the read-event to ensure it
does not have cyclic behaviors (as beat
frequency or any injection-locking might induce).

Test involved accumulating a very large number
of "random_word" samples and performing some
statistical analysis on the population.

Thing is, if you run the same logic simulation
over and over, you get the same result. Some
randomicity has to be injected, but what I've
seen is that simulators only offer pseudorandom
functions (some, not random at all in that if you
specify the same seed, you receive the exact
same sequence of "random" numbers whether
it's tight now or ten years from now).

As far as the code, no idea. This is just observations
from long ago when my then-employer was
developing "randomizer" chips for the spooks
at NSA.
 

LaTeX Commands Quick-Menu:

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top