SlideShare a Scribd company logo
1 of 18
RSA
台科大資安研究社_楊明軒
題外話時間…
string  integer
•NTUST
•336422327124
•0x4e54555354
mod / 模數
•7 / 4 = 1 … 3
•7 mod 4 = 3
•11 / 3 = 3 .. 2
•11 mod 3 = 2
同餘 ≡
•≡ 表示同餘相等
•37 ≡ 13 (mod24)
•37 mod 24 = 13
•41 ≡ 17 (mod24)
•41 mod 24 = 17
回來看 RSA …
RSA
• 非對稱式/公開金鑰加密法
• 使用最廣的公開金鑰加密法
• 大數分解很難
• 量子電腦 / shor algorithm
Euler φ function
•若n為自然數
定義φ(n)為不大於n且與n互質的自然數的個數
•φ(5) = |{1 , 2 , 3 , 4}| = 4
•φ(6) = |{1,5}| = 2
•if p is prime , φ(p) = p-1
•gcd(p,q) = 1 , φ(pq) = φ(p) * φ(q)
Euler's theorem
•如果 a & m 是整數且 gcd(a,m) = 1
a^φ(m) ≡ 1 (mod m)
模逆/mod inverse
• Find x that a*x ≡ 1 (mod n)
• n 小可以直接求
• 費碼小定理/Fermat's little theorem
• 𝑎 𝑛−1 ≡ 1 (mod n)
• 𝑎−1 ≡ 𝑎 𝑛−2 (mod n)
• 擴展歐幾里得算法/輾轉相除法/Extended Euclidean algorithm
• 算 gcd :
• GCD(A,B) = GCD(B,A mod B)
• ax + ny = 1 , find x and y
模逆 in python
• RSA 中,用來求 d
RSA 產生 KEY 過程
1. 選 p , q (prime)
2. 算 n , n = p*q
3. 算 ∅(n) = (p - 1)*( q - 1) << p 不等於 q
4. 選e , 1 < e < ∅(n) , 滿足 gcd(∅(n) , e) = 1
5. 算 d , d 是 e 在 mod ∅(n) 下的乘法反元素
d ≡ ⅇ−1
( mod ∅(n) )
public key: ( e , n )
private key: ( d )
RSA 加解密
明文需小於 n
•加密: E(m) = m^e mod n
•解密: D(c) = c^d mod n
Crack RSA !?(in CTF)
• 可否分解 N ?
• 無法分解 N ,那可否直接算出 ∅(n) ?
• 無法分解 N 也無法直接算出 ∅(n) ,那可否直接求 d ?
• 都無法怎辦 ?...
Tool
• Website
• Factordb.com
• Tool
• Sage
• http://www.sagemath.org/
• Yafu
• General Number Field Sieve , GNFS
• http://sourceforge.net/projects/yafu/files/latest/download
• rsatool
• rsatool.py -p xxx -q xxx -o private.key
• https://goo.gl/h9fGki
Tool
• Python Library
• sympy
• gmpy2
• libnum
• https://github.com/hellman/libnum
RSA 潛在風險
RSA
潛在風險
分解因數
選擇密文
加密指數
廣播
相關訊息
short pad
解密指數
洩漏
低指數
明文
模數 共模攻擊
實作 p、q reuse
RSA 入門練習
•練習: ice ctf 2016 RSA
https://goo.gl/dMRXQj
•練習: ice ctf 2016 RSA?
https://goo.gl/Vph7le
•練習: ice ctf 2016 RSA2
https://goo.gl/BcHJSD

More Related Content

What's hot (20)

C++基礎程式設計 Zero judge介紹
C++基礎程式設計 Zero judge介紹C++基礎程式設計 Zero judge介紹
C++基礎程式設計 Zero judge介紹
 
Part 6 2010
Part 6 2010Part 6 2010
Part 6 2010
 
Python differential equation
Python differential equationPython differential equation
Python differential equation
 
Processing 04
Processing 04Processing 04
Processing 04
 
01.第一章用Matlab求极限
01.第一章用Matlab求极限01.第一章用Matlab求极限
01.第一章用Matlab求极限
 
09.第九章用Matlab求二元泰勒展开式
09.第九章用Matlab求二元泰勒展开式09.第九章用Matlab求二元泰勒展开式
09.第九章用Matlab求二元泰勒展开式
 
02.第二章用Matlab求导
02.第二章用Matlab求导02.第二章用Matlab求导
02.第二章用Matlab求导
 
Ch11 範例
Ch11 範例Ch11 範例
Ch11 範例
 
Ppt 167-173
Ppt 167-173Ppt 167-173
Ppt 167-173
 
07.第七章用Matlab解常微分方程
07.第七章用Matlab解常微分方程07.第七章用Matlab解常微分方程
07.第七章用Matlab解常微分方程
 
香港六合彩
香港六合彩香港六合彩
香港六合彩
 
香港六合彩
香港六合彩香港六合彩
香港六合彩
 
Fux8923
Fux8923Fux8923
Fux8923
 
Ch9 範例
Ch9 範例Ch9 範例
Ch9 範例
 
Pairing for beginneer
Pairing for beginneerPairing for beginneer
Pairing for beginneer
 
Processing 09
Processing 09Processing 09
Processing 09
 
Ch3 教學
Ch3 教學Ch3 教學
Ch3 教學
 
Func diff cal_exercise2-3
Func diff cal_exercise2-3Func diff cal_exercise2-3
Func diff cal_exercise2-3
 
P127 135 new
P127 135 newP127 135 new
P127 135 new
 
Ch4 習題
Ch4 習題Ch4 習題
Ch4 習題
 

introduce RSA

Editor's Notes

  1. https://goo.gl/8UaNUy
  2. 7^484 mod 10 = ?
  3. from Crypto.Util.number import * print long_to_bytes(pow(c,d,N))
  4. 交大腳本 https://goo.gl/cnmEE4