erofs-utils: prefer using OpenSSL for SHA256
PATCH 1/1 erofs-utils: prefer using OpenSSL for SHA256
Since OpenSSL supports hardware or SIMD acceleration on some platforms.
Signed-off-by Gao Xiang <[email protected]>
--- configure.ac | 1 + dump/Makefile.am | 2 +- fsck/Makefile.am | 4 ++-- lib/sha256.c | 27 +++++++++++++++++++++++++++ lib/sha256.h | 8 ++++++++ 5 files changed, 39 insertions(+), 3 deletions(-)
configure.ac +1 -0
@@ -641,6 +641,7 @@ AS_IF([test "x$with_openssl" != "xno"], [ #include <openssl/hmac.h> ]]) ]) + AC_CHECK_HEADERS([openssl/sha.h],[],[]) LIBS="${saved_LIBS}" CPPFLAGS="${saved_CPPFLAGS}"], [ AS_IF([test "x$with_openssl" = "xyes"], [
dump/Makefile.am +1 -1
@@ -8,4 +8,4 @@ dump_erofs_SOURCES = main.c dump_erofs_CFLAGS = -Wall -I$(top_srcdir)/include dump_erofs_LDADD = $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} \ ${liblz4_LIBS} ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS} \ - ${libzstd_LIBS} ${libqpl_LIBS} ${libxxhash_LIBS} + ${libzstd_LIBS} ${libqpl_LIBS} ${libxxhash_LIBS} ${openssl_LIBS}
fsck/Makefile.am +2 -2
@@ -8,7 +8,7 @@ fsck_erofs_SOURCES = main.c fsck_erofs_CFLAGS = -Wall -I$(top_srcdir)/include fsck_erofs_LDADD = $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} \ ${liblz4_LIBS} ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS} \ - ${libzstd_LIBS} ${libqpl_LIBS} ${libxxhash_LIBS} + ${libzstd_LIBS} ${libqpl_LIBS} ${libxxhash_LIBS} ${openssl_LIBS} if ENABLE_FUZZING noinst_PROGRAMS = fuzz_erofsfsck
@@ -17,5 +17,5 @@ fuzz_erofsfsck_CFLAGS = -Wall -I$(top_srcdir)/include -DFUZZING fuzz_erofsfsck_LDFLAGS = -fsanitize=address,fuzzer fuzz_erofsfsck_LDADD = $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} \ ${liblz4_LIBS} ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS} \ - ${libzstd_LIBS} ${libqpl_LIBS} ${libxxhash_LIBS} + ${libzstd_LIBS} ${libqpl_LIBS} ${libxxhash_LIBS} ${openssl_LIBS} endif
lib/sha256.c +27 -0
@@ -7,6 +7,32 @@#include "sha256.h" #include <string.h> +#ifdef __USE_OPENSSL_SHA256 +void erofs_sha256_init (struct sha256_state *md) +{ +int ret; + + ret =SHA256_Init (&md->ctx); +DBG_BUGON (ret !=1 ); +} + +int erofs_sha256_process (struct sha256_state *md, +const unsigned char *in,unsigned long inlen) +{ +int ret; + + ret =SHA256_Update (&md->ctx, in, inlen); +return (ret ==1 ) -1 ; +} + +int erofs_sha256_done (struct sha256_state *md,unsigned char *out) +{ +int ret; + + ret =SHA256_Final (out, &md->ctx); +return (ret ==1 ) -1 ; +} +#else /* This is based on SHA256 implementation in LibTomCrypt that was released into * public domain by Tom St Denis. */ /* the K array */
@@ -186,6 +212,7 @@ int erofs_sha256_done(struct sha256_state *md, unsigned char *out)STORE32H (md->state[i], out + (4 * i)); return 0; } +#endif void erofs_sha256 (const unsigned char *in,unsigned long in_size,unsigned char out[32 ])
lib/sha256.h +8 -0
@@ -4,11 +4,19 @@#include "erofs/defs.h" +#if defined(HAVE_OPENSSL ) && defined(HAVE_OPENSSL_SHA_H ) +#include <openssl/sha.h> +struct sha256_state { +SHA256_CTX ctx; +}; +#define __USE_OPENSSL_SHA256 +#else struct sha256_state {u64 length;u32 state[8 ], curlen;u8 buf[64 ]; }; +#endif void erofs_sha256_init (struct sha256_state *md); int erofs_sha256_process(struct sha256_state *md,
Signature · 1 line
2.43.5
PATCH v2 1/1 erofs-utils: prefer using OpenSSL for SHA256
Since some architectures support hardware or SIMD acceleration.
Signed-off-by Gao Xiang <[email protected]>
---
v2:
- avoid deprecated SHA256_{Init,Update,Final} (OpenSSL 3.0+).
configure.ac | 1 + dump/Makefile.am | 2 +- fsck/Makefile.am | 4 ++-- lib/sha256.c | 41 +++++++++++++++++++++++++++++++++++++++++ lib/sha256.h | 8 ++++++++ 5 files changed, 53 insertions(+), 3 deletions(-)
configure.ac +1 -0
@@ -641,6 +641,7 @@ AS_IF([test "x$with_openssl" != "xno"], [ #include <openssl/hmac.h> ]]) ]) + AC_CHECK_HEADERS([openssl/evp.h],[],[]) LIBS="${saved_LIBS}" CPPFLAGS="${saved_CPPFLAGS}"], [ AS_IF([test "x$with_openssl" = "xyes"], [
dump/Makefile.am +1 -1
@@ -8,4 +8,4 @@ dump_erofs_SOURCES = main.c dump_erofs_CFLAGS = -Wall -I$(top_srcdir)/include dump_erofs_LDADD = $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} \ ${liblz4_LIBS} ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS} \ - ${libzstd_LIBS} ${libqpl_LIBS} ${libxxhash_LIBS} + ${libzstd_LIBS} ${libqpl_LIBS} ${libxxhash_LIBS} ${openssl_LIBS}
fsck/Makefile.am +2 -2
@@ -8,7 +8,7 @@ fsck_erofs_SOURCES = main.c fsck_erofs_CFLAGS = -Wall -I$(top_srcdir)/include fsck_erofs_LDADD = $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} \ ${liblz4_LIBS} ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS} \ - ${libzstd_LIBS} ${libqpl_LIBS} ${libxxhash_LIBS} + ${libzstd_LIBS} ${libqpl_LIBS} ${libxxhash_LIBS} ${openssl_LIBS} if ENABLE_FUZZING noinst_PROGRAMS = fuzz_erofsfsck
@@ -17,5 +17,5 @@ fuzz_erofsfsck_CFLAGS = -Wall -I$(top_srcdir)/include -DFUZZING fuzz_erofsfsck_LDFLAGS = -fsanitize=address,fuzzer fuzz_erofsfsck_LDADD = $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} \ ${liblz4_LIBS} ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS} \ - ${libzstd_LIBS} ${libqpl_LIBS} ${libxxhash_LIBS} + ${libzstd_LIBS} ${libqpl_LIBS} ${libxxhash_LIBS} ${openssl_LIBS} endif
lib/sha256.c +41 -0
59 lines not on this page · raw message
lib/sha256.h +8 -0
@@ -4,11 +4,19 @@#include "erofs/defs.h" +#if defined(HAVE_OPENSSL ) && defined(HAVE_OPENSSL_EVP_H ) +#include <openssl/evp.h> +struct sha256_state { +EVP_MD_CTX *ctx; +}; +#define __USE_OPENSSL_SHA256 +#else struct sha256_state {u64 length;u32 state[8 ], curlen;u8 buf[64 ]; }; +#endif void erofs_sha256_init (struct sha256_state *md); int erofs_sha256_process(struct sha256_state *md,
Signature · 1 line
2.43.5
PATCH v3 1/1 erofs-utils: prefer using OpenSSL for SHA256
Since some architectures support hardware or SIMD acceleration.
Signed-off-by Gao Xiang <[email protected]>
---
v3:
- fix erofsfuse compile error.
configure.ac | 1 + dump/Makefile.am | 2 +- fsck/Makefile.am | 4 ++-- fuse/Makefile.am | 2 +- lib/sha256.c | 41 +++++++++++++++++++++++++++++++++++++++++ lib/sha256.h | 8 ++++++++ 6 files changed, 54 insertions(+), 4 deletions(-)
configure.ac +1 -0
@@ -641,6 +641,7 @@ AS_IF([test "x$with_openssl" != "xno"], [ #include <openssl/hmac.h> ]]) ]) + AC_CHECK_HEADERS([openssl/evp.h],[],[]) LIBS="${saved_LIBS}" CPPFLAGS="${saved_CPPFLAGS}"], [ AS_IF([test "x$with_openssl" = "xyes"], [
dump/Makefile.am +1 -1
@@ -8,4 +8,4 @@ dump_erofs_SOURCES = main.c dump_erofs_CFLAGS = -Wall -I$(top_srcdir)/include dump_erofs_LDADD = $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} \ ${liblz4_LIBS} ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS} \ - ${libzstd_LIBS} ${libqpl_LIBS} ${libxxhash_LIBS} + ${libzstd_LIBS} ${libqpl_LIBS} ${libxxhash_LIBS} ${openssl_LIBS}
fsck/Makefile.am +2 -2
@@ -8,7 +8,7 @@ fsck_erofs_SOURCES = main.c fsck_erofs_CFLAGS = -Wall -I$(top_srcdir)/include fsck_erofs_LDADD = $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} \ ${liblz4_LIBS} ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS} \ - ${libzstd_LIBS} ${libqpl_LIBS} ${libxxhash_LIBS} + ${libzstd_LIBS} ${libqpl_LIBS} ${libxxhash_LIBS} ${openssl_LIBS} if ENABLE_FUZZING noinst_PROGRAMS = fuzz_erofsfsck
@@ -17,5 +17,5 @@ fuzz_erofsfsck_CFLAGS = -Wall -I$(top_srcdir)/include -DFUZZING fuzz_erofsfsck_LDFLAGS = -fsanitize=address,fuzzer fuzz_erofsfsck_LDADD = $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} \ ${liblz4_LIBS} ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS} \ - ${libzstd_LIBS} ${libqpl_LIBS} ${libxxhash_LIBS} + ${libzstd_LIBS} ${libqpl_LIBS} ${libxxhash_LIBS} ${openssl_LIBS} endif
fuse/Makefile.am +1 -1
@@ -8,7 +8,7 @@ erofsfuse_CFLAGS = -Wall -I$(top_srcdir)/include erofsfuse_CFLAGS += ${libfuse2_CFLAGS} ${libfuse3_CFLAGS} ${libselinux_CFLAGS} erofsfuse_LDADD = $(top_builddir)/lib/liberofs.la ${libfuse2_LIBS} ${libfuse3_LIBS} ${liblz4_LIBS} \ ${libselinux_LIBS} ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS} ${libzstd_LIBS} \ - ${libqpl_LIBS} ${libxxhash_LIBS} + ${libqpl_LIBS} ${libxxhash_LIBS} ${openssl_LIBS} if ENABLE_STATIC_FUSE lib_LTLIBRARIES = liberofsfuse.la
lib/sha256.c +41 -0
59 lines not on this page · raw message
lib/sha256.h +8 -0
@@ -4,11 +4,19 @@#include "erofs/defs.h" +#if defined(HAVE_OPENSSL ) && defined(HAVE_OPENSSL_EVP_H ) +#include <openssl/evp.h> +struct sha256_state { +EVP_MD_CTX *ctx; +}; +#define __USE_OPENSSL_SHA256 +#else struct sha256_state {u64 length;u32 state[8 ], curlen;u8 buf[64 ]; }; +#endif void erofs_sha256_init (struct sha256_state *md); int erofs_sha256_process(struct sha256_state *md,
Signature · 1 line
2.43.5