Pseudo Random Bit Generator
Pseudo Random Bit Generator
Generator
Motivation
• It is crucial to security that cryptographic
keys are generated with a truly random
or at least a pseudo-random generation
process
• Otherwise , an attacker might reproduce
the key generation process and easily
find the key used to secure a specific
communication
Motivation
• In cryptography, we are often in a situation
where we need a random integer or a
random sequence of bits.
• For example, secret keys are often required
to be random. But what does that really
mean?
• If we flip a coin eight times and assign 0 to
one of the sides and 1 to the other, then
the sequence 00000000 is just as likely as
the sequence 10011100.
• Still, our intuition tells us that the second
sequence is “more random” than the first
one.
• But actually, humans are quite bad at
consciously creating random sequences –
Random numbers in
•
Cryptography
Random numbers are required in many places
• Producing good random number is difficult
• Generation of pseudo-random numbers is required in
cryptographic protocols for the generation of
• Example 1: One time pad
– Create a pad using random numbers
• Example 2: Initialization vectors
– Required for example by Cipher block Chaining
mode
• Example 3: Session Key
– Create a shared secret for a communication
session
– Cryptographic keys
– Nonce's
• Example usages
– Authentication with challenge-response mechanism,
e.g. GSM (Group SpécialeMobile), and UMTS
(Universal Mobile Telecommunications System )
authentication
Randomness Definition
• Chaitin-Kolmogorov randomness (also called algorithmic
randomness)
– a string of bits is random if and only if it is shorter than any
computer program that can produce that string
• this basically means that random strings are those that
cannot be compressed.
• Consider the following two strings of length 64, each
containing only lowercase letters, numbers, and spaces:
• abababababababababababababababababababababababab
abababababababab
4c1j5b2p0cv4w1x8rx2y39umgw5q85s7uraqbjfdppa0q7ni
eieqe9noc4cvafzf The
• first string has a short English-language description, namely
"ab 32 times", which consists of 11 characters. The
second one has no obvious simple description (using the
same character set) other than writing down the string
itself, which has 64 characters.
•
• Statistical Randomness
Inherent non-
randomness
• Because any PRNG run on a deterministic
computer (contrast quantum computer) is
deterministic, its output will inevitably have
certain properties that a true random sequence
would not exhibit.
– guaranteed periodicity—it is certain that if the
generator uses only a fixed amount of memory
then, given a sufficient number of iterations, the
generator will revisit the same internal state twice,
after which it will repeat forever. A generator that
isn't periodic can be designed, but its memory
requirements would grow as it ran. In addition, a
PRNG can be started from an arbitrary starting
point, or seed state, and will always produce an
identical sequence from that point on.
cont
– In practice, many PRNGs exhibit
artifacts which can cause them to
fail statistically significant tests.
These include, but are certainly not
limited to:
• Shorter than expected periods for
some seed states (not full period)
• Poor dimensional distribution
• Successive values are not independent
• Some bits may be 'more random' than
others
• Lack of uniformity
Random bits
• A sequence of random bits is a sequence where
the bits are independent from each other and
uniformly distributed.
• Random bits can be generated in may different
ways.
• As it turns out, most of these ways are rather
slow and/or expensive.
• Random-bit generators can be based on hardware
or on software.
• For hardware, you could use things like the time
elapsed between emission of particles during
radioactive decay, sounds from different
sources, air turbulence within a disk drive
causing random fluctuations in disk drive sector
read latency times or any other phenomena
• For software, you could use time, some kind of user input
(though having a human type 1’s and 0’s will most likely
not yield a good result,) or the system environment.
• Most likely, none of these methods will give us a uniform
distribution of 1’s and 0’s, but it can be solved by simple
de-skewing techniques.
• For example, you can look at pairs of bits, throw them
away if both bits are the same, and keep the first bit if
they are different.
• Of course, this means you have to produce at least 4 times
as many bits as you will need.
• Combining any number of these methods (as long as they
are independent) should yield results that are as least as
good as the best of the methods.
• There are different ways to accomplish this, a (possibly too)
simple method is to just XOR the results. A better
method would be to use some kind of hash-function on a
concatenation of the results.
Random number,
Pseudorandom
• The outputs of pseudorandom
number generators are not truly
random
– they only approximate some of the
properties of random numbers.
– "Anyone who considers arithmetical
methods of producing random digits
is, of course, in a state of sin.”---
John von Neumann
– Truely random numbers can be
generated using hardware random
Pseudo-random bits
• A way to save a lot of time is to use a pseudo-
random bit generator (PRBG). This is an
algorithm that takes a relatively small number
of random bits (length k) as input, and outputs a
longer sequence (length l) of bits, that appears
to be random.
• These algorithms are deterministic, that means
that they will always produce the same output
for a given input.
• The intent is to make the outputs
indistinguishable from truly random bit-strings.
Random Bit Generator
-example
• Example: random.org
• Atmospheric noise
• You just need – microphone,
soundcard, frequency where
nobody is broadcasting
• Sample at 8kHz
• Discard the upper bits
• Create a stream using the lower bits
•
Construction of PRG’s
• Theorem: Suppose there is a one
way permutation, then there is a
PRG with arbitrary polynomial
expansion.
• Need the following ideas:
– One way function
– One way permutation
– Hard core bit
Pseudo Random Number
Generator (PRNG)
following properties:
1. The length k of the seed (the input to the
function) should be large enough, so that an
adversary cannot simply run through all
possibilities
2. The output sequences should be statistically
indistinguishable from random sequences
3. The output bits should be unpredictable to an
adversary with limited resources
next-bit test
• The next-bit test (for condition 3):
• A PRBG is said to pass the next-bit
test if there is no polynomial-time
algorithm that given bits 0 to m-1
of an output sequence can predict
bit m with probability significantly
higher than 50%.
• A PRBG passing the next-bit test is
called cryptographically secure
(CSPRBG.)
For condition 2
• A random sequence is assumed to have certain
properties. These properties should appear in
pseudo-random sequence as well.
• Some of these are mentioned in Golomb's randomness
postulates.
• For example, the number of 1's and 0's should be
about the same, the bits should not depend on each
other, and so on.
• There are tests for each of these properties.
• Failing one of these tests indicates non-randomness.
• Of course, passing one of these tests does not
guarantee randomness – in fact, even passing all of
these tests does not guarantee randomness.
• Each test just makes it more and more unlikely that a
sequence is non-random.
Five tests for PRBG
• We will now present five tests that are
often used in testing PRBG's.
• They all test the hypothesis that the
sequence was generated by a random
number generator, with a significance
level of 5%.
• That means, that sequences actually
produced with a random number
generator are rejected with a
probability of 5%.
• This may seem like a lot, but it also
makes it more unlikely that we will
accept sequences that do not possess
Frequency test
• The purpose of this test is to see if
there are about as many 1's as 0's.
•n: the number of bits,
DT
EDE
EDE
Si+1
Si
EDE
Ri
Linear Congruential
Generator
• Protocol
– Let M be an integer and a, b less
than M
– Let k be number of bits of M
– Integer l is between k+1 and M-1
– Let s0 be a seed less than M
– Define si=asi-1 +b mod M
– Then the ith random bit is si mod 2
– It is not proved to be secure
Parameter Setting
• Not all a, b are good and m should be
large
• For example, m is a large prime
number
• For fast computation, usually m=231 -
1
– And b is set to 0 often
• For this m, there are less than 100
integers a
– It generates all numbers less than m
– The generated sequences appear to
RSA Generator
• Protocol
– Let p, q be two k/2 bits primes and
define n=pq
– Integer b: gcd(b, (n))=1
– Public: n, b; Private p,q
– A seed s0 with k bits
– Sequence si+1 =sib mod n
– Then the ith random bit is si mod 2
– It is proved to be secure!
BBS Generator
• Blum-Blum-Shub Generator
– Let p, q be two k/2 bits primes and
define n=pq
– Here p=q=3 mod 4
• this guarantees that each quadratic
residue has one square root which is
also a quadratic residue
– gcd(φ(p-1), φ(q-1)) should be small
• this makes the cycle length large.
– Let QR(n) be all quadratic residues
modulo n
– Public: n; Private p,q
– A seed s0 with k bits from QR(n)
– Sequence si+1 =si2 mod n
Cont on BBS
• Provably “secure”
– When the primes are chosen
appropriately,
– and O(log log n) bits of each Si are
output,
– then in the limit as n grows large,
distinguishing the output bits from
random will be at least as difficult as
factoring n.
• However,
– it's theoretically possible that a fast
algorithm for factoring will someday
Discrete Logarithm
Generator
• Protocol
– Let p be a k-bit prime,
– Let be primitive element modulo
p
– A seed s0 is any non-zero integer
less than p
– Define si+1 = si mod p
– Then the ith random bit is
• 1 if si is larger than p/2
• 0 if si is less than p/2
Standards
• A number of designs of CSPRNGs
have been standardized. They can
be found in:
– FIPS 186-2
– ANSI X9.17-1985 Appendix C
– ANSI X9.31-1998 Appendix A.2.4
– ANSI X9.62-1998 Annex A.4
•