From 56cf56465857e79e814b1e2d50f13e176170fcb3 Mon Sep 17 00:00:00 2001 From: bigbiff bigbiff Date: Fri, 19 Aug 2016 17:43:45 -0400 Subject: 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 --- partition.cpp | 47 +---------------------------------------------- 1 file changed, 1 insertion(+), 46 deletions(-) (limited to 'partition.cpp') diff --git a/partition.cpp b/partition.cpp index ac0c19950..1f57a534f 100644 --- a/partition.cpp +++ b/partition.cpp @@ -1,5 +1,5 @@ /* - Copyright 2013 to 2016 TeamWin + Copyright 2013 to 2017 TeamWin This file is part of TWRP/TeamWin Recovery Project. TWRP is free software: you can redistribute it and/or modify @@ -41,7 +41,6 @@ #include "partitions.hpp" #include "data.hpp" #include "twrp-functions.hpp" -#include "twrpDigest.hpp" #include "twrpTar.hpp" #include "exclude.hpp" #include "infomanager.hpp" @@ -1657,50 +1656,6 @@ bool TWPartition::Backup(PartitionSettings *part_settings, pid_t *tar_fork_pid) return false; } -bool TWPartition::Check_Restore_File_MD5(const string& Filename) { - twrpDigest md5sum; - - md5sum.setfn(Filename); - switch (md5sum.verify_md5digest()) { - case MD5_OK: - gui_msg(Msg("md5_matched=MD5 matched for '{1}'.")(Filename)); - return true; - case MD5_FILE_UNREADABLE: - case MD5_NOT_FOUND: - gui_msg(Msg(msg::kError, "no_md5_found=No md5 file found for '{1}'. Please unselect Enable MD5 verification to restore.")(Filename)); - break; - case MD5_MATCH_FAIL: - gui_msg(Msg(msg::kError, "md5_fail_match=MD5 failed to match on '{1}'.")(Filename)); - break; - } - return false; -} - -bool TWPartition::Check_MD5(PartitionSettings *part_settings) { - string Full_Filename; - char split_filename[512]; - int index = 0; - - sync(); - - Full_Filename = part_settings->Backup_Folder + "/" + Backup_FileName; - if (!TWFunc::Path_Exists(Full_Filename)) { - // This is a split archive, we presume - memset(split_filename, 0, sizeof(split_filename)); - while (index < 1000) { - sprintf(split_filename, "%s%03i", Full_Filename.c_str(), index); - if (!TWFunc::Path_Exists(split_filename)) - break; - LOGINFO("split_filename: %s\n", split_filename); - if (!Check_Restore_File_MD5(split_filename)) - return false; - index++; - } - return true; - } - return Check_Restore_File_MD5(Full_Filename); // Single file archive -} - bool TWPartition::Restore(PartitionSettings *part_settings) { TWFunc::GUI_Operation_Text(TW_RESTORE_TEXT, Display_Name, gui_parse_text("{@restoring_hdr}")); LOGINFO("Restore filename is: %s/%s\n", part_settings->Backup_Folder.c_str(), Backup_FileName.c_str()); -- cgit v1.2.3