+ All Categories
Home > Documents > RSA - Cryptographyctc.kbu.ac.th/manatsarin/wp-content/uploads/2007/10/chapter-11-rsa.pdf · RSA -...

RSA - Cryptographyctc.kbu.ac.th/manatsarin/wp-content/uploads/2007/10/chapter-11-rsa.pdf · RSA -...

Date post: 16-Mar-2018
Category:
Upload: doankhuong
View: 214 times
Download: 0 times
Share this document with a friend
22
RSA - Cryptography Asymmetric key cryptography จะมี key อันนึงที่ประกาศให้ชาวบ้านรู้ได้ไม่เป็นความลับเรียกว่า public key แล้วก็มี key ที่เข้าคู่กับ public key เราเก็บไว้เองเรียกว่า private key การใช้งานก็คือถ้าเราต้องการส่งข้อมูลลับไปให้ใครบางคน ก็เข้ารหัสด้วย public key ของคนนัน้ เม่ือส่งไปถึงเค้าก็จะแกะข้อมูลที่เข้ารหัสได้โดยใช้ private key ซึง่เป็นคู่ของ public key ที่เข้ารหัสมา ดังนัน้ คนอ่ืนถึงจะเอาข้อมูลไปได้แต่ไม่มี private key ที่เป็นคู่ของมันก็จะแกะไม่ได้
Transcript
Page 1: RSA - Cryptographyctc.kbu.ac.th/manatsarin/wp-content/uploads/2007/10/chapter-11-rsa.pdf · RSA - Cryptography Asymmetric key ... and m = 13, the solution c is the remainder of dividing

RSA - Cryptography

Asymmetric key cryptography จะม key อนนงทประกาศใหชาวบานรไดไมเปนความลบเรยกวา public key แลวกม key ทเขาคกบ public key เราเกบไวเองเรยกวา private key การใชงานกคอถาเราตองการสงขอมลลบไปใหใครบางคน กเขารหสดวย public key ของคนนน เมอสงไปถงเคากจะแกะขอมลทเขารหสไดโดยใช private key ซงเปนคของ public key ทเขารหสมา ดงนนคนอนถงจะเอาขอมลไปไดแตไมม private key ทเปนคของมนกจะแกะไมได

Page 2: RSA - Cryptographyctc.kbu.ac.th/manatsarin/wp-content/uploads/2007/10/chapter-11-rsa.pdf · RSA - Cryptography Asymmetric key ... and m = 13, the solution c is the remainder of dividing

RSA - Cryptography

Public key cryptography จะมกญแจสองดอก คอ private key ซงจะเกบเปนความลบมเจาของคนเดยวเทานนทร และอกอนคอ public key ซงไมจำาเปนตองเกบเปนความลบ ทงสองตวจะใชงานตางกนคอ ถาใชกญแจอนนงเขารหส จะตองใชกญแจอกตวนงทเขาคกนในการถอดรหส

สมมตวาม public key A กบ private key B เปนกญแจทเขาคกน ถาเอา A เขารหส จะมแต B เทานนทถอดรหสนนออก และในทางกลบกนถาใช B เปนตวเขารหสกจะมแต A เทานนทจะถอดรหสได การทมกญแจสองแบบทำาให public key cryptography ไดเปรยบ secret key cryptography(Symmetric Cryptography) ตรงทผรบกบผสงใชกญแจคนละตวกน ไมจำาเปนตองรความลบของกนและกน กสามารถสงขอมลหากนไดอยางปลอดภย

Page 3: RSA - Cryptographyctc.kbu.ac.th/manatsarin/wp-content/uploads/2007/10/chapter-11-rsa.pdf · RSA - Cryptography Asymmetric key ... and m = 13, the solution c is the remainder of dividing

RSA - Cryptography

ปจจบน ทง public และ private ทเขาคกน สรางไดจากเลขจำานวนเฉพาะขนาดใหญมากๆ เชน 512 bits .. ถายงไมเยอะพอกมบาง algorithm ทใชถง 4096 bits

Page 4: RSA - Cryptographyctc.kbu.ac.th/manatsarin/wp-content/uploads/2007/10/chapter-11-rsa.pdf · RSA - Cryptography Asymmetric key ... and m = 13, the solution c is the remainder of dividing

RSA - Cryptography

ทำำไมตองเปนจำำนวนเฉพำะ ? กเพราะวาคณสมบตพเศษอนนงของจำานวนเฉพาะเมอเอามาคณกน จะมแคจำานวนเฉพาะคนนทหารผลคณได key สวนใหญจะสรางโดยใชจำานวณเฉพาะสองตวคณกนเปนเลขยกกำาลง แลวเอาผลลพธมาทำาการคำานวณรวมกบการ mod การจะหา key ไดจะตองเอาผลคณมาแยกตวประกอบซงทำาไดยาก เพราะมตวประกอบเพยงสองตว

โดยสรปเลขจำานวนเฉพาะทำาใหการสราง key เลยนแบบทำาไดยาก

Page 5: RSA - Cryptographyctc.kbu.ac.th/manatsarin/wp-content/uploads/2007/10/chapter-11-rsa.pdf · RSA - Cryptography Asymmetric key ... and m = 13, the solution c is the remainder of dividing

RSA - Cryptography

ตวอยางเชนการจะหา key ขนาด 664-bit (เลขฐานสบ 200 หลก)

ถาใช brute-force (เทคนคแบบลองทกทางทเปนไปได) กแกะกนประมาณ 4000 ป โดยใชเครองลานเครอง แตละเครองแยกตวประกอบไดลานครงตอวนาท ถาเปน 1024-bit ก 10 กำาลง 10 ป..(เทานนเอง..)

Page 6: RSA - Cryptographyctc.kbu.ac.th/manatsarin/wp-content/uploads/2007/10/chapter-11-rsa.pdf · RSA - Cryptography Asymmetric key ... and m = 13, the solution c is the remainder of dividing

RSA - Cryptography

ประเภทของขอมล อำย ขนำด key

กลยทธทางทหาร นาท/ขวโมง 56 bits

อตราดอกเบย วน/สปดาห 56-64 bits

ความลบทางการคา เชน สตร Coca-cola สบปขนไป 64 bits

ความลบทางทหาร เชน Hydrogen bomb มากกวา 40 ป 128 bits

ความลบสวนตวของบคคล มากกวา 50 ป 128 bits

ขอมลทะเบยนราษฎร 100 ป อยางนอย 128 bits

Page 7: RSA - Cryptographyctc.kbu.ac.th/manatsarin/wp-content/uploads/2007/10/chapter-11-rsa.pdf · RSA - Cryptography Asymmetric key ... and m = 13, the solution c is the remainder of dividing

RSA - Cryptography

Prime number หรอ Prime หรอ จำานวนเฉพาะ

คอจำานวนทมเพยงแคตวมนเองและ 1 เทานนทหารลงตว หรอเปนจำานวนทมตวประกอบ (Factor) เปนตวมนเองกบ 1 เทานน

ตวอยางของจำานวนเฉพาะ เชน

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

คณสมบตทนาสนใจ

เลขฐาน 10 ทเปนจำานวนเฉพาะจะลงทายดวย 1, 3, 7, or 9. (ยกเวน 2 กบ 5)

Every even integer greater than 2 can be written as a sum of two primes.

Every odd integer greater than 5 can be written as a sum of three primes.

ใชในการสราง Public/Private Key

Page 8: RSA - Cryptographyctc.kbu.ac.th/manatsarin/wp-content/uploads/2007/10/chapter-11-rsa.pdf · RSA - Cryptography Asymmetric key ... and m = 13, the solution c is the remainder of dividing

RSA - Cryptography

กำาเนด Public Key Cryptography

Public key cryptography เกดจากหลกคณตศาสตรทเรยกวา ฟงกชนทางเดยว (one-way function) กลมของฟงกชนทางเดยวสวนหนงมความเกยวของกบเลขจำานวนเฉพาะ (prime number) เลขทหารไดเฉพาะ 1 และตวมนเอง คณสมบตนเกยวกบฟงกชนทางเดยวไดยงไง ?

Page 9: RSA - Cryptographyctc.kbu.ac.th/manatsarin/wp-content/uploads/2007/10/chapter-11-rsa.pdf · RSA - Cryptography Asymmetric key ... and m = 13, the solution c is the remainder of dividing

RSA - Cryptography

ถาเอาเลขจำานวนเฉพาะสองตวมาคณกน สมมตเปน 5 กบ 7 ได 35

ลองหาตวประกอบของ 35, เราจะไดวามเพยง 5 และ 7 เทานนทเปนตวประกอบ

ลองหาอกซกจำานวนนง 11,927 x 20,903 = 249,310,081

การคณ 11,927 กบ 20,903 นงายกวาหาตวประกอบของ 249,310,081

ยงเลขจำานวณเฉพาะมคามากเทาไหรยงจะแยกตวประกอบยากขนเทานน

Page 10: RSA - Cryptographyctc.kbu.ac.th/manatsarin/wp-content/uploads/2007/10/chapter-11-rsa.pdf · RSA - Cryptography Asymmetric key ... and m = 13, the solution c is the remainder of dividing

RSA - Cryptography

แนวคดเรอง public key คนแรกทคดเรองนคอ วธฟลด ดฟฟ (Whitfield Diffie) และ มารตน เฮลแมน (Martin Hellman) ซงเสนอวธการแบบ public key นใน National Computer Conference ป 1976 และตพมพใน IEEE Transaction on Information Theory

Page 11: RSA - Cryptographyctc.kbu.ac.th/manatsarin/wp-content/uploads/2007/10/chapter-11-rsa.pdf · RSA - Cryptography Asymmetric key ... and m = 13, the solution c is the remainder of dividing

RSA - Cryptography

การสราง Private / Public key

Public key cryptography เกดจากหลกคณตศาสตรทเรยกวา ฟงกชนทางเดยว (one-way function) กลมของฟงกชนทางเดยวสวนหนงมความเกยวของกบเลขจำานวนเฉพาะ (prime number) เลขทหารไดเฉพาะ 1 และตวมนเอง คณสมบตนเกยวกบฟงกชนทางเดยวไดยงไง ?

5 x 7 = 35

11,927 x 20,903 คำาตอบคอ 249,310,081

ยงเลขจำานวณเฉพาะมคามากเทาไหรยงจะแยกตวประกอบยากขนเทานน สมมตวา 249,310,081 เปนขอมลทเราไดรบและถาเรารจำานวนเฉพาะตวนง(ตวประกอบ) เราจะหาอกตวนงไดอยางงายดาย แตถาเราไมรละกกวาจะหาไดกนานทเดยว

Page 12: RSA - Cryptographyctc.kbu.ac.th/manatsarin/wp-content/uploads/2007/10/chapter-11-rsa.pdf · RSA - Cryptography Asymmetric key ... and m = 13, the solution c is the remainder of dividing

RSA - Cryptography

The calculation a = b^e mod n is known as modular exponentiation

Doing a "modular exponentiation" means calculating the remainder when dividing by a positive integer m (called the modulus) a positive integer b (called the base) raised to the e-th power (e is called the exponent). In other words, problems take the form where given base b, exponent e, and modulus m, one wishes to calculate c such that:

c b^e mod(m)≡

For example, given b = 5, e = 3, and m = 13, the solution c is the remainder of dividing 5^3 by 13, namely the rest of the division 125 / 13, which works out to be 8.

c = 5^3 mod(13)= 125 mod(13)= 8

If b, e, and m are non-negative and b < m, then a unique solution c exists and has the property 0 c < m.≤

Modular exponentiation

Page 13: RSA - Cryptographyctc.kbu.ac.th/manatsarin/wp-content/uploads/2007/10/chapter-11-rsa.pdf · RSA - Cryptography Asymmetric key ... and m = 13, the solution c is the remainder of dividing

RSA - Cryptography

1. Generate two large random primes, p and q, of approximately equal size such that their product n = pq is of the required bit length, e.g. 1024 bits.

2. Compute n = pq and ( ) phi = (p-1)(q-1)φ

3. Choose an integer e, 1 < e < phi, such that gcd(e, phi) = 1

4. Compute the secret exponent d, 1 < d < phi, such thated 1 (mod phi) ≡ หรอd e^-1 (mod phi)≡

5. The public key is (n, e) and the private key is (n, d)

The values of p, q, and phi should also be kept secret.

n is known as the modulus.

e is known as the public exponent or encryption exponent.

d is known as the secret exponent or decryption exponent.

การสราง Private Key และ Public Key

Page 14: RSA - Cryptographyctc.kbu.ac.th/manatsarin/wp-content/uploads/2007/10/chapter-11-rsa.pdf · RSA - Cryptography Asymmetric key ... and m = 13, the solution c is the remainder of dividing

RSA - Cryptography

ใหจำานวนเฉพาะ p=11, q=3 ดงนน

n = pq = 11 . 3 = 33 และphi = (p-1)(q-1) = 10 . 2 = 20

เลอก e=3 แลวตรวจสอบ gcd(e, p-1) = gcd(3, 10) = 1 และ gcd(e, q-1) = gcd(3, 2) = 1

คำานวณหาคา d ททำาให ed 1 (mod phi)≡คำานวณหาคา d = e^-1 mod phi = 3^-1 mod 20หาคา d ททำาให phi แยกตวประกอบได (ed-1)หาคา ททำาให 20 แยกตวประกอบออกมาเปน 3d-1ลอง d = 7 จะได แลวตรวจสอบ ed-1 = 3.7 - 1 = 20, ซงหารดวย phi ลงตว

Public key = (n, e) = (33, 3)

Private key = (n, d) = (33, 7)

ตวอยำง

Page 15: RSA - Cryptographyctc.kbu.ac.th/manatsarin/wp-content/uploads/2007/10/chapter-11-rsa.pdf · RSA - Cryptography Asymmetric key ... and m = 13, the solution c is the remainder of dividing

RSA - Cryptography

ความปลอดภยของ algorithm น ขนกบความยากในการแยกตวประกอบของเลขจำานวนเฉพาะ ทมคามากๆ

Page 16: RSA - Cryptographyctc.kbu.ac.th/manatsarin/wp-content/uploads/2007/10/chapter-11-rsa.pdf · RSA - Cryptography Asymmetric key ... and m = 13, the solution c is the remainder of dividing

RSA - Cryptography

Public key cryptography นำามาประยกตใชคอนขางกวาง จนอาจจะแกปญหาของระบบความปลอดภยไดครบทง 4 อยาง(Authentication, Integrity, Confidentiality, และ Non-repudiation) เลยดวยซำา

อยางเชน ใน secret key cryptography จะตองมการแลก secret key กนเพอใหผรบสามารถถอดรหสได หลายๆ โปรแกรมกใช Diffie-Hellman ในการแลก secret key เพราะจาก algorithm ของ Diffie-Hellman คา k และ k' มคาเทากนและ secret key cryptography ใชเลขสมได ดงนนคา k/k' จะเปนเทาไหรกใชเปน key ไดเสมอ สวนการทำา Encryption โดยวธของ public key กจะทำางานตามนครบ สมมตให A เปนผสงและ B เปนผรบ .. A จะเอา public key ของ B มาเขารหสแลวจงสงไปให B ..ขอมลทสงไปจะมกเพยง B เทานนทจะถอดรหสนนออกเพราะม private key ทเขาคกบ public key ทเปนตวเขารหสสงมา

Page 17: RSA - Cryptographyctc.kbu.ac.th/manatsarin/wp-content/uploads/2007/10/chapter-11-rsa.pdf · RSA - Cryptography Asymmetric key ... and m = 13, the solution c is the remainder of dividing

RSA - Cryptography

Public key cryptography สามารถนำามาประยกตใชเปน digital signature ไดดวย .. ลายเซนดจตอลนเอาไวใชในกรณทเราตองการตรวจสอบตวตนทแทจรง (Identity verification) สมมต A กบ B

A จะเขารหสดวย private key ของตวเอง ขนตอนนเรยกกนวา digital signing ขอมลทผาน digital signing แลวกจะสงไปให B

B สามารถตรวจสอบวาขอมลมาจาก A ตวจรงไดโดยการใช public key ของ A เปนตวถอดรหส ถาสามารถถอดไดกมนใจไดวาขอมลนนมาจาก A จรงๆ เพราะมแต public key ของ A เทานนทถอดรหสขอมลท sign โดย private key ของ A

Page 18: RSA - Cryptographyctc.kbu.ac.th/manatsarin/wp-content/uploads/2007/10/chapter-11-rsa.pdf · RSA - Cryptography Asymmetric key ... and m = 13, the solution c is the remainder of dividing

RSA - Cryptography

SSL (Secure Socket Layer) SSL เรมมาจากบรษท Netscape ททำา browser

การทำางานของ SSL จะเรมจาก

● server สง certificate เพอยนยนตวตนกบผใช ขนตอนนเรยกวา authentication certificate ทใชกนเปนมาตรฐาน X.509 จะรบรอง (ดวย digital signature) โดยผทเชอถอไดเชน US Post Service หรอถาเปนบรษททนยมใชกจะเปนของ VeriSign ซงตองซอและมราคาแพงตาม strength ของความปลอดภย บางเจาขาย 500 certificates ในราคาแสนกวาเหรยญ แต certificate เหลานจะตรวจสอบตวตนจรงๆ ไดชวรสดๆ สำาหรบคนทไมอยากจาย กจะใชวธ self signing ในการสราง ceritifcate คอ เซนเองใชเอง

Page 19: RSA - Cryptographyctc.kbu.ac.th/manatsarin/wp-content/uploads/2007/10/chapter-11-rsa.pdf · RSA - Cryptography Asymmetric key ... and m = 13, the solution c is the remainder of dividing

RSA - Cryptography

หากผใชยอมรบ certificate นนโปรแกรมกจะเรมตกลงกนวาจะใช protocol อะไรในการเขาและถอดรหส ขนกบวาโปรแกรมและตว SSL server รองรบไดขนาดไหน อยาง HTTPS ปจจบนจะใชการเขารหสขนาด 128-bit

หลงจากนนทงสองฝายกจะสงขอมลกนโดยการเขารหสทงหมด โดยใช Private/Public ทไดจาก server ในการเขารหส

Page 20: RSA - Cryptographyctc.kbu.ac.th/manatsarin/wp-content/uploads/2007/10/chapter-11-rsa.pdf · RSA - Cryptography Asymmetric key ... and m = 13, the solution c is the remainder of dividing

RSA - Cryptography

ขอเสยของ public key cryptography คอความเรวในการทำางานตำา อยในชวง 100 - 1000 เทาของ secret key cryptography

1. Prime number generator การหาเลขจำานวนเฉพาะทมคามากๆ ตองใชวธการทยงยาก และเสยเวลามาก มากจนหลายแอพพลเคชน ไมหาจำานวนเฉพาะโดยตรงแตใชการสมตวเลขแลวทดสอบวา เปนเลขจำานวนเฉพาะหรอไมแทน

Page 21: RSA - Cryptographyctc.kbu.ac.th/manatsarin/wp-content/uploads/2007/10/chapter-11-rsa.pdf · RSA - Cryptography Asymmetric key ... and m = 13, the solution c is the remainder of dividing

RSA - Cryptography

2. สมการ exponential ในการเขาและถอดรหสกเปนเหตผลนงททำาใหทำางานชา เพราะตวยกกำาลงเปนเลขทมคาเยอะ ตวอยาง

สมมตเปน RSA ให p=47 q=71 คำานวณคา n=3337 และ (p-1)(q-1)=3220

คา d = 1019 สมคา e = 79 เวลาเขารหสใช m79 mod 3337

ถอดดวย c 1019 mod 3337 สมมตให m เปนตวอกษรรหส ASCII เอาซก 5 คำานกคำานวณกนมอหงกแลวครบ

Page 22: RSA - Cryptographyctc.kbu.ac.th/manatsarin/wp-content/uploads/2007/10/chapter-11-rsa.pdf · RSA - Cryptography Asymmetric key ... and m = 13, the solution c is the remainder of dividing

RSA - Cryptography

3. Secret key cryptography จะใช operation ทซบซอนนอยกวาเยอะ อยางพวก xor, shift จงทำางานไดเรวกวา นอกจากนกญแจกสามารถใช random number ได หรอบาง algorithm อาจจะตองใช secure random number แตกยงไมตองคำานวณเยอะและมเงอนไขมากเหมอน public key cryptography


Recommended