Skip to content

Update liboqs library to latest version #337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class SessionNewRequestBody {
@SerializedName("kem_public_key1")
@Expose
private String kemPublicKey;
@SerializedName("kem_library_version")
@Expose
private String kemLibraryVersion;
@SerializedName("app_name")
@Expose
private String appName;
Expand All @@ -56,6 +59,7 @@ public SessionNewRequestBody(String username, String wgPublicKey, String kemPubl
this.username = username;
this.wgPublicKey = wgPublicKey;
this.kemPublicKey = kemPublicKey;
this.kemLibraryVersion = "0.10.0";
this.appName = "IVPN for Android";
this.force = force;
}
Expand All @@ -64,6 +68,7 @@ public SessionNewRequestBody(String username, String wgPublicKey, String kemPubl
this.username = username;
this.wgPublicKey = wgPublicKey;
this.kemPublicKey = kemPublicKey;
this.kemLibraryVersion = "0.10.0";
this.appName = "IVPN for Android";
this.force = force;
this.tfaToken = tfaToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,23 @@ public class AddWireGuardPublicKeyRequestBody {
@SerializedName("kem_public_key1")
@Expose
private String kemPublicKey;
@SerializedName("kem_library_version")
@Expose
private String kemLibraryVersion;

public AddWireGuardPublicKeyRequestBody(String sessionToken, String publicKey, String connectedPublicKey, String kemPublicKey) {
this.sessionToken = sessionToken;
this.publicKey = publicKey;
this.connectedPublicKey = connectedPublicKey;
this.kemPublicKey = kemPublicKey;
this.kemLibraryVersion = "0.10.0";
}

public AddWireGuardPublicKeyRequestBody(String sessionToken, String publicKey, String kemPublicKey) {
this.sessionToken = sessionToken;
this.publicKey = publicKey;
this.kemPublicKey = kemPublicKey;
this.kemLibraryVersion = "0.10.0";
}

public String getSessionToken() {
Expand Down
1 change: 0 additions & 1 deletion liboqs-android/jni/jni/KeyEncapsulation.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ JNIEXPORT jobject JNICALL Java_net_ivpn_liboqs_KeyEncapsulation_get_1KEM_1detail

// Call back constructor to allocate a new instance, with an int argument
jobject _nativeKED = (*env)->NewObject(env, cls, constructor_meth_id_, obj);
// We need to pass obj (superclass) additionally to run on android: https://stackoverflow.com/questions/25363027/jni-getmethodid-not-working-for-constructor-of-inner-class

OQS_KEM *kem = (OQS_KEM *) getHandle(env, obj, "native_kem_handle_");

Expand Down
21 changes: 0 additions & 21 deletions liboqs-android/jni/jni/Rand.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,3 @@ JNIEXPORT jint JNICALL Java_net_ivpn_liboqs_Rand_randombytes_1switch_1algorithm_
(*env)->ReleaseStringUTFChars(env, jstr, alg_name_native);
return (rv_ == OQS_SUCCESS) ? 0 : -1;
}

/*
* Class: org_openquantumsafe_Rand
* Method: randombytes_nist_kat_init
* Signature: ([B[BJ)V
*/
JNIEXPORT void JNICALL Java_net_ivpn_liboqs_Rand_randombytes_1nist_1kat_1init
(JNIEnv *env, jclass cls, jbyteArray jentropy_input, jbyteArray jpers_str, jlong pers_str_len)
{
jbyte *entropy_input_native = (*env)->GetByteArrayElements(env, jentropy_input, 0);

if (pers_str_len == 0) {
OQS_randombytes_nist_kat_init_256bit((uint8_t*) entropy_input_native, NULL);
} else {
jbyte *pers_str_native = (*env)->GetByteArrayElements(env, jpers_str, 0);
OQS_randombytes_nist_kat_init_256bit((uint8_t*) entropy_input_native, (uint8_t*) pers_str_native);
(*env)->ReleaseByteArrayElements(env, jpers_str, pers_str_native, JNI_ABORT);
}

(*env)->ReleaseByteArrayElements(env, jentropy_input, entropy_input_native, JNI_ABORT);
}
8 changes: 0 additions & 8 deletions liboqs-android/jni/jni/Rand.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion liboqs-android/jni/liboqs
Submodule liboqs updated 2034 files
38 changes: 32 additions & 6 deletions liboqs-android/src/main/java/net/ivpn/liboqs/Common.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package net.ivpn.liboqs;

import android.os.Build;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.util.Arrays;

public class Common {
Expand All @@ -25,10 +28,33 @@ public static boolean isLinux() {
}

public static void loadNativeLibrary() {
System.err.println("---------------------------");
System.err.println("Loading liboqs for: " + Build.CPU_ABI);
System.err.println("---------------------------");
System.loadLibrary("oqs-jni");
// If the library is in the java library path, load it directly. (e.g., -Djava.library.path=src/main/resources)
try {
System.loadLibrary("oqs-jni");
// Otherwise load the library from the liboqs-java.jar
} catch (UnsatisfiedLinkError e) {
String libName = "llliboqs-jni.so";
if (Common.isLinux()) {
libName = "liboqs-jni.so";
} else if (Common.isMac()) {
libName = "liboqs-jni.jnilib";
} else if (Common.isWindows()) {
libName = "oqs-jni.dll";
}
URL url = KEMs.class.getResource("/" + libName);
File tmpDir;
try {
tmpDir = Files.createTempDirectory("oqs-native-lib").toFile();
tmpDir.deleteOnExit();
File nativeLibTmpFile = new File(tmpDir, libName);
nativeLibTmpFile.deleteOnExit();
InputStream in = url.openStream();
Files.copy(in, nativeLibTmpFile.toPath());
System.load(nativeLibTmpFile.getAbsolutePath());
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
}

public static <E, T extends Iterable<E>> void print_list(T list) {
Expand Down
6 changes: 3 additions & 3 deletions liboqs-android/src/main/java/net/ivpn/liboqs/KEMs.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ public class KEMs {
/**
* The single KEMs class instance.
*/
private static KEMs single_instance = null;
private static KEMs single_instance = null;

private KEMs() {}

/**
* \brief Make sure that at most one instance is generated.
* \return Singleton instance
*/
public static synchronized KEMs get_instance() {
public static synchronized KEMs get_instance() {
if (single_instance == null) {
single_instance = new KEMs();
single_instance = new KEMs();
}
return single_instance;
}
Expand Down
35 changes: 0 additions & 35 deletions liboqs-android/src/main/java/net/ivpn/liboqs/Rand.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,39 +36,4 @@ public static void randombytes_switch_algorithm(String alg_name)
throw new RuntimeException("Cannot switch rand algorithm");
}
}

/**
* \brief Wrapper for OQS_API void OQS_randombytes_nist_kat_init(
* const uint8_t *entropy_input,
* const uint8_t *personalization_string,
* int security_strength);
*
* \param Entropy input seed, must be exactly 48 bytes long
* \param Entropy seed length
* \param Optional personalization string, which, if non-empty, must be at
* least 48 byte[] long
* \param personalization string length
*/
private static native void randombytes_nist_kat_init(byte[] entropy_input,
byte[] personalization_string,
long personalization_string_len);

public static void randombytes_nist_kat_init(byte[] entropy_input) {
randombytes_nist_kat_init(entropy_input, null);
}

public static void randombytes_nist_kat_init(byte[] entropy_input,
byte[] personalization_string) {
if (entropy_input.length != 48) {
throw new RuntimeException("The entropy source must be exactly 48 byte[] long");
}
if (personalization_string == null) {
randombytes_nist_kat_init(entropy_input, null, 0);
return;
}
if (personalization_string.length < 48) {
throw new RuntimeException("The personalization string must be either empty or at least 48 byte[] long");
}
randombytes_nist_kat_init(entropy_input, personalization_string, personalization_string.length);
}
}
6 changes: 3 additions & 3 deletions liboqs-android/src/main/java/net/ivpn/liboqs/Sigs.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ public class Sigs {
/**
* The single Sigs class instance.
*/
private static Sigs single_instance = null;
private static Sigs single_instance = null;

private Sigs() {}

/**
* \brief Make sure that at most one instance is generated.
* \return Singleton instance
*/
public static synchronized Sigs get_instance() {
public static synchronized Sigs get_instance() {
if (single_instance == null) {
single_instance = new Sigs();
single_instance = new Sigs();
}
return single_instance;
}
Expand Down
Loading