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' ] ;
0 commit comments