Top Banner
AES 函函函 Speaker : Chungyi Wang Advisor: Quincy Wu
24

AES 函式庫

Jan 25, 2016

Download

Documents

randi

AES 函式庫. Speaker : Chungyi Wang Advisor: Quincy Wu. outline. 加密的目的 加密法簡介 對稱式加密演算法 非對稱式加密演算法 (RSA) DES 簡介 AES 簡介 AES 函式庫 Demo Reference. 加密的目的. 純紙 本的時代 戰爭時傳遞訊息 電子資訊的時代 個人隱私資訊 特定接收者的保護 考量的因素 安全度 速度 鑰匙 (Key) 的型態. 對稱式加密演算法 (1/2). 鑰匙僅有一把 用此鑰匙對文件進行 加密 ,且用此鑰匙對加密過後的文件 解密 - PowerPoint PPT Presentation
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: AES  函式庫

AES 函式庫Speaker : Chungyi Wang

Advisor: Quincy Wu

Page 2: AES  函式庫

2007/10/4 2

outline

加密的目的 加密法簡介

對稱式加密演算法 非對稱式加密演算法 (RSA)

DES 簡介 AES 簡介 AES 函式庫 Demo Reference

Page 3: AES  函式庫

2007/10/4 3

加密的目的 純紙本的時代

戰爭時傳遞訊息 電子資訊的時代

個人隱私資訊 特定接收者的保護

考量的因素 安全度 速度 鑰匙 (Key) 的型態

Page 4: AES  函式庫

2007/10/4 4

對稱式加密演算法 (1/2)

鑰匙僅有一把 用此鑰匙對文件進行加密,且用此鑰匙對加密過後

的文件解密 凱薩加密法、 DES 、 AES… 等

凱薩加密法 從字母 (a~z) 挑選一個當作起頭,接著後面的進而

取代之

Page 5: AES  函式庫

2007/10/4 5

對稱式加密演算法 (2/2)凱薩加密法

a b c d e f g h i j k l m

a

n o p q r s t u v w x y z

a b c d e f g h i j k l m

u v w x y z a b c d e f g

n o p q r s t u v w x y z

h i j k l m n o p q r s t

明文: t e s t f o r t h i s

密文: n y m n z i l n b c m

。雙方事先溝通,或者是僅需知道字母 g 即可解密

。但是可能的排列只有 26 種,很容易被暴力法破解

Page 6: AES  函式庫

2007/10/4 6

非對稱式加密演算法 (RSA) (1/2)

鑰匙共有兩把 Public key ( 可公佈 ) Private key ( 私人擁有 )

非對稱 發送者用收件者的 Public key 進行加密 收件者則用自己的 Private key 進行解密

沒有該 Private key 則難以解開 運用兩個大的質數為原理作加密

http://zh.wikipedia.org/w/index.php?title=RSA&variant=zh-tw

Page 7: AES  函式庫

2007/10/4 7

非對稱式加密演算法 (RSA) (2/2)

加密

Receiver’s Private-key

解密

Page 8: AES  函式庫

2007/10/4 8

DES 簡介 1976 年被美國聯邦政府的聯邦信息處理標準

選中,其短密鑰長度 (56bits) 安全性備受外界質疑

DES 目前已經被視為一種不安全的加密方式 目前已經由 AES 取代之 相關資訊

http://zh.wikipedia.org/w/index.php?title=DES&variant=zh-tw

Page 9: AES  函式庫

2007/10/4 9

AES 簡介 (1/2)

Advanced Encryption Standard (AES) 亦稱 Rijndael 加密法

採用密鑰長度 16 、 24 or 32 bytes 由美國國家標準與技術研究院 ( NIST )於 2

001 年 11 月 26 日發佈,並在 2002 年 5 月 26日成為有效的標準

目前為夠安全的加密方法 沒有一個加密方法絕對安全,或者是永遠安全

Page 10: AES  函式庫

2007/10/4 10

AES 簡介 (2/2)

相較於 DES 密鑰長度較長,且 AES 可以選擇三種不同長度的加

密 ( 本報告選取的函式庫也支援 20 、 28bytes 的長度 )

AES 設計易於實作,且記憶體需求較小 縱然 Triple-DES 安全但速度比 AES 慢

詳細 AES 過程請於內容請參考 http://zh.wikipedia.org/w/index.php?title=

AES&variant=zh-tw

Page 11: AES  函式庫

2007/10/4 11

AES 函式庫 (1/12)

採用 之 AES 函式庫 http://fp.gladman.plus.com/cryptography_technolo

gy/rijndael/index.htm source code:

http://fp.gladman.plus.com/cryptography_technology/rijndael/aessrc.zip

此函式庫之優點: 程式獨立 檔案較小

Page 12: AES  函式庫

2007/10/4 12

AES 函式庫 (2/12)

加密流程Init

Fill rand

Read file

enc

Write file

一次讀取 16bytes一次加密一個區塊

From source

To encrypted

Page 13: AES  函式庫

2007/10/4 13

AES 函式庫 (3/12)

init aes_init

輸入 key 的型態為 char 且用 16 進位表示,於此步驟會檢查 key 是否符合正確型態,並且取得 key 的長度

aes_enc_key 所建立的的 key 會正確存入 ctx 結構當中,並且紀錄回

合以及加解密的所在區塊

關於加密或解密都是使用 aes_init 以及 aes_enc_key 來進行初始動作

Page 14: AES  函式庫

2007/10/4 14

AES 函式庫 (4/12) encrypt

CBC mode

from:http://upload.wikimedia.org/wikipedia/en/d/d3/Cbc_encryption.png

Page 15: AES  函式庫

2007/10/4 15

AES 函式庫 (5/12)

EBC mode

http://upload.wikimedia.org/wikipedia/en/c/c4/Ecb_encryption.png

Page 16: AES  函式庫

2007/10/4 16

AES 函式庫 (6/12)

aes_encode(…) do CBC chaining prior to encryption encrypt the block write data(dbuf by BLOCK_LEN) into file

Page 17: AES  函式庫

2007/10/4 17

AES 函式庫 (7/12)

1616

16

buf

dbuf

16buf

decrypt CBC(Cipher Block Chaining) chaining

for(i = 0; i < BLOCK_LEN; ++i)buf[i] ^= dbuf[i];

aes_enc_blk 對於已經設置好的區塊進行加密

write

Page 18: AES  函式庫

2007/10/4 18

AES 函式庫 (8/12)

dbuf

ctx

buf

write

dbuf : 加密用的陣列

buf : 明文陣列

dbuf

Page 19: AES  函式庫

2007/10/4 19

AES 函式庫 (9/12)

解密流程Init

First read

Read file

dec

Write file

一次讀取 16bytes一次解密一個區塊

From encrypted

To decrypted

Page 20: AES  函式庫

2007/10/4 20

AES 函式庫 (10/12)

b2

b2->b1

dbuf

http://upload.wikimedia.org/wikipedia/en/6/66/Cbc_decryption.png

b1

dbuf : 解密用的陣列

b2 : 密文陣列

b1 : 暫存陣列

ctx

Page 21: AES  函式庫

2007/10/4 21

AES 函式庫 (11/12)

init 與加密一樣也採用 aes_init 和 aes_dec_key 初始

aes_decode(…) decrypt input buffer unchain CBC using the last ciphertext block write data

Page 22: AES  函式庫

2007/10/4 22

AES 函式庫 (12/12)

decrypt aes_dec_blk(…); unchain CBC using the last ciphertext block

for(i = 0; i < BLOCK_LEN; ++i)dbuf[i] ^= b1[i];

write

Page 23: AES  函式庫

2007/10/4 23

Demo

執行結果 ./encode ./decode

程式說明 encrypt.c decrypt.c aesmatt.h

Makefile 必須加入必須的 obj

Page 24: AES  函式庫

2007/10/4 24

Reference 凱薩加密法

http://en.wikipedia.org/wiki/Caesar_Cipher RSA

http://zh.wikipedia.org/w/index.php?title=RSA&variant=zh-tw

DES http://en.wikipedia.org/wiki/Des

AES http://en.wikipedia.org/wiki/Aes

AES 函式庫 http://fp.gladman.plus.com/cryptography_technology/rijnda

el/index.htm 投影片範例:

http://ms11.voip.edu.tw/~chungyi/ncnu-research/aes/aesdemo.zip