(Android) Networking and Cryptography Library (NaCL) JNI binding. JNI is utilized for fastest access to native code. Accessible either in Android or Java application. Uses SWIG to generate Java JNI bindings. SWIG definitions are extensible to other languages.
Java Shell Makefile Other
Clone or download
Latest commit 140b55c Aug 13, 2018
Permalink
Failed to load latest commit information.
example/Sodium Match example/Sodium/build.gradle to build.gradle. May 20, 2018
jni add secret stream methods Jul 4, 2018
keys gpg key Feb 20, 2017
libsodium @ c398a51 2.0.1 release Jul 7, 2018
src Merge pull request #112 from nieldeokar/patch-1 Jul 27, 2018
.gitignore gitignore jni/libsodiumjni.jnilib Dec 23, 2017
.gitmodules branch stable May 25, 2016
.travis.yml retry Jan 12, 2018
Dockerfile Merge pull request #71 from bufke/pwhash Jun 29, 2017
LICENSE Update LICENSE May 29, 2018
README.md Update README.md Jul 27, 2018
Vagrantfile vagrant disksize plugin and script Jul 7, 2018
after-success.sh no siging snapshot Dec 23, 2017
build-kaliumjni.sh verbose Jun 28, 2017
build-libsodium-host.sh adding build-libsodium-host.sh May 25, 2018
build-libsodiumjni.sh gradle build quiet Sep 2, 2016
build-linux.sh separate libsodium host build from gradle. move towards using libsodi… May 25, 2018
build-mac-travis.sh remove gradle compileNative_host from mac build May 25, 2018
build-mac.sh shorten mac time Jan 12, 2018
build.gradle license Jun 3, 2018
check-ndk-api.sh check ndk api Sep 2, 2016
commands.md git tag example Jul 7, 2018
dependencies-linux.sh maven download url Aug 13, 2018
dependencies-mac.sh mac build android dependencies install stdout to file due to too verbose Jul 2, 2018
dependencies.sh disable emulator for now Apr 12, 2017
docker-compose-build.yml docker compose run and build Dec 20, 2016
docker-compose.yml gpg key Feb 20, 2017
docker-copy-files-to-host.sh docker links Dec 13, 2015
download-gradle.sh yes sdkmanager license Jun 2, 2018
enter.sh linux build Feb 21, 2016
gradle.properties version 2.0.1 and bump to 2.0.2-SNAPSHOT Jul 7, 2018
install_docker.sh vagrant disksize plugin and script Jul 7, 2018
libsodiumjni.rb build mac with brew Feb 21, 2016
plugins-vagrant.sh vagrant disksize plugin and script Jul 7, 2018
pom.xml version 2.0.1 and bump to 2.0.2-SNAPSHOT Jul 7, 2018
release.txt mvn deploy jar Feb 17, 2016
setenv.sh remove tools.backup Jun 2, 2018
settings.xml snapshot deploys with travis Apr 13, 2017
singleTest.sh test script verbose Jun 28, 2017
submodule-update.sh verbose Jun 28, 2017
travis.sh shorten mac time Jan 12, 2018
update-android.sh android 27 Jun 2, 2018

README.md

This project is entirely maintained in my spare time. Donations are appreciated.

Bitcoin address: 1EC6j1f2sDGy9L8ma8FFfQyxt9mb9a6Xxy

Bitcoin Cash address: 1PSxB3DRCkeaZK7nSbJ1hoxbsWAXwM8Hyx

Ethereum address: 2f30c73e8d643356ebbcfee7013ccd03c05097fb

Peercoin address: PQUavHtRCLtevq75GhLCec41nvDtmM4wvf

Monero address: 48btz6nV4SjWyhDpkXrVVXAtgN6aStdnz8weMyB6qAMhhBVqiy1v3HC6XL1j7K27ZfFRhpw3Y4A4uE8o2PXMxFxY1Q5gGvW

Raiblocks address: xrb_1dxetbqeo38gcxejt8n6utajorrntbfrr1qftpw7qwarw6d8kp74fwmcuqi9

Build Status Maven Central

libsodium-jni - (Android) Java JNI binding to the Networking and Cryptography (NaCl) library

A Java JNI binding (to allow for Java and Android integration) to Networking and Cryptography library by Daniel J. Bernstein.

Why JNI and not JNA? JNI is much faster than JNA and JNI is faster than JNR.

If you do use this project in your research project, please do cite this repo. Thanks!

Credits to:

Installation

  • Java package is under org.libsodium.jni
  • Maven coordinates are in the Sonatype OSS repository

Android Archive (AAR)

<dependency>
    <groupId>com.github.joshjdevl.libsodiumjni</groupId>
    <artifactId>libsodium-jni-aar</artifactId>
    <version>2.0.1</version>
    <type>aar</type>
</dependency>

Java Archive (JAR)

<dependency>
    <groupId>com.github.joshjdevl.libsodiumjni</groupId>
    <artifactId>libsodium-jni</artifactId>
    <version>2.0.1</version>
    <type>jar</type>
</dependency>

Usage

Example invocations

  • import org.libsodium.jni.NaCl; (this calls System.loadLibrary("sodiumjni");)
  • call NaCl.sodium(). {whatever_method_you_want}
  • Note that Android allowBackup is set to false. WARNING Your application can override the allow backup, just be sure that there is no sensitive data or secrets that might be backed up. Option can be used with tools:replace="android:allowBackup"

Manual Compilation and Installation

MacOS Manual Compilation and Installation

Install brew

Run ./dependencies-mac.sh

Run ./build-mac.sh

Linux Manual Compilation and Installation

Run ./dependencies-linux.sh

Run ./build-linux.sh

Docker Container

The docker container is available from libsodium-jni which is a Automated Build.

Manual compilation and installation

Please refer to the docker build for the commands used to build.

Notes

Docker container

Vagrant

A Vagrantfile is available for those that would like to set up a virtual machine.

Example application

Clone the repo and import project from folder example/Sodium in Android studio (Android studio 2.1). Android studio will handle the rest. Compile and run. Tested to emulators down to Android Version 16.

Manual AAR usage

To use the AAR project as is (No .SO file imports needed).

It is also possible to build the AAR library yourself using the provided scripts linux or mac. After building the library open module settings and add the libsodium-jni-release.aar and/or libsodium-jni-debug.aar as a dependency.

Custom code usage

To use the library with your own custom code, skip the aar file and add

  1. The native .SO libraries in your project (Create jnilibs folder and make the required changes to the gradle file)
  2. Add the source code from the src folder and add your own additional code.

Issues / Improvements / Help Seeked

libsodium-jni is currently being used in production. Feedback, bug reports and patches are always welcome.

Everything has been tested and working on ubuntu 12.04 32bit and 64 bit, macos, and Android

gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 4524D716

SWIG Extensions

SWIG is used to generate the Java JNI bindings. This means that the same interface definition can be used to generate bindings for all languages supported by SWIG. The interface can be found here