information security - 密碼學介紹-對稱式金鑰 introduction to symmetric-key encryption...

35
密密密密密 ( 密密密密密 ) Author: 密密密 wing Blogger: http://autekroy.blogspot.tw/ Email: [email protected]

Upload: yao-jen-chang

Post on 19-Jun-2015

961 views

Category:

Education


6 download

DESCRIPTION

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 "Introduction to Symmetric Encryption Algorithm." 下面是我在大二上資訊安全的課程時所製作的上課報告投影片 這份主題是"密碼學介紹-對稱式金鑰"

TRANSCRIPT

Page 1: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

密碼學介紹

( 對稱式金鑰 )

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

Page 2: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

基本用語• 明文 :Plain text• 密文 :Cipher text• 加密 :Encryption/Encipherment

• 解密 :Decryption/Decipherment

• 加密金鑰 :Encryption key• 解密金鑰 :Decryption key

Page 3: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

資料和加密金鑰

明文Plain text

密文Cipher text

加密金鑰Encryption key

解密金鑰Decryption key

Page 4: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

加密方式分類

• 對稱式密碼系統 - 加解密用同一把鑰匙 ( 此次重點 )

• 非對稱式密碼系統 - 加解密用不同一把鑰匙

Page 5: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

加密方式分類

Page 6: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

對稱式加密• 金鑰數目 :n 人時,需要金鑰數目 = n(n-1)

2串流密碼 stream cipher:以 1 位元或 1 位元組的連續加密方式ex:Vernam Cipher

加密分類區塊密碼 block cipher: 將資料依一定長度 ( 區塊 ) 區分再加

密ex:DES

Page 7: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

古典加密

• 凱薩密碼• 替代密碼• 多字母密碼• 置換密碼

Page 8: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

凱薩密碼 (Caesar cipher)

• 對稱式 - 加密金鑰只有 25 種 !• 將明文各個字母依序推遲 n 個字母的加密

演算法 ex: n=3 時, AD,RU,XA,YB,ZC

EX: M O M O T A R O

P R P R W D U R

Page 9: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

替代密碼 (substitution cipher)

• 對稱式,將凱薩密碼變複雜

• 將明文各個字母推遲得字數有變化的加密演算法

• 將字母作一對一的轉換,即為代替法

• 加密金鑰有 26!種約 =4.0329 X 10^26

Page 10: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

多字母密碼 (polyalphabetic cipher)

• 對稱式,又稱多字母代替法、多字元加密法• 將每 n 個字母分割為一區塊,改變各區的文

字推遲數,擴張版的凱薩密碼• 金鑰數 =26^n

Ex : n=4第 1 個文字推遲 2 個字元第 2 個文字推遲 5 個字元第 3 個文字推遲 3 個字元第 4 個文字推遲 1 個字元

M O M O T A R O ( 明文 )

M O M O T A R O

O T P P V F U P ( 密文 )

Page 11: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

置換密碼 (transposition cipher)• 對稱式,又稱換位密碼、換位法• 將每 n 個字母分割為一塊,改變各區的文字

順序者• 金鑰數 =n!

Ex : n=4置換規則 = 1234

2413

第 1 個文字置換為第 2 個字元第 2 個文字置換為第 4 個字元第 3 個文字置換為第 1 個字元第 4 個文字置換為第 3 個字元

M O M O T A R O ( 明文 )

M O M O T A R O

O O M O A O T R ( 密文 )

Page 12: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

絕對安全的密碼• 弗納姆密碼 : Vernam Cipher• 一種串流密碼• 使用一次性密碼本 ( 以亂數為基礎 )• 即於明文中附加相同長度亂數列,因為沒

有其他可以對照的資料,所以沒法破解• Vernam 1917 年提出• Shannon 1949 證明不可能被破解

Page 13: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

近代加密 - 對稱式

• DES• 3DES• AES• IDEA• RC 系列算法(RC2/RC4)

Page 14: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

DES (Data Encryption Standard)

• DES 為早期最廣泛使用的對稱金鑰的演算法。

• 由 IBM 公司在 1970 年代所發展出的加密演算法並在 1977 年經美國國家標準局( NBS )採用為聯邦標準( FIPS PUB 46-2 )

• 在 2001 年, DES 作為一個標準已經被高階加密標準( AES )所取代。

Page 15: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

DES 原理• 利用 Shannon 的多重加密的觀念,並利用Confusion (混淆)與 Diffusion (散佈)等方式:將明文 (Plain Text) 轉換成其他格式,並散佈明文的每一個小部分擴散到密文的各部分以達到加密效果。

• 將原始資料「明文」弄得非常散亂,讓破解者無法利用統計方式或其他數學分析技巧將加密後的「密文 (Cipher text) 」還原成原來的明文。

• 採用 56 位元的金鑰來對 64 位元的資料區段進行加密,剩下 8 位元用於同位檢查

Page 16: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

DES 流程

透過 16 回合的運算 ( 位移 ) 所組成 :每一回合運算目的,在於將上一回所打散的明文在弄得更亂一些。

就是指每一次的運算相當於在明文中多加了一道鎖,因此經過DES 運算之後,其原始資料已被16 把鎖給保護住了。

Page 17: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

17

DES 之缺點• 加密與解密需用同一個 key:

所以在傳輸時,要如何使雙方都使用同一個 key ,為一重要問題。

• 容易攻破– 金鑰只有 56 bits ,資料區塊 為 64 位 元 :

因其中每個位元組 (8 bits) 皆 取 1 位 元 作 為 同 位(parity) 核 對故 有 效 鍵 長 56 位 元 ( 在其第 8 、16 、 24 、 32 、 40 、 48 、 56 、 64 為同位元檢查碼,同位元檢查碼沒有真正使用。 )

– 金鑰相當於猜測 256 種數據資料,很容易被破解– 因此專家認為金鑰應該考慮採用 Triple-DES 。

(3DES)

Page 18: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

3DES

• 1992 年,研究人員發現 DES 可以反覆使用來增加強度,因此 Triple DES 應運而生。 ( 運算 48 回合 )

• 3DES 可以使用二把或三把金鑰

• 比其它演算法較慢,類型: DES-EEE3 、 DES-EDE3 、 DES-EEE2 、 DES-EDE2

• 許多網路應用系統採用 3DES ,如 PGP 、 S/MIME

Page 19: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

3DES 流程加密流程 -K1 加密、 K2 解密、 K3 加密

Page 20: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

3DES- 金鑰長度• 三把金鑰 :K1( 加密 ) 、 K2( 解

密 ) 、 K3( 加密 )

• 二把金鑰, K1 和 K3 相同, K2 不同 金鑰長度 =56 X 2 = 112

• 三把金鑰, K1 、 K2 、 K3 全都不同 金鑰長度 =56 X 3 = 168

Page 21: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

AES(Advanced Encryption Standard)

• 進階加密標準 form Rijndael 演算法

• 來源 :NIST() 為了取代 DES 於 1997 年 4月正式公告徵求下一代的區塊加密碼器 AES ,以保護敏感(sensitive)但非機密 (unclassified) 的聯邦資料

• 2000 年 10月, NIST宣佈來自比利時 (Belgium) 的兩位密碼學者 Joan Daemen 、 Vincent Rijmen 所提出的 Rijndael 演算法贏得這項徵選活動並作為新一代的加密標準。

Page 22: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

AES• AES 和 Rijndael 加密法不完全一樣(實際應用

中二者可互換)• Rijndael 使用的密鑰和區塊長度可以是 32 位

元的整數倍,以 128 位元為下限, 256 位元為上限。

• AES 的區塊長度固定為 128  位元,密鑰長度則可以是 128 , 192 或 256 位元

• JAVA 有內建 128-bits 的實作

Page 23: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

AES

• 大多數 AES 計算是在一個特別的有限域完成

• AES 加密過程是在一個 4×4 的位元組矩陣上運作,這個矩陣又稱為 state ,其初值就是一個明文區塊

• Rijndael 加密法因支援更大的區塊,其矩陣行數可視情況增加

Page 24: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

AES

各輪 AES加密迴圈(除最後一輪)均包含之後 4個步驟 : (請與下頁的圖相互對照 )

1. AddRoundKey:矩陣中的每一個位元組都與該次回合金鑰( round key)做 XOR運算;每個子密鑰由密鑰生成方案產生。

2. SubBytes:透過一個非線性的替換函數,用尋找表的方式把每個位元組替換成對應的位元組。

3. ShiftRows:將矩陣中的每個橫列進行循環式移位4. MixColumns:為了充分混合矩陣中各個直行的操作。這個步驟使用線性轉換來混合每行內的四個位元組。最後一個加密迴圈中省略 MixColumns步驟,而以另一個 AddRoundKey取代。

Page 25: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

AES1 2

3 4

Page 26: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

DES 、 3DES 、 AES比較

Page 27: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

IDEA

• 由瑞士聯邦技術協會發展出來,解密方法與加密方法相同,只有 subkey選取方式不同(同一套系統可以加解密)

• Confusion (迷惑 ) :加密器的密文與明文之間的關係十分複雜,無法從數學上去描述,或從統計上去分析。

• Diffusion (擴散):明文中的任一位元及密鑰中的任一位元,都對全體密文位元有影響。

Page 28: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

IDEA

• 金鑰長度為 128-bit 對區塊為 64-bit 的明文

• key比較長,可以對抗暴力破解法

• 設計核心是建立在三種簡單的代數運算上1. 以位元為單位的 exclusive-OR ,以表示2.mod 216 運算:以 表示3.mod 216++1 運算:以⊙表示

Page 29: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

IDEA

8 次重複運算 +1 次變換運算

64-bits4*16-bits

每一回合: 6 keys最後一次: 4 keys6*8+4=52 (sub)keys

Page 30: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

IDEA-subkey 補充• 用了 52 個子密鑰 (8輪中的每一輪需要 6

個,其他 4 個用與輸出變換 )• 將 128- 位密鑰分成 8 個 16- 位子密鑰。 這些是算法的第一批 8 個子密鑰(第一輪六個,第二輪的頭兩個)。然後,密鑰向左環移 x 位後再分成 8 個子密鑰。 開始 4個用在第二輪,後面 4 個用在第三輪。 密鑰再次向左環移 25 位產生另外 8 個子密鑰,如此進行直到算法結束。

Page 31: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

IDEA 加解密流程

Page 32: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

RC 系列算法• 大名鼎鼎的 RSA三人組設計• 金鑰長度可變的串流密碼 • RC 系列算法可以使用 2048 位的密鑰,該

算法的速度可以達到 DES 加密的 10倍左右。

• RC2: 以連續的 64-bit 為單位的區塊密碼• RC4:單位不定的串流密碼 • 目前最流行的是 RC4 算法

Page 33: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

RC4

• 1987 年 RSA三人組中的 Ron Rivest 所設計

• 金鑰長度可變

• 目前還沒有發現密鑰長度達到 128 位的 RC4有重複的可能性

• RC4也是目前最安全的加密算法之一

Page 34: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

RC4-簡介算法• 算法有兩部分

• 1.初始化算法 : 將一個 256 字節 ( 長度不定,但一般為 256) 的初始數簇進行隨機攪亂

• 2.偽隨機子密碼生成算法 : 得到不同的子密鑰序列,將得到的子密鑰序列和明文進行 XOR 運算後,得到密文

Page 35: Information Security - 密碼學介紹-對稱式金鑰 Introduction to Symmetric-Key Encryption Algorithm

The endThank you very

much