SlideShare a Scribd company logo
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

PPTX
RSA and Elliptic Curve Cryptography
PPT
Digital Signature
DOC
11.第十一章用Matlab计算多元函数的积分
DOC
06.第六章用Matlab计算二重积分
DOC
12.第十二章用Matlab计算第二类积分
DOC
05.第五章用Matlab计算积分
PDF
PDF
Processing 03
RSA and Elliptic Curve Cryptography
Digital Signature
11.第十一章用Matlab计算多元函数的积分
06.第六章用Matlab计算二重积分
12.第十二章用Matlab计算第二类积分
05.第五章用Matlab计算积分
Processing 03

What's hot (20)

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

introduce RSA

Editor's Notes

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