Skip to content

Commit

Permalink
add multithreading via ms ppl to Checksums tab
Browse files Browse the repository at this point in the history
2.5x faster results for larger files on a quad-core machine
  • Loading branch information
gurnec committed Jul 26, 2016
1 parent b1990d1 commit 5363770
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 20 deletions.
2 changes: 1 addition & 1 deletion HashCheck.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@
<ClCompile Include="libs\sha2.c" />
<ClCompile Include="libs\SimpleList.c" />
<ClCompile Include="libs\SimpleString.c" />
<ClCompile Include="libs\WinHash.c" />
<ClCompile Include="libs\WinHash.cpp" />
<ClCompile Include="libs\Wow64.c" />
<ClCompile Include="RegHelpers.c" />
<ClCompile Include="SetAppID.c" />
Expand Down
6 changes: 3 additions & 3 deletions HashCheck.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@
<ClCompile Include="libs\IsFontAvailable.c">
<Filter>Libraries</Filter>
</ClCompile>
<ClCompile Include="libs\WinHash.c">
<Filter>Libraries</Filter>
</ClCompile>
<ClCompile Include="libs\Wow64.c">
<Filter>Libraries</Filter>
</ClCompile>
Expand All @@ -81,6 +78,9 @@
<ClCompile Include="libs\sha2.c">
<Filter>Libraries</Filter>
</ClCompile>
<ClCompile Include="libs\WinHash.cpp">
<Filter>Libraries</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="HashCheck.def">
Expand Down
2 changes: 1 addition & 1 deletion HashCheckCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extern "C" {

// Tuning constants
#define MAX_PATH_BUFFER 0x800
#define READ_BUFFER_SIZE 0x20000
#define READ_BUFFER_SIZE 0x40000
#define BASE_STACK_SIZE 0x1000
#define MARQUEE_INTERVAL 100 // marquee progress bar animation interval

Expand Down
6 changes: 3 additions & 3 deletions installer/HashCheck.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ FunctionEnd
!insertmacro MUI_LANGUAGE "Ukrainian"
!insertmacro MUI_LANGUAGE "Catalan"

VIProductVersion "2.3.1.10"
VIProductVersion "2.3.2.11"
VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" "HashCheck Shell Extension"
VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductVersion" "2.3.1.10"
VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductVersion" "2.3.2.11"
VIAddVersionKey /LANG=${LANG_ENGLISH} "Comments" "Installer distributed from https://github.com/gurnec/HashCheck/releases"
VIAddVersionKey /LANG=${LANG_ENGLISH} "CompanyName" ""
VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalTrademarks" ""
VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalCopyright" "Copyright © Kai Liu, Christopher Gurnee, Tim Schlueter. All rights reserved."
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileDescription" "Installer (x86/x64) from https://github.com/gurnec/HashCheck/releases"
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "2.3.1.10"
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "2.3.2.11"

; With solid compression, files that are required before the
; actual installation should be stored first in the data block,
Expand Down
35 changes: 33 additions & 2 deletions libs/WinHash.c → libs/WinHash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
* Windows Hashing/Checksumming Library
* Last modified: 2016/02/21
* Original work copyright (C) Kai Liu. All rights reserved.
* Modified work copyright (C) 2014 Christopher Gurnee. All rights reserved.
* Modified work copyright (C) 2014, 2016 Christopher Gurnee. All rights reserved.
* Modified work copyright (C) 2016 Tim Schlueter. All rights reserved.
*
* This is a wrapper for the CRC32, MD5, SHA1, SHA2-256, and SHA2-512
* algorithms.
*
* WinHash.c is needed only if the WH*To* or WH*Ex functions are used.
* WinHash.cpp is needed only if the WH*To* or WH*Ex functions are used.
**/

#include "WinHash.h"
#if _MSC_VER >= 1600
#include <ppl.h>
#endif

// Macro to populate the extensions table. E.g. HASH_EXT_MD5,
#define HASH_EXT_op(alg) HASH_EXT_##alg,
Expand Down Expand Up @@ -130,6 +133,33 @@ VOID WHAPI WHInitEx( PWHCTXEX pContext )

VOID WHAPI WHUpdateEx( PWHCTXEX pContext, PCBYTE pbIn, UINT cbIn )
{
#if _MSC_VER >= 1600
auto task_WHUpdateSHA512 = concurrency::make_task([&] { WHUpdateSHA512(&pContext->ctxSHA512, pbIn, cbIn); } );
auto task_WHUpdateSHA256 = concurrency::make_task([&] { WHUpdateSHA256(&pContext->ctxSHA256, pbIn, cbIn); } );
auto task_WHUpdateSHA1 = concurrency::make_task([&] { WHUpdateSHA1 (&pContext->ctxSHA1, pbIn, cbIn); } );
auto task_WHUpdateMD5 = concurrency::make_task([&] { WHUpdateMD5 (&pContext->ctxMD5, pbIn, cbIn); } );
auto task_WHUpdateCRC32 = concurrency::make_task([&] { WHUpdateCRC32 (&pContext->ctxCRC32, pbIn, cbIn); } );

concurrency::structured_task_group hashing_task_group;

if (pContext->flags & WHEX_CHECKSHA512)
hashing_task_group.run(task_WHUpdateSHA512);

if (pContext->flags & WHEX_CHECKSHA256)
hashing_task_group.run(task_WHUpdateSHA256);

if (pContext->flags & WHEX_CHECKSHA1)
hashing_task_group.run(task_WHUpdateSHA1);

if (pContext->flags & WHEX_CHECKMD5)
hashing_task_group.run(task_WHUpdateMD5);

if (pContext->flags & WHEX_CHECKCRC32)
hashing_task_group.run(task_WHUpdateCRC32);

hashing_task_group.wait();

#else
if (pContext->flags & WHEX_CHECKCRC32)
WHUpdateCRC32(&pContext->ctxCRC32, pbIn, cbIn);

Expand All @@ -144,6 +174,7 @@ VOID WHAPI WHUpdateEx( PWHCTXEX pContext, PCBYTE pbIn, UINT cbIn )

if (pContext->flags & WHEX_CHECKSHA512)
WHUpdateSHA512(&pContext->ctxSHA512, pbIn, cbIn);
#endif
}

VOID WHAPI WHFinishEx( PWHCTXEX pContext, PWHRESULTEX pResults )
Expand Down
15 changes: 8 additions & 7 deletions libs/WinHash.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ __inline void WHAPI WHFinishCRC32( PWHCTXCRC32 pContext )
#define WHFinishSHA512 SHA512Final

/**
* WH*To* hex string conversion functions: These require WinHash.c
* WH*To* hex string conversion functions: These require WinHash.cpp
**/

#define WHAPI __fastcall
Expand All @@ -281,7 +281,7 @@ BOOL WHAPI WHHexToByte( PTSTR pszSrc, PBYTE pbDest, UINT cchHex );
PTSTR WHAPI WHByteToHex( PBYTE pbSrc, PTSTR pszDest, UINT cchHex, UINT8 uCaseMode );

/**
* WH*Ex functions: These require WinHash.c
* WH*Ex functions: These require WinHash.cpp
**/

typedef struct {
Expand All @@ -292,14 +292,15 @@ typedef struct {
TCHAR szHexSHA512[SHA512_DIGEST_STRING_LENGTH];
} WHRESULTEX, *PWHRESULTEX;

// Align all the hash contexts to avoid false sharing (of L1/2 cache lines in multi-core systems)
typedef struct {
UINT8 flags;
UINT8 uCaseMode;
WHCTXCRC32 ctxCRC32;
WHCTXMD5 ctxMD5;
WHCTXSHA1 ctxSHA1;
WHCTXSHA256 ctxSHA256;
WHCTXSHA512 ctxSHA512;
__declspec(align(64)) WHCTXCRC32 ctxCRC32;
__declspec(align(64)) WHCTXMD5 ctxMD5;
__declspec(align(64)) WHCTXSHA1 ctxSHA1;
__declspec(align(64)) WHCTXSHA256 ctxSHA256;
__declspec(align(64)) WHCTXSHA512 ctxSHA512;
WHRESULTEX results;
} WHCTXEX, *PWHCTXEX;

Expand Down
6 changes: 3 additions & 3 deletions version.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* HashCheck Shell Extension
* Original work copyright (C) Kai Liu. All rights reserved.
* Modified work copyright (C) 2014 Christopher Gurnee. All rights reserved.
* Modified work copyright (C) 2014, 2016 Christopher Gurnee. All rights reserved.
* Modified work copyright (C) 2016 Tim Schlueter. All rights reserved.
*
* Please refer to readme.txt for information about this source code.
Expand All @@ -12,10 +12,10 @@
#define HASHCHECK_NAME_STR "HashCheck Shell Extension"

// Full version: MUST be in the form of major,minor,revision,build
#define HASHCHECK_VERSION_FULL 2,3,1,10
#define HASHCHECK_VERSION_FULL 2,3,2,11

// String version: May be any suitable string
#define HASHCHECK_VERSION_STR "2.3.1.10"
#define HASHCHECK_VERSION_STR "2.3.2.11"

#ifdef _USRDLL
// PE version: MUST be in the form of major.minor
Expand Down

0 comments on commit 5363770

Please sign in to comment.