379年前のアルゴリズムを使って RSA 暗号鍵を破った話

no extension

例によって Bruce Schneier さんの記事経由:

RSA 公開鍵暗号の仕組みについては結城浩さんの『暗号技術入門』の第5章に分かりやすく解説されているので,まずはそちらを参照のこと。

今回のポイントとなる部分だけ紹介すると RSA 公開鍵暗号の鍵ペアを生成する際には最初に2つの大きな素数 $(p,q)$ を用意する。 $(p,q)$ を掛け合わせた $N=p \times q$ は公開鍵にも秘密鍵にも使われる値だが「2つの大きな素数を合成した値を(元の素数を知らずに)因数分解するのは難しい」ため $N$ から秘密鍵を推測するのは難しいとされている。 当然ながら素数 $(p,q)$ の組み合わせは第三者に知られないよう管理する必要がある。

The security of RSA keys depends on the difficulty of factoring a key’s large composite number (usually denoted as N) to derive its two factors (usually denoted as P and Q). When P and Q are known publicly, the key they make up is broken, meaning anyone can decrypt data protected by the key or use the key to authenticate messages.

ただし,素数 $(p,q)$ が互いに近い値の場合は容易に因数分解できることも大昔から知られている。

Cryptographers have long known that RSA keys that are generated with primes that are too close together can be trivially broken with Fermat’s factorization method. French mathematician Pierre de Fermat first described this method in 1643.

Fermat’s algorithm was based on the fact that any odd number can be expressed as the difference between two squares. When the factors are near the root of the number, they can be calculated easily and quickly. The method isn’t feasible when factors are truly random and hence far apart.

で,実際に一部の暗号製品で「鍵サイズは大きいけど容易に破られる暗号鍵」を生成してしまうものがあったそうで,これは CVE-2022-26320 として詳細が公開されている。

The Rambus SafeZone Basic Crypto Module before 10.4.0, as used in certain Fujifilm (formerly Fuji Xerox) devices before 2022-03-01, Canon imagePROGRAF and imageRUNNER devices through 2022-03-14, and potentially many other devices, generates RSA keys that can be broken with Fermat’s factorization method. This allows efficient calculation of private RSA keys from the public key of a TLS certificate.

この脆弱性を報告した Hanno Böck さんは自身の記事の中で,更に SKS PGP 鍵サーバにも今回のような脆弱な RSA 公開鍵があったと言っている(実際に運用している鍵ではなさそうだが)。

Is PGP/GnuPG/OpenPGP affected?

I applied the algorithm to a dump of the SKS PGP key servers. I found four vulnerable keys. However all these keys had a user ID that did imply they were created for testing.

It is plausible that these keys were not generated by vulnerable implementations, but were manually crafted, possibly by people aware of this attack creating test data.

また,破られやすい素数の組み合わせとして

How “close” do primes need to be in order to be vulnerable?

With common RSA key sizes (2048 bit) in our tests the Fermat algorithm with 100 rounds reliably factors numbers where p and q differ up to 2^517. In other words it can be said that primes that only differ within the lower 64 bytes (or around half their size) will be vulnerable.

Up to 2^514 it almost always finds the factorization in the first round of the algorithm. It could be argued that the 100 rounds is therefore excessive, however the algorithm is so fast that it practically does not matter much.

と見積もっている。 ちなみに SSH で生成する RSA 鍵については

Is SSH affected?

There are probably no vulnerable SSH implementations creating such keys, though I obviously cannot proove that.

I checked multiple large collections of both SSH host and user keys. I did not find any vulnerable keys.

なんだそうな。 よかったね。

なお,記事の最後では

What do you recommend?

If you are running one of the affected devices you should make sure that you update the devices and regenerate the keys.

If you are in a position where external users will supply public RSA keys to you then you might want to implement checks for this vulnerability. A typical case for this are certificate authorities. I shared the exploit code with certificate authorities and are aware that some have implemented checks in their certificate issuance process to avoid accepting keys vulnerable to this attack.

You can find Let’s Encrypt’s implementation of the check in their Boulder software in this pull request.

と締めている。 今回のケースは暗号製品や CA など暗号鍵を提供・運用する側の問題でユーザ側でできることは殆どないだろうが,とりあえず怪しげな暗号製品は使うなっちうことやね(笑)

参考図書

photo
暗号技術入門 第3版 秘密の国のアリス
結城 浩 (著)
SBクリエイティブ 2015-08-25 (Release 2015-09-17)
Kindle版
B015643CPE (ASIN)
評価     

SHA-3 や Bitcoin/Blockchain など新しい知見や技術要素を大幅追加。暗号技術を使うだけならこれ1冊でとりあえず無問題。

reviewed by Spiegel on 2015-09-20 (powered by PA-APIv5)

photo
暗号化 プライバシーを救った反乱者たち
スティーブン・レビー (著), 斉藤 隆央 (翻訳)
紀伊國屋書店 2002-02-16
単行本
4314009071 (ASIN), 9784314009072 (EAN), 4314009071 (ISBN)
評価     

20世紀末,暗号技術の世界で何があったのか。知りたかったらこちらを読むべし!

reviewed by Spiegel on 2015-03-09 (powered by PA-APIv5)