附錄 密碼學基本觀.

Slides:



Advertisements
Similar presentations
第七课:电脑和网络. 生词 上网 vs. 网上 我上网看天气预报。 今天早上看了网上的天气预报。 正式 zhèngshì (报告,会议,纪录) 他被这所学校正式录取 大桥已经落成,日内就可以正式通车 落伍 luòw ǔ 迟到 chídào 他怕迟到,六点就起床了.
Advertisements

民族音乐与舞蹈艺术.
第6章: 完整性与安全性 域约束 参照完整性 断言 触发器 安全性 授权 SQL中的授权.
電子商務安全防護 線上交易安全機制.
質數的應用 – RSA加密演算法 國立中央大學 資工系 江振瑞.
Chapter 1: 概論 1.1 密碼學術語簡介及假設
-CHINESE TIME (中文时间): Free Response idea: 你周末做了什么?
计算机网络 第 7 章 计算机网络的安全.
電子資料保護 吳啟文 100年6月7日.
06資訊安全-加解密.
電子戶籍謄本申辦及驗證實務作業與問題討論
大專院校校園e 化 PKI、智慧卡應用與整合.
計算機概論 蘇俊銘 (Jun Ming Su) 資料加密技術簡介 計算機概論 蘇俊銘 (Jun Ming Su)
-Artificial Neural Network- Hopfield Neural Network(HNN) 朝陽科技大學 資訊管理系 李麗華 教授.
電子商務 11-1 電子商務概論 11-2 電子商務交易安全與 加密機制 11-3 電子商務交易付費機制
Subversion (SVN) Presented by 李明璋 R /2/21
公開鑰匙加密演算法 密碼學大革命 public key所想要解決的問題 public key密碼系統特性
Euler’s method of construction of the Exponential function
RSA-256bit Digital Circuit Lab TA: Po-Chen Wu.
Population proportion and sample proportion
密碼學簡介與簡單生活應用 Introduction to Cryptography & Simple Applications in Life 2010 Spring ADSP 05/07.
CJLR PDM&SRM 单点登录指南 场景一:在CJLR公司网络中(CJLR办公室/由VPN拨入),使用CJLR公司电脑登录:
資訊安全-資料加解密 主講:陳建民.
RSA Cryptosystem Theorem 1.3: For n = p * q p,q 均是質數
二、現代的加解密法:RSA 非對稱式密碼系統的一種。
Chapter 4 歸納(Induction)與遞迴(Recursion)
第三章 公钥基础设施PKI 本章学习重点掌握内容: 密码学基本术语 密码体制分类 私钥密码体制的主要特点 公钥密码体制的主要特点
非線性規劃 Nonlinear Programming
Module 2:電子商務之安全.
CH19資訊安全 認識資訊安全與其重要性 了解傳統與公開金鑰密碼系統, 以及基本的安全性觀念 了解訊息鑑別與雜湊函數 了解數位簽章法
資電學院 計算機概論 F7810 第十七章 資訊安全 陳邦治編著 旗標出版社.
我祝願你足夠 背景音樂-星空下的小喇叭【電影:亂世忠魂】 AUTO.
Decision Support System (靜宜資管楊子青)
创建型设计模式.
基礎密碼學 非對稱式金鑰加密法 樹德科技大學 資訊工程系 林峻立 助理教授.
第十二讲 数字签名算法 郑东 上海交通大学计算机科学与工程系.
子博弈完美Nash均衡 我们知道,一个博弈可以有多于一个的Nash均衡。在某些情况下,我们可以按照“子博弈完美”的要求,把不符合这个要求的均衡去掉。 扩展型博弈G的一部分g叫做一个子博弈,如果g包含某个节点和它所有的后继点,并且一个G的信息集或者和g不相交,或者整个含于g。 一个Nash均衡称为子博弈完美的,如果它在每.
客户服务 询盘惯例.
Decision Support System (靜宜資管楊子青)
Single’s Day.
解读设题意图,探究阅读策略 年高考试卷题型(阅读理解)分析及对策
Chapter 5 Recursion.
為何電子商務的安全性令人擔憂? 電子商務資訊安全 實體商務也擔心安全-但數位化的偽造數量會更多更快
Version Control System Based DSNs
公開金鑰密碼系統 (Public-Key Cryptosystems)
Guide to a successful PowerPoint design – simple is best
每周三交作业,作业成绩占总成绩的15%; 平时不定期的进行小测验,占总成绩的 15%;
中国科学技术大学计算机系 陈香兰 2013Fall 第七讲 存储器管理 中国科学技术大学计算机系 陈香兰 2013Fall.
虚 拟 仪 器 virtual instrument
Common Qs Regarding Earnings
公钥密码学与RSA.
成才之路 · 英语 人教版 · 必修1 路漫漫其修远兮 吾将上下而求索.
密碼學 Chapter 4 基於電腦的非對稱性金鑰密碼學演算法
中考英语阅读理解 完成句子命题与备考 宝鸡市教育局教研室 任军利
Chapter 3 What Is Money?.
應用加密技術 A 譚惠心 指導教授:梁明章教授.
浅析云计算中的密码技术 马春光 哈尔滨工程大学 教授、博导
高考应试作文写作训练 5. 正反观点对比.
WIRELESS LAN B 邱培哲 B 張宏安.
Outline Overview of this paper Motivation and Initialization
M; Well, let me check again with Jane
整合線上軟體開發工具、線上廣播與加密技術之軟體工程線上考試系統
 隐式欧拉法 /* implicit Euler method */
國立東華大學課程設計與潛能開發學系張德勝
為何電子商務的安全性令人擔憂? 第二節 電子商務資訊安全 實體商務也擔心安全-but數位化的偽造數量會很多 網際網路是互聯的(匿名與距離性)
Introduction to Computer Security and Cryptography
Computer Security and Cryptography
《现代密码学》导入内容 方贤进
Presentation transcript:

附錄 密碼學基本觀

加密與解密 密碼系統是由明文、加密演算法、金鑰、解密演算法及密文所組成 當加密金鑰與解密金鑰為同一把時,此密碼系統為對稱式密碼系統 金鑰用來和加密演算法產生特定密文的符號字串 金鑰是一組具有相當長度的數字或符號字串,其長度通常以位元為單位 金鑰是演算法內的一個變數,不同的金鑰將產生不一樣的密文 就密碼學而言,金鑰的長度越長,密文越安全 當加密金鑰與解密金鑰為同一把時,此密碼系統為對稱式密碼系統 當加密金鑰與解密金鑰不同時,此密碼系統為非對稱式密碼系統

加密與解密 加密演算法 解密演算法 密文 明文 If K=K’, symmetric (對稱) cryp’tography If K≠K’, asymmetric (非對稱) cryptography 加密演算法 解密演算法 Message M (plaintext) Encrypt cyphertext Decrypt Message M 密文 明文 Key K Key K’

完整性驗證 (Integrity Check) 為偵測所傳送出的訊息是否遭竄改,可實行完整性驗證 傳送者和接收者共享一把完整性驗證金鑰(integrity key) 訊息傳送者使用一個公開的訊息驗證函數(message authentication function)及其私密的完整性驗證金鑰,為即將外送的訊息計算其訊息驗證碼(Message Authentication Code, MAC) 訊息的送方將訊息與訊息驗證碼傳給訊息接收者 訊息接收者將所收到的訊息,以訊息驗證函數及其私密的完整性驗證金鑰產生出訊息驗證碼 訊息接收者比對自行產生的訊息驗證碼與所收到的訊息驗證碼是否一致 倘若一致,則判定所收到的訊息並未經過竄改

「完整性驗證」的本質為數位簽章(digital signature)機制

何謂「數位簽章」? An electronic signature that can be used to authenticate the identity of the sender of a message or the signer of a document, and possibly to ensure that the original content of the message or document that has been sent is unchanged. Easily transportable, cannot be imitated by someone else, and can be automatically time-stamped The originator of a message uses a signing key (Private Key) to sign the message and send the message and its digital signature to a recipient The recipient uses a verification key (Public Key) to verify the origin of the message and that it has not been tampered with while in transit

基本組成 (1/2) Digital signatures employ a type of asymmetric cryptography, typically consisting of 3 algorithms A key generation algorithm that selects a private key uniformly at random from a set of possible private keys. The algorithm outputs the private key and a corresponding public key. A signing algorithm that, given a message and a private key, produces a signature. A signature verifying algorithm that, given a message, public key and a signature, either accepts or rejects the message's claim to authenticity Hash value of a message when encrypted with the private key of a person is his digital signature on that e-document

基本組成 (2/2) Each individual (個體) generates his own key pair [public key, private key] Public key is known to everyone, private key only to the owner Private Key – Used for making Digital Signature Public Key – Used to verify the Digital Signature

fe1188eecd44ee23e13c4b6655edc8cd5cdb6f25 數位簽章例 I agree efcc61c1c03db8d8ea8569545c073c814a0ed755 My place of birth is at Gwalior. fe1188eecd44ee23e13c4b6655edc8cd5cdb6f25 I am 62 years old. 0e6d7d56c4520756f59235b6ae981cdb5f9820a0 I am an Engineer. ea0ae29b3b2c20fc018aaca45c3746a057b893e7 I am a Engineer. 01f1d8abd9c2e6130870842055d97d315dff1ea3 These are digital signatures of same person on different documents Digital Signatures are numbers Same Length – 40 digits They are document content dependent

「訊息摘要」演算法(Message-Digest Algorithm)確保簽署者身分與訊息的完整性 訊息摘要演算法亦稱為「雜湊」 演算法 (hash algorithm) Secret key and message are hashed together Re-computation of digest verifies that a message actually originated from the correct peer and was not altered in transit 著名範例: HMAC-MD5, HMAC-SHA Google可找到各種程式語言的實作 “Secret Key” Hash Function A message digest algorithm reduces a message of any length via rounds of compression permutations, to a string of fixed length called the message digest. The hash function is called a one-way function and it’s goal is to produce unique results. Collisions occur when more than one message can hash to the same message digest. The longer the message digest result, the less chance of collisions. The original hash algorithms have been enhanced by the addition of the secret key that is shared between the communicating parties. This key is hashed with the message to help provide uniqueness and authentication. These newer variations are called HMAC (Hash Message Authentication Code) algorithms. The MD5 (Message Digest 5) algorithm produces a 128 bit message digest, the SHA (Secure Hash Algorithm) yields a 160 bit result. See RFC 1321 MD5 for more detail. Hash

數位簽章的實作方式 (1/2) Message One-way function (單向函數): Easy to produce hash from message, “impossible” to produce message from hash Hash Function Alice A digital signature is an application in which the signer, “signs” a message in such a way that anyone can verify that the message was signed byno one but the sender, and consequently that the message has not been modified since it was signed. A digital signature usually involves a message-digest algorithm and a public-key (asymmetric) algorithm for encrypting the message digest. The entire message need not be signed. By using a one-way function—such as a hash function—it is possible to digest the entire message into a small string. The hash of the message can produces the digest, but given a digest, it is impossible to determine what the message was. Minute changes in message—added white space, lowercase letter changed to uppercase—will have demonstrable impact on digest Digest is signed and transmitted with message Hash of Message s74hr7sh7040236fw 7sr7ewq7ytoj56o457 Sign Hash with Private Key Signature = Encrypted Hash of Message 54 21 54

數位簽章的實作方式 (2/2):核驗是否相符 55 22 55 Decrypt the received signature Message Decrypt the received signature Signature Re-hash the received message Message with appended signature Message Signature Alice Hash Function Decrypt using Alice’s Public Key Upon receipt of a signed message, the digest is reproduced, and the signature is verified against this digest. Hash of Message Hash Message If hashes are equal, signature is authentic 55 22 55

RSA數位簽章演算法* 設h(M)代表訊息M的訊息指紋值,則RSA數位簽章的產生與檢驗可描述如下 (1) 產生RSA簽章:用私密金鑰d與公開金鑰n以下列公式計算簽章s (2) 檢驗RSA簽章:將收到的訊息M重新計算訊息指紋值h(M)。用私密金鑰e核驗,若且唯若下列公式成立則接受簽章,否則拒絕

可以OpenSSL實作數位簽章機制 OpenSSL is an open-source implementation of the SSL and TLS protocols Implements basic cryptographic functions and provides various utility functions Support various platforms (Unix/Linux/Windows) Can be invoked with command lines OpenSSL is mostly used on Unix. To use it on Windows, we need to install ActivePerl http://www.activestate.com/ActivePerl/ http://www.openssl.org Win32 OpenSSL (Windows version) http://www.slproweb.com/products/Win32OpenSSL.html

Environment Setup (1/2) Install ActivePerl (http://www.activestate.com/ActivePerl/)

Environment Setup (2/2) Install OpenSSL (http://www.openssl.org/) 下載、並利用WinRAR解壓縮至選定的目錄夾 (e.g. c:\openssl) 啟動MS-DOS視窗 之後,依序鍵入底 下命令 cd c:\openssl ms\bcb4

OpenSSL: 指令例 All the commands are placed in subdirectory OUT32 The following commands help familiarize yourself with common operations openssl des-ecb -e -in xxx.txt -out yyy.out -k password (DES encryption) openssl des-ecb -d -in yyy.out -out xxx.txt -k password (DES decryption) openssl aes-128-ecb -e -in xxx.txt -out yyy.out -k password (AES encryption) openssl aes-128-ecb -d -in yyy.out -out xxx.txt -k password (AES decryption) openssl genrsa -out rsa_privatekey.pem -passoutpass:password -des3 1024 (generate a RSA private key of 1024 bits) openssl rsa -in rsa_privatekey.pem -passinpass:password -pubout -out rsa_publickey.pem (generate the associated RSA public key) openssl rsautl -encrypt -pubin -inkeyrsa_publickey.pem -in xxx.txt -out yyy.txt (Encrypt file xxx.txt using a public key) openssl rsautl -decrypt -inkeyrsa_privatekey.pem -in yyy.txt -out xxx.txt (Decrypt file yyy.txt using a private key)

Key Generation, Signing Generate a file “privatekey.pem” to store the RSA private key and “publickey.pem” store the public key Private key generation openssl genrsa -out privatekey.pem Generate the public key associated with the given private key openssl rsa -in privatekey.pem -out publickey.pem -pubout -outform PEM Signing process To sign file “doc.txt”, compute the digest (hash) with the one-way hash function SHA-256 and then use “privatekey.pem” to generate the resulting signature. The output signature is stored in file “doc.sig” openssl dgst -sha256 -sign privatekey.pem -out doc.sig doc.txt PEM (Privacy Enhanced Email) is a special file format that accommodates cryptographic keys or certificates.

Signature Verification Anyone can verify the authenticity of the received message by checking if its signature is matched Provided file “doc.txt” and its associated signature file “doc.sig” , one can validate the signature using the public key stored in file “publickey.pem” and SHA256/RSA: openssl dgst -sha256 -verify publickey.pem -signature doc.sig doc.txt

Signature Verification Anyone can verify the authenticity of the received message by checking if its signature is matched What happens if we modify any content of file “doc.txt”? Suppose the text “This is a test” is changed to “That is a test” and then saved in another new file “doc2.txt”. Signature verification using “doc.sig” and “doc2.txt” fails!

參考資源 OpenSSL commands http://www.madboa.com/geek/openssl/ http://dsd.lbl.gov/~ksb/Scratch/openssl.html

How to Verify a Public Key? Two approaches: Before you use Alice’s public key, call her or meet her and check that you have the right one Fingerprint or hash of the key can be checked on the phone Find someone you already trust to certify that the key really belongs to Alice By checking for a trusted digital signature on the key Public key infrastructure

RSA (Rivest-Shamir-Adleman) Crypto Algorithms

Modulo Operations Let a,b  Z, m  Z+. Z+ = {n  Z | n > 0} = N−{0} Then a is congruent to b modulo m, written “a  b (mod m)”, iff m | ab Example ≡ 3 (mod 5) ≡ 2 (mod 5) ≡ 1 (mod 5) ≡ 0 (mod 5) ≡ 4 (mod 5) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

Inverse An inverse of a, modulo m is any integer a′ such that a′a ≡ 1 (mod m) If we can find such an a′, notice that we can then solve ax≡b by multiplying through by it, giving a′ax≡a′b, thus 1·x≡a′b, thus x≡a′b Theorem: If gcd(a,m)=1 and m > 1, then a has a unique (modulo m) inverse a′

Chinese Remainder Theorem (CRT, 中國餘數定理) Theorem: Let m1,…,mn > 0 be relatively prime. Then the system of equations x ≡ ai (mod mi) (for i = 1 to n) has a unique solution modulo m = m1·…·mn Proof: (略) Let Mi = m/mi. (Thus gcd(mi, Mi)=1) By theorem 3, yi=Mi′ such that yiMi≡1 (mod mi) Now let x = ∑i aiyiMi. Since mi|Mk for k≠i, Mk≡0 (mod mi), so x≡aiyiMi≡ai (mod mi) Thus the congruences hold. (Uniqueness is an exercise.) □

中國餘數定理 中國餘數定理源出三國或晉朝的「孫子算經」,其中有一題:今有物不知其數,三三數之賸二,五五數之賸三,七七數之賸二,問物幾何? 以同餘式表之,即解 。孫子算經給出答案 x = 23 解: x 的齊次解為105t,假設特別解為x=15a+21b+35c, 代入j,則35c ≡ 2 (mod 3) 取c = 1,代入k,則 b ≡ 3 (mod 5) 取b = 3,代入l,則 a ≡ 2 (mod 7) 取a = 2,所以x=30+63+35=128=105+23,可取x = 23 此即原式的特別解 ∴x=105t+23

Fermat’s Little Theorem (費瑪小定理) Fermat generalized the ancient observation that 2p−1≡1 (mod p) for primes p to the following more general theorem: Theorem: (Fermat’s Little Theorem) If ¬(p|a), then ap−1≡1 (mod p) Further, if p is prime and a is any non-negative integer, then ap≡a (mod p)

Rivest-Shamir-Adleman (RSA) The public key <n,e> The product n = pq (but not p and q), and An exponent e that is relatively prime to (p−1)(q−1) The private key consists of: A pair p,q of large random prime numbers, and d, an inverse of e modulo (p−1)(q−1), but not e itself To encrypt a message encoded as an integer M < n Compute C = Me mod n To decrypt the encoded message C Compute M = Cd mod n

Correctness of RSA Encryption: C = Me mod n Decryption: M = Cd mod n Theorem: (Me)d ≡ M (mod n). 證明方式如下: By the definition of d, we know that de ≡ 1 [mod (p−1)(q−1)] Thus by the definition of modular congruence, k: de = 1 + k(p−1)(q−1) So, the result of decryption is Cd ≡ (Me)d = Mde = M1+k(p−1)(q−1) (mod n) Assuming that M is not divisible by either p or q, Which is nearly always the case when p and q are very large Fermat’s Little Theorem tells us that Mp−1≡1 (mod p) and Mq−1≡1 (mod q) Thus, the following two congruences hold: Cd ≡ M·(Mp−1)k(q−1) ≡ M·1k(q−1) ≡ M (mod p) Cd ≡ M·(Mq−1)k(p−1) ≡ M·1k(p−1) ≡ M (mod q) Since gcd(p,q)=1, we can use the Chinese Remainder Theorem to show that Cd≡M (mod pq) If Cd≡M (mod pq) then s: Cd=spq+M, so Cd≡M (mod p) and (mod q). Thus M is a solution to these two congruences, so (by CRT) it’s the only solution.■