aboutsummaryrefslogtreecommitdiff
path: root/src/crypto
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2018-09-20 02:56:13 +0200
committerFlorian Dold <florian.dold@gmail.com>2018-09-20 02:56:13 +0200
commitbbff7403fbf46f9ad92240ac213df8d30ef31b64 (patch)
treec58400ec5124da1c7d56b01aea83309f80a56c3b /src/crypto
parent003fb34971cf63466184351b4db5f7c67df4f444 (diff)
downloadwallet-core-bbff7403fbf46f9ad92240ac213df8d30ef31b64.tar.xz
update packages
Diffstat (limited to 'src/crypto')
-rw-r--r--src/crypto/cryptoApi.ts7
-rw-r--r--src/crypto/cryptoWorker.ts83
-rw-r--r--src/crypto/emscInterface.ts4
3 files changed, 91 insertions, 3 deletions
diff --git a/src/crypto/cryptoApi.ts b/src/crypto/cryptoApi.ts
index c1f3f4245..03c2a675b 100644
--- a/src/crypto/cryptoApi.ts
+++ b/src/crypto/cryptoApi.ts
@@ -41,6 +41,7 @@ import {
} from "../talerTypes";
import {
+ BenchmarkResult,
CoinWithDenom,
PayCoinInfo,
} from "../walletTypes";
@@ -323,4 +324,10 @@ export class CryptoApi {
newCoinDenoms,
meltFee);
}
+
+ benchmark(repetitions: number): Promise<BenchmarkResult> {
+ return this.doRpc<BenchmarkResult>("benchmark",
+ 1,
+ repetitions);
+ }
}
diff --git a/src/crypto/cryptoWorker.ts b/src/crypto/cryptoWorker.ts
index 88e30e55b..7cec5f284 100644
--- a/src/crypto/cryptoWorker.ts
+++ b/src/crypto/cryptoWorker.ts
@@ -25,6 +25,8 @@
import * as Amounts from "../amounts";
import { AmountJson } from "../amounts";
+import * as timer from "../timer";
+
import {
CoinRecord,
CoinStatus,
@@ -44,6 +46,7 @@ import {
} from "../talerTypes";
import {
+ BenchmarkResult,
CoinWithDenom,
PayCoinInfo,
} from "../walletTypes";
@@ -437,7 +440,7 @@ namespace RpcFunctions {
const confirmSig: string = native.eddsaSign(confirmData.toPurpose(),
- native.EddsaPrivateKey.fromCrock(
+ native.EddsaPrivateKey.fromCrock(
meltCoin.coinPriv)).toCrock();
let valueOutput = Amounts.getZero(newCoinDenoms[0].value.currency);
@@ -478,6 +481,84 @@ namespace RpcFunctions {
export function hashDenomPub(denomPub: string): string {
return native.RsaPublicKey.fromCrock(denomPub).encode().hash().toCrock();
}
+
+ export function benchmark(repetitions: number): BenchmarkResult {
+ let time_hash = 0;
+ for (let i = 0; i < repetitions; i++) {
+ const start = timer.performanceNow();
+ hashString("hello world");
+ time_hash += timer.performanceNow() - start;
+ }
+
+ let time_hash_big = 0;
+ const ba = new native.ByteArray(4096);
+ for (let i = 0; i < repetitions; i++) {
+ ba.randomize(native.RandomQuality.WEAK);
+ const start = timer.performanceNow();
+ ba.hash();
+ time_hash_big += timer.performanceNow() - start;
+ }
+
+ let time_eddsa_create = 0;
+ for (let i = 0; i < repetitions; i++) {
+ const start = timer.performanceNow();
+ const priv: native.EddsaPrivateKey = native.EddsaPrivateKey.create();
+ time_eddsa_create += timer.performanceNow() - start;
+ priv.destroy();
+ }
+
+ let time_eddsa_sign = 0;
+ const eddsaPriv: native.EddsaPrivateKey = native.EddsaPrivateKey.create();
+ const eddsaPub: native.EddsaPublicKey = eddsaPriv.getPublicKey();
+ const h: native.HashCode = new native.HashCode();
+ h.alloc();
+ h.random(native.RandomQuality.WEAK);
+
+ const ps = new native.PaymentSignaturePS({
+ contract_hash: h,
+ });
+
+ const p = ps.toPurpose();
+
+ for (let i = 0; i < repetitions; i++) {
+ const start = timer.performanceNow();
+ native.eddsaSign(p, eddsaPriv);
+ time_eddsa_sign += timer.performanceNow() - start;
+ }
+
+ const eddsaSig = native.eddsaSign(p, eddsaPriv);
+
+ let time_ecdsa_create = 0;
+ for (let i = 0; i < repetitions; i++) {
+ const start = timer.performanceNow();
+ const priv: native.EcdsaPrivateKey = native.EcdsaPrivateKey.create();
+ time_ecdsa_create += timer.performanceNow() - start;
+ priv.destroy();
+ }
+
+
+ let time_eddsa_verify = 0;
+ for (let i = 0; i < repetitions; i++) {
+ const start = timer.performanceNow();
+ native.eddsaVerify(native.SignaturePurpose.MERCHANT_PAYMENT_OK,
+ p,
+ eddsaSig,
+ eddsaPub);
+ time_eddsa_verify += timer.performanceNow() - start;
+ }
+
+ return {
+ repetitions,
+ time: {
+ hash_small: time_hash,
+ hash_big: time_hash_big,
+ eddsa_create: time_eddsa_create,
+ eddsa_sign: time_eddsa_sign,
+ eddsa_verify: time_eddsa_verify,
+ ecdsa_create: time_ecdsa_create,
+ }
+ };
+ }
}
diff --git a/src/crypto/emscInterface.ts b/src/crypto/emscInterface.ts
index ce52c88bd..0662f4a71 100644
--- a/src/crypto/emscInterface.ts
+++ b/src/crypto/emscInterface.ts
@@ -189,7 +189,7 @@ export class HashContext implements ArenaObject {
/**
- * Arena object that points to an allocaed block of memory.
+ * Arena object that points to an allocated block of memory.
*/
abstract class MallocArenaObject implements ArenaObject {
protected _nativePtr: number | undefined = undefined;
@@ -303,7 +303,7 @@ class SyncArena extends SimpleArena {
}
}
-const arenaStack: Arena[] = [];
+export const arenaStack: Arena[] = [];
arenaStack.push(new SyncArena());