├── .editorconfig ├── .gitattributes ├── .gitignore ├── .gitmodules ├── CHANGELOG.md ├── HashCalculator.sln ├── HashCalculator ├── Algorithm │ ├── ExtendedKcpSHA3.cs │ ├── FastXxHashXXH32.cs │ ├── FastXxHashXXH3_128.cs │ ├── FastXxHashXXH3_64.cs │ ├── FastXxHashXXH64.cs │ ├── GmSslSM3.cs │ ├── Gost34112012Streebog.cs │ ├── IHashAlgoInfo.cs │ ├── LibRHashED2K.cs │ ├── LibRHashHAS160.cs │ ├── LibRHashMD4.cs │ ├── LibRHashRipeMD160.cs │ ├── LibRHashSHA224.cs │ ├── LibRHashWhirlpool.cs │ ├── NamazsoQuickXor.cs │ ├── NetCryptoCngAbs.cs │ ├── NetCryptoCngMD5.cs │ ├── NetCryptoCngSHA1.cs │ ├── NetCryptoCngSHA256.cs │ ├── NetCryptoCngSHA384.cs │ ├── NetCryptoCngSHA512.cs │ ├── OfficialImplBlake2.cs │ ├── OfficialImplBlake2b.cs │ ├── OfficialImplBlake2bp.cs │ ├── OfficialImplBlake2s.cs │ ├── OfficialImplBlake2sp.cs │ ├── OfficialImplBlake3.cs │ ├── OpenHashTabCrc64.cs │ └── StbrummeRepoCrc32.cs ├── App.xaml ├── App.xaml.cs ├── Cmders │ ├── AbsHashesCmder.cs │ ├── DeleteFileCmder.cs │ ├── DeleteFileCmderCtrl.xaml │ ├── DeleteFileCmderCtrl.xaml.cs │ ├── MarkFilesCmder.cs │ ├── MarkFilesCmderCtrl.xaml │ ├── MarkFilesCmderCtrl.xaml.cs │ ├── RenameFileCmder.cs │ ├── RenameFileCmderCtrl.xaml │ ├── RenameFileCmderCtrl.xaml.cs │ ├── RestoreFilesCmder.cs │ ├── RestoreFilesCmderCtrl.xaml │ ├── RestoreFilesCmderCtrl.xaml.cs │ ├── SelectTargetsCmder.cs │ ├── SelectTargetsCmderCtrl.xaml │ └── SelectTargetsCmderCtrl.xaml.cs ├── Filters │ ├── AbsHashViewFilter.cs │ ├── CmpResultFilter.cs │ ├── CmpResultFilterCtrl.xaml │ ├── CmpResultFilterCtrl.xaml.cs │ ├── EqualHashByteFilter.cs │ ├── EqualHashByteFilterCtrl.xaml │ ├── EqualHashByteFilterCtrl.xaml.cs │ ├── FileIndexFilter.cs │ ├── FileIndexFilterCtrl.xaml │ ├── FileIndexFilterCtrl.xaml.cs │ ├── FileNameFilter.cs │ ├── FileNameFilterCtrl.xaml │ ├── FileNameFilterCtrl.xaml.cs │ ├── FileSizeFilter.cs │ ├── FileSizeFilterCtrl.xaml │ ├── FileSizeFilterCtrl.xaml.cs │ ├── HashAlgoFilter.cs │ ├── HashAlgoFilterCtrl.xaml │ ├── HashAlgoFilterCtrl.xaml.cs │ ├── HashStringFilter.cs │ ├── HashStringFilterCtrl.xaml │ ├── HashStringFilterCtrl.xaml.cs │ ├── HashingTaskResultFilter.cs │ ├── HashingTaskResultFilterCtrl.xaml │ ├── HashingTaskResultFilterCtrl.xaml.cs │ ├── SameDirFilesFilter.cs │ ├── SameDirFilesFilterCtrl.xaml │ ├── SameDirFilesFilterCtrl.xaml.cs │ ├── SerialNumberFilter.cs │ ├── SerialNumberFilterCtrl.xaml │ └── SerialNumberFilterCtrl.xaml.cs ├── FodyWeavers.xml ├── FodyWeavers.xsd ├── HashCalculator.csproj ├── IconFont │ ├── demo.css │ ├── demo_index.html │ ├── iconfont.css │ ├── iconfont.js │ ├── iconfont.json │ └── iconfont.ttf ├── Images │ ├── icon.ico │ └── loading.gif ├── Initializer │ ├── Initializer.cs │ ├── MMVSReader.cs │ ├── MMVSWriter.cs │ └── MappedInfo.cs ├── Native │ ├── Constants.cs │ ├── Methods.cs │ └── Structures.cs ├── Others │ ├── BytesComparer.cs │ ├── CmdOptions.cs │ ├── CmpableFileIndex.cs │ ├── ColumnProperty.cs │ ├── CommonExts.cs │ ├── CommonUtils.cs │ ├── ComparableColor.cs │ ├── ConfigPaths.cs │ ├── Converters.cs │ ├── Enumerations.cs │ ├── HashChecklist.cs │ ├── HashModelArg.cs │ ├── HcmData.cs │ ├── HcmDataHelper.cs │ ├── MessageToken.cs │ ├── ModelStarter.cs │ ├── PathPackage.cs │ ├── ProcSynchronizer.cs │ └── RelayCommand.cs ├── Properties │ └── AssemblyInfo.cs ├── Property │ └── ExecTargetAttach.cs ├── Resources │ ├── ButtonIcons.xaml │ ├── CmderButtonStyles.xaml │ ├── ComboBoxStyle1.xaml │ ├── ComboBoxStyle2.xaml │ ├── ConverterResource.xaml │ ├── DataGridCellStyles.xaml │ ├── DataGridRowStyles.xaml │ ├── DataGridStyles.xaml │ ├── DescTextBlockStyles.xaml │ ├── GroupBoxStyles.xaml │ ├── IconFont.xaml │ ├── ImageButtonStyles.xaml │ ├── ImgButtonTextStyles.xaml │ ├── TabControlItemStyles.xaml │ └── TabControlStyles.xaml ├── Settings │ ├── Info.cs │ └── Settings.cs ├── ShellExtHelper │ ├── RegNode.cs │ ├── RegValue.cs │ └── ShellExtHelper.cs ├── ViewModels │ ├── AlgoGroupModel.cs │ ├── AlgoInOutModel.cs │ ├── AlgosPanelModel.cs │ ├── DoubleProgressModel.cs │ ├── FilterAndCmdPanelModel.cs │ ├── GenericItemModel.cs │ ├── HashViewModel.cs │ ├── HcCtxMenuModel.cs │ ├── MainWndViewModel.cs │ ├── NotifiableModel.cs │ ├── SettingsViewModel.cs │ ├── ShellMenuEditorModel.cs │ ├── TemplateForChecklistModel.cs │ └── TemplateForExportModel.cs ├── Views │ ├── AlgosPanel.xaml │ ├── AlgosPanel.xaml.cs │ ├── DoubleProgressWnd.xaml │ ├── DoubleProgressWnd.xaml.cs │ ├── FilterAndCmdPanel.xaml │ ├── FilterAndCmdPanel.xaml.cs │ ├── HashDetailsWindow.xaml │ ├── HashDetailsWindow.xaml.cs │ ├── HowToExportResults.xaml │ ├── HowToExportResults.xaml.cs │ ├── MainWindow.xaml │ ├── MainWindow.xaml.cs │ ├── SettingsPanel.xaml │ ├── SettingsPanel.xaml.cs │ ├── ShellMenuEditor.xaml │ ├── ShellMenuEditor.xaml.cs │ ├── ShellSubmenuEditor.xaml │ └── ShellSubmenuEditor.xaml.cs └── packages.config ├── IconTools ├── Icons │ ├── AppIcon │ │ ├── icon.ico │ │ ├── icon_128.png │ │ ├── icon_16.png │ │ ├── icon_256.png │ │ ├── icon_32.png │ │ ├── icon_48.png │ │ └── icon_64.png │ ├── ButtonIcons │ │ ├── algorithm.svg │ │ ├── arrow_down.svg │ │ ├── arrow_down_gray.svg │ │ ├── arrow_up.svg │ │ ├── arrow_up_gray.svg │ │ ├── calculate_force.svg │ │ ├── calculate_force_gray.svg │ │ ├── calculate_newlines.svg │ │ ├── calculate_newlines_gray.svg │ │ ├── calculate_noresults.svg │ │ ├── calculate_noresults_gray.svg │ │ ├── cancel_tasks.svg │ │ ├── clear_filters.svg │ │ ├── clear_filters_gray.svg │ │ ├── clear_table.svg │ │ ├── continue_tasks.svg │ │ ├── export.svg │ │ ├── export_gray.svg │ │ ├── filter.svg │ │ ├── pause_tasks.svg │ │ ├── refresh_filters.svg │ │ ├── refresh_filters_gray.svg │ │ ├── refresh_output.svg │ │ ├── remaining.svg │ │ ├── select_file.svg │ │ ├── select_folder.svg │ │ ├── settings.svg │ │ ├── stop_searching.svg │ │ ├── topmost.svg │ │ ├── topmost_gray.svg │ │ └── total_lines.svg │ ├── HcbIcon │ │ ├── file_icon.ico │ │ ├── icon_128.png │ │ ├── icon_16.png │ │ ├── icon_256.png │ │ ├── icon_32.png │ │ ├── icon_48.png │ │ └── icon_64.png │ ├── OriginalFiles │ │ ├── origin_256_0067CC.png │ │ ├── origin_256_6346D3.png │ │ └── origin_256_FF8660.png │ └── ShellIcons │ │ ├── 256_0067CC.png │ │ ├── 256_6346D3.png │ │ └── 256_FF8660.png ├── Readme.txt └── SvgToXaml │ ├── SvgToXaml.exe │ └── SvgToXaml.exe.config ├── LICENSE.txt ├── README.md ├── Screenshots ├── about.png ├── algorithms.png ├── filters.png ├── settings1.png ├── settings2.png ├── settings3.png ├── settings4.png ├── window1.png └── window2.png ├── ShellExtensions ├── ComputeHash.cpp ├── ComputeHash.h ├── ComputeHash.rgs ├── OpenAsChecklist.cpp ├── OpenAsChecklist.h ├── OpenAsChecklist.rgs ├── ResString.h ├── ShellExtensions.cpp ├── ShellExtensions.def ├── ShellExtensions.idl ├── ShellExtensions.rc ├── ShellExtensions.rgs ├── ShellExtensions.vcxproj ├── ShellExtensions.vcxproj.filters ├── ShellExtensionsps.def ├── app_icon.ico ├── commons.cpp ├── commons.h ├── dllmain.cpp ├── dllmain.h ├── file_icon.ico ├── framework.h ├── icon_1.bmp ├── icon_3.bmp ├── pch.cpp ├── pch.h ├── resource.h └── targetver.h └── TODO.md /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "ShellExtensions/TinyJson"] 2 | path = ShellExtensions/TinyJson 3 | url = git@github.com:rafagafe/tiny-json.git 4 | [submodule "OpenHashLibs"] 5 | path = OpenHashLibs 6 | url = git@github.com:hrpzcf/OpenHashLibs.git 7 | -------------------------------------------------------------------------------- /HashCalculator.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.2.32630.192 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HashCalculator", "HashCalculator\HashCalculator.csproj", "{16B60D29-4D81-4360-814C-1A0FFFF5D75B}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionItems", "{3D318F1A-748B-4730-B262-B495B0A525CB}" 9 | ProjectSection(SolutionItems) = preProject 10 | .editorconfig = .editorconfig 11 | .gitattributes = .gitattributes 12 | .gitignore = .gitignore 13 | CHANGELOG.md = CHANGELOG.md 14 | LICENSE.txt = LICENSE.txt 15 | README.md = README.md 16 | TODO.md = TODO.md 17 | EndProjectSection 18 | EndProject 19 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ShellExtensions", "ShellExtensions\ShellExtensions.vcxproj", "{4DB70050-30FF-487A-AD55-C3E663CD0329}" 20 | EndProject 21 | Global 22 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 23 | Debug|Any CPU = Debug|Any CPU 24 | Debug|x64 = Debug|x64 25 | Debug|x86 = Debug|x86 26 | Release|Any CPU = Release|Any CPU 27 | Release|x64 = Release|x64 28 | Release|x86 = Release|x86 29 | EndGlobalSection 30 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 31 | {16B60D29-4D81-4360-814C-1A0FFFF5D75B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 32 | {16B60D29-4D81-4360-814C-1A0FFFF5D75B}.Debug|Any CPU.Build.0 = Debug|Any CPU 33 | {16B60D29-4D81-4360-814C-1A0FFFF5D75B}.Debug|x64.ActiveCfg = Debug|Any CPU 34 | {16B60D29-4D81-4360-814C-1A0FFFF5D75B}.Debug|x64.Build.0 = Debug|Any CPU 35 | {16B60D29-4D81-4360-814C-1A0FFFF5D75B}.Debug|x86.ActiveCfg = Debug|Any CPU 36 | {16B60D29-4D81-4360-814C-1A0FFFF5D75B}.Debug|x86.Build.0 = Debug|Any CPU 37 | {16B60D29-4D81-4360-814C-1A0FFFF5D75B}.Release|Any CPU.ActiveCfg = Release|Any CPU 38 | {16B60D29-4D81-4360-814C-1A0FFFF5D75B}.Release|Any CPU.Build.0 = Release|Any CPU 39 | {16B60D29-4D81-4360-814C-1A0FFFF5D75B}.Release|x64.ActiveCfg = Release|Any CPU 40 | {16B60D29-4D81-4360-814C-1A0FFFF5D75B}.Release|x64.Build.0 = Release|Any CPU 41 | {16B60D29-4D81-4360-814C-1A0FFFF5D75B}.Release|x86.ActiveCfg = Release|Any CPU 42 | {16B60D29-4D81-4360-814C-1A0FFFF5D75B}.Release|x86.Build.0 = Release|Any CPU 43 | {4DB70050-30FF-487A-AD55-C3E663CD0329}.Debug|Any CPU.ActiveCfg = Debug|Win32 44 | {4DB70050-30FF-487A-AD55-C3E663CD0329}.Debug|Any CPU.Build.0 = Debug|Win32 45 | {4DB70050-30FF-487A-AD55-C3E663CD0329}.Debug|x64.ActiveCfg = Debug|x64 46 | {4DB70050-30FF-487A-AD55-C3E663CD0329}.Debug|x64.Build.0 = Debug|x64 47 | {4DB70050-30FF-487A-AD55-C3E663CD0329}.Debug|x86.ActiveCfg = Debug|Win32 48 | {4DB70050-30FF-487A-AD55-C3E663CD0329}.Debug|x86.Build.0 = Debug|Win32 49 | {4DB70050-30FF-487A-AD55-C3E663CD0329}.Release|Any CPU.ActiveCfg = Release|Win32 50 | {4DB70050-30FF-487A-AD55-C3E663CD0329}.Release|Any CPU.Build.0 = Release|Win32 51 | {4DB70050-30FF-487A-AD55-C3E663CD0329}.Release|x64.ActiveCfg = Release|x64 52 | {4DB70050-30FF-487A-AD55-C3E663CD0329}.Release|x64.Build.0 = Release|x64 53 | {4DB70050-30FF-487A-AD55-C3E663CD0329}.Release|x86.ActiveCfg = Release|Win32 54 | {4DB70050-30FF-487A-AD55-C3E663CD0329}.Release|x86.Build.0 = Release|Win32 55 | EndGlobalSection 56 | GlobalSection(SolutionProperties) = preSolution 57 | HideSolutionNode = FALSE 58 | EndGlobalSection 59 | GlobalSection(ExtensibilityGlobals) = postSolution 60 | SolutionGuid = {523F154A-A33F-4888-893D-78255FB6DA53} 61 | EndGlobalSection 62 | EndGlobal 63 | -------------------------------------------------------------------------------- /HashCalculator/Algorithm/GmSslSM3.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using System.Security.Cryptography; 4 | 5 | namespace HashCalculator 6 | { 7 | internal class GmSslSM3 : HashAlgorithm, IHashAlgoInfo 8 | { 9 | private IntPtr _state = IntPtr.Zero; 10 | 11 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 12 | private static extern IntPtr sm3_new(); 13 | 14 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 15 | private static extern void sm3_delete(IntPtr state); 16 | 17 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 18 | private static extern void sm3_init(IntPtr state); 19 | 20 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 21 | private static extern void sm3_update(IntPtr state, byte[] input, ulong size); 22 | 23 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 24 | private static extern void sm3_update(IntPtr state, ref byte input, ulong size); 25 | 26 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 27 | private static extern void sm3_final(IntPtr state, byte[] output); 28 | 29 | public int DigestLength => 32; 30 | 31 | public string AlgoName => "SM3"; 32 | 33 | public AlgoType AlgoType => AlgoType.SM3; 34 | 35 | private void DeleteState() 36 | { 37 | if (this._state != IntPtr.Zero) 38 | { 39 | sm3_delete(this._state); 40 | this._state = IntPtr.Zero; 41 | } 42 | } 43 | 44 | protected override void Dispose(bool disposing) 45 | { 46 | this.DeleteState(); 47 | base.Dispose(disposing); 48 | } 49 | 50 | public override void Initialize() 51 | { 52 | this.DeleteState(); 53 | this._state = sm3_new(); 54 | if (this._state == IntPtr.Zero) 55 | { 56 | throw new Exception("Initialization failed"); 57 | } 58 | sm3_init(this._state); 59 | } 60 | 61 | public IHashAlgoInfo NewInstance() 62 | { 63 | return new GmSslSM3(); 64 | } 65 | 66 | protected override void HashCore(byte[] array, int ibStart, int cbSize) 67 | { 68 | if (this._state == IntPtr.Zero) 69 | { 70 | throw new InvalidOperationException("Not initialized yet"); 71 | } 72 | if (ibStart == 0 && cbSize == array.Length) 73 | { 74 | sm3_update(this._state, array, (ulong)cbSize); 75 | } 76 | else 77 | { 78 | ReadOnlySpan span = new ReadOnlySpan(array, ibStart, cbSize); 79 | ref byte input = ref MemoryMarshal.GetReference(span); 80 | sm3_update(this._state, ref input, (ulong)cbSize); 81 | } 82 | } 83 | 84 | protected override byte[] HashFinal() 85 | { 86 | if (this._state == IntPtr.Zero) 87 | { 88 | throw new InvalidOperationException("Not initialized yet"); 89 | } 90 | byte[] resultBuffer = new byte[this.DigestLength]; 91 | sm3_final(this._state, resultBuffer); 92 | return resultBuffer; 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /HashCalculator/Algorithm/IHashAlgoInfo.cs: -------------------------------------------------------------------------------- 1 | namespace HashCalculator 2 | { 3 | public interface IHashAlgoInfo 4 | { 5 | string AlgoName { get; } 6 | 7 | AlgoType AlgoType { get; } 8 | 9 | int DigestLength { get; } 10 | 11 | IHashAlgoInfo NewInstance(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /HashCalculator/Algorithm/LibRHashED2K.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using System.Security.Cryptography; 4 | 5 | namespace HashCalculator 6 | { 7 | internal class LibRHashED2K : HashAlgorithm, IHashAlgoInfo 8 | { 9 | private IntPtr _state = IntPtr.Zero; 10 | 11 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 12 | private static extern IntPtr ed2k_new(); 13 | 14 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 15 | private static extern void ed2k_delete(IntPtr state); 16 | 17 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 18 | private static extern void ed2k_init(IntPtr state); 19 | 20 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 21 | private static extern void ed2k_update(IntPtr state, byte[] input, ulong inlen); 22 | 23 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 24 | private static extern void ed2k_update(IntPtr state, ref byte input, ulong inlen); 25 | 26 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 27 | private static extern void ed2k_final(IntPtr state, byte[] output); 28 | 29 | public string AlgoName => "eD2k"; 30 | 31 | public AlgoType AlgoType => AlgoType.ED2K; 32 | 33 | public int DigestLength => 16; 34 | 35 | private void DeleState() 36 | { 37 | if (this._state != IntPtr.Zero) 38 | { 39 | ed2k_delete(this._state); 40 | this._state = IntPtr.Zero; 41 | } 42 | } 43 | 44 | protected override void Dispose(bool disposing) 45 | { 46 | this.DeleState(); 47 | base.Dispose(disposing); 48 | } 49 | 50 | public override void Initialize() 51 | { 52 | this.DeleState(); 53 | this._state = ed2k_new(); 54 | if (this._state == IntPtr.Zero) 55 | { 56 | throw new Exception("Initialization failed"); 57 | } 58 | ed2k_init(this._state); 59 | } 60 | 61 | public IHashAlgoInfo NewInstance() 62 | { 63 | return new LibRHashED2K(); 64 | } 65 | 66 | protected override void HashCore(byte[] array, int ibStart, int cbSize) 67 | { 68 | if (this._state == IntPtr.Zero) 69 | { 70 | throw new InvalidOperationException("Not initialized yet"); 71 | } 72 | if (ibStart == 0 && cbSize == array.Length) 73 | { 74 | ed2k_update(this._state, array, (ulong)cbSize); 75 | } 76 | else 77 | { 78 | ReadOnlySpan span = new ReadOnlySpan(array, ibStart, cbSize); 79 | ref byte input = ref MemoryMarshal.GetReference(span); 80 | ed2k_update(this._state, ref input, (ulong)cbSize); 81 | } 82 | } 83 | 84 | protected override byte[] HashFinal() 85 | { 86 | if (this._state == IntPtr.Zero) 87 | { 88 | throw new InvalidOperationException("Not initialized yet"); 89 | } 90 | byte[] resultBuffer = new byte[this.DigestLength]; 91 | ed2k_final(this._state, resultBuffer); 92 | return resultBuffer; 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /HashCalculator/Algorithm/LibRHashHAS160.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using System.Security.Cryptography; 4 | 5 | namespace HashCalculator 6 | { 7 | internal class LibRHashHas160 : HashAlgorithm, IHashAlgoInfo 8 | { 9 | private IntPtr _state = IntPtr.Zero; 10 | 11 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 12 | private static extern IntPtr has160_new(); 13 | 14 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 15 | private static extern void has160_delete(IntPtr state); 16 | 17 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 18 | private static extern void has160_init(IntPtr state); 19 | 20 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 21 | private static extern void has160_update(IntPtr state, byte[] input, ulong inlen); 22 | 23 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 24 | private static extern void has160_update(IntPtr state, ref byte input, ulong inlen); 25 | 26 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 27 | private static extern void has160_final(IntPtr state, byte[] output); 28 | 29 | public string AlgoName => "Has160"; 30 | 31 | public AlgoType AlgoType => AlgoType.HAS160; 32 | 33 | public int DigestLength => 20; 34 | 35 | private void DeleState() 36 | { 37 | if (this._state != IntPtr.Zero) 38 | { 39 | has160_delete(this._state); 40 | this._state = IntPtr.Zero; 41 | } 42 | } 43 | 44 | protected override void Dispose(bool disposing) 45 | { 46 | this.DeleState(); 47 | base.Dispose(disposing); 48 | } 49 | 50 | public override void Initialize() 51 | { 52 | this.DeleState(); 53 | this._state = has160_new(); 54 | if (this._state == IntPtr.Zero) 55 | { 56 | throw new Exception("Initialization failed"); 57 | } 58 | has160_init(this._state); 59 | } 60 | 61 | public IHashAlgoInfo NewInstance() 62 | { 63 | return new LibRHashHas160(); 64 | } 65 | 66 | protected override void HashCore(byte[] array, int ibStart, int cbSize) 67 | { 68 | if (this._state == IntPtr.Zero) 69 | { 70 | throw new InvalidOperationException("Not initialized yet"); 71 | } 72 | if (ibStart == 0 && cbSize == array.Length) 73 | { 74 | has160_update(this._state, array, (ulong)cbSize); 75 | } 76 | else 77 | { 78 | ReadOnlySpan span = new ReadOnlySpan(array, ibStart, cbSize); 79 | ref byte input = ref MemoryMarshal.GetReference(span); 80 | has160_update(this._state, ref input, (ulong)cbSize); 81 | } 82 | } 83 | 84 | protected override byte[] HashFinal() 85 | { 86 | if (this._state == IntPtr.Zero) 87 | { 88 | throw new InvalidOperationException("Not initialized yet"); 89 | } 90 | byte[] resultBuffer = new byte[this.DigestLength]; 91 | has160_final(this._state, resultBuffer); 92 | return resultBuffer; 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /HashCalculator/Algorithm/LibRHashMD4.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using System.Security.Cryptography; 4 | 5 | namespace HashCalculator 6 | { 7 | internal class LibRHashMD4 : HashAlgorithm, IHashAlgoInfo 8 | { 9 | private IntPtr _state = IntPtr.Zero; 10 | 11 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 12 | private static extern IntPtr md4_new(); 13 | 14 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 15 | private static extern void md4_delete(IntPtr state); 16 | 17 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 18 | private static extern void md4_init(IntPtr state); 19 | 20 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 21 | private static extern void md4_update(IntPtr state, byte[] input, ulong inlen); 22 | 23 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 24 | private static extern void md4_update(IntPtr state, ref byte input, ulong inlen); 25 | 26 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 27 | private static extern void md4_final(IntPtr state, byte[] output); 28 | 29 | public string AlgoName => "MD4"; 30 | 31 | public AlgoType AlgoType => AlgoType.MD4; 32 | 33 | public int DigestLength => 16; 34 | 35 | private void DeleState() 36 | { 37 | if (this._state != IntPtr.Zero) 38 | { 39 | md4_delete(this._state); 40 | this._state = IntPtr.Zero; 41 | } 42 | } 43 | 44 | protected override void Dispose(bool disposing) 45 | { 46 | this.DeleState(); 47 | base.Dispose(disposing); 48 | } 49 | 50 | public override void Initialize() 51 | { 52 | this.DeleState(); 53 | this._state = md4_new(); 54 | if (this._state == IntPtr.Zero) 55 | { 56 | throw new Exception("Initialization failed"); 57 | } 58 | md4_init(this._state); 59 | } 60 | 61 | public IHashAlgoInfo NewInstance() 62 | { 63 | return new LibRHashMD4(); 64 | } 65 | 66 | protected override void HashCore(byte[] array, int ibStart, int cbSize) 67 | { 68 | if (this._state == IntPtr.Zero) 69 | { 70 | throw new InvalidOperationException("Not initialized yet"); 71 | } 72 | if (ibStart == 0 && cbSize == array.Length) 73 | { 74 | md4_update(this._state, array, (ulong)cbSize); 75 | } 76 | else 77 | { 78 | ReadOnlySpan span = new ReadOnlySpan(array, ibStart, cbSize); 79 | ref byte input = ref MemoryMarshal.GetReference(span); 80 | md4_update(this._state, ref input, (ulong)cbSize); 81 | } 82 | } 83 | 84 | protected override byte[] HashFinal() 85 | { 86 | if (this._state == IntPtr.Zero) 87 | { 88 | throw new InvalidOperationException("Not initialized yet"); 89 | } 90 | byte[] resultBuffer = new byte[this.DigestLength]; 91 | md4_final(this._state, resultBuffer); 92 | return resultBuffer; 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /HashCalculator/Algorithm/LibRHashRipeMD160.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using System.Security.Cryptography; 4 | 5 | namespace HashCalculator 6 | { 7 | internal class LibRHashRipeMD160 : HashAlgorithm, IHashAlgoInfo 8 | { 9 | private IntPtr _state = IntPtr.Zero; 10 | 11 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 12 | private static extern IntPtr ripemd160_new(); 13 | 14 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 15 | private static extern void ripemd160_delete(IntPtr state); 16 | 17 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 18 | private static extern void ripemd160_init(IntPtr state); 19 | 20 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 21 | private static extern void ripemd160_update(IntPtr state, byte[] input, ulong inlen); 22 | 23 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 24 | private static extern void ripemd160_update(IntPtr state, ref byte input, ulong inlen); 25 | 26 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 27 | private static extern void ripemd160_final(IntPtr state, byte[] output); 28 | 29 | public string AlgoName => "RipeMD160"; 30 | 31 | public AlgoType AlgoType => AlgoType.RIPEMD160; 32 | 33 | public int DigestLength => 20; 34 | 35 | private void DeleState() 36 | { 37 | if (this._state != IntPtr.Zero) 38 | { 39 | ripemd160_delete(this._state); 40 | this._state = IntPtr.Zero; 41 | } 42 | } 43 | 44 | protected override void Dispose(bool disposing) 45 | { 46 | this.DeleState(); 47 | base.Dispose(disposing); 48 | } 49 | 50 | public override void Initialize() 51 | { 52 | this.DeleState(); 53 | this._state = ripemd160_new(); 54 | if (this._state == IntPtr.Zero) 55 | { 56 | throw new Exception("Initialization failed"); 57 | } 58 | ripemd160_init(this._state); 59 | } 60 | 61 | public IHashAlgoInfo NewInstance() 62 | { 63 | return new LibRHashRipeMD160(); 64 | } 65 | 66 | protected override void HashCore(byte[] array, int ibStart, int cbSize) 67 | { 68 | if (this._state == IntPtr.Zero) 69 | { 70 | throw new InvalidOperationException("Not initialized yet"); 71 | } 72 | if (ibStart == 0 && cbSize == array.Length) 73 | { 74 | ripemd160_update(this._state, array, (ulong)cbSize); 75 | } 76 | else 77 | { 78 | ReadOnlySpan span = new ReadOnlySpan(array, ibStart, cbSize); 79 | ref byte input = ref MemoryMarshal.GetReference(span); 80 | ripemd160_update(this._state, ref input, (ulong)cbSize); 81 | } 82 | } 83 | 84 | protected override byte[] HashFinal() 85 | { 86 | if (this._state == IntPtr.Zero) 87 | { 88 | throw new InvalidOperationException("Not initialized yet"); 89 | } 90 | byte[] resultBuffer = new byte[this.DigestLength]; 91 | ripemd160_final(this._state, resultBuffer); 92 | return resultBuffer; 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /HashCalculator/Algorithm/LibRHashSHA224.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using System.Security.Cryptography; 4 | 5 | namespace HashCalculator 6 | { 7 | internal class LibRHashSHA224 : HashAlgorithm, IHashAlgoInfo 8 | { 9 | private IntPtr _state = IntPtr.Zero; 10 | 11 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 12 | private static extern IntPtr sha224_new(); 13 | 14 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 15 | private static extern void sha224_delete(IntPtr state); 16 | 17 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 18 | private static extern void sha224_init(IntPtr state); 19 | 20 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 21 | private static extern void sha224_update(IntPtr state, byte[] input, ulong size); 22 | 23 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 24 | private static extern void sha224_update(IntPtr state, ref byte input, ulong size); 25 | 26 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 27 | private static extern void sha224_final(IntPtr state, byte[] output); 28 | 29 | public int DigestLength { get; } = 28; 30 | 31 | public string AlgoName => "SHA-224"; 32 | 33 | public AlgoType AlgoType => AlgoType.SHA_224; 34 | 35 | private void DeleteState() 36 | { 37 | if (this._state != IntPtr.Zero) 38 | { 39 | sha224_delete(this._state); 40 | this._state = IntPtr.Zero; 41 | } 42 | } 43 | 44 | protected override void Dispose(bool disposing) 45 | { 46 | this.DeleteState(); 47 | base.Dispose(disposing); 48 | } 49 | 50 | public override void Initialize() 51 | { 52 | this.DeleteState(); 53 | this._state = sha224_new(); 54 | if (this._state == IntPtr.Zero) 55 | { 56 | throw new Exception("Initialization failed"); 57 | } 58 | sha224_init(this._state); 59 | } 60 | 61 | public IHashAlgoInfo NewInstance() 62 | { 63 | return new LibRHashSHA224(); 64 | } 65 | 66 | protected override void HashCore(byte[] array, int ibStart, int cbSize) 67 | { 68 | if (this._state == IntPtr.Zero) 69 | { 70 | throw new InvalidOperationException("Not initialized yet"); 71 | } 72 | if (ibStart == 0 && cbSize == array.Length) 73 | { 74 | sha224_update(this._state, array, (ulong)cbSize); 75 | } 76 | else 77 | { 78 | ReadOnlySpan sp = new ReadOnlySpan(array, ibStart, cbSize); 79 | ref byte input = ref MemoryMarshal.GetReference(sp); 80 | sha224_update(this._state, ref input, (ulong)cbSize); 81 | } 82 | } 83 | 84 | protected override byte[] HashFinal() 85 | { 86 | if (this._state == IntPtr.Zero) 87 | { 88 | throw new InvalidOperationException("Not initialized yet"); 89 | } 90 | byte[] resultBuffer = new byte[this.DigestLength]; 91 | sha224_final(this._state, resultBuffer); 92 | return resultBuffer; 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /HashCalculator/Algorithm/LibRHashWhirlpool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using System.Security.Cryptography; 4 | 5 | namespace HashCalculator 6 | { 7 | internal class LibRHashWhirlpool : HashAlgorithm, IHashAlgoInfo 8 | { 9 | private IntPtr _state = IntPtr.Zero; 10 | 11 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 12 | private static extern IntPtr whirlpool_new(); 13 | 14 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 15 | private static extern void whirlpool_delete(IntPtr state); 16 | 17 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 18 | private static extern void whirlpool_init(IntPtr state); 19 | 20 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 21 | private static extern void whirlpool_update(IntPtr state, byte[] input, ulong inlen); 22 | 23 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 24 | private static extern void whirlpool_update(IntPtr state, ref byte input, ulong inlen); 25 | 26 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 27 | private static extern void whirlpool_final(IntPtr state, byte[] output); 28 | 29 | public int DigestLength { get; } = 64; 30 | 31 | public string AlgoName => "Whirlpool"; 32 | 33 | public AlgoType AlgoType => AlgoType.WHIRLPOOL; 34 | 35 | private void DeleState() 36 | { 37 | if (this._state != IntPtr.Zero) 38 | { 39 | whirlpool_delete(this._state); 40 | this._state = IntPtr.Zero; 41 | } 42 | } 43 | 44 | protected override void Dispose(bool disposing) 45 | { 46 | this.DeleState(); 47 | base.Dispose(disposing); 48 | } 49 | 50 | public override void Initialize() 51 | { 52 | this.DeleState(); 53 | this._state = whirlpool_new(); 54 | if (this._state == IntPtr.Zero) 55 | { 56 | throw new Exception("Initialization failed"); 57 | } 58 | whirlpool_init(this._state); 59 | } 60 | 61 | public IHashAlgoInfo NewInstance() 62 | { 63 | return new LibRHashWhirlpool(); 64 | } 65 | 66 | protected override void HashCore(byte[] array, int ibStart, int cbSize) 67 | { 68 | if (this._state == IntPtr.Zero) 69 | { 70 | throw new InvalidOperationException("Not initialized yet"); 71 | } 72 | if (ibStart == 0 && cbSize == array.Length) 73 | { 74 | whirlpool_update(this._state, array, (ulong)cbSize); 75 | } 76 | else 77 | { 78 | ReadOnlySpan span = new ReadOnlySpan(array, ibStart, cbSize); 79 | ref byte input = ref MemoryMarshal.GetReference(span); 80 | whirlpool_update(this._state, ref input, (ulong)cbSize); 81 | } 82 | } 83 | 84 | protected override byte[] HashFinal() 85 | { 86 | if (this._state == IntPtr.Zero) 87 | { 88 | throw new InvalidOperationException("Not initialized yet"); 89 | } 90 | byte[] resultBuffer = new byte[this.DigestLength]; 91 | whirlpool_final(this._state, resultBuffer); 92 | return resultBuffer; 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /HashCalculator/Algorithm/NamazsoQuickXor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using System.Security.Cryptography; 4 | 5 | namespace HashCalculator 6 | { 7 | internal class NamazsoQuickXor : HashAlgorithm, IHashAlgoInfo 8 | { 9 | private IntPtr _state = IntPtr.Zero; 10 | 11 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 12 | private static extern IntPtr quickxor_new(); 13 | 14 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 15 | private static extern void quickxor_delete(IntPtr state); 16 | 17 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 18 | private static extern void quickxor_init(IntPtr state); 19 | 20 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 21 | private static extern void quickxor_update(IntPtr state, byte[] input, ulong size); 22 | 23 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 24 | private static extern void quickxor_update(IntPtr state, ref byte input, ulong size); 25 | 26 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 27 | private static extern void quickxor_final(IntPtr state, byte[] output); 28 | 29 | public int DigestLength { get; } = 20; 30 | 31 | public string AlgoName => "QuickXor"; 32 | 33 | public AlgoType AlgoType => AlgoType.QUICKXOR; 34 | 35 | private void DeleteState() 36 | { 37 | if (this._state != IntPtr.Zero) 38 | { 39 | quickxor_delete(this._state); 40 | this._state = IntPtr.Zero; 41 | } 42 | } 43 | 44 | protected override void Dispose(bool disposing) 45 | { 46 | this.DeleteState(); 47 | base.Dispose(disposing); 48 | } 49 | 50 | public override void Initialize() 51 | { 52 | this.DeleteState(); 53 | this._state = quickxor_new(); 54 | if (this._state == IntPtr.Zero) 55 | { 56 | throw new Exception("Initialization failed"); 57 | } 58 | quickxor_init(this._state); 59 | } 60 | 61 | public IHashAlgoInfo NewInstance() 62 | { 63 | return new NamazsoQuickXor(); 64 | } 65 | 66 | protected override void HashCore(byte[] array, int ibStart, int cbSize) 67 | { 68 | if (this._state == IntPtr.Zero) 69 | { 70 | throw new InvalidOperationException("Not initialized yet"); 71 | } 72 | if (ibStart == 0 && cbSize == array.Length) 73 | { 74 | quickxor_update(this._state, array, (ulong)cbSize); 75 | } 76 | else 77 | { 78 | ReadOnlySpan sp = new ReadOnlySpan(array, ibStart, cbSize); 79 | ref byte input = ref MemoryMarshal.GetReference(sp); 80 | quickxor_update(this._state, ref input, (ulong)cbSize); 81 | } 82 | } 83 | 84 | protected override byte[] HashFinal() 85 | { 86 | if (this._state == IntPtr.Zero) 87 | { 88 | throw new InvalidOperationException("Not initialized yet"); 89 | } 90 | byte[] resultBuffer = new byte[this.DigestLength]; 91 | quickxor_final(this._state, resultBuffer); 92 | return resultBuffer; 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /HashCalculator/Algorithm/NetCryptoCngAbs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Security.Cryptography; 3 | 4 | namespace HashCalculator 5 | { 6 | internal abstract class NetCryptoCngAbs : HashAlgorithm, IHashAlgoInfo 7 | { 8 | private readonly HashAlgorithm algorithm; 9 | 10 | public NetCryptoCngAbs(HashAlgorithm algorithm) 11 | { 12 | this.algorithm = algorithm; 13 | } 14 | 15 | public abstract int DigestLength { get; } 16 | 17 | public abstract string AlgoName { get; } 18 | 19 | public abstract AlgoType AlgoType { get; } 20 | 21 | public abstract IHashAlgoInfo NewInstance(); 22 | 23 | public override void Initialize() 24 | { 25 | this.algorithm.Initialize(); 26 | } 27 | 28 | protected override void HashCore(byte[] array, int ibStart, int cbSize) 29 | { 30 | this.algorithm.TransformBlock(array, ibStart, cbSize, null, 0); 31 | } 32 | 33 | protected override byte[] HashFinal() 34 | { 35 | this.algorithm.TransformFinalBlock(Array.Empty(), 0, 0); 36 | return this.algorithm.Hash; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /HashCalculator/Algorithm/NetCryptoCngMD5.cs: -------------------------------------------------------------------------------- 1 | using System.Security.Cryptography; 2 | 3 | namespace HashCalculator 4 | { 5 | internal class NetCryptoCngMD5 : NetCryptoCngAbs 6 | { 7 | public override int DigestLength => 16; 8 | 9 | public override string AlgoName => "MD5"; 10 | 11 | public override AlgoType AlgoType => AlgoType.MD5; 12 | 13 | public override IHashAlgoInfo NewInstance() 14 | { 15 | return new NetCryptoCngMD5(); 16 | } 17 | 18 | public NetCryptoCngMD5() : base(new MD5Cng()) 19 | { 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /HashCalculator/Algorithm/NetCryptoCngSHA1.cs: -------------------------------------------------------------------------------- 1 | using System.Security.Cryptography; 2 | 3 | namespace HashCalculator 4 | { 5 | internal class NetCryptoCngSHA1 : NetCryptoCngAbs 6 | { 7 | public override int DigestLength => 20; 8 | 9 | public override string AlgoName => "SHA-1"; 10 | 11 | public override AlgoType AlgoType => AlgoType.SHA_1; 12 | 13 | public override IHashAlgoInfo NewInstance() 14 | { 15 | return new NetCryptoCngSHA1(); 16 | } 17 | 18 | public NetCryptoCngSHA1() : base(new SHA1Cng()) 19 | { 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /HashCalculator/Algorithm/NetCryptoCngSHA256.cs: -------------------------------------------------------------------------------- 1 | using System.Security.Cryptography; 2 | 3 | namespace HashCalculator 4 | { 5 | internal class NetCryptoCngSHA256 : NetCryptoCngAbs 6 | { 7 | public override int DigestLength => 32; 8 | 9 | public override string AlgoName => "SHA-256"; 10 | 11 | public override AlgoType AlgoType => AlgoType.SHA_256; 12 | 13 | public override IHashAlgoInfo NewInstance() 14 | { 15 | return new NetCryptoCngSHA256(); 16 | } 17 | 18 | public NetCryptoCngSHA256() : base(new SHA256Cng()) 19 | { 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /HashCalculator/Algorithm/NetCryptoCngSHA384.cs: -------------------------------------------------------------------------------- 1 | using System.Security.Cryptography; 2 | 3 | namespace HashCalculator 4 | { 5 | internal class NetCryptoCngSHA384 : NetCryptoCngAbs 6 | { 7 | public override int DigestLength => 48; 8 | 9 | public override string AlgoName => "SHA-384"; 10 | 11 | public override AlgoType AlgoType => AlgoType.SHA_384; 12 | 13 | public override IHashAlgoInfo NewInstance() 14 | { 15 | return new NetCryptoCngSHA384(); 16 | } 17 | 18 | public NetCryptoCngSHA384() : base(new SHA384Cng()) 19 | { 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /HashCalculator/Algorithm/NetCryptoCngSHA512.cs: -------------------------------------------------------------------------------- 1 | using System.Security.Cryptography; 2 | 3 | namespace HashCalculator 4 | { 5 | internal class NetCryptoCngSHA512 : NetCryptoCngAbs 6 | { 7 | public override int DigestLength => 64; 8 | 9 | public override string AlgoName => "SHA-512"; 10 | 11 | public override AlgoType AlgoType => AlgoType.SHA_512; 12 | 13 | public override IHashAlgoInfo NewInstance() 14 | { 15 | return new NetCryptoCngSHA512(); 16 | } 17 | 18 | public NetCryptoCngSHA512() : base(new SHA512Cng()) 19 | { 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /HashCalculator/Algorithm/OfficialImplBlake2b.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace HashCalculator 5 | { 6 | internal class OfficialImplBlake2b : OfficialImplBlake2 7 | { 8 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 9 | private static extern IntPtr blake2b_new(); 10 | 11 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 12 | private static extern void blake2b_delete(IntPtr statePtr); 13 | 14 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 15 | private static extern int blake2b_init(IntPtr statePtr, ulong outlen); 16 | 17 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 18 | private static extern int blake2b_update(IntPtr statePtr, byte[] input, ulong inlen); 19 | 20 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 21 | private static extern int blake2b_update(IntPtr statePtr, ref byte input, ulong inlen); 22 | 23 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 24 | private static extern int blake2b_final(IntPtr statePtr, byte[] output, ulong outlen); 25 | 26 | public override int MaxOutputLength => 64; 27 | 28 | public override string NamePrefix => "BLAKE2b"; 29 | 30 | public OfficialImplBlake2b(int bitLength) : base(bitLength) 31 | { 32 | } 33 | 34 | public override IHashAlgoInfo NewInstance() 35 | { 36 | return new OfficialImplBlake2b(this.bitLength); 37 | } 38 | 39 | public override void Blake2DeleteState(IntPtr statePtr) 40 | { 41 | blake2b_delete(statePtr); 42 | } 43 | 44 | public override IntPtr Blake2New() 45 | { 46 | return blake2b_new(); 47 | } 48 | 49 | public override int Blake2Init(IntPtr statePtr, ulong outlen) 50 | { 51 | return blake2b_init(statePtr, outlen); 52 | } 53 | 54 | public override int Blake2Update(IntPtr statePtr, byte[] input, ulong inlen) 55 | { 56 | return blake2b_update(statePtr, input, inlen); 57 | } 58 | 59 | public override int Blake2Update(IntPtr statePtr, ref byte input, ulong inlen) 60 | { 61 | return blake2b_update(statePtr, ref input, inlen); 62 | } 63 | 64 | public override int Blake2Final(IntPtr statePtr, byte[] output, ulong outlen) 65 | { 66 | return blake2b_final(statePtr, output, outlen); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /HashCalculator/Algorithm/OfficialImplBlake2bp.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace HashCalculator 5 | { 6 | internal class OfficialImplBlake2bp : OfficialImplBlake2 7 | { 8 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 9 | private static extern IntPtr blake2bp_new(); 10 | 11 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 12 | private static extern void blake2bp_delete(IntPtr statePtr); 13 | 14 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 15 | private static extern int blake2bp_init(IntPtr statePtr, ulong outlen); 16 | 17 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 18 | private static extern int blake2bp_update(IntPtr statePtr, byte[] input, ulong inlen); 19 | 20 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 21 | private static extern int blake2bp_update(IntPtr statePtr, ref byte input, ulong inlen); 22 | 23 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 24 | private static extern int blake2bp_final(IntPtr statePtr, byte[] output, ulong outlen); 25 | 26 | public override int MaxOutputLength => 64; 27 | 28 | public override string NamePrefix => "BLAKE2bp"; 29 | 30 | public OfficialImplBlake2bp(int bitLength) : base(bitLength) 31 | { 32 | } 33 | 34 | public override IHashAlgoInfo NewInstance() 35 | { 36 | return new OfficialImplBlake2bp(this.bitLength); 37 | } 38 | 39 | public override void Blake2DeleteState(IntPtr statePtr) 40 | { 41 | blake2bp_delete(statePtr); 42 | } 43 | 44 | public override IntPtr Blake2New() 45 | { 46 | return blake2bp_new(); 47 | } 48 | 49 | public override int Blake2Init(IntPtr statePtr, ulong outlen) 50 | { 51 | return blake2bp_init(statePtr, outlen); 52 | } 53 | 54 | public override int Blake2Update(IntPtr statePtr, byte[] input, ulong inlen) 55 | { 56 | return blake2bp_update(statePtr, input, inlen); 57 | } 58 | 59 | public override int Blake2Update(IntPtr statePtr, ref byte input, ulong inlen) 60 | { 61 | return blake2bp_update(statePtr, ref input, inlen); 62 | } 63 | 64 | public override int Blake2Final(IntPtr statePtr, byte[] output, ulong outlen) 65 | { 66 | return blake2bp_final(statePtr, output, outlen); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /HashCalculator/Algorithm/OfficialImplBlake2s.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace HashCalculator 5 | { 6 | internal class OfficialImplBlake2s : OfficialImplBlake2 7 | { 8 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 9 | private static extern IntPtr blake2s_new(); 10 | 11 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 12 | private static extern void blake2s_delete(IntPtr statePtr); 13 | 14 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 15 | private static extern int blake2s_init(IntPtr statePtr, ulong outlen); 16 | 17 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 18 | private static extern int blake2s_update(IntPtr statePtr, byte[] input, ulong inlen); 19 | 20 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 21 | private static extern int blake2s_update(IntPtr statePtr, ref byte input, ulong inlen); 22 | 23 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 24 | private static extern int blake2s_final(IntPtr statePtr, byte[] output, ulong outlen); 25 | 26 | public override int MaxOutputLength => 32; 27 | 28 | public override string NamePrefix => "BLAKE2s"; 29 | 30 | public OfficialImplBlake2s(int bitLength) : base(bitLength) 31 | { 32 | } 33 | 34 | public override IHashAlgoInfo NewInstance() 35 | { 36 | return new OfficialImplBlake2s(this.bitLength); 37 | } 38 | 39 | public override void Blake2DeleteState(IntPtr statePtr) 40 | { 41 | blake2s_delete(statePtr); 42 | } 43 | 44 | public override int Blake2Final(IntPtr statePtr, byte[] output, ulong outlen) 45 | { 46 | return blake2s_final(statePtr, output, outlen); 47 | } 48 | 49 | public override int Blake2Init(IntPtr statePtr, ulong outlen) 50 | { 51 | return blake2s_init(statePtr, outlen); 52 | } 53 | 54 | public override IntPtr Blake2New() 55 | { 56 | return blake2s_new(); 57 | } 58 | 59 | public override int Blake2Update(IntPtr statePtr, byte[] input, ulong inlen) 60 | { 61 | return blake2s_update(statePtr, input, inlen); 62 | } 63 | 64 | public override int Blake2Update(IntPtr statePtr, ref byte input, ulong inlen) 65 | { 66 | return blake2s_update(statePtr, ref input, inlen); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /HashCalculator/Algorithm/OfficialImplBlake2sp.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace HashCalculator 5 | { 6 | internal class OfficialImplBlake2sp : OfficialImplBlake2 7 | { 8 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 9 | private static extern IntPtr blake2sp_new(); 10 | 11 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 12 | private static extern void blake2sp_delete(IntPtr statePtr); 13 | 14 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 15 | private static extern int blake2sp_init(IntPtr statePtr, ulong outlen); 16 | 17 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 18 | private static extern int blake2sp_update(IntPtr statePtr, byte[] input, ulong inlen); 19 | 20 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 21 | private static extern int blake2sp_update(IntPtr statePtr, ref byte input, ulong inlen); 22 | 23 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 24 | private static extern int blake2sp_final(IntPtr statePtr, byte[] output, ulong outlen); 25 | 26 | public override int MaxOutputLength => 32; 27 | 28 | public override string NamePrefix => "BLAKE2sp"; 29 | 30 | public OfficialImplBlake2sp(int bitLength) : base(bitLength) 31 | { 32 | } 33 | 34 | public override IHashAlgoInfo NewInstance() 35 | { 36 | return new OfficialImplBlake2sp(this.bitLength); 37 | } 38 | 39 | public override void Blake2DeleteState(IntPtr statePtr) 40 | { 41 | blake2sp_delete(statePtr); 42 | } 43 | 44 | public override int Blake2Final(IntPtr statePtr, byte[] output, ulong outlen) 45 | { 46 | return blake2sp_final(statePtr, output, outlen); 47 | } 48 | 49 | public override int Blake2Init(IntPtr statePtr, ulong outlen) 50 | { 51 | return blake2sp_init(statePtr, outlen); 52 | } 53 | 54 | public override IntPtr Blake2New() 55 | { 56 | return blake2sp_new(); 57 | } 58 | 59 | public override int Blake2Update(IntPtr statePtr, byte[] input, ulong inlen) 60 | { 61 | return blake2sp_update(statePtr, input, inlen); 62 | } 63 | 64 | public override int Blake2Update(IntPtr statePtr, ref byte input, ulong inlen) 65 | { 66 | return blake2sp_update(statePtr, ref input, inlen); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /HashCalculator/Algorithm/OpenHashTabCrc64.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using System.Security.Cryptography; 4 | 5 | namespace HashCalculator 6 | { 7 | internal class OpenHashTabCrc64 : HashAlgorithm, IHashAlgoInfo 8 | { 9 | private ulong previousCrc64 = 0ul; 10 | 11 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 12 | private static extern ulong crc64_update(ulong prevCrc32, byte[] input, ulong in_len); 13 | 14 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 15 | private static extern ulong crc64_update(ulong prevCrc32, ref byte input, ulong in_len); 16 | 17 | public int DigestLength => 8; 18 | 19 | public string AlgoName => "CRC64"; 20 | 21 | public AlgoType AlgoType => AlgoType.CRC64; 22 | 23 | public override void Initialize() 24 | { 25 | this.previousCrc64 = 0ul; 26 | } 27 | 28 | public IHashAlgoInfo NewInstance() 29 | { 30 | return new OpenHashTabCrc64(); 31 | } 32 | 33 | protected override void HashCore(byte[] array, int ibStart, int cbSize) 34 | { 35 | if (ibStart == 0 && cbSize == array.Length) 36 | { 37 | this.previousCrc64 = crc64_update(this.previousCrc64, array, (ulong)cbSize); 38 | } 39 | else 40 | { 41 | ReadOnlySpan span = new ReadOnlySpan(array, ibStart, cbSize); 42 | ref byte input = ref MemoryMarshal.GetReference(span); 43 | this.previousCrc64 = crc64_update(this.previousCrc64, ref input, (ulong)cbSize); 44 | } 45 | } 46 | 47 | protected override byte[] HashFinal() 48 | { 49 | byte[] resultBuffer = BitConverter.GetBytes(this.previousCrc64); 50 | Array.Reverse(resultBuffer); 51 | return resultBuffer; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /HashCalculator/Algorithm/StbrummeRepoCrc32.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using System.Security.Cryptography; 4 | 5 | namespace HashCalculator 6 | { 7 | internal class StbrummeRepoCrc32 : HashAlgorithm, IHashAlgoInfo 8 | { 9 | private uint previousCrc32 = 0u; 10 | 11 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 12 | private static extern uint crc32_update(byte[] input, ulong in_len, uint prevCrc32); 13 | 14 | [DllImport(Settings.HashAlgs, CallingConvention = CallingConvention.Cdecl)] 15 | private static extern uint crc32_update(ref byte input, ulong in_len, uint prevCrc32); 16 | 17 | public int DigestLength => 4; 18 | 19 | public string AlgoName => "CRC32"; 20 | 21 | public AlgoType AlgoType => AlgoType.CRC32; 22 | 23 | public override void Initialize() 24 | { 25 | this.previousCrc32 = 0u; 26 | } 27 | 28 | public IHashAlgoInfo NewInstance() 29 | { 30 | return new StbrummeRepoCrc32(); 31 | } 32 | 33 | protected override void HashCore(byte[] array, int ibStart, int cbSize) 34 | { 35 | if (ibStart == 0 && cbSize == array.Length) 36 | { 37 | this.previousCrc32 = crc32_update(array, (ulong)cbSize, this.previousCrc32); 38 | } 39 | else 40 | { 41 | ReadOnlySpan span = new ReadOnlySpan(array, ibStart, cbSize); 42 | ref byte input = ref MemoryMarshal.GetReference(span); 43 | this.previousCrc32 = crc32_update(ref input, (ulong)cbSize, this.previousCrc32); 44 | } 45 | } 46 | 47 | protected override byte[] HashFinal() 48 | { 49 | byte[] resultBuffer = BitConverter.GetBytes(this.previousCrc32); 50 | Array.Reverse(resultBuffer); 51 | return resultBuffer; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /HashCalculator/App.xaml: -------------------------------------------------------------------------------- 1 |  11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /HashCalculator/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using System.Windows; 4 | using System.Windows.Threading; 5 | 6 | namespace HashCalculator 7 | { 8 | public partial class App : Application 9 | { 10 | private bool _isSessionEndingHandled = false; 11 | 12 | internal static readonly Assembly Executing = Assembly.GetExecutingAssembly(); 13 | 14 | private void StartupHandler(object sender, StartupEventArgs e) 15 | { 16 | Settings.LoadSettings(); 17 | Initializer.ParseArgsForShell(e.Args); 18 | Initializer.PushArgs(e.Args); 19 | } 20 | 21 | private void ApplicationFinalization() 22 | { 23 | Settings.Current.RunInMultiInstMode = Initializer.RunMultiMode; 24 | Settings.SaveSettings(); 25 | } 26 | 27 | private void ExitHandler(object sender, ExitEventArgs e) 28 | { 29 | if (!this._isSessionEndingHandled) 30 | { 31 | this.ApplicationFinalization(); 32 | } 33 | } 34 | 35 | private void ApplicationSessionEnding(object sender, SessionEndingCancelEventArgs e) 36 | { 37 | this.ApplicationFinalization(); 38 | this._isSessionEndingHandled = true; 39 | } 40 | 41 | private void ExceptionHandler(object sender, DispatcherUnhandledExceptionEventArgs e) 42 | { 43 | MessageBox.Show( 44 | $"遇到异常即将退出:\n{e.Exception.Message}\n\n" + 45 | $"问题反馈:软件设置 - 关于软件 - 问题反馈。", "错误"); 46 | Environment.Exit(3); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /HashCalculator/Cmders/AbsHashesCmder.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Windows.Controls; 3 | 4 | namespace HashCalculator 5 | { 6 | internal abstract class AbsHashesCmder : NotifiableModel 7 | { 8 | protected object RefModels { get; } 9 | 10 | public abstract string Display { get; } 11 | 12 | public abstract string Description { get; } 13 | 14 | public abstract ContentControl UserInterface { get; } 15 | 16 | public virtual void Reset() { } 17 | 18 | public AbsHashesCmder(IEnumerable models) 19 | { 20 | this.RefModels = models; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /HashCalculator/Cmders/DeleteFileCmderCtrl.xaml: -------------------------------------------------------------------------------- 1 |  12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |