diff --git a/benchmarks/aes.ts b/benchmarks/aes.ts index 759e768..5eccf76 100644 --- a/benchmarks/aes.ts +++ b/benchmarks/aes.ts @@ -1,182 +1,131 @@ -import { bench, runBenchmarks } from "../dev_deps.ts"; +import { AES as GodCryptoAES } from "https://deno.land/x/god_crypto@v1.4.11/aes.ts"; import { Aes } from "../aes.ts"; import { Cbc, Cfb, Ctr, Ecb, Ofb } from "../block-modes.ts"; -import { AES as GodCryptoAES } from "https://deno.land/x/god_crypto@v1.4.9/aes.ts"; -import { args } from "./utils/benchmarkArgs.ts"; - -const { runs: _runs, ...opts } = args; -const runs = _runs || 25; const key = new Uint8Array(16); const iv = new Uint8Array(Aes.BLOCK_SIZE); const data = new Uint8Array(1024 * 1024 * 2); -bench({ +Deno.bench({ name: "AES-128-ECB 2MiB Encrypt", - runs, - func(b) { + fn() { const cipher = new Ecb(Aes, key); - b.start(); cipher.encrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "AES-128-ECB 2MiB Decrypt", - runs, - func(b) { + fn() { const cipher = new Ecb(Aes, key); - b.start(); cipher.decrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "AES-128-CBC 2MiB Encrypt", - runs, - func(b) { + fn() { const cipher = new Cbc(Aes, key, iv); - b.start(); cipher.encrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "AES-128-CBC 2MiB Decrypt", - runs, - func(b) { + fn() { const cipher = new Cbc(Aes, key, iv); - b.start(); cipher.decrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "AES-128-CFB 2MiB Encrypt", - runs, - func(b) { + fn() { const cipher = new Cfb(Aes, key, iv); - b.start(); cipher.encrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "AES-128-CFB 2MiB Decrypt", - runs, - func(b) { + fn() { const cipher = new Cfb(Aes, key, iv); - b.start(); cipher.decrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "AES-128-OFB 2MiB Encrypt/Decrypt", - runs, - func(b) { + fn() { const cipher = new Ofb(Aes, key, iv); - b.start(); cipher.encrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "AES-128-CTR 2MiB Encrypt/Decrypt", - runs, - func(b) { + fn() { const cipher = new Ctr(Aes, key, iv); - b.start(); cipher.encrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "AES-128-ECB (GodCrypto) 2MiB Encrypt", - runs, - async func(b) { + async fn() { const cipher = new GodCryptoAES(key, { mode: "ecb" }); - b.start(); await cipher.encrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "AES-128-ECB (GodCrypto) 2MiB Decrypt", - runs, - async func(b) { + async fn() { const cipher = new GodCryptoAES(key, { mode: "ecb" }); - b.start(); await cipher.decrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "AES-128-CBC (GodCrypto) 2MiB Encrypt", - runs, - async func(b) { + async fn() { const cipher = new GodCryptoAES(key, { mode: "cbc", iv, }); - b.start(); await cipher.encrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "AES-128-CBC (GodCrypto) 2MiB Decrypt", - runs, - async func(b) { + async fn() { const cipher = new GodCryptoAES(key, { mode: "cbc", iv, }); - b.start(); await cipher.decrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "AES-128-CFB (GodCrypto) 2MiB Encrypt", - runs, - async func(b) { + async fn() { const cipher = new GodCryptoAES(key, { mode: "cfb", iv, }); - b.start(); await cipher.encrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "AES-128-CFB (GodCrypto) 2MiB Decrypt", - runs, - async func(b) { + async fn() { const cipher = new GodCryptoAES(key, { mode: "cfb", iv, }); - b.start(); await cipher.decrypt(data); - b.stop(); }, }); - -if (import.meta.main) { - runBenchmarks(opts); -} diff --git a/benchmarks/all.ts b/benchmarks/all.ts index d183cd8..96bd5e8 100644 --- a/benchmarks/all.ts +++ b/benchmarks/all.ts @@ -1,11 +1,5 @@ -import { runBenchmarks } from "../dev_deps.ts"; -import { args } from "./utils/benchmarkArgs.ts"; import "./aes.ts"; import "./blowfish.ts"; import "./cast5.ts"; import "./des.ts"; import "./tdes.ts"; - -const { runs: _, ...opts } = args; - -runBenchmarks(opts); diff --git a/benchmarks/blowfish.ts b/benchmarks/blowfish.ts index 4620d38..044e6c1 100644 --- a/benchmarks/blowfish.ts +++ b/benchmarks/blowfish.ts @@ -1,117 +1,79 @@ -import { bench, runBenchmarks } from "../dev_deps.ts"; -import { Blowfish } from "../blowfish.ts"; import { Cbc, Cfb, Ctr, Ecb, Ofb } from "../block-modes.ts"; -import { args } from "./utils/benchmarkArgs.ts"; - -const { runs: _runs, ...opts } = args; -const runs = _runs || 25; +import { Blowfish } from "../blowfish.ts"; const key = new Uint8Array(8); const iv = new Uint8Array(Blowfish.BLOCK_SIZE); const data = new Uint8Array(1024 * 1024 * 2); -bench({ +Deno.bench({ name: "Blowfish-ECB 2MiB Encrypt", - runs, - func(b) { + fn() { const cipher = new Ecb(Blowfish, key); - b.start(); cipher.encrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "Blowfish-ECB 2MiB Encrypt", - runs, - func(b) { + fn() { const cipher = new Ecb(Blowfish, key); - b.start(); cipher.encrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "Blowfish-ECB 2MiB Decrypt", - runs, - func(b) { + fn() { const cipher = new Ecb(Blowfish, key); - b.start(); cipher.decrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "Blowfish-CBC 2MiB Encrypt", - runs, - func(b) { + fn() { const cipher = new Cbc(Blowfish, key, iv); - - b.start(); cipher.encrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "Blowfish-CBC 2MiB Decrypt", - runs, - func(b) { + fn() { const bf = new Cbc(Blowfish, key, iv); - b.start(); bf.decrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "Blowfish-CFB 2MiB Encrypt", - runs, - func(b) { + fn() { const cipher = new Cfb(Blowfish, key, iv); - - b.start(); cipher.encrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "Blowfish-CFB 2MiB Decrypt", - runs, - func(b) { + fn() { const cipher = new Cfb(Blowfish, key, iv); - b.start(); cipher.decrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ // Encryption and decryption are the same name: "Blowfish-OFB 2MiB Encrypt/Decrypt", - runs, - func(b) { + fn() { const cipher = new Ofb(Blowfish, key, iv); - b.start(); cipher.encrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "Blowfish-CTR 2MiB Encrypt/Decrypt", - runs, - func(b) { + fn() { const cipher = new Ctr(Blowfish, key, iv); - b.start(); cipher.encrypt(data); - b.stop(); }, }); - -if (import.meta.main) { - runBenchmarks(opts); -} diff --git a/benchmarks/cast5.ts b/benchmarks/cast5.ts index 74fee8a..3e52d9d 100644 --- a/benchmarks/cast5.ts +++ b/benchmarks/cast5.ts @@ -1,106 +1,70 @@ -import { bench, runBenchmarks } from "../dev_deps.ts"; -import { Cast5 } from "../cast5.ts"; import { Cbc, Cfb, Ctr, Ecb, Ofb } from "../block-modes.ts"; -import { args } from "./utils/benchmarkArgs.ts"; - -const { runs: _runs, ...opts } = args; -const runs = _runs || 25; +import { Cast5 } from "../cast5.ts"; const key = new Uint8Array(16); const iv = new Uint8Array(Cast5.BLOCK_SIZE); const data = new Uint8Array(1024 * 1024 * 2); -bench({ +Deno.bench({ name: "CAST5-ECB 2MiB Encrypt", - runs, - func(b) { + fn() { const cipher = new Ecb(Cast5, key); - b.start(); cipher.encrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "CAST5-ECB 2MiB Decrypt", - runs, - func(b) { + fn() { const cipher = new Ecb(Cast5, key); - b.start(); cipher.decrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "CAST5-CBC 2MiB Encrypt", - runs, - func(b) { + fn() { const cipher = new Cbc(Cast5, key, iv); - - b.start(); cipher.encrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "CAST5-CBC 2MiB Decrypt", - runs, - func(b) { - const bf = new Cbc(Cast5, key, iv); - b.start(); - bf.decrypt(data); - b.stop(); + fn() { + const cipher = new Cbc(Cast5, key, iv); + cipher.decrypt(data); }, }); -bench({ +Deno.bench({ name: "CAST5-CFB 2MiB Encrypt", - runs, - func(b) { + fn() { const cipher = new Cfb(Cast5, key, iv); - - b.start(); cipher.encrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "CAST5-CFB 2MiB Decrypt", - runs, - func(b) { + fn() { const cipher = new Cfb(Cast5, key, iv); - b.start(); cipher.decrypt(data); - b.stop(); }, }); -bench({ - // Encryption and decryption are the same +Deno.bench({ name: "CAST5-OFB 2MiB Encrypt/Decrypt", - runs, - func(b) { + fn() { const cipher = new Ofb(Cast5, key, iv); - b.start(); - cipher.encrypt(data); - b.stop(); + cipher.decrypt(data); }, }); -bench({ +Deno.bench({ name: "CAST5-CTR 2MiB Encrypt/Decrypt", - runs, - func(b) { + fn() { const cipher = new Ctr(Cast5, key, iv); - b.start(); cipher.encrypt(data); - b.stop(); }, }); - -if (import.meta.main) { - runBenchmarks(opts); -} diff --git a/benchmarks/des.ts b/benchmarks/des.ts index 5b8e845..1f3b230 100644 --- a/benchmarks/des.ts +++ b/benchmarks/des.ts @@ -1,103 +1,70 @@ -import { bench, runBenchmarks } from "../dev_deps.ts"; -import { Des } from "../des.ts"; import { Cbc, Cfb, Ctr, Ecb, Ofb } from "../block-modes.ts"; -import { args } from "./utils/benchmarkArgs.ts"; - -const { runs: _runs, ...opts } = args; -const runs = _runs || 25; +import { Des } from "../des.ts"; const key = new Uint8Array(8); const iv = new Uint8Array(Des.BLOCK_SIZE); const data = new Uint8Array(1024 * 1024 * 2); -bench({ +Deno.bench({ name: "DES-ECB 2MiB Encrypt", - runs, - func(b) { + fn() { const cipher = new Ecb(Des, key); - b.start(); cipher.encrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "DES-ECB 2MiB Decrypt", - runs, - func(b) { + fn() { const cipher = new Ecb(Des, key); - b.start(); cipher.decrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "DES-CBC 2MiB Encrypt", - runs, - func(b) { + fn() { const cipher = new Cbc(Des, key, iv); - b.start(); cipher.encrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "DES-CBC 2MiB Decrypt", - runs, - func(b) { + fn() { const cipher = new Cbc(Des, key, iv); - b.start(); cipher.decrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "DES-CFB 2MiB Encrypt", - runs, - func(b) { + fn() { const cipher = new Cfb(Des, key, iv); - b.start(); cipher.encrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "DES-CFB 2MiB Decrypt", - runs, - func(b) { + fn() { const cipher = new Cfb(Des, key, iv); - b.start(); cipher.decrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "DES-OFB 2MiB Encrypt/Decrypt", - runs, - func(b) { + fn() { const cipher = new Ofb(Des, key, iv); - b.start(); cipher.encrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "DES-CTR 2MiB Encrypt/Decrypt", - runs, - func(b) { + fn() { const cipher = new Ctr(Des, key, iv); - b.start(); cipher.encrypt(data); - b.stop(); }, }); - -if (import.meta.main) { - runBenchmarks(opts); -} diff --git a/benchmarks/tdes.ts b/benchmarks/tdes.ts index 2f4d4a1..402d177 100644 --- a/benchmarks/tdes.ts +++ b/benchmarks/tdes.ts @@ -1,103 +1,70 @@ -import { bench, runBenchmarks } from "../dev_deps.ts"; -import { TripleDes } from "../tdes.ts"; import { Cbc, Cfb, Ctr, Ecb, Ofb } from "../block-modes.ts"; -import { args } from "./utils/benchmarkArgs.ts"; - -const { runs: _runs, ...opts } = args; -const runs = _runs || 25; +import { TripleDes } from "../tdes.ts"; const key = new Uint8Array(24); const iv = new Uint8Array(TripleDes.BLOCK_SIZE); const data = new Uint8Array(1024 * 1024 * 2); -bench({ +Deno.bench({ name: "3DES-ECB 2MiB Encrypt", - runs, - func(b) { + fn() { const cipher = new Ecb(TripleDes, key); - b.start(); cipher.encrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "3DES-ECB 2MiB Decrypt", - runs, - func(b) { + fn() { const cipher = new Ecb(TripleDes, key); - b.start(); cipher.decrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "3DES-CBC 2MiB Encrypt", - runs, - func(b) { + fn() { const cipher = new Cbc(TripleDes, key, iv); - b.start(); cipher.encrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "3DES-CBC 2MiB Decrypt", - runs, - func(b) { + fn() { const cipher = new Cbc(TripleDes, key, iv); - b.start(); cipher.decrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "3DES-CFB 2MiB Encrypt", - runs, - func(b) { + fn() { const cipher = new Cfb(TripleDes, key, iv); - b.start(); cipher.encrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "3DES-CFB 2MiB Decrypt", - runs, - func(b) { + fn() { const cipher = new Cfb(TripleDes, key, iv); - b.start(); cipher.decrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "3DES-OFB 2MiB Encrypt/Decrypt", - runs, - func(b) { + fn() { const cipher = new Ofb(TripleDes, key, iv); - b.start(); cipher.encrypt(data); - b.stop(); }, }); -bench({ +Deno.bench({ name: "3DES-CTR 2MiB Encrypt/Decrypt", - runs, - func(b) { + fn() { const cipher = new Ctr(TripleDes, key, iv); - b.start(); cipher.encrypt(data); - b.stop(); }, }); - -if (import.meta.main) { - runBenchmarks(opts); -} diff --git a/dev_deps.ts b/dev_deps.ts index a623792..ca24873 100644 --- a/dev_deps.ts +++ b/dev_deps.ts @@ -1,16 +1,7 @@ -export { parse as parseArgs } from "https://deno.land/std@0.194.0/flags/mod.ts"; export { assertEquals, assertThrows, } from "https://deno.land/std@0.194.0/testing/asserts.ts"; -export { - bench, - runBenchmarks, -} from "https://deno.land/std@0.92.0/testing/bench.ts"; -// export { -// decodeString as decodeHex, -// encodeToString as encodeHex, -// } from "https://deno.land/x/std@0.92.0/encoding/hex.ts"; import { decode, encode } from "https://deno.land/std@0.194.0/encoding/hex.ts"; export function decodeHex(hex: string): Uint8Array {