From c7ab3cf7e776c31dad0908b4033e705501731287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Thu, 26 Apr 2018 21:05:18 +0200 Subject: [PATCH 1/2] crypto: use new OpenSSL constants in CipherBase This change replaces some constants with better alternatives which were unavailable in OpenSSL 1.0.2. Refs: https://github.com/nodejs/node/pull/19794 Refs: https://github.com/nodejs/node/pull/18138 --- src/node_crypto.cc | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 42f4d4035d6632..686e58aaf457f3 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -2798,10 +2798,7 @@ bool CipherBase::InitAuthenticated(const char *cipher_type, int iv_len, unsigned int auth_tag_len) { CHECK(IsAuthenticatedMode()); - // TODO(tniessen) Use EVP_CTRL_AEAD_SET_IVLEN when migrating to OpenSSL 1.1.0 - static_assert(EVP_CTRL_CCM_SET_IVLEN == EVP_CTRL_GCM_SET_IVLEN, - "OpenSSL constants differ between GCM and CCM"); - if (!EVP_CIPHER_CTX_ctrl(ctx_, EVP_CTRL_GCM_SET_IVLEN, iv_len, nullptr)) { + if (!EVP_CIPHER_CTX_ctrl(ctx_, EVP_CTRL_AEAD_SET_IVLEN, iv_len, nullptr)) { env()->ThrowError("Invalid IV length"); return false; } @@ -3111,10 +3108,7 @@ bool CipherBase::Final(unsigned char** out, int *out_len) { // be given by the user. if (mode == EVP_CIPH_GCM_MODE && auth_tag_len_ == kNoAuthTagLength) auth_tag_len_ = sizeof(auth_tag_); - // TOOD(tniessen) Use EVP_CTRL_AEAP_GET_TAG in OpenSSL 1.1.0 - static_assert(EVP_CTRL_CCM_GET_TAG == EVP_CTRL_GCM_GET_TAG, - "OpenSSL constants differ between GCM and CCM"); - CHECK_EQ(1, EVP_CIPHER_CTX_ctrl(ctx_, EVP_CTRL_GCM_GET_TAG, auth_tag_len_, + CHECK_EQ(1, EVP_CIPHER_CTX_ctrl(ctx_, EVP_CTRL_AEAD_GET_TAG, auth_tag_len_, reinterpret_cast(auth_tag_))); } } From eed972c7772199a9ddf7bc568a798040959a5cb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Mon, 30 Apr 2018 15:16:55 +0200 Subject: [PATCH 2/2] fixup! crypto: use new OpenSSL constants in CipherBase --- src/node_crypto.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 686e58aaf457f3..43a6a14b63833b 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -3108,7 +3108,8 @@ bool CipherBase::Final(unsigned char** out, int *out_len) { // be given by the user. if (mode == EVP_CIPH_GCM_MODE && auth_tag_len_ == kNoAuthTagLength) auth_tag_len_ = sizeof(auth_tag_); - CHECK_EQ(1, EVP_CIPHER_CTX_ctrl(ctx_, EVP_CTRL_AEAD_GET_TAG, auth_tag_len_, + CHECK_EQ(1, EVP_CIPHER_CTX_ctrl(ctx_, EVP_CTRL_AEAD_GET_TAG, + auth_tag_len_, reinterpret_cast(auth_tag_))); } }