From f447d7f44c5f06dd3b25b91d492c089c70ac76d8 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Tue, 1 Aug 2023 10:07:17 +0700 Subject: [PATCH 1/4] chore: add noble to benchmark --- README.md | 43 ++++++++++++++++++++++++++++ package.json | 1 + test/perf/chacha20.test.ts | 4 +-- test/perf/chacha20poly1305.test.ts | 45 ++++++++++++++++++++---------- test/perf/util.ts | 9 ++++++ yarn.lock | 5 ++++ 6 files changed, 90 insertions(+), 17 deletions(-) create mode 100644 test/perf/util.ts diff --git a/README.md b/README.md index ee5cce6..f1bae69 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,49 @@ const plainText2 = asImpl.open(key, nonce, sealed, true, ad); expect(plainText2).to.be.deep.equal(plainText); ``` +## Performance + +Benchmark results of this implementation (chainSafe), stablelib 1.0.1 and noble 0.2.0 on a Mac M1 as of Aug 2023 +``` +chacha20poly1305 + ✓ chainsafe seal 32 bytes 653167.9 ops/s 1.531000 us/op - 17196777 runs 30.1 s + ✓ stablelib seal 32 bytes 134499.0 ops/s 7.435000 us/op - 3908292 runs 30.1 s + ✓ noble seal 32 bytes 153350.7 ops/s 6.521000 us/op - 4439299 runs 30.1 s + ✓ chainsafe open 32 bytes 457665.9 ops/s 2.185000 us/op - 11511464 runs 30.1 s + ✓ stablelib open 32 bytes 127388.5 ops/s 7.850000 us/op - 3611082 runs 30.1 s + ✓ noble open 32 bytes 137287.2 ops/s 7.284000 us/op - 3844123 runs 30.1 s + ✓ chainsafe seal 64 bytes 449034.6 ops/s 2.227000 us/op - 12323227 runs 30.1 s + ✓ stablelib seal 64 bytes 125203.5 ops/s 7.987000 us/op - 3651443 runs 30.1 s + ✓ noble seal 64 bytes 146092.0 ops/s 6.845000 us/op - 4241264 runs 30.1 s + ✓ chainsafe open 64 bytes 542299.3 ops/s 1.844000 us/op - 10879791 runs 30.1 s + ✓ stablelib open 64 bytes 126454.2 ops/s 7.908000 us/op - 3399078 runs 30.1 s + ✓ noble open 64 bytes 146134.7 ops/s 6.843000 us/op - 3825147 runs 30.1 s + ✓ chainsafe seal 1.00 KB 99641.29 ops/s 10.03600 us/op - 2930573 runs 30.1 s + ✓ stablelib seal 1.00 KB 36844.63 ops/s 27.14100 us/op - 1097638 runs 30.1 s + ✓ noble seal 1.00 KB 76161.46 ops/s 13.13000 us/op - 2248184 runs 30.1 s + ✓ chainsafe open 1.00 KB 101657.0 ops/s 9.837000 us/op - 2789744 runs 30.1 s + ✓ stablelib open 1.00 KB 34478.00 ops/s 29.00400 us/op - 1000843 runs 30.1 s + ✓ noble open 1.00 KB 72463.77 ops/s 13.80000 us/op - 2020143 runs 30.1 s + ✓ chainsafe seal 8.00 KB 13900.28 ops/s 71.94100 us/op - 412838 runs 30.0 s + ✓ stablelib seal 8.00 KB 5704.604 ops/s 175.2970 us/op - 170190 runs 30.1 s + ✓ noble seal 8.00 KB 15439.48 ops/s 64.76900 us/op - 461084 runs 30.1 s + ✓ chainsafe open 8.00 KB 14481.84 ops/s 69.05200 us/op - 415486 runs 30.0 s + ✓ stablelib open 8.00 KB 5297.705 ops/s 188.7610 us/op - 154945 runs 30.0 s + ✓ noble open 8.00 KB 15275.57 ops/s 65.46400 us/op - 447457 runs 30.1 s + ✓ chainsafe seal 64.00 KB 1805.357 ops/s 553.9070 us/op - 53108 runs 30.0 s + ✓ stablelib seal 64.00 KB 741.8992 ops/s 1.347892 ms/op - 21915 runs 30.1 s + ✓ noble seal 64.00 KB 2024.226 ops/s 494.0160 us/op - 59531 runs 30.0 s + ✓ chainsafe open 64.00 KB 1887.173 ops/s 529.8930 us/op - 54369 runs 30.0 s + ✓ stablelib open 64.00 KB 695.4659 ops/s 1.437885 ms/op - 20400 runs 30.0 s + ✓ noble open 64.00 KB 1985.001 ops/s 503.7780 us/op - 57644 runs 30.0 s + ✓ chainsafe seal 1.00 MB 116.1527 ops/s 8.609358 ms/op - 3426 runs 30.0 s + ✓ stablelib seal 1.00 MB 47.55042 ops/s 21.03031 ms/op - 1406 runs 30.1 s + ✓ noble seal 1.00 MB 130.8939 ops/s 7.639775 ms/op - 3858 runs 30.0 s + ✓ chainsafe open 1.00 MB 120.1874 ops/s 8.320342 ms/op - 3503 runs 30.1 s + ✓ stablelib open 1.00 MB 44.23757 ops/s 22.60522 ms/op - 1301 runs 30.1 s + ✓ noble open 1.00 MB 128.7178 ops/s 7.768935 ms/op - 3756 runs 30.0 s +``` + ### License Apache 2.0 diff --git a/package.json b/package.json index 8458a57..8ffea6a 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "@stablelib/chacha": "^1.0.1", "@stablelib/poly1305": "^1.0.1", "@stablelib/chacha20poly1305": "^1.0.1", + "@noble/ciphers": "^0.2.0", "assemblyscript": "0.9.2", "@dapplion/benchmark": "^0.2.2", "@types/chai": "^4.2.15", diff --git a/test/perf/chacha20.test.ts b/test/perf/chacha20.test.ts index a29db7a..cf7f721 100644 --- a/test/perf/chacha20.test.ts +++ b/test/perf/chacha20.test.ts @@ -15,7 +15,7 @@ describe("chacha20 (streamXOR) assemblyscript vs javascript", function () { const nonceInplaceCounterLength = 4; itBench({ - id: `javascript with input length ${inputLength}`, + id: `stablelib ${inputLength}`, before: () => ({key: new Uint8Array(key), nonce: new Uint8Array(nonce), input: new Uint8Array(input)}), beforeEach: (v) => v, fn: ({key: k, nonce: n, input: i}) => { @@ -24,7 +24,7 @@ describe("chacha20 (streamXOR) assemblyscript vs javascript", function () { }); itBench({ - id: `assemblyscript with input length ${inputLength}`, + id: `chainsafe ${inputLength}`, before: () => ({key: new Uint8Array(key), nonce: new Uint8Array(nonce), input: new Uint8Array(input)}), beforeEach: (v) => v, fn: ({key: k, nonce: n, input: i}) => { diff --git a/test/perf/chacha20poly1305.test.ts b/test/perf/chacha20poly1305.test.ts index 76b70a7..54ab17e 100644 --- a/test/perf/chacha20poly1305.test.ts +++ b/test/perf/chacha20poly1305.test.ts @@ -1,9 +1,11 @@ import {itBench, setBenchOpts} from "@dapplion/benchmark"; import crypto from "crypto"; import {ChaCha20Poly1305 as ChaCha20Poly1305Stablelib} from "@stablelib/chacha20poly1305"; +import {chacha20poly1305 as chacha20poly1305Noble} from '@noble/ciphers/chacha'; import {ChaCha20Poly1305} from "../../src/chacha20poly1305"; -import {KEY_LENGTH, NONCE_LENGTH, TAG_LENGTH} from "../../common/const"; +import {KEY_LENGTH, NONCE_LENGTH} from "../../common/const"; import {newInstance} from "../../src/wasm"; +import {formatBytes} from "./util"; describe("chacha20poly1305", function () { this.timeout(0); @@ -11,46 +13,59 @@ describe("chacha20poly1305", function () { minMs: 30_000, }); const ctx = newInstance(); - const asImpl = new ChaCha20Poly1305(ctx); + const chainsafe = new ChaCha20Poly1305(ctx); const key = new Uint8Array(crypto.randomBytes(KEY_LENGTH)); - const jsImpl = new ChaCha20Poly1305Stablelib(key); + const stablelib = new ChaCha20Poly1305Stablelib(key); const nonce = new Uint8Array(crypto.randomBytes(NONCE_LENGTH)); - // const jsImpl = new ChaCha20Poly1305Stablelib(key); const ad = new Uint8Array(crypto.randomBytes(32)); - for (const dataLength of [512, 4096, 16384, 65_536, 524_288]) { + for (const dataLength of [32, 64, 1024, 8192, 65536, 1048576]) { const plainText = new Uint8Array(crypto.randomBytes(dataLength)); - const sealed = jsImpl.seal(nonce, plainText, ad); + const sealed = stablelib.seal(nonce, plainText, ad); itBench({ - id: `as seal with data length ${dataLength}`, + id: `chainsafe seal ${formatBytes(dataLength)}`, fn: () => { - asImpl.seal(key, nonce, plainText, ad); + chainsafe.seal(key, nonce, plainText, ad); }, }); itBench({ - id: `js seal with data length ${dataLength}`, + id: `stablelib seal ${formatBytes(dataLength)}`, fn: () => { - jsImpl.seal(nonce, plainText, ad); + stablelib.seal(nonce, plainText, ad); }, }); itBench({ - id: `as open with data length ${dataLength}`, + id: `noble seal ${formatBytes(dataLength)}`, + fn: () => { + chacha20poly1305Noble(key, nonce, ad).encrypt(plainText); + }, + }); + + itBench({ + id: `chainsafe open ${formatBytes(dataLength)}`, + beforeEach: () => new Uint8Array(sealed), + fn: (clonedSealed) => { + chainsafe.open(key, nonce, clonedSealed, ad); + }, + }); + + itBench({ + id: `stablelib open ${formatBytes(dataLength)}`, beforeEach: () => new Uint8Array(sealed), fn: (clonedSealed) => { - // overwriteSealed as true to avoid memory allocation - asImpl.open(key, nonce, clonedSealed, ad, clonedSealed.subarray(0, clonedSealed.length - TAG_LENGTH)); + stablelib.open(nonce, clonedSealed, ad); }, }); itBench({ - id: `js open with data length ${dataLength}`, + id: `noble open ${formatBytes(dataLength)}`, beforeEach: () => new Uint8Array(sealed), fn: (clonedSealed) => { - jsImpl.open(nonce, clonedSealed, ad, clonedSealed.subarray(0, clonedSealed.length - TAG_LENGTH)); + chacha20poly1305Noble(key, nonce, ad).decrypt(clonedSealed); }, }); } diff --git a/test/perf/util.ts b/test/perf/util.ts new file mode 100644 index 0000000..873b66f --- /dev/null +++ b/test/perf/util.ts @@ -0,0 +1,9 @@ +export function formatBytes(bytes: number): string { + if (bytes < 1024) { + return bytes + " bytes"; + } else if (bytes < 1024 * 1024) { + return (bytes / 1024).toFixed(2) + " KB"; + } else { + return (bytes / (1024 * 1024)).toFixed(2) + " MB"; + } +} diff --git a/yarn.lock b/yarn.lock index 965114e..642a7e4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -497,6 +497,11 @@ "@jridgewell/resolve-uri" "3.1.0" "@jridgewell/sourcemap-codec" "1.4.14" +"@noble/ciphers@^0.2.0": + version "0.2.0" + resolved "https://registry.yarnpkg.com/@noble/ciphers/-/ciphers-0.2.0.tgz#a12cda60f3cf1ab5d7c77068c3711d2366649ed7" + integrity sha512-6YBxJDAapHSdd3bLDv6x2wRPwq4QFMUaB3HvljNBUTThDd12eSm7/3F+2lnfzx2jvM+S6Nsy0jEt9QbPqSwqRw== + "@nodelib/fs.scandir@2.1.5": version "2.1.5" resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5" From 7bb15c2d72a0000a3e0f0c8831d77f6b83284231 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Tue, 1 Aug 2023 19:41:38 +0700 Subject: [PATCH 2/4] fix: use runsFactor=1000 to benchmark more precisely --- README.md | 72 +++++++++++++------------- test/perf/chacha20poly1305.test.ts | 82 +++++++++++++----------------- 2 files changed, 71 insertions(+), 83 deletions(-) diff --git a/README.md b/README.md index f1bae69..19c9df1 100644 --- a/README.md +++ b/README.md @@ -26,42 +26,42 @@ expect(plainText2).to.be.deep.equal(plainText); Benchmark results of this implementation (chainSafe), stablelib 1.0.1 and noble 0.2.0 on a Mac M1 as of Aug 2023 ``` chacha20poly1305 - ✓ chainsafe seal 32 bytes 653167.9 ops/s 1.531000 us/op - 17196777 runs 30.1 s - ✓ stablelib seal 32 bytes 134499.0 ops/s 7.435000 us/op - 3908292 runs 30.1 s - ✓ noble seal 32 bytes 153350.7 ops/s 6.521000 us/op - 4439299 runs 30.1 s - ✓ chainsafe open 32 bytes 457665.9 ops/s 2.185000 us/op - 11511464 runs 30.1 s - ✓ stablelib open 32 bytes 127388.5 ops/s 7.850000 us/op - 3611082 runs 30.1 s - ✓ noble open 32 bytes 137287.2 ops/s 7.284000 us/op - 3844123 runs 30.1 s - ✓ chainsafe seal 64 bytes 449034.6 ops/s 2.227000 us/op - 12323227 runs 30.1 s - ✓ stablelib seal 64 bytes 125203.5 ops/s 7.987000 us/op - 3651443 runs 30.1 s - ✓ noble seal 64 bytes 146092.0 ops/s 6.845000 us/op - 4241264 runs 30.1 s - ✓ chainsafe open 64 bytes 542299.3 ops/s 1.844000 us/op - 10879791 runs 30.1 s - ✓ stablelib open 64 bytes 126454.2 ops/s 7.908000 us/op - 3399078 runs 30.1 s - ✓ noble open 64 bytes 146134.7 ops/s 6.843000 us/op - 3825147 runs 30.1 s - ✓ chainsafe seal 1.00 KB 99641.29 ops/s 10.03600 us/op - 2930573 runs 30.1 s - ✓ stablelib seal 1.00 KB 36844.63 ops/s 27.14100 us/op - 1097638 runs 30.1 s - ✓ noble seal 1.00 KB 76161.46 ops/s 13.13000 us/op - 2248184 runs 30.1 s - ✓ chainsafe open 1.00 KB 101657.0 ops/s 9.837000 us/op - 2789744 runs 30.1 s - ✓ stablelib open 1.00 KB 34478.00 ops/s 29.00400 us/op - 1000843 runs 30.1 s - ✓ noble open 1.00 KB 72463.77 ops/s 13.80000 us/op - 2020143 runs 30.1 s - ✓ chainsafe seal 8.00 KB 13900.28 ops/s 71.94100 us/op - 412838 runs 30.0 s - ✓ stablelib seal 8.00 KB 5704.604 ops/s 175.2970 us/op - 170190 runs 30.1 s - ✓ noble seal 8.00 KB 15439.48 ops/s 64.76900 us/op - 461084 runs 30.1 s - ✓ chainsafe open 8.00 KB 14481.84 ops/s 69.05200 us/op - 415486 runs 30.0 s - ✓ stablelib open 8.00 KB 5297.705 ops/s 188.7610 us/op - 154945 runs 30.0 s - ✓ noble open 8.00 KB 15275.57 ops/s 65.46400 us/op - 447457 runs 30.1 s - ✓ chainsafe seal 64.00 KB 1805.357 ops/s 553.9070 us/op - 53108 runs 30.0 s - ✓ stablelib seal 64.00 KB 741.8992 ops/s 1.347892 ms/op - 21915 runs 30.1 s - ✓ noble seal 64.00 KB 2024.226 ops/s 494.0160 us/op - 59531 runs 30.0 s - ✓ chainsafe open 64.00 KB 1887.173 ops/s 529.8930 us/op - 54369 runs 30.0 s - ✓ stablelib open 64.00 KB 695.4659 ops/s 1.437885 ms/op - 20400 runs 30.0 s - ✓ noble open 64.00 KB 1985.001 ops/s 503.7780 us/op - 57644 runs 30.0 s - ✓ chainsafe seal 1.00 MB 116.1527 ops/s 8.609358 ms/op - 3426 runs 30.0 s - ✓ stablelib seal 1.00 MB 47.55042 ops/s 21.03031 ms/op - 1406 runs 30.1 s - ✓ noble seal 1.00 MB 130.8939 ops/s 7.639775 ms/op - 3858 runs 30.0 s - ✓ chainsafe open 1.00 MB 120.1874 ops/s 8.320342 ms/op - 3503 runs 30.1 s - ✓ stablelib open 1.00 MB 44.23757 ops/s 22.60522 ms/op - 1301 runs 30.1 s - ✓ noble open 1.00 MB 128.7178 ops/s 7.768935 ms/op - 3756 runs 30.0 s + ✓ chainsafe seal 32 bytes 721249.9 ops/s 1.386482 us/op - 21318 runs 30.1 s + ✓ stablelib seal 32 bytes 144494.9 ops/s 6.920660 us/op - 4265 runs 30.0 s + ✓ noble seal 32 bytes 150163.8 ops/s 6.659396 us/op - 4434 runs 30.0 s + ✓ chainsafe open 32 bytes 671504.2 ops/s 1.489194 us/op - 19851 runs 30.1 s + ✓ stablelib open 32 bytes 147999.8 ops/s 6.756768 us/op - 4363 runs 30.1 s + ✓ noble open 32 bytes 157093.5 ops/s 6.365635 us/op - 4636 runs 30.0 s + ✓ chainsafe seal 64 bytes 494830.5 ops/s 2.020894 us/op - 14610 runs 30.0 s + ✓ stablelib seal 64 bytes 136125.4 ops/s 7.346169 us/op - 4025 runs 30.1 s + ✓ noble seal 64 bytes 150779.6 ops/s 6.632199 us/op - 4459 runs 30.1 s + ✓ chainsafe open 64 bytes 635232.8 ops/s 1.574226 us/op - 18745 runs 30.0 s + ✓ stablelib open 64 bytes 145797.0 ops/s 6.858851 us/op - 4308 runs 30.1 s + ✓ noble open 64 bytes 148018.9 ops/s 6.755892 us/op - 4371 runs 30.0 s + ✓ chainsafe seal 1.00 KB 99285.50 ops/s 10.07196 us/op - 2924 runs 30.0 s + ✓ stablelib seal 1.00 KB 38798.05 ops/s 25.77449 us/op - 1149 runs 30.1 s + ✓ noble seal 1.00 KB 82057.41 ops/s 12.18659 us/op - 2424 runs 30.0 s + ✓ chainsafe open 1.00 KB 100943.3 ops/s 9.906554 us/op - 2982 runs 30.1 s + ✓ stablelib open 1.00 KB 36347.17 ops/s 27.51246 us/op - 1073 runs 30.0 s + ✓ noble open 1.00 KB 80123.76 ops/s 12.48069 us/op - 2368 runs 30.1 s + ✓ chainsafe seal 4.00 KB 28374.74 ops/s 35.24261 us/op - 837 runs 30.1 s + ✓ stablelib seal 4.00 KB 11710.30 ops/s 85.39493 us/op - 347 runs 30.2 s + ✓ noble seal 4.00 KB 30496.07 ops/s 32.79111 us/op - 900 runs 30.0 s + ✓ chainsafe open 4.00 KB 29200.03 ops/s 34.24654 us/op - 861 runs 30.1 s + ✓ stablelib open 4.00 KB 10933.00 ops/s 91.46624 us/op - 323 runs 30.1 s + ✓ noble open 4.00 KB 30155.13 ops/s 33.16186 us/op - 892 runs 30.1 s + ✓ chainsafe seal 8.00 KB 14577.58 ops/s 68.59850 us/op - 431 runs 30.2 s + ✓ stablelib seal 8.00 KB 5880.412 ops/s 170.0561 us/op - 174 runs 30.3 s + ✓ noble seal 8.00 KB 16014.05 ops/s 62.44518 us/op - 473 runs 30.1 s + ✓ chainsafe open 8.00 KB 14990.32 ops/s 66.70972 us/op - 443 runs 30.1 s + ✓ stablelib open 8.00 KB 5563.228 ops/s 179.7517 us/op - 165 runs 30.2 s + ✓ noble open 8.00 KB 15821.22 ops/s 63.20624 us/op - 467 runs 30.1 s + ✓ chainsafe seal 64.00 KB 1784.257 ops/s 560.4575 us/op - 54 runs 30.8 s + ✓ stablelib seal 64.00 KB 735.6552 ops/s 1.359332 ms/op - 23 runs 32.6 s + ✓ noble seal 64.00 KB 2020.801 ops/s 494.8534 us/op - 60 runs 30.7 s + ✓ chainsafe open 64.00 KB 1854.636 ops/s 539.1893 us/op - 56 runs 30.8 s + ✓ stablelib open 64.00 KB 691.5201 ops/s 1.446090 ms/op - 21 runs 31.8 s + ✓ noble open 64.00 KB 2085.731 ops/s 479.4481 us/op - 62 runs 30.9 s ``` ### License diff --git a/test/perf/chacha20poly1305.test.ts b/test/perf/chacha20poly1305.test.ts index 54ab17e..f0a3efb 100644 --- a/test/perf/chacha20poly1305.test.ts +++ b/test/perf/chacha20poly1305.test.ts @@ -1,7 +1,7 @@ import {itBench, setBenchOpts} from "@dapplion/benchmark"; import crypto from "crypto"; import {ChaCha20Poly1305 as ChaCha20Poly1305Stablelib} from "@stablelib/chacha20poly1305"; -import {chacha20poly1305 as chacha20poly1305Noble} from '@noble/ciphers/chacha'; +import {chacha20poly1305 as noble} from '@noble/ciphers/chacha'; import {ChaCha20Poly1305} from "../../src/chacha20poly1305"; import {KEY_LENGTH, NONCE_LENGTH} from "../../common/const"; import {newInstance} from "../../src/wasm"; @@ -19,54 +19,42 @@ describe("chacha20poly1305", function () { const stablelib = new ChaCha20Poly1305Stablelib(key); const nonce = new Uint8Array(crypto.randomBytes(NONCE_LENGTH)); const ad = new Uint8Array(crypto.randomBytes(32)); + const runsFactor = 1000; - for (const dataLength of [32, 64, 1024, 8192, 65536, 1048576]) { + + for (const dataLength of [32, 64, 1024, 4096, 8192, 65536]) { const plainText = new Uint8Array(crypto.randomBytes(dataLength)); const sealed = stablelib.seal(nonce, plainText, ad); - - itBench({ - id: `chainsafe seal ${formatBytes(dataLength)}`, - fn: () => { - chainsafe.seal(key, nonce, plainText, ad); - }, - }); - - itBench({ - id: `stablelib seal ${formatBytes(dataLength)}`, - fn: () => { - stablelib.seal(nonce, plainText, ad); - }, - }); - - itBench({ - id: `noble seal ${formatBytes(dataLength)}`, - fn: () => { - chacha20poly1305Noble(key, nonce, ad).encrypt(plainText); - }, - }); - - itBench({ - id: `chainsafe open ${formatBytes(dataLength)}`, - beforeEach: () => new Uint8Array(sealed), - fn: (clonedSealed) => { - chainsafe.open(key, nonce, clonedSealed, ad); - }, - }); - - itBench({ - id: `stablelib open ${formatBytes(dataLength)}`, - beforeEach: () => new Uint8Array(sealed), - fn: (clonedSealed) => { - stablelib.open(nonce, clonedSealed, ad); - }, - }); - - itBench({ - id: `noble open ${formatBytes(dataLength)}`, - beforeEach: () => new Uint8Array(sealed), - fn: (clonedSealed) => { - chacha20poly1305Noble(key, nonce, ad).decrypt(clonedSealed); - }, - }); + const testCases: {impl: string; sealFn: () => void; openFn: () => void}[] = [ + {impl: "chainsafe", sealFn: () => chainsafe.seal(key, nonce, plainText, ad), openFn: () => chainsafe.open(key, nonce, sealed, ad)}, + {impl: "stablelib", sealFn: () => stablelib.seal(nonce, plainText, ad), openFn: () => stablelib.open(nonce, sealed, ad)}, + {impl: "noble", sealFn: () => noble(key, nonce, ad).encrypt(plainText), openFn: () => noble(key, nonce, ad).decrypt(sealed)} + ] + + // seal + for (const {impl, sealFn} of testCases) { + itBench({ + id: `${impl} seal ${formatBytes(dataLength)}`, + fn: () => { + for (let i = 0; i < runsFactor; i++) { + sealFn(); + } + }, + runsFactor, + }); + } + + // open + for (const {impl, openFn} of testCases) { + itBench({ + id: `${impl} open ${formatBytes(dataLength)}`, + fn: () => { + for (let i = 0; i < runsFactor; i++) { + openFn(); + } + }, + runsFactor, + }); + } } }); From db6db1d35c3e41cdd2c11af52d9f143bb3fc566b Mon Sep 17 00:00:00 2001 From: Cayman Date: Wed, 28 Feb 2024 10:44:49 -0500 Subject: [PATCH 3/4] chore: update @noble/ciphers --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 8ffea6a..c620715 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "@stablelib/chacha": "^1.0.1", "@stablelib/poly1305": "^1.0.1", "@stablelib/chacha20poly1305": "^1.0.1", - "@noble/ciphers": "^0.2.0", + "@noble/ciphers": "^0.5.1", "assemblyscript": "0.9.2", "@dapplion/benchmark": "^0.2.2", "@types/chai": "^4.2.15", diff --git a/yarn.lock b/yarn.lock index 6df2cb0..1048ebe 100644 --- a/yarn.lock +++ b/yarn.lock @@ -531,10 +531,10 @@ "@jridgewell/resolve-uri" "^3.1.0" "@jridgewell/sourcemap-codec" "^1.4.14" -"@noble/ciphers@^0.2.0": - version "0.2.0" - resolved "https://registry.yarnpkg.com/@noble/ciphers/-/ciphers-0.2.0.tgz#a12cda60f3cf1ab5d7c77068c3711d2366649ed7" - integrity sha512-6YBxJDAapHSdd3bLDv6x2wRPwq4QFMUaB3HvljNBUTThDd12eSm7/3F+2lnfzx2jvM+S6Nsy0jEt9QbPqSwqRw== +"@noble/ciphers@^0.5.1": + version "0.5.1" + resolved "https://registry.yarnpkg.com/@noble/ciphers/-/ciphers-0.5.1.tgz#292f388b69c9ed80d49dca1a5cbfd4ff06852111" + integrity sha512-aNE06lbe36ifvMbbWvmmF/8jx6EQPu2HVg70V95T+iGjOuYwPpAccwAQc2HlXO2D0aiQ3zavbMga4jjWnrpiPA== "@nodelib/fs.scandir@2.1.5": version "2.1.5" From 9a1283f3f392dac32b44ae9877e07804ae6dd206 Mon Sep 17 00:00:00 2001 From: Cayman Date: Wed, 28 Feb 2024 10:46:07 -0500 Subject: [PATCH 4/4] chore: update ci node version --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b52170d..58199ee 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: os: [windows-latest, ubuntu-latest, macos-latest] - node: [16] + node: [20] fail-fast: false steps: - uses: actions/checkout@v1