shunf4 cherry-picking hash related commits from zstd. The following commits from 7-zip-zstd repository (https://github.com/mcmilk/7-Zip-zstd) is picked:

commit add56b5aed
Author: Tino Reichardt <milky-7zip@mcmilk.de>
Date:   Thu Nov 1 23:08:00 2018 +0100

    Add MD5 hash function

commit 36a17a5184
Author: Tino Reichardt <milky-7zip@mcmilk.de>
Date:   Sat Nov 3 00:18:33 2018 +0100

    Add some hash functions
    - new: md2, md4, md5, sha384, sha512, xxhash-32, xxhash-64
    - put Blake2sp hash stuff back to rar code
    - added the hashes to GUI and Explorer Menu code

commit 576c5df947
Author: Tino Reichardt <milky-7zip@mcmilk.de>
Date:   Tue Apr 6 19:35:46 2021 +0200

    Add BLAKE3 hash function

commit 6b2a151549
Author: Tino Reichardt <milky-7zip@mcmilk.de>
Date:   Tue Apr 6 19:51:01 2021 +0200

    Remove unneeded file HashesReg.cpp

commit dddf507557
Author: Tino Reichardt <milky-7zip@mcmilk.de>
Date:   Sun Jun 18 09:13:59 2023 +0200

    Add SHA3 hashing

    - added these variants: SHA3-256, SHA3-384, SHA3-512
    - reordered also the hashing id's
    - added some notes about them in DOC/Hashes.txt

    Signed-off-by: Tino Reichardt <milky-7zip@mcmilk.de>

The cherry-picking was a chaos; they're not applied in order, and some
commits even got cherry-picked twice (1->4->0->2->4->3). So subsequent fixes and
adjustments were applied to make it build.
This commit is contained in:
Tino Reichardt
2018-11-03 00:18:33 +01:00
committed by shunf4
parent cd0993fe9c
commit e19abb2958
36 changed files with 3253 additions and 31 deletions

View File

@@ -795,18 +795,10 @@ static const char *SkipWhite(const char *s)
static const char * const k_CsumMethodNames[] =
{
"sha256"
, "sha224"
// , "sha512/224"
// , "sha512/256"
, "sha512"
, "sha384"
, "sha1"
, "md5"
, "blake2b"
, "crc64"
, "crc32"
, "cksum"
"sha3-512", "sha3-384", "sha3-256",
"sha512", "sha384", "sha256", "sha224",
"sha1", "md5", "blake2b",
"crc32", "crc64" , "cksum"
};
static UString GetMethod_from_FileName(const UString &name)
@@ -1409,7 +1401,8 @@ static bool CheckDigests(const Byte *a, const Byte *b, size_t size)
static void AddDefaultMethod(UStringVector &methods, unsigned size)
{
const char *m = NULL;
if (size == 32) m = "sha256";
if (size == 64) m = "sha512";
else if (size == 32) m = "sha256";
else if (size == 20) m = "sha1";
else if (size == 16) m = "md5";
else if (size == 8) m = "crc64";
@@ -2090,11 +2083,11 @@ void Codecs_AddHashArcHandler(CCodecs *codecs)
// ubuntu uses "SHA256SUMS" file
item.AddExts(UString (
"sha256 sha512 sha224 sha384 sha1 sha md5"
// "b2sum"
" crc32 crc64"
" asc"
" cksum"
"sha3-512 sha3-384 sha3-256 "
"sha512 sha384 sha256 sha224 "
"sha1 sha md5 "
"crc32 crc64 "
"asc cksum"
),
UString());

View File

@@ -293,16 +293,30 @@ struct CHashCommand
static const CHashCommand g_HashCommands[] =
{
{ CZipContextMenu::kHash_CRC32, "CRC-32", "CRC32" },
{ CZipContextMenu::kHash_CRC64, "CRC-64", "CRC64" },
{ CZipContextMenu::kHash_SHA1, "SHA-1", "SHA1" },
{ CZipContextMenu::kHash_SHA256, "SHA-256", "SHA256" },
{ CZipContextMenu::kHash_CRC32, "CRC-32", "CRC32" },
{ CZipContextMenu::kHash_CRC64, "CRC-64", "CRC64" },
{ CZipContextMenu::kHash_XXH32, "XXH-32 (NOT WORKING)", "XXH32 (NOT WORKING)" },
{ CZipContextMenu::kHash_XXH64, "XXH-64 (NOT WORKING)", "XXH64 (NOT WORKING)" },
{ CZipContextMenu::kHash_MD5, "MD2", "MD2" },
{ CZipContextMenu::kHash_MD5, "MD4", "MD4" },
{ CZipContextMenu::kHash_MD5, "MD5", "MD5" },
{ CZipContextMenu::kHash_SHA1, "SHA-1", "SHA1" },
{ CZipContextMenu::kHash_SHA256, "SHA2-256", "SHA256" },
{ CZipContextMenu::kHash_SHA384, "SHA2-384", "SHA384" },
{ CZipContextMenu::kHash_SHA512, "SHA2-512", "SHA512" },
{ CZipContextMenu::kHash_BLAKE2sp, "BLAKE2sp", "BLAKE2sp" },
{ CZipContextMenu::kHash_SHA256, "SHA3-256", "SHA3-256" },
{ CZipContextMenu::kHash_SHA384, "SHA3-384", "SHA3-384" },
{ CZipContextMenu::kHash_SHA512, "SHA3-512", "SHA3-512" },
{ CZipContextMenu::kHash_BLAKE3, "BLAKE3", "BLAKE3" },
{ CZipContextMenu::kHash_SHA256, "SHA3-256", "SHA3-256" },
{ CZipContextMenu::kHash_SHA384, "SHA3-384", "SHA3-384" },
{ CZipContextMenu::kHash_SHA512, "SHA3-512", "SHA3-512" },
{ CZipContextMenu::kHash_All, "*", "*" },
{ CZipContextMenu::kHash_Generate_SHA256, "SHA-256 -> file.sha256", "SHA256" },
{ CZipContextMenu::kHash_Generate_SHA256, "SHA2-256 -> file.sha256", "SHA256" },
{ CZipContextMenu::kHash_TestArc, "Checksum : Test", "Hash" }
};
static int FindCommand(CZipContextMenu::enum_CommandInternalID &id)
{
for (unsigned i = 0; i < Z7_ARRAY_SIZE(g_Commands); i++)
@@ -1104,7 +1118,7 @@ Z7_COMWF_B CZipContextMenu::QueryContextMenu(HMENU hMenu, UINT indexMenu,
showName += ".sha256";
cmi.Folder = fs2us(folderPrefix);
cmi.ArcName = name;
s = "SHA-256 -> ";
s = "SHA2-256 -> ";
s += showName;
}
else if (hc.CommandInternalID == kHash_TestArc)
@@ -1332,8 +1346,20 @@ HRESULT CZipContextMenu::InvokeCommandCommon(const CCommandMapItem &cmi)
case kHash_CRC32:
case kHash_CRC64:
case kHash_XXH32:
case kHash_XXH64:
case kHash_MD2:
case kHash_MD4:
case kHash_MD5:
case kHash_SHA1:
case kHash_SHA256:
case kHash_SHA384:
case kHash_SHA512:
case kHash_BLAKE2sp:
case kHash_SHA3_256:
case kHash_SHA3_384:
case kHash_SHA3_512:
case kHash_BLAKE3:
case kHash_All:
case kHash_Generate_SHA256:
case kHash_TestArc:

View File

@@ -87,13 +87,25 @@ public:
kCompressToZipEmail,
kHash_CRC32,
kHash_CRC64,
kHash_XXH32,
kHash_XXH64,
kHash_MD2,
kHash_MD4,
kHash_MD5,
kHash_SHA1,
kHash_SHA256,
kHash_SHA384,
kHash_SHA512,
kHash_BLAKE2sp,
kHash_BLAKE3,
kHash_SHA3_256,
kHash_SHA3_384,
kHash_SHA3_512,
kHash_All,
kHash_Generate_SHA256,
kHash_TestArc
};
public:
void Init_For_7zFM()
{
@@ -103,6 +115,8 @@ public:
void LoadItems(IShellItemArray *psiItemArray);
HRESULT InitContextMenu(const wchar_t *folder, const wchar_t * const *names, unsigned numFiles);
CZipContextMenu();
~CZipContextMenu();

View File

@@ -742,9 +742,18 @@ bool ExecuteFileCommand(unsigned id)
case IDM_HASH_ALL: g_App.CalculateCrc("*"); break;
case IDM_CRC32: g_App.CalculateCrc("CRC32"); break;
case IDM_CRC64: g_App.CalculateCrc("CRC64"); break;
case IDM_SHA1: g_App.CalculateCrc("SHA1"); break;
case IDM_XXH32: g_App.CalculateCrc("XXH32 (NOT WORKING)"); break;
case IDM_XXH64: g_App.CalculateCrc("XXH64 (NOT WORKING)"); break;
case IDM_MD2: g_App.CalculateCrc("MD2"); break;
case IDM_MD4: g_App.CalculateCrc("MD4"); break;
case IDM_MD5: g_App.CalculateCrc("MD5"); break;
case IDM_SHA1: g_App.CalculateCrc("SHA1"); break;
case IDM_SHA256: g_App.CalculateCrc("SHA256"); break;
case IDM_SHA384: g_App.CalculateCrc("SHA384"); break;
case IDM_SHA512: g_App.CalculateCrc("SHA512"); break;
case IDM_BLAKE2sp: g_App.CalculateCrc("BLAKE2sp"); break;
case IDM_BLAKE3: g_App.CalculateCrc("BLAKE3"); break;
case IDM_DIFF: g_App.DiffFiles(); break;
case IDM_VER_EDIT:

View File

@@ -23,8 +23,20 @@
#define IDM_HASH_ALL 101
#define IDM_CRC32 102
#define IDM_CRC64 103
#define IDM_SHA1 104
#define IDM_SHA256 105
#define IDM_XXH32 104
#define IDM_XXH64 105
#define IDM_MD2 106
#define IDM_MD4 107
#define IDM_MD5 108
#define IDM_SHA1 109
#define IDM_SHA256 110
// orig
// #define IDM_SHA1 104
// #define IDM_SHA256 105
#define IDM_SHA384 111
#define IDM_SHA512 112
#define IDM_BLAKE2sp 113
#define IDM_BLAKE3 114
#define IDM_FILE 500

View File

@@ -57,8 +57,17 @@ BEGIN
BEGIN
MENUITEM "CRC-32", IDM_CRC32
MENUITEM "CRC-64", IDM_CRC64
MENUITEM "xxHash-32 (Not Working)", IDM_XXH32
MENUITEM "xxHash-64 (Not Working)", IDM_XXH64
MENUITEM "MD2", IDM_MD2
MENUITEM "MD4", IDM_MD4
MENUITEM "MD5", IDM_MD5
MENUITEM "SHA-1", IDM_SHA1
MENUITEM "SHA-256", IDM_SHA256
MENUITEM "SHA-384", IDM_SHA384
MENUITEM "SHA-512", IDM_SHA512
MENUITEM "Blake2sp", IDM_BLAKE2sp
MENUITEM "Blake3", IDM_BLAKE3
MENUITEM "*", IDM_HASH_ALL
END
MENUITEM "Di&ff", IDM_DIFF