diff --git a/README.md b/README.md index 5a02c7d..d0d6f29 100644 --- a/README.md +++ b/README.md @@ -483,9 +483,9 @@ chacha20 x 1,506,024 ops/sec @ 664ns/op xchacha20 x 1,064,962 ops/sec @ 939ns/op chacha8 x 1,683,501 ops/sec @ 594ns/op chacha12 x 1,628,664 ops/sec @ 614ns/op -aes-256-ecb x 775,193 ops/sec @ 1μs/op -aes-256-cbc x 738,552 ops/sec @ 1μs/op -aes-256-ctr x 737,463 ops/sec @ 1μs/op +aes-ecb-256 x 775,193 ops/sec @ 1μs/op +aes-cbc-256 x 738,552 ops/sec @ 1μs/op +aes-ctr-256 x 737,463 ops/sec @ 1μs/op 1MB xsalsa20poly1305 x 205 ops/sec @ 4ms/op @@ -500,10 +500,10 @@ chacha20 x 506 ops/sec @ 1ms/op xchacha20 x 506 ops/sec @ 1ms/op chacha8 x 956 ops/sec @ 1ms/op chacha12 x 735 ops/sec @ 1ms/op -aes-256-ecb x 229 ops/sec @ 4ms/op -aes-256-cbc x 110 ops/sec @ 9ms/op -aes-256-ctr x 115 ops/sec @ 8ms/op - +# Wrapper over built-in webcrypto +webcrypto ctr-256 x 5,068 ops/sec @ 197μs/op +webcrypto cbc-256 x 1,116 ops/sec @ 895μs/op +webcrypto gcm-256 x 4,374 ops/sec @ 228μs/op ± 1.69% [172μs..7ms] ``` Compare to other implementations: diff --git a/benchmark/noble.js b/benchmark/noble.js index 927b74b..55b8841 100644 --- a/benchmark/noble.js +++ b/benchmark/noble.js @@ -1,15 +1,15 @@ import { mark } from 'micro-bmark'; import { buf } from './_utils.js'; -import { concatBytes } from '@noble/ciphers/utils'; import { xsalsa20poly1305 } from '@noble/ciphers/salsa'; import { xchacha20poly1305, chacha20poly1305 } from '@noble/ciphers/chacha'; import { salsa20, xsalsa20 } from '@noble/ciphers/salsa'; import { chacha20, xchacha20, chacha8, chacha12 } from '@noble/ciphers/chacha'; import { ecb, ctr, cbc, gcm, siv } from '@noble/ciphers/aes'; +import * as aesw from '@noble/ciphers/webcrypto'; const buffers = [ // { size: '16B', samples: 1_500_000, data: buf(16) }, // common block size - { size: '32B', samples: 1_500_000, data: buf(32) }, + // { size: '32B', samples: 1_500_000, data: buf(32) }, { size: '64B', samples: 1_000_000, data: buf(64) }, // { size: '1KB', samples: 50_000, data: buf(1024) }, // { size: '8KB', samples: 10_000, data: buf(1024 * 8) }, @@ -38,9 +38,16 @@ async function main() { await mark('xchacha20', i, () => xchacha20(key, nonce24, buf)); await mark('chacha8', i, () => chacha8(key, nonce, buf)); await mark('chacha12', i, () => chacha12(key, nonce, buf)); - await mark('aes-256-ecb', i, () => ecb(key).encrypt(buf)); - await mark('aes-256-cbc', i, () => cbc(key, nonce16).encrypt(buf)); - await mark('aes-256-ctr', i, () => ctr(key, nonce16).encrypt(buf)); + await mark('aes-ecb-256', i, () => ecb(key).encrypt(buf)); + await mark('aes-cbc-256', i, () => cbc(key, nonce16).encrypt(buf)); + await mark('aes-ctr-256', i, () => ctr(key, nonce16).encrypt(buf)); + + if (size === '1MB') { + console.log('# Wrapper over built-in webcrypto'); + await mark('webcrypto ctr-256', 5000, () => aesw.ctr(key, nonce16).encrypt(buf)); + await mark('webcrypto cbc-256', 5000, () => aesw.cbc(key, nonce16).encrypt(buf)); + await mark('webcrypto gcm-256', 5000, () => aesw.gcm(key, nonce).encrypt(buf)); + } console.log(); } }