mirror of
https://gitlab.com/spectre.app/cli.git
synced 2024-11-01 10:51:44 +01:00
Initial integration of JNI with C implementation.
This commit is contained in:
parent
86f107dafc
commit
81f7616bd0
6 changed files with 25 additions and 8 deletions
|
@ -70,7 +70,8 @@ static MPMasterKey mpw_masterKey_v0(
|
|||
|
||||
// Calculate the master key.
|
||||
trc( "masterKey: scrypt( masterPassword, masterKeySalt, N=%lu, r=%u, p=%u )", MP_N, MP_r, MP_p );
|
||||
MPMasterKey masterKey = mpw_kdf_scrypt( MPMasterKeySize, masterPassword, masterKeySalt, masterKeySaltSize, MP_N, MP_r, MP_p );
|
||||
MPMasterKey masterKey = mpw_kdf_scrypt( MPMasterKeySize,
|
||||
(uint8_t *)masterPassword, strlen( masterPassword ), masterKeySalt, masterKeySaltSize, MP_N, MP_r, MP_p );
|
||||
mpw_free( &masterKeySalt, masterKeySaltSize );
|
||||
if (!masterKey) {
|
||||
err( "Could not derive master key: %s", strerror( errno ) );
|
||||
|
|
|
@ -62,7 +62,8 @@ static MPMasterKey mpw_masterKey_v3(
|
|||
|
||||
// Calculate the master key.
|
||||
trc( "masterKey: scrypt( masterPassword, masterKeySalt, N=%lu, r=%u, p=%u )", MP_N, MP_r, MP_p );
|
||||
MPMasterKey masterKey = mpw_kdf_scrypt( MPMasterKeySize, masterPassword, masterKeySalt, masterKeySaltSize, MP_N, MP_r, MP_p );
|
||||
MPMasterKey masterKey = mpw_kdf_scrypt( MPMasterKeySize,
|
||||
(uint8_t *)masterPassword, strlen( masterPassword ), masterKeySalt, masterKeySaltSize, MP_N, MP_r, MP_p );
|
||||
mpw_free( &masterKeySalt, masterKeySaltSize );
|
||||
if (!masterKey) {
|
||||
err( "Could not derive master key: %s", strerror( errno ) );
|
||||
|
|
|
@ -1,8 +1,22 @@
|
|||
#include <string.h>
|
||||
|
||||
#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); */
|
||||
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, jint passwdlen, jbyteArray salt, jint saltlen, jint N, jint r, jint p, jbyteArray buf, jint buflen) {
|
||||
|
||||
return -2;
|
||||
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,
|
||||
(uint64_t)N, (uint32_t)r, (uint32_t)p );
|
||||
(*env)->ReleaseByteArrayElements( env, passwd, passwdBytes, JNI_ABORT );
|
||||
(*env)->ReleaseByteArrayElements( env, salt, saltBytes, JNI_ABORT );
|
||||
|
||||
if (!key)
|
||||
return ERR;
|
||||
|
||||
memcpy( buf, key, buflen );
|
||||
return OK;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#undef __cplusplus
|
||||
#include <jni.h>
|
||||
/* Header for class com_lyndir_masterpassword_impl_MPAlgorithmV0 */
|
||||
|
||||
|
|
|
@ -169,10 +169,10 @@ bool __mpw_free_strings(char **strings, ...) {
|
|||
return success;
|
||||
}
|
||||
|
||||
uint8_t const *mpw_kdf_scrypt(const size_t keySize, const char *secret, const uint8_t *salt, const size_t saltSize,
|
||||
uint8_t const *mpw_kdf_scrypt(const size_t keySize, const uint8_t *secret, const size_t secretSize, const uint8_t *salt, const size_t saltSize,
|
||||
uint64_t N, uint32_t r, uint32_t p) {
|
||||
|
||||
if (!secret || !salt)
|
||||
if (!secret || !salt || !secretSize || !saltSize)
|
||||
return NULL;
|
||||
|
||||
uint8_t *key = malloc( keySize );
|
||||
|
@ -185,7 +185,7 @@ uint8_t const *mpw_kdf_scrypt(const size_t keySize, const char *secret, const ui
|
|||
return NULL;
|
||||
}
|
||||
#elif MPW_SODIUM
|
||||
if (crypto_pwhash_scryptsalsa208sha256_ll( (const uint8_t *)secret, strlen( secret ), salt, saltSize, N, r, p, key, keySize ) != 0) {
|
||||
if (crypto_pwhash_scryptsalsa208sha256_ll( secret, secretSize, salt, saltSize, N, r, p, key, keySize ) != 0) {
|
||||
mpw_free( &key, keySize );
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -156,7 +156,7 @@ bool __mpw_free_strings(
|
|||
/** Derive a key from the given secret and salt using the scrypt KDF.
|
||||
* @return A new keySize allocated buffer containing the key. */
|
||||
uint8_t const *mpw_kdf_scrypt(
|
||||
const size_t keySize, const char *secret, const uint8_t *salt, const size_t saltSize,
|
||||
const size_t keySize, const uint8_t *secret, const size_t secretSize, const uint8_t *salt, const size_t saltSize,
|
||||
uint64_t N, uint32_t r, uint32_t p);
|
||||
/** Derive a subkey from the given key using the blake2b KDF.
|
||||
* @return A new keySize allocated buffer containing the key. */
|
||||
|
|
Loading…
Reference in a new issue