MCPcopy Index your code
hub / github.com/nodejs/node / deriveBitsImpl

Function deriveBitsImpl

lib/internal/crypto/webcrypto.js:251–297  ·  view source on GitHub ↗
(algorithm, baseKey, length = null)

Source from the content-addressed store, hash-verified

249}
250
251function deriveBitsImpl(algorithm, baseKey, length = null) {
252 const prefix = prepareSubtleMethod(this, 'deriveBits', arguments.length, 2);
253 let i = 0;
254 algorithm = convertSubtleArgument(
255 prefix, 'AlgorithmIdentifier', algorithm, i++);
256 baseKey = convertSubtleArgument(prefix, 'CryptoKey', baseKey, i++);
257 if (length !== null) {
258 length = convertSubtleArgument(prefix, 'unsigned long', length, i++);
259 }
260
261 const normalizedAlgorithm = normalizeAlgorithm(algorithm, 'deriveBits');
262 if (!hasCryptoKeyUsage(baseKey, 'deriveBits')) {
263 throw lazyDOMException(
264 'baseKey does not have deriveBits usage',
265 'InvalidAccessError');
266 }
267 if (getCryptoKeyAlgorithm(baseKey).name !== normalizedAlgorithm.name)
268 throw lazyDOMException('Key algorithm mismatch', 'InvalidAccessError');
269 switch (normalizedAlgorithm.name) {
270 case 'X25519':
271 // Fall through
272 case 'X448':
273 // Fall through
274 case 'ECDH':
275 return require('internal/crypto/diffiehellman')
276 .ecdhDeriveBits(normalizedAlgorithm, baseKey, length);
277 case 'HKDF':
278 return require('internal/crypto/hkdf')
279 .hkdfDeriveBits(normalizedAlgorithm, baseKey, length);
280 case 'PBKDF2':
281 return require('internal/crypto/pbkdf2')
282 .pbkdf2DeriveBits(normalizedAlgorithm, baseKey, length);
283 case 'Argon2d':
284 // Fall through
285 case 'Argon2i':
286 // Fall through
287 case 'Argon2id':
288 return require('internal/crypto/argon2')
289 .argon2DeriveBits(normalizedAlgorithm, baseKey, length);
290 /* c8 ignore start */
291 default: {
292 const assert = require('internal/assert');
293 assert.fail('Unreachable code');
294 }
295 /* c8 ignore stop */
296 }
297}
298
299function getKeyLength({ name, length, hash }) {
300 switch (name) {

Callers

nothing calls this directly

Calls 8

prepareSubtleMethodFunction · 0.85
convertSubtleArgumentFunction · 0.85
hasCryptoKeyUsageFunction · 0.85
lazyDOMExceptionFunction · 0.85
getCryptoKeyAlgorithmFunction · 0.85
normalizeAlgorithmFunction · 0.70
requireFunction · 0.50
failMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…