commit:     dcab7ec282cfb8827a95c59c51322271d14d91c4
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sat May 16 18:24:45 2020 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sat May 16 18:24:45 2020 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=dcab7ec2

libq/hash: unify hash methods into single approach

remove duplicate hashing strategies, use private copies of md5 and sha1
hashes when ssl is not available, else rely on ssl to provide hashing
capabilities

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 Makefile.am                         |  11 +--
 Makefile.in                         |  50 +++++------
 libq/Makefile.am                    |   8 +-
 libq/Makefile.in                    |  93 ++++++++------------
 libq/hash.c                         | 165 +++++++++++++++++++++++++++++++++---
 libq/hash.h                         |  34 ++++++--
 libq/hash_fd.h                      |  13 ---
 libq/{hash_fd.c => hash_md5_sha1.c} | 125 ++-------------------------
 libq/hash_md5_sha1.h                |  35 ++++++++
 libq/md5_sha1_sum.c                 |  93 --------------------
 libq/md5_sha1_sum.h                 |  24 ------
 qcheck.c                            |  10 +--
 qmerge.c                            |  14 ++-
 qpkg.c                              |   7 +-
 14 files changed, 301 insertions(+), 381 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 3107bda..ceded24 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -69,10 +69,12 @@ q_CPPFLAGS = \
        -I$(top_srcdir)/libq \
        -I$(top_builddir)/autotools/gnulib \
        -I$(top_srcdir)/autotools/gnulib \
+       $(OPENMP_CFLAGS) \
        $(NULL)
 q_LDADD = \
        $(top_builddir)/libq/libq.la \
        $(top_builddir)/autotools/gnulib/libgnu.a \
+       $(OPENMP_CFLAGS) \
        $(LIBSSL) \
        $(LIBBL2) \
        $(LIBZ) \
@@ -84,21 +86,12 @@ q_LDADD = \
 if QMANIFEST_ENABLED
 q_SOURCES += qmanifest.c
 q_CPPFLAGS += \
-       $(OPENMP_CFLAGS) \
        $(GPGME_CFLAGS)
-q_LDADD += \
-       $(OPENMP_CFLAGS)
 dist_man_MANS += man/qmanifest.1
 APPLETS += qmanifest
 endif
 if QTEGRITY_ENABLED
 q_SOURCES += qtegrity.c
-if !QMANIFEST_ENABLED
-q_CPPFLAGS += \
-       $(OPENMP_CFLAGS)
-q_LDADD += \
-       $(OPENMP_CFLAGS)
-endif
 dist_man_MANS += man/qtegrity.1
 APPLETS += qtegrity
 endif

diff --git a/Makefile.in b/Makefile.in
index 7403b5b..91d9a3b 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -91,23 +91,13 @@ host_triplet = @host@
 bin_PROGRAMS = q$(EXEEXT)
 @QMANIFEST_ENABLED_TRUE@am__append_1 = qmanifest.c
 @QMANIFEST_ENABLED_TRUE@am__append_2 = \
-@QMANIFEST_ENABLED_TRUE@       $(OPENMP_CFLAGS) \
 @QMANIFEST_ENABLED_TRUE@       $(GPGME_CFLAGS)
 
-@QMANIFEST_ENABLED_TRUE@am__append_3 = \
-@QMANIFEST_ENABLED_TRUE@       $(OPENMP_CFLAGS)
-
-@QMANIFEST_ENABLED_TRUE@am__append_4 = man/qmanifest.1
-@QMANIFEST_ENABLED_TRUE@am__append_5 = qmanifest
-@QTEGRITY_ENABLED_TRUE@am__append_6 = qtegrity.c
-@QMANIFEST_ENABLED_FALSE@@QTEGRITY_ENABLED_TRUE@am__append_7 = \
-@QMANIFEST_ENABLED_FALSE@@QTEGRITY_ENABLED_TRUE@       $(OPENMP_CFLAGS)
-
-@QMANIFEST_ENABLED_FALSE@@QTEGRITY_ENABLED_TRUE@am__append_8 = \
-@QMANIFEST_ENABLED_FALSE@@QTEGRITY_ENABLED_TRUE@       $(OPENMP_CFLAGS)
-
-@QTEGRITY_ENABLED_TRUE@am__append_9 = man/qtegrity.1
-@QTEGRITY_ENABLED_TRUE@am__append_10 = qtegrity
+@QMANIFEST_ENABLED_TRUE@am__append_3 = man/qmanifest.1
+@QMANIFEST_ENABLED_TRUE@am__append_4 = qmanifest
+@QTEGRITY_ENABLED_TRUE@am__append_5 = qtegrity.c
+@QTEGRITY_ENABLED_TRUE@am__append_6 = man/qtegrity.1
+@QTEGRITY_ENABLED_TRUE@am__append_7 = qtegrity
 subdir = .
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/autotools/m4/00gnulib.m4 \
@@ -278,14 +268,12 @@ am_q_OBJECTS = q-main.$(OBJEXT) q-q.$(OBJEXT) 
q-qatom.$(OBJEXT) \
        $(am__objects_2)
 q_OBJECTS = $(am_q_OBJECTS)
 am__DEPENDENCIES_1 =
-@QMANIFEST_ENABLED_TRUE@am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1)
-@QMANIFEST_ENABLED_FALSE@@QTEGRITY_ENABLED_TRUE@am__DEPENDENCIES_3 = 
$(am__DEPENDENCIES_1)
 q_DEPENDENCIES = $(top_builddir)/libq/libq.la \
        $(top_builddir)/autotools/gnulib/libgnu.a \
        $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
        $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
        $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
-       $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_3)
+       $(am__DEPENDENCIES_1)
 AM_V_lt = $(am__v_lt_@AM_V@)
 am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
 am__v_lt_0 = --silent
@@ -1598,21 +1586,29 @@ SUBDIRS = \
 
 APPLETS = q qatom qcheck qdepends qfile qgrep qkeyword qlist qlop \
        qmerge qpkg qsearch qsize qtbz2 quse qxpak $(NULL) \
-       $(am__append_5) $(am__append_10)
+       $(am__append_4) $(am__append_7)
 dist_man_MANS = man/q.1 man/qatom.1 man/qcheck.1 man/qdepends.1 \
        man/qfile.1 man/qgrep.1 man/qkeyword.1 man/qlist.1 man/qlop.1 \
        man/qmerge.1 man/qpkg.1 man/qsearch.1 man/qsize.1 man/qtbz2.1 \
-       man/quse.1 man/qxpak.1 $(NULL) $(am__append_4) $(am__append_9)
+       man/quse.1 man/qxpak.1 $(NULL) $(am__append_3) $(am__append_6)
 q_SOURCES = main.c q.c qatom.c qcheck.c qdepends.c qfile.c qgrep.c \
        qkeyword.c qlist.c qlop.c qmerge.c qpkg.c qsearch.c qsize.c \
-       qtbz2.c quse.c qxpak.c $(NULL) $(am__append_1) $(am__append_6)
+       qtbz2.c quse.c qxpak.c $(NULL) $(am__append_1) $(am__append_5)
 q_CPPFLAGS = -I$(top_srcdir)/libq -I$(top_builddir)/autotools/gnulib \
-       -I$(top_srcdir)/autotools/gnulib $(NULL) $(am__append_2) \
-       $(am__append_7)
-q_LDADD = $(top_builddir)/libq/libq.la \
-       $(top_builddir)/autotools/gnulib/libgnu.a $(LIBSSL) $(LIBBL2) \
-       $(LIBZ) $(GPGME_LIBS) $(LIB_CLOCK_GETTIME) $(LIB_EACCESS) \
-       $(NULL) $(am__append_3) $(am__append_8)
+       -I$(top_srcdir)/autotools/gnulib $(OPENMP_CFLAGS) $(NULL) \
+       $(am__append_2)
+q_LDADD = \
+       $(top_builddir)/libq/libq.la \
+       $(top_builddir)/autotools/gnulib/libgnu.a \
+       $(OPENMP_CFLAGS) \
+       $(LIBSSL) \
+       $(LIBBL2) \
+       $(LIBZ) \
+       $(GPGME_LIBS) \
+       $(LIB_CLOCK_GETTIME) \
+       $(LIB_EACCESS) \
+       $(NULL)
+
 EXTRA_DIST = \
        autotools/m4/gnulib-cache.m4 \
        applets.h \

diff --git a/libq/Makefile.am b/libq/Makefile.am
index 9cb19a2..da100b6 100644
--- a/libq/Makefile.am
+++ b/libq/Makefile.am
@@ -9,10 +9,8 @@ QFILES = \
        dep.c dep.h \
        eat_file.c eat_file.h \
        hash.c hash.h \
-       hash_fd.c hash_fd.h \
        human_readable.c human_readable.h \
        i18n.h \
-       md5_sha1_sum.c md5_sha1_sum.h \
        prelink.c prelink.h \
        profile.c profile.h \
        rmspace.c rmspace.h \
@@ -29,6 +27,12 @@ QFILES = \
        xsystem.c xsystem.h \
        $(NULL)
 
+if !QMANIFEST_ENABLED
+if !QTEGRITY_ENABLED
+QFILES += hash_md5_sha1.c hash_md5_sha1.h
+endif
+endif
+
 noinst_LTLIBRARIES = libq.la
 libq_la_SOURCES = $(QFILES)
 libq_la_CPPFLAGS = \

diff --git a/libq/Makefile.in b/libq/Makefile.in
index cb5fa51..696d469 100644
--- a/libq/Makefile.in
+++ b/libq/Makefile.in
@@ -88,6 +88,7 @@ PRE_UNINSTALL = :
 POST_UNINSTALL = :
 build_triplet = @build@
 host_triplet = @host@
+@QMANIFEST_ENABLED_FALSE@@QTEGRITY_ENABLED_FALSE@am__append_1 = 
hash_md5_sha1.c hash_md5_sha1.h
 subdir = libq
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/autotools/m4/00gnulib.m4 \
@@ -241,16 +242,25 @@ CONFIG_CLEAN_FILES =
 CONFIG_CLEAN_VPATH_FILES =
 LTLIBRARIES = $(noinst_LTLIBRARIES)
 libq_la_LIBADD =
-am__objects_1 = libq_la-atom.lo libq_la-basename.lo libq_la-colors.lo \
+am__libq_la_SOURCES_DIST = atom.c atom.h basename.c basename.h \
+       busybox.h colors.c colors.h contents.c contents.h copy_file.c \
+       copy_file.h dep.c dep.h eat_file.c eat_file.h hash.c hash.h \
+       human_readable.c human_readable.h i18n.h prelink.c prelink.h \
+       profile.c profile.h rmspace.c rmspace.h safe_io.c safe_io.h \
+       scandirat.c scandirat.h set.c set.h tree.c tree.h xarray.c \
+       xarray.h xasprintf.h xchdir.c xchdir.h xmkdir.c xmkdir.h \
+       xpak.c xpak.h xregex.c xregex.h xsystem.c xsystem.h \
+       hash_md5_sha1.c hash_md5_sha1.h
+@QMANIFEST_ENABLED_FALSE@@QTEGRITY_ENABLED_FALSE@am__objects_1 = 
libq_la-hash_md5_sha1.lo
+am__objects_2 = libq_la-atom.lo libq_la-basename.lo libq_la-colors.lo \
        libq_la-contents.lo libq_la-copy_file.lo libq_la-dep.lo \
-       libq_la-eat_file.lo libq_la-hash.lo libq_la-hash_fd.lo \
-       libq_la-human_readable.lo libq_la-md5_sha1_sum.lo \
+       libq_la-eat_file.lo libq_la-hash.lo libq_la-human_readable.lo \
        libq_la-prelink.lo libq_la-profile.lo libq_la-rmspace.lo \
        libq_la-safe_io.lo libq_la-scandirat.lo libq_la-set.lo \
        libq_la-tree.lo libq_la-xarray.lo libq_la-xchdir.lo \
        libq_la-xmkdir.lo libq_la-xpak.lo libq_la-xregex.lo \
-       libq_la-xsystem.lo
-am_libq_la_OBJECTS = $(am__objects_1)
+       libq_la-xsystem.lo $(am__objects_1)
+am_libq_la_OBJECTS = $(am__objects_2)
 libq_la_OBJECTS = $(am_libq_la_OBJECTS)
 AM_V_lt = $(am__v_lt_@AM_V@)
 am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
@@ -277,9 +287,8 @@ am__depfiles_remade = ./$(DEPDIR)/libq_la-atom.Plo \
        ./$(DEPDIR)/libq_la-contents.Plo \
        ./$(DEPDIR)/libq_la-copy_file.Plo ./$(DEPDIR)/libq_la-dep.Plo \
        ./$(DEPDIR)/libq_la-eat_file.Plo ./$(DEPDIR)/libq_la-hash.Plo \
-       ./$(DEPDIR)/libq_la-hash_fd.Plo \
+       ./$(DEPDIR)/libq_la-hash_md5_sha1.Plo \
        ./$(DEPDIR)/libq_la-human_readable.Plo \
-       ./$(DEPDIR)/libq_la-md5_sha1_sum.Plo \
        ./$(DEPDIR)/libq_la-prelink.Plo \
        ./$(DEPDIR)/libq_la-profile.Plo \
        ./$(DEPDIR)/libq_la-rmspace.Plo \
@@ -309,7 +318,7 @@ am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
 am__v_CCLD_0 = @echo "  CCLD    " $@;
 am__v_CCLD_1 = 
 SOURCES = $(libq_la_SOURCES)
-DIST_SOURCES = $(libq_la_SOURCES)
+DIST_SOURCES = $(am__libq_la_SOURCES_DIST)
 am__can_run_installinfo = \
   case $$AM_UPDATE_INFO_DIR in \
     n|no|NO) false;; \
@@ -1470,36 +1479,14 @@ target_alias = @target_alias@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
-QFILES = \
-       atom.c atom.h \
-       basename.c basename.h \
-       busybox.h \
-       colors.c colors.h \
-       contents.c contents.h \
-       copy_file.c copy_file.h \
-       dep.c dep.h \
-       eat_file.c eat_file.h \
-       hash.c hash.h \
-       hash_fd.c hash_fd.h \
-       human_readable.c human_readable.h \
-       i18n.h \
-       md5_sha1_sum.c md5_sha1_sum.h \
-       prelink.c prelink.h \
-       profile.c profile.h \
-       rmspace.c rmspace.h \
-       safe_io.c safe_io.h \
-       scandirat.c scandirat.h \
-       set.c set.h \
-       tree.c tree.h \
-       xarray.c xarray.h \
-       xasprintf.h \
-       xchdir.c xchdir.h \
-       xmkdir.c xmkdir.h \
-       xpak.c xpak.h \
-       xregex.c xregex.h \
-       xsystem.c xsystem.h \
-       $(NULL)
-
+QFILES = atom.c atom.h basename.c basename.h busybox.h colors.c \
+       colors.h contents.c contents.h copy_file.c copy_file.h dep.c \
+       dep.h eat_file.c eat_file.h hash.c hash.h human_readable.c \
+       human_readable.h i18n.h prelink.c prelink.h profile.c \
+       profile.h rmspace.c rmspace.h safe_io.c safe_io.h scandirat.c \
+       scandirat.h set.c set.h tree.c tree.h xarray.c xarray.h \
+       xasprintf.h xchdir.c xchdir.h xmkdir.c xmkdir.h xpak.c xpak.h \
+       xregex.c xregex.h xsystem.c xsystem.h $(NULL) $(am__append_1)
 noinst_LTLIBRARIES = libq.la
 libq_la_SOURCES = $(QFILES)
 libq_la_CPPFLAGS = \
@@ -1569,9 +1556,8 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-dep.Plo@am__quote@ # 
am--include-marker
 @AMDEP_TRUE@@am__include@ 
@am__quote@./$(DEPDIR)/libq_la-eat_file.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-hash.Plo@am__quote@ # 
am--include-marker
-@AMDEP_TRUE@@am__include@ 
@am__quote@./$(DEPDIR)/libq_la-hash_fd.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ 
@am__quote@./$(DEPDIR)/libq_la-hash_md5_sha1.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ 
@am__quote@./$(DEPDIR)/libq_la-human_readable.Plo@am__quote@ # 
am--include-marker
-@AMDEP_TRUE@@am__include@ 
@am__quote@./$(DEPDIR)/libq_la-md5_sha1_sum.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ 
@am__quote@./$(DEPDIR)/libq_la-prelink.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ 
@am__quote@./$(DEPDIR)/libq_la-profile.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ 
@am__quote@./$(DEPDIR)/libq_la-rmspace.Plo@am__quote@ # am--include-marker
@@ -1669,13 +1655,6 @@ libq_la-hash.lo: hash.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) 
$(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC 
$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) 
$(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) 
$(CFLAGS) -c -o libq_la-hash.lo `test -f 'hash.c' || echo '$(srcdir)/'`hash.c
 
-libq_la-hash_fd.lo: hash_fd.c
-@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC 
$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) 
$(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) 
$(CFLAGS) -MT libq_la-hash_fd.lo -MD -MP -MF $(DEPDIR)/libq_la-hash_fd.Tpo -c 
-o libq_la-hash_fd.lo `test -f 'hash_fd.c' || echo '$(srcdir)/'`hash_fd.c
-@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/libq_la-hash_fd.Tpo 
$(DEPDIR)/libq_la-hash_fd.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='hash_fd.c' 
object='libq_la-hash_fd.lo' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) 
$(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC 
$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) 
$(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) 
$(CFLAGS) -c -o libq_la-hash_fd.lo `test -f 'hash_fd.c' || echo 
'$(srcdir)/'`hash_fd.c
-
 libq_la-human_readable.lo: human_readable.c
 @am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC 
$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) 
$(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) 
$(CFLAGS) -MT libq_la-human_readable.lo -MD -MP -MF 
$(DEPDIR)/libq_la-human_readable.Tpo -c -o libq_la-human_readable.lo `test -f 
'human_readable.c' || echo '$(srcdir)/'`human_readable.c
 @am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) 
$(DEPDIR)/libq_la-human_readable.Tpo $(DEPDIR)/libq_la-human_readable.Plo
@@ -1683,13 +1662,6 @@ libq_la-human_readable.lo: human_readable.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) 
$(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC 
$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) 
$(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) 
$(CFLAGS) -c -o libq_la-human_readable.lo `test -f 'human_readable.c' || echo 
'$(srcdir)/'`human_readable.c
 
-libq_la-md5_sha1_sum.lo: md5_sha1_sum.c
-@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC 
$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) 
$(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) 
$(CFLAGS) -MT libq_la-md5_sha1_sum.lo -MD -MP -MF 
$(DEPDIR)/libq_la-md5_sha1_sum.Tpo -c -o libq_la-md5_sha1_sum.lo `test -f 
'md5_sha1_sum.c' || echo '$(srcdir)/'`md5_sha1_sum.c
-@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/libq_la-md5_sha1_sum.Tpo 
$(DEPDIR)/libq_la-md5_sha1_sum.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='md5_sha1_sum.c' 
object='libq_la-md5_sha1_sum.lo' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) 
$(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC 
$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) 
$(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) 
$(CFLAGS) -c -o libq_la-md5_sha1_sum.lo `test -f 'md5_sha1_sum.c' || echo 
'$(srcdir)/'`md5_sha1_sum.c
-
 libq_la-prelink.lo: prelink.c
 @am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC 
$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) 
$(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) 
$(CFLAGS) -MT libq_la-prelink.lo -MD -MP -MF $(DEPDIR)/libq_la-prelink.Tpo -c 
-o libq_la-prelink.lo `test -f 'prelink.c' || echo '$(srcdir)/'`prelink.c
 @am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/libq_la-prelink.Tpo 
$(DEPDIR)/libq_la-prelink.Plo
@@ -1781,6 +1753,13 @@ libq_la-xsystem.lo: xsystem.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) 
$(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC 
$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) 
$(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) 
$(CFLAGS) -c -o libq_la-xsystem.lo `test -f 'xsystem.c' || echo 
'$(srcdir)/'`xsystem.c
 
+libq_la-hash_md5_sha1.lo: hash_md5_sha1.c
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC 
$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) 
$(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) 
$(CFLAGS) -MT libq_la-hash_md5_sha1.lo -MD -MP -MF 
$(DEPDIR)/libq_la-hash_md5_sha1.Tpo -c -o libq_la-hash_md5_sha1.lo `test -f 
'hash_md5_sha1.c' || echo '$(srcdir)/'`hash_md5_sha1.c
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/libq_la-hash_md5_sha1.Tpo 
$(DEPDIR)/libq_la-hash_md5_sha1.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='hash_md5_sha1.c' 
object='libq_la-hash_md5_sha1.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) 
$(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC 
$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) 
$(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) 
$(CFLAGS) -c -o libq_la-hash_md5_sha1.lo `test -f 'hash_md5_sha1.c' || echo 
'$(srcdir)/'`hash_md5_sha1.c
+
 mostlyclean-libtool:
        -rm -f *.lo
 
@@ -1920,9 +1899,8 @@ distclean: distclean-am
        -rm -f ./$(DEPDIR)/libq_la-dep.Plo
        -rm -f ./$(DEPDIR)/libq_la-eat_file.Plo
        -rm -f ./$(DEPDIR)/libq_la-hash.Plo
-       -rm -f ./$(DEPDIR)/libq_la-hash_fd.Plo
+       -rm -f ./$(DEPDIR)/libq_la-hash_md5_sha1.Plo
        -rm -f ./$(DEPDIR)/libq_la-human_readable.Plo
-       -rm -f ./$(DEPDIR)/libq_la-md5_sha1_sum.Plo
        -rm -f ./$(DEPDIR)/libq_la-prelink.Plo
        -rm -f ./$(DEPDIR)/libq_la-profile.Plo
        -rm -f ./$(DEPDIR)/libq_la-rmspace.Plo
@@ -1989,9 +1967,8 @@ maintainer-clean: maintainer-clean-am
        -rm -f ./$(DEPDIR)/libq_la-dep.Plo
        -rm -f ./$(DEPDIR)/libq_la-eat_file.Plo
        -rm -f ./$(DEPDIR)/libq_la-hash.Plo
-       -rm -f ./$(DEPDIR)/libq_la-hash_fd.Plo
+       -rm -f ./$(DEPDIR)/libq_la-hash_md5_sha1.Plo
        -rm -f ./$(DEPDIR)/libq_la-human_readable.Plo
-       -rm -f ./$(DEPDIR)/libq_la-md5_sha1_sum.Plo
        -rm -f ./$(DEPDIR)/libq_la-prelink.Plo
        -rm -f ./$(DEPDIR)/libq_la-profile.Plo
        -rm -f ./$(DEPDIR)/libq_la-rmspace.Plo

diff --git a/libq/hash.c b/libq/hash.c
index 6d0a62b..a174a0c 100644
--- a/libq/hash.c
+++ b/libq/hash.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2018-2019 Gentoo Foundation
+ * Copyright 2018-2020 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2018-     Fabian Groffen  - <grob...@gentoo.org>
@@ -13,11 +13,14 @@
 #include "main.h"
 
 #ifdef HAVE_SSL
-#include <openssl/sha.h>
-#include <openssl/whrlpool.h>
+# include <openssl/md5.h>
+# include <openssl/sha.h>
+# include <openssl/whrlpool.h>
+#else
+# include "hash_md5_sha1.h"
 #endif
 #ifdef HAVE_BLAKE2B
-#include <blake2.h>
+# include <blake2.h>
 #endif
 
 #include "hash.h"
@@ -26,6 +29,28 @@ void
 hash_hex(char *out, const unsigned char *buf, const int length)
 {
        switch (length) {
+               /* MD5_DIGEST_LENGTH */
+               case 16:
+                       snprintf(out, 32 + 1,
+                                       
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
+                                       "%02x%02x%02x%02x%02x%02x",
+                                       buf[ 0], buf[ 1], buf[ 2], buf[ 3], 
buf[ 4],
+                                       buf[ 5], buf[ 6], buf[ 7], buf[ 8], 
buf[ 9],
+                                       buf[10], buf[11], buf[12], buf[13], 
buf[14],
+                                       buf[15]
+                                       );
+                       break;
+               /* SHA1_DIGEST_LENGTH */
+               case 20:
+                       snprintf(out, 40 + 1,
+                                       
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
+                                       
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
+                                       buf[ 0], buf[ 1], buf[ 2], buf[ 3], 
buf[ 4],
+                                       buf[ 5], buf[ 6], buf[ 7], buf[ 8], 
buf[ 9],
+                                       buf[10], buf[11], buf[12], buf[13], 
buf[14],
+                                       buf[15], buf[16], buf[17], buf[18], 
buf[19]
+                                       );
+                       break;
                /* SHA256_DIGEST_LENGTH */
                case 32:
                        snprintf(out, 64 + 1,
@@ -89,8 +114,10 @@ hash_hex(char *out, const unsigned char *buf, const int 
length)
  * the file pointed to by fname is returned in the flen argument.
  */
 void
-hash_compute_file(
-               const char *fname,
+hash_multiple_file_fd(
+               int fd,
+               char *md5,
+               char *sha1,
                char *sha256,
                char *sha512,
                char *whrlpl,
@@ -102,10 +129,14 @@ hash_compute_file(
        char data[8192];
        size_t len;
 #ifdef HAVE_SSL
+       MD5_CTX m5;
+       SHA_CTX s1;
        SHA256_CTX s256;
        SHA512_CTX s512;
        WHIRLPOOL_CTX whrl;
 #else
+       struct md5_ctx_t m5;
+       struct sha1_ctx_t s1;
        (void)sha256;
        (void)sha512;
        (void)whrlpl;
@@ -116,13 +147,18 @@ hash_compute_file(
        (void)blak2b;
 #endif
 
-       if ((f = fopen(fname, "r")) == NULL)
+       if ((f = fdopen(fd, "r")) == NULL)
                return;
 
 #ifdef HAVE_SSL
+       MD5_Init(&m5);
+       SHA1_Init(&s1);
        SHA256_Init(&s256);
        SHA512_Init(&s512);
        WHIRLPOOL_Init(&whrl);
+#else
+       md5_begin(&m5);
+       sha1_begin(&s1);
 #endif
 #ifdef HAVE_BLAKE2B
        blake2b_init(&bl2b, BLAKE2B_OUTBYTES);
@@ -130,10 +166,19 @@ hash_compute_file(
 
        while ((len = fread(data, 1, sizeof(data), f)) > 0) {
                *flen += len;
-#if defined(HAVE_SSL) || defined(HAVE_BLAKE2B)
 #pragma omp parallel sections
                {
 #ifdef HAVE_SSL
+#pragma omp section
+                       {
+                               if (hashes & HASH_MD5)
+                                       MD5_Update(&m5, data, len);
+                       }
+#pragma omp section
+                       {
+                               if (hashes & HASH_SHA1)
+                                       SHA1_Update(&s1, data, len);
+                       }
 #pragma omp section
                        {
                                if (hashes & HASH_SHA256)
@@ -149,6 +194,17 @@ hash_compute_file(
                                if (hashes & HASH_WHIRLPOOL)
                                        WHIRLPOOL_Update(&whrl, data, len);
                        }
+#else
+#pragma omp section
+                       {
+                               if (hashes & HASH_MD5)
+                                       md5_hash(data, len, &m5);
+                       }
+#pragma omp section
+                       {
+                               if (hashes & HASH_SHA1)
+                                       sha1_hash(data, len, &s1);
+                       }
 #endif
 #ifdef HAVE_BLAKE2B
 #pragma omp section
@@ -158,14 +214,29 @@ hash_compute_file(
                        }
 #endif
                }
-#endif /* HAVE_SSL || HAVE_BLAKE2B */
        }
        fclose(f);
 
-#if defined(HAVE_SSL) || defined(HAVE_BLAKE2B)
 #pragma omp parallel sections
        {
 #ifdef HAVE_SSL
+#pragma omp section
+               {
+                       if (hashes & HASH_MD5) {
+                               unsigned char md5buf[MD5_DIGEST_LENGTH];
+                               MD5_Final(md5buf, &m5);
+                               hash_hex(md5, md5buf, MD5_DIGEST_LENGTH);
+                       }
+               }
+#pragma omp section
+               {
+                       if (hashes & HASH_SHA1) {
+                               unsigned char sha1buf[SHA_DIGEST_LENGTH];
+                               SHA1_Final(sha1buf, &s1);
+                               hash_hex(sha1, sha1buf, SHA_DIGEST_LENGTH);
+                       }
+               }
+#pragma omp section
                {
                        if (hashes & HASH_SHA256) {
                                unsigned char sha256buf[SHA256_DIGEST_LENGTH];
@@ -189,6 +260,23 @@ hash_compute_file(
                                hash_hex(whrlpl, whrlplbuf, 
WHIRLPOOL_DIGEST_LENGTH);
                        }
                }
+#else
+#pragma omp section
+               {
+                       if (hashes & HASH_MD5) {
+                               unsigned char md5buf[16];
+                               md5_end(md5buf, &m5);
+                               hash_hex(md5, md5buf, 16);
+                       }
+               }
+#pragma omp section
+               {
+                       if (hashes & HASH_SHA1) {
+                               unsigned char sha1buf[20];
+                               sha1_end(sha1buf, &s1);
+                               hash_hex(sha1, sha1buf, 20);
+                       }
+               }
 #endif
 #ifdef HAVE_BLAKE2B
 #pragma omp section
@@ -201,5 +289,60 @@ hash_compute_file(
                }
 #endif
        }
-#endif /* HAVE_SSL || HAVE_BLAKE2B */
+
+       fclose(f);
+}
+
+void
+hash_multiple_file_at_cb(
+               int pfd,
+               const char *fname,
+               hash_cb_t cb,
+               char *md5,
+               char *sha1,
+               char *sha256,
+               char *sha512,
+               char *whrlpl,
+               char *blak2b,
+               size_t *flen,
+               int hashes)
+{
+       int fd = openat(pfd, fname, O_RDONLY | O_CLOEXEC);
+       if (fd == -1) {
+               *flen = 0;
+               return;
+       }
+
+       if (cb != NULL)
+               fd = cb(fd, fname);
+
+       hash_multiple_file_fd(fd, md5, sha1, sha256, sha512,
+                       whrlpl, blak2b, flen, hashes);
+
+       close(fd);
+}
+
+static char _hash_file_buf[128 + 1];
+char *
+hash_file_at_cb(int pfd, const char *fname, int hash, hash_cb_t cb)
+{
+       size_t dummy;
+
+       switch (hash) {
+               case HASH_MD5:
+               case HASH_SHA1:
+               case HASH_SHA256:
+               case HASH_SHA512:
+               case HASH_WHIRLPOOL:
+               case HASH_BLAKE2B:
+                       hash_multiple_file_at_cb(pfd, fname, cb,
+                                       _hash_file_buf, _hash_file_buf, 
_hash_file_buf,
+                                       _hash_file_buf, _hash_file_buf, 
_hash_file_buf,
+                                       &dummy, hash);
+                       break;
+               default:
+                       return NULL;
+       }
+
+       return _hash_file_buf;
 }

diff --git a/libq/hash.h b/libq/hash.h
index 89f3841..204da5f 100644
--- a/libq/hash.h
+++ b/libq/hash.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2018-2019 Gentoo Foundation
+ * Copyright 2018-2020 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2018-     Fabian Groffen  - <grob...@gentoo.org>
@@ -8,19 +8,41 @@
 #ifndef _HASH_H
 #define _HASH_H 1
 
+/* for AT_FDCWD */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
 enum hash_impls {
-       HASH_SHA256    = 1<<0,
-       HASH_SHA512    = 1<<1,
-       HASH_WHIRLPOOL = 1<<2,
-       HASH_BLAKE2B   = 1<<3
+       HASH_MD5       = 1<<0,
+       HASH_SHA1      = 1<<1,
+       HASH_SHA256    = 1<<2,
+       HASH_SHA512    = 1<<3,
+       HASH_WHIRLPOOL = 1<<4,
+       HASH_BLAKE2B   = 1<<5
 };
 
 /* default changed from sha256, sha512, whirlpool
  * to blake2b, sha512 on 2017-11-21 */
 #define HASH_DEFAULT  (HASH_BLAKE2B | HASH_SHA512);
 
+/* pass in a fd and get back a fd; filename is for display only */
+typedef int (*hash_cb_t) (int, const char *);
+
 void hash_hex(char *out, const unsigned char *buf, const int length);
-void hash_compute_file(const char *fname, char *sha256, char *sha512,
+void hash_multiple_file_fd(
+               int fd, char *md5, char *sha1, char *sha256, char *sha512,
                char *whrlpl, char *blak2b, size_t *flen, int hashes);
+void hash_multiple_file_at_cb(
+               int pfd, const char *fname, hash_cb_t cb, char *md5,
+               char *sha1, char *sha256, char *sha512, char *whrlpl,
+               char *blak2b, size_t *flen, int hashes);
+#define hash_multiple_file(f, m, s1, s2, s5, w, b, l, h) \
+       hash_multiple_file_at_cb(AT_FDCWD, f, NULL, m, s1, s2, s5, w, b, l, h)
+#define hash_compute_file(f, s2, s5, w, b, l, h) \
+       hash_multiple_file_at_cb(AT_FDCWD, f, NULL, NULL, NULL, s2, s5, w, b, 
l, h)
+char *hash_file_at_cb(int pfd, const char *filename, int hash_algo, hash_cb_t 
cb);
+#define hash_file(f, h) hash_file_at_cb(AT_FDCWD, f, h, NULL)
+#define hash_file_at(fd, f, h) hash_file_at_cb(fd, f, h, NULL)
 
 #endif

diff --git a/libq/hash_fd.h b/libq/hash_fd.h
deleted file mode 100644
index 37d21b2..0000000
--- a/libq/hash_fd.h
+++ /dev/null
@@ -1,13 +0,0 @@
-
-/*
- * Copyright 2005-2019 Gentoo Foundation
- * Distributed under the terms of the GNU General Public License v2
- */
-
-#ifndef _HASH_FD_H
-#define _HASH_FD_H 1
-
-int hash_fd(int src_fd, const size_t size, const uint8_t hash_algo,
-                                  uint8_t * hashval);
-
-#endif

diff --git a/libq/hash_fd.c b/libq/hash_md5_sha1.c
similarity index 89%
rename from libq/hash_fd.c
rename to libq/hash_md5_sha1.c
index 9c47078..bdbe0db 100644
--- a/libq/hash_fd.c
+++ b/libq/hash_md5_sha1.c
@@ -53,11 +53,9 @@
 # endif
 #endif
 
-#include "busybox.h"
 #include "xalloc.h"
-#include "hash_fd.h"
+#include "hash_md5_sha1.h"
 
-#ifdef CONFIG_SHA1SUM
 /*
  ---------------------------------------------------------------------------
  Begin Dr. Gladman's sha1 code
@@ -129,13 +127,6 @@
     t = a; a = rotl32(a,5) + f(b,c,d) + e + k + w[i]; \
     e = d; d = c; c = rotl32(b, 30); b = t
 
-/* type to hold the SHA1 context  */
-struct sha1_ctx_t {
-       uint32_t count[2];
-       uint32_t hash[5];
-       uint32_t wbuf[16];
-};
-
 static void sha1_compile(struct sha1_ctx_t *ctx)
 {
        uint32_t w[80], i, a, b, c, d, e, t;
@@ -178,7 +169,7 @@ static void sha1_compile(struct sha1_ctx_t *ctx)
        ctx->hash[4] += e;
 }
 
-static void sha1_begin(struct sha1_ctx_t *ctx)
+void sha1_begin(struct sha1_ctx_t *ctx)
 {
        ctx->count[0] = ctx->count[1] = 0;
        ctx->hash[0] = 0x67452301;
@@ -190,7 +181,7 @@ static void sha1_begin(struct sha1_ctx_t *ctx)
 
 /* SHA1 hash data in an array of bytes into hash buffer and call the        */
 /* hash_compile function as required.                                       */
-static void sha1_hash(const void *data, size_t len, void *ctx_v)
+void sha1_hash(const void *data, size_t len, void *ctx_v)
 {
        struct sha1_ctx_t *ctx = (struct sha1_ctx_t *) ctx_v;
        uint32_t pos = (uint32_t) (ctx->count[0] & SHA1_MASK);
@@ -221,7 +212,7 @@ static uint32_t mask[4] = { 0x00000000, 0xff000000, 
0xffff0000, 0xffffff00 };
 static uint32_t bits[4] = { 0x80000000, 0x00800000, 0x00008000, 0x00000080 };
 # endif /* __BYTE_ORDER */
 
-static void sha1_end(unsigned char hval[], struct sha1_ctx_t *ctx)
+void sha1_end(unsigned char hval[], struct sha1_ctx_t *ctx)
 {
        uint32_t i, cnt = (uint32_t) (ctx->count[0] & SHA1_MASK);
 
@@ -267,9 +258,7 @@ static void sha1_end(unsigned char hval[], struct 
sha1_ctx_t *ctx)
  End of Dr. Gladman's sha1 code
  ---------------------------------------------------------------------------
 */
-#endif /* CONFIG_SHA1 */
 
-#ifdef CONFIG_MD5SUM
 /*
  * md5sum.c - Compute MD5 checksum of files or strings according to the
  *            definition of MD5 in RFC 1321 from April 1992.
@@ -310,21 +299,10 @@ static void sha1_end(unsigned char hval[], struct 
sha1_ctx_t *ctx)
 static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ...  */  };
 # endif        /* MD5SUM_SIZE_VS_SPEED == 0 */
 
-/* Structure to save state of computation between the single steps.  */
-struct md5_ctx_t {
-       uint32_t A;
-       uint32_t B;
-       uint32_t C;
-       uint32_t D;
-       uint32_t total[2];
-       uint32_t buflen;
-       char buffer[128];
-};
-
 /* Initialize structure containing state of computation.
  * (RFC 1321, 3.3: Step 3)
  */
-static void md5_begin(struct md5_ctx_t *ctx)
+void md5_begin(struct md5_ctx_t *ctx)
 {
        ctx->A = 0x67452301;
        ctx->B = 0xefcdab89;
@@ -728,7 +706,7 @@ static void md5_hash_bytes(const void *buffer, size_t len, 
struct md5_ctx_t *ctx
        }
 }
 
-static void md5_hash(const void *buffer, size_t length, void *md5_ctx)
+void md5_hash(const void *buffer, size_t length, void *md5_ctx)
 {
        if (length % 64 == 0) {
                md5_hash_block(buffer, length, md5_ctx);
@@ -745,7 +723,7 @@ static void md5_hash(const void *buffer, size_t length, 
void *md5_ctx)
  * IMPORTANT: On some systems it is required that RESBUF is correctly
  * aligned for a 32 bits value.
  */
-static void *md5_end(void *resbuf, struct md5_ctx_t *ctx)
+void *md5_end(void *resbuf, struct md5_ctx_t *ctx)
 {
        /* Take yet unprocessed bytes into account.  */
        uint32_t bytes = ctx->buflen;
@@ -790,92 +768,3 @@ static void *md5_end(void *resbuf, struct md5_ctx_t *ctx)
 
        return resbuf;
 }
-#endif /* CONFIG_MD5SUM */
-
-int hash_fd(int src_fd, const size_t size, const uint8_t hash_algo,
-                                  uint8_t * hashval)
-{
-       int result = EXIT_SUCCESS;
-/*     size_t hashed_count = 0; */
-       size_t blocksize = 0;
-       size_t remaining = size;
-       unsigned char *buffer = NULL;
-       void (*hash_fn_ptr)(const void *, size_t, void *) = NULL;
-       void *cx = NULL;
-
-#ifdef CONFIG_SHA1SUM
-       struct sha1_ctx_t sha1_cx;
-#endif
-#ifdef CONFIG_MD5SUM
-       struct md5_ctx_t md5_cx;
-#endif
-
-#ifdef CONFIG_SHA1SUM
-       if (hash_algo == HASH_SHA1) {
-               /* Ensure that BLOCKSIZE is a multiple of 64.  */
-               blocksize = 65536;
-               buffer = xmalloc(blocksize);
-               hash_fn_ptr = sha1_hash;
-               cx = &sha1_cx;
-       }
-#endif
-#ifdef CONFIG_MD5SUM
-       if (hash_algo == HASH_MD5) {
-               blocksize = 4096;
-               buffer = xmalloc(blocksize + 72);
-               hash_fn_ptr = md5_hash;
-               cx = &md5_cx;
-       }
-#endif
-
-       /* Initialize the computation context.  */
-#ifdef CONFIG_SHA1SUM
-       if (hash_algo == HASH_SHA1) {
-               sha1_begin(&sha1_cx);
-       }
-#endif
-#ifdef CONFIG_MD5SUM
-       if (hash_algo == HASH_MD5) {
-               md5_begin(&md5_cx);
-       }
-#endif
-       /* Iterate over full file contents.  */
-       while ((remaining == (size_t) -1) || (remaining > 0)) {
-               size_t read_try;
-               ssize_t read_got;
-
-               if (remaining > blocksize) {
-                       read_try = blocksize;
-               } else {
-                       read_try = remaining;
-               }
-               read_got = bb_full_read(src_fd, buffer, read_try);
-               if (read_got < 1) {
-                       /* count == 0 means short read
-                        * count == -1 means read error */
-                       result = read_got - 1;
-                       break;
-               }
-               if (remaining != (size_t) -1) {
-                       remaining -= read_got;
-               }
-
-               /* Process buffer */
-               hash_fn_ptr(buffer, read_got, cx);
-       }
-
-       /* Finalize and write the hash into our buffer.  */
-#ifdef CONFIG_SHA1SUM
-       if (hash_algo == HASH_SHA1) {
-               sha1_end(hashval, &sha1_cx);
-       }
-#endif
-#ifdef CONFIG_MD5SUM
-       if (hash_algo == HASH_MD5) {
-               md5_end(hashval, &md5_cx);
-       }
-#endif
-
-       free(buffer);
-       return result;
-}

diff --git a/libq/hash_md5_sha1.h b/libq/hash_md5_sha1.h
new file mode 100644
index 0000000..6dbbd44
--- /dev/null
+++ b/libq/hash_md5_sha1.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2005-2020 Gentoo Foundation
+ * Distributed under the terms of the GNU General Public License v2
+ */
+
+#ifndef _HASH_FD_H
+#define _HASH_FD_H 1
+
+/* type to hold the SHA1 context  */
+struct sha1_ctx_t {
+       uint32_t count[2];
+       uint32_t hash[5];
+       uint32_t wbuf[16];
+};
+
+void sha1_begin(struct sha1_ctx_t *ctx);
+void sha1_hash(const void *data, size_t len, void *ctx_v);
+void sha1_end(unsigned char hval[], struct sha1_ctx_t *ctx);
+
+/* Structure to save state of computation between the single steps.  */
+struct md5_ctx_t {
+       uint32_t A;
+       uint32_t B;
+       uint32_t C;
+       uint32_t D;
+       uint32_t total[2];
+       uint32_t buflen;
+       char buffer[128];
+};
+
+void md5_begin(struct md5_ctx_t *ctx);
+void md5_hash(const void *buffer, size_t length, void *md5_ctx);
+void *md5_end(void *resbuf, struct md5_ctx_t *ctx);
+
+#endif

diff --git a/libq/md5_sha1_sum.c b/libq/md5_sha1_sum.c
deleted file mode 100644
index 006a63b..0000000
--- a/libq/md5_sha1_sum.c
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- *  Copyright (C) 2003 Glenn L. McGrath
- *  Copyright (C) 2003-2004 Erik Andersen
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#include "main.h"
-
-#include <fcntl.h>
-#include <limits.h>
-#include <stdio.h>
-#include <inttypes.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "busybox.h"
-#include "xalloc.h"
-#include "hash_fd.h"
-#include "md5_sha1_sum.h"
-
-int hash_cb_default(int fd, const char *filename) {
-       (void)filename;
-
-       return fd;
-}
-
-/* This might be useful elsewhere */
-static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
-                                                                         
unsigned char hash_length)
-{
-       int x, len, max;
-       unsigned char *hex_value;
-
-       max = (hash_length * 2) + 2;
-       hex_value = xmalloc(max);
-       for (x = len = 0; x < hash_length; x++) {
-               len += snprintf((char*)(hex_value + len), max - len,
-                               "%02x", hash_value[x]);
-       }
-       return (hex_value);
-}
-
-unsigned char *hash_file_at_cb(
-               int dfd,
-               const char *filename,
-               uint8_t hash_algo,
-               hash_cb_t cb)
-{
-       int fd;
-       fd = openat(dfd, filename, O_RDONLY|O_CLOEXEC);
-       if (fd != -1) {
-               static uint8_t hash_value_bin[20];
-               static unsigned char *hash_value;
-               fd = cb(fd, filename);
-               if (hash_fd(fd, -1, hash_algo, hash_value_bin) != -2)
-                       hash_value = hash_bin_to_hex(hash_value_bin,
-                                       hash_algo == HASH_MD5 ? 16 : 20);
-               else
-                       hash_value = NULL;
-               close(fd);
-               return hash_value;
-       }
-       return NULL;
-}
-
-unsigned char *hash_file_at(int dfd, const char *filename, uint8_t hash_algo)
-{
-       return hash_file_at_cb(dfd, filename, hash_algo, hash_cb_default);
-}
-
-static unsigned char *hash_file_cb(const char *filename, uint8_t hash_algo, 
hash_cb_t cb)
-{
-       return hash_file_at_cb(AT_FDCWD, filename, hash_algo, cb);
-}
-
-unsigned char *hash_file(const char *filename, uint8_t hash_algo)
-{
-       return hash_file_cb(filename, hash_algo, hash_cb_default);
-}

diff --git a/libq/md5_sha1_sum.h b/libq/md5_sha1_sum.h
deleted file mode 100644
index 3c682a4..0000000
--- a/libq/md5_sha1_sum.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright 2005-2019 Gentoo Foundation
- * Distributed under the terms of the GNU General Public License v2
- */
-
-#ifndef _MD5_SHA1_SUM_H
-#define _MD5_SHA1_SUM_H 1
-
-/* for HASH_MD5/HASH_SHA1 */
-#include "busybox.h"
-
-/* pass in a fd and get back a fd; filename is for display only */
-typedef int (*hash_cb_t) (int, const char *);
-
-int hash_cb_default(int fd, const char *filename);
-unsigned char *hash_file_at_cb(
-               int dfd,
-               const char *filename,
-               uint8_t hash_algo,
-               hash_cb_t cb);
-unsigned char *hash_file_at(int dfd, const char *filename, uint8_t hash_algo);
-unsigned char *hash_file(const char *filename, uint8_t hash_algo);
-
-#endif

diff --git a/qcheck.c b/qcheck.c
index 72a68a9..9d9a86c 100644
--- a/qcheck.c
+++ b/qcheck.c
@@ -18,7 +18,7 @@
 #include "atom.h"
 #include "contents.h"
 #include "copy_file.h"
-#include "md5_sha1_sum.h"
+#include "hash.h"
 #include "prelink.h"
 #include "tree.h"
 #include "xarray.h"
@@ -233,8 +233,8 @@ qcheck_cb(tree_pkg_ctx *pkg_ctx, void *priv)
                        }
 
                        hash_cb_t hash_cb =
-                               state->undo_prelink ? hash_cb_prelink_undo : 
hash_cb_default;
-                       f_digest = (char *)hash_file_at_cb(
+                               state->undo_prelink ? hash_cb_prelink_undo : 
NULL;
+                       f_digest = hash_file_at_cb(
                                        pkg_ctx->cat_ctx->ctx->portroot_fd,
                                        entry->name + 1, hash_algo, hash_cb);
 
@@ -242,7 +242,6 @@ qcheck_cb(tree_pkg_ctx *pkg_ctx, void *priv)
                         * Can we get a digest of the file? */
                        if (!f_digest) {
                                ++num_files_unknown;
-                               free(f_digest);
 
                                if (state->qc_update)
                                        fprintf(fp_contents_update, "%s\n", 
buffer);
@@ -283,11 +282,8 @@ qcheck_cb(tree_pkg_ctx *pkg_ctx, void *priv)
                                                fprintf(fp_contents_update, 
"%s\n", buffer);
                                }
 
-                               free(f_digest);
                                continue;
                        }
-
-                       free(f_digest);
                }
 
                /* Validate mtimes */

diff --git a/qmerge.c b/qmerge.c
index 5eec188..103f615 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -24,8 +24,8 @@
 #include "copy_file.h"
 #include "contents.h"
 #include "eat_file.h"
+#include "hash.h"
 #include "human_readable.h"
-#include "md5_sha1_sum.h"
 #include "profile.h"
 #include "rmspace.h"
 #include "scandirat.h"
@@ -828,7 +828,7 @@ merge_tree_at(int fd_src, const char *src, int fd_dst, 
const char *dst,
                        /* Migrate a file */
                        struct timespec times[2];
                        int fd_srcf, fd_dstf;
-                       unsigned char *hash;
+                       char *hash;
                        const char *tmpname, *dname;
                        char buf[_Q_PATH_MAX * 2];
                        struct stat ignore;
@@ -838,7 +838,6 @@ merge_tree_at(int fd_src, const char *src, int fd_dst, 
const char *dst,
                        if (!pretend)
                                fprintf(contents, "obj %s %s %zu""\n",
                                                cpath, hash, 
(size_t)st.st_mtime);
-                       free(hash);
 
                        /* Check CONFIG_PROTECT */
                        if (config_protected(cpath + eprefix_len,
@@ -1502,10 +1501,9 @@ pkg_unmerge(tree_pkg_ctx *pkg_ctx, set *keep,
                        case CONTENTS_OBJ:
                                if (protected && unmerge_config_protected) {
                                        /* If the file wasn't modified, unmerge 
it */
-                                       unsigned char *hash = 
hash_file_at(portroot_fd,
+                                       char *hash = hash_file_at(portroot_fd,
                                                        e->name + 1, HASH_MD5);
                                        protected = strcmp(e->digest, (const 
char *)hash);
-                                       free(hash);
                                }
                                break;
 
@@ -1623,7 +1621,7 @@ pkg_verify_checksums(char *fname, const struct pkg_t 
*pkg, const depend_atom *at
        int ret = 0;
 
        if (pkg->MD5[0]) {
-               if ((hash = (char*) hash_file(fname, HASH_MD5)) == NULL) {
+               if ((hash = hash_file(fname, HASH_MD5)) == NULL) {
                        errf("hash is NULL for %s", fname);
                }
                if (strcmp(hash, pkg->MD5) == 0) {
@@ -1634,11 +1632,10 @@ pkg_verify_checksums(char *fname, const struct pkg_t 
*pkg, const depend_atom *at
                                warn("MD5:  [%sER%s] (%s) != (%s) %s/%s", RED, 
NORM, hash, pkg->MD5, atom->CATEGORY, pkg->PF);
                        ret++;
                }
-               free(hash);
        }
 
        if (pkg->SHA1[0]) {
-               hash = (char*) hash_file(fname, HASH_SHA1);
+               hash = hash_file(fname, HASH_SHA1);
                if (strcmp(hash, pkg->SHA1) == 0) {
                        if (display)
                                qprintf("SHA1: [%sOK%s] %s %s/%s\n", GREEN, 
NORM, hash, atom->CATEGORY, pkg->PF);
@@ -1647,7 +1644,6 @@ pkg_verify_checksums(char *fname, const struct pkg_t 
*pkg, const depend_atom *at
                                warn("SHA1: [%sER%s] (%s) != (%s) %s/%s", RED, 
NORM, hash, pkg->SHA1, atom->CATEGORY, pkg->PF);
                        ret++;
                }
-               free(hash);
        }
 
        if (!pkg->SHA1[0] && !pkg->MD5[0])

diff --git a/qpkg.c b/qpkg.c
index 14e51ce..1494b45 100644
--- a/qpkg.c
+++ b/qpkg.c
@@ -21,8 +21,8 @@
 #include "atom.h"
 #include "basename.h"
 #include "contents.h"
+#include "hash.h"
 #include "human_readable.h"
-#include "md5_sha1_sum.h"
 #include "scandirat.h"
 #include "set.h"
 #include "tree.h"
@@ -228,14 +228,13 @@ qpkg_make(depend_atom *atom)
                        continue;
                if (check_pkg_install_mask(e->name) != 0)
                        continue;
-               fprintf(out, "%s\n", e->name+1); /* dont output leading / */
+               fprintf(out, "%s\n", e->name+1); /* don't output leading / */
                if (e->type == CONTENTS_OBJ && verbose) {
-                       char *hash = (char *)hash_file(e->name, HASH_MD5);
+                       char *hash = hash_file(e->name, HASH_MD5);
                        if (hash != NULL) {
                                if (strcmp(e->digest, hash) != 0)
                                        warn("MD5: mismatch expected %s got %s 
for %s",
                                                        e->digest, hash, 
e->name);
-                               free(hash);
                        }
                }
        }

Reply via email to