]> git.apps.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
src/fssum: use newer EVP_* interface to replace deprecated MD5_* interace
authorQu Wenruo <wqu@suse.com>
Wed, 2 Feb 2022 04:29:29 +0000 (12:29 +0800)
committerEryu Guan <guaneryu@gmail.com>
Sun, 20 Feb 2022 15:40:19 +0000 (23:40 +0800)
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>
src/fssum.c
src/md5.h

index 3d97a70bf02f1f87a436d647fbf62f8998f0cb5a..390bfde02c7da5212596270a62fb751221bc7148 100644 (file)
@@ -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
index 2da44bf355a3a00b5abd283792e53efad339b1f3..07c03ca304dfedd69b37d6f61d1d18a6dbee3ae6 100644 (file)
--- 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