Top Banner
非非非非非非非 -RSA Author: 非非非 wing Blogger: http://autekroy.blogspot.tw/ Email: [email protected]
49

Information security 密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

Jun 20, 2015

Download

Education

Yao-Jen Chang

Please see: http://autekroy.blogspot.tw/

This is my presentation PowerPoint for the information security course.
My apology for the viewers don't know Chinese.
The information security series in this blog are almost in Chinese.
The topic is "Non-Symmetric Encryption Algorithm - RSA."

下面是我在大二上資訊安全的課程時所製作的上課報告投影片
這份主題是"密碼學介紹-非對稱式RSA"
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

非對稱加密系統 -RSA

Author: 張耀仁 wingBlogger: http://autekroy.blogspot.tw/Email: [email protected]

Page 2: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

Outline_1

加密方式分類加密方式分類

RSA 歷史和優缺點RSA 歷史和優缺點

RSA 流程及運作原理RSA 流程及運作原理

RSA 詳述流程RSA 詳述流程

Page 3: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

加密方式分類

Page 4: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

加密方式分類 - 對稱式複習

對稱式加密體系 (Symmetric Key) :

• 加密金鑰和解密金鑰是相同的。• 為了安全性,密鑰要定期的改變。

• 對稱演算法速度快,所以在處理大量資料的時候被廣泛使用,其關鍵是保證密鑰的安全。

• 典型的演算法: DES 、 3DES 、 IDEA 、 AES 、 RC 系列

Page 5: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

加密方式分類 - 非對稱式非對稱式金鑰 (Asymmetric Key) 體系:

• 2 把 key( 鑰匙 )-public and private• Private key( 自己擁有 ) , public key( 發佈 )

• 兩把 key 有對應的關係,用公鑰加密的資料只有用私鑰才能解開。

• 自己加密的資料用 private key 簽署,擁有 public key 的人就使用它來驗證有效性

Page 6: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

加密方式分類 - 非對稱式非對稱式金鑰 (Asymmetric Key) 體系:

• 其效率低於對稱密鑰體系 ( 慢啊 ~)• 典型的演算法: RSA 、背包密碼, Elliptic Curve 等等。

• 最有影響的公鑰加密演算法是 RSA• 足夠位元數的 RSA 能夠抵抗到目前為止已知所有密碼

攻擊。

Page 7: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

Outline_1

加密方式分類加密方式分類

RSA 歷史和優缺點RSA 歷史和優缺點

RSA 流程及運作原理RSA 流程及運作原理

RSA 詳述流程RSA 詳述流程

Page 8: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

RSA 歷史• 1973 年,在英國通訊總部工作的數學家 Clifford Cocks 在一個內部

文件中提出了一個相應的演算法,但他的發現被列入機密,一直到 1997 年才被發表。

• RSA 算取自于它的創始人的名字 :– 於 1977 年,美國麻省理工學院 Rivest 、 Shamir 、 Adelman 3 位

教授所發表。– RSA 基於數學難題,具有大數因數分解。 – RSA 使用兩個密鑰: Public Key( PK) 與 Private Key(SK)

• 在電子商業中 RSA 被廣泛使用

• (1983 年 MIT 在美國為 RSA 演算法申請了專利。專利 2000 年 9 月 21 日失效。由於在申請專利前就已經被發表了,世界大多數地區不承認這個專利權 !)

Page 9: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

RSA 缺點question:

• 之前介紹的 DES 等算法跟 RSA 推算出的年代期時差不多,為什麼沒被普遍採用呢 ?

Answer:1. RSA 需要大數運算,計算量大, 1977 年電腦執

行 RSA 的效率遠低於 DES2. 早期 DES 用 IC 晶片作加解密,用硬體做設計與

演算,而 RSA 若用硬體做計算成本高出許多

Page 10: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

RSA 優點

• 如 DES 、 AES 等對稱式均一個缺點 : 須將解密的金鑰告訴對方!

傳輸密碼始終是一大問題,總不能將金鑰再加密一次吧 ( 這樣還是要再傳加密金鑰的金鑰! )

Page 11: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

RSA 優點• 雖然可以透過 KDC(key distribution center) 解

決,可是必須完全信賴 KDC 才行

• 非對稱式的一大優勢 : 不用傳解密的密碼!• 因未解密金鑰 (private key) 是自己獨有的!

In cryptography, a key distribution center (KDC) is part of a cryptosystem intended to reduce the risks inherent in exchanging keys. KDCs often operate in systems within which some users may have permission to use certain services at some times and not at others.

Page 12: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

Outline_1

加密方式分類加密方式分類

RSA 歷史和優缺點RSA 歷史和優缺點

RSA 流程及運作原理RSA 流程及運作原理

RSA 詳述流程RSA 詳述流程

Page 13: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

13

RSA 流程

Page 14: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

14

1.假設資料 (Data) 要由 A 傳至 B :• 由 B 用決定固定公式產生兩個 key( 之後詳述 )

• 一個為私鑰 Private Key ,只留在 B裡。• 一個為公開金鑰 Public Key

2.將這個 Public Key 透過網路丟給 A :

• 這個 Public Key 的特性是幾乎不可能反演算出Private Key

RSA- 運作原理

Page 15: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

3.A 將明文用 Public Key 加密:• 這個編碼密文一定得用 Private Key 才解得開。• 然後 A 將密文透過網路傳給 B 。

4.B 用 Private Key 將資料解碼。

RSA- 運作原理

如有第三者竊聽資料時:

只能得到 B 傳給 A 的 Public Key 和 A 用 Public Key編碼後的密文。沒有 Private Key ,第三者無法解碼,所以 RSA確實能防止第三者的竊聽。

Page 16: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

Outline_1

加密方式分類加密方式分類

RSA 歷史和優缺點RSA 歷史和優缺點

RSA 流程及運作原理RSA 流程及運作原理

RSA 詳述流程RSA 詳述流程

Page 17: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

RSA詳述 -產生兩把 key

• 公鑰是兩個正整數 (E,N)• 私鑰是一個正整數 (D)( 有些資料寫 (D,N))

1. 使用者秘密挑選兩個很大的質數 P,Q(例如 150 位數 )2. 然後相乘 N=P x Q ,N約 300 位數 (十進制 )3. 根據歐拉函數, <=N且與 N互質的整數個數為 (P-1)X(Q-

1)4. 再挑一個 E <=(P-1)X(Q-1) ,且 GCD(E, (P-1)X(Q-1))=1(即互質 )

5. 算出 D ,滿足 DXE mod((P-1)X(Q-1))=1 (D<=(P-1)X(Q-1))6. 記得將 N , Q銷毀

(後面有數學補充 !!!!!)

Page 18: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

RSA詳述 - 兩把 key舉例• 假設 P=7 , Q=17 , 挑 E=5• 現在 N=7*17=119, (P-1)=5 , (Q-1)=16

滿足 GCD(E,(P-1)*(Q-1))=GCD(5,6*16)=1• 所以公鑰 (E,N)=(5,119)

• 找一個 D 滿足 D*5 mod 96=1• 可用輾轉相除法直接算出 D=77• (77*5=385, 385 mod 96=1)• 所以司鑰 D=77

6*16

Page 19: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

RSA詳述 - 加解密• 公鑰 (E,N) ,私鑰 (D) ,明文 :M ,密文 :C• (當然明文要先轉為數字 n) (後面補充同餘 ≡ )• 加密公式 C= M^E mod N 或• 解密公式 M=C^D mod N 或 • 假設要傳送訊息M ,而 RSA 使用前題是 M<N ,所以

如果M長度很長可以切成數段加密, EX:8-bits 一段

• 加密時把明文分成塊,塊的大小可變,但不超過密鑰的長度。 RSA 把明文塊轉化為與密鑰長度相同的密文

Page 20: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

補充數學 - 同餘• 兩個整數 a , b ,若它們除以整數 m 所得

的餘數相等,則稱 a , b 對於模 m 同餘

• 記作

Page 21: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

RSA 系統詳述• 安全原理 : 兩個大樹相乘容易,分解難• 金鑰產生 :

① 使用者秘密挑選兩個很大的質數 P,Q(例如 150 位數 )② 選一個 E滿足 : GCD(E, (P-1)X(Q-1))=1

公鑰 (public key):E 與 N(N=P x Q)③ 用輾轉相除法,算出 D滿足 DXE mod((P-1)X(Q-1))=1

私鑰 (private key):D

• 加密 : 發文者收到 public key ,計算密文 C C= M^E mod N

• 解密 :收文者用自己的 private key ,計算明文 M M=C^D mod N

Page 22: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

補充數學 -條列• 歐拉函數 : 不大於 N且與 N互質的整數個數

為 (p-1)(q-1)

• 輾轉相除法 : 計算出密鑰 D滿足 D X E mod((P-1)X(Q-1))=1

• 費馬小定理 : 證明加解密這邊補充了一些數學,為避免打斷 RSA 介紹,數學的詳細內容都在放最後面

Page 23: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

Outline_2

攻擊 RSA攻擊 RSA

RSA 結論RSA 結論

RSA 應用RSA 應用

補充數學補充數學

Page 24: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

RSA 系統 - 安全度• 公鑰和私鑰都是兩個超大質數 (P,Q)的函數• 從一個密鑰和密文推斷出明文的難度等同於分解兩個大質數的積 N

• 偷聽者無法直接獲得密鑰 D。要獲得 D,可將 N分解為 P和 Q,這樣就可以藉由 D × E mod(p-1)(q-1))=1 並解出 D,導出明文。

• 至今沒有找到一個多項式時間的演算法來分解一個大整數的因子,也沒有人能證明這種演算法不存在。

• 至今沒有人能夠證明對 N進行因數分解是唯一的從 c導出明文的方法,但也沒有公開且更簡單的方法。

Page 25: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

攻擊 RSA

暴力攻擊 (Brute force)

• 逐一尋找可能的 P,Q ,因為 P,Q 大小差不多都是根號 N 。 EX:N 為 1024-bits ,可逐一嘗試 512-bits 的所有質數,若能用 N除盡就是P,也能找出 Q !

• 然後就破解啦!

Page 26: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

攻擊 RSA

數學攻擊法 (mathematical attacks)

• 攻擊方式有很多種,例如尋找大數分解法快速計算出 N ,或當私鑰 D<N^0.292 時,研究人員可用其他方法破解 RSA

• 比爆力快!

Page 27: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

攻擊 RSA

計時攻擊 (timing attack)

• 利用解密時間差異來猜測金鑰• 在 2進制中, bit=1 所花的運算時間比 bit=0 多• 若 1 多,則計算時間慢;若 1少,則計算時間

快• 若能得到多組訊息與其加密時間,就會有機會

可以反推出私鑰的內容。

Page 28: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

攻擊 RSA-結論• 目前都可以有效預防

• 只要 P,Q 夠大 (150 位 ) ,使得 N 足夠大(300 位 ) , RSA 系統便可安全使用

• 但是未來有更多的挑戰

Page 29: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

攻擊 RSA-結論 - 未來挑戰 1994 年 Peter Shor 證明一台量子計算機

可以在多項式時間內進行因數分解。 假如量子計算機未來成為可行的技術, Shor

的演算法可以淘汰 RSA 和相關的衍生演算法。(依賴分解大整數困難性的加密演算法)

假如未來找到一種有效的分解大整數的演算法的話,或假如量子計算機可行的話那麼就會展開一場密碼長度的競爭。

但那時,從原理上來說 RSA 是不可靠的。

Page 30: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

大數分解懸賞• RSA security 公司懸賞大數分解• N = P*Q

• 目前最大的數為 RSA-2048最大懸賞金額 US$200,000

• RSA 公司只是想宣導大數分解是很困難的!

Page 31: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa
Page 32: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa
Page 33: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

Outline_2

攻擊 RSA攻擊 RSA

RSA 結論RSA 結論

RSA 應用RSA 應用

補充數學補充數學

Page 34: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

• 對極大整數做因數分解的難度決定了 RSA 演算法的可靠性。

• 對一極大整數做因數分解愈困難, RSA 演算法愈可靠。

• 如果找到一種快速因數分解的演算法的話, RSA 加密的可靠性就會極度下降。 (找到如此演算法的可能性非常小 )

RSA-結論

Page 35: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

• 今天只有短的 RSA 金鑰才可能被強力解破。

• 針對 RSA 最流行的攻擊一般是基於大數因數分解。• 1999 年, RSA-155( 512 bits)被成功分解• 2002 年, RSA-158也被成功因數分解。• 2009 年 12 月 12 日,編號為 RSA-768 (768 bits, 232 digits)數也被成功分解。這一事件威脅了現通行的 1024-bit 密鑰的安全性,普遍認為用戶應儘快升級到 2048-bit或以上。

RSA-結論

Page 36: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

• 只要金鑰長度足夠長,加密的資訊實際上是不能被解破的。

• 1997 年後開發的系統,用戶應使用 1024 位密鑰,證書認證機構應用 2048 位或以上。

• 但在分布式計算技術和量子計算機理論日趨成熟的今天, RSA 加密安全性受到了挑戰。

RSA-結論

Page 37: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

Outline_2

攻擊 RSA攻擊 RSA

RSA 結論RSA 結論

RSA 應用RSA 應用

補充數學補充數學

Page 38: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

RSA 應用 -SSL

Page 39: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

RSA 應用 -SSL

• 由 Netscape 所發展,是介於 Application Protocol 和 TCP/IP 間一個公開的、公用的資料安全性之通訊協定。

• 為網路通信提供安全及數據完整性的一種安全協議,在傳輸層對網路連接進行加密。

• 可動態選擇加密的演算法(例如 RSA)• 功能有傳輸資料加密、連結伺服器之認證、確保

傳送信息之完整性等。

Page 40: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

RSA 應用 -SSL

• 左圖為一般的 TCP/IP 架構,右圖加入了一層SSL 。

• 由應用層送出的資訊經SSL 加密後,再送到傳輸層傳送

• 接收端接到傳輸層的封包後,經由 SSL 解密後,再傳到應用層

Page 41: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

RSA 應用 - 數位簽章• 非對稱式金鑰系統• 數位簽章的功能

1. 確認性 2. 不可否認性

雜湊演算法

M訊息M

MDS訊息M'DS 雜湊

演算法 =傳輸訊息

DS

?

加密 解密H

H'

M

DS系統 DS

系統 [U發送者 R, KU)

鑰匙配對

K私有鑰匙 R K公開鑰匙 U

Page 42: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

RSA 應用 - 數位簽章運作程序:

1. 先使用 hash function2. 我們用 private key 簽署簽章碼

對方用 public key 檢視簽章碼

Page 43: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

Outline_2

攻擊 RSA攻擊 RSA

RSA 結論RSA 結論

RSA 應用RSA 應用

補充數學補充數學

Page 44: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

補充數學 -歐拉函數• 不大於 N且與 N互質的整數個數為 (p-1)(q-1)• 為什麼 ??• 歐拉函數 φ(n) 是小於或等於 n 的正整數中與

n互質的數的數目。 又稱 φ函數、歐拉商數• φ(1)=1Ex:• 所以 φ(N)=φ(P*Q)=(P^1-1)(P-1)*(Q^1-1)(Q-1)

=1*(P-1)*1*(Q-1)

Page 45: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

補充數學 -輾轉相除法• 又稱歐幾里得演算法

• 由於每一步的餘數都在減小並且不為負數,必然存在第 N步時 rN等於 0 ,使演算法終止, rN−1  就是a 和 b 的最大公約數。其中 N 不可能無窮大,因為在 r0和 0 之間只有有限個自然數。

a = q0 b + r0

b = q1 r0 + r1

r0 = q2 r1 + r2

r1 = q3 r2 + r3

Page 46: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

補充數學 -輾轉相除法• 計算出密鑰 D滿足 D X E mod((P-1)X(Q-1))=1• 用擴充歐幾里得求出 X滿足 X*T mod N=1

Int t,n;( 已知 )Int a=n,b=t,s=0,x=1,q,r;While(1){ q=floor(a/b); r=a%b; if(r!=0) {a=b; b=r; s=x; x=s-q; } if(x<0) return x=x+n;}

Page 47: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

補充數學 -費馬小定理• 費馬小定理是數論中的一個定理• 假如 a 是一個整數, p 是一個質數 (素數 )

• a 是 p 的倍數,則

• 如果 a 不是 p 的倍數 [GCD(a,p)=1]則

Page 48: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

補充數學 -費馬小定理• 證明加解密,密文 C, 明文轉為的數字 n• 得到 n後,可以將原來的信息 m重新復原。• 解碼的原理是• 以及 E*D ≡ 1 (mod p-1) 和 E*D≡ 1 (mod q-

1) 。由費馬小定理可證明 和( 因為 p 和 q 是質數,且不同,所以互質 )

• 這說明 得證!

Page 49: Information security   密碼學介紹-非對稱式rsa, non-symmetric encryption algorithm - rsa

Thank you for your listening

資訊工程系 102級 -張耀仁wing