https://github.com/signalapp/curve25519-java
Pure Java and JNI backed Curve25519 implementation.
https://github.com/signalapp/curve25519-java
Last synced: 27 days ago
JSON representation
Pure Java and JNI backed Curve25519 implementation.
- Host: GitHub
- URL: https://github.com/signalapp/curve25519-java
- Owner: signalapp
- License: gpl-3.0
- Archived: true
- Created: 2015-01-06T01:51:19.000Z (about 11 years ago)
- Default Branch: main
- Last Pushed: 2022-04-29T21:12:41.000Z (over 3 years ago)
- Last Synced: 2024-06-26T00:22:51.982Z (over 1 year ago)
- Language: C
- Homepage:
- Size: 2.06 MB
- Stars: 229
- Watchers: 18
- Forks: 91
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-java - Curve25519
README
# curve25519-java
A Java Curve25519 implementation that is backed by native code when available, and
pure Java when a native library is not available. There is also a J2ME build variant.
## Installing
To use on Android:
```
dependencies {
compile 'org.whispersystems:curve25519-android:(latest version number here)'
}
```
To use from pure Java:
```
org.whispersystems
curve25519-java
(latest version number here)
```
To use from J2ME:
```
org.whispersystems
curve25519-j2me
(latest version number here)
```
The Android artifact is an AAR that contains an NDK-backed native implementation, while
the Java artifact is a JAR that only contains the pure-Java Curve25519 provider.
## Using
## Obtaining an instance
The caller needs to specify a `provider` when obtaining a Curve25519 instance. There are
four built in providers:
1. `Curve25519.NATIVE` -- This is a JNI backed provider.
1. `Curve25519.JAVA` -- This is a pure Java 7 backed provider.
1. `Curve25519.J2ME` -- This is a J2ME compatible provider.
1. `Curve25519.BEST` -- This is a provider that attempts to use `NATIVE`,
but falls back to `JAVA` if 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());
```
### Generating a Curve25519 keypair:
```
Curve25519KeyPair keyPair = Curve25519.getInstance(Curve25519.BEST).generateKeyPair();
```
### Calculating a shared secret:
```
Curve25519 cipher = Curve25519.getInstance(Curve25519.BEST);
byte[] sharedSecret = cipher.calculateAgreement(publicKey, privateKey);
```
### Calculating a signature:
```
Curve25519 cipher = Curve25519.getInstance(Curve25519.BEST);
byte[] signature = cipher.calculateSignature(secureRandom, privateKey, message);
```
### Verifying a signature:
```
Curve25519 cipher = Curve25519.getInstance(Curve25519.BEST);
boolean validSignature = cipher.verifySignature(publicKey, message, signature);
```
## License
Copyright 2015 Open Whisper Systems
Licensed under the GPLv3: http://www.gnu.org/licenses/gpl-3.0.html