Skip to content

Commit

Permalink
crypto: use new OpenSSL constants in CipherBase
Browse files Browse the repository at this point in the history
This change replaces some constants with better alternatives which were
unavailable in OpenSSL 1.0.2.

PR-URL: #20339
Refs: #19794
Refs: #18138
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Daniel Bevenius <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
tniessen committed Apr 30, 2018
1 parent 109cfa1 commit 0e63724
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2809,10 +2809,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;
}
Expand Down Expand Up @@ -3122,10 +3119,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_);
// 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<unsigned char*>(auth_tag_)));
}
}
Expand Down

0 comments on commit 0e63724

Please sign in to comment.