ECEG-6530 Computer (And Network) Security: RSA, Generating Random Numbers, EL Gamal Encryption, Hybrid Encryption
ECEG-6530 Computer (And Network) Security: RSA, Generating Random Numbers, EL Gamal Encryption, Hybrid Encryption
ECEG-6530 Computer (And Network) Security: RSA, Generating Random Numbers, EL Gamal Encryption, Hybrid Encryption
1
Random Number Generation
Random numbers play an important role in the use of
encryption for various network security applications. In
this section, we provide a brief overview of the use of
random numbers in network security and then look at
some approaches to generating random numbers.
2
The Use of Random Numbers
A number of network security algorithms based on cryptography make
use of random numbers. For example,
•Reciprocal authentication schemes, In both of these key distribution
scenarios, nonces are used for handshaking to prevent replay attacks.
The use of random numbers for the nonces frustrates opponents' efforts
to determine or guess the nonce.
•Session key generation, whether done by a key distribution center or
by one of the principals.
•Generation of keys for the RSA public-key encryption algorithm
3
Introduction to Number Theory
Divisors
– b|a if a=mb for an integer m
– b|a and c|b then c|a
– b|g and b|h then b|(mg+nh) for any integer m,n
Prime number
– P has only positive divisors 1 and p
Relatively prime numbers
– No common divisors for p and q except 1
4
Prime numbers
Upto 200
– 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181
191 193 197 199
Largest known so far (till 2008, Jan 22)
– 232582657-1 with 9808358 digits (found 2006 using proof code G9)
– When 2n-1is prime it is said to be a Mersenne prime (a French monk
1588-1648, conjecture 1644). Clearly n must be odd.
How many prime numbers are there?
– Infinity ---- Euclid gave simple proof
• Proof by contradiction
• They were also irregularly placed (arbitrary gap)
– How many in the range [0,n] -- Theta( n / log n)
• Approximately, the nth prime n log n
– How many primes with d bits approximately? ~ Theta(2d/d)
5
Determining Primes?
How to determine if a given number n is prime?
– Deterministic Brute force testing
• Testing whether a number a | n, for a in certain range
– Random testing
• A prime number should satisfy some properties
• If a number x does NOT have any of such properties, then this
x is NOT a prime
– Otherwise, it may be a prime number
6
Is that number prime?
Use the Fermat primality test
Given:
– n: the number to test for primality
– k: the number of times to test (the certainty)
The algorithm is:
repeat k times:
pick a randomly in the range [1, n−1]
if an−1 mod n ≠ 1 then return composite
return probably prime
7
Is that number prime?
The algorithm is:
repeat k times:
pick a randomly in the range [1, n−1]
if an−1 mod n ≠ 1 then return composite
return probably prime
Let n = 105
– Iteration 1: a = 92: 92104 mod 105 = 1
– Iteration 2: a = 84: 84104 mod 105 = 21
– Therefore, 105 is composite
8
Is that number prime?
The algorithm is:
repeat k times:
pick a randomly in the range [1, n−1]
if an−1 mod n ≠ 1 then return composite
return probably prime
Let n = 101
– Iteration 1: a = 55: 55100 mod 100 = 1
– Iteration 2: a = 60: 60100 mod 100 = 1
– Iteration 3: a = 14: 14100 mod 100 = 1
– Iteration 4: a = 73: 73100 mod 100 = 1
– At this point, 101 has a (½)4 = 1/16 chance of still
being composite
9
RSA
Stands for the inventors: Ron Rivest, Adi
Shamir and Len Adleman
Three parts:
– Key generation
– Encrypting a message
– Decrypting a message
10
Key generation steps
1. Choose two random large prime numbers p ≠ q, and
n = p*q
2. Choose an integer 1 < e < n which is relatively prime
to (p-1)(q-1)
3. Compute d such that d * e ≡ 1 (mod (p-1)(q-1))
– Rephrased: d*e mod (p-1)(q-1) = 1
11
Key generation, step 1
Choose two random large prime numbers p ≠ q
– In reality, 2048 bit numbers are recommended
• That’s 617 digits
12
Key generation, step 1
Java code to find a big prime number:
13
Key generation, step 1
Java code to find a big prime number:
import java.math.*;
import java.util.*;
class BigPrime {
14
Key generation, step 1
How long does this take?
– Keep in mind this is Java!
– These tests done on a 850 Mhz Pentium
machine
– Average of 100 trials (certainty = 100)
– 200 digits (664 bits): about 1.5 seconds
– 617 digits (2048 bits): about 75 seconds
15
Key generation, step 1
Practical considerations
– p and q should not be too close together
– (p-1) and (q-1) should not have small prime
factors
– Use a good random number generator
16
Key generation, step 2
Choose an integer 1 < e < n which is
relatively prime to (p-1)(q-1)
Easy way to do this: make e be a prime
number
– It only has to be relatively prime to (p-1)(q-
1), but can be fully prime
17
Key generation, step 2
Recall that p = 107 and q = 97
– (p-1)(q-1) = 106*96 = 10176 = 26*3*53
We choose e = 85
– 85 = 5*17
– gcd (85, 10176) = 1
– Thus, 85 and 10176 are relatively prime
18
Key generation, step 3
Compute d such that:
d * e ≡ 1 (mod (p-1)(q-1))
– Rephrased: d*e mod (p-1)(q-1) = 1
We choose d = 4669
– 4669*85 mod 10176 = 1
19
Key generation, step 3
Java code to find d:
import java.math.*;
class FindD {
public static void main (String args[]) {
System.out.println (e.modInverse(pq));
}
}
Result: 4669
20
Key generation, step 4
Destroy all records of p and q
d * e ≡ 1 (mod (p-1)(q-1))
21
The keys
We have n = p*q = 10379, e = 85, and
d = 4669
The public key is (n,e) = (10379, 85)
The private key is (n,d) = (10379, 4669)
Thus, n is not private
– Only d is private
In reality, d and e are 600 (or so) digit numbers
– Thus n is a 1200 (or so) digit number
22
Encrypting messages
To encode a message:
1. Encode the message m into a number
2. Split the number into smaller numbers m < n
3. Use the formula c = me mod n
• c is the ciphertext, and m is the message
Java code to do the last step:
– m.modPow (e, n)
– Where the object m is the BigInteger to
encrypt
23
Encrypting messages example
1. Encode the message into a number
– String is “Go Cavaliers!!”
– Modified ASCII codes:
• 41 81 02 37 67 88 67 78 75 71 84 85 03 03
24
Decrypting messages
1. Use the formula m = cd mod n on each
number
2. Split the number into individual ASCII
character numbers
3. Decode the message into a string
25
Decrypting messages example
Encrypted message:
– 4501 2867 4894 0361 3630 4496 6720
Other means:
– Java: use the BigInteger.modPow() method
– Perl: use the bmodpow function in the BigInt library
– Etc…
27
Why this works
m = cd mod n
c = me mod n
30
Signing a message
Recall that we computed
d*e mod (p-1)(q-1) = 1
32
ElGamal
ElGamal
We will also take a look at the ElGamal public key
cipher system for a number of reasons:
34
Setting up ElGamal
Let p be a large prime
– By “large” we mean here a prime rather typical in length to that of
an RSA modulus
y = gx mod p
35
Setting up ElGamal: example
Step 1: Let p = 23
Public key is 9
Private key is 6
36
ElGamal encryption
The first job is to represent the plaintext as a series
of numbers modulo p. Then:
1. Generate a random number k
2. Compute two values C1 and C2, where
37
ElGamal encryption: example
3 - Ciphertext C = (20 , 22 )
38
ElGamal decryption
C1 = gk mod p C2 = Myk mod p
C2 / yk = (Myk) / yk = M mod p
39
ElGamal decryption: example
To decrypt C = (20 , 22 )
2 - Compute 22 / 16 = 10 mod 23
3 - Plaintext = 10
40
Security of ElGamal
Recall the two different strategies for trying
to “break” RSA:
1. Trying to decrypt a ciphertext without
knowledge of the private key
2. Trying to determine the private key
41
ElGamal v RSA
PROS of ElGamal CONS of ElGamal
Does not rely on
Requires a random number
factorisation being hard generator
Message expansion
42
Diffie-Hellman
Diffie-Hellman
The Diffie–Hellman (DH) key exchange technique was first defined
in their seminal paper in 1976.
DH key exchange is a method of exchanging public (i.e. non-secret)
information to obtain a shared secret.
DH is not an encryption algorithm.
44
Principle behind DH
DH key exchange was first proposed before there were any
known public key algorithms, but the idea behind it motivated
the hunt for practical public key algorithms.
DH key exchange is not only a useful and practical key
establishment technique, but also a significant milestone in
the history of modern cryptography.
45
Principle behind DH
Assume that Alice and Bob are the parties who wish to establish a
shared secret, and let their public and private keys in the public
key cipher system be denoted by (PA , SA) and (PB , SB)
respectively.
The basic principle behind Diffie–Hellman key exchange is as
follows:
47
Hybrid Encryption
48
Hybrid Encryption
A hybrid encryption scheme is one that blends the convenience of an asymmetric
encryption scheme with the effectiveness of a symmetric encryption scheme.
Hybrid encryption is achieved through data transfer using unique session keys along
with symmetrical encryption. Public key encryption is implemented for random
symmetric key encryption. The recipient then uses the public key encryption method to
decrypt the symmetric key. Once the symmetric key is recovered, it is then used to
decrypt the message.
The combination of encryption methods has various advantages. One is that a
connection channel is established between two users' sets of equipment. Users then have
the ability to communicate through hybrid encryption. Asymmetric encryption can slow
down the encryption process, but with the simultaneous use of symmetric encryption,
both forms of encryption are enhanced. The result is the added security of the transmittal
process along with overall improved system performance.
49
Summary
Public key systems replace the problem of distributing symmetric keys
with one of authenticating public keys
Public key encryption algorithms need to be trapdoor one-way functions
RSA is a public key encryption algorithm whose security is believed to
be based on the problem of factoring large numbers
ElGamal is a public key encryption algorithm whose security is believed
to be based on the discrete logarithm problem
RSA is generally favoured over ElGamal for practical rather than
security reasons
RSA and ElGamal are less efficient and fast to operate than most
symmetric encryption algorithms because they involve modular
exponentiation
DH key exchange is an important protocol on which many real key
exchange protocols are based
50