Skip to content

Commit 0cd6bfa

Browse files
tniessenjuanarbol
authored andcommitted
src: refactor IsSupportedAuthenticatedMode
Improve the function's structure and clarify the special handling of ChaCha20-Poly1305. Remove the IS_OCB_MODE macro. PR-URL: #42368 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
1 parent ad81dad commit 0cd6bfa

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/crypto/crypto_cipher.cc

+12-13
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,20 @@ using v8::Uint32;
2424
using v8::Value;
2525

2626
namespace crypto {
27-
#ifdef OPENSSL_NO_OCB
28-
# define IS_OCB_MODE(mode) false
29-
#else
30-
# define IS_OCB_MODE(mode) ((mode) == EVP_CIPH_OCB_MODE)
31-
#endif
32-
3327
namespace {
3428
bool IsSupportedAuthenticatedMode(const EVP_CIPHER* cipher) {
35-
const int mode = EVP_CIPHER_mode(cipher);
36-
// Check `chacha20-poly1305` separately, it is also an AEAD cipher,
37-
// but its mode is 0 which doesn't indicate
38-
return EVP_CIPHER_nid(cipher) == NID_chacha20_poly1305 ||
39-
mode == EVP_CIPH_CCM_MODE ||
40-
mode == EVP_CIPH_GCM_MODE ||
41-
IS_OCB_MODE(mode);
29+
switch (EVP_CIPHER_mode(cipher)) {
30+
case EVP_CIPH_CCM_MODE:
31+
case EVP_CIPH_GCM_MODE:
32+
#ifndef OPENSSL_NO_OCB
33+
case EVP_CIPH_OCB_MODE:
34+
#endif
35+
return true;
36+
case EVP_CIPH_STREAM_CIPHER:
37+
return EVP_CIPHER_nid(cipher) == NID_chacha20_poly1305;
38+
default:
39+
return false;
40+
}
4241
}
4342

4443
bool IsSupportedAuthenticatedMode(const EVP_CIPHER_CTX* ctx) {

0 commit comments

Comments
 (0)