In OpenSSL 3.0, MD_Init/Update/Final() interfaces are marked deprecated, and we have to go EVP_DigestInit/Update/Final() instead. Personally I'm not a fan of this, especially the new EVP_MD_CTX structure can no longer be stack allocated, thus we have to dynamically allocate and free EVP_MD_CTX in sum_init() and sum_free(). Hopes this is proper way to go and would solve the problem until OpenSSL chooses to change their interface again. Signed-off-by: Qu Wenruo <wqu@xxxxxxxx> --- src/fssum.c | 23 +++++++++++++++++++++++ src/md5.h | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/fssum.c b/src/fssum.c index 3d97a70bf02f..390bfde02c7d 100644 --- a/src/fssum.c +++ b/src/fssum.c @@ -48,7 +48,11 @@ struct excludes { }; typedef struct _sum { +#ifdef HAVE_OPENSSL + EVP_MD_CTX *ctx; +#else MD5_CTX md5; +#endif unsigned char out[16]; } sum_t; @@ -175,19 +179,38 @@ alloc(size_t sz) void sum_init(sum_t *cs) { +#ifdef HAVE_OPENSSL + cs->ctx = EVP_MD_CTX_new(); + if (!cs->ctx) { + fprintf(stderr, "evp md ctx allocation failed\n"); + exit(-1); + } + EVP_DigestInit(cs->ctx, EVP_md5()); +#else MD5_Init(&cs->md5); +#endif } void sum_fini(sum_t *cs) { +#ifdef HAVE_OPENSSL + EVP_DigestFinal(cs->ctx, cs->out, NULL); + EVP_MD_CTX_free(cs->ctx); + cs->ctx = NULL; +#else MD5_Final(cs->out, &cs->md5); +#endif } void sum_add(sum_t *cs, void *buf, int size) { +#ifdef HAVE_OPENSSL + EVP_DigestUpdate(cs->ctx, buf, size); +#else MD5_Update(&cs->md5, buf, size); +#endif } void diff --git a/src/md5.h b/src/md5.h index 2da44bf355a3..07c03ca304df 100644 --- a/src/md5.h +++ b/src/md5.h @@ -24,7 +24,7 @@ */ #ifdef HAVE_OPENSSL -#include <openssl/md5.h> +#include <openssl/evp.h> #elif !defined(_MD5_H) #define _MD5_H -- 2.35.0