Author Topic: TRNG Tinkering  (Read 1264 times)

0 Members and 1 Guest are viewing this topic.

Offline DabbotTopic starter

  • Regular Contributor
  • *
  • Posts: 198
  • Country: au
TRNG Tinkering
« on: July 08, 2020, 05:10:52 am »
Here's my try at a TRNG. Note this is not for any larger endeavor. I'm merely pulling at the threads of entropy for further understanding.

The majority of the circuit (attached) is an LM324 amplifying it's own noise, which is fed into a basic PIC micro for packaging and shipping. Initially I was simply collecting the LSB from each ADC sample, but it produced a fair amount of bias. I tried a chip with a 10 bit ADC and got similar results.

So I wrote a program which generates each random bit by comparing the ADC sample to a pre-calculated threshold, effectively using the ADC as a comparator. But this on its own is not enough. So the program also keeps track of bias and adjusts a PWM accordingly, giving the noise circuit's virtual ground a very slight nudge until it's about balanced.

The result is a bit stream which still has small localised bias, but tends toward a perfect 50/50 as more is collected. It's also important to note there is no post processing done on the bit stream (whitening / von Neumann etc.). I use a couple of Python scripts to do some very basic analysis on the output (tally bits & hex characters, basic patterns). Nothing approaching the diehard tests, which requires a few GB of sample data and me knowing where to start with them.
 

Offline magic

  • Super Contributor
  • ***
  • Posts: 7571
  • Country: pl
Re: TRNG Tinkering
« Reply #1 on: July 08, 2020, 06:18:35 am »
effectively using the ADC as a comparator
Use one opamp as comparator, lowpass-filter its output to drive the threshold, throw the PIC to trash :P
 

Online RoGeorge

  • Super Contributor
  • ***
  • Posts: 7367
  • Country: ro
Re: TRNG Tinkering
« Reply #2 on: July 08, 2020, 06:18:51 am »
If you need digital noise and have a microcontroller, you can use Von Neumann debiasing algorithm (Von Neumann Extractor) to make sure the ratio between the 0s and 1s is kept 50/50.

From there, by integration you can get any shape you want for a custom probability distribution.

Offline DabbotTopic starter

  • Regular Contributor
  • *
  • Posts: 198
  • Country: au
Re: TRNG Tinkering
« Reply #3 on: July 08, 2020, 06:42:04 am »
Use one opamp as comparator, lowpass-filter its output to drive the threshold, throw the PIC to trash :P

I like your thinking. I'm going to try this.  :D

Edit: No good. The circuit oscillates. Decreasing the gain only causes it to oscillate less vigorously.
« Last Edit: July 08, 2020, 07:57:49 am by Dabbot »
 

Offline magic

  • Super Contributor
  • ***
  • Posts: 7571
  • Country: pl
Re: TRNG Tinkering
« Reply #4 on: July 08, 2020, 02:40:12 pm »
Well, an analog solution has the further disadvantage that you will never get it to output 50/50 unless you get offset voltages perfectly right.

If you want to play with it, be sure to include some hysteresis (positive feedback) in the comparator. The threshold regulator will react immediately to every bit from the comparator (with a slew rate dependent on the RC filter, but with zero delay). To avoid oscillation, the comparator needs to be prevented from reacting to that threshold correction before the analog input signal has a chance of toggling it a few times.

At least that's how I feel about it.
 

Offline DabbotTopic starter

  • Regular Contributor
  • *
  • Posts: 198
  • Country: au
Re: TRNG Tinkering
« Reply #5 on: July 08, 2020, 03:11:14 pm »
Well, an analog solution has the further disadvantage that you will never get it to output 50/50 unless you get offset voltages perfectly right.
I realise that's not going to be possible, but I can always see how close I can get it.

If you want to play with it, be sure to include some hysteresis (positive feedback) in the comparator.
I might give it a try using a separate comparator IC. Having the comparator thrashing about on the same silicon with all that gain present can't be helping either. Any hysteresis will need to be small, given the noise is only roughly 50mv RMS.
 

Offline magic

  • Super Contributor
  • ***
  • Posts: 7571
  • Country: pl
Re: TRNG Tinkering
« Reply #6 on: July 08, 2020, 04:04:53 pm »
I doubt it oscillated due to inter-channel crosstalk. Some amount of hysteresis is necessary IMO, even if it's just 1/1000 of the output.
A real comparator will have the advantage of much faster slew rate. Try TLC3702 or similar with a push-pull output stage (not open collector).

A silly little simulation below. Looks a bit like a delta-sigma ADC but reacting to slope rather than absolute value.
 

Offline DabbotTopic starter

  • Regular Contributor
  • *
  • Posts: 198
  • Country: au
Re: TRNG Tinkering
« Reply #7 on: July 09, 2020, 04:55:52 am »
I just tried an open collector comparator with a 1K resistor (I don't have any push-pull types handy) and got respectable results.
I didn't see any obvious difference by including hysteresis, according to observations on the oscilloscope. This might change once I start sending random samples to the PC.
 

Online RoGeorge

  • Super Contributor
  • ***
  • Posts: 7367
  • Country: ro
Re: TRNG Tinkering
« Reply #8 on: July 09, 2020, 05:49:19 am »
Again, why don't you apply a Von Neumann Debiaser to the ADC bit(s) you said they were unbalanced?

Anyway, if you insist to keep the noise balanced in the analog domain, put a series capacitor.  Also, a revese polarized BE junctions from a bipolar transistor makes a great noise generator, all those OpAmps are not needed.

Offline DabbotTopic starter

  • Regular Contributor
  • *
  • Posts: 198
  • Country: au
Re: TRNG Tinkering
« Reply #9 on: July 09, 2020, 06:34:33 am »
Again, why don't you apply a Von Neumann Debiaser to the ADC bit(s) you said they were unbalanced?
That's part of the challenge. It's easy enough to do debiasing in software, but I wanted to have a good starting point.

Anyway, if you insist to keep the noise balanced in the analog domain, put a series capacitor.
This doesn't treat the ADC's bias.

Also, a revese polarized BE junctions from a bipolar transistor makes a great noise generator, all those OpAmps are not needed.
The reason I came up with this circuit is it will run down to 3 volts. No charge pumps necessary to place BE junctions into avalanche. Besides, all those op amps are very cheap and come in a single package.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf