Skip to content

Commit 9b52db8

Browse files
panvaaduh95
authored andcommitted
crypto: discover ciphers from OpenSSL providers
Enumerate usable ciphers and aliases from activated OpenSSL 3 providers instead of maintaining lists of provider-only algorithms. Skip numeric OID aliases and filter NULL, TLS composite, multiblock, and encrypt-then-MAC implementations that the Cipher APIs cannot use. Preserve the OpenSSL 1.1.1 and BoringSSL paths. Expose CBC-CTS, SM4-GCM, SM4-CCM, SM4-XTS, and additional AES key wrap implementations. Add `ctsMode` (CS1/CS2/CS3) and `xtsStandard` (GB/IEEE) options for selecting provider CTS and SM4-XTS variants. Keep ordinary cipher construction on the original binding and legacy lookup paths. Lazily cache successful provider fetches per Environment for string initialization and `getCipherInfo()`. Index entries by case-insensitive query, canonical, and alias names. Deduplicate owners by provider and canonical identity. Return borrowed pointers on warm hits. Use the shared process-wide FIPS-state generation to invalidate per-Environment cipher caches and refresh `getCiphers()` snapshots in the main thread and workers. Existing cipher contexts retain their implementation and can finish across a transition. Release provider owners before unloading worker addon DSOs. Enforce one-shot updates for CBC-CTS, AES key wrap, SIV/GCM-SIV, and CCM decryption. Reject finalization without required input or CCM tags, and defer authentication failures to `final()`. Document streaming and XTS data-unit constraints. Add known-answer vectors, option validation, provider round trips, cache, worker, snapshot, FIPS transition, and construction benchmark coverage. Fixes: #43040 Fixes: #64866 Refs: #62982 Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #65484 Backport-PR-URL: #65596 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent d0d300f commit 9b52db8

26 files changed

Lines changed: 1802 additions & 225 deletions
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
'use strict';
2+
3+
const common = require('../common.js');
4+
const assert = require('node:assert');
5+
const {
6+
createCipheriv,
7+
createDecipheriv,
8+
getCiphers,
9+
} = require('node:crypto');
10+
11+
const configurations = {
12+
'aes-128-cbc': { keyLength: 16, ivLength: 16 },
13+
'aes-128-gcm': { keyLength: 16, ivLength: 12 },
14+
'aes-128-cbc-cts': { keyLength: 16, ivLength: 16 },
15+
'aes-128-wrap-inv': { keyLength: 16, ivLength: 8 },
16+
'aes128-wrap-inv': {
17+
keyLength: 16,
18+
ivLength: 8,
19+
warmupCipher: 'aes-128-wrap-inv',
20+
},
21+
};
22+
23+
const ciphers = ['aes-128-cbc', 'aes-128-gcm'];
24+
const availableCiphers = new Set(getCiphers());
25+
for (const cipher of [
26+
'aes-128-cbc-cts',
27+
'aes-128-wrap-inv',
28+
'aes128-wrap-inv',
29+
]) {
30+
if (availableCiphers.has(cipher)) {
31+
ciphers.push(cipher);
32+
}
33+
}
34+
35+
const bench = common.createBenchmark(main, {
36+
n: [1e5],
37+
cipher: ciphers,
38+
operation: ['encrypt', 'decrypt'],
39+
});
40+
41+
function main({ n, cipher, operation }) {
42+
const {
43+
keyLength,
44+
ivLength,
45+
warmupCipher = cipher,
46+
} = configurations[cipher];
47+
const key = Buffer.alloc(keyLength);
48+
const iv = Buffer.alloc(ivLength);
49+
const results = new Array(n);
50+
const method = operation === 'encrypt' ? createCipheriv : createDecipheriv;
51+
52+
const warmup = method(warmupCipher, key, iv);
53+
assert.strictEqual(typeof warmup, 'object');
54+
55+
bench.start();
56+
for (let i = 0; i < n; ++i) {
57+
results[i] = method(cipher, key, iv);
58+
}
59+
bench.end(n);
60+
61+
assert.strictEqual(typeof results[n - 1], 'object');
62+
}

0 commit comments

Comments
 (0)