ReactOS 0.4.15-dev-7994-gb388cb6
Hash.c File Reference
#include "precomp.h"
Include dependency graph for Hash.c:

Go to the source code of this file.

Classes

struct  _A_SHA_CTX
 
struct  _MD5_CTX
 
struct  _MD4_CTX
 

Macros

#define A_SHA_DIGEST_LEN   20
 
#define MD5_DIGEST_LEN   16
 
#define MD4_DIGEST_LEN   16
 
#define RSA32API   __stdcall
 

Typedefs

typedef struct _A_SHA_CTX A_SHA_CTX
 
typedef struct _A_SHA_CTXPA_SHA_CTX
 
typedef struct _MD5_CTX MD5_CTX
 
typedef struct _MD5_CTXPMD5_CTX
 
typedef struct _MD4_CTX MD4_CTX
 
typedef struct _MD4_CTXPMD4_CTX
 
typedef VOID RSA32API FN_A_SHAInit(_Out_ PA_SHA_CTX Context)
 
typedef VOID RSA32API FN_A_SHAUpdate(_Inout_ PA_SHA_CTX Context, _In_reads_(BufferSize) PUCHAR Buffer, _In_ ULONG BufferSize)
 
typedef VOID RSA32API FN_A_SHAFinal(_Inout_ PA_SHA_CTX Context, _Out_ PUCHAR Result)
 
typedef VOID RSA32API FN_MD5Init(_Out_ PMD5_CTX Context)
 
typedef VOID RSA32API FN_MD5Update(_Inout_ PMD5_CTX Context, _In_reads_(BufferSize) PUCHAR Buffer, _In_ ULONG BufferSize)
 
typedef VOID RSA32API FN_MD5Final(_Inout_ PMD5_CTX Context)
 
typedef VOID RSA32API FN_MD4Init(_Out_ PMD4_CTX Context)
 
typedef VOID RSA32API FN_MD4Update(_Inout_ PMD4_CTX Context, _In_reads_(BufferSize) PUCHAR Buffer, _In_ ULONG BufferSize)
 
typedef VOID RSA32API FN_MD4Final(_Inout_ PMD4_CTX Context)
 

Functions

static void Test_SHA1 (void)
 
static void Test_MD5 (void)
 
static void Test_MD4 (void)
 
 START_TEST (Hash)
 

Variables

static HMODULE g_hAdvapi32 = NULL
 
static ANSI_STRING g_TestString = RTL_CONSTANT_STRING("ReactOS Hash API Test String")
 
static ULONG g_ctxSHA1StateInit [] = { 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0 }
 
static UCHAR g_aucSHA1Result [A_SHA_DIGEST_LEN]
 
static ULONG g_aulMD5Or4StateInit [] = { 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476 }
 
static UCHAR g_aucMD5Result [MD5_DIGEST_LEN]
 
static UCHAR g_aucMD4Result [MD4_DIGEST_LEN]
 

Macro Definition Documentation

◆ A_SHA_DIGEST_LEN

#define A_SHA_DIGEST_LEN   20

Definition at line 17 of file Hash.c.

◆ MD4_DIGEST_LEN

#define MD4_DIGEST_LEN   16

Definition at line 37 of file Hash.c.

◆ MD5_DIGEST_LEN

#define MD5_DIGEST_LEN   16

Definition at line 27 of file Hash.c.

◆ RSA32API

#define RSA32API   __stdcall

Definition at line 40 of file Hash.c.

Typedef Documentation

◆ A_SHA_CTX

◆ FN_A_SHAFinal

Definition at line 60 of file Hash.c.

◆ FN_A_SHAInit

typedef VOID RSA32API FN_A_SHAInit(_Out_ PA_SHA_CTX Context)

Definition at line 46 of file Hash.c.

◆ FN_A_SHAUpdate

Definition at line 52 of file Hash.c.

◆ FN_MD4Final

typedef VOID RSA32API FN_MD4Final(_Inout_ PMD4_CTX Context)

Definition at line 101 of file Hash.c.

◆ FN_MD4Init

typedef VOID RSA32API FN_MD4Init(_Out_ PMD4_CTX Context)

Definition at line 87 of file Hash.c.

◆ FN_MD4Update

Definition at line 93 of file Hash.c.

◆ FN_MD5Final

typedef VOID RSA32API FN_MD5Final(_Inout_ PMD5_CTX Context)

Definition at line 81 of file Hash.c.

◆ FN_MD5Init

typedef VOID RSA32API FN_MD5Init(_Out_ PMD5_CTX Context)

Definition at line 67 of file Hash.c.

◆ FN_MD5Update

Definition at line 73 of file Hash.c.

◆ MD4_CTX

◆ MD5_CTX

◆ PA_SHA_CTX

◆ PMD4_CTX

◆ PMD5_CTX

Function Documentation

◆ START_TEST()

START_TEST ( Hash  )

Definition at line 290 of file Hash.c.

291{
292 /* Load advapi32.dll */
293 g_hAdvapi32 = GetModuleHandleW(L"advapi32.dll");
294 if (!g_hAdvapi32)
295 {
296 skip("Module advapi32 not found\n");
297 return;
298 }
299
300 Test_SHA1();
301 Test_MD5();
302 Test_MD4();
303}
static void Test_SHA1(void)
Definition: Hash.c:124
static HMODULE g_hAdvapi32
Definition: Hash.c:104
static void Test_MD4(void)
Definition: Hash.c:235
static void Test_MD5(void)
Definition: Hash.c:180
#define skip(...)
Definition: atltest.h:64
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
#define L(x)
Definition: ntvdm.h:50

◆ Test_MD4()

static void Test_MD4 ( void  )
static

Definition at line 235 of file Hash.c.

236{
237 FN_MD4Init* pfnMD4Init;
238 FN_MD4Update* pfnMD4Update;
239 FN_MD4Final* pfnMD4Final;
241 SIZE_T ComparedSize;
242
243 /* Load functions */
244 pfnMD4Init = (FN_MD4Init*)GetProcAddress(g_hAdvapi32, "MD4Init");
247
248 if (!pfnMD4Init || !pfnMD4Update || !pfnMD4Final)
249 {
250 skip("advapi32.dll!MD4*** not found\n");
251 return;
252 }
253
254 /* Test MD4Init */
255 pfnMD4Init(&ctx);
256 ok_eq_ulong(ctx.Count[0], 0UL);
257 ok_eq_ulong(ctx.Count[1], 0UL);
258 ComparedSize = RtlCompareMemory(ctx.State,
261 ok_eq_size(ComparedSize, RTL_FIELD_SIZE(MD4_CTX, State));
262
263 /* Test MD4Update */
265 ComparedSize = RtlCompareMemory(ctx.Buffer,
268 ok_eq_size(ComparedSize, g_TestString.Length);
269 ComparedSize = RtlCompareMemory(ctx.State,
272 ok_eq_size(ComparedSize, RTL_FIELD_SIZE(MD4_CTX, State));
274 ok_eq_ulong(ctx.Count[1], 0UL);
275
276 /* Test MD4Final */
277 pfnMD4Final(&ctx);
278 ok_eq_ulong(ctx.Count[0], 0x200UL);
279 ok_eq_ulong(ctx.Count[1], 0UL);
280 ok_eq_ulong(ctx.State[0], 0x8A50E8E0UL);
281 ok_eq_ulong(ctx.State[1], 0xA602114DUL);
282 ok_eq_ulong(ctx.State[2], 0xABA7F06AUL);
283 ok_eq_ulong(ctx.State[3], 0xED40C4D8UL);
284 ComparedSize = RtlCompareMemoryUlong(ctx.Buffer, sizeof(ctx.Buffer), 0);
285 ok_eq_size(ComparedSize, sizeof(ctx.Buffer));
286 ComparedSize = RtlCompareMemory(ctx.Hash, &g_aucMD4Result, MD4_DIGEST_LEN);
287 ok_eq_size(ComparedSize, MD4_DIGEST_LEN);
288}
static ULONG g_aulMD5Or4StateInit[]
Definition: Hash.c:114
VOID RSA32API FN_MD4Final(_Inout_ PMD4_CTX Context)
Definition: Hash.c:101
static UCHAR g_aucMD4Result[MD4_DIGEST_LEN]
Definition: Hash.c:119
#define MD4_DIGEST_LEN
Definition: Hash.c:37
static ANSI_STRING g_TestString
Definition: Hash.c:105
VOID RSA32API FN_MD4Update(_Inout_ PMD4_CTX Context, _In_reads_(BufferSize) PUCHAR Buffer, _In_ ULONG BufferSize)
Definition: Hash.c:93
VOID RSA32API FN_MD4Init(_Out_ PMD4_CTX Context)
Definition: Hash.c:87
#define ok_eq_ulong(value, expected)
Definition: apitest.h:63
#define ok_eq_size(value, expected)
Definition: apitest.h:69
#define GetProcAddress(x, y)
Definition: compat.h:753
#define CHAR_BIT
Definition: urlcache.c:62
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
VOID WINAPI MD4Final(MD4_CTX *ctx)
Definition: md4.c:113
VOID WINAPI MD4Update(MD4_CTX *ctx, const unsigned char *buf, unsigned int len)
Definition: md4.c:59
VOID WINAPI MD4Init(MD4_CTX *ctx)
Definition: md4.c:45
#define RTL_FIELD_SIZE(type, field)
Definition: kdb_expr.c:86
if(dx< 0)
Definition: linetemp.h:194
#define DECLSPEC_ALIGN(x)
Definition: ntbasedef.h:251
Definition: util.c:82
#define UL
Definition: tui.h:165
ULONG_PTR SIZE_T
Definition: typedefs.h:80
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ NTSYSAPI SIZE_T NTAPI RtlCompareMemoryUlong(_In_reads_bytes_(Length) PVOID Source, _In_ SIZE_T Length, _In_ ULONG Pattern)

Referenced by START_TEST().

◆ Test_MD5()

static void Test_MD5 ( void  )
static

Definition at line 180 of file Hash.c.

181{
182 FN_MD5Init* pfnMD5Init;
183 FN_MD5Update* pfnMD5Update;
184 FN_MD5Final* pfnMD5Final;
186 SIZE_T ComparedSize;
187
188 /* Load functions */
189 pfnMD5Init = (FN_MD5Init*)GetProcAddress(g_hAdvapi32, "MD5Init");
192
193 if (!pfnMD5Init || !pfnMD5Update || !pfnMD5Final)
194 {
195 skip("advapi32.dll!MD5*** not found\n");
196 return;
197 }
198
199 /* Test MD5Init */
200 pfnMD5Init(&ctx);
201 ok_eq_ulong(ctx.Count[0], 0UL);
202 ok_eq_ulong(ctx.Count[1], 0UL);
203 ComparedSize = RtlCompareMemory(ctx.State,
206 ok_eq_size(ComparedSize, RTL_FIELD_SIZE(MD5_CTX, State));
207
208 /* Test MD5Update */
210 ComparedSize = RtlCompareMemory(ctx.Buffer,
213 ok_eq_size(ComparedSize, g_TestString.Length);
214 ComparedSize = RtlCompareMemory(ctx.State,
217 ok_eq_size(ComparedSize, RTL_FIELD_SIZE(MD5_CTX, State));
219 ok_eq_ulong(ctx.Count[1], 0UL);
220
221 /* Test MD5Final */
222 pfnMD5Final(&ctx);
223 ok_eq_ulong(ctx.Count[0], 0x200UL);
224 ok_eq_ulong(ctx.Count[1], 0UL);
225 ok_eq_ulong(ctx.State[0], 0x8B23E83DUL);
226 ok_eq_ulong(ctx.State[1], 0x48CEE09DUL);
227 ok_eq_ulong(ctx.State[2], 0xD9DD1BB1UL);
228 ok_eq_ulong(ctx.State[3], 0xDEB286C6UL);
229 ComparedSize = RtlCompareMemoryUlong(ctx.Buffer, sizeof(ctx.Buffer), 0);
230 ok_eq_size(ComparedSize, sizeof(ctx.Buffer));
231 ComparedSize = RtlCompareMemory(ctx.Hash, &g_aucMD5Result, MD5_DIGEST_LEN);
232 ok_eq_size(ComparedSize, MD5_DIGEST_LEN);
233}
VOID RSA32API FN_MD5Update(_Inout_ PMD5_CTX Context, _In_reads_(BufferSize) PUCHAR Buffer, _In_ ULONG BufferSize)
Definition: Hash.c:73
VOID RSA32API FN_MD5Init(_Out_ PMD5_CTX Context)
Definition: Hash.c:67
VOID RSA32API FN_MD5Final(_Inout_ PMD5_CTX Context)
Definition: Hash.c:81
static UCHAR g_aucMD5Result[MD5_DIGEST_LEN]
Definition: Hash.c:115
#define MD5_DIGEST_LEN
Definition: Hash.c:27
VOID WINAPI MD5Final(MD5_CTX *)
Definition: md5.c:113
VOID WINAPI MD5Init(MD5_CTX *)
Definition: md5.c:45
VOID WINAPI MD5Update(MD5_CTX *, const unsigned char *, unsigned int)
Definition: md5.c:59
Definition: msi.c:4013

Referenced by START_TEST().

◆ Test_SHA1()

static void Test_SHA1 ( void  )
static

Definition at line 124 of file Hash.c.

125{
126 FN_A_SHAInit* pfnA_SHAInit;
127 FN_A_SHAUpdate* pfnA_SHAUpdate;
128 FN_A_SHAFinal* pfnA_SHAFinal;
131 SIZE_T ComparedSize;
132
133 /* Load functions */
137
138 if (!pfnA_SHAInit || !pfnA_SHAUpdate || !pfnA_SHAFinal)
139 {
140 skip("advapi32.dll!A_SHA*** not found\n");
141 return;
142 }
143
144 /* Test A_SHAInit */
145 pfnA_SHAInit(&ctx);
146 ComparedSize = RtlCompareMemory(ctx.State,
149 ok_eq_size(ComparedSize, RTL_FIELD_SIZE(A_SHA_CTX, State));
150 ok_eq_ulong(ctx.Count[0], 0UL);
151 ok_eq_ulong(ctx.Count[1], 0UL);
152
153 /* Test A_SHAUpdate */
154 pfnA_SHAUpdate(&ctx, (PUCHAR)g_TestString.Buffer, g_TestString.Length);
155 ComparedSize = RtlCompareMemory(ctx.Buffer,
158 ok_eq_size(ComparedSize, g_TestString.Length);
159 ComparedSize = RtlCompareMemory(ctx.State,
162 ok_eq_size(ComparedSize, RTL_FIELD_SIZE(A_SHA_CTX, State));
163 ok_eq_ulong(ctx.Count[0], 0UL);
165
166 /* Test A_SHAFinal */
167 pfnA_SHAFinal(&ctx, Result);
168 ComparedSize = RtlCompareMemoryUlong(ctx.Buffer, sizeof(ctx.Buffer), 0);
169 ok_eq_size(ComparedSize, sizeof(ctx.Buffer));
170 ComparedSize = RtlCompareMemory(ctx.State,
173 ok_eq_size(ComparedSize, RTL_FIELD_SIZE(A_SHA_CTX, State));
174 ok_eq_ulong(ctx.Count[0], 0UL);
175 ok_eq_ulong(ctx.Count[1], 0UL);
177 ok_eq_size(ComparedSize, A_SHA_DIGEST_LEN);
178}
#define A_SHA_DIGEST_LEN
Definition: Hash.c:17
VOID RSA32API FN_A_SHAInit(_Out_ PA_SHA_CTX Context)
Definition: Hash.c:46
VOID RSA32API FN_A_SHAFinal(_Inout_ PA_SHA_CTX Context, _Out_ PUCHAR Result)
Definition: Hash.c:60
static UCHAR g_aucSHA1Result[A_SHA_DIGEST_LEN]
Definition: Hash.c:108
VOID RSA32API FN_A_SHAUpdate(_Inout_ PA_SHA_CTX Context, _In_reads_(BufferSize) PUCHAR Buffer, _In_ ULONG BufferSize)
Definition: Hash.c:52
static ULONG g_ctxSHA1StateInit[]
Definition: Hash.c:107
void WINAPI A_SHAInit(PSHA_CTX)
Definition: sha1.c:102
void WINAPI A_SHAUpdate(PSHA_CTX, const unsigned char *, UINT)
Definition: sha1.c:128
void WINAPI A_SHAFinal(PSHA_CTX, PULONG)
Definition: sha1.c:171
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by START_TEST().

Variable Documentation

◆ g_aucMD4Result

UCHAR g_aucMD4Result[MD4_DIGEST_LEN]
static
Initial value:
= {
0xE0, 0xE8, 0x50, 0x8A, 0x4D, 0x11, 0x02, 0xA6,
0x6A, 0xF0, 0xA7, 0xAB, 0xD8, 0xC4, 0x40, 0xED
}

Definition at line 119 of file Hash.c.

Referenced by Test_MD4().

◆ g_aucMD5Result

UCHAR g_aucMD5Result[MD5_DIGEST_LEN]
static
Initial value:
= {
0x3D, 0xE8, 0x23, 0x8B, 0x9D, 0xE0, 0xCE, 0x48,
0xB1, 0x1B, 0xDD, 0xD9, 0xC6, 0x86, 0xB2, 0xDE
}

Definition at line 115 of file Hash.c.

Referenced by Test_MD5().

◆ g_aucSHA1Result

UCHAR g_aucSHA1Result[A_SHA_DIGEST_LEN]
static
Initial value:
= {
0xEC, 0x05, 0x43, 0xE7, 0xDE, 0x8A, 0xEE, 0xFF,
0xAD, 0x72, 0x2B, 0x9D, 0x55, 0x4F, 0xCA, 0x6A,
0x8D, 0x81, 0xF1, 0xC7
}

Definition at line 108 of file Hash.c.

Referenced by Test_SHA1().

◆ g_aulMD5Or4StateInit

ULONG g_aulMD5Or4StateInit[] = { 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476 }
static

Definition at line 114 of file Hash.c.

Referenced by Test_MD4(), and Test_MD5().

◆ g_ctxSHA1StateInit

ULONG g_ctxSHA1StateInit[] = { 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0 }
static

Definition at line 107 of file Hash.c.

Referenced by Test_SHA1().

◆ g_hAdvapi32

HMODULE g_hAdvapi32 = NULL
static

Definition at line 104 of file Hash.c.

Referenced by START_TEST(), Test_MD4(), Test_MD5(), and Test_SHA1().

◆ g_TestString

ANSI_STRING g_TestString = RTL_CONSTANT_STRING("ReactOS Hash API Test String")
static

Definition at line 105 of file Hash.c.

Referenced by Test_MD4(), Test_MD5(), and Test_SHA1().