Fix JNI write-back, bad V3 api usage, duplicate length passing.
This commit is contained in:
@@ -3,13 +3,16 @@
|
||||
#include "mpw-jni.h"
|
||||
#include "mpw-util.h"
|
||||
|
||||
/** native int _scrypt(byte[] passwd, int passwdlen, byte[] salt, int saltlen, int N, int r, int p, byte[] buf, int buflen); */
|
||||
/** native int _scrypt(byte[] passwd, byte[] salt, int N, int r, int p, byte[] buf); */
|
||||
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) {
|
||||
jbyteArray passwd, jbyteArray salt, jint N, jint r, jint p, jbyteArray buf) {
|
||||
|
||||
jbyte *passwdBytes = (*env)->GetByteArrayElements( env, passwd, NULL );
|
||||
jbyte *saltBytes = (*env)->GetByteArrayElements( env, salt, NULL );
|
||||
const uint8_t *key = mpw_kdf_scrypt( (size_t)buflen, (uint8_t *)passwdBytes, (size_t)passwdlen, (uint8_t *)saltBytes, (size_t)saltlen,
|
||||
const size_t keyLength = (*env)->GetArrayLength( env, buf );
|
||||
const uint8_t *key = mpw_kdf_scrypt( keyLength,
|
||||
(uint8_t *)passwdBytes, (size_t)(*env)->GetArrayLength( env, passwd ),
|
||||
(uint8_t *)saltBytes, (size_t)(*env)->GetArrayLength( env, salt ),
|
||||
(uint64_t)N, (uint32_t)r, (uint32_t)p );
|
||||
(*env)->ReleaseByteArrayElements( env, passwd, passwdBytes, JNI_ABORT );
|
||||
(*env)->ReleaseByteArrayElements( env, salt, saltBytes, JNI_ABORT );
|
||||
@@ -17,6 +20,10 @@ JNIEXPORT jint JNICALL Java_com_lyndir_masterpassword_impl_MPAlgorithmV0__1scryp
|
||||
if (!key)
|
||||
return ERR;
|
||||
|
||||
memcpy( buf, key, buflen );
|
||||
jbyte *bufBytes = (*env)->GetByteArrayElements( env, buf, NULL );
|
||||
memcpy( bufBytes, key, keyLength );
|
||||
(*env)->ReleaseByteArrayElements( env, buf, bufBytes, JNI_OK );
|
||||
mpw_free( &key, keyLength );
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
@@ -1,5 +1,4 @@
|
||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#undef __cplusplus
|
||||
#include <jni.h>
|
||||
/* Header for class com_lyndir_masterpassword_impl_MPAlgorithmV0 */
|
||||
|
||||
@@ -13,10 +12,10 @@ extern "C" {
|
||||
/*
|
||||
* Class: com_lyndir_masterpassword_impl_MPAlgorithmV0
|
||||
* Method: _scrypt
|
||||
* Signature: ([BI[BIIII[BI)I
|
||||
* Signature: ([B[BIII[B)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_lyndir_masterpassword_impl_MPAlgorithmV0__1scrypt
|
||||
(JNIEnv *, jobject, jbyteArray, jint, jbyteArray, jint, jint, jint, jint, jbyteArray, jint);
|
||||
(JNIEnv *, jobject, jbyteArray, jbyteArray, jint, jint, jint, jbyteArray);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Reference in New Issue
Block a user