Random Bit Generation and Stream Ciphers
Random Bit Generation and Stream Ciphers
generation
• Stream Ciphers
• RC4
PRINCIPLES OF
PSEUDORANDOM NUMBER
GENERATION
• Key Distribution and Authentication
Applications Schemes.
of Random • Session Key Generation
Numbers in • Generation of bit stream for symmetric
Cryptography stream encryption
and N/w • IVs
security • Nonces
• Digital Signatures
• Uniform Distribution
Requirement • Independence
s while • Unpredictability
Generating • Random Number Generator Source
Random • Length of Random Numbers
Numbers • Reproducibility
• Validation
• Pseudorandom RNGs (PRNGs)
Different
• True RNGs (TRNGs)
Types of
Random
• Cryptographically Secure PRNGs
Number (CSPRNGs)
Generators
(RNGs) • Hybrid RNGs (HRNGs)
• Cryptographic systems generally utilize
algorithms to generate random numbers.
• These algorithms operate in a predictable
manner, leading to number sequences that
Pseudorandom lack true randomness.
Numbers • However, a well-designed algorithm can
yield sequences that meet various
randomness criteria.
• The numbers produced by these algorithms
are known as pseudorandom numbers.
TRNGs
TRNGs (Entropy Sources)
• Mouse Movements
• Keystrokes
• Disk Electric Activity
• Instantaneous values of System Clock
• Avalanche Noise
• Magnetic Fluctuations
• Brownian Motion
• Environmental Conditions
PRNGs
• Produce sequences which approximate
the properties of Random Numbers.
• Uses Seed as the initial value which is
fed to a deterministic algorithm.
• Period of the sequence is decided by the
PRNGs deterministic algorithm.
• A good PRNG follows a uniform
distribution.
• Most common deterministic algorithms
are LCG, Mersenne Twister, XorShift,
etc.
• Most common application is Symmetric
Stream Ciphers.
Pseudorandom
Function
(PRF)
Differences between PRNGs and PRF
PRNGs PRF
• Inputs:- Seed • Inputs:- Seed, Context Specific
Value
• Output is predictable if seed is • Output is deterministic, but
known random
• Limited Key Space • Has more Key Space
• Less Secure • More Secure
Purpose of PRNG and PRF Requirements
• Output Secrecy
• Forward Unpredictability
• Backward Unpredictability
• Tests used for Randomness are also used for testing Unpredictability
LCG
Methods to increase unpredictability feature in
(Contd..) LCG:-
• Using an internal system clock to modify the random
number stream.
• Restarting the sequence after every N numbers with
the current clock value (mod m) as the new seed.
• Adding the current clock value to each random
number (mod m) for further unpredictability.
LCG (Numerical 1)
Solution:-
• m = 123; X0 = 73; a = 5; c = 2
Solution:-
• m = 100; X0 = 27; a = 17; c = 43
Solution:-
• m = 8; X0 = 4; a = 5; c = 3
• X1 = (5*X0 + 3) mod 8 = 7
• X2 = (5*X1 + 3) mod 8 = 6
• X3 = (5*X2 + 3) mod 8 = 1
• X4 = (5*X3 + 3) mod 8 = 0
• X5 = (5*X4 + 3) mod 8 = 3
• X6 = (5*X5 + 3) mod 8 = 2
• X7 = (5*X6 + 3) mod 8 = 5
• X8 = (5*X7 + 3) mod 8 = 4
• Period = 8
• Simple to understand and easy to implement
• Efficient
• Limited Memory consumption
• Minimum state information is sufficient to
produce large outputs.
Pros and
Cons of LCG • Poor Randomness Quality
• Usually, LCG has a short period
• Predictability
• Sequential numbers generation
Choose 2 large primes (‘p’ and ‘q’) such that
p≡q≡3(mod 4)
n = p*q
Blum Blum Choose a random number ‘s’ such that GCD(s,n) = 1
Shub Algorithm:-
Generator
(BBSG)
2
X0 = s mod n
for i = 1 to ∞
{
Xi = (Xi−1)2 mod n
Bi = Xi mod 2
}
BBSG
(Contd..)
• BBSG is referred to as a CSPRNG.
• Generate the random bit sequence (first 3 iterations) using BBSG with
following parameters:- 2 primes (7 and 11), and a seed of 12.
Solution:-
• p = 7, q = 11, s = 12
• n = p*q = 7*11 = 77
• X0 = s2 mod n = 122 mod 77 = 67
• X1 = (X0)2 mod n = 23
• B1 = X1 mod 2 = 1
BBSG (Numerical 1) (Contd..)
• X2 = (X1)2 mod n = 67
• B2 = X2 mod 2 = 1
• X3 = (X2)2 mod n = 23
• B3 = X3 mod 2 = 1
• Generate the random bit sequence (first 10 iterations) using BBSG with
following parameters:- 2 primes (31 and 59), and a seed of 45.
Solution:-
• p = 31, q = 59, s = 45
• n = p*q = 1829
• X0 = s2 mod n = 196
• X1 = (X0)2 mod n = 7
• B1 = X1 mod 2 = 1
BBSG (Numerical 2) (Contd..)
• X2 = (X1)2 mod n = 49
• B2 = X2 mod 2 = 1
• Calculate the period of BBSG with following parameters:- 2 primes (103 and
211), and a seed of 100. Also display, the corresponding random bit sequence.
Solution:-
• p = 103, q = 211, s = 100
• n = p*q = 21733
• X0 = s2 mod n = 10000
Two common methods for creating a PNRG use 2 modes: CTR mode and OFB
mode (seed consists of encryption key, and a value V)
on OFB
PRNG based on OFB (Example)
PRNG
based
on CTR
• ‘V’ is incremented by 1 after each
encryption
while (len (temp) < requested_number_of_bits)
{
b
V = (V + 1) mod 2
output_block = E(Key, V)
temp = temp || output_block
PRNG }
based on
CTR
(Algorithm)
PRNG based on CTR (Example)
STREAM CIPHERS
Stream Ciphers
Stream Ciphers
• A stream cipher encrypts data one byte at a time.
• It can also work on one bit at a time or on larger units of bits.
• A key is used as input to a pseudorandom bit generator which
produces 8-bit random output called keystream.
for i = 0 to 255
{
S[i] = i;
T[i] = K[i mod keylen];
}
RC4 (Initial Permutation of S)
j = 0;
for i = 0 to 255
{
j = (j + S[i] + T[i]) mod 256;
Swap (S[i], S[j]);
}
RC4 (Stream Generation)
i, j = 0;
while (true)
{
i = (i + 1) mod 256;
j = (j + S[i]) mod 256;
Swap (S[i], S[j]);
t = (S[i] + S[j]) mod 256;
k = S[t];
}
Strength of RC4
• Attacking RC4 with a strong key (like 128 bits) is not practical.
• The key generation issue mainly affects WEP, not other uses of RC4.