andrewkiluk / RSA-Library

This is a C library for RSA encryption. It provides three functions for key generation, encryption, and decryption.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem with exiting in rsa_modExp

sqbi-q opened this issue · comments

commented

Edit:
As shipof123 says, there is problem with rsa_modExp function, which is exiting when:
(b < 0 || e < 0 || m <= 0)

Everything compiles fine, but sometimes output of test.c is only showing half of prints:
primes are 74077 and 71537 Private Key: Modulus: 5299246349 Exponent: 3525860801 Public Key: Modulus: 5299246349 Exponent: 257 Original: 49 50 51 97 98 99

instead of:

primes are 25463 and 24793 Private Key: Modulus: 631304159 Exponent: 363523649 Public Key: Modulus: 631304159 Exponent: 257 Original: 49 50 51 97 98 99 Encrypted: 436385454 7093305 328497852 488616667 550174409 97597229 Decrypted: 49 50 51 97 98 99

Any solution?

I have the same issue

echo $? shows that it exited on an error, I'd run a debugger and step through it.

I analyzed it, and this is because the function long long rsa_modExp(long long b, long long e, long long m) fails if any of its parameters is 0, which is fairly often.
This would be fine if it didn't exit instead of aborting its function and provides no reason for the users to see

Hi, I seem to have resolved the issue by replacing long long with unsigned long long throughout the library. Need your feedback on this solution. I believe the multiplication in rsa_modExp(b * b % m, e/2, m), line 56 of rsa.c was causing the overflow.

change the line 56 of rsa.c into return ( rsa_modExp(((b % m) * b) % m, e/2, m) % m );

Hi, I seem to have resolved the issue by replacing long long with unsigned long long throughout the library. Need your feedback on this solution. I believe the multiplication in rsa_modExp(b * b % m, e/2, m), line 56 of rsa.c was causing the overflow.

yup what you said did work, still dont know why the dev did not care about the overflow issues....

hi, i have created a fork that adresses this issue and provides further encryption (OAEP): https://github.com/oskarvonephesos/RSA-Library