2
$\begingroup$
tr -dc 0-9 < /dev/urandom | fold -w 3 | awk '$0>=100 && $0<=200' 

What this line does:

  • /dev/urandom (Linux) is proven to be a CSPRNG, that is not a question
  • the "tr -dc 0-9 < /dev/urandom | fold -w 3" outputs 3 digit long numbers from /dev/urandom, ex.: 630, 418, 037, 992, 186, etc.

The question: we need numbers only in an interval, but we need those numbers to be cryptographically secure pseudo random numbers. We use the following: awk '$0>=100 && $0<=200' to only allow numbers (x) inside a given interval (100 <= x <= 200). Are these numbers (limited due to the interval) still considered as cryptographically secure pseudo random numbers?

$\endgroup$
5
  • $\begingroup$ There is an important thing to note here: /dev/urandom outputs random bytes, and you then use tr to delete (tr -d, delete) all characters in this output, except (-c, use complementary set) for the digits 0 through 9. So on average, assuming that your system uses UTF-8 (where those digits are represented by a single byte each), you are throwing away all but 10/256 of the bytes read, resulting in actually further processing only 3.9% of /dev/urandom's output. I don't know if this changes its security properties in any way, but suspect that it makes predicting the PRNG output harder. $\endgroup$ Commented Feb 7, 2017 at 12:24
  • $\begingroup$ Yes, a hard question, that's why we are trying to ask the community about it, maybe someone with a much greater knowledge about the topic could have a hint that these numbers, that are limited to given interval are truly STILL are CSPRN. Thanks for the addition about the "tr" command. $\endgroup$ Commented Feb 7, 2017 at 12:48
  • 1
    $\begingroup$ If you assume the original function to be a PRG: Yes it is, and it's quite easy to prove (assume an attacker for your scheme, and build an attacker for the original PRG from that). However, your solution is not exactly efficient (in the practical sense). You seem to throw away a lot of the output of the CSPRNG, which you could use instead: For some (long) output, repeatedly do integer division by $101$, and use the remainders of those divisions for your list after adding the offset $100$. $\endgroup$ Commented Feb 7, 2017 at 12:55
  • $\begingroup$ "integer division by 101, and use the remainders of those divisions for your list after adding the offset 100" - can you please explain this with little more detailed? $\endgroup$ Commented Feb 7, 2017 at 17:33
  • $\begingroup$ @PeterBill /dev/urandom outputs bytes (which can be treated as integer values in the range $[0,255]$: 0 through 255 inclusive). Call one such byte value when treated as an integer $c$. Now compute the remainder of the integer division $\frac{c}{101}$ (also known as $c$ modulo 101) -- this transforms the value to one in the range $[0,100]$, because the remainder of an integer division will always be 0 through one less than the divisor. Add 100 to the remainder of the division to bring the total ($100 + [0,100]$) to your desired range $[100,200]$. Clear enough? You can use >1 byte at a time. $\endgroup$ Commented Feb 7, 2017 at 21:03

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.