77
88const {
99 AESCipherJob,
10- kCryptoJobSyncWebCrypto ,
10+ kCryptoJobWebCrypto ,
1111 kKeyVariantAES_CTR_128,
1212 kKeyVariantAES_CBC_128,
1313 kKeyVariantAES_GCM_128,
@@ -28,9 +28,10 @@ const {
2828
2929const {
3030 getUsagesMask,
31- getWebCryptoJobModeForInputLength ,
31+ getWebCryptoJobMode ,
3232 hasAnyNotIn,
3333 jobPromise,
34+ kWebCryptoDefaultSyncThreshold,
3435} = require ( 'internal/crypto/util' ) ;
3536
3637const {
@@ -107,8 +108,10 @@ function getVariant(name, length) {
107108}
108109
109110function asyncAesCtrCipher ( mode , key , data , algorithm ) {
111+ const jobMode = data . byteLength <= kWebCryptoDefaultSyncThreshold ?
112+ getWebCryptoJobMode ( ) : kCryptoJobWebCrypto ;
110113 return jobPromise ( ( ) => new AESCipherJob (
111- getWebCryptoJobModeForInputLength ( data . byteLength ) ,
114+ jobMode ,
112115 mode ,
113116 getCryptoKeyHandle ( key ) ,
114117 data ,
@@ -118,8 +121,10 @@ function asyncAesCtrCipher(mode, key, data, algorithm) {
118121}
119122
120123function asyncAesCbcCipher ( mode , key , data , algorithm ) {
124+ const jobMode = data . byteLength <= kWebCryptoDefaultSyncThreshold ?
125+ getWebCryptoJobMode ( ) : kCryptoJobWebCrypto ;
121126 return jobPromise ( ( ) => new AESCipherJob (
122- getWebCryptoJobModeForInputLength ( data . byteLength ) ,
127+ jobMode ,
123128 mode ,
124129 getCryptoKeyHandle ( key ) ,
125130 data ,
@@ -128,8 +133,10 @@ function asyncAesCbcCipher(mode, key, data, algorithm) {
128133}
129134
130135function asyncAesKwCipher ( mode , key , data ) {
136+ const jobMode = data . byteLength <= kWebCryptoDefaultSyncThreshold ?
137+ getWebCryptoJobMode ( ) : kCryptoJobWebCrypto ;
131138 return jobPromise ( ( ) => new AESCipherJob (
132- getWebCryptoJobModeForInputLength ( data . byteLength ) ,
139+ jobMode ,
133140 mode ,
134141 getCryptoKeyHandle ( key ) ,
135142 data ,
@@ -140,10 +147,12 @@ function asyncAesGcmCipher(mode, key, data, algorithm) {
140147 const { tagLength = 128 } = algorithm ;
141148 const tagByteLength = tagLength / 8 ;
142149 const additionalDataLength = algorithm . additionalData ?. byteLength ?? 0 ;
150+ const inputByteLength = data . byteLength + additionalDataLength ;
151+ const jobMode = inputByteLength <= kWebCryptoDefaultSyncThreshold ?
152+ getWebCryptoJobMode ( ) : kCryptoJobWebCrypto ;
143153
144154 return jobPromise ( ( ) => new AESCipherJob (
145- getWebCryptoJobModeForInputLength (
146- data . byteLength + additionalDataLength ) ,
155+ jobMode ,
147156 mode ,
148157 getCryptoKeyHandle ( key ) ,
149158 data ,
@@ -157,10 +166,12 @@ function asyncAesOcbCipher(mode, key, data, algorithm) {
157166 const { tagLength = 128 } = algorithm ;
158167 const tagByteLength = tagLength / 8 ;
159168 const additionalDataLength = algorithm . additionalData ?. byteLength ?? 0 ;
169+ const inputByteLength = data . byteLength + additionalDataLength ;
170+ const jobMode = inputByteLength <= kWebCryptoDefaultSyncThreshold ?
171+ getWebCryptoJobMode ( ) : kCryptoJobWebCrypto ;
160172
161173 return jobPromise ( ( ) => new AESCipherJob (
162- getWebCryptoJobModeForInputLength (
163- data . byteLength + additionalDataLength ) ,
174+ jobMode ,
164175 mode ,
165176 getCryptoKeyHandle ( key ) ,
166177 data ,
@@ -199,8 +210,9 @@ function aesGenerateKey(algorithm, extractable, usages) {
199210 'SyntaxError' ) ;
200211 }
201212
213+ const jobMode = getWebCryptoJobMode ( ) ;
202214 return jobPromise ( ( ) => new SecretKeyGenJob (
203- kCryptoJobSyncWebCrypto ,
215+ jobMode ,
204216 length ,
205217 { name, length } ,
206218 getUsagesMask ( usagesSet ) ,
0 commit comments