Skip to content

Commit 6643132

Browse files
committed
feat(benchmarks): add AES-128-CBC WebCrypto benchmark
1 parent 6eab45f commit 6643132

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

benchmarks/aes.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Ige } from "../src/block-modes/ige.ts";
44

55
const key = new Uint8Array(16);
66
const iv = new Uint8Array(Aes.BLOCK_SIZE);
7+
const iv2 = new Uint8Array(Aes.BLOCK_SIZE * 2);
78
const data = new Uint8Array(1024 * 1024 * 2);
89

910
Deno.bench({
@@ -38,6 +39,29 @@ Deno.bench({
3839
},
3940
});
4041

42+
Deno.bench({
43+
name: "AES-128-CBC 2MiB Encrypt (WebCrypto)",
44+
async fn() {
45+
const ckey = await crypto.subtle.importKey(
46+
"raw",
47+
key,
48+
{
49+
name: "AES-CBC",
50+
},
51+
true,
52+
["encrypt"],
53+
);
54+
await crypto.subtle.encrypt(
55+
{
56+
name: "AES-CBC",
57+
iv,
58+
},
59+
ckey,
60+
data,
61+
);
62+
},
63+
});
64+
4165
Deno.bench({
4266
name: "AES-128-CFB 2MiB Encrypt",
4367
fn() {
@@ -73,15 +97,15 @@ Deno.bench({
7397
Deno.bench({
7498
name: "AES-128-IGE 2MiB Encrypt",
7599
fn() {
76-
const cipher = new Ige(Aes, key, new Uint8Array(Aes.BLOCK_SIZE * 2));
100+
const cipher = new Ige(Aes, key, iv2);
77101
cipher.encrypt(data);
78102
},
79103
});
80104

81105
Deno.bench({
82106
name: "AES-128-IGE 2MiB Decrypt",
83107
fn() {
84-
const cipher = new Ige(Aes, key, new Uint8Array(Aes.BLOCK_SIZE * 2));
108+
const cipher = new Ige(Aes, key, iv2);
85109
cipher.decrypt(data);
86110
},
87111
});

benchmarks/utils/benchmarkArgs.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)