Skip to content

Commit

Permalink
Merge pull request #10 from dnet/master
Browse files Browse the repository at this point in the history
further fixes to make JNI wrapper actually work again
  • Loading branch information
stef authored Feb 7, 2021
2 parents e480cd0 + 459699c commit cc7923b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
13 changes: 9 additions & 4 deletions src/jni.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#include <jni.h>
#include "sphinx.h"

JNIEXPORT void JNICALL Java_org_hsbp_androsphinx_Sphinx_challenge(JNIEnv *env, jobject ignore, jbyteArray pwd, jbyteArray bfac, jbyteArray chal) {
JNIEXPORT void JNICALL Java_org_hsbp_androsphinx_Sphinx_challenge(JNIEnv *env, jobject ignore, jbyteArray pwd, jbyteArray salt, jbyteArray bfac, jbyteArray chal) {
jbyte* bufferPtrPwd = (*env)->GetByteArrayElements(env, pwd, NULL);
jbyte* bufferPtrSalt = (*env)->GetByteArrayElements(env, salt, NULL);
jbyte* bufferPtrBfac = (*env)->GetByteArrayElements(env, bfac, NULL);
jbyte* bufferPtrChal = (*env)->GetByteArrayElements(env, chal, NULL);
jsize pwdLen = (*env)->GetArrayLength(env, pwd);
jsize saltLen = (*env)->GetArrayLength(env, salt);

sphinx_challenge(bufferPtrPwd, pwdLen, NULL, 0, bufferPtrBfac, bufferPtrChal);
sphinx_challenge(bufferPtrPwd, pwdLen, bufferPtrSalt, saltLen, bufferPtrBfac, bufferPtrChal);

(*env)->ReleaseByteArrayElements(env, pwd, bufferPtrPwd, JNI_ABORT);
(*env)->ReleaseByteArrayElements(env, salt, bufferPtrSalt, JNI_ABORT);
(*env)->ReleaseByteArrayElements(env, bfac, bufferPtrBfac, 0);
(*env)->ReleaseByteArrayElements(env, chal, bufferPtrChal, 0);
}
Expand All @@ -30,18 +33,20 @@ JNIEXPORT jbyteArray JNICALL Java_org_hsbp_androsphinx_Sphinx_respond(JNIEnv *en
return result ? NULL : resp;
}

JNIEXPORT jbyteArray JNICALL Java_org_hsbp_androsphinx_Sphinx_finish(JNIEnv *env, jobject ignore, jbyteArray pwd, jbyteArray bfac, jbyteArray resp) {
JNIEXPORT jbyteArray JNICALL Java_org_hsbp_androsphinx_Sphinx_finish(JNIEnv *env, jobject ignore, jbyteArray pwd, jbyteArray bfac, jbyteArray salt, jbyteArray resp) {
jbyte* bufferPtrPwd = (*env)->GetByteArrayElements(env, pwd, NULL);
jbyte* bufferPtrBfac = (*env)->GetByteArrayElements(env, bfac, NULL);
jbyte* bufferPtrSalt = (*env)->GetByteArrayElements(env, salt, NULL);
jbyte* bufferPtrResp = (*env)->GetByteArrayElements(env, resp, NULL);
jsize pwdLen = (*env)->GetArrayLength(env, pwd);

jbyteArray rwd = (*env)->NewByteArray(env, SPHINX_255_SER_BYTES);
jbyte* bufferPtrRwd = (*env)->GetByteArrayElements(env, rwd, NULL);

int result = sphinx_finish(bufferPtrPwd, pwdLen, bufferPtrBfac, bufferPtrResp, NULL, bufferPtrRwd);
int result = sphinx_finish(bufferPtrPwd, pwdLen, bufferPtrBfac, bufferPtrResp, bufferPtrSalt, bufferPtrRwd);

(*env)->ReleaseByteArrayElements(env, rwd, bufferPtrRwd, result ? JNI_ABORT : 0);
(*env)->ReleaseByteArrayElements(env, salt, bufferPtrSalt, JNI_ABORT);
(*env)->ReleaseByteArrayElements(env, resp, bufferPtrResp, JNI_ABORT);
(*env)->ReleaseByteArrayElements(env, bfac, bufferPtrBfac, JNI_ABORT);
(*env)->ReleaseByteArrayElements(env, pwd, bufferPtrPwd, JNI_ABORT);
Expand Down
2 changes: 1 addition & 1 deletion src/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ bin/2pass$(EXT): bin/2pass.c
$(CC) $(CFLAGS) -o bin/2pass$(EXT) bin/2pass.c $(LDFLAGS)

libsphinx.$(SOEXT): common.o sphinx.o $(EXTRA_OBJECTS)
$(CC) -shared -fpic $(CFLAGS) -o libsphinx.$(SOEXT) $^ $(LDFLAGS)
$(CC) -shared -fpic $(CFLAGS) -o libsphinx.$(SOEXT) common.o sphinx.o $(EXTRA_OBJECTS) $(LDFLAGS)

tests/sphinx$(EXT): tests/test.c libsphinx.$(SOEXT)
$(CC) $(CFLAGS) -o tests/sphinx$(EXT) tests/test.c -L. -lsphinx $(LDFLAGS)
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int main(void) {
if(0!=sphinx_respond(chal, secret, resp)) {
return 1;
}
if(0!=sphinx_finish(pwd, sizeof pwd, bfac, resp, salt, rwd)) {
if(0!=sphinx_finish(pwd, strlen((char*) pwd), bfac, resp, salt, rwd)) {
return 1;
}

Expand Down

0 comments on commit cc7923b

Please sign in to comment.