@@ -476,12 +476,9 @@ Maybe<bool> AESCipherTraits::AdditionalConfig(
476
476
params->variant =
477
477
static_cast <AESKeyVariant>(args[offset].As <Uint32>()->Value ());
478
478
479
- AESCipherMode cipher_op_mode;
480
479
int cipher_nid;
481
-
482
- #define V (name, _, mode, nid ) \
480
+ #define V (name, _, nid ) \
483
481
case kKeyVariantAES_ ##name: { \
484
- cipher_op_mode = mode; \
485
482
cipher_nid = nid; \
486
483
break ; \
487
484
}
@@ -492,15 +489,22 @@ Maybe<bool> AESCipherTraits::AdditionalConfig(
492
489
}
493
490
#undef V
494
491
495
- if (cipher_op_mode != AESCipherMode::KW) {
492
+ params->cipher = EVP_get_cipherbynid (cipher_nid);
493
+ if (params->cipher == nullptr ) {
494
+ THROW_ERR_CRYPTO_UNKNOWN_CIPHER (env);
495
+ return Nothing<bool >();
496
+ }
497
+
498
+ int cipher_op_mode = EVP_CIPHER_mode (params->cipher );
499
+ if (cipher_op_mode != EVP_CIPH_WRAP_MODE) {
496
500
if (!ValidateIV (env, mode, args[offset + 1 ], params)) {
497
501
return Nothing<bool >();
498
502
}
499
- if (cipher_op_mode == AESCipherMode::CTR ) {
503
+ if (cipher_op_mode == EVP_CIPH_CTR_MODE ) {
500
504
if (!ValidateCounter (env, args[offset + 2 ], params)) {
501
505
return Nothing<bool >();
502
506
}
503
- } else if (cipher_op_mode == AESCipherMode::GCM ) {
507
+ } else if (cipher_op_mode == EVP_CIPH_GCM_MODE ) {
504
508
if (!ValidateAuthTag (env, mode, cipher_mode, args[offset + 2 ], params) ||
505
509
!ValidateAdditionalData (env, mode, args[offset + 3 ], params)) {
506
510
return Nothing<bool >();
@@ -510,12 +514,6 @@ Maybe<bool> AESCipherTraits::AdditionalConfig(
510
514
UseDefaultIV (params);
511
515
}
512
516
513
- params->cipher = EVP_get_cipherbynid (cipher_nid);
514
- if (params->cipher == nullptr ) {
515
- THROW_ERR_CRYPTO_UNKNOWN_CIPHER (env);
516
- return Nothing<bool >();
517
- }
518
-
519
517
if (params->iv .size () <
520
518
static_cast <size_t >(EVP_CIPHER_iv_length (params->cipher ))) {
521
519
THROW_ERR_CRYPTO_INVALID_IV (env);
@@ -532,7 +530,7 @@ WebCryptoCipherStatus AESCipherTraits::DoCipher(
532
530
const AESCipherConfig& params,
533
531
const ByteSource& in,
534
532
ByteSource* out) {
535
- #define V (name, fn, _, __ ) \
533
+ #define V (name, fn, _ ) \
536
534
case kKeyVariantAES_ ##name: \
537
535
return fn (env, key_data.get (), cipher_mode, params, in, out);
538
536
switch (params.variant ) {
@@ -546,7 +544,7 @@ WebCryptoCipherStatus AESCipherTraits::DoCipher(
546
544
void AES::Initialize (Environment* env, Local<Object> target) {
547
545
AESCryptoJob::Initialize (env, target);
548
546
549
- #define V (name, _, __, ___ ) NODE_DEFINE_CONSTANT(target, kKeyVariantAES_ ##name);
547
+ #define V (name, _, __ ) NODE_DEFINE_CONSTANT(target, kKeyVariantAES_ ##name);
550
548
VARIANTS (V)
551
549
#undef V
552
550
}
0 commit comments