Module 3
Module 3
TRNG
true random number generator
takes as input a source that is effectively random, the source is often referred to as an
entropy source.
TRNG may simply involve conversion of an analog source to a binary output.
Principles of Pseudorandom Number
Generation
PRNG
PRNG takes as input a fixed value, called the seed, and produces a sequence of output
bits using a deterministic algorithm.
output bit stream is determined solely by the input value or values.
Pseudorandom number generator: An algorithm that is used to produce an open-ended
sequence of bits is referred to as a PRNG.
Pseudorandom function (PRF)
A PRF is used to produce a pseudorandom string of bits of some fixed length. Ex-
symmetric encryption keys, nonces.
the PRF takes as input a seed plus some context specific values, such as a user ID or
an application ID.
Other than the number of bits produced, there is no difference between a PRNG and a
PRF.
Principles of Pseudorandom Number
Generation
Principles of Pseudorandom Number
Generation
PRNG Requirements
RANDOMNESS
1. Uniformity
2. Scalability
3. Consistency
UNPREDICTABILITY
1. forward & backward unpredictability
2. use same tests to check
CHARACTERISTICS OF THE SEED
1. secure
2. if known adversary can determine output
3. must be random or pseudorandom number
Principles of Pseudorandom Number
Generation
Principles of Pseudorandom Number
Generation
Algorithm Design
Two categories:
1. Purpose-built algorithms: These are algorithms designed specifically and solely for
the purpose of generating pseudorandom bit streams.
2. Algorithms based on existing cryptographic algorithms: Cryptographic algorithms
have the effect of randomizing input.
Three categories of cryptographic algorithms are used to create PRNGs:
1. Symmetric block ciphers
2. Asymmetric ciphers
3. Hash functions and message authentication codes
Pseudorandom Number Generators
Linear Congruential Generators
Proposed by Lehmer.
The algorithm is parameterized with four numbers:
m the modulus m>0
a the multiplier 0<a<m
c the increment 0<=c<m
X0 the starting value, or seed 0<=X 0<m
The sequence of random numbers {Xn} is obtained via iterative equation:
Xn+1 = (aXn + c)mod m
If m, a, c and X0 are integers, then this technique will produce a sequence of integers with
each integer in the range 0<=Xn<m.
Pseudorandom Number Generators
Blum Blum Shub Generator
Based on public key algorithms
procedure is:
choose two large prime numbers, p and q, that both have a remainder of 3 when
divided by 4.
That is,
the BBS generator produces a sequence of bits according to the following algorithm:
Pseudorandom Number Generators
Two numbers a, b are relatively prime if have no common divisors apart from 1.
eg. 8 & 15 are relatively prime since factors of 8 are 1,2,4,8 and of 15 are 1,3,5,15 and
1 is the only common factor.
Can determine the greatest common divisor (GCD) by comparing their prime
factorizations and using least powers.
eg. 300 = 21 x 31 x 52 18 = 21 x 32 hence
GCD(18,300) = 21 x 31 x 50 = 6
Fermat's Theorem
Two theorems that play important role in public-key cryptography:
1. Fermat’s theorem and
2. Euler’s theorem.
Fermat's Theorem
ap-1 = 1 (mod p)
where p is prime and gcd(a,p)=1
Fermat's Theorem
The first form of the theorem requires that a be relatively prime to p, but this form does
not.
Euler’s Totient Function ((n))
Suppose m1, … , mk are pairwise relatively prime positive integers, and suppose a 1 , … , ak
are integers.
Then the system of k congruences x = ai (mod mi) (1 ≤ i ≤ k) has a unique solution modulo
M = m1 x . . . . x mk, which is given by
Steps to follow:
1. Find M = m1 × m2 × … × mk. This is the common modulus.
2. Find M1 = M/m1, M2 = M/m2, …, Mk = M/mk.
3. Find the multiplicative inverse of M1, M2, …, Mk using the corresponding moduli
(m1, m2, …, mk). Call the inverses M1−1, M2−1, …, Mk −1.
4. The solution to the simultaneous equations is
The Chinese Remainder Theorem
(Example)
Find the solution to the simultaneous equations:
Solution-
We follow the four steps.
1. M = 3 × 5 × 7 = 105
2. M1 = 105 / 3 = 35, M2 = 105 / 5 = 21, M3 = 105 / 7 = 15
3. The inverses are M1−1 = 2, M2−1 = 1, M3−1 = 1
4. x = (2 × 35 × 2 + 3 × 21 × 1 + 2 × 15 × 1) mod 105 = ???
Stream Ciphers
A key is input to a pseudorandom bit generator that produces a stream of 8-bit numbers.
The output of the generator, called a keystream, is combined one byte at a time with the
plaintext stream using the bitwise exclusive-OR (XOR) operation.
RC4 is a stream cipher designed in 1987 by Ron Rivest for RSA Security.
variable key size, byte-oriented stream cipher
widely used (web SSL/TLS, wireless WEP/WPA)
key forms random permutation of all 8-bit values
uses that permutation to scramble input info processed a byte at a time
Initialization of S
for i = 0 to 255 do
S[i] = i;
T[i] = K[i mod keylen];
RC4
Use T to produce the initial permutation of S
j = 0;
for i = 0 to 255 do
j = (j + S[i] + T[i]) mod 256;
Swap (S[i], S[j]);
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];
To encrypt, XOR the value with the next byte of plaintext. To decrypt, XOR the value with
the next byte of ciphertext.
RC4
Strength of RC4
Private-Key Cryptography
traditional private/secret/single key cryptography uses one key
shared by both sender and receiver
if this key is disclosed communications are compromised
also is symmetric, parties are equal
hence does not protect sender from receiver forging a message & claiming is sent by
sender.
Principles of Public Key cryptosystems
Public-Key Cryptography
probably most significant advance in the 3000 year history of cryptography
uses two keys – a public & a private key
asymmetric since parties are not equal
uses clever application of number theoretic concepts to function
complements rather than replaces private key crypto.
Principles of Public Key cryptosystems
public invention due to Whitfield Diffie & Martin Hellman at Stanford University in
1976
known earlier in classified community
Principles of Public Key cryptosystems
Public-Key Characteristics
Public-Key algorithms rely on two keys with the characteristics that it is:
computationally infeasible to find decryption key knowing only algorithm &
encryption key
computationally easy to en/decrypt messages when the relevant (en/decrypt) key
is known
either of the two related keys can be used for encryption, with the other used for
decryption (in some schemes)
Principles of Public Key cryptosystems
Public-Key Applications
can classify uses into 3 categories:
encryption/decryption (provide secrecy)
digital signatures (provide authentication)
key exchange (of session keys)
some algorithms are suitable for all uses, others are specific to one.
Applications :
Principles of Public Key cryptosystems
RSA Key Setup: each user generates a public/private key pair by:
selecting two large primes at random: p, q.
computing their system modulus N = p × q
note φ(N)=(p-1)×(q-1)
selecting at random the encryption key e
where 1<e<φ(N), gcd(e, φ(N)) = 1
solve following equation to find decryption key d
e*d=1 mod φ(N) and 0≤d≤N
publish their public encryption key: KU={e,N}
keep secret private decryption key: KR={d,p,q}.
The RSA Algorithm
RSA Use
to encrypt a message M the sender:
obtains public key of recipient KU={e,N}
computes: C = Me mod N, where 0≤M<N
to decrypt the ciphertext C the owner:
uses their private key KR={d,p,q}
computes: M = Cd mod N
the message M must be smaller than the modulus N (block if needed)
The RSA Algorithm
Brief summary of RSA
The RSA Algorithm (Example)
Timing Attacks
developed in mid-1990’s
exploit timing variations in operations
eg. multiplying by small vs large number
infer operand size based on time taken
RSA exploits time taken in exponentiation
Countermeasures
use constant exponentiation time
add random delays
blind values used in calculations
Diffie-Hellman Key Exchange
The purpose of the algorithm is to enable two users to securely exchange a key that can
then be used for subsequent encryption of messages. The algorithm itself is limited to the
exchange of secret values.
Diffie-Hellman Key Exchange
Two publicly known numbers: a prime number q and an integer α that is a primitive root
of q.
Each user (eg. A) generates their key:
chooses a secret key (number): XA < q
compute their public key: YA= aXA mod q
Similarly, B also generates the keys.
Each side keeps the X value private and makes the Y value available publicly to the other
side.
User A computes the key as, K = (YB)XA mod q
User B computes the key as, K = (YA)XB mod q
Diffie-Hellman Key Exchange
Suppose Alice and Bob wish to exchange keys, and Darth is the adversary.
The attack proceeds as follows:
Darth prepares for the attack by generating two random private keys X D1 and XD2 and then
computing the corresponding public keys Y D1 and YD2.
Alice transmits YA to Bob.
Darth intercepts YA and transmits YD1 to Bob. Darth also calculates
K2 = (YA)XD2 mod q
Bob receives YD1 and calculates K1 = (YD1)XB mod q
Bob transmits YB to Alice
Darth intercepts YB and transmits YD2 to Alice. Darth calculates
K1 = (YB)XD1 mod q
Alice receives YD2 and calculates K2 = (YD2)XA mod q
Man-in-the-Middle Attack
Bob and Alice think that they share a secret key, but instead Bob and Darth share secret
key K1 and Alice and Darth share secret key K2.
All future communication between Bob and Alice is compromised in the following way:
Alice sends an encrypted message M : E(K2, M)
Darth intercepts the encrypted message and decrypts it to recover
Darth sends Bob E(K1, M) or E(K1, M’), where M’ is any message.
In the first case, Darth simply wants to eavesdrop on the communication without
altering it.
In the second case, Darth wants to modify the message going to Bob.
The key exchange protocol is vulnerable to such an attack because it does not authenticate
the participants.
This vulnerability can be overcome with the use of digital signatures and public-key
certificates.
Elliptic Curve Cryptography
Elliptic curve cryptography uses curves whose variables & coefficients are finite
have two families commonly used:
prime curves Ep(a,b) defined over Zp
use integers modulo a prime
best in software
binary curves E2m(a,b) defined over GF(2n)
use polynomials with binary coefficients
best in hardware
Elliptic Curve Cryptography