TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

RSA is deceptively simple and fun

157 pointsby mikecarltonover 1 year ago

14 comments

tptacekover 1 year ago
This is a fun exploit to code up, and, stealing a note from a workshop tutorial we found, we build up to it with an RSA parity oracle in Cryptopals 6:<p><a href="https:&#x2F;&#x2F;cryptopals.com&#x2F;sets&#x2F;6" rel="nofollow">https:&#x2F;&#x2F;cryptopals.com&#x2F;sets&#x2F;6</a><p>The parity oracle is much easier to code, but I&#x27;ve never seen it in the wild. BB&#x27;98 (the &quot;million message attack&quot;) on the other hand comes up all the time, even in new code; it&#x27;s deceptively tricky to prevent.<p>I think this bug is probably a contender for the top 3 practical cryptography vulnerabilities on the Internet. Its close cousin, Vaudenay&#x27;s CBC padding oracle, is a lock for #1. Then it&#x27;s just down to whether nonce reuse is #2 or #3.
评论 #39048211 未加载
lisperover 1 year ago
The basics of RSA are deceptively simple and fun but if you actually care about security then there are dozens of details you have to worry about which are deceptively nuanced and complicated. It&#x27;s fine to play around with toy implementations like this, but you should never ever use such an implementation in an application where security actually matters. (In fact, if security matters, you probably should not be using RSA at all because there are so many ways to shoot yourself in the foot with it if you are not extremely careful. ECDH and ECDSA are much better, especially when used with Edwards curves like Curve25519.)
评论 #39046444 未加载
评论 #39046016 未加载
评论 #39046493 未加载
coppsilgoldover 1 year ago
The way RSA key exchange has been implemented everywhere involves padding. RSA-KEM[1] has been available since forever and no padding is required, though no one uses it for some reason.<p>RSA-KEM is also trivial to implement as it&#x27;s virtually identical to textbook RSA, with the sole restriction that m has to be randomly sampled from 1 .. n-1. The shared secret (technically, the encapsulated key) is the hash of the randomly sampled number.<p>And just like that, no padding oracles or the headache of implementing padding in the first place.<p>[1] &lt;<a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Key_encapsulation_mechanism" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Key_encapsulation_mechanism</a>&gt; , &lt;<a href="https:&#x2F;&#x2F;datatracker.ietf.org&#x2F;doc&#x2F;html&#x2F;rfc5990" rel="nofollow">https:&#x2F;&#x2F;datatracker.ietf.org&#x2F;doc&#x2F;html&#x2F;rfc5990</a>&gt;
评论 #39046848 未加载
评论 #39049814 未加载
Tainnorover 1 year ago
One thing that many people aren&#x27;t aware of (even mathematicians writing textbooks) is that &quot;textbook&quot; RSA isn&#x27;t actually secure without random padding (it&#x27;s a theorem that deterministic ciphers can&#x27;t be semantically secure).
uticusover 1 year ago
I always wonder who&#x27;s watching the watchers with encryption. I know there are standard, recommended libraries available. But how are those vetted if mere mortals like myself don&#x27;t even know what known vulnerabilities to look for? Is there like a high council of crypto wizards that keep checks and balances on each other?
评论 #39047615 未加载
评论 #39047679 未加载
评论 #39048536 未加载
评论 #39046475 未加载
评论 #39046457 未加载
woodruffwover 1 year ago
Nice writeup, and the point (RSA <i>is</i> very simple, until you actually to need it securely!) is conveyed well.<p>One thing of note: BB98 essentially springs eternal; a new way to find the single bit of oracle state needed for it is discovered every few years. See ROBOT[1] (2018) and this year&#x27;s Marvin[2].<p>[1]: <a href="https:&#x2F;&#x2F;robotattack.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;robotattack.org&#x2F;</a><p>[2]: <a href="https:&#x2F;&#x2F;people.redhat.com&#x2F;~hkario&#x2F;marvin&#x2F;" rel="nofollow">https:&#x2F;&#x2F;people.redhat.com&#x2F;~hkario&#x2F;marvin&#x2F;</a>
mathiasgredalover 1 year ago
Could someone enlighten me on how one goes about testing whether a particular crypto implementation is vulnerable to side-channel attacks?<p>In high school I implemented a basic ECDH key exchange algorithm, which I compiled to WASM, and it can be tested at the bottom of my blog: <a href="https:&#x2F;&#x2F;gredal.dev&#x2F;projects&#x2F;elliptic-curves" rel="nofollow">https:&#x2F;&#x2F;gredal.dev&#x2F;projects&#x2F;elliptic-curves</a><p>Using only the WASM blob, without looking at the source code for exploits, how would Alice find Bobs private key?
评论 #39053123 未加载
评论 #39051879 未加载
vitiralover 1 year ago
I hear so much about &quot;side channel attacks&quot;, and I get why they are important if you don&#x27;t know what software is running on your computer. But are they important if you don&#x27;t run any outside code (not on the cloud, not running JavaScript in a &quot;container&quot;, etc?)<p>Are there other major reasons not to roll your own crypto besides &quot;you might do it wrong&quot;? Wouldn&#x27;t a fuzz tester (comparing your implementation to a known good one) be well adapted to making sure you didn&#x27;t do it wrong?
评论 #39051051 未加载
mo_42over 1 year ago
Only simple in what I call the first level of RSA. But all levels could be fun in an effortful sense.<p>1. Level: encrypting and decrypting a single number or a couple of characters using public and private keys in a couple of lines of code<p>2. Level: Follow mathematical proofs and understand why it&#x27;s theoretically secure<p>3. Level: come up with an implementation that can be used in production<p>I guess 1 takes minutes to implement, 2 takes days to understand, 3 weeks to implement assuming a standard programmer who hasn&#x27;t done security.
thatxlinerover 1 year ago
People have been talking about using ECC (elliptic-curve cryptography) instead of RSA but I can’t really find a way to use ECC for asymmetric encryption (not signing). I’m pretty sure only RSA (instead of ECC) can be used for asymmetric encryption (disregarding the quantum-resistant algorithms which I haven’t looked into), unless I’m missing something important?
评论 #39051582 未加载
评论 #39050553 未加载
xnaclyover 1 year ago
I wrote a similar blog post a while ago using python [1]. I however attacked RSA using prime number factorization.<p>[1]: <a href="https:&#x2F;&#x2F;xnacly.me&#x2F;posts&#x2F;2023&#x2F;rsa&#x2F;" rel="nofollow">https:&#x2F;&#x2F;xnacly.me&#x2F;posts&#x2F;2023&#x2F;rsa&#x2F;</a>
jbverschoorover 1 year ago
0 lessons learned in this write up without knowing almost everything about RSA..<p>Better watch some discrete math 2 videos from Kimberly Brehm or TrevTutor to see how you can actually compute it.
1000thVisitorover 1 year ago
Is no one going to point out the sloppy math in this equation?<p>42^3 = 138 mod 493<p>It should read<p>42^3 mod 493 = 138
stevefan1999over 1 year ago
Yes, RSA itself is as simple, you probably just need to know what a prime is, what is greatest common divisor (gcd) and what coprime means (gcd(a, b) = 1) and how Chinese Remainder Theorem (that Chinese nephew of Bézout&#x27;s Identity) works, and know a little bit of Euler&#x27;s totient theorem (also known as Euler&#x27;s Phi function) which can be optimized to Carmichael function (no need to know the proof just yet), then you should be able to understand RSA real good.<p>The reason RSA works because to crack RSA you need to solve the integer factorization problem which is sufficiently hard until lately (as it is a NP-intermediate problem, which is somewhere between NP-Complete and P-complete, and we don&#x27;t know whether P=NP yet...), but the key generation is pretty easy (as it can be done in polytime), and so this represents a trapdoor function [1].<p>Really it is just year 3 uni stuff that everyone has to exam with. I still remember having to do RSA manually on an exam paper and it sucked to be honest.<p>Mind you: RSA primes may not be unique if you have faulty implementation, because you can do semiprime by squaring a prime. Then you can get another pairs that are effectively the same that can spoof yours, although in reality this shouldn&#x27;t happen.<p>Alas, the problem is, RSA is not really invincible, as processing power doubled every few years thanks to Moore&#x27;s law, the problem of integer factorization is not that hard lately, so much so the RSA challenge was declared dead [2].<p>So, what did people do? They just turned to using bigger and bigger primes to mitigate this, but another problem is, finding primes that are big enough are also getting harder and harder, it takes more space as the bit size expands from RSA-1536 to RSA-8192.<p>Maybe it is fine for a Ryzen PC to do it with fine-tuned AVX2 vectorization to get instant prime generations (I think OpenSSL did that), for MCUs, smartphones and most importantly, smartcards (yes, RSA Security formed just to sell smartcards), that&#x27;s a no-go.<p>Do you want to see your RSA key goes into the range of Kilobytes and even Megabytes? Clearly not. And the gist is that this can&#x27;t go on forever and ever, not only that, it has been proven that by using a quantum computer, the problem of integer factorization was reducible to polytime [3], that also means you can crack RSA in polytime! All in theory of course, as quantum computers they are still in its infancy and it can crack no more than 128-bit for now, but the math tells the fact, many people bet it would catch up lately, and in order to get future proofed, RSA is considered a no-can-do now.<p>And instead, people started moving on to Elliptic Curve Cryptography (ECC) which I clearly lacked the fundamental knowledge to know, but you may need to know Group Theory, know what is finite field arithmetic, and what the heck is an Edwards curve. To this day, even Group Theory looked like a mindfuck to me. But I heard that&#x27;s what Math major students have to suffer along, packaged together with Abstract Algebra.<p>As I&#x27;m just a computer science John Doe who can barely navigate through the abstract algebra textbook, I can tell the pain.<p>N.B. Shor&#x27;s algorithm also spawned a whole slew of Post-Quantum Cryptography such as McEliece cryptosystem, and we are slowly turning into mindfuck category for crypto now. Wish it can be easier and simpler to understand and implement.<p>[1]: <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Trapdoor_function" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Trapdoor_function</a><p>[2]: <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;RSA_Factoring_Challenge" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;RSA_Factoring_Challenge</a><p>[3]: <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Shor%27s_algorithm" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Shor%27s_algorithm</a>
评论 #39051556 未加载