From 30f7d78c82990fa9534b101b9ee80089ff0cfd59 Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Mon, 10 Apr 2023 03:10:38 +0000 Subject: [PATCH] hash-to-curve: update benchmarks, lint --- README.md | 21 ++++++++++----------- benchmark/hash-to-curve.js | 2 +- src/abstract/hash-to-curve.ts | 3 ++- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index b619bd2..63904b7 100644 --- a/README.md +++ b/README.md @@ -760,7 +760,7 @@ Benchmark results on Apple M2 with node v19: secp256k1 init x 58 ops/sec @ 17ms/op getPublicKey x 5,640 ops/sec @ 177μs/op -sign x 3,909 ops/sec @ 255μs/op +sign x 4,471 ops/sec @ 223μs/op verify x 780 ops/sec @ 1ms/op getSharedSecret x 465 ops/sec @ 2ms/op recoverPublicKey x 740 ops/sec @ 1ms/op @@ -770,19 +770,19 @@ schnorr.verify x 775 ops/sec @ 1ms/op P256 init x 31 ops/sec @ 31ms/op getPublicKey x 5,607 ops/sec @ 178μs/op -sign x 3,930 ops/sec @ 254μs/op +sign x 4,583 ops/sec @ 218μs/op verify x 540 ops/sec @ 1ms/op P384 init x 15 ops/sec @ 63ms/op getPublicKey x 2,622 ops/sec @ 381μs/op -sign x 1,913 ops/sec @ 522μs/op +sign x 2,106 ops/sec @ 474μs/op verify x 222 ops/sec @ 4ms/op P521 init x 8 ops/sec @ 119ms/op getPublicKey x 1,371 ops/sec @ 729μs/op -sign x 1,090 ops/sec @ 917μs/op +sign x 1,164 ops/sec @ 858μs/op verify x 118 ops/sec @ 8ms/op ed25519 @@ -821,13 +821,12 @@ aggregateSignatures/128 x 3 ops/sec @ 332ms/opp hash-to-curve hash_to_field x 850,340 ops/sec @ 1μs/op -hashToCurve -├─secp256k1 x 1,850 ops/sec @ 540μs/op -├─P256 x 3,352 ops/sec @ 298μs/op -├─P384 x 1,367 ops/sec @ 731μs/op -├─P521 x 691 ops/sec @ 1ms/op -├─ed25519 x 2,492 ops/sec @ 401μs/op -└─ed448 x 1,045 ops/sec @ 956μs/op +secp256k1 x 2,143 ops/sec @ 466μs/op +P256 x 3,861 ops/sec @ 258μs/op +P384 x 1,526 ops/sec @ 655μs/op +P521 x 748 ops/sec @ 1ms/op +ed25519 x 2,772 ops/sec @ 360μs/op +ed448 x 1,146 ops/sec @ 871μs/op ``` ## Contributing & testing diff --git a/benchmark/hash-to-curve.js b/benchmark/hash-to-curve.js index a268dde..267e5d6 100644 --- a/benchmark/hash-to-curve.js +++ b/benchmark/hash-to-curve.js @@ -20,7 +20,7 @@ run(async () => { // - m, the extension degree of F, m >= 1 // - L = ceil((ceil(log2(p)) + k) / 8), where k is the security of suite (e.g. 128) await mark('hash_to_field', 1000000, () => - hash_to_field(rand, 1, { DST: 'secp256k1', hash: sha256, p: N, m: 1, k: 128 }) + hash_to_field(rand, 1, { DST: 'secp256k1', hash: sha256, expand: 'xmd', p: N, m: 1, k: 128 }) ); const msg = utf8ToBytes('message'); for (let [title, fn] of Object.entries({ secp256k1, P256, P384, P521, ed25519, ed448 })) { diff --git a/src/abstract/hash-to-curve.ts b/src/abstract/hash-to-curve.ts index d18a5a5..38d31d4 100644 --- a/src/abstract/hash-to-curve.ts +++ b/src/abstract/hash-to-curve.ts @@ -145,7 +145,8 @@ export function hash_to_field(msg: Uint8Array, count: number, options: Opts): bi prb = expand_message_xmd(msg, DST, len_in_bytes, hash); } else if (expand === 'xof') { prb = expand_message_xof(msg, DST, len_in_bytes, k, hash); - } else if (expand === '_internal_pass') { // for internal tests only + } else if (expand === '_internal_pass') { + // for internal tests only prb = msg; } else { throw new Error('expand must be "xmd" or "xof"');