A Java Curve25519 implementation that is backed by native code when available, and pure Java when a native library is not available.
Just use Gradle, for example gradle compileJava or gradle jar to build jar.
Call it from the root of project:
mkdir native/build
cd native/build
cmake -DCMAKE_BUILD_TYPE=Release .. && cmake --build .
To run it call gradle jmh
The caller needs to specify a provider when obtaining a Curve25519 instance. There are
four built in providers:
Curve25519.NATIVE-- This is a JNA backed provider.Curve25519.JAVA-- This is a pure Java 7 backed provider.Curve25519.J2ME-- This is a J2ME compatible provider.Curve25519.BEST-- This is a provider that attempts to useNATIVE, but falls back toJAVAif the former is unavailable.
The caller specifies a provider during instance creation:
Curve25519 cipher = Curve25519.getInstance(Curve25519.BEST);
Since J2ME doesn't have built-in SecureRandom support, J2ME users need to supply their
own source of SecureRandom by implementing the SecureRandomProvider interface and
passing it in:
Curve25519 cipher = Curve25519.getInstance(Curve25519.J2ME, new MySecureRandomProvider());
Curve25519KeyPair keyPair = Curve25519.getInstance(Curve25519.BEST).generateKeyPair();
Curve25519 cipher = Curve25519.getInstance(Curve25519.BEST);
byte[] sharedSecret = cipher.calculateAgreement(publicKey, privateKey);
Curve25519 cipher = Curve25519.getInstance(Curve25519.BEST);
byte[] signature = cipher.calculateSignature(secureRandom, privateKey, message);
Curve25519 cipher = Curve25519.getInstance(Curve25519.BEST);
boolean validSignature = cipher.verifySignature(publicKey, message, signature);
Copyright 2015 Open Whisper Systems
Licensed under the GPLv3: http://www.gnu.org/licenses/gpl-3.0.html
Updated by Waves Platform in 2019-2020