A minimal JNA wrapper around the GNU Multiple Precision Arithmetic Library ("libgmp").
##Features
The critical operation in RSA encryption and signing, libgmp's native implementation is signficantly faster and less CPU intensive than Java's implementation. Typical performance improvement would be on the order of 5x faster than Java.
- Use secure modPow for crypto. It's slower, but resistent to timing attacks.
- Use insecure modPow for non-crypto, it's faster.
A faster version of BigInteger.modInverse()
The GMP kronecker implementation generalizes jacobi and legendre symbols.
A very fast way to perform dividend / divisor
if and only if dividend % divisor == 0
.
That is, if the dividend
is a whole-number/integer multiple of divisor
, then exactDivide is
a much faster way to perform division. If the division operation does not follow the
dividend % divisor == 0
requirement then you will get the wrong answer and no error. This is a
limitation of the GMP function (this method is based on:
mpz_divexact
).
Finds the greatest common divisor of the two values that are input. It is exactly
analagous to BigInteger.gcd()
but much faster. When benchmarked with two 6148-bit values
(sharing a 3074-bit factor) the GMP implementation was about 20x faster.
##Notes
- The maven artifact/jar embeds a precompiled libgmp for some platforms. LibGmp will try to load the native library from the Java classpath first. If that fails, it falls back to trying a system-installed libgmp. We are missing binaries for many platforms.
Below are instructions for building the libgmp library that ships with this module
There is an included Dockerfile that can be used to compile libgmp with
First build the Docker image
docker build -t jnagmp-linux-x86-64 -f Dockerfile.linux-x86-64 .
Next run the Docker image which will execute the Makefile and output the compiled library in to src/main/resources
docker run -v $(pwd)/src/main/resources:/build/src/main/resources -t jnagmp-linux-x86-64