Giter VIP home page Giter VIP logo

joshjdevl / libsodium-jni Goto Github PK

View Code? Open in Web Editor NEW
178.0 16.0 82.0 1.47 MB

(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.

License: GNU General Public License v3.0

Makefile 1.09% Shell 6.83% Java 91.26% Ruby 0.66% C 0.01% Dockerfile 0.16%
swig libsodium jni-bindings aar cryptography java nacl

libsodium-jni's Introduction

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
Raiblocks address: xrb_1dxetbqeo38gcxejt8n6utajorrntbfrr1qftpw7qwarw6d8kp74fwmcuqi9
Monero address: 48btz6nV4SjWyhDpkXrVVXAtgN6aStdnz8weMyB6qAMhhBVqiy1v3HC6XL1j7K27ZfFRhpw3Y4A4uE8o2PXMxFxY1Q5gGvW

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>

Android Gradle (AAR)

  1. Add library to dependencies:
// build.gradle
dependencies {
    ...
    compile 'com.github.joshjdevl.libsodiumjni:libsodium-jni-aar:2.0.1'
}
  1. To fix the warning allowBackup, add xmlns:tools="http://schemas.android.com/tools" and tools:replace="android:allowBackup" to your Manifest:
<!-- AndroidManifest.xml -->
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          package="com.name.myapp">
    <application
            ...
            tools:replace="android:allowBackup">
        <activity android:name=".MainActivity">
            ...
        </activity>
    </application>
</manifest>

Java Archive (JAR)

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

Usage

Java

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"

Kotlin

// MainActivity.kt

import org.libsodium.jni.SodiumConstants
import org.libsodium.jni.crypto.Random
import org.libsodium.jni.keys.KeyPair

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // Test Libsodium
        val seed = Random().randomBytes(SodiumConstants.SECRETKEY_BYTES)
        val encryptionKeyPair = KeyPair(seed)
        Log.i("PUBLIC KEY:", encryptionKeyPair.publicKey.toString())
    }
}

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

libsodium-jni's People

Contributors

alexkeramidas avatar bas-d avatar bufke avatar cameronhotchkies avatar codesorcery avatar dnet avatar folex avatar hbmartin avatar jeprojects avatar joshjdevl avatar kalaspuffar avatar lhunath avatar nieldeokar avatar nohum avatar pengj avatar ph0b avatar qmx avatar rmtmckenzie avatar saulshanabrook avatar schwamic avatar vipulnsward avatar vp-of-awesome avatar yekeskin 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  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  avatar  avatar  avatar  avatar  avatar  avatar

libsodium-jni's Issues

No other charset than US-ASCII

I'm trying to encrypt/decrypt strings that contains latin characters like รก,รฉ,รญ,รณ,รบ but when I decrypt I receive ? insted the latin character. I'm sure that's because the static CHARSET defined in Encoder.java.

sodium_version_string() crashes JVM

To reproduce:

     try {
            Method method1 = Class.forName("org.libsodium.jni.SodiumJNI").getMethod("sodium_init");
            int res = (int)method1.invoke(null);

            Method method = Class.forName("org.libsodium.jni.SodiumJNI").getMethod("sodium_version_string");
            method.invoke(null);

        } catch (Exception ex) {}

Crashes on last call with:

A/art: art/runtime/java_vm_ext.cc:410] JNI DETECTED ERROR IN APPLICATION: attempt to return an instance of java.lang.String from byte[] org.libsodium.jni.SodiumJNI.sodium_version_string()

java.lang.UnsatisfiedLinkError using project in tests

I have the following issue when trying to test the code via unit tests.

java.lang.UnsatisfiedLinkError: no sodiumjni in java.library.path

	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
	at java.lang.Runtime.loadLibrary0(Runtime.java:870)
	at java.lang.System.loadLibrary(System.java:1122)
	at org.libsodium.jni.NaCl.<clinit>(NaCl.java:29)

I include the library in my Android project like so:

build.gradle:

dependencies {
  ...

  compile 'com.github.joshjdevl.libsodiumjni:libsodium-jni-aar:1.0.7'

  ...

  testCompile 'com.google.guava:guava:18.0'
  testCompile 'junit:junit:4.10'
}

I have also tried using the non aar version, but to no avail.

Anyone know how to solve this? Do I need to just build the project manually? Building/running tests using Android Studio on a Mac.

Failed to run on OSX 10.11

I got:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x000000010cb2cf54, pid=90574, tid=0x0000000000001003
#
# JRE version: Java(TM) SE Runtime Environment (8.0_112-b16) (build 1.8.0_112-b16)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.112-b16 mixed mode bsd-amd64 compressed oops)
# Problematic frame:
# V  [libjvm.dylib+0x31ff54]
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#

I edited build.gradle to build on mac

defaultConfig {
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        ndk{
            abiFilters "x86", "x86_64"
        }
    }
jdk {
        headers.srcDir "${System.getenv("JAVA_HOME")}/include"
        // this seems to be host OS dependent, but should be host OS independen
        headers.srcDir "${System.getenv("JAVA_HOME")}/include/linux"
        headers.srcDir "${System.getenv("JAVA_HOME")}/include/darwin"
}
binaries.all {
          // -Bsymbolic is gcc only
          // to work around error "shared library text segment is not shareable"
          linker.args "-Wl"
}

sodium_init()?

Hi,
I was wondering how kalium is dealing with the need to call sodium_init() before usage of any function? In particular i think I'm missing the point where the number generator gets initialized? It doesn't seem possible to do that on my own, is this done automatically? Is there any possibility to inject a seed for the random number generator?

Thanks for your help.

Compatibility with libsodium 0.5.0

Is there any chance to get KaliumJNI working with latest stable libsodium 0.5.0? The Error occured after executing "ndk-build" for arm arch on Debian Jessie. The libsodium 0.4.5 is just working fine...

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.380s
[INFO] Finished at: Tue Jun 03 16:35:01 CEST 2014
[INFO] Final Memory: 15M/178M
[INFO] ------------------------------------------------------------------------
[armeabi] Compile thumb  : testjni <= sodium_wrap.c
In file included from /installs/android-ndk-r9c/platforms/android-3/arch-arm/usr/include/linux/stddef.h:21:0,
                 from /installs/android-ndk-r9c/platforms/android-3/arch-arm/usr/include/linux/posix_types.h:15,
                 from /installs/android-ndk-r9c/platforms/android-3/arch-arm/usr/include/sys/types.h:37,
                 from /installs/android-ndk-r9c/platforms/android-3/arch-arm/usr/include/strings.h:42,
                 from /installs/android-ndk-r9c/platforms/android-3/arch-arm/usr/include/stdlib.h:42,
                 from jni/sodium_wrap.c:136:
/installs/android-ndk-r9c/platforms/android-3/arch-arm/usr/include/linux/compiler.h:25:31: warning: ISO C does not permit named variadic macros [-Wvariadic-macros]
jni/sodium_wrap.c: In function 'Java_org_abstractj_kalium_SodiumJNI_crypto_1hash_1sha256_1ref':
jni/sodium_wrap.c:800:3: warning: implicit declaration of function 'crypto_hash_sha256_ref' [-Wimplicit-function-declaration]
jni/sodium_wrap.c: In function 'Java_org_abstractj_kalium_SodiumJNI_crypto_1hash_1sha512_1ref':
jni/sodium_wrap.c:830:3: warning: implicit declaration of function 'crypto_hash_sha512_ref' [-Wimplicit-function-declaration]
jni/sodium_wrap.c: In function 'Java_org_abstractj_kalium_SodiumJNI_crypto_1box_1curve25519xsalsa20poly1305_1ref_1keypair':
jni/sodium_wrap.c:900:3: warning: implicit declaration of function 'crypto_box_curve25519xsalsa20poly1305_ref_keypair' [-Wimplicit-function-declaration]
jni/sodium_wrap.c: In function 'Java_org_abstractj_kalium_SodiumJNI_crypto_1box_1curve25519xsalsa20poly1305_1ref':
jni/sodium_wrap.c:960:3: warning: implicit declaration of function 'crypto_box_curve25519xsalsa20poly1305_ref' [-Wimplicit-function-declaration]
jni/sodium_wrap.c: In function 'Java_org_abstractj_kalium_SodiumJNI_crypto_1box_1curve25519xsalsa20poly1305_1ref_1open':
jni/sodium_wrap.c:1014:3: warning: implicit declaration of function 'crypto_box_curve25519xsalsa20poly1305_ref_open' [-Wimplicit-function-declaration]
jni/sodium_wrap.c: In function 'Java_org_abstractj_kalium_SodiumJNI_crypto_1scalarmult_1curve25519_1ref':
jni/sodium_wrap.c:1058:3: warning: implicit declaration of function 'crypto_scalarmult_curve25519_ref' [-Wimplicit-function-declaration]
jni/sodium_wrap.c: In function 'Java_org_abstractj_kalium_SodiumJNI_crypto_1secretbox_1xsalsa20poly1305_1ref':
jni/sodium_wrap.c:1100:3: warning: implicit declaration of function 'crypto_secretbox_xsalsa20poly1305_ref' [-Wimplicit-function-declaration]
jni/sodium_wrap.c: In function 'Java_org_abstractj_kalium_SodiumJNI_crypto_1secretbox_1xsalsa20poly1305_1ref_1open':
jni/sodium_wrap.c:1146:3: warning: implicit declaration of function 'crypto_secretbox_xsalsa20poly1305_ref_open' [-Wimplicit-function-declaration]
jni/sodium_wrap.c: In function 'Java_org_abstractj_kalium_SodiumJNI_crypto_1sign_1ed25519_1ref_1seed_1keypair':
jni/sodium_wrap.c:1186:3: warning: implicit declaration of function 'crypto_sign_ed25519_ref_seed_keypair' [-Wimplicit-function-declaration]
jni/sodium_wrap.c: In function 'Java_org_abstractj_kalium_SodiumJNI_crypto_1sign_1ed25519_1ref':
jni/sodium_wrap.c:1227:3: warning: implicit declaration of function 'crypto_sign_ed25519_ref' [-Wimplicit-function-declaration]
jni/sodium_wrap.c: In function 'Java_org_abstractj_kalium_SodiumJNI_crypto_1sign_1ed25519_1ref_1open':
jni/sodium_wrap.c:1270:3: warning: implicit declaration of function 'crypto_sign_ed25519_ref_open' [-Wimplicit-function-declaration]
jni/sodium_wrap.c: At top level:
jni/sodium_wrap.c:255:12: warning: 'SWIG_JavaArrayInSchar' defined but not used [-Wunused-function]
jni/sodium_wrap.c:276:13: warning: 'SWIG_JavaArrayArgoutSchar' defined but not used [-Wunused-function]
jni/sodium_wrap.c:284:19: warning: 'SWIG_JavaArrayOutSchar' defined but not used [-Wunused-function]
jni/sodium_wrap.c:301:12: warning: 'SWIG_JavaArrayInUchar' defined but not used [-Wunused-function]
jni/sodium_wrap.c:322:13: warning: 'SWIG_JavaArrayArgoutUchar' defined but not used [-Wunused-function]
jni/sodium_wrap.c:330:20: warning: 'SWIG_JavaArrayOutUchar' defined but not used [-Wunused-function]
jni/sodium_wrap.c:347:12: warning: 'SWIG_JavaArrayInShort' defined but not used [-Wunused-function]
jni/sodium_wrap.c:368:13: warning: 'SWIG_JavaArrayArgoutShort' defined but not used [-Wunused-function]
jni/sodium_wrap.c:376:20: warning: 'SWIG_JavaArrayOutShort' defined but not used [-Wunused-function]
jni/sodium_wrap.c:393:12: warning: 'SWIG_JavaArrayInUshort' defined but not used [-Wunused-function]
jni/sodium_wrap.c:414:13: warning: 'SWIG_JavaArrayArgoutUshort' defined but not used [-Wunused-function]
jni/sodium_wrap.c:422:18: warning: 'SWIG_JavaArrayOutUshort' defined but not used [-Wunused-function]
jni/sodium_wrap.c:439:12: warning: 'SWIG_JavaArrayInInt' defined but not used [-Wunused-function]
jni/sodium_wrap.c:460:13: warning: 'SWIG_JavaArrayArgoutInt' defined but not used [-Wunused-function]
jni/sodium_wrap.c:468:18: warning: 'SWIG_JavaArrayOutInt' defined but not used [-Wunused-function]
jni/sodium_wrap.c:485:12: warning: 'SWIG_JavaArrayInUint' defined but not used [-Wunused-function]
jni/sodium_wrap.c:506:13: warning: 'SWIG_JavaArrayArgoutUint' defined but not used [-Wunused-function]
jni/sodium_wrap.c:514:19: warning: 'SWIG_JavaArrayOutUint' defined but not used [-Wunused-function]
jni/sodium_wrap.c:560:18: warning: 'SWIG_JavaArrayOutLong' defined but not used [-Wunused-function]
jni/sodium_wrap.c:577:12: warning: 'SWIG_JavaArrayInUlong' defined but not used [-Wunused-function]
jni/sodium_wrap.c:598:13: warning: 'SWIG_JavaArrayArgoutUlong' defined but not used [-Wunused-function]
jni/sodium_wrap.c:606:19: warning: 'SWIG_JavaArrayOutUlong' defined but not used [-Wunused-function]
jni/sodium_wrap.c:623:12: warning: 'SWIG_JavaArrayInLonglong' defined but not used [-Wunused-function]
jni/sodium_wrap.c:644:13: warning: 'SWIG_JavaArrayArgoutLonglong' defined but not used [-Wunused-function]
jni/sodium_wrap.c:652:19: warning: 'SWIG_JavaArrayOutLonglong' defined but not used [-Wunused-function]
jni/sodium_wrap.c:669:12: warning: 'SWIG_JavaArrayInFloat' defined but not used [-Wunused-function]
jni/sodium_wrap.c:690:13: warning: 'SWIG_JavaArrayArgoutFloat' defined but not used [-Wunused-function]
jni/sodium_wrap.c:698:20: warning: 'SWIG_JavaArrayOutFloat' defined but not used [-Wunused-function]
jni/sodium_wrap.c:715:12: warning: 'SWIG_JavaArrayInDouble' defined but not used [-Wunused-function]
jni/sodium_wrap.c:736:13: warning: 'SWIG_JavaArrayArgoutDouble' defined but not used [-Wunused-function]
jni/sodium_wrap.c:744:21: warning: 'SWIG_JavaArrayOutDouble' defined but not used [-Wunused-function]
[armeabi] SharedLibrary  : libtestjni.so
/installs/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/testjni/sodium_wrap.o: in function Java_org_abstractj_kalium_SodiumJNI_crypto_1hash_1sha256_1ref:jni/sodium_wrap.c:800: error: undefined reference to 'crypto_hash_sha256_ref'
/installs/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/testjni/sodium_wrap.o: in function Java_org_abstractj_kalium_SodiumJNI_crypto_1hash_1sha512_1ref:jni/sodium_wrap.c:830: error: undefined reference to 'crypto_hash_sha512_ref'
/installs/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/testjni/sodium_wrap.o: in function Java_org_abstractj_kalium_SodiumJNI_crypto_1box_1curve25519xsalsa20poly1305_1ref_1keypair:jni/sodium_wrap.c:900: error: undefined reference to 'crypto_box_curve25519xsalsa20poly1305_ref_keypair'
/installs/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/testjni/sodium_wrap.o: in function Java_org_abstractj_kalium_SodiumJNI_crypto_1box_1curve25519xsalsa20poly1305_1ref:jni/sodium_wrap.c:960: error: undefined reference to 'crypto_box_curve25519xsalsa20poly1305_ref'
/installs/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/testjni/sodium_wrap.o: in function Java_org_abstractj_kalium_SodiumJNI_crypto_1box_1curve25519xsalsa20poly1305_1ref_1open:jni/sodium_wrap.c:1014: error: undefined reference to 'crypto_box_curve25519xsalsa20poly1305_ref_open'
/installs/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/testjni/sodium_wrap.o: in function Java_org_abstractj_kalium_SodiumJNI_crypto_1scalarmult_1curve25519_1ref:jni/sodium_wrap.c:1058: error: undefined reference to 'crypto_scalarmult_curve25519_ref'
/installs/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/testjni/sodium_wrap.o: in function Java_org_abstractj_kalium_SodiumJNI_crypto_1secretbox_1xsalsa20poly1305_1ref:jni/sodium_wrap.c:1100: error: undefined reference to 'crypto_secretbox_xsalsa20poly1305_ref'
/installs/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/testjni/sodium_wrap.o: in function Java_org_abstractj_kalium_SodiumJNI_crypto_1secretbox_1xsalsa20poly1305_1ref_1open:jni/sodium_wrap.c:1146: error: undefined reference to 'crypto_secretbox_xsalsa20poly1305_ref_open'
/installs/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/testjni/sodium_wrap.o: in function Java_org_abstractj_kalium_SodiumJNI_crypto_1sign_1ed25519_1ref_1seed_1keypair:jni/sodium_wrap.c:1186: error: undefined reference to 'crypto_sign_ed25519_ref_seed_keypair'
/installs/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/testjni/sodium_wrap.o: in function Java_org_abstractj_kalium_SodiumJNI_crypto_1sign_1ed25519_1ref:jni/sodium_wrap.c:1227: error: undefined reference to 'crypto_sign_ed25519_ref'
/installs/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/testjni/sodium_wrap.o: in function Java_org_abstractj_kalium_SodiumJNI_crypto_1sign_1ed25519_1ref_1open:jni/sodium_wrap.c:1270: error: undefined reference to 'crypto_sign_ed25519_ref_open'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi/libtestjni.so] Error 1

Howto build / run on windows

I'm looking to use libsodium in my (non-android) java application.

This project seems promising, as it exposes more of the libsodium api than Kalium, but I'm unable to get it to work.

It's looking for sodiumjni.dll, which I assume is not the same as the sodium.dll files available here
https://download.libsodium.org/libsodium/releases/ ?

Do you have any idea where I can obtain this sodiumjni.dll file? It seems like this is the missing piece to get this to work.

thx!

Error when running `mvn clean install`

Hi, I am getting this error when I try to run the last build step:
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/haroldmartin/Documents/kalium-jni/src/test/java/org/abstractj/kalium/keys/VerifyKeyTest.java:[25,43] error: cannot find symbol
[ERROR] package org.abstractj.kalium.encoders
/Users/haroldmartin/Documents/kalium-jni/src/test/java/org/abstractj/kalium/keys/VerifyKeyTest.java:[25,0] error: static import only from classes and interfaces
[ERROR] /Users/haroldmartin/Documents/kalium-jni/src/test/java/org/abstractj/kalium/keys/KeyPairTest.java:[23,43] error: cannot find symbol
[ERROR] package org.abstractj.kalium.encoders
...
and so on with many more like errors

Output doesn't match expected hash

Hi, I'm sure I am probably missing something stupid but I can't get the output to match the official argon2 cli.

I am using com.github.joshjdevl.libsodiumjni:libsodium-jni-aar:1.0.7

Here is my Java code (inside MainActivity.java for an android app).

Sodium sodium = NaCl.sodium(); //To init
byte[] key = new byte[32];
byte[] passwd = "hunter2".getBytes(StandardCharsets.US_ASCII);
byte[] salt = "somesalt".getBytes(StandardCharsets.US_ASCII);
int t = 3;
int m = 32768; //2^15
Sodium.crypto_pwhash(
    key, key.length,
    passwd, passwd.length,
    salt,
    t, m*1024,
    Sodium.crypto_pwhash_alg_argon2i13());
Log.d("ArgonPass", Encoder.HEX.encode(key));

Which produces 6c4d481e349a7c9f26265c1ad49eff79c0247390e89744ce9b62867ff54f7e71.

For reference here is the expected hash

$ echo -n "hunter2" | argon2 "somesalt" -t 3 -m 15 -l 32 -i -v 13
Type:		Argon2i
Iterations:	3 
Memory:		32768 KiB
Parallelism:	1 
Hash:		5025aadc4b722b3ce2de6935eb2f6c5d5ab98f7bd4bbdb73d0f1b190552d7815
Encoded:	$argon2i$v=19$m=32768,t=3,p=1$c29tZXNhbHQ$UCWq3EtyKzzi3mk16y9sXVq5j3vUu9tz0PGxkFUteBU

I have tried using crypto_pwhash_str(key, passwd, passwd.length t, m*1024). And I get an output with $argon2i$v=19$m=32768,t=3,p=1 so it appears I am passing in the work parameters correctly. I used the *1024 because the libsodium docs say the memory is specified in bytes while the argon2cli uses KiB. I have also tried using different encoding formats and raw character arrays to no avail.

Can't create KeyPair from byte[] secretKey

After migrating our code from kalium to libsodium-jni, it's no longer possible to generate a KeyPair from a byte[] secretKey.

See also this change:

This constructor was commented out:

//    public KeyPair(byte[] secretKey) {
//        this.secretKey = secretKey;
//        checkLength(this.secretKey, SECRETKEY_BYTES);
//    }

How are we supposed to generate a KeyPair when we only have the secretKey stored locally? In the past, we used that constructor (KeyPair(byte[] secretKey)) which is now gone. We can of course subclass this class and put it back (copying all the other code as well) but it's not really ideal.

Also, your other constructor's first argument now has a confusing/wrong name:

public KeyPair(String secretKey, Encoder encoder) {
    this(encoder.decode(secretKey));
}

That String secretKey argument is now actually a seed, because it calls the KeyPair(byte[] seed) constructor.

How did you envision this upgrade path scenario from old clients using the KeyPair(byte[] secretKey) constructor? (clients that have already stored that key)

Perhaps you can add that constructor back, or add it as a static factory method (or find some other workaround for the fact they have the same signature).

Using the docker file

I am very new to using docker, and so am slightly confused by how to use the kalium docker file to automatically build the .so file and the kalium .jar have installed docker and set up a VM (due to being on a mac). Do I merely call "docker pull joshjdevl/docker-libsodium" and the .so file and .jar will automatically be built? At that point, am I ready to put those files in an android studio project and have libsodium work?

compile.sh fails

I don't think it is an issue but I do not know where else to put it

I am trying to compile the latest version of libsodium-jni in order to use it for an Android project.
While previous version compiled and failed at the maven step, this latest one fails at sodium_wrap.c.

Specifically
sodium_wrap.c:781:20: fatal error: sodium.h: No such file or directory (which is true as I think it expects it to be the JNI folder)

As it happens the docker files are somewhat outdated, do not include all the functions and the single .so file from there refers only to the arm processors.

I am running this on an Ubuntu VM. Maybe it is my fault and I am not downloading the correct packages to the correct folders.

Should the libsodium folder be inside the libsodim-jni folder?
Should it be outside? And actually where in the system should I do all the git cloning for the whole thing to compile and then produce the .jar snapshop?

I currently do the git cloning in the /home/user path.

NDK and JAVA are declared properly.

Thanks in advance!

Key derivations failures could lead to all zero byte keys

crypto_pwhash can return non-zero error codes in the event of an failure.

The function returns 0 on success, and -1 if the computation didn't complete, usually because the operating system refused to allocate the amount of requested memory.

That case is not handled at all here. If this function fails to derive the key, this will return an all zero key silently instead of signaling an error to the caller.

https://github.com/joshjdevl/libsodium-jni/blob/master/src/main/java/org/libsodium/jni/crypto/Hash.java#L51

This is unrelated, but I think crypto_pwhash_alg_default is (as of 1.0.9) Argon2. So isn't this function misnamed?

Publish on Maven Central

Now that you have a release build (1.0.3), you should really publish this to Maven Central.

On a related note, the readme currently says "libsodium-jni is a work in progress". The readme should be clear on what stuff, if any, is missing and whether the library can be used for production purposes.

Outdated SWIG-generated files

After a build, the files "src/main/java/org/libsodium/jni/Sodium.java" and "src/main/java/org/libsodium/jni/SodiumJNI.java" are changed and git "complains" about this (at least on my machine - I'm using libsodium-jni as a subrepository).

Why are the SWIG-generated files in the repository in the first place? It seems like they are re-generated on every build. Personally I avoid putting auto-generated files in the repository. I'm not sure whether this is just my personal preference or generally accepted best practice. In the end it's your decision.

If you decide to leave them in the repository, please commit the current version of them, as some functions were removed.

java.lang.UnsatisfiedLinkError: No implementation found for int org.libsodium.jni.SodiumJNI.crypto_box_seal_open

I am trying to access box sealed method
org.libsodium.jni.SodiumJNI.crypto_box_seal_open(chipherText,output,chipherText.length,publicKey,privateKey);
but it giving me below error

java.lang.UnsatisfiedLinkError: No implementation found for int org.libsodium.jni.SodiumJNI.crypto_box_seal_open(byte[], byte[], int, byte[], byte[]) (tried Java_org_libsodium_jni_SodiumJNI_crypto_1box_1seal_1open and Java_org_libsodium_jni_SodiumJNI_crypto_1box_1seal_1open___3B_3BI_3B_3B) at org.libsodium.jni.SodiumJNI.crypto_box_seal_open(Native Method)

Make it latest stable NDK (r13b) compatible

Stable branch of libsodium now is NDK r13b ready, moreover build scripts fail when
used with r12b NDK due to new '--force' arg used for ndk-build.

I was trying to change manually NDK version in setenv.sh to r13b,
but some of 64bit arch fail during build process.

It would be great to have "libsodium-jni" r13b ready.

Compiling for android

Hi,

could you provide some information about compiling kalium for android? I was able to compile libsodium for all android cpu architectures. but now I'm wondering, how to compile kalium for each platform?
Could you give me some hints for that?

Thanks in advance!

Problems using the library

Hi,

I'm having trouble getting the library working.

Steps I have taken:

  • Added libsodium-jni as a dependency using Gradle:
dependencies {
    ...
    compile 'com.github.joshjdevl.libsodiumjni:libsodium-jni:1.0.6'
}
  • Installed libsodium by following these instructions
  • Written code that makes use of Sodium.crypto_pwhash_scryptsalsa208sha256_str(), as well as accompanying functions:
    • Sodium.crypto_pwhash_scryptsalsa208sha256_strbytes
    • Sodium.crypto_pwhash_scryptsalsa208sha256_memlimit_interactive
    • crypto_pwhash_scryptsalsa208sha256_opslimit_interactive

When I run my code I get this exception:

org.libsodium.jni.SodiumJNI.crypto_pwhash_scryptsalsa208sha256_strbytes()I
java.lang.UnsatisfiedLinkError: org.libsodium.jni.SodiumJNI.crypto_pwhash_scryptsalsa208sha256_strbytes()I
	at org.libsodium.jni.SodiumJNI.crypto_pwhash_scryptsalsa208sha256_strbytes(Native Method)
	at org.libsodium.jni.Sodium.crypto_pwhash_scryptsalsa208sha256_strbytes(Sodium.java:761)
        ....

I'm running everything under Ubuntu 17.04 with Gradle 3.1, OpenJDK 8. I'm using Kotlin 1.1.2.

All my source code is visible here. Relevant files:

I'd really appreciate help on how to link your library against libsodium. Thanks!

What's up with BLAKE2B?

There's code wrapping blake2b in src/main/java/org/libsodium/jni/crypto/Hash.java but it's commented out. Why is that? Is it unsafe, broken or wrong?

Prebuilt AAR with android64-v8a.so ?

Hey guys, is there a prebuilt aar with the android64-v8a.so included? I see that support has been added but would like pull the aar from maven rather than build it by hand.

Automatic AAR/Shared Object generation doesn't work

We are planing to use your wrapper for some encryption in our Android app. For that we need to adjust the swig file to build our own wrapper so that we have some extra functions from the libsodium library not included in your releases.

In the readme you say "It is also possible to build the AAR library yourself using the provided scripts linux or mac". Unfortunately we can not figure out how to adjust your script to generate either an aar file with all the libraries included or the needed .so files for the different architectures. Everytime we get a x86 library or some empty output directories.

We would really appreciate a short instruction on how to do it. Thanks!

fatal: reference is not a tree when running build.sh

After git submodule update I get
fatal: reference is not a tree: c3d391b0baa9ce8615634f842e2cfa441e5acd8a
Unable to checkout 'c3d391b0baa9ce8615634f842e2cfa441e5acd8a' in submodule path 'libsodium'

Is there a reason it needs to use a specific old commit? Can I use the latest libsodium by doing
git submodule update --remote --merge
instead?

x86_64 architecture support

Congrats for your work

Is there support for x86_64 architecture or should I try adding one?

Any suggestions?

crypto_secretbox_keygen is not found

I want to use this method : crypto_secretbox_keygen, for generating secret key for using in crypto_secretbox_easy method but it is not found in this library.could you provide this method or any alternative method for generating secret box key?

More a question than an issue...

I want to use my Java library which uses kalium on linux, mac, and android. What's the best way to do this given the different implementations? I'm using IntelliJ if that would help customize the builds. Obviously I want to avoid duplicating code for the different platforms and would like to distribute as few components as possible.

Thanks,
Seth

Build Error

/bin/mkdir -p '/installs/libsodium-jni/libsodium/libsodium-android-armv6/include/sodium' /usr/bin/install -c -m 644 sodium/crypto_sign_edwards25519sha512batch.h sodium/crypto_stream.h sodium/crypto_stream_chacha20.h sodium/crypto_stream_salsa20.h sodium/crypto_stream_salsa2012.h sodium/crypto_stream_salsa208.h sodium/crypto_stream_xchacha20.h sodium/crypto_stream_xsalsa20.h sodium/crypto_verify_16.h sodium/crypto_verify_32.h sodium/crypto_verify_64.h sodium/export.h sodium/randombytes.h sodium/randombytes_salsa20_random.h sodium/randombytes_sysrandom.h sodium/runtime.h sodium/utils.h '/installs/libsodium-jni/libsodium/libsodium-android-armv6/include/sodium' make[4]: Leaving directory/installs/libsodium-jni/libsodium/src/libsodium/include'
make[3]: Leaving directory /installs/libsodium-jni/libsodium/src/libsodium/include' make[3]: Entering directory /installs/libsodium-jni/libsodium/src/libsodium'
CC crypto_generichash/blake2b/ref/libssse3_la-blake2b-compress-ssse3.lo
CC crypto_pwhash/argon2/libssse3_la-argon2-fill-block-ssse3.lo
CC crypto_generichash/blake2b/ref/libsse41_la-blake2b-compress-sse41.lo
CC crypto_generichash/blake2b/ref/libavx2_la-blake2b-compress-avx2.lo
CC crypto_pwhash/argon2/libavx2_la-argon2-fill-block-avx2.lo
CC crypto_stream/chacha20/dolbeau/libavx2_la-chacha20_dolbeau-avx2.lo
CC crypto_stream/salsa20/xmm6int/libavx2_la-salsa20_xmm6int-avx2.lo
CC crypto_pwhash/argon2/libavx512f_la-argon2-fill-block-avx512f.lo
CC crypto_aead/chacha20poly1305/sodium/libsodium_la-aead_chacha20poly1305.lo
CC crypto_aead/xchacha20poly1305/sodium/libsodium_la-aead_xchacha20poly1305.lo
CC crypto_auth/libsodium_la-crypto_auth.lo
CC crypto_auth/hmacsha256/libsodium_la-auth_hmacsha256.lo
CC crypto_auth/hmacsha512/libsodium_la-auth_hmacsha512.lo
CC crypto_auth/hmacsha512256/libsodium_la-auth_hmacsha512256.lo
CC crypto_box/libsodium_la-crypto_box.lo
CC crypto_box/libsodium_la-crypto_box_easy.lo
CC crypto_box/libsodium_la-crypto_box_seal.lo
crypto_box/crypto_box.c:55:12: error: use of undeclared identifier 'SIZE_MAX'
return crypto_box_MESSAGEBYTES_MAX;
^
./include/sodium/crypto_box.h:43:37: note: expanded from macro 'crypto_box_MESSAGEBYTES_MAX'
#define crypto_box_MESSAGEBYTES_MAX crypto_box_curve25519xsalsa20poly1305_MESSAGEBYTES_MAX
^
./include/sodium/crypto_box_curve25519xsalsa20poly1305.h:41:6: note: expanded from macro 'crypto_box_curve25519xsalsa20poly1305_MESSAGEBYTES_MAX'
(crypto_stream_xsalsa20_MESSAGEBYTES_MAX - crypto_box_curve25519xsalsa20poly1305_MACBYTES)
^
./include/sodium/crypto_stream_xsalsa20.h:31:49: note: expanded from macro 'crypto_stream_xsalsa20_MESSAGEBYTES_MAX'
#define crypto_stream_xsalsa20_MESSAGEBYTES_MAX SODIUM_SIZE_MAX
^
./include/sodium/export.h:51:48: note: expanded from macro 'SODIUM_SIZE_MAX'
#define SODIUM_SIZE_MAX SODIUM_MIN(UINT64_MAX, SIZE_MAX)
^
crypto_box/crypto_box.c:55:12: error: use of undeclared identifier 'SIZE_MAX'
./include/sodium/crypto_box.h:43:37: note: expanded from macro 'crypto_box_MESSAGEBYTES_MAX'
#define crypto_box_MESSAGEBYTES_MAX crypto_box_curve25519xsalsa20poly1305_MESSAGEBYTES_MAX
^
./include/sodium/crypto_box_curve25519xsalsa20poly1305.h:41:6: note: expanded from macro 'crypto_box_curve25519xsalsa20poly1305_MESSAGEBYTES_MAX'
(crypto_stream_xsalsa20_MESSAGEBYTES_MAX - crypto_box_curve25519xsalsa20poly1305_MACBYTES)
^
./include/sodium/crypto_stream_xsalsa20.h:31:49: note: expanded from macro 'crypto_stream_xsalsa20_MESSAGEBYTES_MAX'
#define crypto_stream_xsalsa20_MESSAGEBYTES_MAX SODIUM_SIZE_MAX
^
./include/sodium/export.h:51:48: note: expanded from macro 'SODIUM_SIZE_MAX'
#define SODIUM_SIZE_MAX SODIUM_MIN(UINT64_MAX, SIZE_MAX)
^
2 errors generated.
make[3]: *** [crypto_box/libsodium_la-crypto_box.lo] Error 1
make[3]: *** Waiting for unfinished jobs....
make[3]: Leaving directory /installs/libsodium-jni/libsodium/src/libsodium' make[2]: *** [install-recursive] Error 1 make[2]: Leaving directory /installs/libsodium-jni/libsodium/src/libsodium'
make[1]: *** [install-recursive] Error 1
make[1]: Leaving directory `/installs/libsodium-jni/libsodium/src'
make: *** [install-recursive] Error 1
:compileNative_android-armv6 FAILED

FAILURE: Build failed with an exception.

  • Where:
    Build file '/installs/libsodium-jni/build.gradle' line: 95

  • What went wrong:
    Execution failed for task ':compileNative_android-armv6'.

Process 'command 'dist-build/android-arm.sh'' finished with non-zero exit value 2

  • Try:
    Run with --info or --debug option to get more log output.

  • Exception is:
    org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':compileNative_android-armv6'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:84)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:55)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:236)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:228)
    at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:61)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:228)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:215)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:77)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:58)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:32)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:113)
    at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
    at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23)
    at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43)
    at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30)
    at org.gradle.initialization.DefaultGradleLauncher$RunTasksAction.execute(DefaultGradleLauncher.java:256)
    at org.gradle.initialization.DefaultGradleLauncher$RunTasksAction.execute(DefaultGradleLauncher.java:253)
    at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:175)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:119)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:102)
    at org.gradle.launcher.exec.GradleBuildController.run(GradleBuildController.java:71)
    at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:75)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:49)
    at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:49)
    at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:31)
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:47)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
    at org.gradle.util.Swapper.swap(Swapper.java:38)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:72)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:297)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:46)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
    Caused by: org.gradle.process.internal.ExecException: Process 'command 'dist-build/android-arm.sh'' finished with non-zero exit value 2
    at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:369)
    at org.gradle.process.internal.DefaultExecAction.execute(DefaultExecAction.java:31)
    at org.gradle.api.internal.file.DefaultFileOperations.exec(DefaultFileOperations.java:176)
    at org.gradle.api.internal.project.DefaultProject.exec(DefaultProject.java:922)
    at org.gradle.groovy.scripts.DefaultScript.exec(DefaultScript.java:239)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:384)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1024)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:812)
    at groovy.lang.GroovyObjectSupport.invokeMethod(GroovyObjectSupport.java:46)
    at org.gradle.internal.metaobject.BeanDynamicObject$GroovyObjectAdapter.invokeOpaqueMethod(BeanDynamicObject.java:562)
    at org.gradle.internal.metaobject.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:492)
    at org.gradle.internal.metaobject.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:176)
    at org.gradle.internal.metaobject.ConfigureDelegate.invokeMethod(ConfigureDelegate.java:80)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeOnDelegationObjects(ClosureMetaClass.java:430)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:369)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1024)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:812)
    at groovy.lang.GroovyObjectSupport.invokeMethod(GroovyObjectSupport.java:46)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeOnDelegationObjects(ClosureMetaClass.java:446)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:371)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1024)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:69)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
    at build_e289yc249qphiv4jyy5nhf66i$_run_closure4$_closure24$_closure26.doCall(/installs/libsodium-jni/build.gradle:95)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1024)
    at groovy.lang.Closure.call(Closure.java:414)
    at groovy.lang.Closure.call(Closure.java:430)
    at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:596)
    at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:577)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:95)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:76)
    ... 73 more

BUILD FAILED

`

Xchacha20Poly1305 algorithm

Hi:
jedisct1 updated an algorithm called Xchacha20Poly1305, Can you provide a new sodium.i file or tell me how to generate sodium.i ?
thank you!

Docker questions and lsb_release: command not found

If I run docker-compose -f docker-compose-build.yml build I get an error.

lsb_release -a
./dependencies-linux.sh: line 7: lsb_release: command not found

It can be avoided by installing lsb-release in the Dockerfile before running the dependencies step. Should this be done? Also is it even necessary to build the Dockerfile or should the existing joshjdevl/libsodium-jni image allow me to build the source? I'm happy to contribute to documentation on getting started with building via docker.

I was also wondering what you think of separating the Dockerfile steps (RUN statements) out more. The ./build-linux.sh step is huge. If we run it in a few different steps it would be easier to use cache layers so that not everything must be done at once. This would make it easier to deal with problems happening at the end. I'd propose at least putting dependencies-linux.sh as it's own step.

[request] Don't throw RuntimeException on invalid signatures

First of all, thanks for providing this package :) I'm using libsodium to verify a signature in my Android app and was really surprised just now when I realized that VerifyKey.verify() (more precisely: Util.isValid()) throws a RuntimeException. At least for me, this was really unexpected and I think it's also not the most elegant solution. Basically, if I want to handle this case gracefully (instead of crashing my app), I have to catch all RuntimeExceptions and compare the message with a constant string that could potentially change in future versions. A few ideas on alternative ways to handle this (in my personal order of preference):

  1. Just let it return false when the signature isn't valid and let developers handle what should happen in that case. After all, it is a boolean method, so just by looking at the interface I would expect it to return true if the signature is valid and false otherwise. Imho, there's no need to throw an exception at all.
  2. Don't use RuntimeException but create a new (checked!) exception class, so that at least I will be prompted to handle that case while writing the code.
  3. At the very minimum, make it a new subclass of RuntimeException, so I don't need to catch all the RuntimeExceptions, but can easily catch "InvalidSignatureException" or similar.

Is there any chance you would be making one of these changes in a future version? Or is there a particular reason you went for the RuntimeException?

JDK 7 Build

As I see there are no troubles to compile the library with minSdkVersion 14 and jdk 7. As Android doesn't support java 8, and it is necessary to use retrolambda(which is not perfect) to workaround java 8 issues, it would be extremely useful to provide java 7 binaries.

unexpected e_machine: 3

I'm getting this error trying to run my little application which simply generates a new KeyPair:

java.lang.IllegalStateException: Could not execute method of the activity
...
Caused by: java.lang.reflect.InvocationTargetException
...
Caused by: java.lang.UnsatisfiedLinkError: dlopen failed: "/data/app-lib/IM.CRYPTO-1/libtestjni.so" has unexpected e_machine: 3
            at java.lang.Runtime.loadLibrary(Runtime.java:364)
            at java.lang.System.loadLibrary(System.java:526)
            at org.abstractj.kalium.NaCl.<clinit>(NaCl.java:36)
            at org.abstractj.kalium.keys.KeyPair.<init>(KeyPair.java:36)
            at IM.CRYPTO.HelloAndroidActivity.buttonClick(HelloAndroidActivity.java:43)
...

I'm running Ubuntu 12.04LTS 64bit, android-arm emulator with Android API 14 and used the latest compile scripts for android-arm from libsodium.

I posted a more extensive description on stackoverflow: http://stackoverflow.com/questions/21908997/unexpected-e-machine-3-in-kaliumjni-for-android

Question on aar and allowbackup

When I install the aar I get

Manifest merger failed : Attribute application@allowBackup value=(true) from AndroidManifest.xml:23:3-29
        is also present at [com.github.joshjdevl.libsodiumjni:libsodium-jni-aar:1.0.7-SNAPSHOT] AndroidManifest.xml:11:18-45 value=(false).

That's easy enough to resolve. But why does this happen? Does something about libsodium-jni break allowBackup? I assume it's coming from https://github.com/joshjdevl/libsodium-jni/blob/master/src/main/AndroidManifest.xml#L2

Question on 1.0.7 aar release

Sorry if this is a dumb question - I feel REALLY REALLY dumb when I do anything with java dependencies and repos. I'm trying to upgrade from 1.0.7 snapshot to 1.0.7 release.

But the releases version doesn't appear to exist. Check out

https://oss.sonatype.org/content/repositories/releases/com/github/joshjdevl/libsodiumjni/libsodium-jni-aar/

Previously I had this in my include.gradle. I'm kind of just guessing that it's at releases for a release as 1.0.6 is there.

repositories {
    mavenCentral()
    mavenLocal()
    maven {
        url "https://oss.sonatype.org/content/repositories/snapshots"
    }
}

dependencies {
	compile 'com.github.joshjdevl.libsodiumjni:libsodium-jni-aar:1.0.7-SNAPSHOT'
}

Not correct work with secretbox

I want reuse a buffer for secretbox methods like crypto_secretbox_xsalsa20poly1305 and crypto_secretbox_xsalsa20poly1305_open

But tests failed if I use the same buffer to in and out arrays, for example

// buffer size is 32 + data.length
Sodium.crypto_secretbox_xsalsa20poly1305(buffer, buffer, buffer.length, nonce, key)

The out array becames with 32 zero bytes at the begining, without MAC

From libsodium docs:

c and m can overlap, making in-place encryption possible. However do not forget that
crypto_secretbox_MACBYTES extra bytes are required to prepend the tag.

Provide native libraries inside a jar?

Many projects provide native libraries inside their jar files, e.g. Netty or LWJGL. However, libsodium-jni does not provide it - apparently, .so files are only present in the AAR package, but not in the regular JAR library. Moreover, it looks like that x86_64 shared object from the AAR file is not usable directly on a regular Linux system:

./libsodiumjni.so: error while loading shared libraries: /usr/lib/libc.so: invalid ELF header

(at least on my system, /usr/libc/libc.so is a textual stub; the proper library is /usr/libc/libc.so.6)

Therefore, there is no simple way to use the library - there is a need to compile the library manually and also add the compiled files to the project by hand. Is it possible to fix this?

Concurrency problem in Hash.java

Hi there,

Just wanted to let you know about one problem we discovered: the Hash class is not thread-safe due to use of "private static byte[] buffer;".
When calculating hashes in multiple threads, they start overwriting each other's buffers.

Actually, there is no need for buffer to be static.

using low-level primitives

You'll have to excuse me - I'm quite new to Android. I wanted to know if it's possible to use the low-level API for methods such as crypto_stream_xsalsa20_xor (for example). I see it listed in SodiumJNI.java but it crashes when I call it.

(java.lang.UnsatisfiedLinkError: No implementation found for int org.libsodium.jni.SodiumJNI.crypto_stream_xsalsa20_xor(byte[], byte[], int, byte[], byte[])

there are problems with Sodium.crypto_generichash_init()

when i run this method ,the app on android will crash, the message: jarray is an invalid stack indirect reference table or invalid reference: 0xffe43950 (0x6a09e667).
Sodium.crypto_hash_sha256_init() also has the same problem

Integration with Gradle and Android Studio

Hi Josh,

First of all thanks for the contribution.

I want to know if it's possible to configure your project in the gradle build system with android studio. I want to do it for compile to different architectures.

Thanks for all! :)

crypto_aead_chacha20poly1305_ietf_encrypt() parameters

I want to use crypto_aead_chacha20poly1305_ietf_encrypt() function in my project. It has a parameter int[] clen_p. From what I understand, it's the cipher length. So, why is it an integer array and not just an integer?

crypto_pwhash (argon2) support

What kind of work would be involved to add crypto_pwhash to this? If I'm understanding right, git master is using a up to date version of libsodium but it doesn't have any references to crypto_pwhash_*. Is it just a matter of adding the bindings? If so, do you think it's something I could help on and would you be able to point me to something on getting started? I've never worked with Java bindings to C. I'd be happy to pay for any work done by someone else if that is of interest.

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.