4

I am not exactly sure if this is for math stackexchange or crypto:

A TRNG outputs numbers in $[0,1]$ in a Gaussian distribution. I would like to convert them into uniform random bytes ($[0,255] $) to perform byte operations. What is s cryptographically secure method of doing this?

Here is an example distribution from my generator before normalized between $[0,1]$: enter image description here

Edit:

Output from my original methodology: Normalize values to to be within $[0,1]$, remove first and second decimal place via $x*100-floor(x*100)$, then put between value discrete values in $[0,255]$ via $floor(x*255)$. The resulting distribution is as follows: enter image description here

Mike Edward Moras
  • 18,161
  • 12
  • 87
  • 240
dylan7
  • 551
  • 4
  • 10

2 Answers2

3

There is no such thing like a Gaussian distribution over [0,1]; this doesn't make any sense. So it is not clear what you have to begin with.

However, if you have independent random values, you can generate a random bit by taking two values A and B and comparing them. E.g., if $A<B$ you set the bit to 0, otherwise you set the bit to 1. A sequence of 8 such bits is then a (uniformly distributed) random byte.

PS: As correctly mentionned by Ilmari Karonen, if you have a non-negligible probability to have A=B, you have to check for this and if it happens you have to discard A and B.

Chris
  • 1,029
  • 7
  • 17
1

Depending on the parameters of the Gaussian, every $X_i$ byte will have some entropy < 8 bits. So you cannot produce cryptographically random bytes from each of them, unless you add some entropy from another source.

You can, however, turn them into smaller values. For example, if they have at least 1 bit of entropy, you can turn them into bits. Like if the distribution had a peak at 127.5, you could just map everything smaller than that to 0 and larger to 1. Since the transform is not an injection, it's non-invertible. The resulting output is uniformly random and independent.

Or you can use a secret key and a one way transform to produce an output byte stream, like the first byte of $H(K||X_i||i)$ for some hash function $H$. But the $X_i$ aren't really doing a whole lot in that case – you could be using just $H(K||i)$.

otus
  • 32,462
  • 5
  • 75
  • 167