| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c00ea01 commit 74ea78d
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -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 | } | |
| 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