Skip to content

Commit

Permalink
fix: add java package
Browse files Browse the repository at this point in the history
  • Loading branch information
cipriansofronia committed Jul 1, 2024
1 parent 6cb7e46 commit dd37049
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 72 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*.o
*.so
*.a
*.jar
.DS_Store
node_modules/
src/tests/opaque-munit
Expand All @@ -15,3 +16,4 @@ src/tests/opaque-tv1
src/tests/opaque-tv1.html
src/tests/opaque-tv1.js
src/utils/opaque
java/build
52 changes: 3 additions & 49 deletions java/opaque.java → java/io/opaque/Opaque.java
Original file line number Diff line number Diff line change
@@ -1,52 +1,6 @@
class OpaqueIds {
public OpaqueIds() {}
public OpaqueIds(byte[] idU_, byte[] idS_) {
idU = idU_;
idS = idS_;
}

public byte[] idU;
public byte[] idS;
}

class OpaqueRecExpKey {
public byte[] rec;
public byte[] export_key;
}

class OpaqueCredReq {
public byte[] sec;
public byte[] pub;
}

class OpaqueCredResp {
public byte[] sec;
public byte[] sk;
public byte[] pub;
}

class OpaqueCreds {
public byte[] sk;
public byte[] authU;
public byte[] export_key;
}

class OpaqueRegReq {
public byte[] sec;
public byte[] M;
}

class OpaqueRegResp {
public byte[] sec;
public byte[] pub;
}

class OpaquePreRecExpKey {
public byte[] rec;
public byte[] export_key;
}
package io.opaque;

class Opaque {
public class Opaque {
static {
System.loadLibrary("opaquejni");
}
Expand Down Expand Up @@ -113,4 +67,4 @@ public byte[] storeRec(byte[] sec, byte[] rec) {
private static native OpaqueRegResp c_createRegResp(byte[] M);
private static native OpaquePreRecExpKey c_finalizeReg(byte[] sec, byte[] pub, OpaqueIds ids);
private static native byte[] c_storeRec(byte[] sec, byte[] rec);
}
}
6 changes: 6 additions & 0 deletions java/io/opaque/OpaqueCredReq.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.opaque;

public class OpaqueCredReq {
public byte[] sec;
public byte[] pub;
}
7 changes: 7 additions & 0 deletions java/io/opaque/OpaqueCredResp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.opaque;

public class OpaqueCredResp {
public byte[] sec;
public byte[] sk;
public byte[] pub;
}
7 changes: 7 additions & 0 deletions java/io/opaque/OpaqueCreds.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.opaque;

public class OpaqueCreds {
public byte[] sk;
public byte[] authU;
public byte[] export_key;
}
12 changes: 12 additions & 0 deletions java/io/opaque/OpaqueIds.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.opaque;

public class OpaqueIds {
public OpaqueIds() {}
public OpaqueIds(byte[] idU_, byte[] idS_) {
idU = idU_;
idS = idS_;
}

public byte[] idU;
public byte[] idS;
}
6 changes: 6 additions & 0 deletions java/io/opaque/OpaquePreRecExpKey.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.opaque;

public class OpaquePreRecExpKey {
public byte[] rec;
public byte[] export_key;
}
6 changes: 6 additions & 0 deletions java/io/opaque/OpaqueRecExpKey.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.opaque;

public class OpaqueRecExpKey {
public byte[] rec;
public byte[] export_key;
}
6 changes: 6 additions & 0 deletions java/io/opaque/OpaqueRegReq.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.opaque;

public class OpaqueRegReq {
public byte[] sec;
public byte[] M;
}
6 changes: 6 additions & 0 deletions java/io/opaque/OpaqueRegResp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.opaque;

public class OpaqueRegResp {
public byte[] sec;
public byte[] pub;
}
42 changes: 21 additions & 21 deletions java/jni.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <jni.h>
#include "opaque.h"

static const char *JNIT_CLASS = "Opaque";
static const char *JNIT_CLASS = "io/opaque/Opaque";

static void exception(JNIEnv *env, const char* msg) {
jclass cls = (*env)->FindClass(env, "java/lang/Exception");
Expand Down Expand Up @@ -52,7 +52,7 @@ typedef struct {
static void getids(JNIEnv *env, jobject ids_, Opaque_Ids *ids, IdGC *gc) {
jclass cls;
jfieldID idUfid, idSfid;
cls = (*env)->FindClass(env, "OpaqueIds");
cls = (*env)->FindClass(env, "io/opaque/OpaqueIds");
idUfid = (*env)->GetFieldID(env, cls, "idU", "[B");
gc->idU = (jbyteArray)(*env)->GetObjectField(env, ids_, idUfid);
idSfid = (*env)->GetFieldID(env, cls, "idS", "[B");
Expand Down Expand Up @@ -128,7 +128,7 @@ static jobject c_register(JNIEnv *env, jobject obj, jstring pwd_, jbyteArray skS
{.key = "export_key", .val = export_key, .len = sizeof(export_key)},
{ .key = NULL, .val = NULL}};

return retlist(env, "OpaqueRecExpKey", ret);
return retlist(env, "io/opaque/OpaqueRecExpKey", ret);
}

static jobject c_register_noIds(JNIEnv *env, jobject obj, jstring pwd_, jbyteArray sks_) {
Expand Down Expand Up @@ -163,7 +163,7 @@ static jobject c_createCredReq(JNIEnv *env, jobject obj, jstring pwd_) {
{.key = "pub", .val = pub, .len = sizeof(pub)},
{ .key = NULL, .val = NULL}};

return retlist(env, "OpaqueCredReq", ret);
return retlist(env, "io/opaque/OpaqueCredReq", ret);
}

static jobject c_createCredResp(JNIEnv *env, jobject obj, jbyteArray pub_, jbyteArray rec_, jobject ids_, jstring context_) {
Expand Down Expand Up @@ -212,7 +212,7 @@ static jobject c_createCredResp(JNIEnv *env, jobject obj, jbyteArray pub_, jbyte
{.key = "pub", .val = resp, .len = sizeof(resp)},
{ .key = NULL, .val = NULL}};

return retlist(env, "OpaqueCredResp", ret);
return retlist(env, "io/opaque/OpaqueCredResp", ret);
}

static jobject c_recoverCredentials(JNIEnv *env, jobject obj, jbyteArray resp_, jbyteArray sec_, jstring context_, jobject ids_) {
Expand Down Expand Up @@ -268,8 +268,8 @@ static jobject c_recoverCredentials(JNIEnv *env, jobject obj, jbyteArray resp_,
{.key = "export_key", .val = export_key, .len = sizeof(export_key)},
{ .key = NULL, .val = NULL}};

jobject ret = retlist(env, "OpaqueCreds", retvals);
jclass clazz = (*env)->FindClass(env, "OpaqueCreds");
jobject ret = retlist(env, "io/opaque/OpaqueCreds", retvals);
jclass clazz = (*env)->FindClass(env, "io/opaque/OpaqueCreds");

return ret;
}
Expand Down Expand Up @@ -327,7 +327,7 @@ static jobject c_createRegReq(JNIEnv *env, jobject obj, jstring pwd_) {
{.key = "M", .val = M, .len = sizeof(M)},
{ .key = NULL, .val = NULL}};

return retlist(env, "OpaqueRegReq", ret);
return retlist(env, "io/opaque/OpaqueRegReq", ret);
}

static jobject c_createRegResp(JNIEnv *env, jobject obj, jbyteArray M_, jbyteArray sks_) {
Expand Down Expand Up @@ -368,7 +368,7 @@ static jobject c_createRegResp(JNIEnv *env, jobject obj, jbyteArray M_, jbyteArr
{.key = "pub", .val = pub, .len = sizeof(pub)},
{ .key = NULL, .val = NULL}};

return retlist(env, "OpaqueRegResp", ret);
return retlist(env, "io/opaque/OpaqueRegResp", ret);
}

static jobject c_createRegResp1(JNIEnv *env, jobject obj, jbyteArray M_) {
Expand Down Expand Up @@ -412,7 +412,7 @@ static jobject c_finalizeReg(JNIEnv *env, jobject obj, jbyteArray sec_, jbyteArr
{.key = "export_key", .val = export_key, .len = sizeof(export_key)},
{ .key = NULL, .val = NULL}};

return retlist(env, "OpaquePreRecExpKey", ret);
return retlist(env, "io/opaque/OpaquePreRecExpKey", ret);
}

static jbyteArray c_storeRec(JNIEnv *env, jobject obj, jbyteArray sec_, jbyteArray recU_) {
Expand Down Expand Up @@ -449,18 +449,18 @@ static jbyteArray c_storeRec(JNIEnv *env, jobject obj, jbyteArray sec_, jbyteArr


static JNINativeMethod funcs[] = {
{ "c_register", "(Ljava/lang/String;[BLOpaqueIds;)LOpaqueRecExpKey;", (void *)&c_register },
{ "c_register", "(Ljava/lang/String;[B)LOpaqueRecExpKey;", (void *)&c_register_noIds },
{ "c_register", "(Ljava/lang/String;LOpaqueIds;)LOpaqueRecExpKey;", (void *)&c_register_noSks },
{ "c_register", "(Ljava/lang/String;)LOpaqueRecExpKey;", (void *)&c_register1 },
{ "c_createCredReq", "(Ljava/lang/String;)LOpaqueCredReq;", (void *)&c_createCredReq },
{ "c_createCredResp", "([B[BLOpaqueIds;Ljava/lang/String;)LOpaqueCredResp;", (void *)&c_createCredResp },
{ "c_recoverCreds", "([B[BLjava/lang/String;LOpaqueIds;)LOpaqueCreds;", (void *)&c_recoverCredentials },
{ "c_register", "(Ljava/lang/String;[BLio/opaque/OpaqueIds;)Lio/opaque/OpaqueRecExpKey;", (void *)&c_register },
{ "c_register", "(Ljava/lang/String;[B)Lio/opaque/OpaqueRecExpKey;", (void *)&c_register_noIds },
{ "c_register", "(Ljava/lang/String;Lio/opaque/OpaqueIds;)Lio/opaque/OpaqueRecExpKey;", (void *)&c_register_noSks },
{ "c_register", "(Ljava/lang/String;)Lio/opaque/OpaqueRecExpKey;", (void *)&c_register1 },
{ "c_createCredReq", "(Ljava/lang/String;)Lio/opaque/OpaqueCredReq;", (void *)&c_createCredReq },
{ "c_createCredResp", "([B[BLio/opaque/OpaqueIds;Ljava/lang/String;)Lio/opaque/OpaqueCredResp;", (void *)&c_createCredResp },
{ "c_recoverCreds", "([B[BLjava/lang/String;Lio/opaque/OpaqueIds;)Lio/opaque/OpaqueCreds;", (void *)&c_recoverCredentials },
{ "c_userAuth", "([B[B)Z", (void *)&c_userAuth },
{ "c_createRegReq", "(Ljava/lang/String;)LOpaqueRegReq;", (void *)&c_createRegReq },
{ "c_createRegResp", "([B[B)LOpaqueRegResp;", (void *)&c_createRegResp},
{ "c_createRegResp", "([B)LOpaqueRegResp;", (void *)&c_createRegResp1},
{ "c_finalizeReg", "([B[BLOpaqueIds;)LOpaquePreRecExpKey;", (void *)&c_finalizeReg },
{ "c_createRegReq", "(Ljava/lang/String;)Lio/opaque/OpaqueRegReq;", (void *)&c_createRegReq },
{ "c_createRegResp", "([B[B)Lio/opaque/OpaqueRegResp;", (void *)&c_createRegResp},
{ "c_createRegResp", "([B)Lio/opaque/OpaqueRegResp;", (void *)&c_createRegResp1},
{ "c_finalizeReg", "([B[BLio/opaque/OpaqueIds;)Lio/opaque/OpaquePreRecExpKey;", (void *)&c_finalizeReg },
{ "c_storeRec", "([B[B)[B", (void *)&c_storeRec },
};

Expand Down
5 changes: 3 additions & 2 deletions java/makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
JAVAINCLUDES?=/usr/lib/jvm/java-11-openjdk/include/
JAVA_SOURCES = $(wildcard io/opaque/*.java)

all: opaque.jar libopaquejni.so

opaque.jar: test.java opaque.java jni.c
javac -d build test.java opaque.java
opaque.jar: test.java $(JAVA_SOURCES) jni.c
javac -d build test.java $(JAVA_SOURCES)
jar -cvfe opaque.jar Main build

libopaquejni.so: jni.c
Expand Down
1 change: 1 addition & 0 deletions java/test.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import java.nio.charset.*;
import io.opaque.*;

class Main {
public static void main(String args[]) {
Expand Down

0 comments on commit dd37049

Please sign in to comment.