Git Product home page Git Product logo

android_external_whispersystems_curve25519-java's Introduction

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:

<dependency>
  <groupId>org.whispersystems</groupId>
  <artifactId>curve25519-java</artifactId>
  <version>(latest version number here)</version>
</dependency>

To use from J2ME:

<dependency>
  <groupId>org.whispersystems</groupId>
  <artifactId>curve25519-j2me</artifactId>
  <version>(latest version number here)</version>
</dependency>

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.
  2. Curve25519.JAVA -- This is a pure Java 7 backed provider.
  3. Curve25519.J2ME -- This is a J2ME compatible provider.
  4. 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

android_external_whispersystems_curve25519-java's People

Contributors

moxie0 avatar

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.