Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTobias Nießen <tniessen@tnie.de>2022-03-21 18:30:07 +0300
committerGitHub <noreply@github.com>2022-03-21 18:30:07 +0300
commitdf39fd64b330e8f0db6892c2984983d0d1da9250 (patch)
treef6f55783da7e91a1f546c50af1f9191ade182f8e /src
parent298cc8212a5b48dccabea1e2b41257f20699a552 (diff)
src: refactor IsSupportedAuthenticatedMode
Improve the function's structure and clarify the special handling of ChaCha20-Poly1305. Remove the IS_OCB_MODE macro. PR-URL: https://github.com/nodejs/node/pull/42368 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/crypto/crypto_cipher.cc25
1 files changed, 12 insertions, 13 deletions
diff --git a/src/crypto/crypto_cipher.cc b/src/crypto/crypto_cipher.cc
index d6c6f0c4375..05acefb6011 100644
--- a/src/crypto/crypto_cipher.cc
+++ b/src/crypto/crypto_cipher.cc
@@ -24,21 +24,20 @@ using v8::Uint32;
using v8::Value;
namespace crypto {
-#ifdef OPENSSL_NO_OCB
-# define IS_OCB_MODE(mode) false
-#else
-# define IS_OCB_MODE(mode) ((mode) == EVP_CIPH_OCB_MODE)
-#endif
-
namespace {
bool IsSupportedAuthenticatedMode(const EVP_CIPHER* cipher) {
- const int mode = EVP_CIPHER_mode(cipher);
- // Check `chacha20-poly1305` separately, it is also an AEAD cipher,
- // but its mode is 0 which doesn't indicate
- return EVP_CIPHER_nid(cipher) == NID_chacha20_poly1305 ||
- mode == EVP_CIPH_CCM_MODE ||
- mode == EVP_CIPH_GCM_MODE ||
- IS_OCB_MODE(mode);
+ switch (EVP_CIPHER_mode(cipher)) {
+ case EVP_CIPH_CCM_MODE:
+ case EVP_CIPH_GCM_MODE:
+#ifndef OPENSSL_NO_OCB
+ case EVP_CIPH_OCB_MODE:
+#endif
+ return true;
+ case EVP_CIPH_STREAM_CIPHER:
+ return EVP_CIPHER_nid(cipher) == NID_chacha20_poly1305;
+ default:
+ return false;
+ }
}
bool IsSupportedAuthenticatedMode(const EVP_CIPHER_CTX* ctx) {