aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2015-11-04 21:27:24 +0100
committerVincent Breitmoser <valodim@mugenguild.com>2015-11-04 21:27:24 +0100
commit33e8699be5fe7b1c756b3bdced7646772a6c6026 (patch)
tree6531321e8f3758fd10fdbd6c4cc4634c5b90ac9d /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations
parent0a266cdb4a15b01ec692eb5d3b69b3a361011245 (diff)
downloadopen-keychain-33e8699be5fe7b1c756b3bdced7646772a6c6026.tar.gz
open-keychain-33e8699be5fe7b1c756b3bdced7646772a6c6026.tar.bz2
open-keychain-33e8699be5fe7b1c756b3bdced7646772a6c6026.zip
bench: add simple s2k benchmark (iterations for 100ms)
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BenchmarkOperation.java51
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java2
2 files changed, 50 insertions, 3 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BenchmarkOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BenchmarkOperation.java
index 7d301d830..f6e157c74 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BenchmarkOperation.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BenchmarkOperation.java
@@ -25,6 +25,15 @@ import java.util.Random;
import android.content.Context;
import android.support.annotation.NonNull;
+import org.spongycastle.bcpg.HashAlgorithmTags;
+import org.spongycastle.bcpg.S2K;
+import org.spongycastle.bcpg.SymmetricKeyAlgorithmTags;
+import org.spongycastle.openpgp.PGPException;
+import org.spongycastle.openpgp.operator.PBEDataDecryptorFactory;
+import org.spongycastle.openpgp.operator.PGPDigestCalculatorProvider;
+import org.spongycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder;
+import org.spongycastle.openpgp.operator.jcajce.JcePBEDataDecryptorFactoryBuilder;
+import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.operations.results.BenchmarkResult;
import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult;
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
@@ -37,6 +46,7 @@ import org.sufficientlysecure.keychain.pgp.SignEncryptParcel;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.service.BenchmarkInputParcel;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
+import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Passphrase;
import org.sufficientlysecure.keychain.util.ProgressScaler;
@@ -81,8 +91,7 @@ public class BenchmarkOperation extends BaseOperation<BenchmarkInputParcel> {
totalTime += encryptResult.getResults().get(0).mOperationTime;
} while (++i < numRepeats);
- log.add(LogType.MSG_BENCH_ENC_TIME_AVG, 1, String.format("%.2f", totalTime / numRepeats /1000.0));
-
+ long encryptionTime = totalTime / numRepeats;
totalTime = 0;
// decrypt
@@ -100,7 +109,43 @@ public class BenchmarkOperation extends BaseOperation<BenchmarkInputParcel> {
totalTime += decryptResult.mOperationTime;
} while (++i < numRepeats);
- log.add(LogType.MSG_BENCH_DEC_TIME_AVG, 1, String.format("%.2f", totalTime / numRepeats / 1000.0));
+ long decryptionTime = totalTime / numRepeats;
+ totalTime = 0;
+
+ int iterationsFor100ms;
+ try {
+ PGPDigestCalculatorProvider digestCalcProvider = new JcaPGPDigestCalculatorProviderBuilder()
+ .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build();
+ PBEDataDecryptorFactory decryptorFactory = new JcePBEDataDecryptorFactoryBuilder(
+ digestCalcProvider).setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(
+ "".toCharArray());
+
+ byte[] iv = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
+ int iterations = 0;
+ while (iterations < 255 && totalTime < 100) {
+ iterations += 1;
+
+ S2K s2k = new S2K(HashAlgorithmTags.SHA1, iv, iterations);
+ totalTime = System.currentTimeMillis();
+ decryptorFactory.makeKeyFromPassPhrase(SymmetricKeyAlgorithmTags.AES_128, s2k);
+ totalTime = System.currentTimeMillis() -totalTime;
+
+ if ((iterations % 10) == 0) {
+ log.add(LogType.MSG_BENCH_S2K_FOR_IT, 1, Integer.toString(iterations), Long.toString(totalTime));
+ }
+
+ }
+ iterationsFor100ms = iterations;
+
+ } catch (PGPException e) {
+ Log.e(Constants.TAG, "internal error during benchmark", e);
+ log.add(LogType.MSG_INTERNAL_ERROR, 0);
+ return new BenchmarkResult(BenchmarkResult.RESULT_ERROR, log);
+ }
+
+ log.add(LogType.MSG_BENCH_S2K_100MS_ITS, 1, Integer.toString(iterationsFor100ms));
+ log.add(LogType.MSG_BENCH_ENC_TIME_AVG, 1, String.format("%.2f", encryptionTime/1000.0));
+ log.add(LogType.MSG_BENCH_DEC_TIME_AVG, 1, String.format("%.2f", decryptionTime/1000.0));
log.add(LogType.MSG_BENCH_SUCCESS, 0);
return new BenchmarkResult(BenchmarkResult.RESULT_OK, log);
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java
index 65c36d246..9b061861c 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java
@@ -880,6 +880,8 @@ public abstract class OperationResult implements Parcelable {
MSG_BENCH_ENC_TIME_AVG (LogLevel.INFO, R.string.msg_bench_enc_time_avg),
MSG_BENCH_DEC_TIME (LogLevel.DEBUG, R.string.msg_bench_dec_time),
MSG_BENCH_DEC_TIME_AVG (LogLevel.INFO, R.string.msg_bench_enc_time_avg),
+ MSG_BENCH_S2K_FOR_IT (LogLevel.DEBUG, R.string.msg_bench_s2k_for_it),
+ MSG_BENCH_S2K_100MS_ITS (LogLevel.INFO, R.string.msg_bench_s2k_100ms_its),
MSG_BENCH_SUCCESS (LogLevel.OK, R.string.msg_bench_success),
;