Add EVP_CTRL_AEAD_* constants. Upstream generalized most of the EVP_CTRL_GCM_* constants to be their general AEAD API in 1.1.0. Define them for better compatibility with code that targets OpenSSL 1.1.0. Change-Id: Ieaed8379eebde3718e3048f6290c21cdeac01efd Reviewed-on: https://boringssl-review.googlesource.com/30604 Commit-Queue: David Benjamin <davidben@google.com> Commit-Queue: Adam Langley <agl@google.com> Reviewed-by: Adam Langley <agl@google.com> CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
diff --git a/crypto/cipher_extra/cipher_test.cc b/crypto/cipher_extra/cipher_test.cc index 83c660a..62ef939 100644 --- a/crypto/cipher_extra/cipher_test.cc +++ b/crypto/cipher_extra/cipher_test.cc
@@ -172,14 +172,15 @@ encrypt ? 1 : 0)); if (t->HasAttribute("IV")) { if (is_aead) { - ASSERT_TRUE( - EVP_CIPHER_CTX_ctrl(ctx.get(), EVP_CTRL_GCM_SET_IVLEN, iv.size(), 0)); + ASSERT_TRUE(EVP_CIPHER_CTX_ctrl(ctx.get(), EVP_CTRL_AEAD_SET_IVLEN, + iv.size(), 0)); } else { ASSERT_EQ(iv.size(), EVP_CIPHER_CTX_iv_length(ctx.get())); } } if (is_aead && !encrypt) { - ASSERT_TRUE(EVP_CIPHER_CTX_ctrl(ctx.get(), EVP_CTRL_GCM_SET_TAG, tag.size(), + ASSERT_TRUE(EVP_CIPHER_CTX_ctrl(ctx.get(), EVP_CTRL_AEAD_SET_TAG, + tag.size(), const_cast<uint8_t *>(tag.data()))); } // The ciphers are run with no padding. For each of the ciphers we test, the @@ -188,7 +189,7 @@ ASSERT_TRUE(EVP_CIPHER_CTX_set_key_length(ctx.get(), key.size())); ASSERT_TRUE(EVP_CipherInit_ex(ctx.get(), nullptr, nullptr, key.data(), iv.data(), -1)); - // Note: the deprecated |EVP_CIPHER|-based AES-GCM API is sensitive to whether + // Note: the deprecated |EVP_CIPHER|-based AEAD API is sensitive to whether // parameters are NULL, so it is important to skip the |in| and |aad| // |EVP_CipherUpdate| calls when empty. if (!aad.empty()) { @@ -203,8 +204,8 @@ if (encrypt && is_aead) { uint8_t rtag[16]; ASSERT_LE(tag.size(), sizeof(rtag)); - ASSERT_TRUE( - EVP_CIPHER_CTX_ctrl(ctx.get(), EVP_CTRL_GCM_GET_TAG, tag.size(), rtag)); + ASSERT_TRUE(EVP_CIPHER_CTX_ctrl(ctx.get(), EVP_CTRL_AEAD_GET_TAG, + tag.size(), rtag)); EXPECT_EQ(Bytes(tag), Bytes(rtag, tag.size())); } }
diff --git a/crypto/fipsmodule/cipher/e_aes.c b/crypto/fipsmodule/cipher/e_aes.c index 5138869..639995d 100644 --- a/crypto/fipsmodule/cipher/e_aes.c +++ b/crypto/fipsmodule/cipher/e_aes.c
@@ -418,7 +418,7 @@ gctx->iv_gen = 0; return 1; - case EVP_CTRL_GCM_SET_IVLEN: + case EVP_CTRL_AEAD_SET_IVLEN: if (arg <= 0) { return 0; } @@ -436,7 +436,7 @@ gctx->ivlen = arg; return 1; - case EVP_CTRL_GCM_SET_TAG: + case EVP_CTRL_AEAD_SET_TAG: if (arg <= 0 || arg > 16 || c->encrypt) { return 0; } @@ -444,14 +444,14 @@ gctx->taglen = arg; return 1; - case EVP_CTRL_GCM_GET_TAG: + case EVP_CTRL_AEAD_GET_TAG: if (arg <= 0 || arg > 16 || !c->encrypt || gctx->taglen < 0) { return 0; } OPENSSL_memcpy(ptr, c->buf, arg); return 1; - case EVP_CTRL_GCM_SET_IV_FIXED: + case EVP_CTRL_AEAD_SET_IV_FIXED: // Special case: -1 length restores whole IV if (arg == -1) { OPENSSL_memcpy(gctx->iv, ptr, gctx->ivlen);
diff --git a/include/openssl/cipher.h b/include/openssl/cipher.h index 7d99d49..727d7a7 100644 --- a/include/openssl/cipher.h +++ b/include/openssl/cipher.h
@@ -448,10 +448,10 @@ #define EVP_CTRL_RAND_KEY 0x6 #define EVP_CTRL_PBE_PRF_NID 0x7 #define EVP_CTRL_COPY 0x8 -#define EVP_CTRL_GCM_SET_IVLEN 0x9 -#define EVP_CTRL_GCM_GET_TAG 0x10 -#define EVP_CTRL_GCM_SET_TAG 0x11 -#define EVP_CTRL_GCM_SET_IV_FIXED 0x12 +#define EVP_CTRL_AEAD_SET_IVLEN 0x9 +#define EVP_CTRL_AEAD_GET_TAG 0x10 +#define EVP_CTRL_AEAD_SET_TAG 0x11 +#define EVP_CTRL_AEAD_SET_IV_FIXED 0x12 #define EVP_CTRL_GCM_IV_GEN 0x13 #define EVP_CTRL_AEAD_SET_MAC_KEY 0x17 // Set the GCM invocation field, decrypt only @@ -465,6 +465,12 @@ // Length of tag for TLS #define EVP_GCM_TLS_TAG_LEN 16 +// The following are legacy aliases for AEAD |EVP_CIPHER_CTX_ctrl| values. +#define EVP_CTRL_GCM_SET_IVLEN EVP_CTRL_AEAD_SET_IVLEN +#define EVP_CTRL_GCM_GET_TAG EVP_CTRL_AEAD_GET_TAG +#define EVP_CTRL_GCM_SET_TAG EVP_CTRL_AEAD_SET_TAG +#define EVP_CTRL_GCM_SET_IV_FIXED EVP_CTRL_AEAD_SET_IV_FIXED + #define EVP_MAX_KEY_LENGTH 64 #define EVP_MAX_IV_LENGTH 16 #define EVP_MAX_BLOCK_LENGTH 32