twrpDigest refactor

This patch is to refactor twrpDigest using polymorphism
and inheritance to use the same call patterns for creating and
reading a digest. Now a library.
Use SHA2 from libcrypto. SHA2 is default if device has libcrypto.

Change string MD5 everywhere to use digest or Digest instead. Updated
string tags to digest. Translation will be required.

Switch out digest code into a driver class from partitionmanager.

SHA2 is better for digest creation due to decreased collision space
compared to MD5 and SHA1.

See https://en.wikipedia.org/wiki/SHA-2

Change-Id: I74b5546789990b12aa4ce2e389d25f80a3fe213f
diff --git a/Android.mk b/Android.mk
index 3d3428f..85cdd32 100644
--- a/Android.mk
+++ b/Android.mk
@@ -51,18 +51,15 @@
     fixContexts.cpp \
     twrpTar.cpp \
     exclude.cpp \
-    twrpDigest.cpp \
-    digest/md5.c \
     find_file.cpp \
-    infomanager.cpp
-
-LOCAL_SRC_FILES += \
+    infomanager.cpp \
     data.cpp \
     partition.cpp \
     partitionmanager.cpp \
     progresstracking.cpp \
     twinstall.cpp \
     twrp-functions.cpp \
+    twrpDigestDriver.cpp \
     openrecoveryscript.cpp \
     tarWrite.c
 
@@ -112,9 +109,11 @@
     system/core/libsparse \
     external/zlib
 
-LOCAL_C_INCLUDES += bionic external/openssl/include
+LOCAL_C_INCLUDES += bionic
 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
-    LOCAL_C_INCLUDES += external/stlport/stlport
+    LOCAL_C_INCLUDES += external/stlport/stlport external/openssl/include
+else
+    LOCAL_C_INCLUDES += external/boringssl/include
 endif
 
 LOCAL_STATIC_LIBRARIES :=
@@ -122,10 +121,11 @@
 
 LOCAL_STATIC_LIBRARIES += libguitwrp
 LOCAL_SHARED_LIBRARIES += libaosprecovery libz libc libcutils libstdc++ libtar libblkid libminuitwrp libminadbd libmtdutils libminzip libtwadbbu libbootloader_message
-LOCAL_SHARED_LIBRARIES += libcrecovery
+LOCAL_SHARED_LIBRARIES += libcrecovery libtwadbbu libtwrpdigest
 
 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
     LOCAL_SHARED_LIBRARIES += libstlport
+    LOCAL_CFLAGS += -DTW_NO_SHA2_LIBRARY
 endif
 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 24; echo $$?),0)
     LOCAL_SHARED_LIBRARIES += libmincrypttwrp
@@ -159,10 +159,8 @@
         #LOCAL_STATIC_LIBRARIES += liblz4
     endif
 endif
-
 LOCAL_C_INCLUDES += external/libselinux/include
 LOCAL_SHARED_LIBRARIES += libselinux
-LOCAL_CFLAGS += -g
 ifneq ($(TARGET_USERIMAGES_USE_EXT4), true)
     LOCAL_CFLAGS += -DUSE_EXT4
     LOCAL_C_INCLUDES += system/extras/ext4_utils
@@ -682,6 +680,7 @@
     $(commands_recovery_local_path)/simg2img/Android.mk \
     $(commands_recovery_local_path)/adbbu/Android.mk \
     $(commands_recovery_local_path)/libpixelflinger/Android.mk \
+    $(commands_recovery_local_path)/twrpDigest/Android.mk \
     $(commands_recovery_local_path)/attr/Android.mk
 
 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 24; echo $$?),0)