2
0

Move native implementation build into masterpassword-core

This commit is contained in:
Maarten Billemont
2018-05-25 13:08:05 -04:00
parent cc82e52c33
commit 3b24e1d1b8
28 changed files with 115 additions and 89 deletions

44
core/c/build.gradle Normal file
View File

@@ -0,0 +1,44 @@
import org.gradle.internal.jvm.Jvm
plugins {
id 'cpp-library'
id 'xcode'
id 'visual-studio'
}
description = 'Master Password Algorithm Implementation'
library {
linkage.set( [Linkage.STATIC, Linkage.SHARED] )
binaries.configureEach {
// Reconfigure the toolchain from C++ to C.
compileTask.get().source.setFrom( fileTree( dir: "src", include: "**/*.c" ) )
if (toolChain instanceof VisualCpp) {
compileTask.get().compilerArgs = ["/TC"]
} else if (toolChain instanceof GccCompatibleToolChain) {
compileTask.get().compilerArgs = ["-x", "c", "-std=c11"]
//linkTask.get().linkerArgs = ["-nodefaultlibs", "-lc"]
}
// Resolve our standard naming for OS platforms.
def platform = System.getProperty( "os.name" ).toLowerCase( Locale.ROOT )
if (platform.startsWith( "mac" ))
platform = "macos"
project.dependencies {
// Depend on JDK for JNI support.
add( includePathConfiguration.name,
files( new File( Jvm.current().javaHome, "include" ) ) { first().eachDir { from it } } )
// Depend on libsodium from `lib`; run `lib/bin/build_libsodium-${os}` first.
add( includePathConfiguration.name,
files( "../../lib/libsodium/build-${platform}~/out/include" ) )
add( linkLibraries.name,
fileTree( "../../lib/libsodium/build-${platform}~/out/lib" ) )
}
compileTask.get().compilerArgs.add "-DMPW_SODIUM=1"
}
}

8
core/c/src/mpw-jni.c Normal file
View File

@@ -0,0 +1,8 @@
#include "mpw-jni.h"
/** native int _scrypt(byte[] passwd, int passwdlen, byte[] salt, int saltlen, int N, int r, int p, byte[] buf, int buflen); */
JNIEXPORT jint JNICALL Java_com_lyndir_masterpassword_impl_MPAlgorithmV0__1scrypt(JNIEnv *env, jobject obj,
jbyteArray passwd, jint passwdlen, jbyteArray salt, jint saltlen, jint N, jint r, jint p, jbyteArray buf, jint buflen) {
return -2;
}

23
core/c/src/mpw-jni.h Normal file
View File

@@ -0,0 +1,23 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_lyndir_masterpassword_impl_MPAlgorithmV0 */
#ifndef _Included_com_lyndir_masterpassword_impl_MPAlgorithmV0
#define _Included_com_lyndir_masterpassword_impl_MPAlgorithmV0
#ifdef __cplusplus
extern "C" {
#endif
#undef com_lyndir_masterpassword_impl_MPAlgorithmV0_AES_BLOCKSIZE
#define com_lyndir_masterpassword_impl_MPAlgorithmV0_AES_BLOCKSIZE 128L
/*
* Class: com_lyndir_masterpassword_impl_MPAlgorithmV0
* Method: _scrypt
* Signature: ([BI[BIIII[BI)I
*/
JNIEXPORT jint JNICALL Java_com_lyndir_masterpassword_impl_MPAlgorithmV0__1scrypt
(JNIEnv *, jobject, jbyteArray, jint, jbyteArray, jint, jint, jint, jint, jbyteArray, jint);
#ifdef __cplusplus
}
#endif
#endif