1
$\begingroup$

This question is quite related to this one, but I am looking for more details.

I am writing a very basic implementation to demonstrate how RSA works. My current implementation generates key pairs using 64-bit integers.

I am looking for the proper method to encrypt a string. I guess the bytes are packed together (32-bits) (smaller than the modulus value), then each packet is encrypted.

I would like to know if each packet is encrypted independently or if they are chained together.

$\endgroup$
  • $\begingroup$ Why don't you use GNU GMP library? Most of the functions that you write can be found on that library. modpow, mpz_probab_prime_p, extgcd, etc.. $\endgroup$ – kelalaka Dec 27 '19 at 23:22
  • $\begingroup$ Because I would like to remain very simple. $\endgroup$ – nowox Dec 27 '19 at 23:23
  • $\begingroup$ Notes: A) the C code shown is limited to 32-bit public modulus $n$, dues to the 64-bit limitation of res * a in modpow. B) 512-bit RSA was unsafe 20 years ago. C) The RSA paper shows a method to directly encipher text, but since it is deterministic, it allows a guess to be verified, which is a disaster in many common cases (names of a guy on the class roll..). D) Text encryption using RSA should RSA-encipher a random symmetric key used to encipher the text. $\endgroup$ – fgrieu Dec 27 '19 at 23:56
  • $\begingroup$ Could you have a look at the following answer about using RSA as a block cipher and see if it answers your question? Basically chaining is not performed, not even for textbook RSA. Note that asking for a code review is not on topic for this site. As there is no specific question about the code in the post either, I cannot migrate to SO. I'll remove the code from the question (you can still see or copy it if you look at the edits). $\endgroup$ – Maarten Bodewes Dec 28 '19 at 9:54
  • $\begingroup$ @Maarten-reinstateMonica Indeed the answer you mentioned helped me to understand that what I am looking for is not related to RSA but to the "Block cipher mode of operation" and therefore to ECB, CBC, CFB and OFB... $\endgroup$ – nowox Dec 28 '19 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.