ReactOS  0.4.13-dev-563-g0561610
crypt_sha.c
Go to the documentation of this file.
1 /*
2  * Unit tests for SHA functions
3  *
4  * Copyright (c) 2004 Filip Navara
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20 
21 #include <stdarg.h>
22 
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winerror.h"
26 
27 #include "wine/test.h"
28 
29 typedef struct {
30  ULONG Unknown[6];
31  ULONG State[5];
32  ULONG Count[2];
33  UCHAR Buffer[64];
34 } SHA_CTX, *PSHA_CTX;
35 
36 static void test_sha_ctx(void)
37 {
38  void (WINAPI *pA_SHAInit)(PSHA_CTX);
39  void (WINAPI *pA_SHAUpdate)(PSHA_CTX, const unsigned char *, UINT);
40  void (WINAPI *pA_SHAFinal)(PSHA_CTX, PULONG);
41  static const unsigned char test_buffer[] = "In our Life there's If"
42  "In our beliefs there's Lie"
43  "In our business there is Sin"
44  "In our bodies, there is Die";
45  HMODULE hmod;
46  SHA_CTX ctx;
47  ULONG result[5];
48  ULONG result_correct[5] = {0xe014f93, 0xe09791ec, 0x6dcf96c8, 0x8e9385fc, 0x1611c1bb};
49 
50  hmod = GetModuleHandleA("advapi32.dll");
51  pA_SHAInit = (void *)GetProcAddress(hmod, "A_SHAInit");
52  pA_SHAUpdate = (void *)GetProcAddress(hmod, "A_SHAUpdate");
53  pA_SHAFinal = (void *)GetProcAddress(hmod, "A_SHAFinal");
54 
55  if (!pA_SHAInit || !pA_SHAUpdate || !pA_SHAFinal)
56  {
57  win_skip("A_SHAInit and/or A_SHAUpdate and/or A_SHAFinal are not available\n");
58  return;
59  }
60 
61  RtlZeroMemory(&ctx, sizeof(ctx));
62  pA_SHAInit(&ctx);
63  pA_SHAUpdate(&ctx, test_buffer, sizeof(test_buffer)-1);
64  pA_SHAUpdate(&ctx, test_buffer, sizeof(test_buffer)-1);
65  pA_SHAFinal(&ctx, result);
66  ok(!memcmp(result, result_correct, sizeof(result)), "incorrect result\n");
67 }
68 
69 START_TEST(crypt_sha)
70 {
71  test_sha_ctx();
72 }
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
Definition: addons.c:68
START_TEST(crypt_sha)
Definition: crypt_sha.c:69
#define ok(value,...)
struct tagSHA_CTX SHA_CTX
Definition: bufpool.h:45
#define WINAPI
Definition: msvc.h:8
unsigned char UCHAR
Definition: xmlstorage.h:181
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:819
struct SHA_CTX * PSHA_CTX
static TCHAR test_buffer[TEST_BUFFER_SIZE]
Definition: _tfileio.c:53
static PEXPLICIT_ACCESSW *static HMODULE hmod
Definition: security.c:141
unsigned int * PULONG
Definition: retypes.h:1
unsigned int UINT
Definition: ndis.h:50
static void test_sha_ctx(void)
Definition: crypt_sha.c:36
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define GetProcAddress(x, y)
Definition: compat.h:410
GLuint64EXT * result
Definition: glext.h:11304
#define win_skip
Definition: test.h:141