マイナス記号は数値 , 空白は 0 を表している
Step 6. B ′ の各ベクトルのうち , Howgrave-Graham’s Lemma
(Lem. 7)
の条件を満たすベクトルを取り出す.
Step 7. Step 6.
で得たベクトルを多項式へと変換し, Unravelled Linearization
によって線形化された項をu = xy + 1
によって戻す. Step 8. Step 7.
で得た多項式のGr¨ obner
基底を計算する.
Step 9. Step 8.
で得た基底がx, y, z
の解を表していれば,
その解を 返す.
解がなければ,
解なしを出力する.
Shiho Midorikawa katagaitai workshop winter March 18, 2018 122 / 142
0CTF 2017 Finals: Authentication&Secrecy
このアルゴリズムを実装することで
, N 1 , N 2 , e
からd
が得られ, RSA
を破ることができる.
▶ CTF
中の問題リリースから論文検索,
実装,
デバッグ時間も含めて8
〜10
時間程度.
今回解くのに利用した論文は購入必須だが
, CTF
中は躊躇なく購入 ボタンを押す.
▶
結果的に解法に結びつかなかったとしても,
後から読める論文が 増えることになるので損はない.
▶
既に大学・研究機関・会社で論文誌の契約等がある場合には大い に活用すべき.
0CTF 2017 Finals: Authentication&Secrecy
蛇足
▶ CTF Crypto
の場合,
競技の一環としてコードを書くこと,
論文を多数短い時間で正確に意図をつかむために読むことが重要になる
.
⋆
そのため,
普通の文章の読み書き能力は高い方がよい.
▶
活字を読み慣れておくと論文を読む速度も上がりやすいため,
趣 味として小説を読むのは実は競技的にも有効.
Shiho Midorikawa katagaitai workshop winter March 18, 2018 124 / 142
Workshop
Workshop
今回紹介した手法が掲載されている論文は
2018/02/22
時点でSpringer
によって有料販売されているものしか存在しない.
▶
手法については今まで解説したとおりの手法であるため,
これを 参考に実装して欲しい.
Shiho Midorikawa katagaitai workshop winter March 18, 2018 126 / 142
Workshop
実際に
Coppersmith’s Method
の実装を書く際には,
得られた多項式 がHowgrave-Graham’s Lemma
を満たしているかどうかをチェックす ることはあまりない▶
得られた多項式のうち最初10
個を雑に取ってくるような実装を書 くことが多い.
また
,
行の入れ替えによって行列式・格子は変わらないため綺麗に三 角行列を作る必要はない.
▶
列についても同様.
単項式の並べ方は多少雑でもなんとかなる.
Workshop
理論的考察に自信がなければ
,
いくつかのパラメータを結果の目視確 認を用いてHeuristic
に設定してしまうのも手.
▶
これはハマると大変時間を吸い取られるため,
実装のデバッグが 完璧なときのみ用いる.
添字の範囲が
<
で指定されているのか≤
で指定されているのかの チェックは欠かさず行う.
▶
添字の数えはじめであったり,
横ベクトル/
縦ベクトルの差等細か いところでミスが起きやすいため,
「これを実装する」と決めた論文 は焦って実装せずに一度理論部分を読み通し,
紙の上で自分なりに整 理することを心がける.
Shiho Midorikawa katagaitai workshop winter March 18, 2018 128 / 142
Workshop
Python
のrange/xrange
関数の引数はミスしやすいので注意が必要.
▶ n ≤ i ≤ m
ならばrange(n, m+1)
▶
逆順(i = m, m − 1, ..., n)
の場合はrange(m, n-1, -1)
Workshop
SageMath
においてGr¨ obner
基底を用いる際のTips
整数係数多項式の場合
, Gr¨ obner
基底を求めるのにメモリ・CPU
を異 様に消費するようになることがある▶
おそらく整数が環であって除算が使えないためと思われる.
そのため.
除算が使えるように一旦対象となる多項式を有理数係数 多項式に変換し,
そのうえでGr¨ obner
基底を計算するようにすると よい.
▶
高速化のTips
としては,
デフォルトのアルゴリズムであるSingular
を用いるものからgiac
等他のアルゴリズムを用いるようにするというものもある
.
Shiho Midorikawa katagaitai workshop winter March 18, 2018 130 / 142
Workshop
実際
,
この問題を解いている当時整数係数多項式20
個によるGr¨ obner
基底を計算しようとしたところ, AWS
のメモリ128GB
イン スタンスを20
分ほどで使い切り,
強制終了された.
▶
有理数係数多項式へと変換することで,
これは1GB
以下に収まる ようになった.
▶
実行時間も2
分足らず程度まで改善されており, giac
を用いるこ とで更に高速になった.
SageMath
では,
以下2
行を挟むだけでよい.
vs = map(str, f.parent().gens())
f = PolynomialRing(QQ, vs)(f)
Workshop
消去式を用いる解法の場合
,
「格子基底の先頭からいくつの多項式に ついて」と限定した考察が多いかと思う.
▶
実際には全ての整数方程式同士の組み合わせを試して成功すれば よし,
という実装をすると解ける確率が気持ち程度上がる.
最初から綺麗に書こうとは思わずに
,
ある程度忠実に実装してバグを 減らすことは常々心がけていくべき.
▶
テストパラメータが論文に示されている場合は,
それを用いてassertion
を書いて確かめていく余裕を持つ.
Shiho Midorikawa katagaitai workshop winter March 18, 2018 132 / 142
Workshop
私が当時書いたソルバは以下の
URL
に存在する.
https://github.com/elliptic-shiho/ctf-writeups/blob/
gh-pages/content/ctf/2017/0CTF%20Finals/
cr1000-AuthenticationSecrecy/solve.sage
▶
少々汚い上に英語の誤りも存在するが,
当時のままということで ご容赦願いたい.
▶ Gr¨ obner
基底の計算にgiac
を用いているが,
手元にはおそらく入っ ていないと思われるため,
その場合’giac’
の部分を削除して動かし ていただきたい.
Workshop
今回解説したい内容については以上である
.
▶
もしも不明な点・誤り等あれば遠慮なく質問をお願いしたい.
Shiho Midorikawa katagaitai workshop winter March 18, 2018 134 / 142
参考文献 I
[Ale07] Alexander May.
Using LLL-Reduction for Solving RSA and Factorization Problems: A Survey.
LLL+25 Conference in honour of the 25th birthday of the LLL algorithm, 2007.
[BD99] Dan Boneh and Glenn Durfee.
Cryptanalysis of RSA with Private Key d Less than N 0.292 , pp.
1–11.
Springer Berlin Heidelberg, Berlin, Heidelberg, 1999.
[Bon99] Dan Boneh.
Twenty years of attacks on the rsa cryptosystem.
NOTICES OF THE AMS, Vol. 46, pp. 203–213, 1999.
参考文献 II
[CFPR96] Don Coppersmith, Matthew K. Franklin, Jacques Patarin, and Michael K. Reiter.
Low-exponent RSA with related messages.
In Advances in Cryptology - EUROCRYPT ’96, International Conference on the Theory and Application of Cryptographic Techniques, Saragossa, Spain, May 12-16, 1996, Proceeding, pp.
1–9, 1996.
[Cop96a] Don Coppersmith.
Finding a small root of a bivariate integer equation; factoring with high bits known.
In Advances in Cryptology - EUROCRYPT ’96, International Conference on the Theory and Application of Cryptographic Techniques, Saragossa, Spain, May 12-16, 1996, Proceeding, pp.
178–189, 1996.
Shiho Midorikawa katagaitai workshop winter March 18, 2018 136 / 142
参考文献 III
[Cop96b] Don Coppersmith.
Finding a small root of a univariate modular equation.
In Advances in Cryptology - EUROCRYPT ’96, International Conference on the Theory and Application of Cryptographic Techniques, Saragossa, Spain, May 12-16, 1996, Proceeding, pp.
155–165, 1996.
[Her11] Mathias Herrmann.
Lattice-based Cryptanalysis using Unravelled Linearization.
PhD thesis, 2011.
[HG97] Nicholas Howgrave-Graham.
Finding small roots of univariate modular equations revisited, pp. 131–142.
Springer Berlin Heidelberg, Berlin, Heidelberg, 1997.
参考文献 IV
[HG01] Nick Howgrave-Graham.
Approximate integer common divisors.
In Joseph H. Silverman, editor, Cryptography and Lattices, pp.
51–66, Berlin, Heidelberg, 2001. Springer Berlin Heidelberg.
[Hin07] Hinek, M. Jason.
On the Security of Some Variants of RSA.
PhD thesis, 2007.
[HM09] Mathias Herrmann and Alexander May.
Attacking power generators using unravelled linearization: When do we output too much?
In Mitsuru Matsui, editor, Advances in Cryptology – ASIACRYPT 2009, pp. 487–504, Berlin, Heidelberg, 2009.
Springer Berlin Heidelberg.
Shiho Midorikawa katagaitai workshop winter March 18, 2018 138 / 142
参考文献 V
[HM10] Mathias Herrmann and Alexander May.
Maximizing small root bounds by linearization and applications to small secret exponent rsa.
In Phong Q. Nguyen and David Pointcheval, editors, Public Key Cryptography – PKC 2010, pp. 53–69, Berlin, Heidelberg, 2010.
Springer Berlin Heidelberg.
[JM06] Ellen Jochemsz and Alexander May.
A strategy for finding roots of multivariate polynomials with new applications in attacking rsa variants.
In Xuejia Lai and Kefei Chen, editors, Advances in Cryptology – ASIACRYPT 2006, pp. 267–282, Berlin, Heidelberg, 2006.
Springer Berlin Heidelberg.
参考文献 VI
[KO08] Noboru Kunihiro and Kazuo Ohta.
RSA
暗号に対する格子理論に基づく攻撃.
Bulletin of the Japan Society for Industrial and Applied Mathematics, 2008.
[LLL82] A. K. Lenstra, H. W. Lenstra, and L. Lov´ asz.
Factoring polynomials with rational coefficients.
Mathematische Annalen, Vol. 261, No. 4, pp. 515–534, Dec 1982.
[May03] Alexander May.
New RSA Vulnerabilities Using Lattice Reduction Methods.
2003.
Shiho Midorikawa katagaitai workshop winter March 18, 2018 140 / 142