square / jna-gmp

A Java JNA wrapper around the GNU Multiple Precision Arithmetic Library.
Apache License 2.0
62 stars 24 forks source link

Fix for #13 #26

Closed thhofer closed 7 years ago

thhofer commented 7 years ago

Allow negative exponents in calls for modPowInsecure, by taking the modInverse of the base and negating the exponent. Yields the expected ArithmeticException when the value cannot be inverted.

thhofer commented 7 years ago

modPowInsecure(1, -1, 1) used to fail in the earlier version of libgmp I had (5.1.0). Took me a while to build the target version (6.1.1) on Windows (sigh). I've fixed the text values so that they make sense and work.

dragonsinth commented 7 years ago

Hi Thomas!

Thanks for the patch. I took a look, and it seemed like we could open this up even more. Take a look at https://github.com/square/jna-gmp/pull/27

I deleted some test code because I think those cases can now be handled by the small exhaustive tests.

dragonsinth commented 7 years ago

By the way, I think we'd be fine with a windows binary version, but up to now no one's come along and asked for it.

thhofer commented 7 years ago

Hi!

I've considered including the secure version here, but I feel this approach would leak the sign byte of the exponent to a timing attack. This might be acceptable but I didn't feel comfortable making this call on my own.