@@ -476,12 +476,9 @@ Maybe<bool> AESCipherTraits::AdditionalConfig(
476476 params->variant =
477477 static_cast <AESKeyVariant>(args[offset].As <Uint32>()->Value ());
478478
479- AESCipherMode cipher_op_mode;
480479 int cipher_nid;
481-
482- #define V (name, _, mode, nid ) \
480+ #define V (name, _, nid ) \
483481 case kKeyVariantAES_ ##name: { \
484- cipher_op_mode = mode; \
485482 cipher_nid = nid; \
486483 break ; \
487484 }
@@ -492,15 +489,22 @@ Maybe<bool> AESCipherTraits::AdditionalConfig(
492489 }
493490#undef V
494491
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) {
496500 if (!ValidateIV (env, mode, args[offset + 1 ], params)) {
497501 return Nothing<bool >();
498502 }
499- if (cipher_op_mode == AESCipherMode::CTR ) {
503+ if (cipher_op_mode == EVP_CIPH_CTR_MODE ) {
500504 if (!ValidateCounter (env, args[offset + 2 ], params)) {
501505 return Nothing<bool >();
502506 }
503- } else if (cipher_op_mode == AESCipherMode::GCM ) {
507+ } else if (cipher_op_mode == EVP_CIPH_GCM_MODE ) {
504508 if (!ValidateAuthTag (env, mode, cipher_mode, args[offset + 2 ], params) ||
505509 !ValidateAdditionalData (env, mode, args[offset + 3 ], params)) {
506510 return Nothing<bool >();
@@ -510,12 +514,6 @@ Maybe<bool> AESCipherTraits::AdditionalConfig(
510514 UseDefaultIV (params);
511515 }
512516
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-
519517 if (params->iv .size () <
520518 static_cast <size_t >(EVP_CIPHER_iv_length (params->cipher ))) {
521519 THROW_ERR_CRYPTO_INVALID_IV (env);
@@ -532,7 +530,7 @@ WebCryptoCipherStatus AESCipherTraits::DoCipher(
532530 const AESCipherConfig& params,
533531 const ByteSource& in,
534532 ByteSource* out) {
535- #define V (name, fn, _, __ ) \
533+ #define V (name, fn, _ ) \
536534 case kKeyVariantAES_ ##name: \
537535 return fn (env, key_data.get (), cipher_mode, params, in, out);
538536 switch (params.variant ) {
@@ -546,7 +544,7 @@ WebCryptoCipherStatus AESCipherTraits::DoCipher(
546544void AES::Initialize (Environment* env, Local<Object> target) {
547545 AESCryptoJob::Initialize (env, target);
548546
549- #define V (name, _, __, ___ ) NODE_DEFINE_CONSTANT(target, kKeyVariantAES_ ##name);
547+ #define V (name, _, __ ) NODE_DEFINE_CONSTANT(target, kKeyVariantAES_ ##name);
550548 VARIANTS (V)
551549#undef V
552550}
0 commit comments