kokke / tiny-bignum-c

Small portable multiple-precision unsigned integer arithmetic in C
The Unlicense
419 stars 86 forks source link

RSA does not work #13

Closed qdk0901 closed 4 years ago

qdk0901 commented 4 years ago

Hi, When I run the RSA test case, it output empty decrypt result.

kokke commented 4 years ago

Hi @qdk0901 and thanks for your interest in the project :)

The RSA-code works fine, but expects at least 2048bit bignums, and the default size is 1024. For this reason among others, I have commented-out the RSA-test in the Makefile (as you may have noticed).

I also did not want people to start writing cryptography code with this library. For crypto code, you want constant-time operations, which this module does not implement. That makes the code vulnerable to timing attacks, if used to implement crypto primitives, so beware :) Vanilla RSA also has many dangerous traps[1], so you should not use this for serious business.

However, to answer your question: You can change the default key-size from 1024 bits (128 bytes) to 2048 bits (256 bytes), by changing #define BN_ARRAY_SIZE (128 / WORD_SIZE) => #define BN_ARRAY_SIZE (256 / WORD_SIZE) in bn.h and that should make the RSA code work again.

Let me know if that works for you :)

[1] - Check out this blog-post on RSA for instance: https://blog.trailofbits.com/2019/07/08/fuck-rsa/

qdk0901 commented 4 years ago

Sorry for late reply. Yes, it works when I change key-size from 128 bytes to 256 bytes. This test case is great!

kokke commented 4 years ago

Hi @qdk0901 - no worries :)

I hope you got everything working as expected.