4 msΒ·
Part 2 of this article seems to explain that to encrypt arbitrary plaintexts, those larger than 256 bytes, you should chunk your messages up, pad the last block
by tptacek 5y ago
Part 2 of this article seems to explain that to encrypt arbitrary plaintexts, those larger than 256 bytes, you should chunk your messages up, pad the last block, and encrypt with RSA-ECB.
With the code presented here and in the last article, you can make a working RSA encryption & decryption application. However, it still lacks protection from side-channel attacks.
These articles are describing something now known as "textbook" or "schoolbook" RSA, which is worth looking up.
- criticaltinker 5y agoRelevant excerpt from stackexchange answer [1]: Some (Undesirable) Properties of Textbook RSA: It is malleable. I.e., if you give me a ciphertext π which encrypts π, I can compute πβ²β‘πβ 2πmodπ. When the owner of the private key decrypts πβ², she will get 2πmodπ. In other words, I can make predictable changes to ciphertexts. It is deterministic, and thus not semantically secure. I.e., I can distinguish between the encryptions of 0 and 1 (simply by encrypting both values myself and comparing the ciphertexts). Differences with Deployed RSA: Padding Chinese Remainder Theorem is sometimes used in deployed systems for more efficient decryption. π is often statically set to 65537=2^16+1 for encryption speed (since there are only two set bits in that number). Side-channel attack mitigations can be put in place for deployed systems too. [1] https://crypto.stackexchange.com/a/1449 https://crypto.stackexchange.com/a/1449
- olliej 5y agoI remember a cryptography project at uni where we had to implement RSA - that is everything including the large integer support. A portion of the grade was determined by the speed of your code. Because this was essentially only a course about number theory you can bet there were issues :) First: no symmetric crypto, just rsa applied block by block Second: no counter or chaining of blocks - eg encrypt(m) is the same for any m in the plaintext Third: because thereβs no symmetric cipher modular arithmetic becomes the overwhelming perf cost. My implementation had many many many possible timing attacks. Fourth: the same key pair was used for encryption and signing. This clearly results in sadness. Fifth: many of the implementations in the class operated performed an rsa operation for each byte in the input, making the lack of a proper block mode even worse. Mine operated at the maximum size the public key could handle, making it Secure (tm)!
- unbanned 5y ago
- olliej 5y agoGenuinely curious why you think this is pointless?
- st_goliath 5y ago> I remember a cryptography project at uni where we had to implement RSA - that is everything including the large integer support. Besides my day job, I'm still kinda-sorta fumbling around doing CS masters courses and ended up doing a similar project last semester. The project I was doing was actually about power analysis side channel attacks (in a group of CS students, I was the only one who would take a project where you had to touch actual hardware), so the end game was getting my make-shift 128 bit RSA to run on an AVR. The big-integer-code actually turned out to be the nastiest part of the whole thing. My initial naive implementation took several minutes on my desktop PC. A few long nights later, it ran in 30-ish seconds or so on the AVR, using the internal 1 MHz RC oscillator[1][2]. I initially expected the static power analysis to be a PITA, but finding the square-multiply-loop in the trace and triggering on it turned out to be surprisingly simple[3][4]. It was IMO kinda scary how easy that turned out to be. So yes, even if you get the obvious cryptographic foot guns right (as opposed to the additional non-obvious foot guns), the possibility for additional side-channel attacks are also plenty. [1] https://i.imgur.com/zk7IXKd.jpeg https://i.imgur.com/zk7IXKd.jpeg [2] https://i.imgur.com/Ddu2sgo.jpg https://i.imgur.com/Ddu2sgo.jpg [3] https://i.imgur.com/D1cMhzn.png https://i.imgur.com/D1cMhzn.png [4] https://i.imgur.com/rNnLJan.png https://i.imgur.com/rNnLJan.png
- commandlinefan 5y ago> The big-integer-code actually turned out to be the nastiest part of the whole thing I did a full TLS implementation from scratch a few years back - the big integer code was the nastiest part of all of TLS, including X.509 certificate parsing and validation.