Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 1343x 1343x 1343x 1343x 1343x 1343x 1343x 1343x 2x 2x 2x 2x 2x 1288x 1288x 1288x 1288x 1288x 1288x 1288x 1288x 25x 25x 1332x 1332x 1332x 88x 88x 96x 80x 80x 80x 96x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 70x 70x 1332x 25x 1290x 1290x 1290x 1290x 1290x 1290x 1290x 1290x 1290x 1290x 1290x 1290x 1290x 1290x 1260x 1260x 1290x 1290x 1290x 1290x 25x 53x 53x 53x 53x 53x 53x 53x 53x 53x 53x 53x 53x 53x 24x 24x 53x 25x 1636x 1636x 1636x 1636x 1636x 1636x 1476x 1476x 1476x 1476x 1476x 1396x 1476x 1316x 1476x 80x 80x 80x 80x 1236x 1236x 1236x 1236x 1236x 1236x 1236x 1236x 1236x 1236x 1236x 1236x 1236x 1236x 1236x 1636x 25x 25x 25x 25x 25x 25x | 'use strict'; const { FunctionPrototypeCall, Promise, } = primordials; const { HKDFJob, kCryptoJobAsync, kCryptoJobSync, } = internalBinding('crypto'); const { validateFunction, validateInteger, validateString, validateUint32, } = require('internal/validators'); const { kMaxLength } = require('buffer'); const { getArrayBufferOrView, normalizeHashName, toBuf, validateByteSource, kKeyObject, } = require('internal/crypto/util'); const { createSecretKey, isKeyObject, } = require('internal/crypto/keys'); const { lazyDOMException, } = require('internal/util'); const { isAnyArrayBuffer, isArrayBufferView, } = require('internal/util/types'); const { codes: { ERR_INVALID_ARG_TYPE, ERR_OUT_OF_RANGE, ERR_MISSING_OPTION, }, hideStackFrames, } = require('internal/errors'); const validateParameters = hideStackFrames((hash, key, salt, info, length) => { validateString(hash, 'digest'); key = prepareKey(key); salt = validateByteSource(salt, 'salt'); info = validateByteSource(info, 'info'); validateInteger(length, 'length', 0, kMaxLength); if (info.byteLength > 1024) { throw ERR_OUT_OF_RANGE( 'info', 'must not contain more than 1024 bytes', info.byteLength); } return { hash, key, salt, info, length, }; }); function prepareKey(key) { if (isKeyObject(key)) return key; if (isAnyArrayBuffer(key)) return createSecretKey(key); key = toBuf(key); if (!isArrayBufferView(key)) { throw new ERR_INVALID_ARG_TYPE( 'ikm', [ 'string', 'SecretKeyObject', 'ArrayBuffer', 'TypedArray', 'DataView', 'Buffer', ], key); } return createSecretKey(key); } function hkdf(hash, key, salt, info, length, callback) { ({ hash, key, salt, info, length, } = validateParameters(hash, key, salt, info, length)); validateFunction(callback, 'callback'); const job = new HKDFJob(kCryptoJobAsync, hash, key, salt, info, length); job.ondone = (error, bits) => { if (error) return FunctionPrototypeCall(callback, job, error); FunctionPrototypeCall(callback, job, null, bits); }; job.run(); } function hkdfSync(hash, key, salt, info, length) { ({ hash, key, salt, info, length, } = validateParameters(hash, key, salt, info, length)); const job = new HKDFJob(kCryptoJobSync, hash, key, salt, info, length); const { 0: err, 1: bits } = job.run(); if (err !== undefined) throw err; return bits; } async function hkdfDeriveBits(algorithm, baseKey, length) { const { hash } = algorithm; const salt = getArrayBufferOrView(algorithm.salt, 'algorithm.salt'); const info = getArrayBufferOrView(algorithm.info, 'algorithm.info'); if (hash === undefined) throw new ERR_MISSING_OPTION('algorithm.hash'); let byteLength = 512 / 8; if (length !== undefined) { if (length === 0) throw lazyDOMException('length cannot be zero', 'OperationError'); if (length === null) throw lazyDOMException('length cannot be null', 'OperationError'); validateUint32(length, 'length'); if (length % 8) { throw lazyDOMException( 'length must be a multiple of 8', 'OperationError'); } byteLength = length / 8; } return new Promise((resolve, reject) => { hkdf( normalizeHashName(hash.name), baseKey[kKeyObject], salt, info, byteLength, (err, bits) => { if (err) return reject(err); resolve(bits); }); }); } module.exports = { hkdf, hkdfSync, hkdfDeriveBits, }; |