Information system security wk4-cryptography-2

27
Faculty of Information Technology Page IT346 Information System Security Week 4: Cryptography (Continue) อ.ออออออออออ ออออออ

description

If you have question Message me!

Transcript of Information system security wk4-cryptography-2

Page 1: Information system security wk4-cryptography-2

Faculty of Information Technology Page

IT346 Information System Security

Week 4: Cryptography (Continue)อ.พงษ์�ศั�กดิ์� ไผ่�แดิ์ง

Page 2: Information system security wk4-cryptography-2

Faculty of Information Technology Page

Cryptography Cryptography หมายถึ�งวิทยาการรห�สลั�บ มา

จากคำ�าวิ�า crypto ท !แปลัวิ�า ซ่�อน แลัะคำ�าวิ�า graph ท !แปลัวิ�าการเขี ยนCryptography จ�งม คำวิามหมายวิ�า “การเขี ยนเพ(!อซ่�อนขี)อม*ลั ”

Cryptography ใช้)ในการป-องก�นขี)อม*ลัแลัะสารสนเทศั โดิ์ยประกอบดิ์)วิย 3 เทคำโนโลัย หลั�ก‣ Symmetric Key Cryptography หร(อ

Secret Key Cryptographyคำ(อการเขี)ารห�สขี)อม*ลัแบบ สมมาตร“ ”

‣ Asymmetric Key Cryptography หร(อ Public Key Cryptographyคำ(อการเขี)ารห�สขี)อม*ลัแบบ อสมมาตร“ ”

‣ Hash Function คำ(อการสร)างต�วิแทนขี)อม*ลั

Page 3: Information system security wk4-cryptography-2

Faculty of Information Technology Page

Symmetric Key Cryptography

เราสามารถึแบ�งระบบ Cryptography แบบ Symmetric Key ออกตามร*ปแบบการดิ์�าเนนการบน Plaintext จะแบ�งไดิ์)เป0น

แบบบลั1อคำ (Block Cipher)‣ ซ่�!งจะท�าการเขี)ารห�สท ลัะบลั1อคำ 1 บลั1อคำประกอบดิ์)วิย

หลัายบต• DES:1 Data Block = 64 bits• 3DES: 1 Data Block = 64 bits• AES: 1 Data Block = 128 bits

แบบสตร ม (Stream Cipher) ‣ ซ่�!งจะท�าการเขี)ารห�สท ลัะบต

• RC4

Page 4: Information system security wk4-cryptography-2

Faculty of Information Technology Page

Stream Ciphers ดิ์�าเนนการเขี)ารห�สบน bit ท ลัะ bit

‣ เป0นการดิ์�าเนนการบนสาย (Stream) ขีองขี)อม*ลั Key ท !ใช้)ในการเขี)ารห�สจะเป0นสายเช้�นเดิ์ ยวิก�น

เร ยกวิ�า Keystream ‣ Keystream ส�าหร�บการเขี)ารห�สแบบ Stream

Cipher เป0น pseudorandom keystream‣ Pseudorandom คำ(อการส2�มแบบเท ยม จะไดิ์)คำ�าท !

เสม(อนเป0นคำ�าส2�ม แต�สร)างมาจากกระบวินการท !ถึ*กก�าหนดิ์ไวิ)อย�างแน�นอน

Page 5: Information system security wk4-cryptography-2

Faculty of Information Technology Page

Stream Ciphers แต�ลัะ bit ขีอง Keystream จะถึ*กดิ์�าเนนการ

(เช้�นการ XOR) ก�บแต�ลัะ bit ขีองขี)อม*ลั คำ2ณสมบ�ต random ใน keystream จะท�าลัาย

คำ2ณสมบ�ตเช้งสถึตขีอง plaintext (เช้�น คำวิามถึ !ขีองต�วิอ�กษ์รใน plaintext) โดิ์ยอ�ตโนม�ต

จะไม�ม การใช้)งาน Keystream ซ่�4า มฉะน�4นจะสามารถึหา plaintext ท !เคำยใช้) Key น�4นๆในการ encrypt ไดิ์)Ci = Pi XOR StreamKeyi

Page 6: Information system security wk4-cryptography-2

Faculty of Information Technology Page

Stream Ciphers คำ�า Secret Key ขีอง Stream Cipher ก1คำ(อ

คำ�า Seed ท !ป-อนให)ก�บต�วิสร)าง Pseudorandom Keystream

KeyStream Generator(Pseudorandom byte

generator)

+Plaintext

ByteStreamP

CiphertextByte

StreamC

KeyK

KeyStream Generator(Pseudorandom byte

generator)

+Plaintext

ByteStreamP

KeyK

ENCRYPTION DECRYPTION

Page 7: Information system security wk4-cryptography-2

Faculty of Information Technology Page

One-Time-Pad (OTP)

Stream Cipher ไดิ์)แรงบ�นดิ์าลัใจมาจาก One-Time-Pad (หร(อเร ยกวิ�า Vernam Cipher) ซ่�!งเป0นเทคำนคำการเขี)ารห�สท !เช้(!อวิ�าไม�สามารถึ break ไดิ์) (unbreakable cipher) ‣ Keystream ขีอง OTP เป0น random

number อย�างแท)จรง ไม�ไดิ์)สร)างมาจาก Secret Key ผ่�าน Pseudorandom number generator

‣ Secret Key ขีอง OTP คำ(อต�วิ Keystream ซ่�!งต)องม ขีนาดิ์ใหญ่�อย�างน)อยเท�าก�บ plaintext ท�าให) การสร)างระบบ OTP ท�าไดิ์)ยาก จ�งไม�เป0นท !นยมใช้)อย�างแพร�หลัายน�ก

Page 8: Information system security wk4-cryptography-2

Faculty of Information Technology Page

Stream Cipher Properties

ขี)อคำวิรคำ�าน�งในการสร)าง Stream Cipher‣ ใช้)ก�บการ Encryption ท !แต�ลัะคำร�4งจะท�างานเป0น

ระยะเวิลัายาวินาน ช้�วิงการท�างานยาวินานก�อนท !จะม การวินกลั�บมาท�าซ่�4าแบบเดิ์ม

‣ Keystream ท !สร)างจะต)อง random ให)มากท !ส2ดิ์ ย!ง random มากเท�าใดิ์ จะให)ระดิ์�บคำวิามปลัอดิ์ภั�ยส*งขี�4นเท�าน�4น

‣ Secret Key คำวิรม ขีนาดิ์ใหญ่� เพ!มป-องก�น Brute-force Attack โดิ์ยปกตจะไม�ต�!ากวิ�า 128 bits

แม)จะอาศั�ยการท�างานท !ง�ายแลัะซ่�บซ่)อนน)อยกวิ�า Block Cipher แต�ถึ)าออกแบบมาเหมาะสม Stream Cipher สามารถึให)คำวิามปลัอดิ์ภั�ยไดิ์)เท ยบเท�าก�บ Block Cipher ดิ์)วิย Key ขีนาดิ์เท�าก�น

Page 9: Information system security wk4-cryptography-2

Faculty of Information Technology Page

RC4 RC4 เป0น Stream Cipher ท !ออกแบบโดิ์ย

Ron Rivest ให)ก�บ RSA Security (Security Company)

ใช้) Key ท !ปร�บขีนาดิ์ไดิ์) (variable key size) ม การท�างานในระดิ์�บไบต� (Byte-oriented Stream Cipher) แลัะท�าการโดิ์ยอาศั�ยเทคำนคำ random permutation

RC4 เป0นท !นยมอย�างแพร�หลัาย ใช้)ในกลัไกการร�กษ์าคำวิามปลัอดิ์ภั�ยต�างๆ เช้�น SSL/TLS แลัะ wireless WEP

Page 10: Information system security wk4-cryptography-2

Faculty of Information Technology Page

RC4 Keystream Generation

RC4 สร)าง keystream จาก secret internal state ซ่�!งประกอบดิ์)วิย 2 ส�วิน ไดิ์)แก�‣ อาร�เรย� S ขีนาดิ์ 256 ไบต�: เก1บคำ�า

Permutation (สลั�บต�าแหน�ง) ขีองคำ�าท !เป0นไดิ์)ท�4งหมดิ์ขีองไบต� รวิม 256 bytes

‣ Pointer i แลัะ j: Pointer ขีนาดิ์ 8 bits ส�าหร�บเก1บต�าแหน�งบน S

Keystream Generation ประกอบดิ์)วิย 2 ขี�4นตอน ไดิ์)แก�‣ ใช้) Key (ปกตขีนาดิ์ต�4งแต� 40 – 256 bits) ในการ

ก�าหนดิ์คำ�าเร!มต)นให)ก�บอาร�เรย� S โดิ์ยผ่�าน Key Scheduling Algorithm (KSA)

‣ น�าอาร�เรย� S ท !ไดิ์)จากขี�4นตอนแรก มาสร)าง key stream โดิ์ยใช้) pseudo-random generation algorithm (PRGA)

Page 11: Information system security wk4-cryptography-2

Faculty of Information Technology Page

Key Scheduling Algorithm (KSA)

KSA ใช้)ในการก�าหนดิ์คำ�าเร!มต)นให)ก�บอาร�เรย� S โดิ์ยท�างานดิ์�งน 4‣ ขี�4นตอนแรก อาร�เรย� S จะถึ*กต�4งคำ�าให)สมาช้กแต�ลัะต�วิ

เก1บคำ�า byte ท !ม คำ�าเท�าก�บคำ�าต�าแหน�งขีองสมาช้กต�วิน�4นๆ (เช้�น S[0] เก1บ 00000000, S[1] เก1บ 00000001, ... ) เร ยกการจ�ดิ์เร ยงดิ์�งกลั�าวิวิ�า Identity Permutation

‣ ดิ์�าเนนการ 256 รอบ แต�ลัะรอบจะท�าการ Permute (สลั�บต�าแหน�ง) คำ�าใน S โดิ์ยน�าคำ�า Key มาผ่สม ดิ์�งน 4

for i from 0 to 255 j := (j + S[i] + key[i mod keylength]) mod 256 swap S[i] and S[j] endfor

for i from 0 to 255 S[i] := i endfor

Page 12: Information system security wk4-cryptography-2

Faculty of Information Technology Page

Pseudo-Random Generation Algorithm (PRGA) PRGA ใช้)ในการสร)าง Keystream

‣ ในแต�ลัะรอบขีองการท�างานขีอง PRGA จะสร)าง keystream ออกมา 1 byte ดิ์�งน�4น จ�านวินรอบในการท�างานจ�งขี�4นอย*�ก�บจ�านวิน Byte ขีอง Keystream ท !ต)องการใช้)ในการ encryption

Page 13: Information system security wk4-cryptography-2

Faculty of Information Technology Page

Pseudo-Random Generation Algorithm (PRGA) การท�างานขีอง PRGA เป0นดิ์�งน 4

‣ เร!มต)น ต�4งคำ�า pointer i แลัะ j ไวิ)ท !ต�าแหน�ง 0‣ แต�ลัะรอบขีองการท�างานขีอง PRGA ประกอบดิ์)วิย

• เลั(!อน i ไปทางขีวิา (แบบวิน) 1 ต�าแหน�ง จากน�4นอ�านคำ�า S[i] ออกมา

• เลั(!อน j ไปทางขีวิา (แบบวิน) เท�าก�บคำ�า S[i] ท !อ�านมาไดิ์) จากน�4นอ�านคำ�า S[j]

• สลั�บคำ�า S[i] แลัะ S[j]• คำ�าไบต�ขีอง Keystream รอบน�4นๆ เท�าก�บคำ�าใน

อาร�เรย� S ต�าแหน�งท ! (S[i] + S[j]) mod 256

i := 0 , j := 0 while GeneratingOutput: i := (i + 1) mod 256 j := (j + S[i]) mod 256 swap S[i] and S[j] K := S[(S[i] + S[j]) mod 256] output K endwhile

Page 14: Information system security wk4-cryptography-2

Faculty of Information Technology Page

Pseudo-Random Generation Algorithm (PRGA) แสดิ์งแต�ลัะรอบขีองการท�างานขีอง PRGA

Page 15: Information system security wk4-cryptography-2

Faculty of Information Technology Page

Attack on Cryptography

Cryptanalysis คำ(อกระบวินการท !ให)ไดิ์)มาซ่�!ง plaintext โดิ์ยท !ไม�ต)องทราบ Key ท !ใช้) เป0นการ break การ encrypt ซ่�!งแบ�งไดิ์)เป0น 3 ประเภัท‣ Ciphertext-only attack ม ciphertext ท !

encrypt จาก key เดิ์ ยวิก�น เป0นปรมาณมากพอท !จะสามารถึน�ามาวิเคำราะห�หา plaintext หร(อ key ไดิ์)

‣ Known-plaintext attack ม ท�4ง ciphertextแลัะ plaintext ท !มาจาก key เดิ์ ยวิก�น มากพอท !จะสามารถึน�ามาวิเคำราะห�หา key ไดิ์)

‣ Chosen-plaintext attack ม ท�4ง ciphertextแลัะ plaintext ท !มาจาก key เดิ์ ยวิก�น โดิ์ย attacker สามารถึเลั(อก plaintext เองเพ(!อป-อนเขี)าไปในระบบเพ(!อให)ไดิ์) ciphertextท !ส�มพ�นธ์�ก�บ plaintext น�4นๆ ใช้)เป0นขี)อม*ลัเพ!มเตมท !จะสามารถึน�ามาวิเคำราะห�หา key ไดิ์)

15

Page 16: Information system security wk4-cryptography-2

Faculty of Information Technology Page

Asymmetric Key Cryptography

(Public Key Cryptography)

Page 17: Information system security wk4-cryptography-2

Faculty of Information Technology Page

Asymmetric Key Cryptography

ขี)อเส ยขีอง symmetric key cryptography คำ(อ ท�4งผ่*)ส�งแลัะผ่*)ร�บต)องใช้) key เดิ์ ยวิก�นในการ encrypt แลัะ decrypt ท�าให)‣ ต)องม การแลักเปลั !ยน key ก�อนท !จะเร!มร�บส�งขี)อม*ลั

ท�าให)ย2�งยากหากผ่*)ร�บแลัะผ่*)ส�งไม�เคำยม ปฏิส�มพ�นธ์�ก�นมาก�อน

‣ ป;ญ่หาเร(!องการถึ*กดิ์�กจ�บ Key ‣ ป;ญ่หาเก !ยวิก�บการจ�ดิ์การ Key ท !ม อย*�เป0นจ�านวินมาก

เม(!อใช้)ในระบบใหญ่�‣ เน(!องจากท�4งผ่*)ร�บแลัะผ่*)ส�งถึ(อ key เดิ์ ยวิก�น ผ่*)ส�ง

สามารถึปฏิเสธ์การส�งขี)อม*ลัไดิ์) เน(!องจากผ่*)ร�บเองก1สามารถึสร)าง ciphertext ดิ์�งกลั�าวิขี�4นมาไดิ์)เช้�นก�น น�!นคำ(อ Symmetric Key Encryption ไม�สน�บสน2น non-repudiation

Asymmetric Encryption หร(อ Public Key Encryption ใช้) key ต�างก�นในการ encrypt แลัะ decrypt ขี)อม*ลั

17

Page 18: Information system security wk4-cryptography-2

Faculty of Information Technology Page

Asymmetric Key Cryptography

ระบบ cryptosystem แบบ asymmetric key cryptography แต�ลัะฝ่=ายจะถึ(อ key 2 อ�น ไดิ์)แก�‣ Public Key หร(อคำ ย�สาธ์ารณะ เป0น key ท !เผ่ยแพร�

เป0นสาธ์ารณะ ฝ่=ายอ(!นๆไดิ์)ร*)‣ Private Key หร(อคำ ย�ส�วินต�วิ เป0น key ท !เก1บไวิ)

ส�วินต�วิ เป0นคำวิามลั�บส�าหร�บแต�ลัะฝ่=าย ขี�4นตอนการ Encryption ประกอบดิ์)วิย

‣ ผ่*)ส�งขี)อม*ลั หา public key ขีองผ่*)ร�บ ซ่�!งประกาศัเป0นสาธ์ารณะ หร(อไดิ์)มาจากผ่*)ร�บก�อนหน)าน 4 จากน�4น encrypt ขี)อม*ลั ดิ์)วิย public key ขีองผ่*)ร�บ

‣ ผ่*)ร�บ decrypt ขี)อม*ลั ดิ์)วิย private key ท !ส�มพ�นธ์�ก�น

‣ บ2คำคำลัใดิ์ก1สามารถึ encrypt ขี)อม*ลัมาย�งผ่*)ร�บไดิ์) เพราะ public key เป0นสาธ์ารณะ แต�เฉพาะผ่*)ร�บเท�าน�4นท !ม private key แลัะสามารถึ decrypt ไดิ์)

18

Page 19: Information system security wk4-cryptography-2

Faculty of Information Technology Page

Asymmetric Key Cryptography

Page 20: Information system security wk4-cryptography-2

Faculty of Information Technology Page

Asymmetric Encryption

Public-Key Cryptosystem ม คำ2ณสมบ�ตดิ์�งน 4‣ เม(!อ encrypt ขี)อม*ลั เราจะไดิ์) ciphertext แลัะ

เม(!อ decrypt ขี)อม*ลัจะไดิ์) plaintext กลั�บออกมา

‣ ถึ)าม ท�4ง public key แลัะ private key เราสามารถึดิ์�าเนนการ encryption แลัะ decryption ไดิ์)อย�างง�ายดิ์าย

‣ การเป>ดิ์เผ่ย public key เป0นสาธ์ารณะ ไม�ท�าให)สามารถึคำ�านวิณหา private key ท !ส�มพ�นธ์�ก�นไดิ์)ง�ายๆ

20

Encryption

Decryption

Plaintext Ciphertext Plaintext

Public Key

E(P, PKreceiver) = C

P = PlaintextC = CiphertextPK = Public KeySK = Private Key

E(C, SKreceiver) = P

Private Key

Page 21: Information system security wk4-cryptography-2

Faculty of Information Technology Page

Public Key Cryptography

Public Key Cryptography ท�างานภัายใต)ทฤษ์ฎี ท !เร ยกวิ�า one-way function ‣ One-Way Function เป0นฟั;งก�ช้�นทาง

คำณตศัาสตร� ท !สามารถึคำ�านวิณไดิ์)ง�าย แต�ในทางตรงก�นขี)าม ถึ)าจะคำ�านวิณหาคำ�าเร!มต)นจากผ่ลัลั�พธ์�จะท�าไดิ์)ยากมาก เช้�น

‣ การคำ*ณ (Multiplication) เท ยบก�บ การหาต�วิประกอบ (Factorization)• ถึ)าต�4งต)นดิ์)วิย 12x12 เราสามารถึหาผ่ลัคำ*ณไดิ์)ง�าย

12x12 = 144• แต�ถึ)าต�4งต)นดิ์)วิย 144 เราหาไดิ์)ยากวิ�าเกดิ์จากการ

ดิ์�าเนนการใดิ์ เพราะ 144 = 12x12 = 144x1 = 24x6, …

‣ Exponential เท ยบก�บ Logarithms• ถึ)าต�4งต)นดิ์)วิย 3 ก�บ 6 เราสามารถึหาผ่ลัยกก�าลั�งไดิ์)ง�าย

36 =729 • แต�ถึ)าต�4งต)นดิ์)วิย 729 เราหาไดิ์)ยากวิ�าเกดิ์จากการ

ดิ์�าเนนการใดิ์ logx 729 = y (x=?, y=?)

21

Page 22: Information system security wk4-cryptography-2

Faculty of Information Technology Page

มาตรฐานการเขี)ารห�สขี)อม*ลั

RSA Algorithm Diffie-Hellman Algorithm (เหม(อนก�บท !

ใช้)ใน Key Exchange) Elliptic Curve Cryptography Digital Signature Algorithm

22

Page 23: Information system security wk4-cryptography-2

Faculty of Information Technology Page

RSA RSA คำดิ์คำ)นโดิ์ย รอน รเวิสต� (Ron Rivest)

อาดิ์ ช้าม ร� (Adi Shamir) แลัะเลั1น แอเดิ์ลัแมน (Len Adleman) ท ! MIT โดิ์ยท ! RSA มาจากนามสก2ลัขีองท�4ง 3 คำน

23

Page 24: Information system security wk4-cryptography-2

Faculty of Information Technology Page

ขี�4นตอนในการเลั(อกคำ ย�ขีอง RSA

เลั(อกเลัขีจ�านวินเฉพาะ (prime number) p แลัะ q ท !ม การต�างก�น‣ หลั�กในการเลั(อกต�วิเลัขีท�4งสองน 4คำ(อ ย!งมากย!งท�าให)

ยากต�อการถึอดิ์รห�สลั�บไดิ์) แต�ก1จะท�าให)การเขี)าแลัะถึอดิ์รห�สช้)าลัง

คำ�านวิณ n = pq คำ�านวิณ m = (p-1)(q-1) เลั(อกคำ�า e ท ! 1 < e < m แลัะต�วิหารร�วิมมาก

(gcd) ขีอง e ก�บ m เป0น 1 ดิ์�งน�4น e แลัะ m จ�งเป0นจ�านวินเฉพาะซ่�!งก�นแลัะก�น‣ หาโดิ์ยการส2�ม e แลั)วิทดิ์สอบวิ�า gcd(e, m) เป0น 1

หร(อไม� คำ�านวิณหาเลัขี d โดิ์ยท ! ed mod m = 1 Public Key = คำ�า (e, n) Private Key = คำ�า (d, n)

24

Page 25: Information system security wk4-cryptography-2

Faculty of Information Technology Page

ขี�4นตอนการเขี)าแลัะถึอดิ์รห�ส

RSA Encryption เม(!อต)องการส�งขี)อม*ลั M โดิ์ย M < n ในการเขี)า

รห�สน�4นจะใช้) Public Key (e, n) โดิ์ยใช้)ส*ตร ‣ Ciphertext C = Me mod n

RSA Decryption ถึอดิ์รห�ส ciphertext C โดิ์ยใช้) Private Key

(d, n) โดิ์ยใช้)ส*ตร ‣ Message M = Cd mod n

ต�วิอย�าง ‣ p = 5, q = 7, n = 35, m = 24‣ e = 5, d = 29

25

Page 26: Information system security wk4-cryptography-2

Faculty of Information Technology Page

ต�วิอย�างการเขี)ารห�ส n = 35, e = 5

26

Plaintext

M Me Ciphertext = Me mod n

L 12 248832

17

O 15 759375

15

V 22 5153632

22

E 5 3125 10

Page 27: Information system security wk4-cryptography-2

Faculty of Information Technology Page

ต�วิอย�างการถึอดิ์รห�ส n = 35, d = 29

27

Ciphertext

Cd M= Cd mod n

Plaintext

17 48196857210675091509141182522307000

12 L

15 12783403948858939111232757568359400

15 O

22 8.5164331908653770195619449972111e+38

22 V

10 100000000000000000000000000000

5 E