| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,9 +4,7 @@ const { | |||
| 4 | 4 | ArrayBufferIsView, | |
| 5 | 5 | ArrayBufferPrototypeSlice, | |
| 6 | 6 | ArrayFrom, | |
| 7 | - ArrayPrototypeIncludes, | ||
| 8 | 7 | ArrayPrototypePush, | |
| 9 | - MathFloor, | ||
| 10 | 8 | PromiseReject, | |
| 11 | 9 | SafeSet, | |
| 12 | 10 | TypedArrayPrototypeSlice, | |
@@ -35,10 +33,7 @@ const { | |||
| 35 | 33 | const { | |
| 36 | 34 | hasAnyNotIn, | |
| 37 | 35 | jobPromise, | |
| 38 | - validateByteLength, | ||
| 39 | 36 | validateKeyOps, | |
| 40 | - validateMaxBufferLength, | ||
| 41 | - kAesKeyLengths, | ||
| 42 | 37 | kHandle, | |
| 43 | 38 | kKeyObject, | |
| 44 | 39 | } = require('internal/crypto/util'); | |
@@ -58,7 +53,6 @@ const { | |||
| 58 | 53 | generateKey: _generateKey, | |
| 59 | 54 | } = require('internal/crypto/keygen'); | |
| 60 | 55 | ||
| 61 | - const kTagLengths = [32, 64, 96, 104, 112, 120, 128]; | ||
| 62 | 56 | const generateKey = promisify(_generateKey); | |
| 63 | 57 | ||
| 64 | 58 | function getAlgorithmName(name, length) { | |
@@ -108,20 +102,7 @@ function getVariant(name, length) { | |||
| 108 | 102 | } | |
| 109 | 103 | } | |
| 110 | 104 | ||
| 111 | - function validateAesCtrAlgorithm(algorithm) { | ||
| 112 | - validateByteLength(algorithm.counter, 'algorithm.counter', 16); | ||
| 113 | - // The length must specify an integer between 1 and 128. While | ||
| 114 | - // there is no default, this should typically be 64. | ||
| 115 | - if (algorithm.length === 0 || algorithm.length > 128) { | ||
| 116 | - throw lazyDOMException( | ||
| 117 | - 'AES-CTR algorithm.length must be between 1 and 128', | ||
| 118 | - 'OperationError'); | ||
| 119 | - } | ||
| 120 | - } | ||
| 121 | - | ||
| 122 | 105 | function asyncAesCtrCipher(mode, key, data, algorithm) { | |
| 123 | - validateAesCtrAlgorithm(algorithm); | ||
| 124 | - | ||
| 125 | 106 | return jobPromise(() => new AESCipherJob( | |
| 126 | 107 | kCryptoJobAsync, | |
| 127 | 108 | mode, | |
@@ -132,12 +113,7 @@ function asyncAesCtrCipher(mode, key, data, algorithm) { | |||
| 132 | 113 | algorithm.length)); | |
| 133 | 114 | } | |
| 134 | 115 | ||
| 135 | - function validateAesCbcAlgorithm(algorithm) { | ||
| 136 | - validateByteLength(algorithm.iv, 'algorithm.iv', 16); | ||
| 137 | - } | ||
| 138 | - | ||
| 139 | 116 | function asyncAesCbcCipher(mode, key, data, algorithm) { | |
| 140 | - validateAesCbcAlgorithm(algorithm); | ||
| 141 | 117 | return jobPromise(() => new AESCipherJob( | |
| 142 | 118 | kCryptoJobAsync, | |
| 143 | 119 | mode, | |
@@ -156,25 +132,10 @@ function asyncAesKwCipher(mode, key, data) { | |||
| 156 | 132 | getVariant('AES-KW', key.algorithm.length))); | |
| 157 | 133 | } | |
| 158 | 134 | ||
| 159 | - function validateAesGcmAlgorithm(algorithm) { | ||
| 160 | - if (!ArrayPrototypeIncludes(kTagLengths, algorithm.tagLength)) { | ||
| 161 | - throw lazyDOMException( | ||
| 162 | - `${algorithm.tagLength} is not a valid AES-GCM tag length`, | ||
| 163 | - 'OperationError'); | ||
| 164 | - } | ||
| 165 | - | ||
| 166 | - validateMaxBufferLength(algorithm.iv, 'algorithm.iv'); | ||
| 167 | - | ||
| 168 | - if (algorithm.additionalData !== undefined) { | ||
| 169 | - validateMaxBufferLength(algorithm.additionalData, 'algorithm.additionalData'); | ||
| 170 | - } | ||
| 171 | - } | ||
| 172 | - | ||
| 173 | 135 | function asyncAesGcmCipher(mode, key, data, algorithm) { | |
| 174 | - algorithm.tagLength ??= 128; | ||
| 175 | - validateAesGcmAlgorithm(algorithm); | ||
| 136 | + const { tagLength = 128 } = algorithm; | ||
| 176 | 137 | ||
| 177 | - const tagByteLength = MathFloor(algorithm.tagLength / 8); | ||
| 138 | + const tagByteLength = tagLength / 8; | ||
| 178 | 139 | let tag; | |
| 179 | 140 | switch (mode) { | |
| 180 | 141 | case kWebCryptoCipherDecrypt: { | |
@@ -220,16 +181,7 @@ function aesCipher(mode, key, data, algorithm) { | |||
| 220 | 181 | } | |
| 221 | 182 | } | |
| 222 | 183 | ||
| 223 | - function validateAesGenerateKeyAlgorithm(algorithm) { | ||
| 224 | - if (!ArrayPrototypeIncludes(kAesKeyLengths, algorithm.length)) { | ||
| 225 | - throw lazyDOMException( | ||
| 226 | - 'AES key length must be 128, 192, or 256 bits', | ||
| 227 | - 'OperationError'); | ||
| 228 | - } | ||
| 229 | - } | ||
| 230 | - | ||
| 231 | 184 | async function aesGenerateKey(algorithm, extractable, keyUsages) { | |
| 232 | - validateAesGenerateKeyAlgorithm(algorithm); | ||
| 233 | 185 | const { name, length } = algorithm; | |
| 234 | 186 | ||
| 235 | 187 | const checkUsages = ['wrapKey', 'unwrapKey']; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -329,15 +329,7 @@ function cfrgImportKey( | |||
| 329 | 329 | extractable); | |
| 330 | 330 | } | |
| 331 | 331 | ||
| 332 | - function validateEdDSASignVerifyAlgorithm(algorithm) { | ||
| 333 | - if (algorithm.name === 'Ed448' && algorithm.context?.byteLength) { | ||
| 334 | - throw lazyDOMException( | ||
| 335 | - 'Non zero-length context is not yet supported.', 'NotSupportedError'); | ||
| 336 | - } | ||
| 337 | - } | ||
| 338 | - | ||
| 339 | 332 | function eddsaSignVerify(key, data, algorithm, signature) { | |
| 340 | - validateEdDSASignVerifyAlgorithm(algorithm); | ||
| 341 | 333 | const mode = signature === undefined ? kSignJobModeSign : kSignJobModeVerify; | |
| 342 | 334 | const type = mode === kSignJobModeSign ? 'private' : 'public'; | |
| 343 | 335 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -297,22 +297,9 @@ function diffieHellman(options) { | |||
| 297 | 297 | } | |
| 298 | 298 | ||
| 299 | 299 | let masks; | |
| 300 | - | ||
| 301 | - function validateEcdhDeriveBitsAlgorithmAndLength(algorithm, length) { | ||
| 302 | - if (algorithm.public.type !== 'public') { | ||
| 303 | - throw lazyDOMException( | ||
| 304 | - 'algorithm.public must be a public key', 'InvalidAccessError'); | ||
| 305 | - } | ||
| 306 | - | ||
| 307 | - if (algorithm.name !== algorithm.public.algorithm.name) { | ||
| 308 | - throw lazyDOMException(`algorithm.public must be an ${algorithm.name} key`, 'InvalidAccessError'); | ||
| 309 | - } | ||
| 310 | - } | ||
| 311 | - | ||
| 312 | 300 | // The ecdhDeriveBits function is part of the Web Crypto API and serves both | |
| 313 | 301 | // deriveKeys and deriveBits functions. | |
| 314 | 302 | async function ecdhDeriveBits(algorithm, baseKey, length) { | |
| 315 | - validateEcdhDeriveBitsAlgorithmAndLength(algorithm, length); | ||
| 316 | 303 | const { 'public': key } = algorithm; | |
| 317 | 304 | ||
| 318 | 305 | if (baseKey.type !== 'private') { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,6 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | 3 | const { | |
| 4 | - ObjectPrototypeHasOwnProperty, | ||
| 5 | 4 | SafeSet, | |
| 6 | 5 | } = primordials; | |
| 7 | 6 | ||
@@ -76,16 +75,7 @@ function createECPublicKeyRaw(namedCurve, keyData) { | |||
| 76 | 75 | return new PublicKeyObject(handle); | |
| 77 | 76 | } | |
| 78 | 77 | ||
| 79 | - function validateEcKeyAlgorithm(algorithm) { | ||
| 80 | - if (!ObjectPrototypeHasOwnProperty(kNamedCurveAliases, algorithm.namedCurve)) { | ||
| 81 | - throw lazyDOMException( | ||
| 82 | - 'Unrecognized namedCurve', | ||
| 83 | - 'NotSupportedError'); | ||
| 84 | - } | ||
| 85 | - } | ||
| 86 | - | ||
| 87 | 78 | async function ecGenerateKey(algorithm, extractable, keyUsages) { | |
| 88 | - validateEcKeyAlgorithm(algorithm); | ||
| 89 | 79 | const { name, namedCurve } = algorithm; | |
| 90 | 80 | ||
| 91 | 81 | const usageSet = new SafeSet(keyUsages); | |
@@ -158,7 +148,6 @@ function ecImportKey( | |||
| 158 | 148 | extractable, | |
| 159 | 149 | keyUsages, | |
| 160 | 150 | ) { | |
| 161 | - validateEcKeyAlgorithm(algorithm); | ||
| 162 | 151 | const { name, namedCurve } = algorithm; | |
| 163 | 152 | ||
| 164 | 153 | let keyObject; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -138,7 +138,7 @@ function hkdfSync(hash, key, salt, info, length) { | |||
| 138 | 138 | } | |
| 139 | 139 | ||
| 140 | 140 | const hkdfPromise = promisify(hkdf); | |
| 141 | - function validateHkdfDeriveBitsAlgorithmAndLength(algorithm, length) { | ||
| 141 | + function validateHkdfDeriveBitsLength(length) { | ||
| 142 | 142 | if (length === null) | |
| 143 | 143 | throw lazyDOMException('length cannot be null', 'OperationError'); | |
| 144 | 144 | if (length % 8) { | |
@@ -149,7 +149,7 @@ function validateHkdfDeriveBitsAlgorithmAndLength(algorithm, length) { | |||
| 149 | 149 | } | |
| 150 | 150 | ||
| 151 | 151 | async function hkdfDeriveBits(algorithm, baseKey, length) { | |
| 152 | - validateHkdfDeriveBitsAlgorithmAndLength(algorithm, length); | ||
| 152 | + validateHkdfDeriveBitsLength(length); | ||
| 153 | 153 | const { hash, salt, info } = algorithm; | |
| 154 | 154 | ||
| 155 | 155 | if (length === 0) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,10 +33,6 @@ const { | |||
| 33 | 33 | parsePrivateKeyEncoding, | |
| 34 | 34 | } = require('internal/crypto/keys'); | |
| 35 | 35 | ||
| 36 | - const { | ||
| 37 | - kAesKeyLengths, | ||
| 38 | - } = require('internal/crypto/util'); | ||
| 39 | - | ||
| 40 | 36 | const { | |
| 41 | 37 | customPromisifyArgs, | |
| 42 | 38 | kEmptyObject, | |
@@ -355,7 +351,7 @@ function generateKeyJob(mode, keyType, options) { | |||
| 355 | 351 | validateInteger(length, 'options.length', 8, 2 ** 31 - 1); | |
| 356 | 352 | break; | |
| 357 | 353 | case 'aes': | |
| 358 | - validateOneOf(length, 'options.length', kAesKeyLengths); | ||
| 354 | + validateOneOf(length, 'options.length', [128, 192, 256]); | ||
| 359 | 355 | break; | |
| 360 | 356 | default: | |
| 361 | 357 | throw new ERR_INVALID_ARG_VALUE( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,24 +40,7 @@ const { | |||
| 40 | 40 | ||
| 41 | 41 | const generateKey = promisify(_generateKey); | |
| 42 | 42 | ||
| 43 | - function validateHmacGenerateKeyAlgorithm(algorithm) { | ||
| 44 | - if (algorithm.length !== undefined) { | ||
| 45 | - if (algorithm.length === 0) | ||
| 46 | - throw lazyDOMException( | ||
| 47 | - 'Zero-length key is not supported', | ||
| 48 | - 'OperationError'); | ||
| 49 | - | ||
| 50 | - // The Web Crypto spec allows for key lengths that are not multiples of 8. We don't. | ||
| 51 | - if (algorithm.length % 8) { | ||
| 52 | - throw lazyDOMException( | ||
| 53 | - 'Unsupported algorithm.length', | ||
| 54 | - 'NotSupportedError'); | ||
| 55 | - } | ||
| 56 | - } | ||
| 57 | - } | ||
| 58 | - | ||
| 59 | 43 | async function hmacGenerateKey(algorithm, extractable, keyUsages) { | |
| 60 | - validateHmacGenerateKeyAlgorithm(algorithm); | ||
| 61 | 44 | const { hash, name } = algorithm; | |
| 62 | 45 | let { length } = algorithm; | |
| 63 | 46 | ||
@@ -96,27 +79,13 @@ function getAlgorithmName(hash) { | |||
| 96 | 79 | } | |
| 97 | 80 | } | |
| 98 | 81 | ||
| 99 | - function validateHmacImportKeyAlgorithm(algorithm) { | ||
| 100 | - if (algorithm.length !== undefined) { | ||
| 101 | - if (algorithm.length === 0) { | ||
| 102 | - throw lazyDOMException('Zero-length key is not supported', 'DataError'); | ||
| 103 | - } | ||
| 104 | - | ||
| 105 | - // The Web Crypto spec allows for key lengths that are not multiples of 8. We don't. | ||
| 106 | - if (algorithm.length % 8) { | ||
| 107 | - throw lazyDOMException('Unsupported algorithm.length', 'NotSupportedError'); | ||
| 108 | - } | ||
| 109 | - } | ||
| 110 | - } | ||
| 111 | - | ||
| 112 | 82 | function hmacImportKey( | |
| 113 | 83 | format, | |
| 114 | 84 | keyData, | |
| 115 | 85 | algorithm, | |
| 116 | 86 | extractable, | |
| 117 | 87 | keyUsages, | |
| 118 | 88 | ) { | |
| 119 | - validateHmacImportKeyAlgorithm(algorithm); | ||
| 120 | 89 | const usagesSet = new SafeSet(keyUsages); | |
| 121 | 90 | if (hasAnyNotIn(usagesSet, ['sign', 'verify'])) { | |
| 122 | 91 | throw lazyDOMException( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -92,12 +92,7 @@ function check(password, salt, iterations, keylen, digest) { | |||
| 92 | 92 | } | |
| 93 | 93 | ||
| 94 | 94 | const pbkdf2Promise = promisify(pbkdf2); | |
| 95 | - function validatePbkdf2DeriveBitsAlgorithmAndLength(algorithm, length) { | ||
| 96 | - if (algorithm.iterations === 0) | ||
| 97 | - throw lazyDOMException( | ||
| 98 | - 'iterations cannot be zero', | ||
| 99 | - 'OperationError'); | ||
| 100 | - | ||
| 95 | + function validatePbkdf2DeriveBitsLength(length) { | ||
| 101 | 96 | if (length === null) | |
| 102 | 97 | throw lazyDOMException('length cannot be null', 'OperationError'); | |
| 103 | 98 | ||
@@ -109,7 +104,7 @@ function validatePbkdf2DeriveBitsAlgorithmAndLength(algorithm, length) { | |||
| 109 | 104 | } | |
| 110 | 105 | ||
| 111 | 106 | async function pbkdf2DeriveBits(algorithm, baseKey, length) { | |
| 112 | - validatePbkdf2DeriveBitsAlgorithmAndLength(algorithm, length); | ||
| 107 | + validatePbkdf2DeriveBitsLength(length); | ||
| 113 | 108 | const { iterations, hash, salt } = algorithm; | |
| 114 | 109 | ||
| 115 | 110 | if (length === 0) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -111,23 +111,17 @@ function rsaOaepCipher(mode, key, data, algorithm) { | |||
| 111 | 111 | algorithm.label)); | |
| 112 | 112 | } | |
| 113 | 113 | ||
| 114 | - function validateRsaKeyGenerateAlgorithm(algorithm) { | ||
| 114 | + async function rsaKeyGenerate( | ||
| 115 | + algorithm, | ||
| 116 | + extractable, | ||
| 117 | + keyUsages, | ||
| 118 | + ) { | ||
| 115 | 119 | const publicExponentConverted = bigIntArrayToUnsignedInt(algorithm.publicExponent); | |
| 116 | 120 | if (publicExponentConverted === undefined) { | |
| 117 | 121 | throw lazyDOMException( | |
| 118 | 122 | 'The publicExponent must be equivalent to an unsigned 32-bit value', | |
| 119 | 123 | 'OperationError'); | |
| 120 | 124 | } | |
| 121 | - | ||
| 122 | - return publicExponentConverted; | ||
| 123 | - } | ||
| 124 | - | ||
| 125 | - async function rsaKeyGenerate( | ||
| 126 | - algorithm, | ||
| 127 | - extractable, | ||
| 128 | - keyUsages, | ||
| 129 | - ) { | ||
| 130 | - const publicExponentConverted = validateRsaKeyGenerateAlgorithm(algorithm); | ||
| 131 | 125 | const { | |
| 132 | 126 | name, | |
| 133 | 127 | modulusLength, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -168,8 +168,6 @@ const kNamedCurveAliases = { | |||
| 168 | 168 | 'P-521': 'secp521r1', | |
| 169 | 169 | }; | |
| 170 | 170 | ||
| 171 | - const kAesKeyLengths = [128, 192, 256]; | ||
| 172 | - | ||
| 173 | 171 | const kSupportedAlgorithms = { | |
| 174 | 172 | 'digest': { | |
| 175 | 173 | 'SHA-1': null, | |
@@ -416,14 +414,6 @@ function hasAnyNotIn(set, checks) { | |||
| 416 | 414 | return false; | |
| 417 | 415 | } | |
| 418 | 416 | ||
| 419 | - function validateByteLength(buf, name, target) { | ||
| 420 | - if (buf.byteLength !== target) { | ||
| 421 | - throw lazyDOMException( | ||
| 422 | - `${name} must contain exactly ${target} bytes`, | ||
| 423 | - 'OperationError'); | ||
| 424 | - } | ||
| 425 | - } | ||
| 426 | - | ||
| 427 | 417 | const validateByteSource = hideStackFrames((val, name) => { | |
| 428 | 418 | val = toBuf(val); | |
| 429 | 419 | ||
@@ -597,11 +587,9 @@ module.exports = { | |||
| 597 | 587 | toBuf, | |
| 598 | 588 | ||
| 599 | 589 | kNamedCurveAliases, | |
| 600 | - kAesKeyLengths, | ||
| 601 | 590 | normalizeAlgorithm, | |
| 602 | 591 | normalizeHashName, | |
| 603 | 592 | hasAnyNotIn, | |
| 604 | - validateByteLength, | ||
| 605 | 593 | validateByteSource, | |
| 606 | 594 | validateKeyOps, | |
| 607 | 595 | jobPromise, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments