The University of Babylon Department of Software LECTURE NOTES ON PUBLIC- KEY CRYPTOGRAPHY (RSA and ElGamal) By Dr. Samaher Hussein Ali College of Information Technology, University of Babylon, Iraq Samaher@itnet.uobabylon.edu.iq 2 November 2013 Public-key cryptography Called also asymmetric cryptography The keys used to encrypt and decrypt are different. Anyone who wants to be a sender needs to “publish” an encryption key, which is known as the public key, KB. Anyone who wants to be a receiver needs a unique decryption key, which is known as the private key, kv. If B wants to send an enciphered text to A, B should knows the the encryption algorithm and A’s public key. 2 November 2013 Dr. Samaher Hussein Ali Notes of Lecture 8 Confidentiality via Public key cryptography Samaher wants to send a secret message m to Eman Eman should have 2 keys: public KB and private kv Prior to message encryption, samaher gets by some means an authentic copy of Eman’s public key (i.e., the encryption key) 2 November 2013 Dr. Samaher Hussein Ali Notes of Lecture 8 Public-key Systems It provides confidentiality by depend on digital signatures. It reduce number of using keys , example; if we need communication among 100 users in tradition methods, we need (n(n-1)/2)= 100(99)/2=4950 keys while, when we use the public key system need only 100 keys RSA It is named after it inventors Ron Rivest, Adi Shamir and Len Adleman. Published in 1978۔ It is the most widely used public-key encryption algorithm today. It provides confidentiality and digital signatures. Its security is based on the difficulty of integer factorization 2 November 2013 Dr. Samaher Hussein Ali Notes of Lecture 8 RSA algorithm (key generation for RSA public-key encryption) Each entity A creates a public key and a corresponding private key by doing the following Who is capable of computing public key? Generate three prime numbers p and q, e Compute n=p*q A’s Public key: (e, n) // to be published Who is capable of computing d? d gcd( (n)) * (n) 1 e -- (n)=(p-1)(q-1) To verification d : we must [e*d mod (n) 1] A’s private key: (d, n)) // to be kept secretly by A 2 November 2013 Dr. Samaher Hussein Ali Notes of Lecture 8 RSA Encryption/Decryption Summary: A encrypts a message m for B. Upon reception, B decrypts it using its private key. Encryption: A should do the following Obtain B’s authentic public key (n,e). Represent the message as an integer in the interval [0,n-1] Compute c = me mod n // Encryption Send the ciphertext c to B Decryption: to recover plaintext m from c, B does the following Use the private key d to recover m = cd mod n // Decryption 2 November 2013 Dr. Samaher Hussein Ali Notes of Lecture 8 RSA Encryption/Decryption 2 November 2013 Dr. Samaher Hussein Ali Notes of Lecture 8 Example 1: Let, p=3, q=17, e=5: Find the public and Secret key then cipher the message ABC n=p*q=3*17=51 Public key ------<e,n>=<5,51> d=(GCD((n))* (n)+1)/e (n)= (p-1)(q-1)=(3-1)(17-1)=(2*16)=32 GCD((n))= GCD[(P-1)(q-1)]=GCD(2,16)=2 d=((2*32+1)/5)= (64+1) /5 =65/5=13 Secret Key-------<d,n>=<13,51> To verification d : e.d mod (n)=1 5*13 mod 32 65 mod 32 =1 2 November 2013 Dr. Samaher Hussein Ali Notes of Lecture 8 Example 1: Let, p=3, q=17, e=5: Find the public and Secret key then cipher the message ABC 2. Find the cipher text using the public key <e,n>=<5,51> Ci=Mie mod n C1=(1)5 Mod 51=1 mod 51 =1 C2=(2)5 Mod 51=32 mod 51 =32 C1=(3)5 Mod 51=243 mod 51 =39 3. Find the cipher text using the Secret Key-------<d,n>=<13,51> Mi=Cid mod n M1=(1)13Mod 51=1 M2=(32)13 Mod 51=2 M1=(39)13 Mod 51=3 2 November 2013 Dr. Samaher Hussein Ali Notes of Lecture 8 Example 2: Confidentiality Take p = 7, q = 11, so n =p*q= 77 (n) =(p-1)(q-1) =(7-1)(11-1)=60 Let e = 17 -------- public key(17,77) Compute d =[gcd(6,10)*60+1]/17= 53 17 x 53 mod 60 = 1 -------- secret key(53,77) samaher wants to secretly send Eman the message HELLO [07 04 11 11 14] 0717 mod 77 = 28 0417 mod 77 = 16 1117 mod 77 = 44 1117 mod 77 = 44 1417 mod 77 = 42 samaher sends ciphertext [28 16 44 44 42] 2 November 2013 Dr. Samaher Hussein Ali Notes of Lecture 8 Example 2: Confidentiality Eman receives [28 16 44 44 42] Eman uses private key < 53,77>, to decrypt the message: 2853 mod 77 = 07 H 1653 mod 77 = 04 E 4453 mod 77 = 11 L 4453 mod 77 = 11 L 4253 mod 77 = 14 O No one else could read it, as only Eman knows his private key and that is needed for decryption 2 November 2013 Dr. Samaher Hussein Ali Notes of Lecture 8