GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — crypto: refactoring internals, add WebCrypto · lerouxb/node@dae283d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .github
    • CODEOWNERS
  • benchmark/crypto
    • hkdf.js
    • keygen.js
    • webcrypto-digest.js
  • doc/api
    • crypto.md
    • deprecations.md
    • errors.md
    • index.md
    • webcrypto.md
  • lib
    • crypto.js
    • internal
      • crypto
        • aes.js
        • certificate.js
        • cipher.js
        • diffiehellman.js
        • dsa.js
        • ec.js
        • hash.js
        • hashnames.js
        • hkdf.js
        • keygen.js
        • keys.js
        • mac.js
        • pbkdf2.js
        • random.js
        • rsa.js
        • scrypt.js
        • sig.js
        • util.js
        • webcrypto.js
      • per_context
        • primordials.js
  • node.gyp
  • src
    • async_wrap.h
    • base64-inl.h
    • base64.h
    • base_object.h
    • crypto
      • README.md
      • crypto_aes.cc
      • crypto_aes.h
      • crypto_bio.cc
      • crypto_bio.h
      • crypto_cipher.cc
      • crypto_cipher.h
      • crypto_clienthello-inl.h
      • crypto_clienthello.cc
      • crypto_clienthello.h
      • crypto_common.cc
      • crypto_common.h
      • crypto_context.cc
      • crypto_context.h
      • crypto_dh.cc
      • crypto_dh.h
      • crypto_dsa.cc
      • crypto_dsa.h
      • crypto_ecdh.cc
      • crypto_ecdh.h
      • crypto_hash.cc
      • crypto_hash.h
      • crypto_hkdf.cc
      • crypto_hkdf.h
      • crypto_hmac.cc
      • crypto_hmac.h
      • crypto_keygen.cc
      • crypto_keygen.h
      • crypto_keys.cc
      • crypto_keys.h
      • crypto_pbkdf2.cc
      • crypto_pbkdf2.h
      • crypto_random.cc
      • crypto_random.h
      • crypto_rsa.cc
      • crypto_rsa.h
      • crypto_scrypt.cc
      • crypto_scrypt.h
      • crypto_sig.cc
      • crypto_sig.h
      • crypto_spkac.cc
      • crypto_spkac.h
      • crypto_ssl.cc
      • crypto_ssl.h
      • crypto_timing.cc
      • crypto_timing.h
      • crypto_util.cc
      • crypto_util.h
    • env.h
    • inspector_io.cc
    • node.h
    • node_crypto.cc
    • node_crypto.h
    • node_errors.h
    • node_native_module.cc
    • node_task_queue.cc
    • quic
      • node_quic.cc
      • node_quic_crypto.cc
    • string_bytes.cc
    • tls_wrap.cc
    • tls_wrap.h
  • test
    • cctest
      • test_base64.cc
    • fixtures/crypto
      • aes_cbc.js
      • aes_ctr.js
      • aes_gcm.js
      • dsa.js
      • ecdsa.js
      • hmac.js
      • rsa.js
      • rsa_pkcs.js
      • rsa_pss.js
    • parallel
      • test-crypto-authenticated.js
      • test-crypto-certificate.js
      • test-crypto-cipher-decipher.js
      • test-crypto-cipheriv-decipheriv.js
      • test-crypto-dh.js
      • test-crypto-ecdh-convert-key.js
      • test-crypto-hash.js
      • test-crypto-hkdf.js
      • test-crypto-hmac.js
      • test-crypto-key-objects.js
      • test-crypto-keygen.js
      • test-crypto-pbkdf2.js
      • test-crypto-random.js
      • test-crypto-rsa-dsa.js
      • test-crypto-secret-keygen.js
      • test-crypto-sign-verify.js
      • test-webcrypto-cryptokey-workers.js
      • test-webcrypto-derivebits-ecdh.js
      • test-webcrypto-derivebits-hkdf.js
      • test-webcrypto-derivebits-node-dh.js
      • test-webcrypto-derivebits-pbkdf2.js
      • test-webcrypto-derivebits.js
      • test-webcrypto-derivekey-ecdh.js
      • test-webcrypto-derivekey.js
      • test-webcrypto-digest.js
      • test-webcrypto-encrypt-decrypt-aes.js
      • test-webcrypto-encrypt-decrypt-rsa.js
      • test-webcrypto-encrypt-decrypt.js
      • test-webcrypto-export-import-dsa.js
      • test-webcrypto-export-import-ec.js
      • test-webcrypto-export-import-rsa.js
      • test-webcrypto-export-import.js
      • test-webcrypto-keygen.js
      • test-webcrypto-random.js
      • test-webcrypto-sign-verify-ecdsa.js
      • test-webcrypto-sign-verify-hmac.js
      • test-webcrypto-sign-verify-node-dsa.js
      • test-webcrypto-sign-verify-rsa.js
      • test-webcrypto-sign-verify.js
      • test-webcrypto-wrap-unwrap.js
    • sequential
      • test-async-wrap-getasyncid.js
      • test-crypto-timing-safe-equal.js
  • tools/doc
    • type-parser.js

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.github/CODEOWNERS‎

Copy file name to clipboardExpand all lines: .github/CODEOWNERS
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
/lib/crypto.js @nodejs/crypto
6060
/lib/tls.js @nodejs/crypto @nodejs/net
6161
/src/node_crypto* @nodejs/crypto
62-
/src/node_crypto_common* @nodejs/crypto @nodejs/quic
62+
/src/crypto/* @nodejs/crypto @nodejs/quic
6363

6464
# http
6565

Collapse file

‎benchmark/crypto/hkdf.js‎

Copy file name to clipboard
+44Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use strict';
2+
3+
const common = require('../common.js');
4+
const assert = require('assert');
5+
const {
6+
hkdf,
7+
hkdfSync
8+
} = require('crypto');
9+
10+
const bench = common.createBenchmark(main, {
11+
sync: [0, 1],
12+
size: [10, 64, 1024],
13+
key: ['a', 'secret', 'this-is-a-much-longer-secret'],
14+
salt: ['', 'salt'],
15+
info: ['', 'info'],
16+
hash: ['sha256', 'sha512'],
17+
n: [1e3],
18+
});
19+
20+
function measureSync(n, size, salt, info, hash, key) {
21+
bench.start();
22+
for (let i = 0; i < n; ++i)
23+
hkdfSync(hash, key, salt, info, size);
24+
bench.end(n);
25+
}
26+
27+
function measureAsync(n, size, salt, info, hash, key) {
28+
let remaining = n;
29+
function done(err) {
30+
assert.ifError(err);
31+
if (--remaining === 0)
32+
bench.end(n);
33+
}
34+
bench.start();
35+
for (let i = 0; i < n; ++i)
36+
hkdf(hash, key, salt, info, size, done);
37+
}
38+
39+
function main({ n, sync, size, salt, info, hash, key }) {
40+
if (sync)
41+
measureSync(n, size, salt, info, hash, key);
42+
else
43+
measureAsync(n, size, salt, info, hash, key);
44+
}
Collapse file

‎benchmark/crypto/keygen.js‎

Copy file name to clipboard
+71Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
'use strict';
2+
3+
const common = require('../common.js');
4+
const assert = require('assert');
5+
const {
6+
generateKeyPair,
7+
generateKeyPairSync
8+
} = require('crypto');
9+
10+
const bench = common.createBenchmark(main, {
11+
method: ['rsaSync', 'rsaAsync', 'dsaSync', 'dsaAsync'],
12+
n: [1e2],
13+
});
14+
15+
const methods = {
16+
rsaSync(n) {
17+
bench.start();
18+
for (let i = 0; i < n; ++i) {
19+
generateKeyPairSync('rsa', {
20+
modulusLength: 1024,
21+
publicExponent: 0x10001
22+
});
23+
}
24+
bench.end(n);
25+
},
26+
27+
rsaAsync(n) {
28+
let remaining = n;
29+
function done(err) {
30+
assert.ifError(err);
31+
if (--remaining === 0)
32+
bench.end(n);
33+
}
34+
bench.start();
35+
for (let i = 0; i < n; ++i)
36+
generateKeyPair('rsa', {
37+
modulusLength: 512,
38+
publicExponent: 0x10001
39+
}, done);
40+
},
41+
42+
dsaSync(n) {
43+
bench.start();
44+
for (let i = 0; i < n; ++i) {
45+
generateKeyPairSync('dsa', {
46+
modulusLength: 512,
47+
divisorLength: 256,
48+
});
49+
}
50+
bench.end(n);
51+
},
52+
53+
dsaAsync(n) {
54+
let remaining = n;
55+
function done(err) {
56+
assert.ifError(err);
57+
if (--remaining === 0)
58+
bench.end(n);
59+
}
60+
bench.start();
61+
for (let i = 0; i < n; ++i)
62+
generateKeyPair('dsa', {
63+
modulusLength: 512,
64+
divisorLength: 256,
65+
}, done);
66+
},
67+
};
68+
69+
function main({ n, method }) {
70+
methods[method](n);
71+
}
Collapse file

‎benchmark/crypto/webcrypto-digest.js‎

Copy file name to clipboard
+58Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
'use strict';
2+
3+
const common = require('../common.js');
4+
const {
5+
createHash,
6+
webcrypto: {
7+
subtle,
8+
getRandomValues
9+
}
10+
} = require('crypto');
11+
12+
const bench = common.createBenchmark(main, {
13+
sync: ['createHash', 'subtle'],
14+
data: [10, 20, 50, 100],
15+
method: ['SHA-1', 'SHA-256', 'SHA-384', 'SHA-512'],
16+
n: [1e3],
17+
});
18+
19+
const kMethods = {
20+
'SHA-1': 'sha1',
21+
'SHA-256': 'sha256',
22+
'SHA-384': 'sha384',
23+
'SHA-512': 'sha512'
24+
};
25+
26+
// This benchmark only looks at clock time and ignores factors
27+
// such as event loop delay, event loop utilization, and memory.
28+
// As such, it is expected that the synchronous legacy method
29+
// will always be faster in clock time.
30+
31+
function measureLegacy(n, data, method) {
32+
method = kMethods[method];
33+
bench.start();
34+
for (let i = 0; i < n; ++i) {
35+
createHash(method).update(data).digest();
36+
}
37+
bench.end(n);
38+
}
39+
40+
function measureSubtle(n, data, method) {
41+
const ec = new TextEncoder();
42+
data = ec.encode(data);
43+
const jobs = new Array(n);
44+
bench.start();
45+
for (let i = 0; i < n; i++)
46+
jobs[i] = subtle.digest(method, data);
47+
Promise.all(jobs).then(() => bench.end(n)).catch((err) => {
48+
process.nextTick(() => { throw err; });
49+
});
50+
}
51+
52+
function main({ n, sync, data, method }) {
53+
data = getRandomValues(Buffer.alloc(data));
54+
switch (sync) {
55+
case 'createHash': return measureLegacy(n, data, method);
56+
case 'subtle': return measureSubtle(n, data, method);
57+
}
58+
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.