aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQu Wenruo <wqu@suse.com>2022-02-02 12:29:29 +0800
committerEryu Guan <guaneryu@gmail.com>2022-02-20 23:40:19 +0800
commit11342071e1054c65a28d32f3c6ab63c4bd6ef5a6 (patch)
tree3a1fd479a7b53729e30a3ce3e93faf23e17b1048
parentb91862aa4c950e0157f241136207e3827cee407e (diff)
downloadxfstests-dev-11342071e1054c65a28d32f3c6ab63c4bd6ef5a6.tar.gz
src/fssum: use newer EVP_* interface to replace deprecated MD5_* interace
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@suse.com> Reviewed-by: Eryu Guan <guaneryu@gmail.com> Signed-off-by: Eryu Guan <guaneryu@gmail.com>
-rw-r--r--src/fssum.c23
-rw-r--r--src/md5.h2
2 files changed, 24 insertions, 1 deletions
diff --git a/src/fssum.c b/src/fssum.c
index 3d97a70bf0..390bfde02c 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 2da44bf355..07c03ca304 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