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