Giter Site home page Giter Site logo

jna-gmp's Introduction

JNA GMP project

A Java JNA wrapper around the GNU Multiple Precision Arithmetic Library ("libgmp").

Features

The basic JNA GMP library; minimal dependencies.

Available on Maven central as com.squareup.jnagmp:jnagmp.

Example module that shows integrating JNA GMP with Bouncy Castle.

Available on Maven central as com.squareup.jnagmp:bouncycastle-rsa.

Contributors

Licensing

jna-gmp's People

Contributors

batmaninpink avatar dekobon avatar dependabot[bot] avatar dragonsinth avatar jacobwil avatar jakewharton avatar mkristian avatar ruescasd avatar swankjesse avatar thhofer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jna-gmp's Issues

java.lang.NoClassDefFoundError exception

Hi

Thanks for this great wrapper, first of all

The issue I've been messing around in a last couple of days is the exception mentioned in the subject, which is thrown in runtime. The trivial things like playing dependencies definitions and their scopes in pom.xml did not help, the local maven repositories and paths seem to be OK.
The stack is as the following:

Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class ```
com.squareup.jnagmp.LibGmp
	at com.squareup.jnagmp.Gmp.<init>(Gmp.java:175)
	at com.squareup.jnagmp.Gmp.<init>(Gmp.java:33)
	at com.squareup.jnagmp.Gmp$1.initialValue(Gmp.java:133)
	at com.squareup.jnagmp.Gmp$1.initialValue(Gmp.java:131)
	at java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:180)
	at java.lang.ThreadLocal.get(ThreadLocal.java:170)
	at com.squareup.jnagmp.Gmp.modPowInsecure(Gmp.java:95)

The relevant pom.xml section:

<dependencies>
		<dependency>
			<groupId>com.squareup.jnagmp</groupId>
			<artifactId>jnagmp</artifactId>
			<version>2.1.0</version>
		</dependency>
..........
		<dependency>
			<groupId>com.squareup.jnagmp</groupId>
			<artifactId>bouncycastle-rsa</artifactId>
			<version>2.1.0</version>
		</dependency>
</dependencies>

Any ideas?

Thanks

Not using the embedded library

We saw this internally when deploying.

2017-05-19T13:48:53,422  WARN [main] module.NativeRSAModule - Could not load native library for NativeRSAEngine, falling back to RSAEn
gine
java.lang.UnsatisfiedLinkError: Error looking up function '__gmpz_powm_sec': /usr/lib64/libgmp.so.3.5.0: undefined symbol: __gmpz_powm
_sec
        at com.sun.jna.Function.<init>(Function.java:208)
        at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:536)
        at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:513)
        at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:499)
        at com.sun.jna.Native.register(Native.java:1509)
        at com.squareup.jnagmp.LibGmp.load(LibGmp.java:70)
        at com.squareup.jnagmp.LibGmp.loadLibGmp(LibGmp.java:65)
        at com.squareup.jnagmp.LibGmp.<clinit>(LibGmp.java:52)
        at com.squareup.jnagmp.Gmp.<clinit>(Gmp.java:49)

Should GmpInteger be relaxed to allow negative numbers?

Originally, GmpInteger was restricted to non-negatives because the only implemented methods (modPowSecure, modPowInsecure) required all arguments to be non-negative (or in some cases, positive).

Now that we have some other methods in the library, we should consider relaxing this.

How to run on Windows?

What steps are necessary to use this library on Windows?

Apart from compiling a dll, what settings (PATH) and configurations have to be done?

Gmp.modPowInsecure() should support negative exponent.

  /**
   * Set rop to (base raised to exp) modulo mod.
   *
   * Negative exp is supported if an inverse base^-1 mod mod exists (see mpz_invert in Number
   * Theoretic Functions). If an inverse doesn't exist then a divide by zero is raised.
   */
  public static native void __gmpz_powm(mpz_t rop, mpz_t base, mpz_t exp, mpz_t mod);

We simply never call this with a negative exponent to avoid the possibility of raising a native exception. Someone would need to figure out how to allow the native exception to be raised, and safely trap it and convert the result into the appropriate ArithmeticException that BigInteger does in this case.

Consider having GmpInteger override certain BigInteger methods

For modPow, we did not override BigInteger due to subtle behavioral differences; for example BigInteger.mowPow() supports negative exponents, whereas our GmpInteger does not.

However, for things like modInverse(), it might be a reasonable straight up replacement.

Break apart GmpTest

A huge amount of line space in GmpTest is devoted to modPow, but we now have several other accessible methods. We should break this test class up by the method being tested, or at least into categories.

We probably want a base test class that implements:

  @BeforeClass public static void checkLoaded()
  @AfterClass public static void forceGc()

plz help me

image

I am currently also encountering problems with RSA algorithms that need to be optimized, and I was very excited to see this sdk, but my service is already online and the key cannot be modified.

So I am now running into a problem where the private BigInteger e; p; q; dP; dQ; qInv; has been lost.

But PKCS8Key encodedKey[] is stored normally, how can I use jnagmp with only this one key[] ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.