| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 84bf93b commit 8422064
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -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 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,29 +15,22 @@ constexpr size_t kAesBlockSize = 16; | |||
| 15 | 15 | constexpr unsigned kNoAuthTagLength = static_cast<unsigned>(-1); | |
| 16 | 16 | constexpr const char* kDefaultWrapIV = "\xa6\xa6\xa6\xa6\xa6\xa6\xa6\xa6"; | |
| 17 | 17 | ||
| 18 | - enum class AESCipherMode { | ||
| 19 | - CTR, | ||
| 20 | - CBC, | ||
| 21 | - GCM, | ||
| 22 | - KW, | ||
| 23 | - }; | ||
| 24 | - | ||
| 25 | 18 | #define VARIANTS(V) \ | |
| 26 | - V(CTR_128, AES_CTR_Cipher, AESCipherMode::CTR, NID_aes_128_ctr) \ | ||
| 27 | - V(CTR_192, AES_CTR_Cipher, AESCipherMode::CTR, NID_aes_192_ctr) \ | ||
| 28 | - V(CTR_256, AES_CTR_Cipher, AESCipherMode::CTR, NID_aes_256_ctr) \ | ||
| 29 | - V(CBC_128, AES_Cipher, AESCipherMode::CBC, NID_aes_128_cbc) \ | ||
| 30 | - V(CBC_192, AES_Cipher, AESCipherMode::CBC, NID_aes_192_cbc) \ | ||
| 31 | - V(CBC_256, AES_Cipher, AESCipherMode::CBC, NID_aes_256_cbc) \ | ||
| 32 | - V(GCM_128, AES_Cipher, AESCipherMode::GCM, NID_aes_128_gcm) \ | ||
| 33 | - V(GCM_192, AES_Cipher, AESCipherMode::GCM, NID_aes_192_gcm) \ | ||
| 34 | - V(GCM_256, AES_Cipher, AESCipherMode::GCM, NID_aes_256_gcm) \ | ||
| 35 | - V(KW_128, AES_Cipher, AESCipherMode::KW, NID_id_aes128_wrap) \ | ||
| 36 | - V(KW_192, AES_Cipher, AESCipherMode::KW, NID_id_aes192_wrap) \ | ||
| 37 | - V(KW_256, AES_Cipher, AESCipherMode::KW, NID_id_aes256_wrap) | ||
| 19 | + V(CTR_128, AES_CTR_Cipher, NID_aes_128_ctr) \ | ||
| 20 | + V(CTR_192, AES_CTR_Cipher, NID_aes_192_ctr) \ | ||
| 21 | + V(CTR_256, AES_CTR_Cipher, NID_aes_256_ctr) \ | ||
| 22 | + V(CBC_128, AES_Cipher, NID_aes_128_cbc) \ | ||
| 23 | + V(CBC_192, AES_Cipher, NID_aes_192_cbc) \ | ||
| 24 | + V(CBC_256, AES_Cipher, NID_aes_256_cbc) \ | ||
| 25 | + V(GCM_128, AES_Cipher, NID_aes_128_gcm) \ | ||
| 26 | + V(GCM_192, AES_Cipher, NID_aes_192_gcm) \ | ||
| 27 | + V(GCM_256, AES_Cipher, NID_aes_256_gcm) \ | ||
| 28 | + V(KW_128, AES_Cipher, NID_id_aes128_wrap) \ | ||
| 29 | + V(KW_192, AES_Cipher, NID_id_aes192_wrap) \ | ||
| 30 | + V(KW_256, AES_Cipher, NID_id_aes256_wrap) | ||
| 38 | 31 | ||
| 39 | 32 | enum AESKeyVariant { | |
| 40 | - #define V(name, _, __, ___) kKeyVariantAES_##name, | ||
| 33 | + #define V(name, _, __) kKeyVariantAES_##name, | ||
| 41 | 34 | VARIANTS(V) | |
| 42 | 35 | #undef V | |
| 43 | 36 | }; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments