44 ArrayBufferIsView,
55 ArrayBufferPrototypeSlice,
66 ArrayFrom,
7- ArrayPrototypeIncludes,
87 ArrayPrototypePush,
98 MathFloor,
109 PromiseReject,
@@ -35,10 +34,7 @@ const {
3534const {
3635 hasAnyNotIn,
3736 jobPromise,
38- validateByteLength,
3937 validateKeyOps,
40- validateMaxBufferLength,
41- kAesKeyLengths,
4238 kHandle,
4339 kKeyObject,
4440} = require ( 'internal/crypto/util' ) ;
@@ -58,7 +54,6 @@ const {
5854 generateKey : _generateKey ,
5955} = require ( 'internal/crypto/keygen' ) ;
6056
61- const kTagLengths = [ 32 , 64 , 96 , 104 , 112 , 120 , 128 ] ;
6257const generateKey = promisify ( _generateKey ) ;
6358
6459function getAlgorithmName ( name , length ) {
@@ -108,20 +103,7 @@ function getVariant(name, length) {
108103 }
109104}
110105
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-
122106function asyncAesCtrCipher ( mode , key , data , algorithm ) {
123- validateAesCtrAlgorithm ( algorithm ) ;
124-
125107 return jobPromise ( ( ) => new AESCipherJob (
126108 kCryptoJobAsync ,
127109 mode ,
@@ -132,12 +114,7 @@ function asyncAesCtrCipher(mode, key, data, algorithm) {
132114 algorithm . length ) ) ;
133115}
134116
135- function validateAesCbcAlgorithm ( algorithm ) {
136- validateByteLength ( algorithm . iv , 'algorithm.iv' , 16 ) ;
137- }
138-
139117function asyncAesCbcCipher ( mode , key , data , algorithm ) {
140- validateAesCbcAlgorithm ( algorithm ) ;
141118 return jobPromise ( ( ) => new AESCipherJob (
142119 kCryptoJobAsync ,
143120 mode ,
@@ -156,23 +133,8 @@ function asyncAesKwCipher(mode, key, data) {
156133 getVariant ( 'AES-KW' , key . algorithm . length ) ) ) ;
157134}
158135
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-
173136function asyncAesGcmCipher ( mode , key , data , algorithm ) {
174137 algorithm . tagLength ??= 128 ;
175- validateAesGcmAlgorithm ( algorithm ) ;
176138
177139 const tagByteLength = MathFloor ( algorithm . tagLength / 8 ) ;
178140 let tag ;
@@ -220,16 +182,7 @@ function aesCipher(mode, key, data, algorithm) {
220182 }
221183}
222184
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-
231185async function aesGenerateKey ( algorithm , extractable , keyUsages ) {
232- validateAesGenerateKeyAlgorithm ( algorithm ) ;
233186 const { name, length } = algorithm ;
234187
235188 const checkUsages = [ 'wrapKey' , 'unwrapKey' ] ;
0 commit comments