module 4
module 4
7
Public-Key Cryptography: essential steps
1. Each user generates a pair of keys to be used for the encryption
and decryption of messages.
2. Each user places one of the two keys in a public register or other
accessible file. This is the public key. The companion key is kept
private. Each user maintains a collection of public keys obtained
from others.
3. If Bob wishes to send a confidential message to Alice, Bob
encrypts the message using Alice’s public key.
4. When Alice receives the message, she decrypts it using her
private key. No other recipient can decrypt the message because
only Alice knows Alice’s private key.
8
Symmetric vs Public-Key
Public-Key Cryptography
10
Public-Key Cryptosystems
11
Public-Key Cryptosystems
12
Public-Key Cryptosystems:
Authentication and Secrecy
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
Public-Key Requirements
Public-Key algorithms rely on two keys where:
● it is computationally infeasible to find decryption key
knowing only algorithm & encryption key
● it is 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 (for some algorithms)
these are formidable requirements which only a
few algorithms have satisfied
Public-Key Requirements
need a trapdoor one-way function
one-way function has
● Y = f(X) easy
● X = f–1(Y) infeasible
bi 1 1 0 0 0 0 1
c 1 3 6 12 24 48 97
f 3 27 23 176 265 33 40
26
Modular exponentiation column wise computations
64 32 16 8 4 2 1
bi 1 1 0 0 0 0 1
c 1 3 6 12 24 48 97
f 3 27 23 176 265 331 40
• Initially c=0,f=1. Start from MSB i.e. 7th bit of binary (column numerical 64) bi=1,c=c+1=1,
f=1x3=3
• Then compute c=1 x 2=2, f=f x f mod 353= 3 x 3 mod 353 =9
• 6th bit of binary (column numerical 32) bi=1,c=2+1=3, f=9x3=27 mod 353.
• c=6, f=27 x 27 mod 353 =23 next bit =0 update the column with c=6 and f=23
• c=12, f=23 x 23 mod 353 = 176 next bit =0 update the column with c=12 and f=176
• c=24, f=176 x 176 mod 353 =265 next bit =0 update the column with c=24 and f=265
• c=48, f=265 x 265 mod 353 =331 next bit =0 update the column with c=48 and f=331
• c=96 and f=331 x 331 mod 353=131 next bit =1 so
• c=c+1=96+1=97 and f=f x a = 131 x 3 mod 353 =393 mod 353 =40
27
Exponentiation
• Compute modular exponentiation for 7560 mod 561
bi 1 1 1 0 1 0 0 1
c 1 3 7 14 29 58 116 233
f 3 27 69 172 149 315 32 248
Efficient Encryption
encryption uses exponentiation to power e
hence if e small, this will be faster
● often choose e=65537 (216-1)
● also see choices of e=3 or e=17
but if e too small (eg e=3) can attack
● using Chinese remainder theorem & 3 messages with
different moduli
if e fixed must ensure gcd(e,ø(n))=1
● i.e. reject any p or q not relatively prime to e
Efficient Decryption
decryption uses exponentiation to power d
● this is likely large, insecure if not
can use the Chinese Remainder Theorem (CRT) to
compute mod p & q separately. then combine to get
desired answer
● approx 4 times faster than doing directly
only owner of private key who knows values of p & q can
use this technique
RSA Key Generation
users of RSA must:
● determine two primes at random - p, q
● select either e or d and compute the other
primes p,q must not be easily derived from
modulus n=p.q
● means must be sufficiently large
● typically guess and use probabilistic test
exponents e, d are inverses, so use Inverse
algorithm to compute the other
RSA Security
possible approaches to attacking RSA are:
● brute force key search - infeasible given size of
numbers
● mathematical attacks - based on difficulty of computing
ø(n), by factoring modulus n
● timing attacks - on running of decryption
● chosen ciphertext attacks - given properties of RSA
Factoring Problem
mathematical approach takes 3 forms:
● factor n=p.q, hence compute ø(n) and then d
● determine ø(n) directly and compute d
● find d directly
currently believe all equivalent to factoring
● have seen slow improvements over the years
•as of May-05 best is 200 decimal digits (663) bit with LS
● biggest improvement comes from improved algorithm
•GNFS to SNFS
● currently assume 1024-2048 bit RSA is secure
•ensure p, q of similar size and matching other constraints
Progress in Factoring
Progress
in
Factoring
Timing Attacks
developed by Paul Kocher in mid-1990’s
exploit timing variations in operations
● eg. multiplying by small vs large number
● or IF's varying which instructions executed
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
Chosen Ciphertext Attacks
• RSA is vulnerable to a Chosen Ciphertext
Attack (CCA)
• attackers chooses ciphertexts & gets
decrypted plaintext back
• choose ciphertext to exploit properties of RSA
to provide info to help cryptanalysis
• can counter with random pad of plaintext
• or use Optimal Asymmetric Encryption
Padding (OASP)
Optimal
Asymmetric
Encryption
Padding
(OASP)
Diffie-Hellman Key Exchange Algorithm
39
Diffie-Hellman Key Exchange
a public-key distribution scheme
● cannot be used to exchange an arbitrary
message
● rather it can establish a common key
42
The Problem of Key Exchange
• One of the main problems of symmetric key encryption
is it requires a secure & reliable channel for the shared
key exchange.
Adding Mathematics
Let’s get back to math
55
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.
56
Pr. If Alice and Bob agrees to the prime number p=7 and g=3 the primitive root of 7,
then compute the secret key that they share using Diffie-Hellman key exchange
algorithm. (Assume XA=2,XB=5)
• Alice combines her Private key of XA with the public information to compute YA
– YA = gXA mod p
– YA = 32 mod 7
– YA = 9 mod 7=2
• Bob combines his Private key of XB with the public information to compute YB.
– YB = gXB mod p
– YB = 35 mod 7
– YB = 243 mod 7 =5
• Alice shares her combined value, YA=2 with Bob. Bob shares his combined value, YB=5
with Alice.
• Alice computes secret key
– s = (YB mod p) XA mod p=52 mod 7
• Bob computes secret key
– s = (YA mod p) XB mod p=25 mod 7
57
Pr. If Alice and Bob agrees to the prime number p=353 and g=3 the primitive root
of 7, then compute the secret key that they share using Diffie-Hellman key
exchange algorithm. (Assume XA=97,XB=233)
• Alice combines her Private key of XA with the public information to compute YA
– YA = gXA mod p
– YA = 397 mod 353 = 40
– Use modular exponentiation algorithm to solve this
• We wish to compute say ab mod p convert b to binary bits bi
• Initially assume c=0 and f=1
• Check bi=1 then c=c+1 and f = f x a mod p
• c = c+2; f = f x f mod p
• Now to compute 397 a=3 and b=97
64 32 16 8 4 2 1
bi 1 1 0 0 0 0 1
c 1 3 6 12 24 48 97
f 3 27 23 176 265 33 40
• Column wise computations are described in next slide
58
Modular exponentiation column wise computations
64 32 16 8 4 2 1
bi 1 1 0 0 0 0 1
c 1 3 6 12 24 48 97
f 3 27 23 176 265 331 40
• Initially c=0,f=1. Start from MSB i.e. 7th bit of binary (column numerical 64) bi=1,c=c+1=1,
f=1x3=3
• Then compute c=1 x 2=2, f=f x f mod 353= 3 x 3 mod 353 =9
• 6th bit of binary (column numerical 32) bi=1,c=2+1=3, f=9x3=27 mod 353.
• c=6, f=27 x 27 mod 353 =23 next bit =0 update the column with c=6 and f=23
• c=12, f=23 x 23 mod 353 = 176 next bit =0 update the column with c=12 and f=176
• c=24, f=176 x 176 mod 353 =265 next bit =0 update the column with c=24 and f=265
• c=48, f=265 x 265 mod 353 =331 next bit =0 update the column with c=48 and f=331
• c=96 and f=331 x 331 mod 353=131 next bit =1 so
• c=c+1=96+1=97 and f=f x a = 131 x 3 mod 353 =393 mod 353 =40
59
Pr.If Alice and Bob agrees to the prime number p=353 and g=3 the primitive root
of 7, then compute the secret key that they share using Diffie-Hellman key
exchange algorithm. (Assume XA=97,XB=233)
• Bob combines his Private key of XB with the public information to compute YB.
– YB = gXB mod p
– YB = 3233 mod 353 = 248
• Now to compute 3233 a=3 and b=233
• Initially assume c=0 and f=1
• Check bi=1 then c=c+1 and f = f x a mod p
• c = c x 2; f = f x f mod p
128 64 32 16 8 4 2 1
bi 1 1 1 0 1 0 0 1
c 1 3 7 14 29 58 116 233
f 3 27 69 172 149 315 32 248
• For secret key computation see next slide
60
Pr. If Alice and Bob agrees to the prime number p=353 and g=3 the primitive root
of 7, then compute the secret key that they share using Diffie-Hellman key
exchange algorithm. (Assume XA=97,XB=233)
• Alice shares her combined value, YA=40 with Bob. Bob shares his combined
value, YB=248 with Alice.
• Alice compute secret key (use modular exponentiation algorithm to compute)
– s = (YB mod p) XA mod p=24897 mod 7 = 160
bi 1 1 0 0 0 0 1
c 1 3 6 12 24 48 97
f 248 215 335 324 135 222 160
Mathematical concepts
Graphical Representation
Y axis
X axis
x3 = λ² - x1 - x2
y3 = λ(x1 – x3) - y1, and
λ = (y2 – y1) / (x2 – x1)
Defining Addition on E : Case 2
For the case x1 = x2 and y1 = - y2 , addition is defined as
follows:
x3 = λ² - x1 - x2
y3 = λ(x1 – x3) - y1, and
λ = (3x12 + a) / 2y1
Defining the Identity
• The point at infinity O, is the identity element. P + O = O + P = P, for all P
∈ E.
• From Case 2, and the Identity Element, we now have the existence of
inverses
• Beyond the scope here to prove that we have commutativity and
associativity as well
• Therefore the set of solutions E, forms an Abelian group (Importance of
this will be shown later)
Elliptic Curves modulo p
• Let p > 3 be prime. The elliptic curve y² = x³ + ax + b over ℤp is the
set of solutions (x,y) ∈ ℤp
y² ≡ x³ + ax + b (mod p)
where a ∈ ℤp, b ∈ ℤp, are constants such that 4a³ + 27b² ≢ 0 (mod
p), together with a special point O called the point at infinity.
• Solutions still form an Abelian group
Examples
Elliptic Curve Picture
P3
Addition in Affine Co-ordinates
y=m(x-x1)+y1
y Let, P≠Q,
y2=x3+Ax+B
Doubling of a point
• Let, P=Q
y P2=O=∞
P1=P1+ O=P1
P1
Sum of two points
Define for two points P (x1,y1) and Q (x2,y2) in the Elliptic curve
P+P = 2P
X 0 1 2 3 4 5 6 7 8 9 10
x³ + x + 6 mod 11
6 8 5 3 8 4 8 4 9 7 4
QR? N N Y Y N Y N Y Y N Y
Y 4,7 5,6 2,9 2,9 3,8 2,9
Generating our group
• From the previous slide we have 13 points on the curve y² = x³ + x
+ 6 over ℤ11 including the point at infinity O.
• Since the O(E) is prime, the group is cyclic.
• We can generate the group by choosing any point other then the
point at infinity.
• Let our generator = α = (2,7) now to get 2α
∴2α = (5,2)
The Group
We can generate this by using the rules of addition we defined
earlier where 3a = a + 2a, a = (2,7),2a = (5,2)
85
Diffie Hellman Key exchange using ECC
• First pick a large integer q, which is either a prime
number or an integer of the form 2m and elliptic curve
parameters a and b.
• This defines the elliptic group of points Eq(a, b). Next,
pick a base point G = (x1, y1) in Eq(a, b) whose order is a
very large value n.
• The order n of a point G on an elliptic curve is the
smallest positive integer n such that nG = 0 and G are
parameters of the cryptosystem known to all
participants.
86
Diffie Hellman Key exchange using ECC
• Alice selects an integer XA less than n. This is Alice’s
private key.
• Alice then generates a public key PA = XA * G; the
public key is a point in Eq(a, b).
• Bob similarly selects a private key XB and computes a
public key PB.
• Alice generates the secret key k = XA * PB.
• Bob generates the secret key k = XB * PA.
• The two calculations in step 3 produce the same result
because
• XA * PB = XA * (XB * G) = XB * (XA * G) = XB * PA
87
Diffie Hellman Key exchange using ECC
• As an example, take q = 211; Eq(0,-4), which is equivalent to
the curve y2 = x3 - 4; and G = (2, 2).
• One can calculate that 240G = O.
• A’s private key is XA = 121, so A’s public key is PA = 121(2, 2) =
(115, 48).
• B’s private key is XB = 203, so B’s public key is 203(2, 3) = (130,
203).
• The shared secret key is 121(130, 203) = 203(115, 48) = (161,
69)
88
Elliptic Curve Encryption
• The first task in this system is to encode the plaintext
message m to be sent as an (x, y) point Pm.
• As with the key exchange system, an encryption/
decryption system requires a point G and an elliptic group
Eq(a, b) as parameters.
• Each user A selects a private key XA and generates a public
key PA = XA * G.
• To encrypt and send a message Pm to B, A chooses a
random positive integer k and produces the ciphertext Cm
• Cm = {kG, Pm + kPB}
89
Elliptic Curve Decryption
• To decrypt the cipher text, B multiplies the first point in the
pair by B’s private key and subtracts the result from the
second point
• Pm + kPB - XB(kG) = Pm + k(XBG) - XB(kG) = Pm
• For an attacker to recover the message, the attacker would
have to compute k given G and kG, which is assumed to be
hard.
90
Thank you
91