mirror of
https://github.com/signalapp/libsignal.git
synced 2024-09-20 03:52:17 +02:00
Android: Add very basic Curve25519 benchmarks
This commit is contained in:
parent
f6e5f9772f
commit
98fd87ee9b
5
.gitignore
vendored
5
.gitignore
vendored
@ -15,10 +15,7 @@
|
||||
\#*\#
|
||||
.\#*
|
||||
|
||||
java/build
|
||||
java/android/build/
|
||||
java/client/build
|
||||
java/server/build
|
||||
java/**/build
|
||||
java/.gradle
|
||||
java/local.properties
|
||||
java/android/src/main/jniLibs
|
||||
|
38
java/android/benchmarks/build.gradle
Normal file
38
java/android/benchmarks/build.gradle
Normal file
@ -0,0 +1,38 @@
|
||||
plugins {
|
||||
id 'com.android.library' version '7.0.0'
|
||||
id 'androidx.benchmark' version '1.1.1'
|
||||
}
|
||||
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 31
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 30
|
||||
multiDexEnabled true
|
||||
}
|
||||
|
||||
testBuildType "release"
|
||||
|
||||
compileOptions {
|
||||
coreLibraryDesugaringEnabled true
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
namespace "org.signal.libsignal.benchmarks"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
androidTestImplementation "androidx.test:runner:1.4.0"
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
androidTestImplementation 'androidx.benchmark:benchmark-junit4:1.1.1'
|
||||
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.6'
|
||||
androidTestImplementation project(':android')
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<application
|
||||
android:debuggable="false"/>
|
||||
</manifest>
|
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright (C) 2022 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
|
||||
import org.signal.libsignal.protocol.ecc.*;
|
||||
|
||||
import androidx.benchmark.BenchmarkState;
|
||||
import androidx.benchmark.junit4.BenchmarkRule;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ECCBenchmark {
|
||||
@Rule
|
||||
public final BenchmarkRule benchmarkRule = new BenchmarkRule();
|
||||
|
||||
private final ECKeyPair alicePair = Curve.generateKeyPair();
|
||||
private final ECKeyPair bobPair = Curve.generateKeyPair();
|
||||
private final byte[] arbitraryData = new byte[] { 0x53, 0x69, 0x67, 0x6E, 0x61, 0x6C };
|
||||
|
||||
@Test
|
||||
public void benchmarkKeyAgreement() {
|
||||
final BenchmarkState state = benchmarkRule.getState();
|
||||
|
||||
while (state.keepRunning()) {
|
||||
alicePair.getPrivateKey().calculateAgreement(bobPair.getPublicKey());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void benchmarkSignature() {
|
||||
final BenchmarkState state = benchmarkRule.getState();
|
||||
|
||||
while (state.keepRunning()) {
|
||||
final byte[] signature = alicePair.getPrivateKey().calculateSignature(arbitraryData);
|
||||
alicePair.getPublicKey().verifySignature(arbitraryData, signature);
|
||||
}
|
||||
}
|
||||
}
|
2
java/android/benchmarks/src/main/AndroidManifest.xml
Normal file
2
java/android/benchmarks/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1,2 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
</manifest>
|
@ -1 +1,2 @@
|
||||
android.enableAdditionalTestOutput=true
|
||||
android.useAndroidX=true
|
@ -9,7 +9,7 @@ pluginManagement {
|
||||
include ':client', ':server'
|
||||
|
||||
if (JavaVersion.current().isJava11Compatible()) {
|
||||
include ':android'
|
||||
include ':android', ':android:benchmarks'
|
||||
} else if (gradle.startParameter.getTaskNames().any { name -> name.contains('android:') }) {
|
||||
throw new GradleException("building for Android requires JDK 11 or newer")
|
||||
} else if (gradle.startParameter.getTaskNames().any { name -> name.lastIndexOf(':') <= 0 }) {
|
||||
|
Loading…
Reference in New Issue
Block a user