Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@

############
JAVA
############

*.class

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.war
*.ear

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*




################################################################
Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode
####################################################################


## Directory-based project format
.idea/
# if you remove the above rule, at least ignore user-specific stuff:
# .idea/workspace.xml
# .idea/tasks.xml
# and these sensitive or high-churn files:
# .idea/dataSources.ids
# .idea/dataSources.xml
# .idea/sqlDataSources.xml
# .idea/dynamic.xml

## File-based project format
*.ipr
*.iws
*.iml

## Additional for IntelliJ
out/

# generated by mpeltonen/sbt-idea plugin
.idea_modules/

# generated by JIRA plugin
atlassian-ide-plugin.xml

eclipsebin/


#########################################
ECLIPSe
##########################################

*.pydevproject
.metadata
.gradle
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.classpath
.project

# External tool builders
.externalToolBuilders/
target/

# Locally stored "Eclipse launch configurations"
*.launch

# CDT-specific
.cproject

# PDT-specific
.buildpath

# sbteclipse plugin
.target

# TeXlipse plugin
.texlipse



.gradletasknamecache
build

*.hprof

.DS_Store


trexjavaclient.properties
31 changes: 17 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
CP = `find lib -name "*.jar" -printf %p:`
JAVA_BUILD_OPTS = -g -source 1.8 -target 1.8 -cp .:$(CP)
JAVA_BUILD_OPTS = -g -source 1.8 -target 1.8
CP_SPACE = .

.PHONY: def
Expand All @@ -8,30 +7,34 @@ def: clean compile jni test
.PHONY: clean
clean:
rm -fr build
rm -f libtweetnacl.so
rm -f Test.jar

.PHONY: compile
compile:
mkdir -p build
javac $(JAVA_BUILD_OPTS) -d build `find src -name \*.java`
mkdir -p build/classes/jar

javac $(JAVA_BUILD_OPTS) -cp ".:lib/*" -d build/classes/jar `find src/main -name \*.java`
javac $(JAVA_BUILD_OPTS) -cp ".:lib/*:build/classes/jar" -d build/classes/jar `find src/test -name \*.java`



.PHONY: test
test: compile
echo "Name: TweetNaCl.java Tests" > def.manifest
echo "Main-Class: test.JSTest" >> def.manifest
echo "Main-Class: org.peergos.crypto.JSTest" >> def.manifest
echo "Build-Date: " `date` >> def.manifest
echo "Class-Path: " $(CP_SPACE)>> def.manifest
jar -cfm Test.jar def.manifest \
-C build org -C build test


jar -cfm build/Test.jar def.manifest -C build/classes/jar org -C src/test/resources nacl.js

rm -f def.manifest


.PHONY: jni
jni: compile
javah -jni -classpath build -d jni org.peergos.crypto.JniTweetNacl
gcc -Wimplicit-function-declaration -fPIC -std=c11 -I${JAVA_HOME}/include -I${JAVA_HOME}/include/linux -Inative -Ijni -shared -o libtweetnacl.so jni/org_peergos_crypto_JniTweetNacl.c
javah -jni -classpath build/classes/jar org.peergos.crypto.JniTweetNacl
gcc -Wimplicit-function-declaration -fPIC -std=c11 -I${JAVA_HOME}/include -I${JAVA_HOME}/include/linux -Isrc/test/resources -Ibuild/jniheaders -shared -obuild/libtweetnacl.so src/test/resources/org_peergos_crypto_JniTweetNacl.c

.PHONY: jni_test
jni_tests: def
java -Djava.library.path=. -cp "Test.jar:lib/*" test.TestRunner

jni_tests: def
java -Xmx250m -Xms250m -Djava.library.path=build -cp "build/Test.jar:lib/*" org.peergos.crypto.TestRunner
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ A Java port of TweetNaCl from the original C.
It has been extensively tested against the original C version and TweetNaCl.js for messages up to 2^24 bytes. It still needs a professional cryptographic audit.

To import into your project you only need [org/peergos/crypto/TweetNaCl.java](https://github.com/ianopolous/tweetnacl-java/raw/master/src/org/peergos/crypto/TweetNaCl.java).

If you want to build and test the project via gradle you can run ./gradlew check. Currently the gradle build works on OSX and Linux

If you are using Linux, you can build and test via "make" as well.
118 changes: 118 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
group 'org.peergos'
version '0.1'


buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.gradle:osdetector-gradle-plugin:1.4.0'
}

}

apply plugin: "java"
apply plugin: 'com.google.osdetector'


repositories {
mavenCentral()

}


compileJava {
sourceCompatibility = 1.6
targetCompatibility = 1.6
}

compileTestJava {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}

[compileJava, compileTestJava].each() {
it.options.compilerArgs += ["-Xlint:unchecked", "-Xlint:deprecation", "-Xlint:-options"]
it.options.encoding = "UTF-8"
}


javadoc.options {
encoding = 'UTF-8'
links 'https://docs.oracle.com/javase/8/docs/api/'
}


test {
testLogging {
exceptionFormat = 'full'
showExceptions true
showCauses true
showStackTraces true
}
maxParallelForks = Runtime.runtime.availableProcessors()

}


task buildNativeHeaders(type: Exec) {

def classpath = sourceSets.main.output.classesDir



commandLine "javah", "-d", "build/jniheaders", "-classpath", "$classpath", "org.peergos.crypto.JniTweetNacl"

}



task compileNativeLib(type: Exec) {

def jniPath;
def objPath;

if (osdetector.os.equalsIgnoreCase("linux")) {
jniPath = "linux"
objPath = "-obuild/libtweetnacl.so"

} else if (osdetector.os.equalsIgnoreCase("osx")) {
jniPath = "darwin"
objPath = "-obuild/libtweetnacl.jnilib"
} else {
throw new RuntimeException("Only Linux & OSX builds are supported currently")
}


commandLine "gcc", "-Wimplicit-function-declaration", "-fPIC", "-std=c11", "-I${System.env.JAVA_HOME}/include",
"-I${System.env.JAVA_HOME}/include/${jniPath}", "-Isrc/test/resources/", "-shared", "-Ibuild/jniheaders",
objPath, "src/test/resources/org_peergos_crypto_JniTweetNacl.c"


}

testClasses.dependsOn {
buildNativeHeaders
compileNativeLib
}




test {
systemProperty "java.library.path", "${buildDir}"
}

jar {
from "license.txt"
}


dependencies {

testCompile files('lib/hamcrest-core-1.3.jar')
testCompile files('lib/junit-4.11.jar')

}

Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Thu Nov 26 10:22:04 EET 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-bin.zip
Loading