Skip to content

Commit

Permalink
Merge pull request #25 from xybei/master
Browse files Browse the repository at this point in the history
Optimize pom.xml & Some fixes
  • Loading branch information
jimouris authored Aug 20, 2024
2 parents debdf38 + 0ab4732 commit 2b15c8d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 64 deletions.
62 changes: 8 additions & 54 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,6 @@
</properties>

<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
Expand All @@ -53,7 +43,8 @@
</property>
</activation>
<properties>
<lib_name>liboqs-jni.jnilib</lib_name>
<lib_name>liboqs-jni</lib_name>
<lib_name_ext>jnilib</lib_name_ext>
<liboqs.include.dir>/usr/local/include</liboqs.include.dir>
<liboqs.lib.dir>/usr/local/lib</liboqs.lib.dir>
<java.os.include>-I${JAVA_HOME}/include -I${JAVA_HOME}/include/darwin</java.os.include>
Expand All @@ -69,7 +60,8 @@
</property>
</activation>
<properties>
<lib_name>liboqs-jni.so</lib_name>
<lib_name>liboqs-jni</lib_name>
<lib_name_ext>so</lib_name_ext>
<liboqs.include.dir>/usr/local/include</liboqs.include.dir>
<liboqs.lib.dir>/usr/local/lib</liboqs.lib.dir>
<java.os.include>-I${JAVA_HOME}/include -I${JAVA_HOME}/include/linux</java.os.include>
Expand All @@ -84,7 +76,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<argLine>-Xss10M -Djava.library.path=${basedir}/src/main/resources/</argLine>
<argLine>-Xss10M -Djava.library.path=${project.build.outputDirectory}</argLine>
</configuration>
</plugin>
<plugin>
Expand All @@ -95,23 +87,6 @@
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>initialize</phase>
<configuration>
<target>
<mkdir dir="${basedir}/src/main/resources/"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>native-maven-plugin</artifactId>
Expand Down Expand Up @@ -140,15 +115,15 @@
<compilerStartOption>-O3</compilerStartOption>
<compilerStartOption>-I${liboqs.include.dir}</compilerStartOption>
</compilerStartOptions>
<linkerOutputDirectory>target</linkerOutputDirectory>
<linkerOutputDirectory>${project.build.outputDirectory}</linkerOutputDirectory>
<linkerExecutable>gcc</linkerExecutable>
<linkerStartOptions>
<linkerStartOption>-shared</linkerStartOption>
<linkerStartOption>-L${liboqs.lib.dir}</linkerStartOption>
</linkerStartOptions>
<linkerFinalName/>
<linkerFinalName>${lib_name}</linkerFinalName>
<linkerFinalNameExt>${lib_name_ext}</linkerFinalNameExt>
<linkerEndOptions>
<linkerEndOption>-o ${basedir}/src/main/resources/${lib_name}</linkerEndOption>
<linkerEndOption>-loqs</linkerEndOption>
</linkerEndOptions>
</configuration>
Expand All @@ -164,27 +139,6 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>process-classes</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/resources/</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
10 changes: 5 additions & 5 deletions src/main/c/KeyEncapsulation.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ JNIEXPORT jint JNICALL Java_org_openquantumsafe_KeyEncapsulation_generate_1keypa
// Invoke liboqs KEM keypair generation function
OQS_STATUS rv_ = OQS_KEM_keypair(kem, (uint8_t*) public_key_native, (uint8_t*) secret_key_native);

(*env)->ReleaseByteArrayElements(env, jpublic_key, public_key_native, JNI_COMMIT);
(*env)->ReleaseByteArrayElements(env, jsecret_key, secret_key_native, JNI_COMMIT);
(*env)->ReleaseByteArrayElements(env, jpublic_key, public_key_native, 0);
(*env)->ReleaseByteArrayElements(env, jsecret_key, secret_key_native, 0);
return (rv_ == OQS_SUCCESS) ? 0 : -1;
}

Expand All @@ -129,8 +129,8 @@ JNIEXPORT jint JNICALL Java_org_openquantumsafe_KeyEncapsulation_encap_1secret

// Release C public_key
(*env)->ReleaseByteArrayElements(env, jpublic_key, public_key, JNI_ABORT);
(*env)->ReleaseByteArrayElements(env, jciphertext, ciphertext, JNI_COMMIT);
(*env)->ReleaseByteArrayElements(env, jshared_secret, shared_secret, JNI_COMMIT);
(*env)->ReleaseByteArrayElements(env, jciphertext, ciphertext, 0);
(*env)->ReleaseByteArrayElements(env, jshared_secret, shared_secret, 0);
return (rv_ == OQS_SUCCESS) ? 0 : -1;
}

Expand All @@ -150,7 +150,7 @@ JNIEXPORT jint JNICALL Java_org_openquantumsafe_KeyEncapsulation_decap_1secret
OQS_STATUS rv_ = OQS_KEM_decaps(kem, (uint8_t*) shared_secret_native, (uint8_t*) ciphertext_native, (uint8_t*) secret_key_native);

// release memory
(*env)->ReleaseByteArrayElements(env, jshared_secret, shared_secret_native, JNI_COMMIT);
(*env)->ReleaseByteArrayElements(env, jshared_secret, shared_secret_native, 0);
(*env)->ReleaseByteArrayElements(env, jciphertext, ciphertext_native, JNI_ABORT);
(*env)->ReleaseByteArrayElements(env, jsecret_key, secret_key_native, JNI_ABORT);
return (rv_ == OQS_SUCCESS) ? 0 : -1;
Expand Down
6 changes: 3 additions & 3 deletions src/main/c/Signature.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ JNIEXPORT jint JNICALL Java_org_openquantumsafe_Signature_generate_1keypair
// Invoke liboqs sig keypair generation function
OQS_STATUS rv_ = OQS_SIG_keypair(sig, (uint8_t*) public_key_native, (uint8_t*) secret_key_native);

(*env)->ReleaseByteArrayElements(env, jpublic_key, public_key_native, JNI_COMMIT);
(*env)->ReleaseByteArrayElements(env, jsecret_key, secret_key_native, JNI_COMMIT);
(*env)->ReleaseByteArrayElements(env, jpublic_key, public_key_native, 0);
(*env)->ReleaseByteArrayElements(env, jsecret_key, secret_key_native, 0);
return (rv_ == OQS_SUCCESS) ? 0 : -1;
}

Expand Down Expand Up @@ -140,7 +140,7 @@ JNIEXPORT jint JNICALL Java_org_openquantumsafe_Signature_sign
(*env)->SetObjectField(env, sig_len_obj, value_fid, jlong_obj);

// Release C memory
(*env)->ReleaseByteArrayElements(env, jsignature, signature_native, JNI_COMMIT);
(*env)->ReleaseByteArrayElements(env, jsignature, signature_native, 0);
(*env)->ReleaseByteArrayElements(env, jmessage, message_native, JNI_ABORT);
(*env)->ReleaseByteArrayElements(env, jsecret_key, secret_key_native, JNI_ABORT);

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/openquantumsafe/Pair.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public Pair(L left, R right) {

@Override
public boolean equals(Object o) {
if (!(o instanceof Pair)) return false;
Pair pairo = (Pair) o;
if (!(o instanceof Pair<?, ?>)) return false;
Pair<?, ?> pairo = (Pair<?, ?>) o;
return this.left.equals(pairo.getLeft()) && this.right.equals(pairo.getRight());
}

Expand Down

0 comments on commit 2b15c8d

Please sign in to comment.