diff --git a/benchmark/decaf448.js b/benchmark/decaf448.js new file mode 100644 index 0000000..004c62f --- /dev/null +++ b/benchmark/decaf448.js @@ -0,0 +1,18 @@ +import { run, mark, utils } from 'micro-bmark'; +import { shake256 } from '@noble/hashes/sha3'; +import * as mod from '../abstract/modular.js'; +import { ed448, DecafPoint } from '../ed448.js'; + +run(async () => { + const RAM = false; + if (RAM) utils.logMem(); + console.log(`\x1b[36mdecaf448\x1b[0m`); + const priv = mod.hashToPrivateScalar(shake256(ed448.utils.randomPrivateKey(), { dkLen: 112 }), ed448.CURVE.n); + const pub = DecafPoint.BASE.multiply(priv); + const encoded = pub.toRawBytes(); + await mark('add', 1000000, () => pub.add(DecafPoint.BASE)); + await mark('multiply', 1000, () => DecafPoint.BASE.multiply(priv)); + await mark('encode', 10000, () => DecafPoint.BASE.toRawBytes()); + await mark('decode', 10000, () => DecafPoint.fromHex(encoded)); + if (RAM) utils.logMem(); +}); diff --git a/benchmark/ristretto255.js b/benchmark/ristretto255.js new file mode 100644 index 0000000..5041693 --- /dev/null +++ b/benchmark/ristretto255.js @@ -0,0 +1,18 @@ +import { run, mark, utils } from 'micro-bmark'; +import { sha512 } from '@noble/hashes/sha512'; +import * as mod from '../abstract/modular.js'; +import { ed25519, RistrettoPoint } from '../ed25519.js'; + +run(async () => { + const RAM = false; + if (RAM) utils.logMem(); + console.log(`\x1b[36mristretto255\x1b[0m`); + const priv = mod.hashToPrivateScalar(sha512(ed25519.utils.randomPrivateKey()), ed25519.CURVE.n); + const pub = RistrettoPoint.BASE.multiply(priv); + const encoded = pub.toRawBytes(); + await mark('add', 1000000, () => pub.add(RistrettoPoint.BASE)); + await mark('multiply', 10000, () => RistrettoPoint.BASE.multiply(priv)); + await mark('encode', 10000, () => RistrettoPoint.BASE.toRawBytes()); + await mark('decode', 10000, () => RistrettoPoint.fromHex(encoded)); + if (RAM) utils.logMem(); +}); diff --git a/package.json b/package.json index 8d59a95..294f7e5 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "*.d.ts.map" ], "scripts": { - "bench": "cd benchmark; node secp256k1.js; node curves.js; node ecdh.js; node hash-to-curve.js; node modular.js; node bls.js", + "bench": "cd benchmark; node secp256k1.js; node curves.js; node ecdh.js; node hash-to-curve.js; node modular.js; node bls.js; node ristretto255.js; node decaf448.js", "build": "tsc && tsc -p tsconfig.esm.json", "build:release": "rollup -c rollup.config.js", "build:clean": "rm *.{js,d.ts,d.ts.map,js.map} esm/*.{js,d.ts,d.ts.map,js.map} 2> /dev/null",