net 311d information securityinformation security tutorial 3 : asymmetric ciphers (rsa) networks and...
TRANSCRIPT
NET 311D
INFORMATION SECURITY
TUTORIAL 3 : Asymmetric Ciphers (RSA)
Networks and
Communication
Department
1
A Symmetric-Key Cryptography
(Public-Key Cryptography)
Asymmetric-key (public key cryptography) uses two
keys: one private and one public.
There are two algorithms:
RSA
ELGAMAL
RSA
The most common public key algorithm is RSA,
named for its inventors Rivest, Shamir, and Adelman.
It uses two numbers:
e public key
d private
Networks and Communication Systems Department - Prepared by : TA. Anfal AlHazzaa
RSA – Step 1:selecting keys
1. Choose two very large prime numbers p and q
2. Find n n=p x q
3. Calculates another number ф = (p -1) X (q -1)
4. Choose random encryption number e ,
1< e< ф
gcd(e, ф)=1 (coprime)
(You can use Euclidian algorithm to help you find correct e)
5. Calculate d so that d X e mod ф = 1 (using table method)
Note : Announce e and n to the public; keep ф and d secret.
Networks and Communication Systems Department - Prepared by : TA. Anfal AlHazzaa
RSA – Step 2: Encryption (Sender)
Where P : plain text
n= pxq
C : cipher text
e: public key
Restriction
P < n , if not, the plaintext needs to be divided into blocks to make P less than n.
Networks and Communication Systems Department - Prepared by : TA. Anfal AlHazzaa
RSA – Step 3: Decryption (Receiver)
Where P : plain text
n= pxq
C : cipher text
d: private key
Networks and Communication Systems Department - Prepared by : TA. Anfal AlHazzaa
RSA: Example 1
Perform encryption and decryption using the RSA
algorithm, for the following:
p = 3; q = 11, e = 7; M = 5
Networks and Communication Systems Department - Prepared by : TA. Anfal AlHazzaa
RSA – Step 1:selecting keys
1. p=3 ; q =11
2. n=p x q = 3 x 11 =33 n=33
3. ф = (p -1) X (q -1) = (3-1) x (11-1)= 2 x10 = 20 ф = 20
4. e (which is mentioned in question ) e=7
1< e< ф
gcd(e, ф)=1 (coprime)
(You can use Euclidian algorithm to help you find correct e)
5. Calculate d so that d X e mod ф = 1 (using table method)
Note : Announce e and n to the public; keep ф and d secret.
Networks and Communication Systems Department - Prepared by : TA. Anfal AlHazzaa
Euclidian algorithm
7 20
14
6
2
7
6
1
1
6
6
0
1
1. Divide the ф by e
2. Divide the divisor of the previous division
by the reminder of the previous division
3. Repeat step 2 until the reminder become 0
STOP
Networks and Communication Systems Department - Prepared by : TA. Anfal AlHazzaa
Rewrite the previous operations as the following:
Dividend= (divisor x quotient )+ Reminder
20=(7 x 2) + 6
7= (6 x 1) + 1
6=(6 x 1) +0
This is the gcd(20,7)
Euclidian algorithm cont.
Networks and Communication Systems Department - Prepared by : TA. Anfal AlHazzaa
Table method
1. As default in all situations , put the values of a 1 and b0 in 1st row and
the values of a 0 and b 1in 2nd row
2. 1st row : c= ф and g= empty
3. 2nd row : c= e and g= (c1 /c2) (take only the integer part)
(20/7)=2.8 2
Row # a b c g
1 1 0 20 -
2 0 1 7 2
Networks and Communication Systems Department - Prepared by : TA. Anfal AlHazzaa
Table method cont.
3. 3rd row:
a3= a1-a2*g2 1-0*2=1
b3= b1-b2*g2 0-1*2=-2
c3= c1-c2*g2 20-7*2=6 ( it’s the reminder of 20/7)
g3= (c2 /c3) (take only the integer part) (7/6)=1.16 1
Row # a b c g
1 1 0 20 -
2 0 1 7 2
3 1 -2 6 1
In 𝑟𝑜𝑤𝑛
𝑐𝑜𝑙𝑢𝑚𝑛𝑛 = 𝑐𝑜𝑙𝑢𝑚𝑛𝑛−2 − 𝑐𝑜𝑙𝑢𝑚𝑛𝑛−1 x 𝑔𝑛−1
except 𝑔𝑛 = 𝑐𝑛−1 / 𝑐𝑛 (take only the integer part)
Networks and Communication Systems Department - Prepared by : TA. Anfal AlHazzaa
Table method cont.
4. 4th row:
a4= a2-a3*g3 0-1*1=-1
b4= b2-b3*g3 1-(-2)*1=3
c4= c2-c3*g3 7-6*1=1 ( it’s the reminder of 7/6)
g4= (c3 /c4) (take only the integer part) (6/1)=6
Row # a b c g
1 1 0 20 -
2 0 1 7 2
3 1 -2 6 1
4 -1 3 1 6
In 𝑟𝑜𝑤𝑛
𝑐𝑜𝑙𝑢𝑚𝑛𝑛 = 𝑐𝑜𝑙𝑢𝑚𝑛𝑛−2 − 𝑐𝑜𝑙𝑢𝑚𝑛𝑛−1 x 𝑔𝑛−1
except 𝑔𝑛 = 𝑐𝑛−1 / 𝑐𝑛 (take only the integer part)
Networks and Communication Systems Department - Prepared by : TA. Anfal AlHazzaa
Table method cont.
Stop when the value of c become 1
Then the latest value of b is the value of d d=3
Row # a b c g
1 1 0 20 -
2 0 1 7 2
3 1 -2 6 1
4 -1 3 1 6
Important notes : 1. If the value of b is negative d= ф + b
2. If the value of b> ф d= b mod ф
To confirm your answer: a*ф + b*e = gcd (ф,e)
In our example : -20 + 21 = 1
1=1 it’s correct
Networks and Communication Systems Department - Prepared by : TA. Anfal AlHazzaa
RSA – Step 1:selecting keys
1. p=3 ; q =11
2. n=33
3. ф = 20
4. e=7
5. d=3
Note : Announce e and n to the public; keep ф and d secret.
Networks and Communication Systems Department - Prepared by : TA. Anfal AlHazzaa
RSA – Step 2: Encryption (Sender)
P=M= 5 , e=7 ,n=33
C = 57 mod (33)
C = [(54 mod 33) * (52 mod 33) * (51 mod 33)] mod 33
C = (31 * 25 * 5) mod 33
C = 3875 mod 33
C=14
Networks and Communication Systems Department - Prepared by : TA. Anfal AlHazzaa
RSA – Step 3: Decryption (Receiver)
C=14 , d=3 ,n=33
P=143 mod 33
P = [(142 mod 33)*(141 mod 33)] mod 33
P= 434 mod 33
P=5
Networks and Communication Systems Department - Prepared by : TA. Anfal AlHazzaa
RSA: Example 2
Encrypt the following message “YES” By Using RSA
algorithm.
Assume that
p=5, q =11, e= 3
Each character will be encoded according to this
algorithm (A - Z) (00 – 25)
Find d , then encrypt each character individually
Networks and Communication Systems Department - Prepared by : TA. Anfal AlHazzaa
RSA – Step 1:selecting keys
1. p=5 ; q =11
2. n=p x q = 5 x 11 =55 55
3. ф = (p -1) X (q -1) = (5-1) x (11-1)= 4 x10 = 40 ф = 40
4. e (which is mentioned in question ) e=3
1< e< ф
gcd(e, ф)=1 (coprime)
(You can use Euclidian algorithm to help you find correct e)
5. Calculate d so that d X e mod ф = 1 (using table method)
Note : Announce e and n to the public; keep ф and d secret.
Networks and Communication Systems Department - Prepared by : TA. Anfal AlHazzaa
Euclidian algorithm
3 40
39
1
13
3
3
0
3
1. Divide the ф by e
2. Divide the divisor of the previous division
by the reminder of the previous division
3. Repeat step 2 until the reminder become 0 STOP
Networks and Communication Systems Department - Prepared by : TA. Anfal AlHazzaa
Rewrite the previous operations as the following:
Dividend= (divisor x quotient )+ Reminder
40=(13x 3) + 1
3= (3 x 1) + 0
This is the gcd(40,3)
Euclidian algorithm cont.
Networks and Communication Systems Department - Prepared by : TA. Anfal AlHazzaa
Table method
1. As default in all situations , put the values of a 1 and b0 in 1st row and
the values of a 0 and b 1in 2nd row
2. 1st row : c= ф and g= empty
3. 2nd row : c= e and g= (c1 /c2) (take only the integer part)
(40/3)=13.3 13
Row # a b c g
1 1 0 40 -
2 0 1 3 13
Networks and Communication Systems Department - Prepared by : TA. Anfal AlHazzaa
Table method cont.
3. 3rd row:
a3= a1-a2*g2 1-0*13=1
b3= b1-b2*g2 0-1*13=-13
c3= c1-c2*g2 40-3*13=1 ( it’s the reminder of 40/3)
g3= (c2 /c3) (take only the integer part) (3/1)=3
Row # a b c g
1 1 0 40 -
2 0 1 3 13
3 1 -13 1 3
In 𝑟𝑜𝑤𝑛
𝑐𝑜𝑙𝑢𝑚𝑛𝑛 = 𝑐𝑜𝑙𝑢𝑚𝑛𝑛−2 − 𝑐𝑜𝑙𝑢𝑚𝑛𝑛−1 x 𝑔𝑛−1
except 𝑔𝑛 = 𝑐𝑛−1 / 𝑐𝑛 (take only the integer part)
Networks and Communication Systems Department - Prepared by : TA. Anfal AlHazzaa
Table method cont.
Stop when the value of c become 1
Then the latest value of b is the value of d b= -13 (It’s negative )
Based on note 1 d= ф+b 40+(-13)= 27 d= 27
Row # a b c g
1 1 0 40 -
2 0 1 3 13
3 1 -13 1 3
Important notes : 1. If the value of b is negative d= ф + b
2. If the value of b> ф d= b mod ф
To confirm your answer: a*ф + b*e = gcd (ф,e)
In our example : 40+ (-39) = 1
1=1 it’s correct
Networks and Communication Systems Department - Prepared by : TA. Anfal AlHazzaa
RSA – Step 1:selecting keys
1. p=5 ; q =11
2. n=55
3. ф = 40
4. e=3
5. d=27
Note : Announce e and n to the public; keep ф and d secret.
Networks and Communication Systems Department - Prepared by : TA. Anfal AlHazzaa
RSA – Step 2: Encryption (Sender)
P=M=YES(must be encoded before) , e=3 ,n=55
Y=24
C = 243 mod (55)
C= 19
E=4
C = 43 mod (55)
C= 9
S=18
C = 183 mod (55)
C= 2
Networks and Communication Systems Department - Prepared by : TA. Anfal AlHazzaa
RSA – Step 2: Encryption (Sender) cont.
24-Feb-15
27
Networks and Communication Systems Department - Prepared by : TA. Anfal AlHazzaa
RSA – Step 3: Decryption (Receiver)
C=19
P = 1927 mod (55)
P= 24
C=9
P = 927 mod (55)
P= 4
C=2
P = 227 mod (55)
P= 18
Networks and Communication Systems Department - Prepared by : TA. Anfal AlHazzaa