@@ -6,6 +6,13 @@ const bench = common.createBenchmark(main, {
66 op: [
77 'normalizeAlgorithm-string',
88 'normalizeAlgorithm-dict',
9+ 'normalizeAlgorithm-validate-aes-gcm',
10+ 'normalizeAlgorithm-validate-aes-cbc',
11+ 'normalizeAlgorithm-validate-aes-ctr',
12+ 'normalizeAlgorithm-validate-aes-generate',
13+ 'normalizeAlgorithm-validate-hkdf',
14+ 'normalizeAlgorithm-validate-hmac',
15+ 'normalizeAlgorithm-validate-rsa',
916 'webidl-dict',
1017 'webidl-algorithm-identifier-string',
1118 'webidl-algorithm-identifier-object',
@@ -17,7 +24,7 @@ const bench = common.createBenchmark(main, {
1724}, { flags: ['--expose-internals'] });
1825
1926function main({ n, op }) {
20- const { normalizeAlgorithm } = require('internal/crypto/util');
27+ const { normalizeAlgorithm, validateAlgorithm } = require('internal/crypto/util');
2128
2229 switch (op) {
2330 case 'normalizeAlgorithm-string': {
@@ -37,6 +44,54 @@ function main({ n, op }) {
3744 bench.end(n);
3845 break;
3946 }
47+ case 'normalizeAlgorithm-validate-aes-gcm':
48+ case 'normalizeAlgorithm-validate-aes-cbc':
49+ case 'normalizeAlgorithm-validate-aes-ctr':
50+ case 'normalizeAlgorithm-validate-aes-generate':
51+ case 'normalizeAlgorithm-validate-hkdf':
52+ case 'normalizeAlgorithm-validate-hmac':
53+ case 'normalizeAlgorithm-validate-rsa': {
54+ const cases = {
55+ 'aes-gcm': [
56+ { name: 'AES-GCM', iv: new Uint8Array(12), tagLength: 128 },
57+ 'encrypt',
58+ ],
59+ 'aes-cbc': [
60+ { name: 'AES-CBC', iv: new Uint8Array(16) },
61+ 'encrypt',
62+ ],
63+ 'aes-ctr': [
64+ { name: 'AES-CTR', counter: new Uint8Array(16), length: 64 },
65+ 'encrypt',
66+ ],
67+ 'aes-generate': [{ name: 'AES-GCM', length: 256 }, 'generateKey'],
68+ 'hkdf': [
69+ {
70+ name: 'HKDF', hash: 'SHA-256',
71+ salt: new Uint8Array(32), info: new Uint8Array(32),
72+ },
73+ 'deriveBits',
74+ ],
75+ 'hmac': [{ name: 'HMAC', hash: 'SHA-256', length: 256 }, 'importKey'],
76+ 'rsa': [
77+ {
78+ name: 'RSA-PSS', hash: 'SHA-256', modulusLength: 2048,
79+ publicExponent: new Uint8Array([1, 0, 1]),
80+ },
81+ 'generateKey',
82+ ],
83+ };
84+ const name = op.slice('normalizeAlgorithm-validate-'.length);
85+ const [input, operation] = cases[name];
86+ bench.start();
87+ for (let i = 0; i < n; i++) {
88+ const normalized = normalizeAlgorithm(input, operation);
89+ // Older revisions validate inside normalizeAlgorithm.
90+ validateAlgorithm?.(normalized, operation);
91+ }
92+ bench.end(n);
93+ break;
94+ }
4095 case 'webidl-dict': {
4196 // WebIDL dictionary converter in isolation.
4297 const webidl = require('internal/crypto/webidl');
@@ -85,7 +140,7 @@ function main({ n, op }) {
85140 break;
86141 }
87142 case 'webidl-dict-ensure-sha': {
88- // Exercises ensureSHA on a hash member .
143+ // Converts a dictionary containing a hash identifier .
89144 const webidl = require('internal/crypto/webidl');
90145 const input = { name: 'RSASSA-PKCS1-v1_5', hash: 'SHA-256' };
91146 const opts = { prefix: 'test', context: 'test' };
0 commit comments