├── .gitignore ├── IntChecker2.sln ├── LICENSE.txt ├── README.md ├── appveyor.yml ├── depends ├── far3 │ ├── DlgBuilder.hpp │ ├── PluginSettings.hpp │ ├── farcolor.hpp │ └── plugin.hpp ├── farhelpers │ ├── Far3Menu.hpp │ └── Far3Panel.hpp └── rhash │ ├── librhash │ ├── aich.c │ ├── aich.h │ ├── algorithms.c │ ├── algorithms.h │ ├── blake2b.c │ ├── blake2b.h │ ├── blake2s.c │ ├── blake2s.h │ ├── byte_order.c │ ├── byte_order.h │ ├── crc32.c │ ├── crc32.h │ ├── ed2k.c │ ├── ed2k.h │ ├── edonr.c │ ├── edonr.h │ ├── gost12.c │ ├── gost12.h │ ├── gost94.c │ ├── gost94.h │ ├── has160.c │ ├── has160.h │ ├── hex.c │ ├── hex.h │ ├── md4.c │ ├── md4.h │ ├── md5.c │ ├── md5.h │ ├── plug_openssl.c │ ├── plug_openssl.h │ ├── rhash.c │ ├── rhash.h │ ├── rhash_timing.c │ ├── rhash_timing.h │ ├── rhash_torrent.c │ ├── rhash_torrent.h │ ├── ripemd-160.c │ ├── ripemd-160.h │ ├── sha1.c │ ├── sha1.h │ ├── sha256.c │ ├── sha256.h │ ├── sha3.c │ ├── sha3.h │ ├── sha512.c │ ├── sha512.h │ ├── snefru.c │ ├── snefru.h │ ├── tiger.c │ ├── tiger.h │ ├── tiger_sbox.c │ ├── torrent.c │ ├── torrent.h │ ├── tth.c │ ├── tth.h │ ├── ustd.h │ ├── util.c │ ├── util.h │ ├── whirlpool.c │ ├── whirlpool.h │ └── whirlpool_sbox.c │ ├── rhash.vcxproj │ ├── rhash.vcxproj.filters │ ├── rhash.vcxproj.user │ └── version.h ├── extra ├── m4.props ├── m4.targets ├── m4.xml ├── pack_releases.bat ├── scripts │ ├── IntChecker.GetFileHash.lua │ ├── IntChecker.Run.lua │ └── script-docs.txt └── version.txt.m4 └── source ├── Far3Guids.h ├── FarCommon.h ├── IntChecker2-Far3.cpp ├── IntChecker2-Far3.def ├── IntChecker2.rc ├── IntChecker2.vcxproj ├── IntChecker2.vcxproj.filters ├── IntChecker2.vcxproj.user ├── Lang.h ├── Text ├── IntCheckerEng.lng ├── IntCheckerPol.lng ├── IntCheckerRus.lng ├── IntCheckerSpa.lng ├── history_en.txt ├── history_pl.txt ├── history_ru.txt └── license.txt ├── Utils.cpp ├── Utils.h ├── dllmain.cpp ├── hashing.cpp ├── hashing.h ├── m4 ├── FILE_ID.DIZ.m4 ├── IntCheckerPol.hlf.m4 ├── IntCheckerRus.hlf.m4 ├── readme_pl.txt.m4 ├── readme_ru.txt.m4 └── version.h.m4 ├── resource.h ├── stdafx.cpp ├── stdafx.h ├── targetver.h ├── trust.cpp ├── trust.h └── version.m4i /.gitignore: -------------------------------------------------------------------------------- 1 | /obj/ 2 | /bin/ 3 | /ipch/ 4 | /.vs/ 5 | *.ncb 6 | *.suo 7 | *.sdf 8 | *.opensdf 9 | *.VC.* 10 | /source/version.h 11 | -------------------------------------------------------------------------------- /IntChecker2.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.32510.428 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "IntChecker2", "source\IntChecker2.vcxproj", "{575E3215-DAD6-4B44-8231-C7D53D25BE82}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rhash", "depends\rhash\rhash.vcxproj", "{66FEB52E-3624-4806-B018-02DAD5CF59DF}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug-Far3|Win32 = Debug-Far3|Win32 13 | Debug-Far3|x64 = Debug-Far3|x64 14 | Release-Far3|Win32 = Release-Far3|Win32 15 | Release-Far3|x64 = Release-Far3|x64 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {575E3215-DAD6-4B44-8231-C7D53D25BE82}.Debug-Far3|Win32.ActiveCfg = Debug-Far3|Win32 19 | {575E3215-DAD6-4B44-8231-C7D53D25BE82}.Debug-Far3|Win32.Build.0 = Debug-Far3|Win32 20 | {575E3215-DAD6-4B44-8231-C7D53D25BE82}.Debug-Far3|x64.ActiveCfg = Debug-Far3|x64 21 | {575E3215-DAD6-4B44-8231-C7D53D25BE82}.Debug-Far3|x64.Build.0 = Debug-Far3|x64 22 | {575E3215-DAD6-4B44-8231-C7D53D25BE82}.Release-Far3|Win32.ActiveCfg = Release-Far3|Win32 23 | {575E3215-DAD6-4B44-8231-C7D53D25BE82}.Release-Far3|Win32.Build.0 = Release-Far3|Win32 24 | {575E3215-DAD6-4B44-8231-C7D53D25BE82}.Release-Far3|x64.ActiveCfg = Release-Far3|x64 25 | {575E3215-DAD6-4B44-8231-C7D53D25BE82}.Release-Far3|x64.Build.0 = Release-Far3|x64 26 | {66FEB52E-3624-4806-B018-02DAD5CF59DF}.Debug-Far3|Win32.ActiveCfg = Debug-Far3|Win32 27 | {66FEB52E-3624-4806-B018-02DAD5CF59DF}.Debug-Far3|Win32.Build.0 = Debug-Far3|Win32 28 | {66FEB52E-3624-4806-B018-02DAD5CF59DF}.Debug-Far3|x64.ActiveCfg = Debug-Far3|x64 29 | {66FEB52E-3624-4806-B018-02DAD5CF59DF}.Debug-Far3|x64.Build.0 = Debug-Far3|x64 30 | {66FEB52E-3624-4806-B018-02DAD5CF59DF}.Release-Far3|Win32.ActiveCfg = Release-Far3|Win32 31 | {66FEB52E-3624-4806-B018-02DAD5CF59DF}.Release-Far3|Win32.Build.0 = Release-Far3|Win32 32 | {66FEB52E-3624-4806-B018-02DAD5CF59DF}.Release-Far3|x64.ActiveCfg = Release-Far3|x64 33 | {66FEB52E-3624-4806-B018-02DAD5CF59DF}.Release-Far3|x64.Build.0 = Release-Far3|x64 34 | EndGlobalSection 35 | GlobalSection(SolutionProperties) = preSolution 36 | HideSolutionNode = FALSE 37 | EndGlobalSection 38 | GlobalSection(ExtensibilityGlobals) = postSolution 39 | SolutionGuid = {5DD68ECA-C76B-4802-835D-919C9AD59523} 40 | EndGlobalSection 41 | EndGlobal 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Integrity Checker Plugin for Far Manager 2.0/3.0 2 | 3 | Hash sums calculation/verification plugin. 4 | 5 | The following hash algorithms are supported: CRC32, MD5, SHA1, SHA-256, SHA-512, SHA3-512, Whirlpool 6 | 7 | Based on [RHash](https://github.com/rhash/RHash) utility code. 8 | 9 | ## Installation ## 10 | 11 | Download binary package for your Far Manager version and copy to Plugins folder. 12 | 13 | ## Building from source ## 14 | 15 | [![Build status](https://ci.appveyor.com/api/projects/status/8edsoy9csw4f7qk1?svg=true)](https://ci.appveyor.com/project/lazyhamster/intchecker) 16 | 17 | Project is developed under MS Visual Studio 2017. 18 | 19 | Additional requirements (not included in source distribution): 20 | 21 | * M4 Macro Processor (must be in %PATH%). 22 | 23 | ## License ## 24 | 25 | Integrity Checker is free software: you can use it, redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 26 | Integrity Checker is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See the GNU General Public License for more details. 27 | 28 | Code from RHash is licensed under [RHash License](https://github.com/rhash/RHash/blob/master/COPYING). 29 | 30 | ## Links ## 31 | 32 | [Support forum](https://forum.farmanager.com/viewtopic.php?f=5&t=5870) 33 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 2.0.{build} 2 | 3 | image: Visual Studio 2019 4 | 5 | shallow_clone: true 6 | clone_depth: 1 7 | 8 | configuration: 9 | - Release-Far3 10 | 11 | platform: 12 | - Win32 13 | - x64 14 | 15 | build: 16 | project: IntChecker2.sln 17 | verbosity: minimal 18 | 19 | test: off 20 | 21 | matrix: 22 | fast_finish: true 23 | 24 | install: 25 | - SET PATH=%PATH%;C:\msys64\usr\bin 26 | - cd extra 27 | - m4 -P version.txt.m4 > version.txt 28 | - SET /p PVER=- 34 | cd %APPVEYOR_BUILD_FOLDER% 35 | 36 | xcopy bin\%configuration%-%platform%\* export\IntChecker2 /E /I /Y > nul 37 | 38 | xcopy source\Text\*.txt export\IntChecker2 /E /I /Y > nul 39 | 40 | xcopy extra\scripts\* export\IntChecker2\scripts /E /I /Y > nul 41 | 42 | IF "%platform%" == "Win32" (SET P_ARCH=x86) ELSE (SET P_ARCH=%platform%) 43 | 44 | 7z a -r -sdel -bd -x!*.ipdb -x!*.iobj -- IntChecker2_%configuration:~-4%_%P_ARCH%_%PVER%.7z .\export\* 45 | 46 | artifacts: 47 | - path: '*.7z' 48 | name: distr 49 | 50 | deploy: 51 | - provider: GitHub 52 | tag: $(APPVEYOR_REPO_TAG_NAME) 53 | release: $(PVER) 54 | description: 'Stable Release' 55 | auth_token: 56 | secure: 8yIMSvujlGt6MF6RMRvIYhNG9JTzQa8eqnx+BBBb4kbsZ/IKovnbJD1WnInPEt4/ 57 | artifact: distr 58 | draft: true 59 | prerelease: false 60 | on: 61 | APPVEYOR_REPO_TAG: true # deploy on tag push only 62 | -------------------------------------------------------------------------------- /depends/far3/PluginSettings.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __PLUGINSETTINGS_HPP__ 2 | #define __PLUGINSETTINGS_HPP__ 3 | 4 | #include "plugin.hpp" 5 | 6 | class PluginSettings 7 | { 8 | HANDLE handle; 9 | FARAPISETTINGSCONTROL SettingsControl; 10 | 11 | public: 12 | 13 | PluginSettings(const GUID &guid, FARAPISETTINGSCONTROL SettingsControl) 14 | { 15 | this->SettingsControl = SettingsControl; 16 | handle = INVALID_HANDLE_VALUE; 17 | 18 | FarSettingsCreate settings={sizeof(FarSettingsCreate),guid,handle}; 19 | if (SettingsControl(INVALID_HANDLE_VALUE,SCTL_CREATE,0,&settings)) 20 | handle = settings.Handle; 21 | } 22 | 23 | ~PluginSettings() 24 | { 25 | SettingsControl(handle,SCTL_FREE,0,nullptr); 26 | } 27 | 28 | int CreateSubKey(size_t Root, const wchar_t *Name) 29 | { 30 | FarSettingsValue value={sizeof(FarSettingsValue),Root,Name}; 31 | return (int)SettingsControl(handle,SCTL_CREATESUBKEY,0,&value); 32 | } 33 | 34 | int OpenSubKey(size_t Root, const wchar_t *Name) 35 | { 36 | FarSettingsValue value={sizeof(FarSettingsValue),Root,Name}; 37 | return (int)SettingsControl(handle,SCTL_OPENSUBKEY,0,&value); 38 | } 39 | 40 | bool DeleteSubKey(size_t Root) 41 | { 42 | FarSettingsValue value={sizeof(FarSettingsValue),Root,nullptr}; 43 | return (int)SettingsControl(handle,SCTL_DELETE,0,&value) ? true : false; 44 | } 45 | 46 | bool DeleteValue(size_t Root, const wchar_t *Name) 47 | { 48 | FarSettingsValue value={sizeof(FarSettingsValue),Root,Name}; 49 | return (int)SettingsControl(handle,SCTL_DELETE,0,&value) ? true : false; 50 | } 51 | 52 | const wchar_t *Get(size_t Root, const wchar_t *Name, const wchar_t *Default) 53 | { 54 | FarSettingsItem item={sizeof(FarSettingsItem),Root,Name,FST_STRING}; 55 | if (SettingsControl(handle,SCTL_GET,0,&item)) 56 | { 57 | return item.String; 58 | } 59 | return Default; 60 | } 61 | 62 | void Get(size_t Root, const wchar_t *Name, wchar_t *Value, size_t Size, const wchar_t *Default) 63 | { 64 | lstrcpyn(Value, Get(Root,Name,Default), (int)Size); 65 | } 66 | 67 | unsigned __int64 Get(size_t Root, const wchar_t *Name, unsigned __int64 Default) 68 | { 69 | FarSettingsItem item={sizeof(FarSettingsItem),Root,Name,FST_QWORD}; 70 | if (SettingsControl(handle,SCTL_GET,0,&item)) 71 | { 72 | return item.Number; 73 | } 74 | return Default; 75 | } 76 | 77 | __int64 Get(size_t Root, const wchar_t *Name, __int64 Default) { return (__int64)Get(Root,Name,(unsigned __int64)Default); } 78 | int Get(size_t Root, const wchar_t *Name, int Default) { return (int)Get(Root,Name,(unsigned __int64)Default); } 79 | unsigned int Get(size_t Root, const wchar_t *Name, unsigned int Default) { return (unsigned int)Get(Root,Name,(unsigned __int64)Default); } 80 | DWORD Get(size_t Root, const wchar_t *Name, DWORD Default) { return (DWORD)Get(Root,Name,(unsigned __int64)Default); } 81 | bool Get(size_t Root, const wchar_t *Name, bool Default) { return Get(Root,Name,Default?1ull:0ull)?true:false; } 82 | 83 | size_t Get(size_t Root, const wchar_t *Name, void *Value, size_t Size) 84 | { 85 | FarSettingsItem item={sizeof(FarSettingsItem),Root,Name,FST_DATA}; 86 | if (SettingsControl(handle,SCTL_GET,0,&item)) 87 | { 88 | Size = (item.Data.Size>Size)?Size:item.Data.Size; 89 | memcpy(Value,item.Data.Data,Size); 90 | return Size; 91 | } 92 | return 0; 93 | } 94 | 95 | bool Set(size_t Root, const wchar_t *Name, const wchar_t *Value) 96 | { 97 | FarSettingsItem item={sizeof(FarSettingsItem),Root,Name,FST_STRING}; 98 | item.String=Value; 99 | return SettingsControl(handle,SCTL_SET,0,&item)!=FALSE; 100 | } 101 | 102 | bool Set(size_t Root, const wchar_t *Name, unsigned __int64 Value) 103 | { 104 | FarSettingsItem item={sizeof(FarSettingsItem),Root,Name,FST_QWORD}; 105 | item.Number=Value; 106 | return SettingsControl(handle,SCTL_SET,0,&item)!=FALSE; 107 | } 108 | 109 | bool Set(size_t Root, const wchar_t *Name, __int64 Value) { return Set(Root,Name,(unsigned __int64)Value); } 110 | bool Set(size_t Root, const wchar_t *Name, int Value) { return Set(Root,Name,(unsigned __int64)Value); } 111 | bool Set(size_t Root, const wchar_t *Name, unsigned int Value) { return Set(Root,Name,(unsigned __int64)Value); } 112 | bool Set(size_t Root, const wchar_t *Name, DWORD Value) { return Set(Root,Name,(unsigned __int64)Value); } 113 | bool Set(size_t Root, const wchar_t *Name, bool Value) { return Set(Root,Name,Value?1ull:0ull); } 114 | 115 | bool Set(size_t Root, const wchar_t *Name, const void *Value, size_t Size) 116 | { 117 | FarSettingsItem item={sizeof(FarSettingsItem),Root,Name,FST_DATA}; 118 | item.Data.Size=Size; 119 | item.Data.Data=Value; 120 | return SettingsControl(handle,SCTL_SET,0,&item)!=FALSE; 121 | } 122 | 123 | bool Enum(size_t Root, FarSettingsEnum* fse) 124 | { 125 | fse->Root=Root; 126 | fse->StructSize=sizeof(FarSettingsEnum); 127 | return SettingsControl(handle, SCTL_ENUM, 0, fse)!=FALSE; 128 | } 129 | }; 130 | 131 | #endif 132 | -------------------------------------------------------------------------------- /depends/far3/farcolor.hpp: -------------------------------------------------------------------------------- 1 | #ifndef FARCOLOR_HPP_57151931_4591_44A5_92CF_8E51D1FBC57E 2 | #define FARCOLOR_HPP_57151931_4591_44A5_92CF_8E51D1FBC57E 3 | #pragma once 4 | 5 | /* 6 | farcolor.hpp 7 | 8 | Colors Index for FAR Manager 3.0.6226.0 9 | */ 10 | /* 11 | Copyright © 1996 Eugene Roshal 12 | Copyright © 2000 Far Group 13 | All rights reserved. 14 | 15 | Redistribution and use in source and binary forms, with or without 16 | modification, are permitted provided that the following conditions 17 | are met: 18 | 1. Redistributions of source code must retain the above copyright 19 | notice, this list of conditions and the following disclaimer. 20 | 2. Redistributions in binary form must reproduce the above copyright 21 | notice, this list of conditions and the following disclaimer in the 22 | documentation and/or other materials provided with the distribution. 23 | 3. The name of the authors may not be used to endorse or promote products 24 | derived from this software without specific prior written permission. 25 | 26 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 27 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 28 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 29 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 30 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 31 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 35 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | 37 | EXCEPTION: 38 | Far Manager plugins that use this header file can be distributed under any 39 | other possible license with no implications from the above license on them. 40 | */ 41 | 42 | 43 | enum PaletteColors 44 | { 45 | COL_MENUTEXT, 46 | COL_MENUSELECTEDTEXT, 47 | COL_MENUHIGHLIGHT, 48 | COL_MENUSELECTEDHIGHLIGHT, 49 | COL_MENUBOX, 50 | COL_MENUTITLE, 51 | 52 | COL_HMENUTEXT, 53 | COL_HMENUSELECTEDTEXT, 54 | COL_HMENUHIGHLIGHT, 55 | COL_HMENUSELECTEDHIGHLIGHT, 56 | 57 | COL_PANELTEXT, 58 | COL_PANELSELECTEDTEXT, 59 | COL_PANELHIGHLIGHTTEXT, 60 | COL_PANELINFOTEXT, 61 | COL_PANELCURSOR, 62 | COL_PANELSELECTEDCURSOR, 63 | COL_PANELTITLE, 64 | COL_PANELSELECTEDTITLE, 65 | COL_PANELCOLUMNTITLE, 66 | COL_PANELTOTALINFO, 67 | COL_PANELSELECTEDINFO, 68 | 69 | COL_DIALOGTEXT, 70 | COL_DIALOGHIGHLIGHTTEXT, 71 | COL_DIALOGBOX, 72 | COL_DIALOGBOXTITLE, 73 | COL_DIALOGHIGHLIGHTBOXTITLE, 74 | COL_DIALOGEDIT, 75 | COL_DIALOGBUTTON, 76 | COL_DIALOGSELECTEDBUTTON, 77 | COL_DIALOGHIGHLIGHTBUTTON, 78 | COL_DIALOGHIGHLIGHTSELECTEDBUTTON, 79 | 80 | COL_DIALOGLISTTEXT, 81 | COL_DIALOGLISTSELECTEDTEXT, 82 | COL_DIALOGLISTHIGHLIGHT, 83 | COL_DIALOGLISTSELECTEDHIGHLIGHT, 84 | 85 | COL_WARNDIALOGTEXT, 86 | COL_WARNDIALOGHIGHLIGHTTEXT, 87 | COL_WARNDIALOGBOX, 88 | COL_WARNDIALOGBOXTITLE, 89 | COL_WARNDIALOGHIGHLIGHTBOXTITLE, 90 | COL_WARNDIALOGEDIT, 91 | COL_WARNDIALOGBUTTON, 92 | COL_WARNDIALOGSELECTEDBUTTON, 93 | COL_WARNDIALOGHIGHLIGHTBUTTON, 94 | COL_WARNDIALOGHIGHLIGHTSELECTEDBUTTON, 95 | 96 | COL_KEYBARNUM, 97 | COL_KEYBARTEXT, 98 | COL_KEYBARBACKGROUND, 99 | 100 | COL_COMMANDLINE, 101 | 102 | COL_CLOCK, 103 | 104 | COL_VIEWERTEXT, 105 | COL_VIEWERSELECTEDTEXT, 106 | COL_VIEWERSTATUS, 107 | 108 | COL_EDITORTEXT, 109 | COL_EDITORSELECTEDTEXT, 110 | COL_EDITORSTATUS, 111 | 112 | COL_HELPTEXT, 113 | COL_HELPHIGHLIGHTTEXT, 114 | COL_HELPTOPIC, 115 | COL_HELPSELECTEDTOPIC, 116 | COL_HELPBOX, 117 | COL_HELPBOXTITLE, 118 | 119 | COL_PANELDRAGTEXT, 120 | COL_DIALOGEDITUNCHANGED, 121 | COL_PANELSCROLLBAR, 122 | COL_HELPSCROLLBAR, 123 | COL_PANELBOX, 124 | COL_PANELSCREENSNUMBER, 125 | COL_DIALOGEDITSELECTED, 126 | COL_COMMANDLINESELECTED, 127 | COL_VIEWERARROWS, 128 | 129 | COL_DIALOGLISTSCROLLBAR, 130 | COL_MENUSCROLLBAR, 131 | COL_VIEWERSCROLLBAR, 132 | COL_COMMANDLINEPREFIX, 133 | COL_DIALOGDISABLED, 134 | COL_DIALOGEDITDISABLED, 135 | COL_DIALOGLISTDISABLED, 136 | COL_WARNDIALOGDISABLED, 137 | COL_WARNDIALOGEDITDISABLED, 138 | COL_WARNDIALOGLISTDISABLED, 139 | 140 | COL_MENUDISABLEDTEXT, 141 | 142 | COL_EDITORCLOCK, 143 | COL_VIEWERCLOCK, 144 | 145 | COL_DIALOGLISTTITLE, 146 | COL_DIALOGLISTBOX, 147 | 148 | COL_WARNDIALOGEDITSELECTED, 149 | COL_WARNDIALOGEDITUNCHANGED, 150 | 151 | COL_DIALOGCOMBOTEXT, 152 | COL_DIALOGCOMBOSELECTEDTEXT, 153 | COL_DIALOGCOMBOHIGHLIGHT, 154 | COL_DIALOGCOMBOSELECTEDHIGHLIGHT, 155 | COL_DIALOGCOMBOBOX, 156 | COL_DIALOGCOMBOTITLE, 157 | COL_DIALOGCOMBODISABLED, 158 | COL_DIALOGCOMBOSCROLLBAR, 159 | 160 | COL_WARNDIALOGLISTTEXT, 161 | COL_WARNDIALOGLISTSELECTEDTEXT, 162 | COL_WARNDIALOGLISTHIGHLIGHT, 163 | COL_WARNDIALOGLISTSELECTEDHIGHLIGHT, 164 | COL_WARNDIALOGLISTBOX, 165 | COL_WARNDIALOGLISTTITLE, 166 | COL_WARNDIALOGLISTSCROLLBAR, 167 | 168 | COL_WARNDIALOGCOMBOTEXT, 169 | COL_WARNDIALOGCOMBOSELECTEDTEXT, 170 | COL_WARNDIALOGCOMBOHIGHLIGHT, 171 | COL_WARNDIALOGCOMBOSELECTEDHIGHLIGHT, 172 | COL_WARNDIALOGCOMBOBOX, 173 | COL_WARNDIALOGCOMBOTITLE, 174 | COL_WARNDIALOGCOMBODISABLED, 175 | COL_WARNDIALOGCOMBOSCROLLBAR, 176 | 177 | COL_DIALOGLISTARROWS, 178 | COL_DIALOGLISTARROWSDISABLED, 179 | COL_DIALOGLISTARROWSSELECTED, 180 | COL_DIALOGCOMBOARROWS, 181 | COL_DIALOGCOMBOARROWSDISABLED, 182 | COL_DIALOGCOMBOARROWSSELECTED, 183 | COL_WARNDIALOGLISTARROWS, 184 | COL_WARNDIALOGLISTARROWSDISABLED, 185 | COL_WARNDIALOGLISTARROWSSELECTED, 186 | COL_WARNDIALOGCOMBOARROWS, 187 | COL_WARNDIALOGCOMBOARROWSDISABLED, 188 | COL_WARNDIALOGCOMBOARROWSSELECTED, 189 | COL_MENUARROWS, 190 | COL_MENUARROWSDISABLED, 191 | COL_MENUARROWSSELECTED, 192 | COL_COMMANDLINEUSERSCREEN, 193 | COL_EDITORSCROLLBAR, 194 | 195 | COL_MENUGRAYTEXT, 196 | COL_MENUSELECTEDGRAYTEXT, 197 | COL_DIALOGCOMBOGRAY, 198 | COL_DIALOGCOMBOSELECTEDGRAYTEXT, 199 | COL_DIALOGLISTGRAY, 200 | COL_DIALOGLISTSELECTEDGRAYTEXT, 201 | COL_WARNDIALOGCOMBOGRAY, 202 | COL_WARNDIALOGCOMBOSELECTEDGRAYTEXT, 203 | COL_WARNDIALOGLISTGRAY, 204 | COL_WARNDIALOGLISTSELECTEDGRAYTEXT, 205 | 206 | COL_DIALOGDEFAULTBUTTON, 207 | COL_DIALOGSELECTEDDEFAULTBUTTON, 208 | COL_DIALOGHIGHLIGHTDEFAULTBUTTON, 209 | COL_DIALOGHIGHLIGHTSELECTEDDEFAULTBUTTON, 210 | COL_WARNDIALOGDEFAULTBUTTON, 211 | COL_WARNDIALOGSELECTEDDEFAULTBUTTON, 212 | COL_WARNDIALOGHIGHLIGHTDEFAULTBUTTON, 213 | COL_WARNDIALOGHIGHLIGHTSELECTEDDEFAULTBUTTON, 214 | 215 | COL_LASTPALETTECOLOR 216 | }; 217 | 218 | #endif // FARCOLOR_HPP_57151931_4591_44A5_92CF_8E51D1FBC57E 219 | -------------------------------------------------------------------------------- /depends/farhelpers/Far3Menu.hpp: -------------------------------------------------------------------------------- 1 | #ifndef Far3Menu_h__ 2 | #define Far3Menu_h__ 3 | 4 | #ifndef __cplusplus 5 | #error C++ only 6 | #endif 7 | 8 | typedef std::function MenuAction; 9 | 10 | #define OPT_STR_VAL(str) (!str.empty() ? str.c_str() : nullptr) 11 | #define PTR2STR(ptr) (ptr ? ptr : L"") 12 | 13 | class FarMenu 14 | { 15 | protected: 16 | const PluginStartupInfo* m_SInfo; 17 | 18 | GUID m_PluginId; 19 | GUID m_Id; 20 | FARMENUFLAGS m_Flags; 21 | intptr_t m_MaxHeight; 22 | std::wstring m_Title; 23 | std::wstring m_Bottom; 24 | std::wstring m_HelpTopic; 25 | 26 | std::vector m_Items; 27 | std::vector m_Actions; 28 | 29 | public: 30 | FarMenu(const PluginStartupInfo* SInfo, const GUID* aPluginId, const GUID* aId, const wchar_t* aTitle, const wchar_t* aBottom = nullptr) 31 | { 32 | m_SInfo = SInfo; 33 | 34 | m_PluginId = *aPluginId; 35 | m_Id = *aId; 36 | m_Title = PTR2STR(aTitle); 37 | m_Bottom = PTR2STR(aBottom); 38 | 39 | m_Flags = 0; 40 | m_MaxHeight = 0; 41 | } 42 | 43 | void SetMaxHeight(intptr_t aMaxHeight) { m_MaxHeight = aMaxHeight; } 44 | void SetFlags(FARMENUFLAGS aFlags) { m_Flags = aFlags; } 45 | void SetHelpTopic(const wchar_t* aHelpTopic) { m_HelpTopic = PTR2STR(aHelpTopic); } 46 | 47 | void AddItem(const wchar_t* aText, MENUITEMFLAGS aFlags = MIF_NONE, intptr_t aUserData = 0) 48 | { 49 | AddItemEx(aText, NULL, aFlags, aUserData); 50 | } 51 | 52 | void AddItemEx(const wchar_t* aText, MenuAction aAction, MENUITEMFLAGS aFlags = MIF_NONE, intptr_t aUserData = 0) 53 | { 54 | FarMenuItem item = {0}; 55 | 56 | item.Text = aText; 57 | item.Flags = aFlags; 58 | item.UserData = aUserData; 59 | 60 | m_Items.push_back(item); 61 | m_Actions.push_back(aAction); 62 | } 63 | 64 | void AddSeparator() 65 | { 66 | AddItem(nullptr, MIF_SEPARATOR); 67 | } 68 | 69 | void Clear() { m_Items.clear(); m_Actions.clear(); } 70 | 71 | size_t ItemCount() { return m_Items.size(); } 72 | 73 | // Returns index of selected menu item 74 | intptr_t Run() 75 | { 76 | return m_SInfo->Menu(&m_PluginId, &m_Id, -1, -1, m_MaxHeight, m_Flags, OPT_STR_VAL(m_Title), OPT_STR_VAL(m_Bottom), OPT_STR_VAL(m_HelpTopic), nullptr, nullptr, &m_Items[0], m_Items.size()); 77 | } 78 | 79 | bool RunEx() 80 | { 81 | intptr_t rc = Run(); 82 | if (rc >= 0) 83 | { 84 | // Execute bound action 85 | if (rc <= (intptr_t) m_Actions.size()) 86 | { 87 | MenuAction &action = m_Actions[rc]; 88 | FarMenuItem &item = m_Items[rc]; 89 | if (action) action(item.UserData); 90 | } 91 | return true; 92 | } 93 | 94 | return false; 95 | } 96 | }; 97 | 98 | #endif // Far3Menu_h__ 99 | -------------------------------------------------------------------------------- /depends/rhash/librhash/aich.h: -------------------------------------------------------------------------------- 1 | /* aich.h */ 2 | #ifndef AICH_H 3 | #define AICH_H 4 | #include "sha1.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /* algorithm context */ 11 | typedef struct aich_ctx 12 | { 13 | sha1_ctx sha1_context; /* context used to hash tree leaves */ 14 | #if defined(USE_OPENSSL) || defined(OPENSSL_RUNTIME) 15 | unsigned long reserved; /* need more space for openssl sha1 context */ 16 | void (*sha_init)(void*); 17 | void (*sha_update)(void*, const void*, size_t size); 18 | void (*sha_final)(void*, unsigned char*); 19 | #endif 20 | unsigned index; /* algorithm position in the current ed2k chunk */ 21 | unsigned char (*block_hashes)[sha1_hash_size]; 22 | 23 | void** chunk_table; /* table of chunk hashes */ 24 | size_t allocated; /* allocated size of the chunk_table */ 25 | size_t chunks_number; /* number of ed2k chunks hashed */ 26 | int error; /* non-zero if a memory error occurred, 0 otherwise */ 27 | } aich_ctx; 28 | 29 | /* hash functions */ 30 | 31 | void rhash_aich_init(aich_ctx* ctx); 32 | void rhash_aich_update(aich_ctx* ctx, const unsigned char* msg, size_t size); 33 | void rhash_aich_final(aich_ctx* ctx, unsigned char result[20]); 34 | 35 | /* Clean up context by freeing allocated memory. 36 | * The function is called automatically by rhash_aich_final. 37 | * Shall be called when aborting hash calculations. */ 38 | void rhash_aich_cleanup(aich_ctx* ctx); 39 | 40 | #ifdef __cplusplus 41 | } /* extern "C" */ 42 | #endif /* __cplusplus */ 43 | 44 | #endif /* AICH_H */ 45 | -------------------------------------------------------------------------------- /depends/rhash/librhash/algorithms.h: -------------------------------------------------------------------------------- 1 | /* algorithms.h - rhash library algorithms */ 2 | #ifndef RHASH_ALGORITHMS_H 3 | #define RHASH_ALGORITHMS_H 4 | 5 | #include "rhash.h" 6 | #include "byte_order.h" 7 | #include 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | #ifndef RHASH_API 14 | /* modifier for RHash library functions */ 15 | # define RHASH_API 16 | #endif 17 | 18 | /** 19 | * Bit flag: default hash output format is base32. 20 | */ 21 | #define RHASH_INFO_BASE32 1 22 | 23 | /** 24 | * Information about a hash function. 25 | */ 26 | typedef struct rhash_info 27 | { 28 | /** 29 | * Hash function indentifier. 30 | */ 31 | unsigned hash_id; 32 | /** 33 | * Flags bit-mask, including RHASH_INFO_BASE32 bit. 34 | */ 35 | unsigned flags; 36 | /** 37 | The size of of the raw message digest in bytes. 38 | */ 39 | size_t digest_size; 40 | /** 41 | * The hash function name. 42 | */ 43 | const char* name; 44 | /** 45 | * The corresponding paramenter name in a magnet link. 46 | */ 47 | const char* magnet_name; 48 | } rhash_info; 49 | 50 | typedef void (*pinit_t)(void*); 51 | typedef void (*pupdate_t)(void* ctx, const void* msg, size_t size); 52 | typedef void (*pfinal_t)(void*, unsigned char*); 53 | typedef void (*pcleanup_t)(void*); 54 | 55 | /** 56 | * Information about a hash function 57 | */ 58 | typedef struct rhash_hash_info 59 | { 60 | rhash_info* info; 61 | size_t context_size; 62 | ptrdiff_t digest_diff; 63 | pinit_t init; 64 | pupdate_t update; 65 | pfinal_t final; 66 | pcleanup_t cleanup; 67 | } rhash_hash_info; 68 | 69 | /** 70 | * Information on a hash function and its context 71 | */ 72 | typedef struct rhash_vector_item 73 | { 74 | struct rhash_hash_info* hash_info; 75 | void* context; 76 | } rhash_vector_item; 77 | 78 | /** 79 | * The rhash context containing contexts for several hash functions 80 | */ 81 | typedef struct rhash_context_ext 82 | { 83 | struct rhash_context rc; 84 | unsigned hash_vector_size; /* number of contained hash sums */ 85 | unsigned flags; 86 | volatile unsigned state; 87 | rhash_callback_t callback; 88 | void* callback_data; 89 | void* bt_ctx; 90 | rhash_vector_item vector[]; /* contexts of contained hash sums */ 91 | } rhash_context_ext; 92 | 93 | extern rhash_hash_info rhash_hash_info_default[RHASH_HASH_COUNT]; 94 | extern rhash_hash_info* rhash_info_table; 95 | extern int rhash_info_size; 96 | extern unsigned rhash_uninitialized_algorithms; 97 | 98 | extern rhash_info info_crc32; 99 | extern rhash_info info_crc32c; 100 | extern rhash_info info_md4; 101 | extern rhash_info info_md5; 102 | extern rhash_info info_sha1; 103 | extern rhash_info info_tiger; 104 | extern rhash_info info_tth ; 105 | extern rhash_info info_btih; 106 | extern rhash_info info_ed2k; 107 | extern rhash_info info_aich; 108 | extern rhash_info info_whirlpool; 109 | extern rhash_info info_rmd160; 110 | extern rhash_info info_gost; 111 | extern rhash_info info_gostpro; 112 | extern rhash_info info_has160; 113 | extern rhash_info info_snf128; 114 | extern rhash_info info_snf256; 115 | extern rhash_info info_sha224; 116 | extern rhash_info info_sha256; 117 | extern rhash_info info_sha384; 118 | extern rhash_info info_sha512; 119 | extern rhash_info info_sha3_224; 120 | extern rhash_info info_sha3_256; 121 | extern rhash_info info_sha3_384; 122 | extern rhash_info info_sha3_512; 123 | extern rhash_info info_edr256; 124 | extern rhash_info info_edr512; 125 | 126 | /* rhash_info flags */ 127 | #define F_BS32 1 /* default output in base32 */ 128 | #define F_SWAP32 2 /* Big endian flag */ 129 | #define F_SWAP64 4 130 | 131 | /* define endianness flags */ 132 | #if IS_LITTLE_ENDIAN 133 | #define F_LE32 0 134 | #define F_LE64 0 135 | #define F_BE32 F_SWAP32 136 | #define F_BE64 F_SWAP64 137 | #else 138 | #define F_LE32 F_SWAP32 139 | #define F_LE64 F_SWAP64 140 | #define F_BE32 0 141 | #define F_BE64 0 142 | #endif 143 | 144 | void rhash_init_algorithms(unsigned mask); 145 | const rhash_info* rhash_info_by_id(unsigned hash_id); /* get hash sum info by hash id */ 146 | 147 | #if defined(OPENSSL_RUNTIME) && !defined(USE_OPENSSL) 148 | # define USE_OPENSSL 149 | #endif 150 | 151 | #ifdef __cplusplus 152 | } /* extern "C" */ 153 | #endif /* __cplusplus */ 154 | 155 | #endif /* RHASH_ALGORITHMS_H */ 156 | -------------------------------------------------------------------------------- /depends/rhash/librhash/blake2b.c: -------------------------------------------------------------------------------- 1 | /* blake2b.c - an implementation of blake2b hash function. 2 | * 3 | * Copyright (c) 2012, Samuel Neves 4 | * Copyright (c) 2021, Aleksey Kravchenko 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 10 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 | * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 | * PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #include "blake2b.h" 19 | #include "byte_order.h" 20 | #include 21 | 22 | static const uint64_t blake2b_IV[8] = 23 | { 24 | I64(0x6a09e667f3bcc908), I64(0xbb67ae8584caa73b), 25 | I64(0x3c6ef372fe94f82b), I64(0xa54ff53a5f1d36f1), 26 | I64(0x510e527fade682d1), I64(0x9b05688c2b3e6c1f), 27 | I64(0x1f83d9abfb41bd6b), I64(0x5be0cd19137e2179) 28 | }; 29 | 30 | static const uint8_t blake2b_sigma[12][16] = 31 | { 32 | { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, 33 | { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 }, 34 | { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 }, 35 | { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 }, 36 | { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 }, 37 | { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 }, 38 | { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 }, 39 | { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 }, 40 | { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 }, 41 | { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 }, 42 | { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, 43 | { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 } 44 | }; 45 | 46 | void rhash_blake2b_init(blake2b_ctx* ctx) 47 | { 48 | memset(ctx, 0, sizeof(*ctx)); 49 | /* init state by xoring IV with blake2b input parameter block */ 50 | ctx->hash[0] = blake2b_IV[0] ^ I64(0x01010040); 51 | ctx->hash[1] = blake2b_IV[1]; 52 | ctx->hash[2] = blake2b_IV[2]; 53 | ctx->hash[3] = blake2b_IV[3]; 54 | ctx->hash[4] = blake2b_IV[4]; 55 | ctx->hash[5] = blake2b_IV[5]; 56 | ctx->hash[6] = blake2b_IV[6]; 57 | ctx->hash[7] = blake2b_IV[7]; 58 | } 59 | 60 | #define G(r,i,a,b,c,d) \ 61 | do { \ 62 | a = a + b + m[blake2b_sigma[r][2*i+0]]; \ 63 | d = ROTR64(d ^ a, 32); \ 64 | c = c + d; \ 65 | b = ROTR64(b ^ c, 24); \ 66 | a = a + b + m[blake2b_sigma[r][2*i+1]]; \ 67 | d = ROTR64(d ^ a, 16); \ 68 | c = c + d; \ 69 | b = ROTR64(b ^ c, 63); \ 70 | } while(0) 71 | 72 | #define ROUND(r) \ 73 | do { \ 74 | G(r,0,v[0],v[4],v[ 8],v[12]); \ 75 | G(r,1,v[1],v[5],v[ 9],v[13]); \ 76 | G(r,2,v[2],v[6],v[10],v[14]); \ 77 | G(r,3,v[3],v[7],v[11],v[15]); \ 78 | G(r,4,v[0],v[5],v[10],v[15]); \ 79 | G(r,5,v[1],v[6],v[11],v[12]); \ 80 | G(r,6,v[2],v[7],v[ 8],v[13]); \ 81 | G(r,7,v[3],v[4],v[ 9],v[14]); \ 82 | } while(0) 83 | 84 | static void rhash_blake2b_process_block(blake2b_ctx* ctx, const uint64_t* m, uint64_t finalization_flag) 85 | { 86 | uint64_t v[16]; 87 | size_t i; 88 | 89 | memcpy(v, ctx->hash, sizeof(uint64_t) * 8); 90 | v[ 8] = blake2b_IV[0]; 91 | v[ 9] = blake2b_IV[1]; 92 | v[10] = blake2b_IV[2]; 93 | v[11] = blake2b_IV[3]; 94 | v[12] = blake2b_IV[4] ^ ctx->length; /* length correction */ 95 | v[13] = blake2b_IV[5]; 96 | v[14] = blake2b_IV[6] ^ finalization_flag; 97 | v[15] = blake2b_IV[7]; 98 | 99 | ROUND(0); 100 | ROUND(1); 101 | ROUND(2); 102 | ROUND(3); 103 | ROUND(4); 104 | ROUND(5); 105 | ROUND(6); 106 | ROUND(7); 107 | ROUND(8); 108 | ROUND(9); 109 | ROUND(10); 110 | ROUND(11); 111 | 112 | for(i = 0; i < 8; ++i) 113 | ctx->hash[i] ^= v[i] ^ v[i + 8]; 114 | } 115 | 116 | void rhash_blake2b_update(blake2b_ctx* ctx, const unsigned char* msg, size_t size) 117 | { 118 | if(size > 0) 119 | { 120 | size_t index = (size_t)ctx->length & 127; 121 | if(index) 122 | { 123 | size_t rest = blake2b_block_size - index; 124 | if (size > rest) { 125 | le64_copy(ctx->message, index, msg, rest); /* fill the block */ 126 | 127 | /* process the block */ 128 | size -= rest; 129 | msg += rest; 130 | ctx->length += rest; 131 | index = 0; 132 | rhash_blake2b_process_block(ctx, ctx->message, I64(0)); 133 | } 134 | } else if (ctx->length) { 135 | rhash_blake2b_process_block(ctx, ctx->message, I64(0)); 136 | } 137 | while(size > blake2b_block_size) { 138 | uint64_t* aligned_message_block; 139 | if (IS_LITTLE_ENDIAN && IS_ALIGNED_64(msg)) { 140 | aligned_message_block = (uint64_t*)msg; 141 | } else { 142 | le64_copy(ctx->message, 0, msg, blake2b_block_size); 143 | aligned_message_block = ctx->message; 144 | } 145 | size -= blake2b_block_size; 146 | msg += blake2b_block_size; 147 | ctx->length += blake2b_block_size; 148 | rhash_blake2b_process_block(ctx, aligned_message_block, I64(0)); 149 | } 150 | le64_copy(ctx->message, index, msg, size); /* save leftovers */ 151 | ctx->length += size; 152 | } 153 | } 154 | 155 | void rhash_blake2b_final(blake2b_ctx* ctx, unsigned char *result) 156 | { 157 | size_t length = (size_t)ctx->length & 127; 158 | if (length) 159 | { 160 | /* pad the message with zeros */ 161 | size_t index = length >> 3; 162 | size_t shift = (length & 7) * 8; 163 | ctx->message[index] &= ~(I64(0xFFFFFFFFFFFFFFFF) << shift); 164 | for(index++; index < 16; index++) 165 | ctx->message[index] = 0; 166 | } 167 | rhash_blake2b_process_block(ctx, ctx->message, I64(0xFFFFFFFFFFFFFFFF)); 168 | 169 | /* convert hash state to result bytes */ 170 | le64_copy(result, 0, ctx->hash, blake2b_hash_size); 171 | } 172 | -------------------------------------------------------------------------------- /depends/rhash/librhash/blake2b.h: -------------------------------------------------------------------------------- 1 | /* blake2b.h */ 2 | #ifndef BLAKE2B_H 3 | #define BLAKE2B_H 4 | #include "ustd.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #define blake2b_block_size 128 11 | #define blake2b_hash_size 64 12 | 13 | typedef struct blake2b_ctx 14 | { 15 | uint64_t hash[8]; 16 | uint64_t message[16]; 17 | uint64_t length; 18 | } blake2b_ctx; 19 | 20 | void rhash_blake2b_init(blake2b_ctx* ctx); 21 | void rhash_blake2b_update(blake2b_ctx* ctx, const unsigned char* msg, size_t size); 22 | void rhash_blake2b_final(blake2b_ctx* ctx, unsigned char* result); 23 | 24 | #ifdef __cplusplus 25 | } /* extern "C" */ 26 | #endif /* __cplusplus */ 27 | 28 | #endif /* BLAKE2B_H */ 29 | -------------------------------------------------------------------------------- /depends/rhash/librhash/blake2s.c: -------------------------------------------------------------------------------- 1 | /* blake2s.c - an implementation of blake2s hash function. 2 | * 3 | * Copyright (c) 2012, Samuel Neves 4 | * Copyright (c) 2021, Aleksey Kravchenko 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 10 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 | * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 | * PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #include "blake2s.h" 19 | #include "byte_order.h" 20 | #include 21 | 22 | static const uint32_t blake2s_IV[8] = 23 | { 24 | 0x6A09E667UL, 0xBB67AE85UL, 0x3C6EF372UL, 0xA54FF53AUL, 25 | 0x510E527FUL, 0x9B05688CUL, 0x1F83D9ABUL, 0x5BE0CD19UL 26 | }; 27 | 28 | static const uint8_t blake2s_sigma[10][16] = 29 | { 30 | { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, 31 | { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 }, 32 | { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 }, 33 | { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 }, 34 | { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 }, 35 | { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 }, 36 | { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 }, 37 | { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 }, 38 | { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 }, 39 | { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 }, 40 | }; 41 | 42 | void rhash_blake2s_init(blake2s_ctx* ctx) 43 | { 44 | memset(ctx, 0, sizeof(*ctx)); 45 | /* init state by xoring IV with blake2s input parameter block */ 46 | ctx->hash[0] = blake2s_IV[0] ^ 0x01010020; 47 | ctx->hash[1] = blake2s_IV[1]; 48 | ctx->hash[2] = blake2s_IV[2]; 49 | ctx->hash[3] = blake2s_IV[3]; 50 | ctx->hash[4] = blake2s_IV[4]; 51 | ctx->hash[5] = blake2s_IV[5]; 52 | ctx->hash[6] = blake2s_IV[6]; 53 | ctx->hash[7] = blake2s_IV[7]; 54 | } 55 | 56 | #define G(r,i,a,b,c,d) \ 57 | do { \ 58 | a = a + b + m[blake2s_sigma[r][2*i+0]]; \ 59 | d = ROTR32(d ^ a, 16); \ 60 | c = c + d; \ 61 | b = ROTR32(b ^ c, 12); \ 62 | a = a + b + m[blake2s_sigma[r][2*i+1]]; \ 63 | d = ROTR32(d ^ a, 8); \ 64 | c = c + d; \ 65 | b = ROTR32(b ^ c, 7); \ 66 | } while(0) 67 | 68 | #define ROUND(r) \ 69 | do { \ 70 | G(r,0,v[0],v[4],v[ 8],v[12]); \ 71 | G(r,1,v[1],v[5],v[ 9],v[13]); \ 72 | G(r,2,v[2],v[6],v[10],v[14]); \ 73 | G(r,3,v[3],v[7],v[11],v[15]); \ 74 | G(r,4,v[0],v[5],v[10],v[15]); \ 75 | G(r,5,v[1],v[6],v[11],v[12]); \ 76 | G(r,6,v[2],v[7],v[ 8],v[13]); \ 77 | G(r,7,v[3],v[4],v[ 9],v[14]); \ 78 | } while(0) 79 | 80 | static void rhash_blake2s_process_block(blake2s_ctx* ctx, const uint32_t* m, uint32_t finalization_flag) 81 | { 82 | uint32_t v[16]; 83 | size_t i; 84 | 85 | memcpy(v, ctx->hash, sizeof(uint32_t) * 8); 86 | v[ 8] = blake2s_IV[0]; 87 | v[ 9] = blake2s_IV[1]; 88 | v[10] = blake2s_IV[2]; 89 | v[11] = blake2s_IV[3]; 90 | v[12] = blake2s_IV[4] ^ (uint32_t)ctx->length; 91 | v[13] = blake2s_IV[5] ^ (uint32_t)(ctx->length >> 32); 92 | v[14] = blake2s_IV[6] ^ finalization_flag; 93 | v[15] = blake2s_IV[7]; 94 | 95 | ROUND(0); 96 | ROUND(1); 97 | ROUND(2); 98 | ROUND(3); 99 | ROUND(4); 100 | ROUND(5); 101 | ROUND(6); 102 | ROUND(7); 103 | ROUND(8); 104 | ROUND(9); 105 | 106 | for(i = 0; i < 8; ++i) 107 | ctx->hash[i] ^= v[i] ^ v[i + 8]; 108 | } 109 | 110 | void rhash_blake2s_update(blake2s_ctx* ctx, const unsigned char* msg, size_t size) 111 | { 112 | if(size > 0) 113 | { 114 | size_t index = (size_t)ctx->length & 63; 115 | if(index) 116 | { 117 | size_t rest = blake2s_block_size - index; 118 | if (size > rest) { 119 | le32_copy(ctx->message, index, msg, rest); /* fill the block */ 120 | 121 | /* process the block */ 122 | size -= rest; 123 | msg += rest; 124 | ctx->length += rest; 125 | index = 0; 126 | rhash_blake2s_process_block(ctx, ctx->message, 0); 127 | } 128 | } else if (ctx->length) { 129 | rhash_blake2s_process_block(ctx, ctx->message, 0); 130 | } 131 | while(size > blake2s_block_size) { 132 | uint32_t* aligned_message_block; 133 | if (IS_LITTLE_ENDIAN && IS_ALIGNED_32(msg)) { 134 | aligned_message_block = (uint32_t*)msg; 135 | } else { 136 | le32_copy(ctx->message, 0, msg, blake2s_block_size); 137 | aligned_message_block = ctx->message; 138 | } 139 | size -= blake2s_block_size; 140 | msg += blake2s_block_size; 141 | ctx->length += blake2s_block_size; 142 | rhash_blake2s_process_block(ctx, aligned_message_block, 0); 143 | } 144 | le32_copy(ctx->message, index, msg, size); /* save leftovers */ 145 | ctx->length += size; 146 | } 147 | } 148 | 149 | void rhash_blake2s_final(blake2s_ctx* ctx, unsigned char *result) 150 | { 151 | size_t length = (size_t)ctx->length & 63; 152 | if (length) 153 | { 154 | /* pad the message with zeros */ 155 | size_t index = length >> 2; 156 | unsigned shift = (unsigned)(length & 3) * 8; 157 | ctx->message[index] &= ~(0xFFFFFFFFu << shift); 158 | for(index++; index < 16; index++) 159 | ctx->message[index] = 0; 160 | } 161 | rhash_blake2s_process_block(ctx, ctx->message, 0xFFFFFFFFu); 162 | 163 | /* convert hash state to result bytes */ 164 | le32_copy(result, 0, ctx->hash, blake2s_hash_size); 165 | } 166 | -------------------------------------------------------------------------------- /depends/rhash/librhash/blake2s.h: -------------------------------------------------------------------------------- 1 | /* blake2s.h */ 2 | #ifndef BLAKE2S_H 3 | #define BLAKE2S_H 4 | #include "ustd.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #define blake2s_block_size 64 11 | #define blake2s_hash_size 32 12 | 13 | typedef struct blake2s_ctx 14 | { 15 | uint32_t hash[8]; 16 | uint32_t message[16]; 17 | uint64_t length; 18 | } blake2s_ctx; 19 | 20 | void rhash_blake2s_init(blake2s_ctx* ctx); 21 | void rhash_blake2s_update(blake2s_ctx* ctx, const unsigned char* msg, size_t size); 22 | void rhash_blake2s_final(blake2s_ctx* ctx, unsigned char* result); 23 | 24 | #ifdef __cplusplus 25 | } /* extern "C" */ 26 | #endif /* __cplusplus */ 27 | 28 | #endif /* BLAKE2S_H */ 29 | -------------------------------------------------------------------------------- /depends/rhash/librhash/byte_order.c: -------------------------------------------------------------------------------- 1 | /* byte_order.c - byte order related platform dependent routines, 2 | * 3 | * Copyright (c) 2008, Aleksey Kravchenko 4 | * 5 | * Permission to use, copy, modify, and/or distribute this software for any 6 | * purpose with or without fee is hereby granted. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 9 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 | * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 11 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 13 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 | * PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | #include "byte_order.h" 17 | 18 | #ifndef rhash_ctz 19 | 20 | # if _MSC_VER >= 1300 && (_M_IX86 || _M_AMD64 || _M_IA64) /* if MSVC++ >= 2002 on x86/x64 */ 21 | # include 22 | # pragma intrinsic(_BitScanForward) 23 | 24 | /** 25 | * Returns index of the trailing bit of x. 26 | * 27 | * @param x the number to process 28 | * @return zero-based index of the trailing bit 29 | */ 30 | unsigned rhash_ctz(unsigned x) 31 | { 32 | unsigned long index; 33 | unsigned char isNonzero = _BitScanForward(&index, x); /* MSVC intrinsic */ 34 | return (isNonzero ? (unsigned)index : 0); 35 | } 36 | # else /* _MSC_VER >= 1300... */ 37 | 38 | /** 39 | * Returns index of the trailing bit of a 32-bit number. 40 | * This is a plain C equivalent for GCC __builtin_ctz() bit scan. 41 | * 42 | * @param x the number to process 43 | * @return zero-based index of the trailing bit 44 | */ 45 | unsigned rhash_ctz(unsigned x) 46 | { 47 | /* array for conversion to bit position */ 48 | static unsigned char bit_pos[32] = { 49 | 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 50 | 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9 51 | }; 52 | 53 | /* The De Bruijn bit-scan was devised in 1997, according to Donald Knuth 54 | * by Martin Lauter. The constant 0x077CB531UL is a De Bruijn sequence, 55 | * which produces a unique pattern of bits into the high 5 bits for each 56 | * possible bit position that it is multiplied against. 57 | * See http://graphics.stanford.edu/~seander/bithacks.html 58 | * and http://chessprogramming.wikispaces.com/BitScan */ 59 | return (unsigned)bit_pos[((uint32_t)((x & -x) * 0x077CB531U)) >> 27]; 60 | } 61 | # endif /* _MSC_VER >= 1300... */ 62 | #endif /* rhash_ctz */ 63 | 64 | /** 65 | * Copy a memory block with simultaneous exchanging byte order. 66 | * The byte order is changed from little-endian 32-bit integers 67 | * to big-endian (or vice-versa). 68 | * 69 | * @param to the pointer where to copy memory block 70 | * @param index the index to start writing from 71 | * @param from the source block to copy 72 | * @param length length of the memory block 73 | */ 74 | void rhash_swap_copy_str_to_u32(void* to, int index, const void* from, size_t length) 75 | { 76 | /* if all pointers and length are 32-bits aligned */ 77 | if ( 0 == (( (uintptr_t)to | (uintptr_t)from | (uintptr_t)index | length ) & 3) ) { 78 | /* copy memory as 32-bit words */ 79 | const uint32_t* src = (const uint32_t*)from; 80 | const uint32_t* end = (const uint32_t*)((const char*)src + length); 81 | uint32_t* dst = (uint32_t*)((char*)to + index); 82 | for (; src < end; dst++, src++) 83 | *dst = bswap_32(*src); 84 | } else { 85 | const char* src = (const char*)from; 86 | for (length += index; (size_t)index < length; index++) 87 | ((char*)to)[index ^ 3] = *(src++); 88 | } 89 | } 90 | 91 | /** 92 | * Copy a memory block with changed byte order. 93 | * The byte order is changed from little-endian 64-bit integers 94 | * to big-endian (or vice-versa). 95 | * 96 | * @param to the pointer where to copy memory block 97 | * @param index the index to start writing from 98 | * @param from the source block to copy 99 | * @param length length of the memory block 100 | */ 101 | void rhash_swap_copy_str_to_u64(void* to, int index, const void* from, size_t length) 102 | { 103 | /* if all pointers and length are 64-bits aligned */ 104 | if ( 0 == (( (uintptr_t)to | (uintptr_t)from | (uintptr_t)index | length ) & 7) ) { 105 | /* copy aligned memory block as 64-bit integers */ 106 | const uint64_t* src = (const uint64_t*)from; 107 | const uint64_t* end = (const uint64_t*)((const char*)src + length); 108 | uint64_t* dst = (uint64_t*)((char*)to + index); 109 | while (src < end) *(dst++) = bswap_64( *(src++) ); 110 | } else { 111 | const char* src = (const char*)from; 112 | for (length += index; (size_t)index < length; index++) ((char*)to)[index ^ 7] = *(src++); 113 | } 114 | } 115 | 116 | /** 117 | * Copy data from a sequence of 64-bit words to a binary string of given length, 118 | * while changing byte order. 119 | * 120 | * @param to the binary string to receive data 121 | * @param from the source sequence of 64-bit words 122 | * @param length the size in bytes of the data being copied 123 | */ 124 | void rhash_swap_copy_u64_to_str(void* to, const void* from, size_t length) 125 | { 126 | /* if all pointers and length are 64-bits aligned */ 127 | if ( 0 == (( (uintptr_t)to | (uintptr_t)from | length ) & 7) ) { 128 | /* copy aligned memory block as 64-bit integers */ 129 | const uint64_t* src = (const uint64_t*)from; 130 | const uint64_t* end = (const uint64_t*)((const char*)src + length); 131 | uint64_t* dst = (uint64_t*)to; 132 | while (src < end) *(dst++) = bswap_64( *(src++) ); 133 | } else { 134 | size_t index; 135 | char* dst = (char*)to; 136 | for (index = 0; index < length; index++) *(dst++) = ((char*)from)[index ^ 7]; 137 | } 138 | } 139 | 140 | /** 141 | * Exchange byte order in the given array of 32-bit integers. 142 | * 143 | * @param arr the array to process 144 | * @param length array length 145 | */ 146 | void rhash_u32_mem_swap(unsigned* arr, int length) 147 | { 148 | unsigned* end = arr + length; 149 | for (; arr < end; arr++) { 150 | *arr = bswap_32(*arr); 151 | } 152 | } 153 | 154 | #ifdef HAS_INTEL_CPUID 155 | #include 156 | 157 | static uint64_t get_cpuid_features(void) 158 | { 159 | uint32_t tmp, edx, ecx; 160 | if (__get_cpuid(1, &tmp, &tmp, &ecx, &edx)) 161 | return ((((uint64_t)ecx) << 32) ^ edx); 162 | return 0; 163 | } 164 | 165 | int has_cpu_feature(unsigned feature_bit) 166 | { 167 | static uint64_t features; 168 | const uint64_t feature = ((uint64_t)1) << feature_bit; 169 | if (!features) 170 | features = (get_cpuid_features() | 1); 171 | return !!(features & feature); 172 | } 173 | #endif 174 | -------------------------------------------------------------------------------- /depends/rhash/librhash/crc32.h: -------------------------------------------------------------------------------- 1 | /* crc32.h */ 2 | #ifndef CRC32_H 3 | #define CRC32_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | /* hash functions */ 10 | 11 | #ifndef DISABLE_CRC32 12 | unsigned rhash_get_crc32(unsigned crcinit, const unsigned char* msg, size_t size); 13 | #endif 14 | 15 | #ifndef DISABLE_CRC32C 16 | unsigned rhash_get_crc32c(unsigned crcinit, const unsigned char* msg, size_t size); 17 | #endif 18 | 19 | #ifdef __cplusplus 20 | } /* extern "C" */ 21 | #endif /* __cplusplus */ 22 | 23 | #endif /* CRC32_H */ 24 | -------------------------------------------------------------------------------- /depends/rhash/librhash/ed2k.c: -------------------------------------------------------------------------------- 1 | /* ed2k.c - an implementation of EDonkey 2000 Hash Algorithm. 2 | * 3 | * Copyright (c) 2006, Aleksey Kravchenko 4 | * 5 | * Permission to use, copy, modify, and/or distribute this software for any 6 | * purpose with or without fee is hereby granted. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 9 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 | * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 11 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 13 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 | * PERFORMANCE OF THIS SOFTWARE. 15 | * 16 | * This file implements eMule-compatible version of algorithm. 17 | * Note that eDonkey and eMule ed2k hashes are different only for 18 | * files containing exactly multiple of 9728000 bytes. 19 | * 20 | * The file data is divided into full chunks of 9500 KiB (9728000 bytes) plus 21 | * a remainder chunk, and a separate 128-bit MD4 hash is computed for each. 22 | * If the file length is an exact multiple of 9500 KiB, the remainder zero 23 | * size chunk is still used at the end of the hash list. The ed2k hash is 24 | * computed by concatenating the chunks' MD4 hashes in order and hashing the 25 | * result using MD4. Although, if the file is composed of a single non-full 26 | * chunk, its MD4 hash is returned with no further modifications. 27 | * 28 | * See http://en.wikipedia.org/wiki/EDonkey_network for algorithm description. 29 | */ 30 | 31 | #include 32 | #include "ed2k.h" 33 | 34 | /* each hashed file is divided into 9500 KiB sized chunks */ 35 | #define ED2K_CHUNK_SIZE 9728000 36 | 37 | /** 38 | * Initialize context before calculaing hash. 39 | * 40 | * @param ctx context to initialize 41 | */ 42 | void rhash_ed2k_init(ed2k_ctx* ctx) 43 | { 44 | rhash_md4_init(&ctx->md4_context); 45 | rhash_md4_init(&ctx->md4_context_inner); 46 | ctx->not_emule = 0; 47 | } 48 | 49 | /** 50 | * Calculate message hash. 51 | * Can be called repeatedly with chunks of the message to be hashed. 52 | * 53 | * @param ctx the algorithm context containing current hashing state 54 | * @param msg message chunk 55 | * @param size length of the message chunk 56 | */ 57 | void rhash_ed2k_update(ed2k_ctx* ctx, const unsigned char* msg, size_t size) 58 | { 59 | unsigned char chunk_md4_hash[16]; 60 | unsigned blockleft = ED2K_CHUNK_SIZE - (unsigned)ctx->md4_context_inner.length; 61 | 62 | /* note: eMule-compatible algorithm hashes by md4_inner 63 | * the messages which sizes are multiple of 9728000 64 | * and then processes obtained hash by external md4 */ 65 | 66 | while ( size >= blockleft ) 67 | { 68 | if (size == blockleft && ctx->not_emule) break; 69 | 70 | /* if internal ed2k chunk is full, then finalize it */ 71 | rhash_md4_update(&ctx->md4_context_inner, msg, blockleft); 72 | msg += blockleft; 73 | size -= blockleft; 74 | blockleft = ED2K_CHUNK_SIZE; 75 | 76 | /* just finished an ed2k chunk, updating md4_external context */ 77 | rhash_md4_final(&ctx->md4_context_inner, chunk_md4_hash); 78 | rhash_md4_update(&ctx->md4_context, chunk_md4_hash, 16); 79 | rhash_md4_init(&ctx->md4_context_inner); 80 | } 81 | 82 | if (size) { 83 | /* hash leftovers */ 84 | rhash_md4_update(&ctx->md4_context_inner, msg, size); 85 | } 86 | } 87 | 88 | /** 89 | * Store calculated hash into the given array. 90 | * 91 | * @param ctx the algorithm context containing current hashing state 92 | * @param result calculated hash in binary form 93 | */ 94 | void rhash_ed2k_final(ed2k_ctx* ctx, unsigned char result[16]) 95 | { 96 | /* check if hashed message size is greater or equal to ED2K_CHUNK_SIZE */ 97 | if ( ctx->md4_context.length ) { 98 | 99 | /* note: weird eMule algorithm always processes the inner 100 | * md4 context, no matter if it contains data or is empty */ 101 | 102 | /* if any data are left in the md4_context_inner */ 103 | if ( (size_t)ctx->md4_context_inner.length > 0 || !ctx->not_emule) 104 | { 105 | /* emule algorithm processes aditional block, even if it's empty */ 106 | unsigned char md4_digest_inner[16]; 107 | rhash_md4_final(&ctx->md4_context_inner, md4_digest_inner); 108 | rhash_md4_update(&ctx->md4_context, md4_digest_inner, 16); 109 | } 110 | /* first call final to flush md4 buffer and finalize the hash value */ 111 | rhash_md4_final(&ctx->md4_context, result); 112 | /* store the calculated ed2k hash in the md4_context_inner.hash */ 113 | memcpy(&ctx->md4_context_inner.hash, &ctx->md4_context.hash, md4_hash_size); 114 | } else { 115 | /* return just the message MD4 hash */ 116 | if (result) rhash_md4_final(&ctx->md4_context_inner, result); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /depends/rhash/librhash/ed2k.h: -------------------------------------------------------------------------------- 1 | /* ed2k.h */ 2 | #ifndef ED2K_H 3 | #define ED2K_H 4 | #include "md4.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /* algorithm context */ 11 | typedef struct ed2k_ctx 12 | { 13 | md4_ctx md4_context_inner; /* md4 context to hash file blocks */ 14 | md4_ctx md4_context; /* md4 context to hash block hashes */ 15 | int not_emule; /* flag: 0 for emule ed2k algorithm */ 16 | } ed2k_ctx; 17 | 18 | /* hash functions */ 19 | 20 | void rhash_ed2k_init(ed2k_ctx* ctx); 21 | void rhash_ed2k_update(ed2k_ctx* ctx, const unsigned char* msg, size_t size); 22 | void rhash_ed2k_final(ed2k_ctx* ctx, unsigned char result[16]); 23 | 24 | #ifdef __cplusplus 25 | } /* extern "C" */ 26 | #endif /* __cplusplus */ 27 | 28 | #endif /* ED2K_H */ 29 | -------------------------------------------------------------------------------- /depends/rhash/librhash/edonr.h: -------------------------------------------------------------------------------- 1 | /* edonr.h EDON-R 224/256/384/512 hash functions */ 2 | #ifndef EDONR_H 3 | #define EDONR_H 4 | #include "ustd.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #define edonr224_hash_size 28 11 | #define edonr256_hash_size 32 12 | #define edonr256_block_size 64 13 | 14 | #define edonr384_hash_size 48 15 | #define edonr512_hash_size 64 16 | #define edonr512_block_size 128 17 | 18 | struct edonr256_data { 19 | unsigned message[16]; /* 512-bit buffer for leftovers */ 20 | unsigned hash[16]; /* 512-bit algorithm internal hashing state */ 21 | }; 22 | 23 | struct edonr512_data { 24 | uint64_t message[16]; /* 1024-bit buffer for leftovers */ 25 | uint64_t hash[16]; /* 1024-bit algorithm internal hashing state */ 26 | }; 27 | 28 | /* algorithm context */ 29 | typedef struct edonr_ctx 30 | { 31 | union { 32 | struct edonr256_data data256; 33 | struct edonr512_data data512; 34 | } u; 35 | uint64_t length; /* number of processed bytes */ 36 | unsigned digest_length; /* length of the algorithm digest in bytes */ 37 | } edonr_ctx; 38 | 39 | void rhash_edonr224_init(edonr_ctx* ctx); 40 | void rhash_edonr256_init(edonr_ctx* ctx); 41 | void rhash_edonr256_update(edonr_ctx* ctx, const unsigned char* data, size_t length); 42 | void rhash_edonr256_final(edonr_ctx* ctx, unsigned char* result); 43 | 44 | void rhash_edonr384_init(edonr_ctx* ctx); 45 | void rhash_edonr512_init(edonr_ctx* ctx); 46 | void rhash_edonr512_update(edonr_ctx* ctx, const unsigned char* data, size_t length); 47 | void rhash_edonr512_final(edonr_ctx* ctx, unsigned char* result); 48 | 49 | #ifdef __cplusplus 50 | } /* extern "C" */ 51 | #endif /* __cplusplus */ 52 | 53 | #endif /* EDONR_H */ 54 | -------------------------------------------------------------------------------- /depends/rhash/librhash/gost12.h: -------------------------------------------------------------------------------- 1 | /* gost12.h */ 2 | #ifndef GOST12_H 3 | #define GOST12_H 4 | #include "ustd.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #define gost12_block_size 64 11 | #define gost12_256_hash_size 32 12 | #define gost12_512_hash_size 64 13 | 14 | /* algorithm context */ 15 | typedef struct gost12_ctx { 16 | uint64_t h[8]; 17 | uint64_t N[8]; 18 | uint64_t S[8]; 19 | uint64_t message[8]; 20 | unsigned index; 21 | unsigned hash_size; 22 | } gost12_ctx; 23 | 24 | /* hash functions */ 25 | 26 | void rhash_gost12_256_init(gost12_ctx* ctx); 27 | void rhash_gost12_512_init(gost12_ctx* ctx); 28 | void rhash_gost12_update(gost12_ctx* ctx, const unsigned char* msg, size_t size); 29 | void rhash_gost12_final(gost12_ctx* ctx, unsigned char* result); 30 | 31 | #ifdef __cplusplus 32 | } /* extern "C" */ 33 | #endif /* __cplusplus */ 34 | 35 | #endif /* GOST12_H */ 36 | -------------------------------------------------------------------------------- /depends/rhash/librhash/gost94.h: -------------------------------------------------------------------------------- 1 | /* gost94.h */ 2 | #ifndef GOST94_H 3 | #define GOST94_H 4 | #include "ustd.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #define gost94_block_size 32 11 | #define gost94_hash_length 32 12 | 13 | /* algorithm context */ 14 | typedef struct gost94_ctx 15 | { 16 | unsigned hash[8]; /* algorithm 256-bit state */ 17 | unsigned sum[8]; /* sum of processed message blocks */ 18 | unsigned char message[gost94_block_size]; /* 256-bit buffer for leftovers */ 19 | uint64_t length; /* number of processed bytes */ 20 | unsigned cryptpro; /* boolean flag, the type of sbox to use */ 21 | } gost94_ctx; 22 | 23 | /* hash functions */ 24 | 25 | void rhash_gost94_init(gost94_ctx* ctx); 26 | void rhash_gost94_cryptopro_init(gost94_ctx* ctx); 27 | void rhash_gost94_update(gost94_ctx* ctx, const unsigned char* msg, size_t size); 28 | void rhash_gost94_final(gost94_ctx* ctx, unsigned char result[32]); 29 | 30 | #ifdef GENERATE_GOST94_LOOKUP_TABLE 31 | void rhash_gost94_init_table(void); /* initialize algorithm static data */ 32 | #endif 33 | 34 | #ifdef __cplusplus 35 | } /* extern "C" */ 36 | #endif /* __cplusplus */ 37 | 38 | #endif /* GOST94_H */ 39 | -------------------------------------------------------------------------------- /depends/rhash/librhash/has160.h: -------------------------------------------------------------------------------- 1 | /* has160.h */ 2 | #ifndef HAS160_H 3 | #define HAS160_H 4 | #include "ustd.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #define has160_block_size 64 11 | #define has160_hash_size 20 12 | 13 | typedef struct has160_ctx 14 | { 15 | unsigned message[has160_block_size / 4]; /* 512-bit buffer for leftovers */ 16 | uint64_t length; /* number of processed bytes */ 17 | unsigned hash[5]; /* 160-bit algorithm internal hashing state */ 18 | } has160_ctx; 19 | 20 | /* hash functions */ 21 | 22 | void rhash_has160_init(has160_ctx* ctx); 23 | void rhash_has160_update(has160_ctx* ctx, const unsigned char* msg, size_t size); 24 | void rhash_has160_final(has160_ctx* ctx, unsigned char* result); 25 | 26 | #ifdef __cplusplus 27 | } /* extern "C" */ 28 | #endif /* __cplusplus */ 29 | 30 | #endif /* HAS160_H */ 31 | -------------------------------------------------------------------------------- /depends/rhash/librhash/hex.c: -------------------------------------------------------------------------------- 1 | /* hex.c - conversion for hexadecimal and base32 strings. 2 | * 3 | * Copyright (c) 2008, Aleksey Kravchenko 4 | * 5 | * Permission to use, copy, modify, and/or distribute this software for any 6 | * purpose with or without fee is hereby granted. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 9 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 | * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 11 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 13 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 | * PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | #include "hex.h" 17 | #include 18 | #include 19 | #include 20 | 21 | /** 22 | * Store hexadecimal representation of a binary string to given buffer. 23 | * 24 | * @param dst the buffer to receive hexadecimal representation 25 | * @param src binary string 26 | * @param length string length 27 | * @param upper_case flag to print string in uppercase 28 | */ 29 | void rhash_byte_to_hex(char* dst, const unsigned char* src, size_t length, int upper_case) 30 | { 31 | const char hex_add = (upper_case ? 'A' - 10 : 'a' - 10); 32 | for (; length > 0; src++, length--) { 33 | const unsigned char hi = (*src >> 4) & 15; 34 | const unsigned char lo = *src & 15; 35 | *dst++ = (hi > 9 ? hi + hex_add : hi + '0'); 36 | *dst++ = (lo > 9 ? lo + hex_add : lo + '0'); 37 | } 38 | *dst = '\0'; 39 | } 40 | 41 | /** 42 | * Encode a binary string to base32. 43 | * 44 | * @param dst the buffer to store result 45 | * @param src binary string 46 | * @param length string length 47 | * @param upper_case flag to print string in uppercase 48 | */ 49 | void rhash_byte_to_base32(char* dst, const unsigned char* src, size_t length, int upper_case) 50 | { 51 | const char a = (upper_case ? 'A' : 'a'); 52 | unsigned shift = 0; 53 | unsigned char word; 54 | const unsigned char* e = src + length; 55 | while (src < e) { 56 | if (shift > 3) { 57 | word = (*src & (0xFF >> shift)); 58 | shift = (shift + 5) % 8; 59 | word <<= shift; 60 | if (src + 1 < e) 61 | word |= *(src + 1) >> (8 - shift); 62 | ++src; 63 | } else { 64 | shift = (shift + 5) % 8; 65 | word = ( *src >> ( (8 - shift) & 7 ) ) & 0x1F; 66 | if (shift == 0) src++; 67 | } 68 | *dst++ = ( word < 26 ? word + a : word + '2' - 26 ); 69 | } 70 | *dst = '\0'; 71 | } 72 | 73 | /** 74 | * Encode a binary string to base64. 75 | * Encoded output length is always a multiple of 4 bytes. 76 | * 77 | * @param dst the buffer to store result 78 | * @param src binary string 79 | * @param length string length 80 | */ 81 | void rhash_byte_to_base64(char* dst, const unsigned char* src, size_t length) 82 | { 83 | static const char* tail = "0123456789+/"; 84 | unsigned shift = 0; 85 | unsigned char word; 86 | const unsigned char* e = src + length; 87 | while (src < e) { 88 | if (shift > 2) { 89 | word = (*src & (0xFF >> shift)); 90 | shift = (shift + 6) % 8; 91 | word <<= shift; 92 | if (src + 1 < e) 93 | word |= *(src + 1) >> (8 - shift); 94 | ++src; 95 | } else { 96 | shift = (shift + 6) % 8; 97 | word = ( *src >> ( (8 - shift) & 7 ) ) & 0x3F; 98 | if (shift == 0) src++; 99 | } 100 | *dst++ = ( word < 52 ? (word < 26 ? word + 'A' : word - 26 + 'a') : tail[word - 52]); 101 | } 102 | if (shift > 0) { 103 | *dst++ = '='; 104 | if (shift == 4) *dst++ = '='; 105 | } 106 | *dst = '\0'; 107 | } 108 | 109 | size_t rhash_base64_url_encoded_helper(char* dst, const unsigned char* src, size_t length, int url_encode, int upper_case) 110 | { 111 | #define B64_CHUNK_SIZE 120 112 | char buffer[164]; 113 | assert((BASE64_LENGTH(B64_CHUNK_SIZE) + 4) <= sizeof(buffer)); 114 | assert((B64_CHUNK_SIZE % 6) == 0); 115 | if (url_encode) { 116 | size_t result_length = 0; 117 | for (; length > 0; src += B64_CHUNK_SIZE) { 118 | size_t chunk_size = (length < B64_CHUNK_SIZE ? length : B64_CHUNK_SIZE); 119 | size_t encoded_length; 120 | rhash_byte_to_base64(buffer, src, chunk_size); 121 | encoded_length = rhash_urlencode(dst, buffer, BASE64_LENGTH(chunk_size), upper_case); 122 | result_length += encoded_length; 123 | dst += encoded_length; 124 | length -= chunk_size; 125 | } 126 | return result_length; 127 | } 128 | rhash_byte_to_base64(dst, src, length); 129 | return BASE64_LENGTH(length); 130 | } 131 | 132 | /* RFC 3986: safe url characters are ascii alpha-numeric and "-._~", other characters should be percent-encoded */ 133 | static unsigned url_safe_char_mask[4] = { 0, 0x03ff6000, 0x87fffffe, 0x47fffffe }; 134 | #define IS_URL_GOOD_CHAR(c) ((unsigned)(c) < 128 && (url_safe_char_mask[c >> 5] & (1 << (c & 31)))) 135 | 136 | /** 137 | * URL-encode specified binary string. 138 | * 139 | * @param dst (nullable) buffer to output encoded string to, 140 | * NULL to just calculate the lengths of encoded string 141 | * @param src binary string to encode 142 | * @param size size of the binary string 143 | * @param upper_case flag to output hex-codes in uppercase 144 | * @return the length of the result string 145 | */ 146 | size_t rhash_urlencode(char* dst, const char* src, size_t size, int upper_case) 147 | { 148 | const char* start; 149 | size_t i; 150 | if (!dst) { 151 | size_t length = size; 152 | for (i = 0; i < size; i++) 153 | if (!IS_URL_GOOD_CHAR(src[i])) 154 | length += 2; 155 | return length; 156 | } else { 157 | const char hex_add = (upper_case ? 'A' - 10 : 'a' - 10); 158 | start = dst; 159 | /* percent-encode all but unreserved URL characters */ 160 | for (i = 0; i < size; i++) { 161 | if (IS_URL_GOOD_CHAR(src[i])) { 162 | *dst++ = src[i]; 163 | } else { 164 | unsigned char hi = ((unsigned char)(src[i]) >> 4) & 0x0f; 165 | unsigned char lo = (unsigned char)(src[i]) & 0x0f; 166 | *dst++ = '%'; 167 | *dst++ = (hi > 9 ? hi + hex_add : hi + '0'); 168 | *dst++ = (lo > 9 ? lo + hex_add : lo + '0'); 169 | } 170 | } 171 | *dst = 0; 172 | } 173 | return dst - start; 174 | } 175 | 176 | /** 177 | * Print 64-bit number with trailing '\0' to a string buffer. 178 | * if dst is NULL, then just return the length of the number. 179 | * 180 | * @param dst output buffer 181 | * @param number the number to print 182 | * @return length of the printed number (without trailing '\0') 183 | */ 184 | int rhash_sprintI64(char* dst, uint64_t number) 185 | { 186 | /* The biggest number has 20 digits: 2^64 = 18 446 744 073 709 551 616 */ 187 | char buf[24]; 188 | char* p; 189 | size_t length; 190 | 191 | if (dst == NULL) { 192 | /* just calculate the length of the number */ 193 | if (number == 0) return 1; 194 | for (length = 0; number != 0; number /= 10) length++; 195 | return (int)length; 196 | } 197 | 198 | p = buf + 23; 199 | *p = '\0'; /* last symbol should be '\0' */ 200 | if (number == 0) { 201 | *(--p) = '0'; 202 | } else { 203 | for (; p >= buf && number != 0; number /= 10) { 204 | *(--p) = '0' + (char)(number % 10); 205 | } 206 | } 207 | length = buf + 23 - p; 208 | memcpy(dst, p, length + 1); 209 | return (int)length; 210 | } 211 | -------------------------------------------------------------------------------- /depends/rhash/librhash/hex.h: -------------------------------------------------------------------------------- 1 | /* hex.h - conversion for hexadecimal and base32 strings. */ 2 | #ifndef HEX_H 3 | #define HEX_H 4 | 5 | #include "ustd.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | void rhash_byte_to_hex(char* dest, const unsigned char* src, size_t length, int upper_case); 12 | void rhash_byte_to_base32(char* dest, const unsigned char* src, size_t length, int upper_case); 13 | void rhash_byte_to_base64(char* dest, const unsigned char* src, size_t length); 14 | char* rhash_print_hex_byte(char* dest, const unsigned char byte, int upper_case); 15 | size_t rhash_urlencode(char* dst, const char* str, size_t size, int upper_case); 16 | size_t rhash_base64_url_encoded_helper(char* dst, const unsigned char* src, size_t length, int url_encode, int upper_case); 17 | int rhash_sprintI64(char* dst, uint64_t number); 18 | 19 | #define BASE32_LENGTH(bytes) (((bytes) * 8 + 4) / 5) 20 | #define BASE64_LENGTH(bytes) ((((bytes) + 2) / 3) * 4) 21 | 22 | #ifdef __cplusplus 23 | } /* extern "C" */ 24 | #endif /* __cplusplus */ 25 | 26 | #endif /* HEX_H */ 27 | -------------------------------------------------------------------------------- /depends/rhash/librhash/md4.c: -------------------------------------------------------------------------------- 1 | /* md4.c - an implementation of MD4 Message-Digest Algorithm based on RFC 1320. 2 | * 3 | * Copyright (c) 2007, Aleksey Kravchenko 4 | * 5 | * Permission to use, copy, modify, and/or distribute this software for any 6 | * purpose with or without fee is hereby granted. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 9 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 | * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 11 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 13 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 | * PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | #include "byte_order.h" 19 | #include "md4.h" 20 | 21 | /** 22 | * Initialize context before calculaing hash. 23 | * 24 | * @param ctx context to initialize 25 | */ 26 | void rhash_md4_init(md4_ctx* ctx) 27 | { 28 | memset(ctx, 0, sizeof(*ctx)); 29 | 30 | /* initialize state */ 31 | ctx->hash[0] = 0x67452301; 32 | ctx->hash[1] = 0xefcdab89; 33 | ctx->hash[2] = 0x98badcfe; 34 | ctx->hash[3] = 0x10325476; 35 | } 36 | 37 | /* First, define three auxiliary functions that each take as input 38 | * three 32-bit words and returns a 32-bit word. 39 | * F(x,y,z) = XY v not(X) Z = ((Y xor Z) X) xor Z (the last form is faster) 40 | * G(X,Y,Z) = XY v XZ v YZ 41 | * H(X,Y,Z) = X xor Y xor Z */ 42 | 43 | #define MD4_F(x, y, z) ((((y) ^ (z)) & (x)) ^ (z)) 44 | #define MD4_G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z))) 45 | #define MD4_H(x, y, z) ((x) ^ (y) ^ (z)) 46 | 47 | /* transformations for rounds 1, 2, and 3. */ 48 | #define MD4_ROUND1(a, b, c, d, x, s) { \ 49 | (a) += MD4_F((b), (c), (d)) + (x); \ 50 | (a) = ROTL32((a), (s)); \ 51 | } 52 | #define MD4_ROUND2(a, b, c, d, x, s) { \ 53 | (a) += MD4_G((b), (c), (d)) + (x) + 0x5a827999; \ 54 | (a) = ROTL32((a), (s)); \ 55 | } 56 | #define MD4_ROUND3(a, b, c, d, x, s) { \ 57 | (a) += MD4_H((b), (c), (d)) + (x) + 0x6ed9eba1; \ 58 | (a) = ROTL32((a), (s)); \ 59 | } 60 | 61 | /** 62 | * The core transformation. Process a 512-bit block. 63 | * The function has been taken from RFC 1320 with little changes. 64 | * 65 | * @param state algorithm state 66 | * @param x the message block to process 67 | */ 68 | static void rhash_md4_process_block(unsigned state[4], const unsigned* x) 69 | { 70 | register unsigned a, b, c, d; 71 | a = state[0], b = state[1], c = state[2], d = state[3]; 72 | 73 | MD4_ROUND1(a, b, c, d, x[ 0], 3); 74 | MD4_ROUND1(d, a, b, c, x[ 1], 7); 75 | MD4_ROUND1(c, d, a, b, x[ 2], 11); 76 | MD4_ROUND1(b, c, d, a, x[ 3], 19); 77 | MD4_ROUND1(a, b, c, d, x[ 4], 3); 78 | MD4_ROUND1(d, a, b, c, x[ 5], 7); 79 | MD4_ROUND1(c, d, a, b, x[ 6], 11); 80 | MD4_ROUND1(b, c, d, a, x[ 7], 19); 81 | MD4_ROUND1(a, b, c, d, x[ 8], 3); 82 | MD4_ROUND1(d, a, b, c, x[ 9], 7); 83 | MD4_ROUND1(c, d, a, b, x[10], 11); 84 | MD4_ROUND1(b, c, d, a, x[11], 19); 85 | MD4_ROUND1(a, b, c, d, x[12], 3); 86 | MD4_ROUND1(d, a, b, c, x[13], 7); 87 | MD4_ROUND1(c, d, a, b, x[14], 11); 88 | MD4_ROUND1(b, c, d, a, x[15], 19); 89 | 90 | MD4_ROUND2(a, b, c, d, x[ 0], 3); 91 | MD4_ROUND2(d, a, b, c, x[ 4], 5); 92 | MD4_ROUND2(c, d, a, b, x[ 8], 9); 93 | MD4_ROUND2(b, c, d, a, x[12], 13); 94 | MD4_ROUND2(a, b, c, d, x[ 1], 3); 95 | MD4_ROUND2(d, a, b, c, x[ 5], 5); 96 | MD4_ROUND2(c, d, a, b, x[ 9], 9); 97 | MD4_ROUND2(b, c, d, a, x[13], 13); 98 | MD4_ROUND2(a, b, c, d, x[ 2], 3); 99 | MD4_ROUND2(d, a, b, c, x[ 6], 5); 100 | MD4_ROUND2(c, d, a, b, x[10], 9); 101 | MD4_ROUND2(b, c, d, a, x[14], 13); 102 | MD4_ROUND2(a, b, c, d, x[ 3], 3); 103 | MD4_ROUND2(d, a, b, c, x[ 7], 5); 104 | MD4_ROUND2(c, d, a, b, x[11], 9); 105 | MD4_ROUND2(b, c, d, a, x[15], 13); 106 | 107 | MD4_ROUND3(a, b, c, d, x[ 0], 3); 108 | MD4_ROUND3(d, a, b, c, x[ 8], 9); 109 | MD4_ROUND3(c, d, a, b, x[ 4], 11); 110 | MD4_ROUND3(b, c, d, a, x[12], 15); 111 | MD4_ROUND3(a, b, c, d, x[ 2], 3); 112 | MD4_ROUND3(d, a, b, c, x[10], 9); 113 | MD4_ROUND3(c, d, a, b, x[ 6], 11); 114 | MD4_ROUND3(b, c, d, a, x[14], 15); 115 | MD4_ROUND3(a, b, c, d, x[ 1], 3); 116 | MD4_ROUND3(d, a, b, c, x[ 9], 9); 117 | MD4_ROUND3(c, d, a, b, x[ 5], 11); 118 | MD4_ROUND3(b, c, d, a, x[13], 15); 119 | MD4_ROUND3(a, b, c, d, x[ 3], 3); 120 | MD4_ROUND3(d, a, b, c, x[11], 9); 121 | MD4_ROUND3(c, d, a, b, x[ 7], 11); 122 | MD4_ROUND3(b, c, d, a, x[15], 15); 123 | 124 | state[0] += a, state[1] += b, state[2] += c, state[3] += d; 125 | } 126 | 127 | /** 128 | * Calculate message hash. 129 | * Can be called repeatedly with chunks of the message to be hashed. 130 | * 131 | * @param ctx the algorithm context containing current hashing state 132 | * @param msg message chunk 133 | * @param size length of the message chunk 134 | */ 135 | void rhash_md4_update(md4_ctx* ctx, const unsigned char* msg, size_t size) 136 | { 137 | unsigned index = (unsigned)ctx->length & 63; 138 | ctx->length += size; 139 | 140 | /* fill partial block */ 141 | if (index) { 142 | unsigned left = md4_block_size - index; 143 | le32_copy(ctx->message, index, msg, (size < left ? size : left)); 144 | if (size < left) return; 145 | 146 | /* process partial block */ 147 | rhash_md4_process_block(ctx->hash, ctx->message); 148 | msg += left; 149 | size -= left; 150 | } 151 | while (size >= md4_block_size) { 152 | unsigned* aligned_message_block; 153 | if (IS_LITTLE_ENDIAN && IS_ALIGNED_32(msg)) { 154 | /* the most common case is processing a 32-bit aligned message 155 | on a little-endian CPU without copying it */ 156 | aligned_message_block = (unsigned*)msg; 157 | } else { 158 | le32_copy(ctx->message, 0, msg, md4_block_size); 159 | aligned_message_block = ctx->message; 160 | } 161 | 162 | rhash_md4_process_block(ctx->hash, aligned_message_block); 163 | msg += md4_block_size; 164 | size -= md4_block_size; 165 | } 166 | if (size) { 167 | /* save leftovers */ 168 | le32_copy(ctx->message, 0, msg, size); 169 | } 170 | } 171 | 172 | /** 173 | * Store calculated hash into the given array. 174 | * 175 | * @param ctx the algorithm context containing current hashing state 176 | * @param result calculated hash in binary form 177 | */ 178 | void rhash_md4_final(md4_ctx* ctx, unsigned char result[16]) 179 | { 180 | unsigned index = ((unsigned)ctx->length & 63) >> 2; 181 | unsigned shift = ((unsigned)ctx->length & 3) * 8; 182 | 183 | /* pad message and run for last block */ 184 | 185 | /* append the byte 0x80 to the message */ 186 | ctx->message[index] &= ~(0xFFFFFFFFu << shift); 187 | ctx->message[index++] ^= 0x80u << shift; 188 | 189 | /* if no room left in the message to store 64-bit message length */ 190 | if (index > 14) { 191 | /* then fill the rest with zeros and process it */ 192 | while (index < 16) { 193 | ctx->message[index++] = 0; 194 | } 195 | rhash_md4_process_block(ctx->hash, ctx->message); 196 | index = 0; 197 | } 198 | while (index < 14) { 199 | ctx->message[index++] = 0; 200 | } 201 | ctx->message[14] = (unsigned)(ctx->length << 3); 202 | ctx->message[15] = (unsigned)(ctx->length >> 29); 203 | rhash_md4_process_block(ctx->hash, ctx->message); 204 | 205 | if (result) le32_copy(result, 0, &ctx->hash, 16); 206 | } 207 | -------------------------------------------------------------------------------- /depends/rhash/librhash/md4.h: -------------------------------------------------------------------------------- 1 | /* md4.h */ 2 | #ifndef MD4_HIDER 3 | #define MD4_HIDER 4 | #include "ustd.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #define md4_block_size 64 11 | #define md4_hash_size 16 12 | 13 | /* algorithm context */ 14 | typedef struct md4_ctx 15 | { 16 | unsigned hash[4]; /* 128-bit algorithm internal hashing state */ 17 | unsigned message[md4_block_size / 4]; /* 512-bit buffer for leftovers */ 18 | uint64_t length; /* number of processed bytes */ 19 | } md4_ctx; 20 | 21 | /* hash functions */ 22 | 23 | void rhash_md4_init(md4_ctx* ctx); 24 | void rhash_md4_update(md4_ctx* ctx, const unsigned char* msg, size_t size); 25 | void rhash_md4_final(md4_ctx* ctx, unsigned char result[16]); 26 | 27 | #ifdef __cplusplus 28 | } /* extern "C" */ 29 | #endif /* __cplusplus */ 30 | 31 | #endif /* MD4_HIDER */ 32 | -------------------------------------------------------------------------------- /depends/rhash/librhash/md5.h: -------------------------------------------------------------------------------- 1 | /* md5.h */ 2 | #ifndef MD5_HIDER 3 | #define MD5_HIDER 4 | #include "ustd.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #define md5_block_size 64 11 | #define md5_hash_size 16 12 | 13 | /* algorithm context */ 14 | typedef struct md5_ctx 15 | { 16 | unsigned message[md5_block_size / 4]; /* 512-bit buffer for leftovers */ 17 | uint64_t length; /* number of processed bytes */ 18 | unsigned hash[4]; /* 128-bit algorithm internal hashing state */ 19 | } md5_ctx; 20 | 21 | /* hash functions */ 22 | 23 | void rhash_md5_init(md5_ctx* ctx); 24 | void rhash_md5_update(md5_ctx* ctx, const unsigned char* msg, size_t size); 25 | void rhash_md5_final(md5_ctx* ctx, unsigned char result[16]); 26 | 27 | #ifdef __cplusplus 28 | } /* extern "C" */ 29 | #endif /* __cplusplus */ 30 | 31 | #endif /* MD5_HIDER */ 32 | -------------------------------------------------------------------------------- /depends/rhash/librhash/plug_openssl.h: -------------------------------------------------------------------------------- 1 | /* plug_openssl.h - plug-in openssl algorithms */ 2 | #ifndef RHASH_PLUG_OPENSSL_H 3 | #define RHASH_PLUG_OPENSSL_H 4 | #if defined(USE_OPENSSL) || defined(OPENSSL_RUNTIME) 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | int rhash_plug_openssl(void); /* load openssl algorithms */ 11 | unsigned rhash_get_openssl_supported_hash_mask(void); 12 | unsigned rhash_get_openssl_available_hash_mask(void); 13 | 14 | extern unsigned rhash_openssl_hash_mask; /* mask of hash sums to use */ 15 | 16 | #ifdef __cplusplus 17 | } /* extern "C" */ 18 | #endif /* __cplusplus */ 19 | 20 | #else 21 | # define rhash_get_openssl_supported_hash_mask() (0) 22 | # define rhash_get_openssl_available_hash_mask() (0) 23 | #endif /* defined(USE_OPENSSL) || defined(OPENSSL_RUNTIME) */ 24 | #endif /* RHASH_PLUG_OPENSSL_H */ 25 | -------------------------------------------------------------------------------- /depends/rhash/librhash/rhash_timing.h: -------------------------------------------------------------------------------- 1 | /** @file rhash_timing.h timer and benchmarking functions */ 2 | #ifndef RHASH_TIMING_H 3 | #define RHASH_TIMING_H 4 | 5 | /**************************************************************************** 6 | * Warning: all functions in this file are deprecated and will be removed 7 | * from the library in the future. They are still exported for backward 8 | * compatibility. 9 | ****************************************************************************/ 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #ifndef RHASH_API 16 | /** 17 | * Modifier for LibRHash functions. 18 | */ 19 | # define RHASH_API 20 | #endif 21 | 22 | #if defined(_WIN32) || defined(__CYGWIN__) 23 | /** 24 | * Platform-dependent time delta. 25 | */ 26 | typedef unsigned long long timedelta_t; 27 | 28 | #else 29 | # include /* for timeval */ 30 | /** 31 | * Platform-dependent time delta. 32 | */ 33 | typedef struct timeval timedelta_t; 34 | #endif 35 | 36 | 37 | /** 38 | * Start a timer. 39 | * 40 | * @deprecated This function shall be removed soon, since 41 | * it is not related to the hashing library main functionality. 42 | * 43 | * @param timer timer to start 44 | */ 45 | RHASH_API void rhash_timer_start(timedelta_t* timer); 46 | 47 | /** 48 | * Stop given timer. 49 | * 50 | * @deprecated This function shall be removed soon, since 51 | * it is not related to the hashing library main functionality. 52 | * 53 | * @param timer the timer to stop 54 | * @return number of seconds timed 55 | */ 56 | RHASH_API double rhash_timer_stop(timedelta_t* timer); 57 | 58 | 59 | /** 60 | * Benchmarking flag: don't print intermediate benchmarking info. 61 | */ 62 | #define RHASH_BENCHMARK_QUIET 1 63 | 64 | /** 65 | * Benchmarking flag: measure the CPU "clocks per byte" speed. 66 | */ 67 | #define RHASH_BENCHMARK_CPB 2 68 | 69 | /** 70 | * Benchmarking flag: print benchmark result in tab-delimed format. 71 | */ 72 | #define RHASH_BENCHMARK_RAW 4 73 | 74 | /** 75 | * Benchmark a hash algorithm. 76 | * 77 | * @deprecated This function will be removed from the librhash API, 78 | * since it is not related to the hashing library main functionality. 79 | * 80 | * @param hash_id hash algorithm identifier 81 | * @param flags benchmark flags 82 | * @param output the stream to print results 83 | */ 84 | RHASH_API void rhash_run_benchmark(unsigned hash_id, unsigned flags, 85 | FILE* output); 86 | 87 | #ifdef __cplusplus 88 | } /* extern "C" */ 89 | #endif /* __cplusplus */ 90 | 91 | #endif /* RHASH_TIMING_H */ 92 | -------------------------------------------------------------------------------- /depends/rhash/librhash/rhash_torrent.c: -------------------------------------------------------------------------------- 1 | /* rhash_torrent.c - functions to make a torrent file. 2 | * 3 | * Copyright (c) 2013, Aleksey Kravchenko 4 | * 5 | * Permission to use, copy, modify, and/or distribute this software for any 6 | * purpose with or without fee is hereby granted. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 9 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 | * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 11 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 13 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 | * PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* modifier for Windows DLL */ 18 | #if (defined(_WIN32) || defined(__CYGWIN__) ) && defined(RHASH_EXPORTS) 19 | # define RHASH_API __declspec(dllexport) 20 | #endif 21 | 22 | #include "rhash_torrent.h" 23 | #include "algorithms.h" 24 | #include "torrent.h" 25 | #include 26 | 27 | /* obtain torrent context from rhash context */ 28 | #define BT_CTX(rctx) ((torrent_ctx*)(((rhash_context_ext*)rctx)->bt_ctx)) 29 | 30 | RHASH_API int rhash_torrent_add_file(rhash ctx, const char* filepath, unsigned long long filesize) 31 | { 32 | if (!BT_CTX(ctx)) return 0; 33 | return bt_add_file(BT_CTX(ctx), filepath, filesize); 34 | } 35 | 36 | RHASH_API void rhash_torrent_set_options(rhash ctx, unsigned options) 37 | { 38 | if (!BT_CTX(ctx)) return; 39 | bt_set_options(BT_CTX(ctx), options); 40 | } 41 | 42 | RHASH_API int rhash_torrent_add_announce(rhash ctx, const char* announce_url) 43 | { 44 | if (!BT_CTX(ctx)) return 0; 45 | return bt_add_announce(BT_CTX(ctx), announce_url); 46 | } 47 | 48 | RHASH_API int rhash_torrent_set_program_name(rhash ctx, const char* name) 49 | { 50 | if (!BT_CTX(ctx)) return 0; 51 | return bt_set_program_name(BT_CTX(ctx), name); 52 | } 53 | 54 | RHASH_API void rhash_torrent_set_piece_length(rhash ctx, size_t piece_length) 55 | { 56 | if (!BT_CTX(ctx)) return; 57 | bt_set_piece_length(BT_CTX(ctx), piece_length); 58 | } 59 | 60 | RHASH_API size_t rhash_torrent_get_default_piece_length(unsigned long long total_size) 61 | { 62 | return bt_default_piece_length(total_size); 63 | } 64 | 65 | RHASH_API const rhash_str* rhash_torrent_generate_content(rhash ctx) 66 | { 67 | torrent_ctx* tc = BT_CTX(ctx); 68 | if (!tc || tc->error || !tc->content.str) return 0; 69 | return (rhash_str*)(&tc->content); 70 | } 71 | -------------------------------------------------------------------------------- /depends/rhash/librhash/rhash_torrent.h: -------------------------------------------------------------------------------- 1 | /* rhash_torrent.h */ 2 | #ifndef RHASH_TORRENT_H 3 | #define RHASH_TORRENT_H 4 | 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #ifndef RHASH_API 12 | /* modifier for LibRHash functions */ 13 | # define RHASH_API 14 | #endif 15 | 16 | #ifndef LIBRHASH_RHASH_CTX_DEFINED 17 | #define LIBRHASH_RHASH_CTX_DEFINED 18 | /** 19 | * Hashing context. 20 | */ 21 | typedef struct rhash_context* rhash; 22 | #endif /* LIBRHASH_RHASH_CTX_DEFINED */ 23 | 24 | /** 25 | * Binary string with length. 26 | */ 27 | typedef struct rhash_str 28 | { 29 | char* str; 30 | size_t length; 31 | } rhash_str; 32 | 33 | /* possible torrent options */ 34 | 35 | /** 36 | * Torrent option: generate private BitTorrent. 37 | */ 38 | #define RHASH_TORRENT_OPT_PRIVATE 1 39 | /** 40 | * Torrent option: calculate infohash without torrent file body. 41 | */ 42 | #define RHASH_TORRENT_OPT_INFOHASH_ONLY 2 43 | 44 | /* torrent functions */ 45 | 46 | /** 47 | * Add a file info into the batch of files of given torrent. 48 | * 49 | * @param ctx rhash context 50 | * @param filepath file path 51 | * @param filesize file size 52 | * @return non-zero on success, zero on fail 53 | */ 54 | RHASH_API int rhash_torrent_add_file(rhash ctx, const char* filepath, unsigned long long filesize); 55 | 56 | /** 57 | * Set the torrent algorithm options. 58 | * 59 | * @param ctx rhash context 60 | * @param options the options to set 61 | */ 62 | RHASH_API void rhash_torrent_set_options(rhash ctx, unsigned options); 63 | 64 | /** 65 | * Add an torrent announcement-URL for storing into torrent file. 66 | * 67 | * @param ctx rhash context 68 | * @param announce_url the announcement-URL 69 | * @return non-zero on success, zero on error 70 | */ 71 | RHASH_API int rhash_torrent_add_announce(rhash ctx, const char* announce_url); 72 | 73 | /** 74 | * Set optional name of the program generating the torrent 75 | * for storing into torrent file. 76 | * 77 | * @param ctx rhash context 78 | * @param name the program name 79 | * @return non-zero on success, zero on error 80 | */ 81 | RHASH_API int rhash_torrent_set_program_name(rhash ctx, const char* name); 82 | 83 | /** 84 | * Set length of a file piece. 85 | * 86 | * @param ctx rhash context 87 | * @param piece_length the piece length in bytes 88 | */ 89 | RHASH_API void rhash_torrent_set_piece_length(rhash ctx, size_t piece_length); 90 | 91 | /** 92 | * Calculate, using uTorrent algorithm, the default torrent piece length 93 | * for a given torrent batch size. 94 | * 95 | * @param total_size the total size of files included into a torrent file 96 | * @return piece length for the torrent file 97 | */ 98 | RHASH_API size_t rhash_torrent_get_default_piece_length(unsigned long long total_size); 99 | 100 | /* 101 | * Macro to set a torrent batch size (the total size of files included into this torrent). 102 | * It's defined as rhash_torrent_set_piece_length(ctx, rhash_torrent_get_default_piece_length(total_size)) 103 | * 104 | * @param ctx rhash context 105 | * @param total_size total size of files included into the torrent file 106 | */ 107 | #define rhash_torrent_set_batch_size(ctx, total_size) \ 108 | rhash_torrent_set_piece_length((ctx), rhash_torrent_get_default_piece_length(total_size)) 109 | 110 | /** 111 | * Get the content of the generated torrent file. 112 | * 113 | * @param ctx rhash context 114 | * @return binary string with the torrent file content, if successful. 115 | * On fail the function returns NULL. 116 | */ 117 | RHASH_API const rhash_str* rhash_torrent_generate_content(rhash ctx); 118 | 119 | #ifdef __cplusplus 120 | } /* extern "C" */ 121 | #endif /* __cplusplus */ 122 | 123 | #endif /* RHASH_TORRENT_H */ 124 | -------------------------------------------------------------------------------- /depends/rhash/librhash/ripemd-160.h: -------------------------------------------------------------------------------- 1 | /* ripemd-160.h */ 2 | #ifndef RMD160_H 3 | #define RMD160_H 4 | #include "ustd.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #define ripemd160_block_size 64 11 | #define ripemd160_hash_size 20 12 | 13 | /* algorithm context */ 14 | typedef struct ripemd160_ctx 15 | { 16 | unsigned message[ripemd160_block_size / 4]; /* 512-bit buffer for leftovers */ 17 | uint64_t length; /* number of processed bytes */ 18 | unsigned hash[5]; /* 160-bit algorithm internal hashing state */ 19 | } ripemd160_ctx; 20 | 21 | /* hash functions */ 22 | 23 | void rhash_ripemd160_init(ripemd160_ctx* ctx); 24 | void rhash_ripemd160_update(ripemd160_ctx* ctx, const unsigned char* msg, size_t size); 25 | void rhash_ripemd160_final(ripemd160_ctx* ctx, unsigned char result[20]); 26 | 27 | #ifdef __cplusplus 28 | } /* extern "C" */ 29 | #endif /* __cplusplus */ 30 | 31 | #endif /* RMD160_H */ 32 | -------------------------------------------------------------------------------- /depends/rhash/librhash/sha1.c: -------------------------------------------------------------------------------- 1 | /* sha1.c - an implementation of Secure Hash Algorithm 1 (SHA1) 2 | * based on RFC 3174. 3 | * 4 | * Copyright (c) 2008, Aleksey Kravchenko 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 10 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 | * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 | * PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #include 19 | #include "byte_order.h" 20 | #include "sha1.h" 21 | 22 | /** 23 | * Initialize context before calculaing hash. 24 | * 25 | * @param ctx context to initialize 26 | */ 27 | void rhash_sha1_init(sha1_ctx* ctx) 28 | { 29 | ctx->length = 0; 30 | 31 | /* initialize algorithm state */ 32 | ctx->hash[0] = 0x67452301; 33 | ctx->hash[1] = 0xefcdab89; 34 | ctx->hash[2] = 0x98badcfe; 35 | ctx->hash[3] = 0x10325476; 36 | ctx->hash[4] = 0xc3d2e1f0; 37 | } 38 | 39 | /** 40 | * The core transformation. Process a 512-bit block. 41 | * The function has been taken from RFC 3174 with little changes. 42 | * 43 | * @param hash algorithm state 44 | * @param block the message block to process 45 | */ 46 | static void rhash_sha1_process_block(unsigned* hash, const unsigned* block) 47 | { 48 | int t; /* Loop counter */ 49 | uint32_t temp; /* Temporary word value */ 50 | uint32_t W[80]; /* Word sequence */ 51 | uint32_t A, B, C, D, E; /* Word buffers */ 52 | 53 | /* initialize the first 16 words in the array W */ 54 | for (t = 0; t < 16; t++) { 55 | /* note: it is much faster to apply be2me here, then using be32_copy */ 56 | W[t] = be2me_32(block[t]); 57 | } 58 | 59 | /* initialize the rest */ 60 | for (t = 16; t < 80; t++) { 61 | W[t] = ROTL32(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1); 62 | } 63 | 64 | A = hash[0]; 65 | B = hash[1]; 66 | C = hash[2]; 67 | D = hash[3]; 68 | E = hash[4]; 69 | 70 | for (t = 0; t < 20; t++) { 71 | /* the following is faster than ((B & C) | ((~B) & D)) */ 72 | temp = ROTL32(A, 5) + (((C ^ D) & B) ^ D) 73 | + E + W[t] + 0x5A827999; 74 | E = D; 75 | D = C; 76 | C = ROTL32(B, 30); 77 | B = A; 78 | A = temp; 79 | } 80 | 81 | for (t = 20; t < 40; t++) { 82 | temp = ROTL32(A, 5) + (B ^ C ^ D) + E + W[t] + 0x6ED9EBA1; 83 | E = D; 84 | D = C; 85 | C = ROTL32(B, 30); 86 | B = A; 87 | A = temp; 88 | } 89 | 90 | for (t = 40; t < 60; t++) { 91 | temp = ROTL32(A, 5) + ((B & C) | (B & D) | (C & D)) 92 | + E + W[t] + 0x8F1BBCDC; 93 | E = D; 94 | D = C; 95 | C = ROTL32(B, 30); 96 | B = A; 97 | A = temp; 98 | } 99 | 100 | for (t = 60; t < 80; t++) { 101 | temp = ROTL32(A, 5) + (B ^ C ^ D) + E + W[t] + 0xCA62C1D6; 102 | E = D; 103 | D = C; 104 | C = ROTL32(B, 30); 105 | B = A; 106 | A = temp; 107 | } 108 | 109 | hash[0] += A; 110 | hash[1] += B; 111 | hash[2] += C; 112 | hash[3] += D; 113 | hash[4] += E; 114 | } 115 | 116 | /** 117 | * Calculate message hash. 118 | * Can be called repeatedly with chunks of the message to be hashed. 119 | * 120 | * @param ctx the algorithm context containing current hashing state 121 | * @param msg message chunk 122 | * @param size length of the message chunk 123 | */ 124 | void rhash_sha1_update(sha1_ctx* ctx, const unsigned char* msg, size_t size) 125 | { 126 | unsigned index = (unsigned)ctx->length & 63; 127 | ctx->length += size; 128 | 129 | /* fill partial block */ 130 | if (index) { 131 | unsigned left = sha1_block_size - index; 132 | memcpy(ctx->message + index, msg, (size < left ? size : left)); 133 | if (size < left) return; 134 | 135 | /* process partial block */ 136 | rhash_sha1_process_block(ctx->hash, (unsigned*)ctx->message); 137 | msg += left; 138 | size -= left; 139 | } 140 | while (size >= sha1_block_size) { 141 | unsigned* aligned_message_block; 142 | if (IS_ALIGNED_32(msg)) { 143 | /* the most common case is processing of an already aligned message 144 | without copying it */ 145 | aligned_message_block = (unsigned*)msg; 146 | } else { 147 | memcpy(ctx->message, msg, sha1_block_size); 148 | aligned_message_block = (unsigned*)ctx->message; 149 | } 150 | 151 | rhash_sha1_process_block(ctx->hash, aligned_message_block); 152 | msg += sha1_block_size; 153 | size -= sha1_block_size; 154 | } 155 | if (size) { 156 | /* save leftovers */ 157 | memcpy(ctx->message, msg, size); 158 | } 159 | } 160 | 161 | /** 162 | * Store calculated hash into the given array. 163 | * 164 | * @param ctx the algorithm context containing current hashing state 165 | * @param result calculated hash in binary form 166 | */ 167 | void rhash_sha1_final(sha1_ctx* ctx, unsigned char* result) 168 | { 169 | unsigned index = (unsigned)ctx->length & 63; 170 | unsigned* msg32 = (unsigned*)ctx->message; 171 | 172 | /* pad message and run for last block */ 173 | ctx->message[index++] = 0x80; 174 | while ((index & 3) != 0) { 175 | ctx->message[index++] = 0; 176 | } 177 | index >>= 2; 178 | 179 | /* if no room left in the message to store 64-bit message length */ 180 | if (index > 14) { 181 | /* then fill the rest with zeros and process it */ 182 | while (index < 16) { 183 | msg32[index++] = 0; 184 | } 185 | rhash_sha1_process_block(ctx->hash, msg32); 186 | index = 0; 187 | } 188 | while (index < 14) { 189 | msg32[index++] = 0; 190 | } 191 | msg32[14] = be2me_32( (unsigned)(ctx->length >> 29) ); 192 | msg32[15] = be2me_32( (unsigned)(ctx->length << 3) ); 193 | rhash_sha1_process_block(ctx->hash, msg32); 194 | 195 | if (result) be32_copy(result, 0, &ctx->hash, sha1_hash_size); 196 | } 197 | -------------------------------------------------------------------------------- /depends/rhash/librhash/sha1.h: -------------------------------------------------------------------------------- 1 | /* sha1.h */ 2 | #ifndef SHA1_H 3 | #define SHA1_H 4 | #include "ustd.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #define sha1_block_size 64 11 | #define sha1_hash_size 20 12 | 13 | /* algorithm context */ 14 | typedef struct sha1_ctx 15 | { 16 | unsigned char message[sha1_block_size]; /* 512-bit buffer for leftovers */ 17 | uint64_t length; /* number of processed bytes */ 18 | unsigned hash[5]; /* 160-bit algorithm internal hashing state */ 19 | } sha1_ctx; 20 | 21 | /* hash functions */ 22 | 23 | void rhash_sha1_init(sha1_ctx* ctx); 24 | void rhash_sha1_update(sha1_ctx* ctx, const unsigned char* msg, size_t size); 25 | void rhash_sha1_final(sha1_ctx* ctx, unsigned char* result); 26 | 27 | #ifdef __cplusplus 28 | } /* extern "C" */ 29 | #endif /* __cplusplus */ 30 | 31 | #endif /* SHA1_H */ 32 | -------------------------------------------------------------------------------- /depends/rhash/librhash/sha256.h: -------------------------------------------------------------------------------- 1 | /* sha.h sha256 and sha224 hash functions */ 2 | #ifndef SHA256_H 3 | #define SHA256_H 4 | #include "ustd.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #define sha256_block_size 64 11 | #define sha256_hash_size 32 12 | #define sha224_hash_size 28 13 | 14 | /* algorithm context */ 15 | typedef struct sha256_ctx 16 | { 17 | unsigned message[16]; /* 512-bit buffer for leftovers */ 18 | uint64_t length; /* number of processed bytes */ 19 | unsigned hash[8]; /* 256-bit algorithm internal hashing state */ 20 | unsigned digest_length; /* length of the algorithm digest in bytes */ 21 | } sha256_ctx; 22 | 23 | void rhash_sha224_init(sha256_ctx* ctx); 24 | void rhash_sha256_init(sha256_ctx* ctx); 25 | void rhash_sha256_update(sha256_ctx* ctx, const unsigned char* data, size_t length); 26 | void rhash_sha256_final(sha256_ctx* ctx, unsigned char result[32]); 27 | 28 | #ifdef __cplusplus 29 | } /* extern "C" */ 30 | #endif /* __cplusplus */ 31 | 32 | #endif /* SHA256_H */ 33 | -------------------------------------------------------------------------------- /depends/rhash/librhash/sha3.h: -------------------------------------------------------------------------------- 1 | /* sha3.h */ 2 | #ifndef RHASH_SHA3_H 3 | #define RHASH_SHA3_H 4 | #include "ustd.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #define sha3_224_hash_size 28 11 | #define sha3_256_hash_size 32 12 | #define sha3_384_hash_size 48 13 | #define sha3_512_hash_size 64 14 | #define sha3_max_permutation_size 25 15 | #define sha3_max_rate_in_qwords 24 16 | 17 | /** 18 | * SHA3 Algorithm context. 19 | */ 20 | typedef struct sha3_ctx 21 | { 22 | /* 1600 bits algorithm hashing state */ 23 | uint64_t hash[sha3_max_permutation_size]; 24 | /* 1536-bit buffer for leftovers */ 25 | uint64_t message[sha3_max_rate_in_qwords]; 26 | /* count of bytes in the message[] buffer */ 27 | unsigned rest; 28 | /* size of a message block processed at once */ 29 | unsigned block_size; 30 | } sha3_ctx; 31 | 32 | /* methods for calculating the hash function */ 33 | 34 | void rhash_sha3_224_init(sha3_ctx* ctx); 35 | void rhash_sha3_256_init(sha3_ctx* ctx); 36 | void rhash_sha3_384_init(sha3_ctx* ctx); 37 | void rhash_sha3_512_init(sha3_ctx* ctx); 38 | void rhash_sha3_update(sha3_ctx* ctx, const unsigned char* msg, size_t size); 39 | void rhash_sha3_final(sha3_ctx* ctx, unsigned char* result); 40 | 41 | #ifdef USE_KECCAK 42 | #define rhash_keccak_224_init rhash_sha3_224_init 43 | #define rhash_keccak_256_init rhash_sha3_256_init 44 | #define rhash_keccak_384_init rhash_sha3_384_init 45 | #define rhash_keccak_512_init rhash_sha3_512_init 46 | #define rhash_keccak_update rhash_sha3_update 47 | void rhash_keccak_final(sha3_ctx* ctx, unsigned char* result); 48 | #endif 49 | 50 | #ifdef __cplusplus 51 | } /* extern "C" */ 52 | #endif /* __cplusplus */ 53 | 54 | #endif /* RHASH_SHA3_H */ 55 | -------------------------------------------------------------------------------- /depends/rhash/librhash/sha512.h: -------------------------------------------------------------------------------- 1 | /* sha.h sha512 and sha384 hash functions */ 2 | #ifndef SHA512_H 3 | #define SHA512_H 4 | #include "ustd.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #define sha512_block_size 128 11 | #define sha512_hash_size 64 12 | #define sha384_hash_size 48 13 | 14 | /* algorithm context */ 15 | typedef struct sha512_ctx 16 | { 17 | uint64_t message[16]; /* 1024-bit buffer for leftovers */ 18 | uint64_t length; /* number of processed bytes */ 19 | uint64_t hash[8]; /* 512-bit algorithm internal hashing state */ 20 | unsigned digest_length; /* length of the algorithm digest in bytes */ 21 | } sha512_ctx; 22 | 23 | void rhash_sha384_init(sha512_ctx* ctx); 24 | void rhash_sha512_init(sha512_ctx* ctx); 25 | void rhash_sha512_update(sha512_ctx* ctx, const unsigned char* data, size_t length); 26 | void rhash_sha512_final(sha512_ctx* ctx, unsigned char* result); 27 | 28 | #ifdef __cplusplus 29 | } /* extern "C" */ 30 | #endif /* __cplusplus */ 31 | 32 | #endif /* SHA512_H */ 33 | -------------------------------------------------------------------------------- /depends/rhash/librhash/snefru.h: -------------------------------------------------------------------------------- 1 | /* snefru.h */ 2 | #ifndef SNEFRU_H 3 | #define SNEFRU_H 4 | #include "ustd.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /* Snefru-128 processses message by blocks of 48 bytes, */ 11 | /* and Snefru-256 uses blocks of 32 bytes */ 12 | 13 | /* here we declare the maximal block size */ 14 | #define snefru_block_size 48 15 | 16 | #define snefru128_hash_length 16 17 | #define snefru256_hash_length 32 18 | 19 | /* algorithm context */ 20 | typedef struct snefru_ctx 21 | { 22 | unsigned hash[8]; /* algorithm 512-bit hashing state */ 23 | unsigned char buffer[48]; /* 384-bit message block */ 24 | uint64_t length; /* processed message length */ 25 | unsigned index; /* index in the buffer of the last byte stored */ 26 | unsigned digest_length; /* length of the algorithm digest in bytes */ 27 | } snefru_ctx; 28 | 29 | /* hash functions */ 30 | 31 | void rhash_snefru128_init(snefru_ctx* ctx); 32 | void rhash_snefru256_init(snefru_ctx* ctx); 33 | void rhash_snefru_update(snefru_ctx* ctx, const unsigned char* data, size_t size); 34 | void rhash_snefru_final(snefru_ctx* ctx, unsigned char* result); 35 | 36 | #ifdef __cplusplus 37 | } /* extern "C" */ 38 | #endif /* __cplusplus */ 39 | 40 | #endif /* SNEFRU_H */ 41 | -------------------------------------------------------------------------------- /depends/rhash/librhash/tiger.c: -------------------------------------------------------------------------------- 1 | /* tiger.c - an implementation of Tiger Hash Function 2 | * based on the article by 3 | * Ross Anderson and Eli Biham "Tiger: A Fast New Hash Function". 4 | * 5 | * Copyright (c) 2007, Aleksey Kravchenko 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 11 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 12 | * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 13 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 14 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 15 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 16 | * PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | #include "byte_order.h" 21 | #include "tiger.h" 22 | 23 | /** 24 | * Initialize algorithm context before calculaing hash. 25 | * 26 | * @param ctx context to initialize 27 | */ 28 | void rhash_tiger_init(tiger_ctx* ctx) 29 | { 30 | ctx->length = 0; 31 | ctx->tiger2 = 0; 32 | 33 | /* initialize algorithm state */ 34 | ctx->hash[0] = I64(0x0123456789ABCDEF); 35 | ctx->hash[1] = I64(0xFEDCBA9876543210); 36 | ctx->hash[2] = I64(0xF096A5B4C3B2E187); 37 | } 38 | 39 | /* lookup tables */ 40 | extern uint64_t rhash_tiger_sboxes[4][256]; 41 | #define t1 rhash_tiger_sboxes[0] 42 | #define t2 rhash_tiger_sboxes[1] 43 | #define t3 rhash_tiger_sboxes[2] 44 | #define t4 rhash_tiger_sboxes[3] 45 | 46 | #ifdef CPU_X64 /* for x86-64 */ 47 | #define round(a,b,c,x,mul) \ 48 | c ^= x; \ 49 | a -= t1[(uint8_t)(c)] ^ \ 50 | t2[(uint8_t)((c) >> (2 * 8))] ^ \ 51 | t3[(uint8_t)((c) >> (4 * 8))] ^ \ 52 | t4[(uint8_t)((c) >> (6 * 8))] ; \ 53 | b += t4[(uint8_t)((c) >> (1 * 8))] ^ \ 54 | t3[(uint8_t)((c) >> (3 * 8))] ^ \ 55 | t2[(uint8_t)((c) >> (5 * 8))] ^ \ 56 | t1[(uint8_t)((c) >> (7 * 8))]; \ 57 | b *= mul; 58 | 59 | #else /* for IA32 */ 60 | 61 | #define round(a,b,c,x,mul) \ 62 | c ^= x; \ 63 | a -= t1[(uint8_t)(c)] ^ \ 64 | t2[(uint8_t)(((uint32_t)(c)) >> (2 * 8))] ^ \ 65 | t3[(uint8_t)((c) >> (4 * 8))] ^ \ 66 | t4[(uint8_t)(((uint32_t)((c) >> (4 * 8))) >> (2 * 8))] ; \ 67 | b += t4[(uint8_t)(((uint32_t)(c)) >> (1 * 8))] ^ \ 68 | t3[(uint8_t)(((uint32_t)(c)) >> (3 * 8))] ^ \ 69 | t2[(uint8_t)(((uint32_t)((c) >> (4 * 8))) >> (1 * 8))] ^ \ 70 | t1[(uint8_t)(((uint32_t)((c) >> (4 * 8))) >> (3 * 8))]; \ 71 | b *= mul; 72 | #endif /* CPU_X64 */ 73 | 74 | #define pass(a,b,c,mul) \ 75 | round(a,b,c,x0,mul) \ 76 | round(b,c,a,x1,mul) \ 77 | round(c,a,b,x2,mul) \ 78 | round(a,b,c,x3,mul) \ 79 | round(b,c,a,x4,mul) \ 80 | round(c,a,b,x5,mul) \ 81 | round(a,b,c,x6,mul) \ 82 | round(b,c,a,x7,mul) 83 | 84 | #define key_schedule { \ 85 | x0 -= x7 ^ I64(0xA5A5A5A5A5A5A5A5); \ 86 | x1 ^= x0; \ 87 | x2 += x1; \ 88 | x3 -= x2 ^ ((~x1)<<19); \ 89 | x4 ^= x3; \ 90 | x5 += x4; \ 91 | x6 -= x5 ^ ((~x4)>>23); \ 92 | x7 ^= x6; \ 93 | x0 += x7; \ 94 | x1 -= x0 ^ ((~x7)<<19); \ 95 | x2 ^= x1; \ 96 | x3 += x2; \ 97 | x4 -= x3 ^ ((~x2)>>23); \ 98 | x5 ^= x4; \ 99 | x6 += x5; \ 100 | x7 -= x6 ^ I64(0x0123456789ABCDEF); \ 101 | } 102 | 103 | /** 104 | * The core transformation. Process a 512-bit block. 105 | * 106 | * @param state the algorithm state 107 | * @param block the message block to process 108 | */ 109 | static void rhash_tiger_process_block(uint64_t state[3], uint64_t* block) 110 | { 111 | /* Optimized for GCC IA32. 112 | The order of declarations is important for compiler. */ 113 | uint64_t a, b, c; 114 | uint64_t x0, x1, x2, x3, x4, x5, x6, x7; 115 | #ifndef CPU_X64 116 | uint64_t tmp; 117 | char i; 118 | #endif 119 | 120 | x0 = le2me_64(block[0]); x1 = le2me_64(block[1]); 121 | x2 = le2me_64(block[2]); x3 = le2me_64(block[3]); 122 | x4 = le2me_64(block[4]); x5 = le2me_64(block[5]); 123 | x6 = le2me_64(block[6]); x7 = le2me_64(block[7]); 124 | 125 | a = state[0]; 126 | b = state[1]; 127 | c = state[2]; 128 | 129 | /* passes and key shedules */ 130 | #ifndef CPU_X64 131 | for (i = 0; i < 3; i++) { 132 | if (i != 0) key_schedule; 133 | pass(a, b, c, (i == 0 ? 5 : i == 1 ? 7 : 9)); 134 | tmp = a; 135 | a = c; 136 | c = b; 137 | b = tmp; 138 | } 139 | #else 140 | pass(a, b, c, 5); 141 | key_schedule; 142 | pass(c, a, b, 7); 143 | key_schedule; 144 | pass(b, c, a, 9); 145 | #endif 146 | 147 | /* feedforward operation */ 148 | state[0] = a ^ state[0]; 149 | state[1] = b - state[1]; 150 | state[2] = c + state[2]; 151 | } 152 | 153 | /** 154 | * Calculate message hash. 155 | * Can be called repeatedly with chunks of the message to be hashed. 156 | * 157 | * @param ctx the algorithm context containing current hashing state 158 | * @param msg message chunk 159 | * @param size length of the message chunk 160 | */ 161 | void rhash_tiger_update(tiger_ctx* ctx, const unsigned char* msg, size_t size) 162 | { 163 | size_t index = (size_t)ctx->length & 63; 164 | ctx->length += size; 165 | 166 | /* fill partial block */ 167 | if (index) { 168 | size_t left = tiger_block_size - index; 169 | if (size < left) { 170 | if (size > 0) 171 | memcpy(ctx->message + index, msg, size); 172 | return; 173 | } else { 174 | memcpy(ctx->message + index, msg, left); 175 | rhash_tiger_process_block(ctx->hash, (uint64_t*)ctx->message); 176 | msg += left; 177 | size -= left; 178 | } 179 | } 180 | while (size >= tiger_block_size) { 181 | if (IS_ALIGNED_64(msg)) { 182 | /* the most common case is processing of an already aligned message 183 | without copying it */ 184 | rhash_tiger_process_block(ctx->hash, (uint64_t*)msg); 185 | } else { 186 | memcpy(ctx->message, msg, tiger_block_size); 187 | rhash_tiger_process_block(ctx->hash, (uint64_t*)ctx->message); 188 | } 189 | 190 | msg += tiger_block_size; 191 | size -= tiger_block_size; 192 | } 193 | if (size) { 194 | /* save leftovers */ 195 | memcpy(ctx->message, msg, size); 196 | } 197 | } 198 | 199 | /** 200 | * Store calculated hash into the given array. 201 | * 202 | * @param ctx the algorithm context containing current hashing state 203 | * @param result calculated hash in binary form 204 | */ 205 | void rhash_tiger_final(tiger_ctx* ctx, unsigned char result[24]) 206 | { 207 | unsigned index = (unsigned)ctx->length & 63; 208 | uint64_t* msg64 = (uint64_t*)ctx->message; 209 | 210 | /* pad message and run for last block */ 211 | 212 | /* append the byte 0x01 to the message */ 213 | ctx->message[index++] = (ctx->tiger2 ? 0x80 : 0x01); 214 | 215 | /* if no room left in the message to store 64-bit message length */ 216 | if (index > 56) { 217 | /* then fill the rest with zeros and process it */ 218 | while (index < 64) { 219 | ctx->message[index++] = 0; 220 | } 221 | rhash_tiger_process_block(ctx->hash, msg64); 222 | index = 0; 223 | } 224 | while (index < 56) { 225 | ctx->message[index++] = 0; 226 | } 227 | msg64[7] = le2me_64(ctx->length << 3); 228 | rhash_tiger_process_block(ctx->hash, msg64); 229 | 230 | /* save result hash */ 231 | le64_copy(result, 0, &ctx->hash, 24); 232 | } 233 | -------------------------------------------------------------------------------- /depends/rhash/librhash/tiger.h: -------------------------------------------------------------------------------- 1 | /* tiger.h */ 2 | #ifndef TIGER_H 3 | #define TIGER_H 4 | #include "ustd.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #define tiger_block_size 64 11 | #define tiger_hash_length 24 12 | 13 | /* algorithm context */ 14 | typedef struct tiger_ctx 15 | { 16 | /* the order of the fields slightly influence the algorithm speed */ 17 | uint64_t hash[3]; /* algorithm 192-bit state */ 18 | unsigned char message[tiger_block_size]; /* 512-bit buffer for leftovers */ 19 | uint64_t length; /* processed message length */ 20 | int tiger2; /* flag, 1 for Tiger2 algorithm, default is 0 */ 21 | } tiger_ctx; 22 | 23 | /* hash functions */ 24 | 25 | void rhash_tiger_init(tiger_ctx* ctx); 26 | void rhash_tiger_update(tiger_ctx* ctx, const unsigned char* msg, size_t size); 27 | void rhash_tiger_final(tiger_ctx* ctx, unsigned char result[24]); 28 | 29 | #ifdef __cplusplus 30 | } /* extern "C" */ 31 | #endif /* __cplusplus */ 32 | 33 | #endif /* TIGER_H */ 34 | -------------------------------------------------------------------------------- /depends/rhash/librhash/torrent.h: -------------------------------------------------------------------------------- 1 | /* torrent.h */ 2 | #ifndef TORRENT_H 3 | #define TORRENT_H 4 | #include "ustd.h" 5 | #include "sha1.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #define btih_hash_size 20 12 | 13 | /* vector structure */ 14 | typedef struct torrent_vect 15 | { 16 | void** array; /* array of elements of the vector */ 17 | size_t size; /* vector size */ 18 | size_t allocated; /* number of allocated elements */ 19 | } torrent_vect; 20 | 21 | /* a binary string */ 22 | typedef struct torrent_str 23 | { 24 | char* str; 25 | size_t length; 26 | size_t allocated; 27 | } torrent_str; 28 | 29 | /* BitTorrent algorithm context */ 30 | typedef struct torrent_ctx 31 | { 32 | unsigned char btih[20]; /* resulting BTIH hash sum */ 33 | unsigned options; /* algorithm options */ 34 | sha1_ctx sha1_context; /* context for hashing current file piece */ 35 | #if defined(USE_OPENSSL) || defined(OPENSSL_RUNTIME) 36 | unsigned long reserved; /* need more space for OpenSSL SHA1 context */ 37 | void (*sha_init)(void*); 38 | void (*sha_update)(void*, const void*, size_t size); 39 | void (*sha_final)(void*, unsigned char*); 40 | #endif 41 | size_t index; /* byte index in the current piece */ 42 | size_t piece_length; /* length of a torrent file piece */ 43 | size_t piece_count; /* the number of pieces processed */ 44 | torrent_vect hash_blocks; /* array of blocks storing SHA1 hashes */ 45 | torrent_vect files; /* names of files in a torrent batch */ 46 | torrent_vect announce; /* announce URLs */ 47 | char* program_name; /* the name of the program */ 48 | 49 | torrent_str content; /* the content of generated torrent file */ 50 | int error; /* non-zero if error occurred, zero otherwise */ 51 | } torrent_ctx; 52 | 53 | void bt_init(torrent_ctx* ctx); 54 | void bt_update(torrent_ctx* ctx, const void* msg, size_t size); 55 | void bt_final(torrent_ctx* ctx, unsigned char result[20]); 56 | void bt_cleanup(torrent_ctx* ctx); 57 | 58 | unsigned char* bt_get_btih(torrent_ctx* ctx); 59 | size_t bt_get_text(torrent_ctx* ctx, char** pstr); 60 | 61 | /* possible options */ 62 | #define BT_OPT_PRIVATE 1 63 | #define BT_OPT_INFOHASH_ONLY 2 64 | 65 | void bt_set_options(torrent_ctx* ctx, unsigned options); 66 | int bt_add_file(torrent_ctx* ctx, const char* path, uint64_t filesize); 67 | int bt_add_announce(torrent_ctx* ctx, const char* announce_url); 68 | int bt_set_program_name(torrent_ctx* ctx, const char* name); 69 | void bt_set_piece_length(torrent_ctx* ctx, size_t piece_length); 70 | size_t bt_default_piece_length(uint64_t total_size); 71 | 72 | #ifdef __cplusplus 73 | } /* extern "C" */ 74 | #endif /* __cplusplus */ 75 | 76 | #endif /* TORRENT_H */ 77 | -------------------------------------------------------------------------------- /depends/rhash/librhash/tth.c: -------------------------------------------------------------------------------- 1 | /* tth.c - calculate TTH (Tiger Tree Hash) function. 2 | * 3 | * Copyright (c) 2007, Aleksey Kravchenko 4 | * 5 | * Permission to use, copy, modify, and/or distribute this software for any 6 | * purpose with or without fee is hereby granted. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 9 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 | * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 11 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 13 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 | * PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | #include "byte_order.h" 19 | #include "tth.h" 20 | 21 | /** 22 | * Initialize context before calculaing hash. 23 | * 24 | * @param ctx context to initialize 25 | */ 26 | void rhash_tth_init(tth_ctx* ctx) 27 | { 28 | rhash_tiger_init(&ctx->tiger); 29 | ctx->tiger.message[ ctx->tiger.length++ ] = 0x00; 30 | ctx->block_count = 0; 31 | } 32 | 33 | /** 34 | * The core transformation. 35 | * 36 | * @param ctx algorithm state 37 | */ 38 | static void rhash_tth_process_block(tth_ctx* ctx) 39 | { 40 | uint64_t it; 41 | unsigned pos = 0; 42 | unsigned char msg[24]; 43 | 44 | for (it = 1; it & ctx->block_count; it <<= 1) { 45 | rhash_tiger_final(&ctx->tiger, msg); 46 | rhash_tiger_init(&ctx->tiger); 47 | ctx->tiger.message[ctx->tiger.length++] = 0x01; 48 | rhash_tiger_update(&ctx->tiger, (unsigned char*)(ctx->stack + pos), 24); 49 | /* note: we can cut this step, if the previous rhash_tiger_final saves directly to ctx->tiger.message+25; */ 50 | rhash_tiger_update(&ctx->tiger, msg, 24); 51 | pos += 3; 52 | } 53 | rhash_tiger_final(&ctx->tiger, (unsigned char*)(ctx->stack + pos)); 54 | ctx->block_count++; 55 | } 56 | 57 | /** 58 | * Calculate message hash. 59 | * Can be called repeatedly with chunks of the message to be hashed. 60 | * 61 | * @param ctx the algorithm context containing current hashing state 62 | * @param msg message chunk 63 | * @param size length of the message chunk 64 | */ 65 | void rhash_tth_update(tth_ctx* ctx, const unsigned char* msg, size_t size) 66 | { 67 | size_t rest = 1025 - (size_t)ctx->tiger.length; 68 | for (;;) { 69 | if (size < rest) rest = size; 70 | rhash_tiger_update(&ctx->tiger, msg, rest); 71 | msg += rest; 72 | size -= rest; 73 | if (ctx->tiger.length < 1025) { 74 | return; 75 | } 76 | 77 | /* process block hash */ 78 | rhash_tth_process_block(ctx); 79 | 80 | /* init block hash */ 81 | rhash_tiger_init(&ctx->tiger); 82 | ctx->tiger.message[ ctx->tiger.length++ ] = 0x00; 83 | rest = 1024; 84 | } 85 | } 86 | 87 | /** 88 | * Store calculated hash into the given array. 89 | * 90 | * @param ctx the algorithm context containing current hashing state 91 | * @param result calculated hash in binary form 92 | */ 93 | void rhash_tth_final(tth_ctx* ctx, unsigned char result[24]) 94 | { 95 | uint64_t it = 1; 96 | unsigned pos = 0; 97 | unsigned char msg[24]; 98 | const unsigned char* last_message; 99 | 100 | /* process the bytes left in the context buffer */ 101 | if (ctx->tiger.length > 1 || ctx->block_count == 0) { 102 | rhash_tth_process_block(ctx); 103 | } 104 | 105 | for (; it < ctx->block_count && (it & ctx->block_count) == 0; it <<= 1) pos += 3; 106 | last_message = (unsigned char*)(ctx->stack + pos); 107 | 108 | for (it <<= 1; it <= ctx->block_count; it <<= 1) { 109 | /* merge TTH sums in the tree */ 110 | pos += 3; 111 | if (it & ctx->block_count) { 112 | rhash_tiger_init(&ctx->tiger); 113 | ctx->tiger.message[ ctx->tiger.length++ ] = 0x01; 114 | rhash_tiger_update(&ctx->tiger, (unsigned char*)(ctx->stack + pos), 24); 115 | rhash_tiger_update(&ctx->tiger, last_message, 24); 116 | 117 | rhash_tiger_final(&ctx->tiger, msg); 118 | last_message = msg; 119 | } 120 | } 121 | 122 | /* save result hash */ 123 | memcpy(ctx->tiger.hash, last_message, tiger_hash_length); 124 | if (result) memcpy(result, last_message, tiger_hash_length); 125 | } 126 | -------------------------------------------------------------------------------- /depends/rhash/librhash/tth.h: -------------------------------------------------------------------------------- 1 | #ifndef TTH_H 2 | #define TTH_H 3 | 4 | #include "ustd.h" 5 | #include "tiger.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | /* algorithm context */ 12 | typedef struct tth_ctx 13 | { 14 | tiger_ctx tiger; /* context used to hash tree leaves */ 15 | uint64_t block_count; /* number of processed blocks */ 16 | uint64_t stack[64 * 3]; 17 | } tth_ctx; 18 | 19 | /* hash functions */ 20 | 21 | void rhash_tth_init(tth_ctx* ctx); 22 | void rhash_tth_update(tth_ctx* ctx, const unsigned char* msg, size_t size); 23 | void rhash_tth_final(tth_ctx* ctx, unsigned char result[24]); 24 | 25 | #ifdef __cplusplus 26 | } /* extern "C" */ 27 | #endif /* __cplusplus */ 28 | 29 | #endif /* TTH_H */ 30 | -------------------------------------------------------------------------------- /depends/rhash/librhash/ustd.h: -------------------------------------------------------------------------------- 1 | /* ustd.h common macros and includes */ 2 | #ifndef LIBRHASH_USTD_H 3 | #define LIBRHASH_USTD_H 4 | 5 | #if _MSC_VER > 1000 6 | # include /* size_t for vc6.0 */ 7 | 8 | # if _MSC_VER >= 1600 9 | /* Visual Studio >= 2010 has stdint.h */ 10 | # include 11 | # else 12 | /* vc6.0 has bug with __int8, so using char instead */ 13 | typedef signed char int8_t; 14 | typedef signed __int16 int16_t; 15 | typedef signed __int32 int32_t; 16 | typedef signed __int64 int64_t; 17 | typedef unsigned char uint8_t; 18 | typedef unsigned __int16 uint16_t; 19 | typedef unsigned __int32 uint32_t; 20 | typedef unsigned __int64 uint64_t; 21 | # endif /* _MSC_VER >= 1600 */ 22 | 23 | /* disable warnings: The POSIX name for this item is deprecated. Use the ISO C++ conformant name. */ 24 | # pragma warning(disable : 4996) 25 | 26 | #else /* _MSC_VER > 1000 */ 27 | 28 | # include 29 | # include 30 | 31 | #endif /* _MSC_VER > 1000 */ 32 | 33 | #endif /* LIBRHASH_USTD_H */ 34 | 35 | -------------------------------------------------------------------------------- /depends/rhash/librhash/util.c: -------------------------------------------------------------------------------- 1 | /* util.c - memory functions. 2 | * 3 | * Copyright (c) 2020, Aleksey Kravchenko 4 | * 5 | * Permission to use, copy, modify, and/or distribute this software for any 6 | * purpose with or without fee is hereby granted. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 9 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 | * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 11 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 13 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 | * PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | #include "util.h" 17 | 18 | #if defined(HAS_POSIX_ALIGNED_ALLOC) 19 | 20 | #include 21 | 22 | void* rhash_px_aalloc(size_t alignment, size_t size) 23 | { 24 | void* ptr; 25 | if ((errno = posix_memalign(&ptr, alignment, size)) != 0) 26 | return NULL; 27 | return ptr; 28 | } 29 | 30 | #elif defined(HAS_GENERIC_ALIGNED_ALLOC) 31 | 32 | #include 33 | #include 34 | 35 | void* rhash_aligned_alloc(size_t alignment, size_t size) 36 | { 37 | unsigned char* block = (unsigned char*)malloc(size + alignment); 38 | assert((alignment & (alignment - 1)) == 0); 39 | assert(alignment >= sizeof(void*)); 40 | if (block) { 41 | const size_t alignment_mask = (alignment - 1); 42 | unsigned char* basement = block + sizeof(void*); 43 | size_t offset = ((unsigned char*)0 - basement) & alignment_mask; 44 | void** result = (void**)(basement + offset); 45 | assert((((unsigned char*)result - (unsigned char*)0) % alignment) == 0); 46 | result[-1] = block; /* store original pointer */ 47 | return result; 48 | } 49 | return NULL; 50 | } 51 | 52 | void rhash_aligned_free(void* ptr) 53 | { 54 | void** pfree = (void**)ptr; 55 | if (ptr) 56 | free(pfree[-1]); 57 | } 58 | 59 | #else 60 | typedef int dummy_declaration_required_by_strict_iso_c; 61 | #endif /* HAS_POSIX_ALIGNED_ALLOC / HAS_GENERIC_ALIGNED_ALLOC */ 62 | -------------------------------------------------------------------------------- /depends/rhash/librhash/util.h: -------------------------------------------------------------------------------- 1 | /* util.h */ 2 | #ifndef UTIL_H 3 | #define UTIL_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | #if (defined(__GNUC__) && __GNUC__ >= 4 && (__GNUC__ > 4 || __GNUC_MINOR__ >= 1) \ 10 | && defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)) \ 11 | || (defined(__INTEL_COMPILER) && !defined(_WIN32)) 12 | /* atomic operations are defined by ICC and GCC >= 4.1, but by the later one supposedly not for ARM */ 13 | /* note: ICC on ia64 platform possibly require ia64intrin.h, need testing */ 14 | # define atomic_compare_and_swap(ptr, oldval, newval) __sync_val_compare_and_swap(ptr, oldval, newval) 15 | #elif defined(_MSC_VER) 16 | # include 17 | # define atomic_compare_and_swap(ptr, oldval, newval) InterlockedCompareExchange(ptr, newval, oldval) 18 | #elif defined(__sun) 19 | # include 20 | # define atomic_compare_and_swap(ptr, oldval, newval) atomic_cas_32(ptr, oldval, newval) 21 | #else 22 | /* pray that it will work */ 23 | # define atomic_compare_and_swap(ptr, oldval, newval) { if (*(ptr) == (oldval)) *(ptr) = (newval); } 24 | # define NO_ATOMIC_BUILTINS 25 | #endif 26 | 27 | /* alignment macros */ 28 | #define DEFAULT_ALIGNMENT 64 29 | #define ALIGN_SIZE_BY(size, align) (((size) + ((align) - 1)) & ~((align) - 1)) 30 | #define IS_SIZE_ALIGNED_BY(size, align) (((size) & ((align) - 1)) == 0) 31 | #define IS_PTR_ALIGNED_BY(ptr, align) IS_SIZE_ALIGNED_BY((uintptr_t)(ptr), (align)) 32 | 33 | /* define rhash_aligned_alloc() and rhash_aligned_free() */ 34 | #if defined(_WIN32) 35 | 36 | # define HAS_WIN32_ALIGNED_ALLOC 37 | # include 38 | # define rhash_aligned_alloc(alignment, size) _aligned_malloc((size), (alignment)) 39 | # define rhash_aligned_free(ptr) _aligned_free(ptr) 40 | 41 | #elif (__STDC_VERSION__ >= 201112L || defined(_ISOC11_SOURCE)) && !defined(__APPLE__) 42 | 43 | # define HAS_STDC_ALIGNED_ALLOC 44 | # include 45 | # define rhash_aligned_alloc(alignment, size) aligned_alloc((alignment), ALIGN_SIZE_BY(size, alignment)) 46 | # define rhash_aligned_free(ptr) free(ptr) 47 | 48 | #else /* defined(_WIN32) ... */ 49 | 50 | # include "ustd.h" /* for _POSIX_VERSION macro */ 51 | 52 | # if _POSIX_VERSION >= 200112L || _XOPEN_SOURCE >= 600 53 | 54 | # define HAS_POSIX_ALIGNED_ALLOC 55 | # include 56 | # define rhash_aligned_alloc(alignment, size) rhash_px_aalloc((alignment), ALIGN_SIZE_BY(size, sizeof(void*))) 57 | # define rhash_aligned_free(ptr) free(ptr) 58 | void* rhash_px_aalloc(size_t size, size_t alignment); 59 | 60 | # else 61 | 62 | # define HAS_GENERIC_ALIGNED_ALLOC 63 | void* rhash_aligned_alloc(size_t alignment, size_t size); 64 | void rhash_aligned_free(void* ptr); 65 | 66 | # endif /* _POSIX_VERSION >= ... */ 67 | #endif /* defined(_WIN32) ... */ 68 | 69 | #ifdef __cplusplus 70 | } /* extern "C" */ 71 | #endif /* __cplusplus */ 72 | 73 | #endif /* UTIL_H */ 74 | -------------------------------------------------------------------------------- /depends/rhash/librhash/whirlpool.c: -------------------------------------------------------------------------------- 1 | /* whirlpool.c - an implementation of the Whirlpool Hash Function. 2 | * 3 | * Copyright (c) 2009, Aleksey Kravchenko 4 | * 5 | * Permission to use, copy, modify, and/or distribute this software for any 6 | * purpose with or without fee is hereby granted. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 9 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 | * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 11 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 13 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 | * PERFORMANCE OF THIS SOFTWARE. 15 | * 16 | * Documentation: 17 | * P. S. L. M. Barreto, V. Rijmen, ``The Whirlpool hashing function,'' 18 | * NESSIE submission, 2000 (tweaked version, 2001) 19 | * 20 | * The algorithm is named after the Whirlpool Galaxy in Canes Venatici. 21 | */ 22 | 23 | #include 24 | #include 25 | #include "byte_order.h" 26 | #include "whirlpool.h" 27 | 28 | /** 29 | * Initialize context before calculaing hash. 30 | * 31 | * @param ctx context to initialize 32 | */ 33 | void rhash_whirlpool_init(struct whirlpool_ctx* ctx) 34 | { 35 | ctx->length = 0; 36 | memset(ctx->hash, 0, sizeof(ctx->hash)); 37 | } 38 | 39 | /* Algorithm S-Box */ 40 | extern uint64_t rhash_whirlpool_sbox[8][256]; 41 | 42 | #define WHIRLPOOL_OP(src, shift) ( \ 43 | rhash_whirlpool_sbox[0][(int)(src[ shift & 7] >> 56) ] ^ \ 44 | rhash_whirlpool_sbox[1][(int)(src[(shift + 7) & 7] >> 48) & 0xff] ^ \ 45 | rhash_whirlpool_sbox[2][(int)(src[(shift + 6) & 7] >> 40) & 0xff] ^ \ 46 | rhash_whirlpool_sbox[3][(int)(src[(shift + 5) & 7] >> 32) & 0xff] ^ \ 47 | rhash_whirlpool_sbox[4][(int)(src[(shift + 4) & 7] >> 24) & 0xff] ^ \ 48 | rhash_whirlpool_sbox[5][(int)(src[(shift + 3) & 7] >> 16) & 0xff] ^ \ 49 | rhash_whirlpool_sbox[6][(int)(src[(shift + 2) & 7] >> 8) & 0xff] ^ \ 50 | rhash_whirlpool_sbox[7][(int)(src[(shift + 1) & 7] ) & 0xff]) 51 | 52 | /** 53 | * The core transformation. Process a 512-bit block. 54 | * 55 | * @param hash algorithm state 56 | * @param block the message block to process 57 | */ 58 | static void rhash_whirlpool_process_block(uint64_t* hash, uint64_t* p_block) 59 | { 60 | int i; /* loop counter */ 61 | uint64_t K[2][8]; /* key */ 62 | uint64_t state[2][8]; /* state */ 63 | 64 | /* alternating binary flags */ 65 | unsigned int m = 0; 66 | 67 | /* the number of rounds of the internal dedicated block cipher */ 68 | const int number_of_rounds = 10; 69 | 70 | /* array used in the rounds */ 71 | static const uint64_t rc[10] = { 72 | I64(0x1823c6e887b8014f), 73 | I64(0x36a6d2f5796f9152), 74 | I64(0x60bc9b8ea30c7b35), 75 | I64(0x1de0d7c22e4bfe57), 76 | I64(0x157737e59ff04ada), 77 | I64(0x58c9290ab1a06b85), 78 | I64(0xbd5d10f4cb3e0567), 79 | I64(0xe427418ba77d95d8), 80 | I64(0xfbee7c66dd17479e), 81 | I64(0xca2dbf07ad5a8333) 82 | }; 83 | 84 | /* map the message buffer to a block */ 85 | for (i = 0; i < 8; i++) { 86 | /* store K^0 and xor it with the intermediate hash state */ 87 | K[0][i] = hash[i]; 88 | state[0][i] = be2me_64(p_block[i]) ^ hash[i]; 89 | hash[i] = state[0][i]; 90 | } 91 | 92 | /* iterate over algorithm rounds */ 93 | for (i = 0; i < number_of_rounds; i++) 94 | { 95 | /* compute K^i from K^{i-1} */ 96 | K[m ^ 1][0] = WHIRLPOOL_OP(K[m], 0) ^ rc[i]; 97 | K[m ^ 1][1] = WHIRLPOOL_OP(K[m], 1); 98 | K[m ^ 1][2] = WHIRLPOOL_OP(K[m], 2); 99 | K[m ^ 1][3] = WHIRLPOOL_OP(K[m], 3); 100 | K[m ^ 1][4] = WHIRLPOOL_OP(K[m], 4); 101 | K[m ^ 1][5] = WHIRLPOOL_OP(K[m], 5); 102 | K[m ^ 1][6] = WHIRLPOOL_OP(K[m], 6); 103 | K[m ^ 1][7] = WHIRLPOOL_OP(K[m], 7); 104 | 105 | /* apply the i-th round transformation */ 106 | state[m ^ 1][0] = WHIRLPOOL_OP(state[m], 0) ^ K[m ^ 1][0]; 107 | state[m ^ 1][1] = WHIRLPOOL_OP(state[m], 1) ^ K[m ^ 1][1]; 108 | state[m ^ 1][2] = WHIRLPOOL_OP(state[m], 2) ^ K[m ^ 1][2]; 109 | state[m ^ 1][3] = WHIRLPOOL_OP(state[m], 3) ^ K[m ^ 1][3]; 110 | state[m ^ 1][4] = WHIRLPOOL_OP(state[m], 4) ^ K[m ^ 1][4]; 111 | state[m ^ 1][5] = WHIRLPOOL_OP(state[m], 5) ^ K[m ^ 1][5]; 112 | state[m ^ 1][6] = WHIRLPOOL_OP(state[m], 6) ^ K[m ^ 1][6]; 113 | state[m ^ 1][7] = WHIRLPOOL_OP(state[m], 7) ^ K[m ^ 1][7]; 114 | 115 | m = m ^ 1; 116 | } 117 | 118 | /* apply the Miyaguchi-Preneel compression function */ 119 | hash[0] ^= state[0][0]; 120 | hash[1] ^= state[0][1]; 121 | hash[2] ^= state[0][2]; 122 | hash[3] ^= state[0][3]; 123 | hash[4] ^= state[0][4]; 124 | hash[5] ^= state[0][5]; 125 | hash[6] ^= state[0][6]; 126 | hash[7] ^= state[0][7]; 127 | } 128 | 129 | /** 130 | * Calculate message hash. 131 | * Can be called repeatedly with chunks of the message to be hashed. 132 | * 133 | * @param ctx the algorithm context containing current hashing state 134 | * @param msg message chunk 135 | * @param size length of the message chunk 136 | */ 137 | void rhash_whirlpool_update(whirlpool_ctx* ctx, const unsigned char* msg, size_t size) 138 | { 139 | unsigned index = (unsigned)ctx->length & 63; 140 | unsigned left; 141 | ctx->length += size; 142 | 143 | /* fill partial block */ 144 | if (index) { 145 | left = whirlpool_block_size - index; 146 | memcpy(ctx->message + index, msg, (size < left ? size : left)); 147 | if (size < left) return; 148 | 149 | /* process partial block */ 150 | rhash_whirlpool_process_block(ctx->hash, (uint64_t*)ctx->message); 151 | msg += left; 152 | size -= left; 153 | } 154 | while (size >= whirlpool_block_size) { 155 | uint64_t* aligned_message_block; 156 | if (IS_ALIGNED_64(msg)) { 157 | /* the most common case is processing of an already aligned message 158 | without copying it */ 159 | aligned_message_block = (uint64_t*)msg; 160 | } else { 161 | memcpy(ctx->message, msg, whirlpool_block_size); 162 | aligned_message_block = (uint64_t*)ctx->message; 163 | } 164 | 165 | rhash_whirlpool_process_block(ctx->hash, aligned_message_block); 166 | msg += whirlpool_block_size; 167 | size -= whirlpool_block_size; 168 | } 169 | if (size) { 170 | /* save leftovers */ 171 | memcpy(ctx->message, msg, size); 172 | } 173 | } 174 | 175 | /** 176 | * Store calculated hash into the given array. 177 | * 178 | * @param ctx the algorithm context containing current hashing state 179 | * @param result calculated hash in binary form 180 | */ 181 | void rhash_whirlpool_final(whirlpool_ctx* ctx, unsigned char* result) 182 | { 183 | unsigned index = (unsigned)ctx->length & 63; 184 | uint64_t* msg64 = (uint64_t*)ctx->message; 185 | 186 | /* pad message and run for last block */ 187 | ctx->message[index++] = 0x80; 188 | 189 | /* if no room left in the message to store 256-bit message length */ 190 | if (index > 32) { 191 | /* then pad the rest with zeros and process it */ 192 | while (index < 64) { 193 | ctx->message[index++] = 0; 194 | } 195 | rhash_whirlpool_process_block(ctx->hash, msg64); 196 | index = 0; 197 | } 198 | /* due to optimization actually only 64-bit of message length are stored */ 199 | while (index < 56) { 200 | ctx->message[index++] = 0; 201 | } 202 | msg64[7] = be2me_64(ctx->length << 3); 203 | rhash_whirlpool_process_block(ctx->hash, msg64); 204 | 205 | /* save result hash */ 206 | be64_copy(result, 0, ctx->hash, 64); 207 | } 208 | -------------------------------------------------------------------------------- /depends/rhash/librhash/whirlpool.h: -------------------------------------------------------------------------------- 1 | /* whirlpool.h */ 2 | #ifndef WHIRLPOOL_H 3 | #define WHIRLPOOL_H 4 | #include "ustd.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #define whirlpool_block_size 64 11 | 12 | /* algorithm context */ 13 | typedef struct whirlpool_ctx 14 | { 15 | uint64_t hash[8]; /* 512-bit algorithm internal hashing state */ 16 | unsigned char message[whirlpool_block_size]; /* 512-bit buffer to hash */ 17 | 18 | /* Note: original algorith uses 256-bit counter, allowing to hash up to 19 | 2^256 bits sized message. For optimization we use here 64-bit counter, 20 | thus reducing maximal message size to 2^64 bits = 2 Exbibytes = 2^21 TiB) */ 21 | uint64_t length; /* number of processed bytes */ 22 | } whirlpool_ctx; 23 | 24 | /* hash functions */ 25 | 26 | void rhash_whirlpool_init(whirlpool_ctx* ctx); 27 | void rhash_whirlpool_update(whirlpool_ctx* ctx, const unsigned char* msg, size_t size); 28 | void rhash_whirlpool_final(whirlpool_ctx* ctx, unsigned char* result); 29 | 30 | #ifdef __cplusplus 31 | } /* extern "C" */ 32 | #endif /* __cplusplus */ 33 | 34 | #endif /* WHIRLPOOL_H */ 35 | -------------------------------------------------------------------------------- /depends/rhash/rhash.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | Source Files 38 | 39 | 40 | Source Files 41 | 42 | 43 | Source Files 44 | 45 | 46 | Source Files 47 | 48 | 49 | Source Files 50 | 51 | 52 | Source Files 53 | 54 | 55 | Source Files 56 | 57 | 58 | Source Files 59 | 60 | 61 | Source Files 62 | 63 | 64 | Source Files 65 | 66 | 67 | Source Files 68 | 69 | 70 | Source Files 71 | 72 | 73 | Source Files 74 | 75 | 76 | Source Files 77 | 78 | 79 | Source Files 80 | 81 | 82 | Source Files 83 | 84 | 85 | Source Files 86 | 87 | 88 | Source Files 89 | 90 | 91 | Source Files 92 | 93 | 94 | Source Files 95 | 96 | 97 | Source Files 98 | 99 | 100 | Source Files 101 | 102 | 103 | Source Files 104 | 105 | 106 | 107 | 108 | Header Files 109 | 110 | 111 | Header Files 112 | 113 | 114 | Header Files 115 | 116 | 117 | Header Files 118 | 119 | 120 | Header Files 121 | 122 | 123 | Header Files 124 | 125 | 126 | Header Files 127 | 128 | 129 | Header Files 130 | 131 | 132 | Header Files 133 | 134 | 135 | Header Files 136 | 137 | 138 | Header Files 139 | 140 | 141 | Header Files 142 | 143 | 144 | Header Files 145 | 146 | 147 | Header Files 148 | 149 | 150 | Header Files 151 | 152 | 153 | Header Files 154 | 155 | 156 | Header Files 157 | 158 | 159 | Header Files 160 | 161 | 162 | Header Files 163 | 164 | 165 | Header Files 166 | 167 | 168 | Header Files 169 | 170 | 171 | Header Files 172 | 173 | 174 | Header Files 175 | 176 | 177 | Header Files 178 | 179 | 180 | Header Files 181 | 182 | 183 | Header Files 184 | 185 | 186 | Header Files 187 | 188 | 189 | Header Files 190 | 191 | 192 | Header Files 193 | 194 | 195 | -------------------------------------------------------------------------------- /depends/rhash/rhash.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /depends/rhash/version.h: -------------------------------------------------------------------------------- 1 | #define VERSION "1.4.2" 2 | #define RHASH_XVERSION VERSION 3 | -------------------------------------------------------------------------------- /extra/m4.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 5 | Midl 6 | CustomBuild 7 | 8 | 9 | _SelectedFiles;$(M4_MacroDependsOn) 11 | 12 | 13 | 14 | $(OutDir)%(Filename) 15 | m4 -P [AdditionalOptions] [Inputs] > [OutputFile] 16 | Processing m4 script (%(Identity)) ... 17 | version.m4i 18 | 19 | 20 | -------------------------------------------------------------------------------- /extra/m4.targets: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 6 | 8 | _M4_Macro 9 | 10 | 11 | 15 | $(MSBuildThisFileDirectory)$(MSBuildThisFileName).xml 16 | 17 | 25 | 27 | 30 | 31 | 32 | 35 | @(M4_Macro, '|') 36 | 37 | 38 | 41 | 45 | 51 | 52 | 53 | 54 | $(ComputeLinkInputsTargets); 55 | ComputeM4_MacroOutput; 56 | 57 | 58 | $(ComputeLibInputsTargets); 59 | ComputeM4_MacroOutput; 60 | 61 | 62 | 65 | 66 | 69 | 72 | 75 | 78 | 79 | 81 | 82 | -------------------------------------------------------------------------------- /extra/m4.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 8 | 9 | 12 | 13 | 14 | 16 | 17 | General 18 | 19 | 20 | 23 | 24 | Command Line 25 | 26 | 27 | 28 | 33 | 34 | 38 | 39 | 40 | 45 | 50 | 55 | 56 | Execute Before 57 | 58 | 59 | Specifies the targets for the build customization to run before. 60 | 61 | 62 | 65 | 66 | 67 | 70 | 71 | 72 | 77 | 78 | Execute After 79 | 80 | 81 | Specifies the targets for the build customization to run after. 82 | 83 | 84 | 87 | 88 | 89 | 93 | 94 | 95 | 100 | 105 | 110 | 114 | 115 | Additional Options 116 | 117 | 118 | Additional Options 119 | 120 | 121 | 122 | 125 | 128 | 132 | -------------------------------------------------------------------------------- /extra/pack_releases.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | ECHO Fetching version 4 | 5 | for /f %%i in ('m4 -P version.txt.m4') do set PVER=%%i 6 | 7 | IF "%PVER%" == "" GOTO :EMPTY_VERSION 8 | ECHO Version found: %PVER% 9 | ECHO. 10 | 11 | ECHO Searching for Visual Studio 12 | 13 | IF DEFINED ProgramFiles(x86) ( 14 | SET VS_WHERE_PATH="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer" 15 | ) ELSE ( 16 | SET VS_WHERE_PATH="%ProgramFiles%\Microsoft Visual Studio\Installer" 17 | ) 18 | 19 | SET PATH=%PATH%;%VS_WHERE_PATH% 20 | for /f "usebackq tokens=1* delims=: " %%i in (`vswhere.exe -latest -requires Microsoft.VisualStudio.Workload.NativeDesktop`) do ( 21 | if /i "%%i"=="productPath" set DEVENV_EXE_PATH="%%j" 22 | ) 23 | 24 | IF EXIST %DEVENV_EXE_PATH% GOTO VS_FOUND 25 | ECHO [ERROR] MS Visual Studio 2017 is not found. Exiting. 26 | PAUSE 27 | EXIT 1 28 | 29 | :VS_FOUND 30 | ECHO Using Visual Studio from 31 | ECHO %DEVENV_EXE_PATH% 32 | ECHO. 33 | 34 | SET SOLUTION_FILE=..\IntChecker2.sln 35 | 36 | :Far2 37 | ECHO Building version for Far 2 x86 38 | call :Build_Version Far2 Win32 x86 39 | if ERRORLEVEL == 1 GOTO BUILD_ERROR 40 | if ERRORLEVEL == 2 GOTO PACK_ERROR 41 | 42 | :Far2x64 43 | ECHO Building version for Far 2 x64 44 | call :Build_Version Far2 x64 x64 45 | if ERRORLEVEL == 1 GOTO BUILD_ERROR 46 | if ERRORLEVEL == 2 GOTO PACK_ERROR 47 | 48 | :Far3 49 | ECHO Building version for Far 3 x86 50 | call :Build_Version Far3 Win32 x86 51 | if ERRORLEVEL == 1 GOTO BUILD_ERROR 52 | if ERRORLEVEL == 2 GOTO PACK_ERROR 53 | 54 | :Far3x64 55 | ECHO Building version for Far 3 x64 56 | call :Build_Version Far3 x64 x64 57 | if ERRORLEVEL == 1 GOTO BUILD_ERROR 58 | if ERRORLEVEL == 2 GOTO PACK_ERROR 59 | 60 | :Done 61 | ECHO [SUCCESS] 62 | EXIT 0 63 | 64 | :Build_Version 65 | REM Arguments 66 | 67 | ECHO Executing build 68 | %DEVENV_EXE_PATH% /Rebuild "Release-%~1|%~2" "%SOLUTION_FILE%" 69 | IF NOT EXIST ..\bin\Release-%~1-%~2\ EXIT /B 1 70 | ECHO Packing archive 71 | SET SCRIPTS= 72 | IF "%~1" == "Far3" SET SCRIPTS=.\*.lua 73 | rar.exe a -y -r -ep1 -apIntChecker2 -x*.iobj -x*.ipdb -- ..\bin\IntChecker2_%~1_%~3_%PVER%.rar "..\bin\Release-%~1-%~2\*" "..\source\Text\*.txt" %SCRIPTS% > nul 74 | if NOT ERRORLEVEL == 0 EXIT /B 2 75 | ECHO Cleanup 76 | rmdir /s /q "..\bin\Release-%~1-%~2\" 77 | rmdir /s /q "..\obj\Release-%~1-%~2\" 78 | ECHO. 79 | EXIT /B 0 80 | 81 | :PACK_ERROR 82 | ECHO Unable to pack release into archive 83 | EXIT 1 84 | 85 | :EMPTY_VERSION 86 | ECHO Unable to find version information 87 | EXIT 2 88 | 89 | :BUILD_ERROR 90 | ECHO Build failed 91 | EXIT 3 92 | -------------------------------------------------------------------------------- /extra/scripts/IntChecker.GetFileHash.lua: -------------------------------------------------------------------------------- 1 | -- Demo скрипт для вызова плагина 2 | -- 3 | -- Параметры вызова: "команда", "алгоритм", "путь к файлу" 4 | -- Поддерживается пока одна команда "gethash" - получить хеш одного файла 5 | -- Список доступных алгоритмов: crc32, md5, sha1, sha-256, sha-512, sha3-512, whirlpool 6 | -- Регистр в названии команд и в названии алгоритмов не учитывается. 7 | -- Вызов возвращает расчитанный хеш файла. 8 | 9 | Macro { 10 | description="Calculate hash for the file under the cursor"; 11 | area="Shell"; 12 | key="CtrlShiftH"; 13 | action=function() 14 | far.Show (Plugin.SyncCall("E186306E-3B0D-48C1-9668-ED7CF64C0E65", 15 | "gethash", "md5", APanel.Path0.."\\"..APanel.Current)) 16 | end; 17 | } -------------------------------------------------------------------------------- /extra/scripts/script-docs.txt: -------------------------------------------------------------------------------- 1 | Скрипты управления и макросы плагина. 2 | 3 | 1 Макросы плагина. 4 | 5 | Вместе с плагином поставляются скрипты управления содержащие макросы позволяющие 6 | упростить некоторые часто используемые операции. Они расположены в подкаталоге 7 | Scripts плагина в двух Lua скриптах: 8 | 9 | IntChecker.Run.lua - этот скрипт содержит макросы: 10 | 11 | - вызов основного меню плагина по Alt-H; 12 | 13 | - запуск проверки целостности файлов по имеющемуся файлу хэшей который может 14 | быть записан в одном из распознаваемых плагином форматов: 15 | 16 | GNU : * 17 | 18 | или 19 | 20 | BSD (UNIX): () = 21 | 22 | где, - значение хэша; 23 | - путь к файлу для которого вычислен хэш; 24 | - имя алгоритма, используется только в BSD (UNIX) формате записи. 25 | 26 | Имена файлов хэшей должны иметь расширение в зависимости от алгоритма: 27 | 28 | CRC-32 - .sfv; MD5 - .md5; SHA1 - .sha1; SHA-256 - .sha256; 29 | SHA-512 - .sha512; SHA3-512 - .sha3 и для Whirlpool - .wrpl 30 | 31 | этот макрос запускается либо по Enter либо по нажатию колеса мыши или 32 | средней кнопки мыши. 33 | 34 | В макрос встроена проверка на условие "Командная строка пуста?" - если курсор 35 | стоит на хэшфайле и командная строка не пустая, то макрос спросит вас что 36 | сделать: 37 | 38 | при нажатии OK - будет запущена набранная в командной строке команда; 39 | при нажатии Cancel - будет проверена целостность указанных в хэшфайле объектов 40 | 41 | Оговорка: По умолчанию выполнение команды считается более важной задачей. 42 | 43 | Примечание: 44 | 45 | Существуют и другие криптографические алгоритмы длина хэша у которых совпадает 46 | с поддерживаемыми плагином, но если вы решите проверить с их помощью файлы, то 47 | даже при корректном формате хэшфайла получите сообщение плагина "Файл не 48 | является списком хешей", а дальше будете долго и мучительно пытаться понять 49 | почему плагин его отвергает? 50 | 51 | - пошаговый мастер вычисления хэша запускаемый по Alt-G. 52 | 53 | Мастер работает для файла под курсором, выбранных или всех файлов в текущем 54 | каталоге, рекурсивно для текущего каталога, произвольного файла или рекурсивно 55 | поддерева каталогов (выводится запрос пути) и позволяет вывести вычисленный 56 | хэш на экран, либо скопировать его в буфер обмена ОС, или записать в файл. 57 | 58 | Для операций копирования в буфер обмена или записи в файл вы можете выбрать 59 | любой из двух форматов выходной строки - GNU или BSD (UNIX) и пути в стиле 60 | Windows (обратный слэш - "\") или UNIX (прямой слэш - "/"). 61 | 62 | Доступные на текущем шаге мастера хоткеи выводятся в заголовке его поля ввода, 63 | регистр символов игнорируется. Каталоги и файлы нулевой длинны при расчёте 64 | хэша пропускаются, в вывод мастера попадают только файлы, если они находятся в 65 | подкаталоге, то для них указывается относительный путь. За точку отсчёта 66 | принимается указанный вами каталог, формат записи сходен с форматом записи BSD 67 | UNIX: 68 | 69 | SHA-256 (test.txt) = 70 | SHA-256 (Cat\test.txt) = --- Windows стиль пути 71 | SHA-256 (Cat/test.txt) = --- UNIX стиль пути 72 | 73 | Система команд макроса достаточно проста: 74 | 75 | Режимы для объектов на активной панели: 76 | 77 | F - файл. Автоматика скрипта различает когда мы хотим посчитать хэши для 78 | отдельного файла под курсором или группы выделенных файлов и каталогов. 79 | 80 | D - аналогичен режиму F, но для всех файлов в текущем каталоге 81 | 82 | Для произвольных файлов или каталогов находящихся вне панели, в т.ч. и на 83 | сетевых ресурсах: 84 | 85 | U - выводится запрос на ввод UNC пути который может указывать на произвольный 86 | файл либо каталог. Путь может вводится в любом из допустимых UNC форматов: 87 | 88 | \\SERVER\Share\ObjectPath 89 | Disk:\path 90 | 91 | и иметь любой вариант стиля записи пути к файлу (Windows/UNIX). chex() 92 | сама преобразует путь в используемый внутри Windows формат записи и при 93 | необходимости по возможности исправляет ошибки ввода. 94 | 95 | R - учитывать подкаталоги. Флаг R (от Recursive) применим только в комбинации 96 | с командами D или U. В команде F флаг R игнорируется. 97 | 98 | Формат вывода: 99 | 100 | B - в стиле BSD (UNIX) 101 | 102 | G - в стиле GNU LINUX 103 | 104 | Стиль пути к файлам: 105 | 106 | W - Windows 107 | 108 | U - UNIX 109 | 110 | Макрос имеет встроенные средства коррекции ряда типичных ошибок набора, таких 111 | как неправильная раскладка клавиатуры, неверный набок команды. 112 | 113 | В тех случаях когда скрипт сам не сможет исправить ошибку ввода будет выбран 114 | режим по умолчанию: 115 | 116 | Файл под курсором (F), вывод на экран (D), считаем MD5, формат вывода GNU, 117 | стиль пути Windows 118 | 119 | В случае возникновения ошибок по возможности будет проведена диагностика с 120 | выводом сообщения об ошибке и статистикой. В обычных случаях статистика не 121 | выводится за ненужностью, хотя и возвращается chex(). 122 | 123 | Статистика включает счётчики успешно обработанных файлов и числа ошибки. 124 | 125 | Работу скрипта можно прервать в любой момент нажатием кнопки ESC при этом 126 | будет выведено сообщение об отмене операций пользователем. 127 | 128 | Выходной массив сохраняется в каталоге обрабатываемого объекта. 129 | 130 | Если файл не может быть обработан, например если он нулевой длины или доступ 131 | запрещён (Access Denied) то в выходной массив и в статистику обработанных 132 | файлов он не включается, а в случае если доступ к объекту запрещён (Access 133 | Denied) то он включается в счётчик ошибок. 134 | 135 | Коды возврата chex() (1 - 6) расшифровываются скриптом который выводит и 136 | диагностические сообщения пользователю. 137 | 138 | Список кодов возврата chex() v2.1: 139 | 140 | 0 - без ошибок; 141 | 1 - Пустой каталог; 142 | 2 - Рекурсия запрещена и указанный объект не найден; 143 | 3 - Доступ к файлу запрещён, он пропущен, доступные файлы обработаны; 144 | 4 - Доступ к каталогу запрещён, он пропущен, доступные файлы обработаны; 145 | 5 - Выбранный объект не существует; 146 | 6 - Пользователь нажал кнопку отмены (ESC), не обработанные файлы будут 147 | пропущены, а обработка текущего файла прервана; 148 | 149 | Колы возврата chex() v1.0 отличаются от кодов возврата chex() v2.1: 150 | 151 | 0 - без ошибок; 152 | 1 - Пустой каталог, рекурсия запрещена или файлы не найдены; 153 | 2 - Пусть не существует; 154 | 3 - Доступ запрещён; 155 | 4 - Пользователь нажал кнопку отмены (ESC), не обработанные файлы будут 156 | пропущены, а обработка текущего файла прервана; 157 | 158 | 2. Демо-скрипт IntChecker.GetFileHash.lua 159 | 160 | Этот скрипт содержит учебный пример вызова плагина из макросов и вы можете 161 | посмотреть в нём как работать с плагином из макросов, в том числе и 162 | в прерываемых диалогах. 163 | 164 | 3. Установка макросов. 165 | 166 | Установка макросов аналогична другим макросам в Far3 - скопируйте выбранный 167 | файл скрипта в каталог скриптов Far (путь к нему настраивается в Far.exe.ini) 168 | и перезапустите Far, либо если у вас установлен скрипт перезагрузки макросов, 169 | например ReloadMacros.lua можно с его помощью перезагрузить макросы. Главное, 170 | чтобы Far обновил внутренний список доступных в данный момент макросов и тогда 171 | они будут у вас работать. -------------------------------------------------------------------------------- /extra/version.txt.m4: -------------------------------------------------------------------------------- 1 | m4_include(`..\source\version.m4i')m4_dnl 2 | m4_format(`%d.%d.%d',VMAJOR,VMINOR,VREVISION) -------------------------------------------------------------------------------- /source/Far3Guids.h: -------------------------------------------------------------------------------- 1 | #ifndef Far3Guids_h__ 2 | #define Far3Guids_h__ 3 | 4 | // {E186306E-3B0D-48c1-9668-ED7CF64C0E65} 5 | DEFINE_GUID(GUID_PLUGIN_MAIN, 0xe186306e, 0x3b0d, 0x48c1, 0x96, 0x68, 0xed, 0x7c, 0xf6, 0x4c, 0xe, 0x65); 6 | 7 | // {A22F9043-C94A-4037-845C-26ED67E843D1} 8 | DEFINE_GUID(GUID_INFO_MENU, 0xa22f9043, 0xc94a, 0x4037, 0x84, 0x5c, 0x26, 0xed, 0x67, 0xe8, 0x43, 0xd1); 9 | 10 | // {D8CB3CB4-0C6B-4530-810E-10A4ACC176A0} 11 | DEFINE_GUID(GUID_INFO_CONFIG, 0xd8cb3cb4, 0xc6b, 0x4530, 0x81, 0xe, 0x10, 0xa4, 0xac, 0xc1, 0x76, 0xa0); 12 | 13 | // {A41F7DA9-F678-48F5-8159-BF615C4B9EB7} 14 | DEFINE_GUID(GUID_MESSAGE_BOX, 0xa41f7da9, 0xf678, 0x48f5, 0x81, 0x59, 0xbf, 0x61, 0x5c, 0x4b, 0x9e, 0xb7); 15 | 16 | // {01672689-DED5-4BF6-A6EB-88A0B7EC0D0F} 17 | DEFINE_GUID(GUID_DIALOG_RESULTS, 0x1672689, 0xded5, 0x4bf6, 0xa6, 0xeb, 0x88, 0xa0, 0xb7, 0xec, 0xd, 0xf); 18 | 19 | // {CF96C10C-C1A3-432E-87A6-FA9B26A0D18C} 20 | DEFINE_GUID(GUID_DIALOG_MENU, 0xcf96c10c, 0xc1a3, 0x432e, 0x87, 0xa6, 0xfa, 0x9b, 0x26, 0xa0, 0xd1, 0x8c); 21 | 22 | // {0D011242-50C9-4151-A399-2F1F5C306978} 23 | DEFINE_GUID(GUID_DIALOG_PARAMS, 0xd011242, 0x50c9, 0x4151, 0xa3, 0x99, 0x2f, 0x1f, 0x5c, 0x30, 0x69, 0x78); 24 | 25 | // {A7325930-9E21-48C5-9D32-7885A6A04172} 26 | DEFINE_GUID(GUID_DIALOG_CONFIG, 0xa7325930, 0x9e21, 0x48c5, 0x9d, 0x32, 0x78, 0x85, 0xa6, 0xa0, 0x41, 0x72); 27 | 28 | #endif // Far3Guids_h__ 29 | -------------------------------------------------------------------------------- /source/FarCommon.h: -------------------------------------------------------------------------------- 1 | #ifndef FarCommon_h__ 2 | #define FarCommon_h__ 3 | 4 | #include "hashing.h" 5 | #include "Lang.h" 6 | 7 | PluginStartupInfo FarSInfo; 8 | static FARSTANDARDFUNCTIONS FSF; 9 | 10 | enum HashOutputTargets 11 | { 12 | OT_SINGLEFILE = 0, // One single hash file for all selected input files 13 | OT_SEPARATEFILES = 1, // One hash file per one input file 14 | OT_DISPLAY = 2, 15 | OT_SEPARATEDIRS = 3 // One hash file per one directory 16 | }; 17 | 18 | #define EDR_SKIP 0 19 | #define EDR_SKIPALL 1 20 | #define EDR_RETRY 2 21 | #define EDR_ABORT 3 22 | 23 | const size_t cntProgressDialogWidth = 65; 24 | const int cntProgressRedrawTimeout = 50; // ms 25 | 26 | class FarScreenSave 27 | { 28 | private: 29 | HANDLE hScreen; 30 | 31 | public: 32 | FarScreenSave() 33 | { 34 | hScreen = FarSInfo.SaveScreen(0, 0, -1, -1); 35 | } 36 | 37 | ~FarScreenSave() 38 | { 39 | FarSInfo.RestoreScreen(hScreen); 40 | } 41 | }; 42 | 43 | static std::wstring ShortenPath(const std::wstring &path, size_t maxWidth) 44 | { 45 | if (path.length() > maxWidth) 46 | { 47 | wchar_t* tmpBuf = _wcsdup(path.c_str()); 48 | FSF.TruncPathStr(tmpBuf, maxWidth); 49 | 50 | std::wstring result(tmpBuf); 51 | free(tmpBuf); 52 | return result; 53 | } 54 | 55 | return path; 56 | } 57 | 58 | struct ProgressContext 59 | { 60 | ProgressContext(int totalFiles, int64_t totalBytes) 61 | : TotalFilesSize(totalBytes), TotalFilesCount(totalFiles), CurrentFileSize(0), CurrentFileIndex(-1), 62 | TotalProcessedBytes(0), CurrentFileProcessedBytes(0),m_nPrevTotalBytes(0), 63 | m_tRefreshTime(time_check::mode::immediate, std::chrono::milliseconds(cntProgressRedrawTimeout)), m_tStartTime(clock_type::now()) 64 | {} 65 | 66 | std::wstring HashAlgoName; 67 | 68 | int64_t TotalFilesSize; 69 | int TotalFilesCount; 70 | 71 | int64_t CurrentFileSize; 72 | int CurrentFileIndex; 73 | 74 | int64_t TotalProcessedBytes; 75 | int64_t CurrentFileProcessedBytes; 76 | 77 | void NextFile(const std::wstring& displayPath, int64_t fileSize) 78 | { 79 | m_nPrevTotalBytes = TotalProcessedBytes; 80 | 81 | m_sFilePath = displayPath; 82 | m_sShortenedFilePath = ShortenPath(displayPath, cntProgressDialogWidth); 83 | CurrentFileIndex++; 84 | CurrentFileProcessedBytes = 0; 85 | CurrentFileSize = fileSize; 86 | } 87 | 88 | void NextFile(const std::wstring& displayPath) 89 | { 90 | NextFile(displayPath, GetFileSize_i64(displayPath.c_str())); 91 | } 92 | 93 | void RestartFile() 94 | { 95 | TotalProcessedBytes = m_nPrevTotalBytes; 96 | CurrentFileProcessedBytes = 0; 97 | } 98 | 99 | void SetAlgorithm(rhash_ids algo) 100 | { 101 | HashAlgoName = GetAlgoInfo(algo)->AlgoName; 102 | } 103 | 104 | // Returns true if progress dialog needs to be updated 105 | bool IncreaseProcessedBytes(int64_t bytesProcessed) 106 | { 107 | CurrentFileProcessedBytes += bytesProcessed; 108 | TotalProcessedBytes += bytesProcessed; 109 | 110 | if (!m_tRefreshTime) 111 | return false; 112 | 113 | return true; 114 | } 115 | 116 | const wchar_t* GetShortenedPath() const 117 | { 118 | return m_sShortenedFilePath.c_str(); 119 | } 120 | 121 | int GetCurrentFileProgress() const 122 | { 123 | return (CurrentFileSize > 0) ? (int)((CurrentFileProcessedBytes * 100) / CurrentFileSize) : 0; 124 | } 125 | 126 | int GetTotalProgress() const 127 | { 128 | return (TotalFilesSize > 0) ? (int)((TotalProcessedBytes * 100) / TotalFilesSize) : 0; 129 | } 130 | 131 | int64_t GetElapsedTimeMS() 132 | { 133 | clock_type::duration timeDiff = clock_type::now() - m_tStartTime; 134 | return std::chrono::duration_cast(timeDiff).count(); 135 | } 136 | 137 | private: 138 | std::wstring m_sFilePath; 139 | std::wstring m_sShortenedFilePath; 140 | 141 | int64_t m_nPrevTotalBytes; 142 | 143 | time_check m_tRefreshTime; 144 | clock_type::time_point m_tStartTime; 145 | FarScreenSave m_pScreen; 146 | 147 | ProgressContext() = delete; 148 | }; 149 | 150 | struct RectSize 151 | { 152 | int Width; 153 | int Height; 154 | 155 | RectSize() : Width(0), Height(0) {} 156 | RectSize(int aWidth, int aHeight) : Width(aWidth), Height(aHeight) {} 157 | 158 | void Assign(SMALL_RECT sr) 159 | { 160 | Width = sr.Right - sr.Left + 1; 161 | Height = sr.Bottom - sr.Top + 1; 162 | } 163 | }; 164 | 165 | typedef bool (*FARSIZECALLBACK)(RectSize &farSize); 166 | 167 | static bool FindBestListBoxSize(std::vector listItems, FARSIZECALLBACK sizeFunc, RectSize &listBoxSize) 168 | { 169 | int maxLineWidth = 0; 170 | RectSize farSize; 171 | 172 | if (!sizeFunc(farSize)) 173 | return false; 174 | 175 | for (auto cit = listItems.cbegin(); cit != listItems.cend(); cit++) 176 | { 177 | const std::wstring &str = *cit; 178 | maxLineWidth = max(maxLineWidth, (int) str.length()); 179 | } 180 | 181 | maxLineWidth += 2; // spaces on both sides of the text 182 | if (maxLineWidth > listBoxSize.Width) 183 | listBoxSize.Width = min(maxLineWidth, farSize.Width - 20); 184 | 185 | int numLines = (int) listItems.size(); 186 | if (numLines > listBoxSize.Height) 187 | listBoxSize.Height = min(numLines, farSize.Height - 12); 188 | 189 | return true; 190 | } 191 | 192 | static std::wstring ProgressBarString(intptr_t Percentage, intptr_t Width) 193 | { 194 | std::wstring result; 195 | // 0xB0 - 0x2591 196 | // 0xDB - 0x2588 197 | result = std::wstring((Width - 5) * (Percentage > 100 ? 100 : Percentage) / 100, 0x2588); 198 | result += std::wstring((Width - 5) - result.length(), 0x2591); 199 | result += FormatString(L"%4d%%", Percentage > 100 ? 100 : Percentage); 200 | return result; 201 | } 202 | 203 | static std::wstring DurationToString(int64_t durationMs) 204 | { 205 | int64_t durationSec = durationMs / 1000; 206 | 207 | int64_t hours = durationSec / 3600; 208 | int64_t mins = (durationSec / 60) - (hours * 60); 209 | int64_t secs = durationSec - (hours * 3600) - (mins * 60); 210 | 211 | return FormatString(L"%02lld:%02lld:%02lld", hours, mins, secs); 212 | } 213 | 214 | static std::wstring JoinProgressLine(const std::wstring &prefix, const std::wstring &suffix, size_t maxWidth, size_t rightPadding) 215 | { 216 | size_t middlePadding = maxWidth - prefix.length() - suffix.length() - rightPadding; 217 | std::wstring result = prefix + std::wstring(middlePadding, ' ') + suffix + std::wstring(rightPadding, ' '); 218 | 219 | return result; 220 | } 221 | 222 | static std::wstring ConvertPathToNative(const std::wstring &path) 223 | { 224 | std::vector Buffer(MAX_PATH); 225 | 226 | for (;;) 227 | { 228 | size_t ActualSize = FSF.ConvertPath(CPM_NATIVE, path.c_str(), Buffer.data(), Buffer.size()); 229 | if (ActualSize <= Buffer.size()) 230 | break; 231 | Buffer.resize(ActualSize); 232 | } 233 | 234 | return Buffer.data(); 235 | } 236 | 237 | #endif // FarCommon_h__ 238 | -------------------------------------------------------------------------------- /source/IntChecker2-Far3.def: -------------------------------------------------------------------------------- 1 | LIBRARY "IntChecker2" 2 | 3 | EXPORTS 4 | GetGlobalInfoW 5 | SetStartupInfoW 6 | GetPluginInfoW 7 | ConfigureW 8 | OpenW 9 | ExitFARW -------------------------------------------------------------------------------- /source/IntChecker2.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | #include "version.h" 5 | 6 | #define stringize( x ) stringizei( x ) 7 | #define stringizei( x ) #x 8 | 9 | #define VERSION_FULL PLUGIN_VERSION_MAJOR, PLUGIN_VERSION_MINOR, PLUGIN_VERSION_REVISION, 0 10 | #define VERSION_FULL_STR PLUGIN_VERSION_MAJOR.PLUGIN_VERSION_MINOR.PLUGIN_VERSION_REVISION.0 11 | 12 | #define APSTUDIO_READONLY_SYMBOLS 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // 15 | // Generated from the TEXTINCLUDE 2 resource. 16 | // 17 | #include "winres.h" 18 | 19 | ///////////////////////////////////////////////////////////////////////////// 20 | #undef APSTUDIO_READONLY_SYMBOLS 21 | 22 | ///////////////////////////////////////////////////////////////////////////// 23 | // Russian resources 24 | 25 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS) 26 | #ifdef _WIN32 27 | LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT 28 | #pragma code_page(1251) 29 | #endif //_WIN32 30 | 31 | #ifdef APSTUDIO_INVOKED 32 | ///////////////////////////////////////////////////////////////////////////// 33 | // 34 | // TEXTINCLUDE 35 | // 36 | 37 | 1 TEXTINCLUDE 38 | BEGIN 39 | "resource.h\0" 40 | END 41 | 42 | 2 TEXTINCLUDE 43 | BEGIN 44 | "#include ""winres.h""\r\n" 45 | "\0" 46 | END 47 | 48 | 3 TEXTINCLUDE 49 | BEGIN 50 | "\r\n" 51 | "\0" 52 | END 53 | 54 | #endif // APSTUDIO_INVOKED 55 | 56 | 57 | ///////////////////////////////////////////////////////////////////////////// 58 | // 59 | // Version 60 | // 61 | 62 | VS_VERSION_INFO VERSIONINFO 63 | FILEVERSION VERSION_FULL 64 | PRODUCTVERSION VERSION_FULL 65 | FILEFLAGSMASK 0x17L 66 | #ifdef _DEBUG 67 | FILEFLAGS 0x1L 68 | #else 69 | FILEFLAGS 0x0L 70 | #endif 71 | FILEOS 0x4L 72 | FILETYPE 0x2L 73 | FILESUBTYPE 0x0L 74 | BEGIN 75 | BLOCK "StringFileInfo" 76 | BEGIN 77 | BLOCK "041904b0" 78 | BEGIN 79 | VALUE "FileDescription", "Integrity Checker plugin for Far Manager" 80 | VALUE "FileVersion", stringize(VERSION_FULL_STR) 81 | VALUE "InternalName", "Integrity Checker" 82 | VALUE "LegalCopyright", "Copyright (C) 2014 - 2021, Ariman" 83 | VALUE "OriginalFilename", "IntChecker2.dll" 84 | VALUE "ProductName", "Integrity Checker" 85 | VALUE "ProductVersion", stringize(VERSION_FULL_STR) 86 | END 87 | END 88 | BLOCK "VarFileInfo" 89 | BEGIN 90 | VALUE "Translation", 0x419, 1200 91 | END 92 | END 93 | 94 | #endif // Russian resources 95 | ///////////////////////////////////////////////////////////////////////////// 96 | 97 | 98 | 99 | #ifndef APSTUDIO_INVOKED 100 | ///////////////////////////////////////////////////////////////////////////// 101 | // 102 | // Generated from the TEXTINCLUDE 3 resource. 103 | // 104 | 105 | 106 | ///////////////////////////////////////////////////////////////////////////// 107 | #endif // not APSTUDIO_INVOKED 108 | 109 | -------------------------------------------------------------------------------- /source/IntChecker2.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | {a0861177-bc27-4bc6-83b5-a66e453a5b41} 18 | 19 | 20 | {0bf826ca-3f08-433c-9726-e0f229583c8e} 21 | 22 | 23 | {6fe6f40c-e0ca-452b-9a99-a491c299b67d} 24 | 25 | 26 | {044c6747-ee68-423c-b506-50a69763c551} 27 | 28 | 29 | {0e4cdaab-c19f-49ec-96b9-171143f0e397} 30 | *.lng 31 | false 32 | 33 | 34 | 35 | 36 | Source Files 37 | 38 | 39 | Source Files 40 | 41 | 42 | Source Files 43 | 44 | 45 | Source Files 46 | 47 | 48 | Source Files 49 | 50 | 51 | Source Files 52 | 53 | 54 | 55 | 56 | Source Files 57 | 58 | 59 | Source Files\m4 60 | 61 | 62 | 63 | 64 | 65 | Header Files 66 | 67 | 68 | Header Files 69 | 70 | 71 | Header Files 72 | 73 | 74 | Header Files 75 | 76 | 77 | Header Files 78 | 79 | 80 | Header Files 81 | 82 | 83 | Header Files 84 | 85 | 86 | Header Files 87 | 88 | 89 | Header Files 90 | 91 | 92 | Header Files\depends\far3 93 | 94 | 95 | Header Files\depends\far3 96 | 97 | 98 | Header Files\depends\far3 99 | 100 | 101 | Header Files\depends\far3 102 | 103 | 104 | Header Files\depends\helpers 105 | 106 | 107 | Header Files 108 | 109 | 110 | Header Files\depends\helpers 111 | 112 | 113 | 114 | 115 | Source Files\m4 116 | 117 | 118 | Source Files\m4 119 | 120 | 121 | Source Files\m4 122 | 123 | 124 | Source Files\m4 125 | 126 | 127 | Source Files\m4 128 | 129 | 130 | Source Files\m4 131 | 132 | 133 | 134 | 135 | Resource Files 136 | 137 | 138 | 139 | 140 | Source Files\Text 141 | 142 | 143 | Source Files\Text 144 | 145 | 146 | Source Files\Text 147 | 148 | 149 | Source Files\Text 150 | 151 | 152 | 153 | 154 | Source Files\Text 155 | 156 | 157 | Source Files\Text 158 | 159 | 160 | Source Files\Text 161 | 162 | 163 | Source Files\Text 164 | 165 | 166 | -------------------------------------------------------------------------------- /source/IntChecker2.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | C:\Tools\Far-DBG\Far3\Far.exe 5 | WindowsLocalDebugger 6 | 7 | 8 | C:\Tools\Far-DBG\Far3-x64\Far.exe 9 | WindowsLocalDebugger 10 | 11 | -------------------------------------------------------------------------------- /source/Lang.h: -------------------------------------------------------------------------------- 1 | #ifndef Lang_h__ 2 | #define Lang_h__ 3 | 4 | enum 5 | { 6 | MSG_PLUGIN_NAME, 7 | MSG_PLUGIN_CONFIG_NAME, 8 | 9 | // Action menu 10 | MSG_MENU_GENERATE, 11 | MSG_MENU_COMPARE, 12 | MSG_MENU_VALIDATE, 13 | MSG_MENU_VALIDATE_WITH_PARAMS, 14 | MSG_MENU_COMPARE_CLIP, 15 | MSG_MENU_BENCHMARK, 16 | MSG_MENU_VERIFY_SIGNATURE, 17 | MSG_MENU_SIGNATURE_INFO, 18 | 19 | // Configuration 20 | MSG_CONFIG_TITLE, 21 | MSG_CONFIG_PREFIX, 22 | MSG_CONFIG_DEFAULT_ALGO, 23 | MSG_CONFIG_CONFIRM_ABORT, 24 | MSG_CONFIG_CLEAR_SELECTION, 25 | MSG_CONFIG_AUTOEXT, 26 | MSG_CONFIG_UPPERCASE, 27 | MSG_CONFIG_REMEMBER_LAST_ALGO, 28 | MSG_CONFIG_DEFAULT_CP, 29 | MSG_CONFIG_DEFAULT_OUTPUT, 30 | MSG_CONFIG_OUTPUT_SINGLE_FILE, 31 | MSG_CONFIG_OUTPUT_SEPARATE_FILE, 32 | MSG_CONFIG_OUTPUT_DISPLAY, 33 | MSG_CONFIG_OUTPUT_SEPARATE_DIRS, 34 | MSG_CONFIG_PREVENT_SLEEP, 35 | 36 | // Buttons 37 | MSG_BTN_OK, 38 | MSG_BTN_CANCEL, 39 | MSG_BTN_RUN, 40 | MSG_BTN_CLOSE, 41 | MSG_BTN_CLIPBOARD, 42 | MSG_BTN_RETRY, 43 | MSG_BTN_SKIP, 44 | MSG_BTN_SKIPALL, 45 | MSG_BTN_FILTER, 46 | 47 | // Dialogs 48 | MSG_DLG_ERROR, 49 | MSG_DLG_CONFIRM, 50 | MSG_DLG_NOTVALIDLIST, 51 | MSG_DLG_PROCESSING, 52 | MSG_DLG_PREPARE_LIST, 53 | MSG_DLG_OVERWRITE_FILE, 54 | MSG_DLG_OVERWRITE_FILE_TEXT, 55 | MSG_DLG_NO_FILES_SELECTED, 56 | MSG_DLG_NOFILES_TITLE, 57 | MSG_DLG_NOFILES_TEXT, 58 | MSG_DLG_CALCULATING, 59 | MSG_DLG_ASK_ABORT, 60 | MSG_DLG_VALIDATION_COMPLETE, 61 | MSG_DLG_CALC_COMPLETE, 62 | MSG_DLG_MISMATCHED_FILES, 63 | MSG_DLG_MISSING_FILES, 64 | MSG_DLG_COMPARE, 65 | MSG_DLG_FILE_ERROR, 66 | MSG_DLG_FILE_PANEL_REQUIRED, 67 | MSG_DLG_NO_MISMATCHES, 68 | MSG_DLG_NUM_SKIPPED, 69 | MSG_DLG_NO_COMPARE_SELF, 70 | MSG_DLG_LOOKS_NO_HASH, 71 | MSG_DLG_CLIP_ERROR, 72 | MSG_DLG_FILE_CLIP_MATCH, 73 | MSG_DLG_FILE_CLIP_MISMATCH, 74 | MSG_DLG_PROGRESS, 75 | MSG_DLG_CANT_SAVE_HASHLIST, 76 | MSG_DLG_USE_FILTER, 77 | MSG_DLG_SELECT_ALGORITHM, 78 | MSG_DLG_PROGRESS_NUMFILES, 79 | MSG_DLG_PROGRESS_NUMBYTES, 80 | MSG_DLG_IGNORE_MISSING, 81 | MSG_DLG_STOP_ON_FIRST_MISMATCH, 82 | MSG_DLG_INVALID_PARAMS, 83 | MSG_DLG_SELECT_PARAMS, 84 | MSG_DLG_BENCHMARKING, 85 | MSG_DLG_ELAPSEDTIME, 86 | MSG_DLG_OPERATION_COMPLETE, 87 | MSG_DLG_NOSIGNATURE, 88 | MSG_DLG_READ_ERROR, 89 | MSG_DLG_INVALID_PANEL_TYPE, 90 | MSG_DLG_CLIP_HASH, 91 | MSG_DLG_FILE_HASH, 92 | MSG_DLG_VALIDATE_OPTIONS, 93 | MSG_DLG_SIGNATURE_OK, 94 | 95 | // Generation 96 | MSG_GEN_TITLE, 97 | MSG_GEN_ALGO, 98 | MSG_GEN_RECURSE, 99 | MSG_GEN_ABSPATH, 100 | MSG_GEN_TARGET, 101 | MSG_GEN_TO_FILE, 102 | MSG_GEN_TO_SEPARATE, 103 | MSG_GEN_TO_SCREEN, 104 | MSG_GEN_TO_DIRS, 105 | MSG_GEN_CODEPAGE, 106 | 107 | // Algo list 108 | MSG_ALGO_CRC, 109 | MSG_ALGO_MD5, 110 | MSG_ALGO_SHA1, 111 | MSG_ALGO_SHA256, 112 | MSG_ALGO_SHA512, 113 | MSG_ALGO_SHA3_512, 114 | MSG_ALGO_WHIRLPOOL, 115 | }; 116 | 117 | #endif // Lang_h__ -------------------------------------------------------------------------------- /source/Text/IntCheckerEng.lng: -------------------------------------------------------------------------------- 1 | .Language=English,English 2 | 3 | "Integrity Checker" 4 | "Integrity Checker" 5 | 6 | "&Generate Hashes" 7 | "Compare &Panels" 8 | "&Validate Files" 9 | "Validate Files (params)" 10 | "Compare With &Clipboard" 11 | "Run Benchmark" 12 | "Verify Digital &Signature" 13 | "Get Digital Signature Information" 14 | 15 | "Configuration" 16 | "Use &prefix" 17 | "Default algorithm" 18 | "Confirm &abort" 19 | "Clear &selection on complete" 20 | "Automatic hashlist &extension" 21 | "Save hashes in &uppercase" 22 | "&Remember last used algorithm" 23 | "Default hashlist codepage" 24 | "Default output to" 25 | "Single File" 26 | "Separate hash files" 27 | "Display" 28 | "Directory hash files" 29 | "Prevent sleep when calculating" 30 | 31 | "OK" 32 | "Cancel" 33 | "Run" 34 | "Close" 35 | "To Clipboard" 36 | "Retry" 37 | "Skip" 38 | "Skip All" 39 | "Filter" 40 | 41 | "Error" 42 | "Confirm" 43 | "File is not a valid hash list" 44 | "Processing" 45 | "Preparing file list" 46 | "Overwrite file" 47 | "File %s already exists. Overwrite?" 48 | "No files selected" 49 | "No files" 50 | "No files from hash list exists" 51 | "Calculating hash (%s)" 52 | "Abort calculations?" 53 | "Complete" 54 | "Calculation complete" 55 | "Mismatched Files (%d)" 56 | "Missing Files (%d)" 57 | "Compare" 58 | "Can not calculate hash for" 59 | "Only file panels are supported for comparison" 60 | "No mismatches found" 61 | "file(s) were skipped" 62 | "Can not compare panel to itself" 63 | "Text in clipboard doesn't look like valid hash" 64 | "Can not get text from clipboard" 65 | "File hash matches the clipboard" 66 | "File hash does not match the clipboard" 67 | "File: %d / %d. Progress: %2d%% / %2d%%" 68 | "Can not save hashlist to file" 69 | "&Use filter" 70 | "Select algorithm" 71 | "Files:" 72 | "Bytes:" 73 | "&Ignore missing files" 74 | "&Stop on first mismatch" 75 | "Invalid parameters selected" 76 | "Select parameters" 77 | "Benchmarking %s" 78 | "Time:" 79 | "Operation complete" 80 | "File is not signed or signature is not recognized" 81 | "File reading error" 82 | "Invalid panel type" 83 | "Clipboard hash:" 84 | "File hash:" 85 | "Validate Options" 86 | "File signature is valid" 87 | 88 | "Generate" 89 | "Algorithm" 90 | "Process directories &recursively" 91 | "Store &absolute paths" 92 | "Output to" 93 | "Single &File" 94 | "&Separate hash files" 95 | "&Display" 96 | "Directory hash files" 97 | "File Encoding" 98 | 99 | "&1. CRC32" 100 | "&2. MD5" 101 | "&3. SHA1" 102 | "&4. SHA-256" 103 | "&5. SHA-512" 104 | "&6. SHA3-512" 105 | "&7. Whirlpool" 106 | -------------------------------------------------------------------------------- /source/Text/IntCheckerPol.lng: -------------------------------------------------------------------------------- 1 | .Language=Polish,Polish (Polski) 2 | 3 | "Integrity Checker - Obliczanie sum kontrolnych" 4 | "Integrity Checker - Obliczanie sum kontrolnych" 5 | 6 | "&Generuj sumy kontrolne" 7 | "&Porównaj panele" 8 | "&Weryfikuj pliki" 9 | "W&eryfikuj pliki (parametry)" 10 | "Porównaj ze &schowkiem" 11 | "Uruchom &benchmark" 12 | "Weryfikuj podpis &cyfrowy" 13 | "Pobierz informacje o podpisie cyfrowym" 14 | 15 | "Konfiguracja" 16 | "Użyj &przedrostka" 17 | "Domyślny &algorytm" 18 | "Potwierdź a&nulowanie" 19 | "Wyczyść &zaznaczenie po zakończeniu" 20 | "Automatyczne &rozszerzenie pliku" 21 | "Zapisz sumy &WIELKIMI literami" 22 | "Zapamiętaj &ostatni algorytm" 23 | "Domyślna strona &kodowa" 24 | "Domyślne wy&jście do" 25 | "Pojedynczy plik" 26 | "Osobne pliki kontrolne" 27 | "Ekran" 28 | "Folder plików kontrolnych" 29 | "Zapobiegaj uśpieniu podczas obliczania" 30 | 31 | "OK" 32 | "Anuluj" 33 | "Uruchom" 34 | "Zamknij" 35 | "&Do schowka" 36 | "Ponów" 37 | "Pomiń" 38 | "Pomiń wszystkie" 39 | "&Filtr" 40 | 41 | "Błąd" 42 | "Potwierdź" 43 | "Plik nie jest poprawną listą sum kontrolnych" 44 | "Przetwarzanie" 45 | "Przygotowywanie listy plików" 46 | "Zastąp plik" 47 | "Plik %s już istnieje. Zastąpić?" 48 | "Nie wybrano plików" 49 | "Brak plików" 50 | "Brak plików z listy kontrolnej plików" 51 | "Obliczam sumę (%s)" 52 | "Przerwać obliczanie?" 53 | "Sprawdzanie zakończone" 54 | "Obliczanie zakończone" 55 | "Pliki niezgodne (%d)" 56 | "Brakujące pliki (%d)" 57 | "Porównaj" 58 | "Nie można obliczyć sumy kontrolnej dla" 59 | "Do porównywania obsługiwane są tylko panele plików" 60 | "Brak różnic" 61 | "plik(ów) zostało ominiętych" 62 | "Nie można porównać tego samego panelu" 63 | "Tekst w schowku nie wygląda jak suma kontrolna" 64 | "Nie można pobrać tekstu ze schowka" 65 | "Plik ma sumę kontrolną zgodną ze schowkiem" 66 | "Plik ma inną sumę kontrolną niż schowek" 67 | "Plik: %d / %d. Postęp: %2d%% / %2d%%" 68 | "Nie można zapisać sumy kontrolnej do pliku" 69 | "Użyj filt&ra" 70 | "Wybierz algorytm" 71 | "Plików:" 72 | "Bajtów:" 73 | "&Ignoruj brakujące pliki" 74 | "&Zatrzymaj przy pierwszej niezgodności" 75 | "Wybrano nieprawidłowy parametr" 76 | "Wybierz parametry" 77 | "Testuję %s" 78 | "Czas:" 79 | "Operacja zakończona" 80 | "Plik nie jest podpisany lub podpis nie został rozpoznany" 81 | "Błąd odczytu pliku" 82 | "Nieprawidłowy typ panelu" 83 | "Suma kontrolna w schowku:" 84 | "Suma kontrolna pliku:" 85 | "*Validate Options" 86 | "*File signature is valid" 87 | 88 | "Generuj" 89 | "Al&gorytm" 90 | "&Przetwarzaj podfoldery" 91 | "&Zapisz pełną ścieżkę" 92 | "Wyjście do:" 93 | "&Jeden plik" 94 | "&Osobne pliki" 95 | "&Ekran" 96 | "F&older plików kontrolnych" 97 | "&Kodowanie pliku" 98 | 99 | "&1. CRC32" 100 | "&2. MD5" 101 | "&3. SHA1" 102 | "&4. SHA-256" 103 | "&5. SHA-512" 104 | "&6. SHA3-512" 105 | "&7. Whirlpool" 106 | -------------------------------------------------------------------------------- /source/Text/IntCheckerRus.lng: -------------------------------------------------------------------------------- 1 | .Language=Russian,Russian (Русский) 2 | 3 | "Integrity Checker" 4 | "Integrity Checker" 5 | 6 | "Генерация хешей" 7 | "Сравнение панелей" 8 | "Проверка файлов" 9 | "Проверка файлов (параметры)" 10 | "Сравнить с буфером обмена" 11 | "Запустить тест" 12 | "Проверить цифровую подпись" 13 | "Параметры цифровой подписи" 14 | 15 | "Настройки" 16 | "Использовать префикс" 17 | "Алгоритм по умолчанию" 18 | "Подтверждать прерывание" 19 | "Снимать выделение в конце" 20 | "Добавлять расширение к файлу хешей" 21 | "Сохранять хеши в верхнем регистре" 22 | "Запоминать последний использованный" 23 | "Кодировка хеш-файлов по-умолчанию" 24 | "Вывод по умолчанию" 25 | "Общий файл" 26 | "Отдельные хеш файлы" 27 | "Экран" 28 | "Хеш файлы для каталогов" 29 | "Предотвращать засыпание во время рассчётов" 30 | 31 | "OK" 32 | "Отмена" 33 | "Запуск" 34 | "Закрыть" 35 | "To Clipboard" 36 | "Повторить" 37 | "Пропустить" 38 | "Пропустить все" 39 | "Фильтр" 40 | 41 | "Ошибка" 42 | "Подтверждение" 43 | "Файл не является списком хешей" 44 | "Обработка" 45 | "Подготовка списка файлов" 46 | "Перезаписать файл" 47 | "Файл %s уже существует. Перезаписать?" 48 | "Не выбран ни один файл" 49 | "Нет файлов" 50 | "Ни один файл из списка не существует" 51 | "Вычисление хеша (%s)" 52 | "Прервать расчеты?" 53 | "Проверка закончена" 54 | "Готово" 55 | "Несовпадающие файлы (%d)" 56 | "Отсутствующие файлы (%d)" 57 | "Сравнить" 58 | "Невозможно вычислить хеш для" 59 | "Можно сравнивать только файловые панели" 60 | "Все файлы совпадают" 61 | "файл(ов) пропущено" 62 | "Нельзя сравнить панель с самой собой" 63 | "Текст в буфере обмена не похож на хеш" 64 | "Ошибка с доступом к буферу обмена" 65 | "Хеш файла совпадает с буфером обмена" 66 | "Хеш файла не совпадает с буфером обмена" 67 | "Файл: %d / %d. Прогресс: %2d%% / %2d%%" 68 | "Невозможно сохранить хешлист в файл" 69 | "Использовать фильтр" 70 | "Выберите алгоритм" 71 | "Файлов:" 72 | "Байт:" 73 | "Игнорировать отсутствующие файлы" 74 | "Остановиться на первом несовпадении" 75 | "Заданы неправильные параметры" 76 | "Выберите параметры" 77 | "Тестирую %s" 78 | "Время:" 79 | "Операция завершена" 80 | "Файл не подписан или цифровая подпись не распознана" 81 | "Ошибка чтения файла" 82 | "Неправильный тип панели" 83 | "Хеш из буфера:" 84 | "Хеш файла:" 85 | "Параметры проверки" 86 | "Цифровая подпись правильная" 87 | 88 | "Generate" 89 | "Алгоритм" 90 | "Обрабатывать каталоги рекурсивно" 91 | "Сохранять абсолютные пути" 92 | "Вывод в/на" 93 | "Общий &файл" 94 | "&Отдельные хеш файлы" 95 | "&Экран" 96 | "Хеш файлы для &каталогов" 97 | "Кодировка файла" 98 | 99 | "&1. CRC32" 100 | "&2. MD5" 101 | "&3. SHA1" 102 | "&4. SHA-256" 103 | "&5. SHA-512" 104 | "&6. SHA3-512" 105 | "&7. Whirlpool" 106 | -------------------------------------------------------------------------------- /source/Text/IntCheckerSpa.lng: -------------------------------------------------------------------------------- 1 | .Language=Spanish,Spanish 2 | 3 | "Integrity Checker" 4 | "Integrity Checker" 5 | 6 | "&Generar Hashes" 7 | "Comparar &Paneles" 8 | "&Validar Archivos" 9 | "Validar Archivos (parámetros)" 10 | "&Comparar con Portapapeles" 11 | "*Run Benchmark" 12 | "*Verify Digital Signature" 13 | "*Get Digital Signature Information" 14 | 15 | "Configuración" 16 | "Usar &prefijo" 17 | "Algoritmo por defecto" 18 | "Confirmar interrupción" 19 | "Limpiar &selección al completar hashing" 20 | "Extensión automática de lista hash" 21 | "Guardar hashes en mayúsc&ulas" 22 | "Recordar último algoritmo utilizado" 23 | "Página de códigos predeterminada para lista hash" 24 | "Salida predeterminada a" 25 | "Archivo Simple" 26 | "Archivos hash separados" 27 | "Visualización" 28 | "*Directory hash files" 29 | "*Prevent sleep when calculating" 30 | 31 | "Aceptar" 32 | "Cancelar" 33 | "Ejecutar" 34 | "Cerrar" 35 | "Al Portapapeles" 36 | "Reiterar" 37 | "Saltar" 38 | "Saltar Todo" 39 | "Filtro" 40 | 41 | "Error" 42 | "Confirmar" 43 | "Archivo %s es un archivo de lista hash válido." 44 | "Procesando" 45 | "Preparando lista de archivos" 46 | "Sobrescribir archivo" 47 | "Archivo %s ya existe. Quiere sobrescribirlo?" 48 | "No hay archivos seleccionados" 49 | "No hay archivos" 50 | "No hay archivos existentes de la lista hash" 51 | "Generando hash (%s)" 52 | "Interrumpir cálculo?" 53 | "Completado" 54 | "Cálculo completado" 55 | "Archivos no coincidentes (%d)" 56 | "Archivos perdidos (%d)" 57 | "Comparar" 58 | "No se puede calcular hash para" 59 | "Solo paneles de archivos son soportados para comparación" 60 | "No se encontraron diferencias" 61 | "archivo(s) fueron saltados" 62 | "No se puede comparar panel en si mismo" 63 | "El texto en portapapeles no parece ser un hash válido" 64 | "No se puede obtener texto desde portapapeles" 65 | "Hash de archivo coincide con portapapeles" 66 | "Hash de archivo no coincide con portapapeles" 67 | "Archivo: %d / %d. Progreso: %2d%% / %2d%%" 68 | "No se puede guardar lista hash al archivo" 69 | "Usar filtro" 70 | "Seleccionar algoritmo" 71 | "Archivos:" 72 | "Bytes:" 73 | "*&Ignore missing files" 74 | "*&Stop on first mismatch" 75 | "*Invalid parameters selected" 76 | "*Select parameters" 77 | "*Benchmarking %s" 78 | "*Time:" 79 | "*Operation complete" 80 | "*File is not signed or signature is not recognized" 81 | "*File reading error" 82 | "*Invalid panel type" 83 | "*Clipboard hash:" 84 | "*File hash:" 85 | "*Validate Options" 86 | "*File signature is valid" 87 | 88 | "Generar" 89 | "Algoritmo" 90 | "Procesar &directorios recursivamente" 91 | "Almacenar &rutas absolutas" 92 | "Salida a" 93 | "&Archivo Simple" 94 | "Archivos hash &separados" 95 | "&Visualización" 96 | "*Directory hash files*" 97 | "Codificación de Archivo" 98 | 99 | "&1. CRC32" 100 | "&2. MD5" 101 | "&3. SHA1" 102 | "&4. SHA-256" 103 | "&5. SHA-512" 104 | "&6. SHA3-512" 105 | "&7. Whirlpool" 106 | -------------------------------------------------------------------------------- /source/Text/history_en.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lazyhamster/IntChecker/86156760d81924d8f44432edc545027a00a2ff1f/source/Text/history_en.txt -------------------------------------------------------------------------------- /source/Text/history_pl.txt: -------------------------------------------------------------------------------- 1 | Historia zmian: 2 | 3 | 2.8.2 4 | - Poprawiono ładowanie list sum kontrolnych w formacie BSD dla kilku algorytmów. 5 | - Dodanoo możliwość zatrzymania po pieerwszym niedopasowaniu podczas sprawdzenia sum. 6 | - Dodano możliwość zapobiegania przejścia komputera w stań uśpienia podczas obliczania sum. 7 | - Bieżąca nazwa folderu jest używana jako nazwa pliku sum kontrolnych (dla głównego folderu nazwa pliku bez zmian). 8 | - Zaktualizowano bibliotekę RHash do wersji 1.4.2. 9 | 10 | 2.8.1 11 | - W trybie porównywania paneli można używać tylko CRC32 i SHA1 (nie ma potrzeby używania wszystkich algorytmów). 12 | - Drobne poprawki. 13 | 14 | 2.8.0 15 | - Dodana weryfikacja podpisu cyfrowego dla plików PE. 16 | - Funkcja makro 'gethash' zwraca teraz tekst 'userabort', jeżeli użytkownik przerwał operację. 17 | - Poprawione błędy obliczania sum dla linków symbolicznych za pomocą poleceń makro. 18 | - Poprawione błędy graficzne przy generowaniu okien dialogwych w nowszych wersjach Far (podziękiękowanie dla ctapmex). 19 | 20 | 2.7.3 21 | - Dodano możliwość zapisania obliczonych sum do jednego pliku dla każdego folderu. 22 | - Naprawiono zwracanie hash poprzedniego pliku z makr, gdy bieżący plik nie jest dostępny. 23 | - Dodano opcjonalny parametr "Quiet" do wywołań makr typu bool (true/false). Jeśli ma wartość true, komunikaty o błędach nie będą wyświetlane. 24 | - Drobne poprawki. 25 | 26 | 2.7.2 27 | - Dodane polskie tłumaczenie (autor Andrzej Rudnik). 28 | - Added whitespace trimming around file name supplied through prefix (previously spaces were treated as part of the file name). 29 | 30 | 2.7.1 31 | - Fixed invalid elapsed time display in hash progress dialog when it is more then an hour. 32 | - Fixed problem with validating files from Directory Junctions. 33 | - Uaktualniono bibliotekę RHash do wersji 1.3.8 (powinna przyspieszać przy niektórych algorytmach). 34 | 35 | 2.7.0 36 | - Dodano możliwość użycia wtyczki w skryptach lua (np. IntChecker.GetFileHash.lua). 37 | - Dodany prosty benchmark do testowania prędkości obliczania sum. 38 | - Added validation option to ignore missing files. 39 | - Fixed loading of the hashlists that have paths stored in UNC format. 40 | - Allowed SFV files to have variable amount of spaces between file path and checksum. 41 | - Uaktualnione hiszpańskie tłumaczenie (dziękuję Mauro72). 42 | 43 | 2.6.2 44 | - Naprawiono zepsutą opcję wielkich liter w hash (regresja). 45 | 46 | 2.6.1 47 | - Naprawiony błąd podczas obliczania szybkości wyliczania. 48 | 49 | 2.6.0 50 | - Nowe okno postępu obliczania. 51 | 52 | 2.5.1 53 | - Naprawiono problemy z oknem porównywania paneli (regresja). 54 | 55 | 2.5.0 56 | - Dodano możliwość użycia algorytmu SHA3-512. 57 | - Naprawiono włączanie/wyłączanie przycisku filtru w oknie dialogowym generowania skrótu. 58 | - Drobne poprawki. 59 | 60 | 2.4.3 61 | - Dodano nową opcję ustawień, aby wybrać domyślny cel w oknie dialogowym generowania skrótu. 62 | - Naprawiono problem z nieprawidłowym odczytem niektórych ustawień przy starcie. 63 | 64 | 2.4.2 65 | - Naprawiono awarię podczas sprawdzania poprawności plików z łączeniem katalogów w ścieżce. 66 | - Naprawiono tworzenie plików dla niektórych nazw z cyrylicą. 67 | - Dodano możliwość wyboru strony kodowej pliku hash do weryfikacji. 68 | 69 | 2.4.1 70 | - Naprawiono przetwarzanie ścieżek w stylu Linuksa w plikach skrótu. 71 | - Naprawiono problem z uszkodzeniem prefiksu w Far3 x64. 72 | - Dodano możliwość wyboru strony kodowej pliku wyjściowego podczas generowania skrótów. 73 | 74 | 2.4.0 75 | - Dodano obsługę filtrów plików w generowaniu skrótów (tylko Far3). 76 | - Drobne poprawki. 77 | 78 | 2.3.5 79 | - Naprawiono problem z udziałami sieciowymi. 80 | - Dodano możliwość kopiowania wyników weryfikacji plików do schowka. 81 | 82 | 2.3.4 83 | - Nowa opcja ustawień: domyślna strona kodowa dla list skrótów. 84 | - Okno dialogowe wyświetlania listy skrótów zostało dostosowane do rozmiaru okna Far. 85 | - Drobne poprawki. 86 | 87 | 2.3.3 88 | - Dodano sprawdzenie, czy plik hash można zapisać przed wygenerowaniem. 89 | 90 | 2.3.2 91 | - Dodano opcję ustawień, aby zapisać ostatnio używany algorytm skrótu. 92 | - Usunięto limit wielkości obliczanych plików. 93 | 94 | 2.3.1 95 | - Dodane hiszpańskie tłumaczenie (autor Mauro72). 96 | 97 | 2.3.0 98 | - Dodano możliwość porównania sumy pliku z zawartością schowka. 99 | - Teraz wtyczka działa z panelami, które mają ustawioną flagę PFLAGS_REALNAMES (eksperymentalna). 100 | - Drobne poprawki. 101 | 102 | 2.2.1 103 | - Dodano przycisk „Pomiń wszystko” do okna dialogowego po wystąpieniu błędu. 104 | - Dodana opcja do zapisywania sum kontrolnych wielkimi literami. 105 | - Naprawiona awaria przy porównywaniu paneli z SHA-512 i Whirlpool. 106 | 107 | 2.2.0 108 | - Poprawiony błąd dla plików ze ścieżką powyżej 256 znaków. 109 | - Zwiększona maksymalna wielkość pliku kontrolnego do 10MB. 110 | - Dodano sprawdzanie rozszerzenia pliku listy skrótów dla skrótów o tej samej długości. 111 | - Poprawiony zły algorytm wykrywania w niektórych przypadkach. 112 | - Dodana obsługa plików kontrolnych w formacie BSD. 113 | 114 | 2.1.0 115 | - Poprawione odczytywanie plików kontrolnych ze znakami nie-łacińskimi. 116 | - Drobne poprawki.. 117 | 118 | 2.0.4 119 | - Poprawiony panel porównywania w Far3. 120 | - Poprawione błędy w oknie dialogowym wyników w panelu porównywania. 121 | 122 | 2.0.3 123 | - Uaktualniona biblioteka RHash do wersji 1.3.2. 124 | To uaktualnienie rozwiązuje kilka rzadkich błędów podczas używania SHA512. 125 | 126 | 2.0.2 127 | - Poprawiona obsługa plików kontrolnych ze ścieżkami względnymi. 128 | 129 | 2.0.1 130 | - Poprawiony przedrostek w Far3. 131 | - Teraz wtyczka nie działa w innym panelu wtyczki. 132 | - Dodana opcja zapisania pełnej ścieżki w plikach kontrolnych. 133 | - Poprawione zaznaczanie brakujących plików po walidacji w Far3. 134 | - Drobne zmiany. 135 | 136 | 2.0 137 | - Nowa wersja, całkowite przepisane od wersji 1.x. 138 | -------------------------------------------------------------------------------- /source/Text/history_ru.txt: -------------------------------------------------------------------------------- 1 | История изменений: 2 | 3 | 2.8.3 4 | - Убраны ограничения по расширениям на проверку цифровой подписи для файлов. 5 | - Мелкие правки. 6 | 7 | 2.8.2 8 | - Исправлена загрузка хеш-файлов в формате BSD для некоторых алгоритмов. 9 | - Добавлена возможность остановки при первом несовпадении при проверке файлов. 10 | - Добавлена возможность предотвращать засыпание компьютера во время рассчётов хешей. 11 | - Имя текущего каталога используется как основа для имени хеш-файла (для корневых каталогов по прежнему используется hashlist). 12 | - Библиотека RHash обновлена до версии 1.4.2. 13 | 14 | 2.8.1 15 | - Для режима сравнения панелей оставлены только CRC32 и SHA1 (нет смысла использовать все алгоритмы). 16 | - Мелкие изменения. 17 | 18 | 2.8.0 19 | - Добавлена возможность проверки цифровой подписи для PE файлов. 20 | - Макро-функция 'gethash' теперь возращает строку 'userabort' если пользователь прервал операцию. 21 | - Исправлена проблема с подсчетом хеша через макрокоманду для символической ссылки на файл. 22 | - Исправлена визуальная проблема с диалогом генератора хешей на новых версиях Far-а (спасибо ctapmex). 23 | 24 | 2.7.3 25 | - Добавлена возможность сохранять хеши по одному файлу на каталог. 26 | - Исправлена выдача из макроса хеша от предыдущего файла, если текущий файл невозможно прочитать. 27 | - Добавлен новый опциональный параметр Quiet типа bool для макросов. Если выставлен в true, то сообщения об ошибках не будут показываться. 28 | - Мелкие правки. 29 | 30 | 2.7.2 31 | - Добавлена польская локализация (спасибо Andrzej Rudnik). 32 | - Добавлена обрезка пробелов вокруг имени файла, переданного через префикс (ранее пробелы трактовались как часть имени). 33 | 34 | 2.7.1 35 | - Исправлено отображение прошедшего времени в диалоге прогресса хеширования когда оно больше часа. 36 | - Исправлена проблема с валидацией файлов доступных через Directory Junction. 37 | - Обновлена библиотека RHash (должна увеличиться скорость некоторых алгоритмов). 38 | 39 | 2.7.0 40 | - Добавлена возможность вызова плагина из lua макросов (см. IntChecker.GetFileHash.lua). 41 | - Добавлена базовая функциональность для тестирования скорости хеширования. 42 | - Добавлена опция игнорирования отсутствующих файлов при проверке. 43 | - Исправлена невозможность загрузки хешлиста если пути были сохранены в формате UNC. 44 | - Теперь SFV файлы могут иметь произвольное количество пробелов между путём файла и контрольной суммой. 45 | - Обновлена испанская локализация (спасибо Mauro72). 46 | 47 | 2.6.2 48 | - Исправлена неработающая опция сохранения хешей в верхнем регистре (регрессия). 49 | 50 | 2.6.1 51 | - Исправлено падение при расчете скорости хеширования. 52 | 53 | 2.6.0 54 | - Новый диалог прогресса хеширования. 55 | 56 | 2.5.1 57 | - Исправлены проблемы с диалогом сравнения панелей (регрессия). 58 | 59 | 2.5.0 60 | - Добавлена возможность использования алгоритма SHA3-512. 61 | - Исправлено включение\выключение кнопки фильтра в диалоге генерирования хешей. 62 | - Мелкие правки. 63 | 64 | 2.4.3 65 | - Добавлена настройка вывода по умолчанию в диалоге генерирования хешей. 66 | - Исправлена проблема с неправильным чтением некоторых настроек при старте. 67 | 68 | 2.4.2 69 | - Исправлено падение при валидации файлов, пути которых содержат directory junction. 70 | - Исправлен assert на некоторых именах с кириллицей. 71 | - Добавлена возможность выбора кодовой страницы хеш-файла для операции проверки. 72 | 73 | 2.4.1 74 | - Исправлена обработка Linux-style путей в хеш файлах. 75 | - Исправлена проблема с порчей значения префикса в Far x64. 76 | - Добавлена возможность выбора кодовой страницы файла при генерации хешей. 77 | 78 | 2.4.0 79 | - Добавлена поддержка файловых фильтров при генерировании хешей (Far3 only). 80 | - Мелкие правки. 81 | 82 | 2.3.5 83 | - Исправлена проблема в работе с сетевыми путями. 84 | - Добавлена возможность скопировать в буфер обмена результат проверки файлов. 85 | 86 | 2.3.4 87 | - Новая опция настроек: кодировка по умолчанию для хеш-файлов. 88 | - Диалог вывода списка хешей на экран адаптируется по размерам к окну Far-а. 89 | - Мелкие правки. 90 | 91 | 2.3.3 92 | - Добавлена проверка на возможность сохранения хеш-файла перед запуском генератора. 93 | 94 | 2.3.2 95 | - Добавлена опция настроек сохранять последний использованный алгоритм. 96 | - Убран лимит на размер загружаемого хеш-файла. 97 | 98 | 2.3.1 99 | - Добавлена локализация на испанский (от Mauro72). 100 | 101 | 2.3.0 102 | - Добавлена возможность сравнить хеш выбранного файла с буфером обмена. 103 | - Теперь плагин работает на панелях с флагом PFLAGS_REALNAMES (эксперементально). 104 | - Мелкие правки. 105 | 106 | 2.2.1 107 | - Добавлена кнопка "Skip All" в диалог с ошибкой генерации хеша. 108 | - Добавлена настройка для сохранения хешей в верхнем регистре. 109 | - Исправлено падение при сравнении панелей с алгоритмами SHA-512 и Whirlpool. 110 | 111 | 2.2.0 112 | - Исправлена работа с файлами с длиной пути больше чем 256 символов. 113 | - Увеличен максимально возможный размер хеш-файла до 10 Мб. 114 | - Добавлена проверка на расширение файла хешлиста для хешей с одинаковой длиной. 115 | - Исправлено неправильное определение алгоритма в некоторых случаях. 116 | - Добавлена поддержка хеш листов в формате BSD. 117 | 118 | 2.1.0 119 | - Исправлено чтение хеш-файлов с нелатинскими буквами. 120 | - Мелкие правки. 121 | 122 | 2.0.4 123 | - Исправлен режим сравнения панелей для Far3. 124 | - Исправлена проблема с диалогом результатов сравнения панелей. 125 | 126 | 2.0.3 127 | - Обновлена бибилотека RHash до версии 1.3.2. 128 | Это решило некоторые редкие проблемы с работой SHA512. 129 | 130 | 2.0.2 131 | - Исправлена обработка хеш-файлов с абсолютными путями. 132 | 133 | 2.0.1 134 | - Исправлена работа префикса для Far3. 135 | - Плагин не запускается теперь на панелях других плагинов. 136 | - Добавлена опция сохранения полных путей в хеш-файле. 137 | - Исправлено выделение несовпадающих файлов при проверке для Far3. 138 | - Мелкие правки. 139 | 140 | 2.0 141 | - Новая версия, полность переписанная по отношению к 1.х 142 | -------------------------------------------------------------------------------- /source/Utils.h: -------------------------------------------------------------------------------- 1 | #ifndef Utils_h__ 2 | #define Utils_h__ 3 | 4 | bool CheckEsc(); 5 | 6 | void IncludeTrailingPathDelim(wchar_t *pathBuf, size_t bufMaxSize); 7 | void IncludeTrailingPathDelim(std::wstring &pathStr); 8 | std::wstring ExtractFileName(const std::wstring& fullPath); 9 | std::wstring ExtractFileExt(const std::wstring& path); 10 | std::wstring PrependLongPrefix(const std::wstring &basePath); 11 | 12 | int64_t GetFileSize_i64(const wchar_t* path); 13 | int64_t GetFileSize_i64(HANDLE hFile); 14 | bool IsFile(const std::wstring &path, int64_t *fileSize = nullptr); 15 | bool CanCreateFile(const wchar_t* path); 16 | 17 | void TrimRight(char* str); 18 | void TrimStr(std::string &str); 19 | void TrimLeft(wchar_t* str); 20 | void TrimRight(wchar_t* str); 21 | void TrimStr(wchar_t* str); 22 | 23 | bool SameText(const wchar_t* str1, const wchar_t* str2); 24 | 25 | typedef bool (CALLBACK *FilterCompareProc)(const WIN32_FIND_DATA*, HANDLE); 26 | int PrepareFilesList(const wchar_t* basePath, const wchar_t* basePrefix, StringList &destList, int64_t &totalSize, bool recursive, FilterCompareProc filterProc, HANDLE filterData); 27 | 28 | bool CopyTextToClipboard(std::wstring &data); 29 | bool CopyTextToClipboard(std::vector &data); 30 | bool GetTextFromClipboard(std::string &data); 31 | 32 | std::wstring FormatString(const std::wstring fmt, ...); 33 | std::wstring ConvertToUnicode(const std::string &str, int cp); 34 | 35 | typedef std::chrono::steady_clock clock_type; 36 | 37 | class time_check 38 | { 39 | public: 40 | enum class mode { delayed, immediate }; 41 | time_check(mode Mode, clock_type::duration Interval) : 42 | m_Begin(Mode == mode::delayed ? clock_type::now() : clock_type::now() - Interval), 43 | m_Interval(Interval) {} 44 | 45 | void reset(clock_type::time_point Value = clock_type::now()) { m_Begin = Value; } 46 | 47 | bool operator!() 48 | { 49 | const auto Current = clock_type::now(); 50 | if (Current - m_Begin > m_Interval) 51 | { 52 | reset(Current); 53 | return false; 54 | } 55 | return true; 56 | } 57 | 58 | private: 59 | mutable clock_type::time_point m_Begin; 60 | const clock_type::duration m_Interval; 61 | }; 62 | 63 | #endif // Utils_h__ -------------------------------------------------------------------------------- /source/dllmain.cpp: -------------------------------------------------------------------------------- 1 | // dllmain.cpp : Defines the entry point for the DLL application. 2 | #include "stdafx.h" 3 | 4 | BOOL APIENTRY DllMain( HMODULE hModule, 5 | DWORD ul_reason_for_call, 6 | LPVOID lpReserved 7 | ) 8 | { 9 | switch (ul_reason_for_call) 10 | { 11 | case DLL_PROCESS_ATTACH: 12 | case DLL_THREAD_ATTACH: 13 | case DLL_THREAD_DETACH: 14 | case DLL_PROCESS_DETACH: 15 | break; 16 | } 17 | return TRUE; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /source/hashing.h: -------------------------------------------------------------------------------- 1 | #ifndef hashing_h__ 2 | #define hashing_h__ 3 | 4 | #include "rhash/librhash/rhash.h" 5 | 6 | enum HashListFormat 7 | { 8 | HLF_UNKNOWN, 9 | HLF_SIMPLE, 10 | HLF_BSD, 11 | HLF_SFV 12 | }; 13 | 14 | struct HashAlgoInfo 15 | { 16 | rhash_ids AlgoId; 17 | std::wstring AlgoName; 18 | std::wstring DefaultExt; 19 | }; 20 | 21 | #define NUMBER_OF_SUPPORTED_HASHES 7 22 | extern HashAlgoInfo SupportedHashes[NUMBER_OF_SUPPORTED_HASHES]; 23 | 24 | struct FileHashInfo 25 | { 26 | std::wstring Filename; 27 | std::string HashStr; 28 | rhash_ids HashAlgo; 29 | 30 | std::wstring ToString() const; 31 | void Serialize(std::stringstream& dest, UINT codepage, bool stripFilePath) const; 32 | }; 33 | 34 | typedef std::vector FileHashList; 35 | 36 | class HashList 37 | { 38 | private: 39 | FileHashList m_HashList; 40 | 41 | int GetFileRecordIndex(const wchar_t* fileName) const; 42 | bool DumpStringToFile(const std::string& data, const wchar_t* filePath); 43 | bool SaveHashesToFile(const std::wstring &filePath, FileHashList &hashList, UINT codepage, bool stripPathInfo); 44 | 45 | bool DetectFormat(const char* testStr, UINT codepage, const wchar_t* filePath, rhash_ids &foundAlgo, HashListFormat &listFormat); 46 | 47 | bool TryParseBSD(const char* inputStr, UINT codepage, FileHashInfo &fileInfo); 48 | bool TryParseSimple(const char* inputStr, UINT codepage, rhash_ids hashAlgo, FileHashInfo &fileInfo); 49 | bool TryParseSfv(const char* inputStr, UINT codepage, rhash_ids hashAlgo, FileHashInfo &fileInfo); 50 | 51 | public: 52 | HashList() {} 53 | 54 | bool SaveList(const wchar_t* filepath, UINT codepage); 55 | bool SaveListSeparate(const wchar_t* baseDir, UINT codepage, int &successCount, int &failCount); 56 | bool SaveListEachDir(const wchar_t* baseDir, UINT codepage, int &successCount, int &failCount); 57 | bool LoadList(const wchar_t* filepath, UINT codepage, bool merge); 58 | 59 | void SetFileHash(const std::wstring &fileName, std::string hashVal, rhash_ids hashAlgo); 60 | 61 | size_t GetCount() const { return m_HashList.size(); } 62 | const FileHashInfo& GetFileInfo(size_t index) const { return m_HashList.at(index); } 63 | }; 64 | 65 | // Params: context, processed bytes 66 | typedef bool (CALLBACK *HashingProgressFunc)(HANDLE context, int64_t bytesProcessed); 67 | 68 | enum class GenResult 69 | { 70 | Success = 0, 71 | Error = 1, 72 | Aborted = 2 73 | }; 74 | 75 | extern size_t FileReadBufferSize; 76 | 77 | GenResult GenerateHash(const std::wstring& filePath, std::vector hashAlgos, std::vector &results, bool useUppercase, HashingProgressFunc progressFunc, HANDLE progressContext); 78 | GenResult GenerateHash(const std::wstring& filePath, rhash_ids hashAlgo, std::string& result, bool useUppercase, HashingProgressFunc progressFunc, HANDLE progressContext); 79 | 80 | HashAlgoInfo* GetAlgoInfo(rhash_ids algoId); 81 | int GetAlgoIndex(rhash_ids algoId); 82 | int GetAlgoIndexByName(const wchar_t* name); 83 | 84 | // Returns list of algorithms that have matching hash pattern 85 | std::vector DetectHashAlgo(const std::string &testStr); 86 | 87 | bool SameHash(const std::string& hash1, const std::string& hash2); 88 | 89 | int64_t BenchmarkAlgorithm(rhash_ids algo, size_t dataSize); 90 | 91 | #endif // hashing_h__ 92 | -------------------------------------------------------------------------------- /source/m4/FILE_ID.DIZ.m4: -------------------------------------------------------------------------------- 1 | m4_include(`version.m4i')m4_dnl 2 | Integrity Checker PLUGIN_VERSION 3 | Plugin for Far Manager 3.0 4 | --------------------------- 5 | 6 | This plugin allows creation and 7 | verification of the hash sum files for 8 | integrity checking purposes. 9 | 10 | Supported algorithms: 11 | - CRC32 (sfv files) 12 | - MD5 13 | - SHA1 14 | - SHA-256 15 | - SHA-512 16 | - SHA3-512 17 | - Whirlpool 18 | 19 | (c) 2014-2024, Ariman 20 | ----------------------------------------- 21 | E-mail for suggestions, bug reports, etc: ariman@inbox.ru 22 | -------------------------------------------------------------------------------- /source/m4/IntCheckerPol.hlf.m4: -------------------------------------------------------------------------------- 1 | .Language=Polish,Polish (Polski) 2 | .PluginContents=Integrity Checker - Obliczanie sum kontrolnych 3 | 4 | @Contents 5 | $^.Language=Polish,Polish (Polski)# 6 | 7 | @GenerateParams 8 | $ #Parametry obliczania sumy kontrolnej# 9 | Dostępne są następujące opcje do wyboru: 10 | 11 | #Algorytm# 12 | Możesz wybrać jeden z dostępnych algorytmów obliczania sum. 13 | Wybór ten wpływa na format pliku wynikowego. 14 | Algorytmy różnią się rozmiarem i szybkością obliczania. 15 | 16 | #Wyjście# 17 | Jeden z możliwych wariantów pokazania wyników. 18 | 19 | #Pojedynczy plik# 20 | W katalogu aktywnego panelu zostanie utworzony jeden wspólny plik ze wszystkimi danymi. Poniżej możesz podać nazwę tego pliku. Podczas zmiany wybranego algorytmu odpowiednie rozszerzenie pliku jest automatycznie zmieniane. 21 | 22 | #Osobne pliki# 23 | Dla każdego pliku zostanie utworzony osobny plik z jego sumą kontrolną. Nazwa pliku skrótu jest tworzona automatycznie na podstawie nazwy pliku źródłowego i wybranego algorytmu. 24 | 25 | #Ekran# 26 | Wynik zostanie wyświetlony w oknie dialogowym na ekranie; żadne pliki nie zostaną utworzone na dysku. 27 | 28 | #Przetwarzaj podfoldery# 29 | [ ] - przetwarzaj tylko foldery wybrane w panelu, podfoldery będą ignorowane 30 | [X] - przetwarzaj wszystkie podfoldery znajdujące się w zaznaczonych folderach 31 | 32 | #Zapisz pełną ścieżkę# 33 | [ ] - ścieżki są zapisywane względem położenia pliku wynikowego 34 | [X] - zachowaj pełną ścieżkę 35 | 36 | #Użyj filtra# 37 | Przetwarzaj pliki zgodnie z ~filtrami~@:FiltersMenu@. 38 | -------------------------------------------------------------------------------- /source/m4/IntCheckerRus.hlf.m4: -------------------------------------------------------------------------------- 1 | .Language=Russian,Russian (Русский) 2 | .PluginContents=Integrity Checker 3 | 4 | @Contents 5 | $^Integrity Checker# 6 | 7 | @GenerateParams 8 | $ #Параметры вычисления хешей# 9 | Доступны для выбора следующие параметры: 10 | 11 | #Алгоритм# 12 | Можно выбрать один из доступных алгоритмов хеширования. 13 | Данный выбор влияет на формат файла результатов. 14 | Алгоритмы отличаются размеров хеша и скоростью работы. 15 | 16 | #Вывод# 17 | Один из вариантов вывода результата. 18 | 19 | #Общий файл# 20 | В каталоге активной панели будет создан один общий файл со всеми данными. Ниже можно задать имя этого файла. При смене выбранного алгоритма, автоматически подставляется соотвествующее расширение для файла. 21 | 22 | #Отдельные хеш файлы# 23 | Для каждого файла будет создан отдельный файл с его хешем. Имя для хеш файла создается автоматически на основе имени исходного файла и выбранного алгоритма. 24 | 25 | #Экран# 26 | Результат будет выведен в диалог на экране, никаких файлов на диске не создается. 27 | 28 | #Обрабатывать каталоги рекурсивно# 29 | [ ] - обрабатывать только каталоги выбранные на панели, подкаталоги игнорируются 30 | [X] - обрабатывать каталоги любой вложенности внутри выбранных на панели 31 | 32 | #Сохранять абсолютные пути# 33 | [ ] - пути сохраняются относительно результирующего хеш файла 34 | [X] - сохраняются абсолютные пути 35 | 36 | #Использовать фильтр# 37 | Обрабатывать файлы согласно ~фильтру~@:FiltersMenu@. -------------------------------------------------------------------------------- /source/m4/readme_pl.txt.m4: -------------------------------------------------------------------------------- 1 | m4_include(`version.m4i')m4_dnl 2 | Wtyczka: Integrity Checker 3 | Wersja: PLUGIN_VERSION 4 | Autor: Ariman 5 | URL: https://github.com/lazyhamster/IntChecker 6 | 7 | -------------------------------------------------------- 8 | 9 | 1. Opis. 10 | Wtyczka została zaprojektowana do generowania sum kontrolnych w różnych 11 | algorytmach i sprawdzania integralności plików z wcześniej utworzonymi 12 | sumami kontrolnymi. 13 | 14 | Obsługiwane są nieograniczone poziomy zagnieżdżenia plików w folderach. 15 | 16 | Zaimplementowane algorytmy: 17 | CRC32, MD5, SHA1, SHA-256, SHA-512, SHA3-512, Whirlpool 18 | 19 | Wtyczka bazuje na kodzie programu RHash (https://github.com/rhash/RHash). 20 | 21 | 2. Wymagania. 22 | Minimalna wersja FAR do pracy z wtyczką to 3.0.5886 23 | 24 | 3. Gwarancja. 25 | Wtyczka jest udostępniana "jak jest" (bez gwarancji). Autor nie odpowiada 26 | za konsekwencje wynikające z używania tego programu. 27 | 28 | 4. Licencja. 29 | Wtyczka dostarczana jest na licencje GNU GPL v3. 30 | Tekst licencji (po angielsku) można znaleźć w folderze wtyczki. 31 | 32 | 4. Praca z wtyczką. 33 | Wtyczkę można wywołać na kilka sposobów: 34 | - poprzez listę wtyczek (klawisz F11) 35 | - poprzez przedrostek (niestandardowo, do dalszego sprawdzenia) 36 | 37 | Działa tylko z panelami plików. Nie ma reakcji na próbę wywołania wtyczki z dowolnego innego panelu. 38 | 39 | 4.1. Generowanie sum kontrolnych. 40 | Algorytm można wybrać w oknie dialogowym wtyczki. 41 | Domyślny algorytm można wybrać w menu konfiguracji wtyczki. 42 | Wtyczka tworzy 2 rodzaje plików: .sfv (dla sum CRC32) i pliki podobne do md5, 43 | obsługiwane m.in. przez programy md5sum, sha256sum, itp. 44 | W trybie odczytu (weryfikacja) wtyczka rozpoznaje pliki w formacie BSD. 45 | Można utworzyć jeden wspólny plik kontrolny dla wszystkich plików lub osobne pliki dla każdego 46 | sprawdzanego pliku. 47 | 48 | 4.2. Weryfikacja sum. 49 | Jeśli w panelu zostanie wybrany jeden plik, do menu zostanie dodana nowa pozycja do sprawdzania plików. 50 | Jeśli plik zostanie pomyślnie rozpoznany, rozpocznie się weryfikacja pliku. 51 | Możliwe jest także porównanie skrótu pojedynczego pliku z zawartością schowka. 52 | 53 | 4.3. Porównywanie plików z różnych paneli. 54 | Dodatkową funkcjonalnością jest możliwość porównania plików o takich samych nazwach 55 | w różnych panelach plików. Porównanie odbywa się zgodnie z wybranym algorytmem 56 | w oknie dialogowym wtyczki. Jeśli ten sam katalog jest wybrany na obu panelach, lub 57 | drugi panel należy do innej wtyczki, funkcja ta będzie niedostępna. 58 | 59 | 5. Kontakty. 60 | Komunikaty o błędach, sugestie, pomysły, itp. wyślij na adres ariman@inbox.ru 61 | lub przez system GitHub. 62 | -------------------------------------------------------------------------------- /source/m4/readme_ru.txt.m4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lazyhamster/IntChecker/86156760d81924d8f44432edc545027a00a2ff1f/source/m4/readme_ru.txt.m4 -------------------------------------------------------------------------------- /source/m4/version.h.m4: -------------------------------------------------------------------------------- 1 | m4_include(`version.m4i')m4_dnl 2 | m4_define(`CPP_DEFINE', `#define $1 $2')m4_dnl 3 | 4 | CPP_DEFINE(PLUGIN_VERSION_MAJOR, VMAJOR) 5 | CPP_DEFINE(PLUGIN_VERSION_MINOR, VMINOR) 6 | CPP_DEFINE(PLUGIN_VERSION_REVISION, VREVISION) 7 | -------------------------------------------------------------------------------- /source/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by IntChecker2.rc 4 | 5 | // Next default values for new objects 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | -------------------------------------------------------------------------------- /source/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // IntChecker2.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // Reference any additional headers you need in STDAFX.H and not in this file 8 | -------------------------------------------------------------------------------- /source/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | 8 | #include "targetver.h" 9 | 10 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 11 | // Windows Header Files: 12 | #include 13 | #include 14 | 15 | // Additional headers 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | typedef std::vector StringList; 27 | 28 | #include 29 | 30 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) 31 | #define PATH_BUFFER_SIZE 4096 32 | -------------------------------------------------------------------------------- /source/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // The following macros define the minimum required platform. The minimum required platform 4 | // is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run 5 | // your application. The macros work by enabling all features available on platform versions up to and 6 | // including the version specified. 7 | 8 | // Modify the following defines if you have to target a platform prior to the ones specified below. 9 | // Refer to MSDN for the latest info on corresponding values for different platforms. 10 | #ifndef WINVER // Specifies that the minimum required platform is Windows Vista. 11 | #define WINVER 0x0600 // Change this to the appropriate value to target other versions of Windows. 12 | #endif 13 | 14 | #ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista. 15 | #define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows. 16 | #endif 17 | 18 | #ifndef _WIN32_WINDOWS // Specifies that the minimum required platform is Windows 98. 19 | #define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later. 20 | #endif 21 | 22 | #ifndef _WIN32_IE // Specifies that the minimum required platform is Internet Explorer 7.0. 23 | #define _WIN32_IE 0x0700 // Change this to the appropriate value to target other versions of IE. 24 | #endif 25 | -------------------------------------------------------------------------------- /source/trust.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "trust.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | static std::wstring GetAlgorithmName(const CRYPT_ALGORITHM_IDENTIFIER &algoId) 9 | { 10 | if (algoId.pszObjId) 11 | { 12 | PCCRYPT_OID_INFO pOidInfo = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, algoId.pszObjId, 0); 13 | if (pOidInfo && pOidInfo->pwszName) 14 | return pOidInfo->pwszName; 15 | } 16 | 17 | return L""; 18 | } 19 | 20 | static bool GetCertificateInfo(HCERTSTORE hStore, PCMSG_SIGNER_INFO pSignerInfo, CertificateInfo& decodedInfo) 21 | { 22 | CERT_INFO certInfo = {0}; 23 | certInfo.Issuer = pSignerInfo->Issuer; 24 | certInfo.SerialNumber = pSignerInfo->SerialNumber; 25 | 26 | PCCERT_CONTEXT pCertContext = CertFindCertificateInStore(hStore, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, 0, CERT_FIND_SUBJECT_CERT, &certInfo, NULL); 27 | if (!pCertContext) return false; 28 | 29 | wchar_t wszNameBuf[1024] = { 0 }; 30 | DWORD dwRetSize; 31 | 32 | dwRetSize = CertGetNameString(pCertContext, CERT_NAME_SIMPLE_DISPLAY_TYPE, CERT_NAME_ISSUER_FLAG, NULL, wszNameBuf, _countof(wszNameBuf)); 33 | decodedInfo.IssuerName = dwRetSize > 1 ? wszNameBuf : L""; 34 | 35 | dwRetSize = CertGetNameString(pCertContext, CERT_NAME_SIMPLE_DISPLAY_TYPE, 0, NULL, wszNameBuf, _countof(wszNameBuf)); 36 | decodedInfo.SubjectName = dwRetSize > 1 ? wszNameBuf : L""; 37 | 38 | decodedInfo.SignatureAlgorithm = pCertContext->pCertInfo ? GetAlgorithmName(pCertContext->pCertInfo->SignatureAlgorithm) : L""; 39 | 40 | CertFreeCertificateContext(pCertContext); 41 | return true; 42 | } 43 | 44 | static bool GetProgAndPublisherInfo(PCMSG_SIGNER_INFO pSignerInfo, DigitalSignatureInfo &sigInfo) 45 | { 46 | for (DWORD i = 0; i < pSignerInfo->AuthAttrs.cAttr; ++i) 47 | { 48 | if (strcmp(pSignerInfo->AuthAttrs.rgAttr[i].pszObjId, SPC_SP_OPUS_INFO_OBJID) == 0) 49 | { 50 | PSPC_SP_OPUS_INFO pOpusInfo = NULL; 51 | DWORD dwDataSize = 0; 52 | 53 | if (CryptDecodeObjectEx(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, SPC_SP_OPUS_INFO_OBJID, 54 | pSignerInfo->AuthAttrs.rgAttr[i].rgValue[0].pbData, pSignerInfo->AuthAttrs.rgAttr[i].rgValue[0].cbData, 55 | CRYPT_DECODE_ALLOC_FLAG, 0, &pOpusInfo, &dwDataSize) && dwDataSize && pOpusInfo) 56 | { 57 | if (pOpusInfo->pwszProgramName) 58 | { 59 | sigInfo.ProgramName = pOpusInfo->pwszProgramName; 60 | } 61 | if (pOpusInfo->pPublisherInfo) 62 | { 63 | switch (pOpusInfo->pPublisherInfo->dwLinkChoice) 64 | { 65 | case SPC_URL_LINK_CHOICE: 66 | sigInfo.PublisherLink = pOpusInfo->pPublisherInfo->pwszUrl; 67 | break; 68 | case SPC_FILE_LINK_CHOICE: 69 | sigInfo.PublisherLink = pOpusInfo->pPublisherInfo->pwszFile; 70 | break; 71 | } 72 | } 73 | if (pOpusInfo->pMoreInfo) 74 | { 75 | switch (pOpusInfo->pMoreInfo->dwLinkChoice) 76 | { 77 | case SPC_URL_LINK_CHOICE: 78 | sigInfo.MoreInfoLink = pOpusInfo->pMoreInfo->pwszUrl; 79 | break; 80 | case SPC_FILE_LINK_CHOICE: 81 | sigInfo.MoreInfoLink = pOpusInfo->pMoreInfo->pwszFile; 82 | break; 83 | } 84 | } 85 | } 86 | 87 | if (pOpusInfo) LocalFree(pOpusInfo); 88 | 89 | return true; 90 | } 91 | } 92 | 93 | return false; 94 | } 95 | 96 | bool GetDigitalSignatureInfo(const wchar_t* path, SignedFileInformation &info) 97 | { 98 | DWORD dwEncodingType, dwContentType, dwFormatType; 99 | HCERTSTORE hStore = nullptr; 100 | HCRYPTMSG hMsg = nullptr; 101 | 102 | BOOL fResult = CryptQueryObject(CERT_QUERY_OBJECT_FILE, path, CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED, 103 | CERT_QUERY_FORMAT_FLAG_BINARY, 0, &dwEncodingType, &dwContentType, &dwFormatType, &hStore, &hMsg, nullptr); 104 | if (!fResult) return false; 105 | 106 | DWORD dwNumSigners; 107 | DWORD dwParamSize = sizeof(dwNumSigners); 108 | 109 | fResult = CryptMsgGetParam(hMsg, CMSG_SIGNER_COUNT_PARAM, 0, &dwNumSigners, &dwParamSize); 110 | if (fResult) 111 | { 112 | for (DWORD i = 0; i < dwNumSigners; ++i) 113 | { 114 | DWORD dwSignerInfoSize = 0; 115 | 116 | fResult = CryptMsgGetParam(hMsg, CMSG_SIGNER_INFO_PARAM, i, nullptr, &dwSignerInfoSize); 117 | if (fResult) 118 | { 119 | PCMSG_SIGNER_INFO pSignerInfo = (PCMSG_SIGNER_INFO)LocalAlloc(LPTR, dwSignerInfoSize); 120 | fResult = CryptMsgGetParam(hMsg, CMSG_SIGNER_INFO_PARAM, i, pSignerInfo, &dwSignerInfoSize); 121 | if (fResult) 122 | { 123 | DigitalSignatureInfo signatureInfo; 124 | if (GetCertificateInfo(hStore, pSignerInfo, signatureInfo.CertInfo) 125 | && GetProgAndPublisherInfo(pSignerInfo, signatureInfo)) 126 | { 127 | signatureInfo.HashAlgorithm = GetAlgorithmName(pSignerInfo->HashAlgorithm); 128 | signatureInfo.HashEncryptionAlgorithm = GetAlgorithmName(pSignerInfo->HashEncryptionAlgorithm); 129 | 130 | info.Signatures.push_back(signatureInfo); 131 | } 132 | } 133 | LocalFree(pSignerInfo); 134 | } 135 | } 136 | } 137 | 138 | if (hStore) CertCloseStore(hStore, 0); 139 | if (hMsg) CryptMsgClose(hMsg); 140 | 141 | return info.Signatures.size() > 0; 142 | } 143 | 144 | long VerifyPeSignature(const wchar_t* path) 145 | { 146 | WINTRUST_FILE_INFO wtfi = { 0 }; 147 | wtfi.cbStruct = sizeof(WINTRUST_FILE_INFO); 148 | wtfi.pcwszFilePath = path; 149 | 150 | WINTRUST_DATA wtData = { 0 }; 151 | wtData.cbStruct = sizeof(WINTRUST_DATA); 152 | wtData.dwUIChoice = WTD_UI_NONE; 153 | wtData.dwUnionChoice = WTD_CHOICE_FILE; 154 | wtData.dwStateAction = WTD_STATEACTION_VERIFY; 155 | wtData.fdwRevocationChecks = WTD_REVOKE_NONE; 156 | wtData.pFile = &wtfi; 157 | 158 | GUID pgActionId = WINTRUST_ACTION_GENERIC_VERIFY_V2; 159 | 160 | LONG lStatus = WinVerifyTrust(NULL, &pgActionId, &wtData); 161 | 162 | wtData.dwStateAction = WTD_STATEACTION_CLOSE; 163 | WinVerifyTrust(0, &pgActionId, &wtData); 164 | 165 | return lStatus; 166 | } 167 | -------------------------------------------------------------------------------- /source/trust.h: -------------------------------------------------------------------------------- 1 | #ifndef trust_h__ 2 | #define trust_h__ 3 | 4 | struct CertificateInfo 5 | { 6 | std::wstring IssuerName; 7 | std::wstring SubjectName; 8 | std::wstring SignatureAlgorithm; 9 | }; 10 | 11 | struct DigitalSignatureInfo 12 | { 13 | std::wstring ProgramName; 14 | std::wstring PublisherLink; 15 | std::wstring MoreInfoLink; 16 | 17 | std::wstring HashAlgorithm; 18 | std::wstring HashEncryptionAlgorithm; 19 | 20 | CertificateInfo CertInfo; 21 | }; 22 | 23 | struct SignedFileInformation 24 | { 25 | std::vector Signatures; 26 | }; 27 | 28 | long VerifyPeSignature(const wchar_t* path); 29 | bool GetDigitalSignatureInfo(const wchar_t* path, SignedFileInformation &info); 30 | 31 | #endif // trust_h__ 32 | -------------------------------------------------------------------------------- /source/version.m4i: -------------------------------------------------------------------------------- 1 | m4_define(VMAJOR, `2')m4_dnl 2 | m4_define(VMINOR, `8')m4_dnl 3 | m4_define(VREVISION, `3')m4_dnl 4 | m4_define(PLUGIN_VERSION, `VMAJOR.VMINOR.VREVISION')m4_dnl 5 | --------------------------------------------------------------------------------