From bafb34529604987f648954dcf3c3776598e1133f Mon Sep 17 00:00:00 2001 From: WillChilds-Klein Date: Mon, 11 Nov 2024 16:02:41 +0000 Subject: [PATCH] Convert macros to concrete functions --- crypto/pkcs7/bio/bio_md_test.cc | 10 +++++----- crypto/pkcs7/bio/cipher.c | 4 ++++ crypto/pkcs7/bio/md.c | 8 ++++++++ crypto/pkcs7/internal.h | 13 ++++++------- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/crypto/pkcs7/bio/bio_md_test.cc b/crypto/pkcs7/bio/bio_md_test.cc index eb1f93cdc8..7c3008e307 100644 --- a/crypto/pkcs7/bio/bio_md_test.cc +++ b/crypto/pkcs7/bio/bio_md_test.cc @@ -62,7 +62,7 @@ TEST_P(BIOMessageDigestTest, Basic) { bio_md.reset(BIO_new(BIO_f_md())); ASSERT_TRUE(bio_md); EXPECT_FALSE(BIO_reset(bio_md.get())); - EXPECT_TRUE(BIO_set_md(bio_md.get(), (EVP_MD *)md)); + EXPECT_TRUE(BIO_set_md(bio_md.get(), md)); EVP_MD_CTX *ctx_tmp; // |bio_md| owns the context, we just take a ref here EXPECT_TRUE(BIO_get_md_ctx(bio_md.get(), &ctx_tmp)); EXPECT_EQ(EVP_MD_type(md), EVP_MD_CTX_type(ctx_tmp)); @@ -98,7 +98,7 @@ TEST_P(BIOMessageDigestTest, Basic) { // Write-through digest BIO bio_md.reset(BIO_new(BIO_f_md())); ASSERT_TRUE(bio_md); - EXPECT_TRUE(BIO_set_md(bio_md.get(), (void *)md)); + EXPECT_TRUE(BIO_set_md(bio_md.get(), md)); bio_mem.reset(BIO_new(BIO_s_mem())); ASSERT_TRUE(bio_mem); bio.reset(BIO_push(bio_md.get(), bio_mem.get())); @@ -126,7 +126,7 @@ TEST_P(BIOMessageDigestTest, Basic) { // Read-through digest BIO bio_md.reset(BIO_new(BIO_f_md())); ASSERT_TRUE(bio_md); - EXPECT_TRUE(BIO_set_md(bio_md.get(), (void *)md)); + EXPECT_TRUE(BIO_set_md(bio_md.get(), md)); bio_mem.reset(BIO_new_mem_buf(message, sizeof(message))); ASSERT_TRUE(bio_mem); bio.reset(BIO_push(bio_md.get(), bio_mem.get())); @@ -208,7 +208,7 @@ TEST_P(BIOMessageDigestTest, Randomized) { // Write-through digest BIO, check against expectation bio_md.reset(BIO_new(BIO_f_md())); ASSERT_TRUE(bio_md); - EXPECT_TRUE(BIO_set_md(bio_md.get(), (void *)md)); + EXPECT_TRUE(BIO_set_md(bio_md.get(), md)); bio_mem.reset(BIO_new(BIO_s_mem())); ASSERT_TRUE(bio_mem); bio.reset(BIO_push(bio_md.get(), bio_mem.get())); @@ -232,7 +232,7 @@ TEST_P(BIOMessageDigestTest, Randomized) { // Read-through digest BIO, check against expectation bio_md.reset(BIO_new(BIO_f_md())); ASSERT_TRUE(bio_md); - EXPECT_TRUE(BIO_set_md(bio_md.get(), (void *)md)); + EXPECT_TRUE(BIO_set_md(bio_md.get(), md)); bio_mem.reset(BIO_new_mem_buf(message.data(), message.size())); ASSERT_TRUE(bio_mem); bio.reset(BIO_push(bio_md.get(), bio_mem.get())); diff --git a/crypto/pkcs7/bio/cipher.c b/crypto/pkcs7/bio/cipher.c index e08f7ea8cc..8950a6ceff 100644 --- a/crypto/pkcs7/bio/cipher.c +++ b/crypto/pkcs7/bio/cipher.c @@ -322,3 +322,7 @@ static const BIO_METHOD methods_enc = { }; const BIO_METHOD *BIO_f_cipher(void) { return &methods_enc; } + +int BIO_get_cipher_ctx(BIO *b, EVP_CIPHER_CTX **ctx) { + return BIO_ctrl(b, BIO_C_GET_CIPHER_CTX, 0, ctx); +} \ No newline at end of file diff --git a/crypto/pkcs7/bio/md.c b/crypto/pkcs7/bio/md.c index d233939ab3..8b5489e130 100644 --- a/crypto/pkcs7/bio/md.c +++ b/crypto/pkcs7/bio/md.c @@ -171,3 +171,11 @@ static const BIO_METHOD methods_md = { }; const BIO_METHOD *BIO_f_md(void) { return &methods_md; } + +int BIO_get_md_ctx(BIO *b, EVP_MD_CTX **ctx) { + return BIO_ctrl(b, BIO_C_GET_MD_CTX, 0, ctx); +} + +int BIO_set_md(BIO *b, const EVP_MD *md) { + return BIO_ctrl(b, BIO_C_SET_MD, 0, (EVP_MD*)md); +} diff --git a/crypto/pkcs7/internal.h b/crypto/pkcs7/internal.h index e6015ff9ea..a59f01f3c2 100644 --- a/crypto/pkcs7/internal.h +++ b/crypto/pkcs7/internal.h @@ -204,26 +204,25 @@ int pkcs7_add_signed_data(CBB *out, // |BIO_get_md_ctx| before it can be used. OPENSSL_EXPORT const BIO_METHOD *BIO_f_md(void); -// BIO_get_md_ctx writes a reference of |b|'s EVP_MD_CTX* to |*mdcp| -#define BIO_get_md_ctx(b, mdcp) BIO_ctrl(b, BIO_C_GET_MD_CTX, 0, mdcp) +// BIO_get_md_ctx writes a reference of |b|'s EVP_MD_CTX* to |*ctx| +OPENSSL_EXPORT int BIO_get_md_ctx(BIO *b, EVP_MD_CTX **ctx); // BIO_set_md set's |b|'s EVP_MD* to |md| -#define BIO_set_md(b, md) BIO_ctrl(b, BIO_C_SET_MD, 0, md) +OPENSSL_EXPORT int BIO_set_md(BIO *b, const EVP_MD *md); // BIO_f_cipher is used internally by the pkcs7 module. It is not recommended // for external use. OPENSSL_EXPORT const BIO_METHOD *BIO_f_cipher(void); +// BIO_get_cipher_ctx writes a reference of |b|'s EVP_CIPHER_CTX* to |*ctx| +int BIO_get_cipher_ctx(BIO *b, EVP_CIPHER_CTX **ctx); + // BIO_set_cipher is used internally for testing. It is not recommended for // external use. OPENSSL_EXPORT int BIO_set_cipher(BIO *b, const EVP_CIPHER *cipher, const unsigned char *key, const unsigned char *iv, int enc); -#define BIO_get_cipher_ctx(bio, contents) BIO_ctrl(bio, BIO_C_GET_CIPHER_CTX, 0, \ - (char *)(contents)) - - #if defined(__cplusplus) } // extern C #endif